Skip to content

Instantly share code, notes, and snippets.

@DanielRTeixeira
Forked from nicholasmckinney/PacHost.ps1
Created November 2, 2017 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielRTeixeira/d07ed423affee222f775d4f732e952c4 to your computer and use it in GitHub Desktop.
Save DanielRTeixeira/d07ed423affee222f775d4f732e952c4 to your computer and use it in GitHub Desktop.
function Start-PACFileHosting()
{
# Example PAC File Hosting
# Pattern after http://obscuresecurity.blogspot.com/2014/05/dirty-powershell-webserver.html
# example: http://localhost:8083/i.pac
# Be Certain Line 19 matches your Interceptor Config
Start-Job -ScriptBlock {
$Hso = New-Object Net.HttpListener
$Hso.Prefixes.Add("http://+:8083/")
$Hso.Start()
While ($Hso.IsListening) {
$HC = $Hso.GetContext()
$HRes = $HC.Response
$HRes.Headers.Add("Content-Type","text/plain")
$Buf = [Text.Encoding]::UTF8.GetBytes('function FindProxyForURL(url, host){
// Intercepted Domains
if (shExpMatch(url, "https://www.google.com/*"))
return "PROXY 127.0.0.1:8081";
// DEFAULT RULE: All other traffic, use below proxies, in fail-over order.
return "DIRECT";
}')
$HRes.ContentLength64 = $Buf.Length
$HRes.OutputStream.Write($Buf,0,$Buf.Length)
$HRes.Close()
}
$Hso.Stop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment