Skip to content

Commit 6444d8b

Browse files
committed
use kind_of? for checking exceptions
1 parent 3a73b40 commit 6444d8b

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

lib/msf/base/simple/auxiliary.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ def self.job_run_proc(ctx)
153153
mod.print_error("Auxiliary failed: #{e.class} #{e}")
154154
elog("Auxiliary failed: #{e.class} #{e}", 'core', LEV_0)
155155

156-
if(e.class.to_s != 'Msf::OptionValidateError')
156+
if e.kind_of?(Msf::OptionValidateError)
157+
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3)
158+
else
157159
mod.print_error("Call stack:")
158160
e.backtrace.each do |line|
159161
break if line =~ /lib.msf.base.simple.auxiliary.rb/
160162
mod.print_error(" #{line}")
161163
end
162164
elog("Call stack:\n#{$@.join("\n")}", 'core', LEV_0)
163-
else
164-
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3)
165165
end
166166

167167
mod.cleanup

lib/msf/base/simple/exploit.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ def self.exploit_simple(oexploit, opts, &block)
148148
exploit.print_error("Exploit failed: #{e}")
149149
elog("Exploit failed (#{exploit.refname}): #{e}", 'core', LEV_0)
150150

151-
if(e.class.to_s != 'Msf::OptionValidateError')
151+
if e.kind_of?(Msf::OptionValidateError)
152+
dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3)
153+
else
152154
mod.print_error("Call stack:")
153155
e.backtrace.each do |line|
154156
break if line =~ /lib.msf.base.simple.exploit.rb/
155157
mod.print_error(" #{line}")
156158
end
157159
elog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_0)
158-
else
159-
dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3)
160160
end
161161
end
162162

lib/msf/base/simple/post.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ def self.job_run_proc(ctx)
123123
mod.print_error("Post failed: #{e.class} #{e}")
124124
elog("Post failed: #{e.class} #{e}", 'core', LEV_0)
125125

126-
if(e.class.to_s != 'Msf::OptionValidateError')
126+
if e.kind_of?(Msf::OptionValidateError)
127+
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3)
128+
else
127129
mod.print_error("Call stack:")
128130
e.backtrace.each do |line|
129131
break if line =~ /lib.msf.base.simple.post.rb/
130132
mod.print_error(" #{line}")
131133
end
132134
elog("Call stack:\n#{$@.join("\n")}", 'core', LEV_0)
133-
else
134-
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3)
135135
end
136136

137137
mod.cleanup

lib/msf/ui/console/command_dispatcher/auxiliary.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,17 @@ def cmd_run(*args)
120120
print_error("Auxiliary interrupted by the console user")
121121
rescue ::Exception => e
122122
print_error("Auxiliary failed: #{e.class} #{e}")
123-
if(e.class.to_s != 'Msf::OptionValidateError')
123+
elog("Auxiliary failed: #{e.class} #{e}", 'core', LEV_0)
124+
125+
if e.kind_of?(Msf::OptionValidateError)
126+
dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3)
127+
else
124128
print_error("Call stack:")
125129
e.backtrace.each do |line|
126130
break if line =~ /lib.msf.base.simple/
127131
print_error(" #{line}")
128132
end
133+
elog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_0)
129134
end
130135

131136
return false
@@ -152,4 +157,3 @@ def cmd_run_help
152157
end
153158

154159
end end end end
155-

lib/msf/ui/console/command_dispatcher/exploit.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,18 @@ def cmd_exploit(*args)
121121
raise $!
122122
rescue ::Exception => e
123123
print_error("Exploit exception (#{mod.refname}): #{e.class} #{e}")
124-
if(e.class.to_s != 'Msf::OptionValidateError')
124+
125+
elog("Exploit exception (#{mod.refname}): #{e.class} #{e}", 'core', LEV_0)
126+
127+
if e.kind_of?(Msf::OptionValidateError)
128+
dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3)
129+
else
125130
print_error("Call stack:")
126131
e.backtrace.each do |line|
127132
break if line =~ /lib.msf.base.simple/
128133
print_error(" #{line}")
129134
end
135+
elog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_0)
130136
end
131137
end
132138

lib/msf/ui/console/command_dispatcher/post.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,18 @@ def cmd_run(*args)
122122
print_error("Post interrupted by the console user")
123123
rescue ::Exception => e
124124
print_error("Post failed: #{e.class} #{e}")
125-
if (e.class.to_s != 'Msf::OptionValidateError')
125+
126+
elog("Post failed: #{e.class} #{e}", 'core', LEV_0)
127+
128+
if e.kind_of?(Msf::OptionValidateError)
129+
dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3)
130+
else
126131
print_error("Call stack:")
127132
e.backtrace.each do |line|
128133
break if line =~ /lib.msf.base.simple/
129134
print_error(" #{line}")
130135
end
136+
elog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_0)
131137
end
132138

133139
return false
@@ -154,4 +160,3 @@ def cmd_run_help
154160
end
155161

156162
end end end end
157-

0 commit comments

Comments
 (0)