File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -1218,10 +1218,31 @@ def reset_session_counts
1218
1218
# Failure tracking
1219
1219
##
1220
1220
1221
+ # Raises a Msf::Exploit::Failed exception. It overrides the fail_with method
1222
+ # in lib/msf/core/module.rb
1223
+ #
1224
+ # @param reason [String] A constant from Msf::Module::Failure.
1225
+ # If the reason does not come from there, then it will default to
1226
+ # Msf::Module::Failure::Unknown.
1227
+ # @param mssg [String] (Optional) A message about the failure.
1228
+ # @raise [Msf::Exploit::Failed] A custom Msf::Exploit::Failed exception.
1229
+ # @return [void]
1230
+ # @see Msf::Module::Failure
1231
+ # @see Msf::Module#fail_with
1232
+ # @example
1233
+ # fail_with(Msf::Module::Failure::NoAccess, 'Unable to login to upload payload')
1221
1234
def fail_with ( reason , msg = nil )
1222
- self . fail_reason = reason
1235
+ # The reason being registered here will be used later on, so it's important we don't actually
1236
+ # provide a made-up one.
1237
+ allowed_values = Msf ::Module ::Failure . constants . collect { |e | Msf ::Module ::Failure . const_get ( e ) }
1238
+ if allowed_values . include? ( reason )
1239
+ self . fail_reason = reason
1240
+ else
1241
+ self . fail_reason = Msf ::Module ::Failure ::Unknown
1242
+ end
1243
+
1223
1244
self . fail_detail = msg
1224
- raise Msf ::Exploit ::Failed , ( msg || "No reason given" )
1245
+ raise Msf ::Exploit ::Failed , ( msg || "No failure message given" )
1225
1246
end
1226
1247
1227
1248
def report_failure
Original file line number Diff line number Diff line change @@ -276,7 +276,18 @@ def debugging?
276
276
end
277
277
278
278
#
279
- # Support fail_with for all module types, allow specific classes to override
279
+ # Raises a RuntimeError failure message. This is meant to be used for all non-exploits,
280
+ # and allows specific classes to override.
281
+ #
282
+ # @param reason [String] A reason about the failure.
283
+ # @param msg [String] (Optional) A message about the failure.
284
+ # @raise [RuntimeError]
285
+ # @return [void]
286
+ # @note If you are writing an exploit, you don't use this API. Instead, please refer to the
287
+ # API documentation from lib/msf/core/exploit.rb.
288
+ # @see Msf::Exploit#fail_with
289
+ # @example
290
+ # fail_with('No Access', 'Unable to login')
280
291
#
281
292
def fail_with ( reason , msg = nil )
282
293
raise RuntimeError , "#{ reason . to_s } : #{ msg } "
You can’t perform that action at this time.
0 commit comments