Module: Msf::DBManager::Import::MetasploitFramework
- Includes:
- Credential, XML, Zip
- Included in:
- Msf::DBManager::Import
- Defined in:
- lib/msf/core/db_manager/import/metasploit_framework.rb
Defined Under Namespace
Modules: Credential, XML, Zip
Constant Summary
Constants included from XML
XML::MSF_WEB_PAGE_TEXT_ELEMENT_NAMES, XML::MSF_WEB_TEXT_ELEMENT_NAMES, XML::MSF_WEB_VULN_TEXT_ELEMENT_NAMES
Instance Method Summary collapse
-
#nils_for_nulls(str) ⇒ Object
Convert the string “NULL” to actual nil.
- #unserialize_object(xml_elem, allow_yaml = false) ⇒ Object
Methods included from Zip
#import_msf_collateral, #import_msf_zip, #is_child_of?, #parse_zip_host, #parse_zip_loot, #parse_zip_report, #parse_zip_task
Methods included from XML
#import_msf_file, #import_msf_note_element, #import_msf_web_form_element, #import_msf_web_page_element, #import_msf_web_vuln_element, #import_msf_xml
Methods included from Credential
#import_msf_cred_dump, #import_msf_cred_dump_zip, #import_msf_pwdump
Instance Method Details
#nils_for_nulls(str) ⇒ Object
Convert the string “NULL” to actual nil
14 15 16 |
# File 'lib/msf/core/db_manager/import/metasploit_framework.rb', line 14 def nils_for_nulls(str) str == "NULL" ? nil : str end |
#unserialize_object(xml_elem, allow_yaml = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/msf/core/db_manager/import/metasploit_framework.rb', line 18 def unserialize_object(xml_elem, allow_yaml = false) return nil unless xml_elem string = xml_elem.text.to_s.strip return string unless string.is_a?(String) return nil if (string.empty? || string.nil?) begin # Validate that it is properly formed base64 first if string.gsub(/\s+/, '') =~ /^([a-z0-9A-Z\+\/=]+)$/ marshalled_data = $1.unpack("m")[0] # Only attempt Marshal deserialization if the decoded data # starts with the Marshal version header (4.8). Otherwise # treat it as a plain string that happened to be base64-like. if Msf::DBManager::Import::MarshalValidator.marshalled_data?(marshalled_data) Msf::DBManager::Import::MarshalValidator.safe_load(marshalled_data, permitted_classes: %w[Time]) else string end else if allow_yaml begin YAML.safe_load(string, permitted_classes: MetasploitDataModels::YAML::PERMITTED_CLASSES) rescue dlog("Badly formatted YAML: '#{string}'") string end else string end end rescue Msf::DBManager::Import::MarshalValidationError => e # Marshal validation failure indicates a potentially tampered export # file — abort the entire import rather than silently continuing. elem_name = xml_elem.respond_to?(:name) ? xml_elem.name : 'unknown' elem_path = xml_elem.respond_to?(:path) ? xml_elem.path : elem_name preview = string.length > 80 ? "#{string[0, 80]}..." : string raise Msf::DBImportError, "Unsafe deserialization blocked in <#{elem_name}> (#{elem_path}): " \ "#{e.} — base64 value: #{preview}" rescue ::Exception => e dlog("Failed to unserialize object: #{e.class} #{e.}") if allow_yaml YAML.safe_load(string, permitted_classes: MetasploitDataModels::YAML::PERMITTED_CLASSES) rescue string else string end end end |