@@ -1263,6 +1263,96 @@ def fail_with(reason,msg=nil)
1263
1263
raise Msf ::Exploit ::Failed , ( msg || "No failure message given" )
1264
1264
end
1265
1265
1266
+ def setup_fail_detail_from_exception e
1267
+ # Build a user-friendly error message
1268
+ msg = "#{ e } "
1269
+ unless e . class == Msf ::Exploit ::Failed
1270
+ msg = "#{ e . class } #{ e } "
1271
+ end
1272
+
1273
+ self . error = e
1274
+
1275
+ # Record the detailed reason
1276
+ self . fail_detail ||= e . to_s
1277
+ msg
1278
+ end
1279
+
1280
+ #
1281
+ # Handle the exception
1282
+ #
1283
+ def handle_exception e
1284
+ msg = setup_fail_detail_from_exception e
1285
+
1286
+ case e
1287
+ when Msf ::Exploit ::Complete
1288
+ # Nothing to show in this case
1289
+ return
1290
+
1291
+ when Msf ::Exploit ::Failed
1292
+ self . print_error ( "Exploit aborted due to failure: #{ self . fail_reason } : #{ msg } " )
1293
+
1294
+ # The caller should have already set self.fail_reason
1295
+ if self . fail_reason == Msf ::Exploit ::Failure ::None
1296
+ self . fail_reason = Msf ::Exploit ::Failure ::Unknown
1297
+ end
1298
+
1299
+ when Rex ::ConnectionError
1300
+ self . fail_reason = Msf ::Exploit ::Failure ::Unreachable
1301
+ self . print_error ( "Exploit failed [#{ self . fail_reason } ]: #{ msg } " )
1302
+ elog ( "Exploit failed (#{ self . refname } ): #{ msg } " , 'core' , LEV_0 )
1303
+ dlog ( "Call stack:\n #{ e . backtrace . join ( "\n " ) } " , 'core' , LEV_3 )
1304
+
1305
+ when Rex ::BindFailed
1306
+ self . fail_reason = Msf ::Exploit ::Failure ::BadConfig
1307
+ self . print_error ( "Exploit failed [#{ self . fail_reason } ]: #{ msg } " )
1308
+ elog ( "Exploit failed (#{ self . refname } ): #{ msg } " , 'core' , LEV_0 )
1309
+ dlog ( "Call stack:\n #{ e . backtrace . join ( "\n " ) } " , 'core' , LEV_3 )
1310
+
1311
+ when Timeout ::Error
1312
+ self . fail_reason = Msf ::Exploit ::Failure ::TimeoutExpired
1313
+ self . print_error ( "Exploit failed [#{ self . fail_reason } ]: #{ msg } " )
1314
+ elog ( "Exploit failed (#{ self . refname } ): #{ msg } " , 'core' , LEV_0 )
1315
+ dlog ( "Call stack:\n #{ e . backtrace . join ( "\n " ) } " , 'core' , LEV_3 )
1316
+ else
1317
+
1318
+ # Compare as a string since not all error classes may be loaded
1319
+ case msg
1320
+ when /access.denied|Login Failed/i # Covers SMB as well as some generic errors
1321
+ self . fail_reason = Msf ::Exploit ::Failure ::NoAccess
1322
+ when /connection reset/i
1323
+ self . fail_reason = Msf ::Exploit ::Failure ::Disconnected
1324
+ when /connection timed out|SSL_connect|unreachable|connection was refused/i
1325
+ self . fail_reason = Msf ::Exploit ::Failure ::Unreachable
1326
+ when /unable.*target/i
1327
+ self . fail_reason = Msf ::Exploit ::Failure ::NoTarget
1328
+ when /execution expired/i
1329
+ self . fail_reason = Msf ::Exploit ::Failure ::TimeoutExpired
1330
+ when /(doesn.t|not).*vulnerable|may.*patched/i
1331
+ self . fail_reason = Msf ::Exploit ::Failure ::NotVulnerable
1332
+ end
1333
+
1334
+ # The caller should have already set self.fail_reason
1335
+ if self . fail_reason == Msf ::Exploit ::Failure ::None
1336
+ self . fail_reason = Msf ::Exploit ::Failure ::Unknown
1337
+ end
1338
+
1339
+ if self . fail_reason == Msf ::Exploit ::Failure ::Unknown
1340
+ self . print_error ( "Exploit failed: #{ msg } " )
1341
+ else
1342
+ self . print_error ( "Exploit failed [#{ self . fail_reason } ]: #{ msg } " )
1343
+ end
1344
+
1345
+ elog ( "Exploit failed (#{ self . refname } ): #{ msg } " , 'core' , LEV_0 )
1346
+ dlog ( "Call stack:\n #{ e . backtrace . join ( "\n " ) } " , 'core' , LEV_3 )
1347
+ end
1348
+
1349
+ # Record the error to various places
1350
+ self . framework . events . on_module_error ( self , msg )
1351
+
1352
+ # Report the failure (and attempt) in the database
1353
+ self . report_failure
1354
+ end
1355
+
1266
1356
def report_failure
1267
1357
return unless framework . db and framework . db . active
1268
1358
0 commit comments