Skip to content

Commit c611249

Browse files
committed
Take full advantage of the check command
1 parent 9edb2b4 commit c611249

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

modules/auxiliary/scanner/rdp/ms12_020_check.rb

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,9 @@ def peer
130130

131131
def check_rdp_vuln
132132
# check if rdp is open
133-
if not check_rdp
133+
unless check_rdp
134134
vprint_status "#{peer} Could not connect to RDP."
135-
disconnect
136-
return
135+
return Exploit::CheckCode::Unknown
137136
end
138137

139138
# send connectInitial
@@ -142,43 +141,63 @@ def check_rdp_vuln
142141
# send userRequest
143142
sock.put(user_request)
144143
res = sock.get_once(-1, 5)
144+
return Exploit::CheckCode::Unknown unless res # nil due to a timeout
145145
user1 = res[9,2].unpack("n").first
146146
chan1 = user1 + 1001
147147

148148
# send 2nd userRequest
149149
sock.put(user_request)
150150
res = sock.get_once(-1, 5)
151-
151+
return Exploit::CheckCode::Unknown unless res # nil due to a timeout
152152
user2 = res[9,2].unpack("n").first
153153
chan2 = user2 + 1001
154154

155155
# send channel request one
156156
sock.put(channel_request << [user1, chan2].pack("nn"))
157157
res = sock.get_once(-1, 5)
158-
159-
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"
160160
# send ChannelRequestTwo - prevent BSoD
161161
sock.put(channel_request << [user2, chan2].pack("nn"))
162162

163-
print_good("#{peer} Vulnerable to MS12-020")
163+
return Exploit::CheckCode::Vulnerable
164164
report_goods
165165
else
166-
vprint_status("#{peer} Not Vulnerable")
166+
return Exploit::CheckCode::Safe
167167
end
168+
169+
# Can't determine, but at least I know the service is running
170+
return Exploit::CheckCode::Detected
168171
end
169172

170-
def run_host(ip)
173+
def check_host(ip)
174+
# The check command will call this method instead of run_host
175+
176+
status = Exploit::CheckCode::Unknown
177+
171178
begin
172179
connect
173-
check_rdp_vuln
180+
status = check_rdp_vuln
174181
rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e
175182
bt = e.backtrace.join("\n")
176-
print_error("Unexpected error: #{e.message}")
183+
vprint_error("Unexpected error: #{e.message}")
177184
vprint_line(bt)
178185
elog("#{e.message}\n#{bt}")
179186
ensure
180187
disconnect
181188
end
189+
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
182201
end
183202

184203
end

0 commit comments

Comments
 (0)