Skip to content

Commit 0113cbd

Browse files
committed
Nokogiri::XML::Builder instead
1 parent 9a2696a commit 0113cbd

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

modules/auxiliary/admin/upnp/soap_portmapping.rb

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
##
66

77
require 'msf/core'
8+
require 'nokogiri'
89

910
class Metasploit3 < Msf::Auxiliary
1011
include Msf::Exploit::Remote::HttpClient
@@ -80,35 +81,39 @@ def soap_action
8081
@soap_action ||= action.opts['SOAP_ACTION']
8182
end
8283

83-
def run
84-
content = "<?xml version=\"1.0\"?>"
85-
content << "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
86-
content << "<SOAP-ENV:Body>"
87-
content << "<m:#{soap_action} xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\">"
88-
case action.name
89-
when 'ADD'
90-
content << "<NewPortMappingDescription>#{Rex::Text.rand_text_alpha(8)}</NewPortMappingDescription>"
91-
content << "<NewLeaseDuration>#{lease_duration}</NewLeaseDuration>"
92-
content << "<NewInternalClient>#{internal_client}</NewInternalClient>"
93-
content << "<NewEnabled>1</NewEnabled>"
94-
content << "<NewExternalPort>#{external_port}</NewExternalPort>"
95-
content << "<NewRemoteHost>#{external_client}</NewRemoteHost>"
96-
content << "<NewProtocol>#{protocol}</NewProtocol>"
97-
content << "<NewInternalPort>#{internal_port}</NewInternalPort>"
98-
when 'DELETE'
99-
content << "<NewExternalPort>#{external_port}</NewExternalPort>"
100-
content << "<NewRemoteHost>#{external_client}</NewRemoteHost>"
101-
content << "<NewProtocol>#{protocol}</NewProtocol>"
84+
def build_soap
85+
builder = ::Nokogiri::XML::Builder.new do |xml|
86+
xml['SOAP-ENV'].Envelope("xmlns:SOAP-ENV" => 'http://schemas.xmlsoap.org/soap/envelope', 'SOAP-ENV:encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/') do
87+
xml['SOAP-ENV'].Body do
88+
xml['m'].send(soap_action, 'xmlns:m' => 'urn:schemas-upnp-org:service:WANIPConnection:1') do
89+
case action.name
90+
when 'ADD'
91+
xml.NewPortMappingDescription(Rex::Text.rand_text_alpha(8)) { xml.parent.namespace = nil }
92+
xml.NewLeaseDuration(lease_duration) { xml.parent.namespace = nil }
93+
xml.NewInternalClient(internal_client) { xml.parent.namespace = nil }
94+
xml.NewEnabled(1) { xml.parent.namespace = nil }
95+
xml.NewExternalPort(external_port) { xml.parent.namespace = nil }
96+
xml.NewRemoteHost(external_client) { xml.parent.namespace = nil }
97+
xml.NewProtocol(protocol) { xml.parent.namespace = nil }
98+
xml.NewInternalPort(internal_port) { xml.parent.namespace = nil }
99+
when 'DELETE'
100+
xml.NewExternalPort(external_port) { xml.parent.namespace = nil }
101+
xml.NewRemoteHost(external_client) { xml.parent.namespace = nil }
102+
xml.NewProtocol(protocol) { xml.parent.namespace = nil }
103+
end
104+
end
105+
end
106+
end
102107
end
103-
content << "</m:#{soap_action}>"
104-
content << "</SOAP-ENV:Body>"
105-
content << "</SOAP-ENV:Envelope>"
108+
builder.to_xml
109+
end
106110

111+
def run
107112
res = send_request_cgi(
108113
'uri' => normalize_uri(target_uri.path),
109114
'method' => 'POST',
110115
'content-type' => 'text/xml;charset="utf-8"',
111-
'data' => content,
116+
'data' => build_soap,
112117
'headers' => {
113118
'SoapAction' => "urn:schemas-upnp-org:service:WANIPConnection:1##{soap_action}"
114119
}

0 commit comments

Comments
 (0)