Skip to content

Commit f6af86a

Browse files
committed
Land rapid7#4402, ms12_020_check NilClass fix
2 parents 3a00db3 + c611249 commit f6af86a

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

modules/auxiliary/scanner/rdp/ms12_020_check.rb

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,11 @@ def peer
128128
"#{rhost}:#{rport}"
129129
end
130130

131-
def run_host(ip)
132-
133-
connect
134-
131+
def check_rdp_vuln
135132
# check if rdp is open
136-
if not check_rdp
133+
unless check_rdp
137134
vprint_status "#{peer} Could not connect to RDP."
138-
disconnect
139-
return
135+
return Exploit::CheckCode::Unknown
140136
end
141137

142138
# send connectInitial
@@ -145,31 +141,63 @@ def run_host(ip)
145141
# send userRequest
146142
sock.put(user_request)
147143
res = sock.get_once(-1, 5)
144+
return Exploit::CheckCode::Unknown unless res # nil due to a timeout
148145
user1 = res[9,2].unpack("n").first
149146
chan1 = user1 + 1001
150147

151148
# send 2nd userRequest
152149
sock.put(user_request)
153150
res = sock.get_once(-1, 5)
154-
151+
return Exploit::CheckCode::Unknown unless res # nil due to a timeout
155152
user2 = res[9,2].unpack("n").first
156153
chan2 = user2 + 1001
157154

158155
# send channel request one
159156
sock.put(channel_request << [user1, chan2].pack("nn"))
160157
res = sock.get_once(-1, 5)
161-
162-
if res and res[7,2] == "\x3e\x00"
158+
return Exploit::CheckCode::Unknown unless res # nil due to a timeout
159+
if res[7,2] == "\x3e\x00"
163160
# send ChannelRequestTwo - prevent BSoD
164161
sock.put(channel_request << [user2, chan2].pack("nn"))
165162

166-
print_good("#{peer} Vulnerable to MS12-020")
163+
return Exploit::CheckCode::Vulnerable
167164
report_goods
168165
else
169-
vprint_status("#{peer} Not Vulnerable")
166+
return Exploit::CheckCode::Safe
167+
end
168+
169+
# Can't determine, but at least I know the service is running
170+
return Exploit::CheckCode::Detected
171+
end
172+
173+
def check_host(ip)
174+
# The check command will call this method instead of run_host
175+
176+
status = Exploit::CheckCode::Unknown
177+
178+
begin
179+
connect
180+
status = check_rdp_vuln
181+
rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e
182+
bt = e.backtrace.join("\n")
183+
vprint_error("Unexpected error: #{e.message}")
184+
vprint_line(bt)
185+
elog("#{e.message}\n#{bt}")
186+
ensure
187+
disconnect
170188
end
171189

172-
disconnect()
190+
status
191+
end
192+
193+
def run_host(ip)
194+
# Allow the run command to call the check command
195+
status = check_host(ip)
196+
if status == Exploit::CheckCode::Vulnerable
197+
print_good("#{ip}:#{rport} - #{status[1]}")
198+
else
199+
print_status("#{ip}:#{rport} - #{status[1]}")
200+
end
173201
end
174202

175203
end

0 commit comments

Comments
 (0)