@@ -130,10 +130,9 @@ def peer
130
130
131
131
def check_rdp_vuln
132
132
# check if rdp is open
133
- if not check_rdp
133
+ unless check_rdp
134
134
vprint_status "#{ peer } Could not connect to RDP."
135
- disconnect
136
- return
135
+ return Exploit ::CheckCode ::Unknown
137
136
end
138
137
139
138
# send connectInitial
@@ -142,43 +141,63 @@ def check_rdp_vuln
142
141
# send userRequest
143
142
sock . put ( user_request )
144
143
res = sock . get_once ( -1 , 5 )
144
+ return Exploit ::CheckCode ::Unknown unless res # nil due to a timeout
145
145
user1 = res [ 9 , 2 ] . unpack ( "n" ) . first
146
146
chan1 = user1 + 1001
147
147
148
148
# send 2nd userRequest
149
149
sock . put ( user_request )
150
150
res = sock . get_once ( -1 , 5 )
151
-
151
+ return Exploit :: CheckCode :: Unknown unless res # nil due to a timeout
152
152
user2 = res [ 9 , 2 ] . unpack ( "n" ) . first
153
153
chan2 = user2 + 1001
154
154
155
155
# send channel request one
156
156
sock . put ( channel_request << [ user1 , chan2 ] . pack ( "nn" ) )
157
157
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 "
160
160
# send ChannelRequestTwo - prevent BSoD
161
161
sock . put ( channel_request << [ user2 , chan2 ] . pack ( "nn" ) )
162
162
163
- print_good ( " #{ peer } Vulnerable to MS12-020" )
163
+ return Exploit :: CheckCode :: Vulnerable
164
164
report_goods
165
165
else
166
- vprint_status ( " #{ peer } Not Vulnerable" )
166
+ return Exploit :: CheckCode :: Safe
167
167
end
168
+
169
+ # Can't determine, but at least I know the service is running
170
+ return Exploit ::CheckCode ::Detected
168
171
end
169
172
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
+
171
178
begin
172
179
connect
173
- check_rdp_vuln
180
+ status = check_rdp_vuln
174
181
rescue Rex ::AddressInUse , ::Errno ::ETIMEDOUT , Rex ::HostUnreachable , Rex ::ConnectionTimeout , Rex ::ConnectionRefused , ::Timeout ::Error , ::EOFError => e
175
182
bt = e . backtrace . join ( "\n " )
176
- print_error ( "Unexpected error: #{ e . message } " )
183
+ vprint_error ( "Unexpected error: #{ e . message } " )
177
184
vprint_line ( bt )
178
185
elog ( "#{ e . message } \n #{ bt } " )
179
186
ensure
180
187
disconnect
181
188
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
182
201
end
183
202
184
203
end
0 commit comments