Created
February 24, 2021 21:53
-
-
Save deoxykev/7a48b566ea0eb72d2ecb302fb02fd044 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#Requires -RunAsAdministrator | |
# Creates split VPN tunnel using routing rules | |
# To find this, run: Get-NetAdapter | select InterfaceDescription | |
# And paste the one that corresponds to your VPN client | |
$VPNInterfaceDescription = "PANGP Virtual Ethernet Adapter" | |
# This is the subnet you want to route to the VPN; all other traffic will be through local connection | |
$SplitVPNSubnet = "10.2.0.0/16" | |
$VPNInterfaceIndex = ( | |
Get-NetAdapter -ErrorAction Stop | ? { | |
$_.InterfaceDescription -eq $VPNInterfaceDescription | |
}).ifIndex | |
try { | |
$VPNGatewayIPv4 = [String]( | |
Get-NetIPConfiguration -ErrorAction Stop -InterfaceIndex $VPNInterfaceIndex | |
).IPv4Address | |
} catch { | |
Write-Host "[-] Could not find VPN default gateway address, is VPN on?" | |
exit 0 | |
} | |
try { | |
$SNIArgs = @{ | |
InterfaceIndex = $VPNInterfaceIndex | |
InterfaceMetric = 51 | |
} | |
Set-NetIPInterface @SNIArgs | |
$SNArgs = @{ | |
DestinationPrefix = "0.0.0.0/0" | |
RouteMetric = 100 | |
InterfaceIndex = $VPNInterfaceIndex | |
ErrorAction = "Ignore" | |
} | |
if (! $(Get-NetRoute @SNArgs)){ | |
Set-NetRoute @SNArgs | |
} else { | |
Write-Host "skipping set netroute" | |
} | |
$NNArgs = @{ | |
DestinationPrefix = $SplitVPNSubnet | |
RouteMetric = 50 | |
InterfaceIndex = $VPNInterfaceIndex | |
NextHop = $VPNGatewayIPv4 | |
ErrorAction = "Ignore" | |
} | |
if (! $(Get-NetRoute @NNArgs)){ | |
New-NetRoute @NNArgs | |
} else { | |
Write-Host "skipping new netroute" | |
} | |
} catch { | |
Write-host "[-] Could not create split VPN tunnel, are you administrator?" | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment