Skip to content

Instantly share code, notes, and snippets.

@zr0n
Created December 25, 2025 14:13
Show Gist options
  • Select an option

  • Save zr0n/59ea62e94d21fa1720865467ed7e233d to your computer and use it in GitHub Desktop.

Select an option

Save zr0n/59ea62e94d21fa1720865467ed7e233d to your computer and use it in GitHub Desktop.
Burp Proxy
# configure-system-proxy.ps1 - Configura proxy a nível de SISTEMA e aplica imediatamente.
# Execute como Administrador.
$ProxyServer = "192.168.0.41:8080"
$CertURL = "http://$ProxyServer/cert"
Write-Host "[*] Configurando proxy de sistema para $ProxyServer..." -ForegroundColor Cyan
# 1. CONFIGURAÇÃO DO REGISTRO (SISTEMA E USUÁRIO ATUAL)
Write-Host "[1] Configurando chaves de registro do proxy..."
# Para TODOS OS USUÁRIOS (HKLM - Sistema)
$sysPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path $sysPath -Name ProxyEnable -Value 1 -Type DWord -Force
Set-ItemProperty -Path $sysPath -Name ProxyServer -Value $ProxyServer -Force
Set-ItemProperty -Path $sysPath -Name ProxyOverride -Valu.e "<local>" -Force
# Para o USUÁRIO ATUAL (HKCU - Sessão)
$userPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path $userPath -Name ProxyEnable -Value 1 -Type DWord -Force
Set-ItemProperty -Path $userPath -Name ProxyServer -Value $ProxyServer -Force
Set-ItemProperty -Path $userPath -Name ProxyOverride -Value "<local>" -Force
# 2. CONFIGURAR PROXY VIA WINHTTP (USADO POR ALGUNS APLICATIVOS DO SISTEMA)
Write-Host "[2] Configurando proxy WinHTTP (netsh)..." -ForegroundColor Cyan
netsh winhttp set proxy $ProxyServer "<local>"
# 3. INSTALAR CERTIFICADO (Igual ao anterior, essencial para HTTPS)
Write-Host "[3] Instalando certificado CA do Burp..." -ForegroundColor Cyan
try {
$CertPath = "$env:TEMP\burp_ca.der"
Invoke-WebRequest -Uri $CertURL -OutFile $CertPath -ErrorAction Stop
$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($CertPath)
$Store = New-Object System.Security.Cryptography.X509Certificates.X509Store("Root", "LocalMachine")
$Store.Open("ReadWrite")
$Store.Add($Cert)
$Store.Close()
Remove-Item $CertPath -Force
Write-Host " > Certificado instalado com sucesso." -ForegroundColor Green
} catch {
Write-Host " [!] Atenção: Não foi possível baixar/instalar o certificado." -ForegroundColor Yellow
Write-Host " O proxy funcionará, mas sites HTTPS mostrarão erros." -ForegroundColor Yellow
}
# 4. FORÇAR RECARGA DAS CONFIGURAÇÕES DE REDE
Write-Host "[4] Forçando aplicação das novas configurações..." -ForegroundColor Cyan
# A) Notificar processos que as configurações de proxy mudaram
# Isso afeta navegadores abertos (Explorer, Chrome, Edge) sem precisar reiniciar
$signature = @'
[DllImport("wininet.dll", SetLastError = true, CharSet=CharSet.Auto)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
'@
$interop = Add-Type -MemberDefinition $signature -Name "Wininet" -Namespace "Win32" -PassThru
$INTERNET_OPTION_SETTINGS_CHANGED = 39
$INTERNET_OPTION_REFRESH = 37
$null = $interop::InternetSetOption([IntPtr]::Zero, $INTERNET_OPTION_SETTINGS_CHANGED, [IntPtr]::Zero, 0)
$null = $interop::InternetSetOption([IntPtr]::Zero, $INTERNET_OPTION_REFRESH, [IntPtr]::Zero, 0)
# B) Liberar e renovar cache de DNS (evita problemas de resolução via proxy)
ipconfig /flushdns | Out-Null
Write-Host " > Sistema notificado. Configurações aplicadas." -ForegroundColor Green
# 5. VERIFICAÇÃO FINAL
Write-Host "`n[*] VERIFICAÇÃO MANUAL NECESSÁRIA" -ForegroundColor Cyan
Write-Host " Abra o Painel de Controle do Windows e siga:" -ForegroundColor White
Write-Host " 'Rede e Internet' -> 'Opções da Internet' -> 'Conexões' -> 'Configurações da LAN'" -ForegroundColor White
Write-Host "`n O proxy configurado deve aparecer ali: $ProxyServer" -ForegroundColor White
Write-Host "`n[*] Para testar:" -ForegroundColor Cyan
Write-Host " 1. Reinicie o Chrome/Edge (se estava aberto)" -ForegroundColor Yellow
Write-Host " 2. Acesse 'http://burp'. Deve mostrar a página do Burp." -ForegroundColor Yellow
Write-Host " 3. Acesse qualquer site. Deve aparecer no 'HTTP History' do Burp." -ForegroundColor Yellow
Write-Host "`n[*] Configuração de SISTEMA concluída." -ForegroundColor Green
# revert-system-proxy.ps1 - Reverte proxy de sistema + WinHTTP e remove CA do Burp (se existir).
# Execute como Administrador.
$ProxyServer = "127.0.0.1:8080" # mesmo do script original (para referência)
$ExpectedCertUrl = "http://$ProxyServer/cert" # usado só como referência (não baixa nada)
$BurpSubjectHints = @("PortSwigger", "Burp", "CA") # heurística para achar certificado, se necessário
Write-Host "[*] Revertendo configurações de proxy e certificado..." -ForegroundColor Cyan
# 1) Reverter proxy em HKLM (Policies) - SISTEMA
Write-Host "[1] Limpando proxy em HKLM (Policies)..." -ForegroundColor Cyan
$sysPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings"
if (Test-Path $sysPath) {
try {
# Se existirem, remove valores; se não, ignora
foreach ($name in @("ProxyEnable","ProxyServer","ProxyOverride")) {
if (Get-ItemProperty -Path $sysPath -Name $name -ErrorAction SilentlyContinue) {
Remove-ItemProperty -Path $sysPath -Name $name -ErrorAction SilentlyContinue
}
}
Write-Host " > HKLM Policies limpo." -ForegroundColor Green
} catch {
Write-Host " [!] Falha ao limpar HKLM Policies: $($_.Exception.Message)" -ForegroundColor Yellow
}
} else {
Write-Host " > HKLM Policies não existe. OK." -ForegroundColor Green
}
# 2) Reverter proxy em HKCU - USUÁRIO ATUAL
Write-Host "[2] Desabilitando proxy em HKCU (usuário atual)..." -ForegroundColor Cyan
$userPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
try {
# ProxyEnable=0 e limpar strings para evitar residual
Set-ItemProperty -Path $userPath -Name ProxyEnable -Value 0 -Type DWord -Force
foreach ($name in @("ProxyServer","ProxyOverride")) {
if (Get-ItemProperty -Path $userPath -Name $name -ErrorAction SilentlyContinue) {
Remove-ItemProperty -Path $userPath -Name $name -ErrorAction SilentlyContinue
}
}
Write-Host " > HKCU proxy desabilitado." -ForegroundColor Green
} catch {
Write-Host " [!] Falha ao ajustar HKCU: $($_.Exception.Message)" -ForegroundColor Yellow
}
# 3) Resetar proxy do WinHTTP
Write-Host "[3] Resetando proxy WinHTTP (netsh)..." -ForegroundColor Cyan
try {
netsh winhttp reset proxy | Out-Null
Write-Host " > WinHTTP proxy resetado." -ForegroundColor Green
} catch {
Write-Host " [!] Falha ao resetar WinHTTP: $($_.Exception.Message)" -ForegroundColor Yellow
}
# 4) Remover certificado CA do Burp do LocalMachine\Root
Write-Host "[4] Removendo certificado CA do Burp (LocalMachine\Root), se existir..." -ForegroundColor Cyan
function Remove-CertByThumbprint {
param(
[Parameter(Mandatory=$true)][string]$Thumbprint
)
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("Root", "LocalMachine")
$store.Open("ReadWrite")
try {
$match = $store.Certificates | Where-Object { $_.Thumbprint -eq $Thumbprint }
if ($match) {
foreach ($c in $match) { $store.Remove($c) }
return $true
}
return $false
} finally {
$store.Close()
}
}
function Find-BurpCandidates {
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("Root", "LocalMachine")
$store.Open("ReadOnly")
try {
$certs = $store.Certificates
# Heurística: Subject/Issuer contendo termos comuns de Burp/PortSwigger
$candidates = $certs | Where-Object {
$s = ($_.Subject + " " + $_.Issuer)
($BurpSubjectHints | Where-Object { $s -match [regex]::Escape($_) }).Count -gt 0
}
return $candidates
} finally {
$store.Close()
}
}
try {
$cands = Find-BurpCandidates
if (-not $cands -or $cands.Count -eq 0) {
Write-Host " > Nenhum candidato óbvio de Burp encontrado no Root (LocalMachine)." -ForegroundColor Green
} else {
Write-Host " > Encontrados $($cands.Count) candidato(s). Removendo..." -ForegroundColor Yellow
foreach ($c in $cands) {
$tp = $c.Thumbprint
$sub = $c.Subject
$iss = $c.Issuer
if (Remove-CertByThumbprint -Thumbprint $tp) {
Write-Host " - Removido: $sub | Issuer: $iss | Thumbprint: $tp" -ForegroundColor Green
} else {
Write-Host " [!] Não consegui remover (talvez já removido): Thumbprint $tp" -ForegroundColor Yellow
}
}
}
} catch {
Write-Host " [!] Falha ao procurar/remover certificado: $($_.Exception.Message)" -ForegroundColor Yellow
}
# 5) Forçar refresh do WinINet e DNS
Write-Host "[5] Forçando refresh de configurações (WinINet) e limpando DNS..." -ForegroundColor Cyan
try {
$signature = @'
[DllImport("wininet.dll", SetLastError = true, CharSet=CharSet.Auto)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
'@
$interop = Add-Type -MemberDefinition $signature -Name "Wininet" -Namespace "Win32" -PassThru -ErrorAction SilentlyContinue
$INTERNET_OPTION_SETTINGS_CHANGED = 39
$INTERNET_OPTION_REFRESH = 37
$null = $interop::InternetSetOption([IntPtr]::Zero, $INTERNET_OPTION_SETTINGS_CHANGED, [IntPtr]::Zero, 0)
$null = $interop::InternetSetOption([IntPtr]::Zero, $INTERNET_OPTION_REFRESH, [IntPtr]::Zero, 0)
ipconfig /flushdns | Out-Null
Write-Host " > Refresh aplicado e DNS limpo." -ForegroundColor Green
} catch {
Write-Host " [!] Falha no refresh/DNS: $($_.Exception.Message)" -ForegroundColor Yellow
}
Write-Host "`n[*] Concluído." -ForegroundColor Green
Write-Host " - Verifique em: Painel de Controle -> Opções da Internet -> Conexões -> Configurações da LAN" -ForegroundColor White
Write-Host " - WinHTTP: execute 'netsh winhttp show proxy' (deve estar 'Direct access')" -ForegroundColor White
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment