Skip to content

Commit 1f7ad1c

Browse files
committed
unserialize_object -> Msf::DBManager::Import::MetasploitFramework
MSP-11124
1 parent 1aca55b commit 1f7ad1c

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

lib/msf/core/db_manager/import.rb

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -436,37 +436,6 @@ def service_name_map(proto)
436436
end
437437
end
438438

439-
def unserialize_object(xml_elem, allow_yaml = false)
440-
return nil unless xml_elem
441-
string = xml_elem.text.to_s.strip
442-
return string unless string.is_a?(String)
443-
return nil if (string.empty? || string.nil?)
444-
445-
begin
446-
# Validate that it is properly formed base64 first
447-
if string.gsub(/\s+/, '') =~ /^([a-z0-9A-Z\+\/=]+)$/
448-
Marshal.load($1.unpack("m")[0])
449-
else
450-
if allow_yaml
451-
begin
452-
YAML.load(string)
453-
rescue
454-
dlog("Badly formatted YAML: '#{string}'")
455-
string
456-
end
457-
else
458-
string
459-
end
460-
end
461-
rescue ::Exception => e
462-
if allow_yaml
463-
YAML.load(string) rescue string
464-
else
465-
string
466-
end
467-
end
468-
end
469-
470439
# Boils down the validate_import_file to a boolean
471440
def validate_import_file(data)
472441
begin

lib/msf/core/db_manager/import/metasploit_framework.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,35 @@ module Msf::DBManager::Import::MetasploitFramework
1111
def nils_for_nulls(str)
1212
str == "NULL" ? nil : str
1313
end
14+
15+
def unserialize_object(xml_elem, allow_yaml = false)
16+
return nil unless xml_elem
17+
string = xml_elem.text.to_s.strip
18+
return string unless string.is_a?(String)
19+
return nil if (string.empty? || string.nil?)
20+
21+
begin
22+
# Validate that it is properly formed base64 first
23+
if string.gsub(/\s+/, '') =~ /^([a-z0-9A-Z\+\/=]+)$/
24+
Marshal.load($1.unpack("m")[0])
25+
else
26+
if allow_yaml
27+
begin
28+
YAML.load(string)
29+
rescue
30+
dlog("Badly formatted YAML: '#{string}'")
31+
string
32+
end
33+
else
34+
string
35+
end
36+
end
37+
rescue ::Exception => e
38+
if allow_yaml
39+
YAML.load(string) rescue string
40+
else
41+
string
42+
end
43+
end
44+
end
1445
end

0 commit comments

Comments
 (0)