@@ -128,15 +128,11 @@ def peer
128
128
"#{ rhost } :#{ rport } "
129
129
end
130
130
131
- def run_host ( ip )
132
-
133
- connect
134
-
131
+ def check_rdp_vuln
135
132
# check if rdp is open
136
- if not check_rdp
133
+ unless check_rdp
137
134
vprint_status "#{ peer } Could not connect to RDP."
138
- disconnect
139
- return
135
+ return Exploit ::CheckCode ::Unknown
140
136
end
141
137
142
138
# send connectInitial
@@ -145,31 +141,63 @@ def run_host(ip)
145
141
# send userRequest
146
142
sock . put ( user_request )
147
143
res = sock . get_once ( -1 , 5 )
144
+ return Exploit ::CheckCode ::Unknown unless res # nil due to a timeout
148
145
user1 = res [ 9 , 2 ] . unpack ( "n" ) . first
149
146
chan1 = user1 + 1001
150
147
151
148
# send 2nd userRequest
152
149
sock . put ( user_request )
153
150
res = sock . get_once ( -1 , 5 )
154
-
151
+ return Exploit :: CheckCode :: Unknown unless res # nil due to a timeout
155
152
user2 = res [ 9 , 2 ] . unpack ( "n" ) . first
156
153
chan2 = user2 + 1001
157
154
158
155
# send channel request one
159
156
sock . put ( channel_request << [ user1 , chan2 ] . pack ( "nn" ) )
160
157
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 "
163
160
# send ChannelRequestTwo - prevent BSoD
164
161
sock . put ( channel_request << [ user2 , chan2 ] . pack ( "nn" ) )
165
162
166
- print_good ( " #{ peer } Vulnerable to MS12-020" )
163
+ return Exploit :: CheckCode :: Vulnerable
167
164
report_goods
168
165
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
170
188
end
171
189
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
173
201
end
174
202
175
203
end
0 commit comments