Skip to content

Commit 553030b

Browse files
committed
Land rapid7#4473 - Log backtraces by default
2 parents d248cad + 6444d8b commit 553030b

File tree

7 files changed

+52
-21
lines changed

7 files changed

+52
-21
lines changed

lib/msf/base/simple/auxiliary.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,19 @@ def self.job_run_proc(ctx)
151151
rescue ::Exception => e
152152
mod.error = e
153153
mod.print_error("Auxiliary failed: #{e.class} #{e}")
154-
if(e.class.to_s != 'Msf::OptionValidateError')
154+
elog("Auxiliary failed: #{e.class} #{e}", 'core', LEV_0)
155+
156+
if e.kind_of?(Msf::OptionValidateError)
157+
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3)
158+
else
155159
mod.print_error("Call stack:")
156160
e.backtrace.each do |line|
157161
break if line =~ /lib.msf.base.simple.auxiliary.rb/
158162
mod.print_error(" #{line}")
159163
end
164+
elog("Call stack:\n#{$@.join("\n")}", 'core', LEV_0)
160165
end
161166

162-
elog("Auxiliary failed: #{e.class} #{e}", 'core', LEV_0)
163-
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3)
164-
165167
mod.cleanup
166168

167169
return
@@ -182,4 +184,3 @@ def self.job_cleanup_proc(ctx)
182184

183185
end
184186
end
185-

lib/msf/base/simple/exploit.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,17 @@ def self.exploit_simple(oexploit, opts, &block)
147147
exploit.error = e
148148
exploit.print_error("Exploit failed: #{e}")
149149
elog("Exploit failed (#{exploit.refname}): #{e}", 'core', LEV_0)
150-
dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3)
150+
151+
if e.kind_of?(Msf::OptionValidateError)
152+
dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3)
153+
else
154+
mod.print_error("Call stack:")
155+
e.backtrace.each do |line|
156+
break if line =~ /lib.msf.base.simple.exploit.rb/
157+
mod.print_error(" #{line}")
158+
end
159+
elog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_0)
160+
end
151161
end
152162

153163
return driver.session if driver
@@ -199,4 +209,3 @@ def check_simple(opts)
199209

200210
end
201211
end
202-

lib/msf/base/simple/post.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,19 @@ def self.job_run_proc(ctx)
121121
rescue ::Exception => e
122122
mod.error = e
123123
mod.print_error("Post failed: #{e.class} #{e}")
124-
if(e.class.to_s != 'Msf::OptionValidateError')
124+
elog("Post failed: #{e.class} #{e}", 'core', LEV_0)
125+
126+
if e.kind_of?(Msf::OptionValidateError)
127+
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3)
128+
else
125129
mod.print_error("Call stack:")
126130
e.backtrace.each do |line|
127131
break if line =~ /lib.msf.base.simple.post.rb/
128132
mod.print_error(" #{line}")
129133
end
134+
elog("Call stack:\n#{$@.join("\n")}", 'core', LEV_0)
130135
end
131136

132-
elog("Post failed: #{e.class} #{e}", 'core', LEV_0)
133-
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3)
134-
135137
mod.cleanup
136138

137139
return
@@ -154,4 +156,3 @@ def self.job_cleanup_proc(ctx)
154156

155157
end
156158
end
157-

lib/msf/core/exploit_driver.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,20 @@ def job_run_proc(ctx)
271271
exploit.fail_reason = Msf::Exploit::Failure::Unknown
272272
end
273273

274+
elog("Exploit failed (#{exploit.refname}): #{msg}", 'core', LEV_0)
275+
274276
if exploit.fail_reason == Msf::Exploit::Failure::Unknown
275277
exploit.print_error("Exploit failed: #{msg}")
278+
exploit.print_error("Call stack:")
279+
e.backtrace.each do |line|
280+
break if line =~ /lib.msf.base.core.exploit_driver.rb/
281+
exploit.print_error(" #{line}")
282+
end
283+
elog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_0)
276284
else
277285
exploit.print_error("Exploit failed [#{exploit.fail_reason}]: #{msg}")
286+
dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3)
278287
end
279-
280-
elog("Exploit failed (#{exploit.refname}): #{msg}", 'core', LEV_0)
281-
dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3)
282288
end
283289

284290
# Record the error to various places
@@ -329,4 +335,3 @@ def job_cleanup_proc(ctx)
329335
end
330336

331337
end
332-

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)