diff --git a/lib/msf/ui/console/command_dispatcher/creds.rb b/lib/msf/ui/console/command_dispatcher/creds.rb index b26a89eb47..e726f2cede 100644 --- a/lib/msf/ui/console/command_dispatcher/creds.rb +++ b/lib/msf/ui/console/command_dispatcher/creds.rb @@ -106,8 +106,6 @@ class Creds cmd_creds_help when 'add' creds_add(*args) - when 'export' - creds_export else # then it's not actually a subcommand args.unshift(subcommand) if subcommand @@ -129,9 +127,6 @@ class Creds print_line "Usage - Listing credentials:" print_line " creds [filter options] [address range]" print_line - print_line "Usage - Exporting in JtR format:" - print_line " creds export" - print_line print_line "Usage - Adding credentials:" print_line " creds add uses the following named parameters." { @@ -171,7 +166,9 @@ class Creds print_line print_line "General options" print_line " -h,--help Show this help information" - print_line " -o Send output to a file in csv format" + print_line " -o Send output to a file in csv/jtr (john the ripper) format." + print_line " If file name ends in '.jtr', that format will be used." + print_line " csv by default." print_line " -d,--delete Delete one or more credentials" print_line print_line "Filter options for listing" @@ -534,10 +531,25 @@ class Creds end if output_file.nil? - print_line(tbl.to_s) + print_line(tbl.to_s) else - # create the output file - ::File.open(output_file, "wb") { |f| f.write(tbl.to_csv) } + if output_file.end_with? '.jtr' + hashlist = ::File.open(output_file, "wb") + ['Metasploit::Credential::NonreplayableHash', + 'Metasploit::Credential::PostgresMD5', + 'Metasploit::Credential::NTLMHash'].each do |type| + framework.db.creds(type: type).each do |core| + formatted = hash_to_jtr(core) + unless formatted.nil? + hashlist.puts formatted + end + end + end + hashlist.close + else #csv + # create the output file + ::File.open(output_file, "wb") { |f| f.write(tbl.to_csv) } + end print_status("Wrote creds to #{output_file}") end @@ -567,21 +579,6 @@ class Creds end def creds_export - hashlist = Rex::Quickfile.new("jtr_hashes") - count = 0 - ['Metasploit::Credential::NonreplayableHash', - 'Metasploit::Credential::PostgresMD5', - 'Metasploit::Credential::NTLMHash'].each do |type| - framework.db.creds(type: type).each do |core| - formatted = hash_to_jtr(core) - unless formatted.nil? - count += 1 - hashlist.puts formatted - end - end - end - hashlist.close - print_status("#{count} JtR formatted hashes written to #{hashlist.path}") end end