Class: Msf::Util::DotNetDeserialization::Formatters::SoapFormatter::SoapBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/util/dot_net_deserialization/formatters/soap_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ SoapBuilder

Returns a new instance of SoapBuilder.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/msf/util/dot_net_deserialization/formatters/soap_formatter.rb', line 8

def initialize(stream)
  @document = Nokogiri::XML::Document.new
  @root = envelop = node('SOAP-ENV:Envelope', attributes: {
    'xmlns:xsi'              => 'http://www.w3.org/2001/XMLSchema-instance',
    'xmlns:xsd'              => 'http://www.w3.org/2001/XMLSchema',
    'xmlns:SOAP-ENC'         => 'http://schemas.xmlsoap.org/soap/encoding/',
    'xmlns:SOAP-ENV'         => 'http://schemas.xmlsoap.org/soap/envelope/',
    'xmlns:clr'              => 'http://schemas.microsoft.com/soap/encoding/clr/1.0',
    'SOAP-ENV:encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'
  })

  body = node('SOAP-ENV:Body', parent: envelop)

  stream.records.each do |record|
    record_value = record.record_value
    case record.record_type
    when Enums::RecordTypeEnum[:SystemClassWithMembersAndTypes]
      build_class_with_members_and_types(body, record_value)
    when Enums::RecordTypeEnum[:ClassWithMembersAndTypes]
      library = stream.get_object(record_value.library_id)
      build_class_with_members_and_types(body, record_value, library_name: library.library_name)
    end
  end
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



33
34
35
# File 'lib/msf/util/dot_net_deserialization/formatters/soap_formatter.rb', line 33

def root
  @root
end

Instance Method Details

#build_class_with_members_and_types(body, record_value, library_name: Assemblies::VERSIONS['4.0.0.0']['mscorlib']) ⇒ Object (protected)



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/msf/util/dot_net_deserialization/formatters/soap_formatter.rb', line 37

def build_class_with_members_and_types(body, record_value, library_name: Assemblies::VERSIONS['4.0.0.0']['mscorlib'])
  library_name = library_name.to_s if library_name.is_a? Assemblies::StrongName
  ns = "a#{body.children.length + 1}"
  class_node = node("#{ns}:#{record_value.class_info.name.split('.')[-1]}", parent: body, attributes: {
    'id'          => "ref-#{record_value.class_info.obj_id}",
    "xmlns:#{ns}" => "http://schemas.microsoft.com/clr/nsassem/#{record_value.class_info.name.split('.')[0...-1].join('.')}/#{library_name}"
  })
  member_value_nodes(record_value).each do |value_node|
    class_node.add_child value_node
  end

  class_node
end

#member_value_nodes(record_value) ⇒ Object (protected)



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/msf/util/dot_net_deserialization/formatters/soap_formatter.rb', line 51

def member_value_nodes(record_value)
  value_nodes = []
  record_value.class_info.member_names.each_with_index do |name, index|
    binary_type = record_value.member_type_info.binary_type_enums[index].value
    case binary_type
    when Enums::BinaryTypeEnum[:String]
      string_record_value = record_value.member_values[index].record_value
      value_nodes << node(name, content: string_record_value.string, attributes: {
        'id'       => "ref-#{string_record_value.obj_id}",
        'xsi:type' => 'xsd:string',
        'xmlns'    => ''
      })
    else
      raise ::NotImplementedError, "Member value type #{Enums::BinaryTypeEnum.key(binary_type)} is not implemented"
    end
  end

  value_nodes
end

#node(name, attributes: {}, content: nil, parent: nil) ⇒ Object (protected)



71
72
73
74
75
76
77
78
79
80
# File 'lib/msf/util/dot_net_deserialization/formatters/soap_formatter.rb', line 71

def node(name, attributes: {}, content: nil, parent: nil)
  node = Nokogiri::XML::Node.new(name, @document)
  attributes.each_pair do |key, value|
    node[key] = value
  end
  node.content = content unless content.nil?
  parent.add_child node unless parent.nil?

  node
end