Skip to content

Commit a1d11f6

Browse files
committed
WOW64FS Redirection Bypass
1 parent 8104e9b commit a1d11f6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

LabTech.psm1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ If ($env:PROCESSOR_ARCHITEW6432 -match '64' -and [IntPtr]::Size -ne 8) {
4949
$MethodSignature = @"
5050
[DllImport("kernel32.dll", SetLastError=true)]
5151
public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
52-
public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
5352
"@
54-
$Kernel32 = Add-Type -MemberDefinition $MethodSignature -Namespace "Kernel32" -Passthru
55-
$ptr = [IntPtr]::Zero
56-
$Result = $Kernel32::Wow64DisableWow64FsRedirection([ref]$ptr)
53+
$Kernel32 = Add-Type -MemberDefinition $MethodSignature -Namespace "Kernel32" -Passthru -Name DisableWow64Redirection
54+
[ref]$ptr = New-Object System.IntPtr
55+
$Result = $Kernel32::Wow64DisableWow64FsRedirection($ptr)
5756
# Now you can call 64-bit Powershell from system32
5857
$pshell="${env:windir}\System32\WindowsPowershell\v1.0\powershell.exe"
5958
}
@@ -65,7 +64,13 @@ public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
6564
&"$pshell" -NonInteractive -NoProfile $myInvocation.MyCommand
6665
}
6766
If ($RevertFSRedirection -eq $True) {
68-
$Result = $Kernel32::Wow64RevertWow64FsRedirection($ptr)
67+
$MethodSignature = @"
68+
[DllImport("kernel32.dll", SetLastError=true)]
69+
public static extern bool Wow64RevertWow64FsRedirection(ref IntPtr ptr);
70+
"@
71+
$Kernel32Default = Add-Type -MemberDefinition $MethodSignature -Namespace "Kernel32" -Passthru -Name Wow64RevertWow64FsRedirection
72+
[ref]$defaultptr = New-Object System.IntPtr
73+
$Result = $Kernel32Default::Wow64RevertWow64FsRedirection($defaultptr)
6974
}
7075
Write-Warning 'Exiting 64-bit session. Module will only remain loaded in native 64-bit PowerShell environment.'
7176
Exit $lastexitcode

0 commit comments

Comments
 (0)