diff --git a/lib/msf/core/db.rb b/lib/msf/core/db.rb index a0e641b888..110bfd836b 100644 --- a/lib/msf/core/db.rb +++ b/lib/msf/core/db.rb @@ -2047,6 +2047,7 @@ class DBManager data = args[:data] wspace = args[:wspace] || workspace bl = validate_ips(args[:blacklist]) ? args[:blacklist].split : [] + last_host = nil addr = nil port = nil @@ -2088,7 +2089,8 @@ class DBManager if bl.include? addr next else - yield(:address,addr) if block + yield(:address,addr) if block and addr != last_host + last_host = addr end cred_info = { diff --git a/lib/msf/core/db_export.rb b/lib/msf/core/db_export.rb index e445144087..e245c316f4 100644 --- a/lib/msf/core/db_export.rb +++ b/lib/msf/core/db_export.rb @@ -75,6 +75,12 @@ class Export return sz end + # Converts binary and whitespace characters to a hex notation. + def ascii_safe_hex(str) + str.gsub!(/([\x00-\x20\x80-\xFF])/){ |x| "\\x%.2x" % x.unpack("C*")[0] } + return str + end + # Formats credentials according to their type, and writes it out to the # supplied report file. Note for reimporting: Blank values are def write_credentials(ptype,creds,report_file) @@ -106,8 +112,8 @@ class Export end else "text" data.each do |c| - user = (c.user.nil? || c.user.empty?) ? "" : c.user - pass = (c.pass.nil? || c.pass.empty?) ? "" : c.pass + user = (c.user.nil? || c.user.empty?) ? "" : ascii_safe_hex(c.user) + pass = (c.pass.nil? || c.pass.empty?) ? "" : ascii_safe_hex(c.pass) report_file.write "%s %s\n" % [user,pass] end end @@ -136,7 +142,7 @@ class Export next unless host_allowed?(cred.service.host.address) # Skip anything that's not associated with a specific host and port next unless (cred.service && cred.service.host && cred.service.host.address && cred.service.port) - # Skip anything that's not active. + # TODO: Toggle active/all next unless cred.active svc = "%s:%d/%s (%s)" % [cred.service.host.address,cred.service.port,cred.service.proto,cred.service.name] case cred.ptype diff --git a/lib/msf/ui/console/command_dispatcher/db.rb b/lib/msf/ui/console/command_dispatcher/db.rb index 50984cbd08..205c5fdbca 100644 --- a/lib/msf/ui/console/command_dispatcher/db.rb +++ b/lib/msf/ui/console/command_dispatcher/db.rb @@ -1157,12 +1157,12 @@ class Db export_formats = %W{xml pwdump} format = 'xml' output = nil - + while (arg = args.shift) case arg when '-h','--help' print_line("Usage:") - print_line(" db_export -f [filename]") + print_line(" db_export -f [-a] [filename]") print_line(" Format can be one of: #{export_formats.join(", ")}") when '-f','--format' format = args.shift.to_s.downcase @@ -1178,6 +1178,7 @@ class Db if not export_formats.include?(format) print_error("Unsupported file format: #{format}") + print_error("Unsupported file format: '#{format}'. Must be one of: #{export_formats.join(", ")}") return end