* Conoscenza del computer >> Software >  >> LinkedIn

Autenticazione proxy: metodi, protocolli e configurazione (Basic, NTLM, Kerberos)

Un proxy che richiede autenticazione impedisce accessi non autorizzati e abilita accounting, policy per utente/gruppo, audit. Ecco i metodi standard, come funzionano "sotto il cofano" e come configurarli.

Classificazione metodi

MetodoStandardSicurezzaCasi d'usoSupporto client
Nessuna (Transparent/Open)-NessunaCaptive portal, filtro obbligatorio ISP/azienda, caching trasparenteTutti (intercettazione L3/L4)
IP Allowlist (Transparent auth)-Bassa (IP spoofable)Server, device IoT, subnet noteNessuna config client
Basic Auth (RFC 7617)HTTP 407 Proxy-Authenticate: BasicMedia (credenziali in Base64 = chiaro se no TLS)Semplice, compatibilità universale, script, tool CLITutti browser, curl, wget, librerie HTTP
Digest Auth (RFC 7616)HTTP 407 Proxy-Authenticate: DigestMedia-Alta (challenge-response, no password in chiaro, ma replay possible se no nonce timeout)Legacy, evita Basic su HTTPBrowser, curl, wget, alcune librerie
NTLM (NT LAN Manager)Microsoft proprietario (MS-NLMP)Alta (challenge-response, hash NTLMv2, session key)Ambienti Active Directory, Windows Integrated AuthIE, Edge, Chrome, Firefox (con config), app Windows (WinHTTP, WinINet)
Kerberos (SPNEGO/GSS-API)RFC 4178, RFC 4559 (SPNEGO)Molto Alta (ticket, mutual auth, delegation, no password hash in rete)Enterprise AD, Single Sign-On, delegation, high securityBrowser (SPNEGO), curl (--negotiate), librerie GSS-API, Java, .NET
OAuth 2.0 / OIDC / Bearer TokenRFC 6750, RFC 7662Alta (token short-lived, scope, revocabile)Proxy moderni, API Gateway, Zero Trust, cloud (AWS, Azure, GCP)App custom, browser (redirect), CLI (device flow)
Client Certificate (mTLS)TLS 1.2/1.3Molto Alta (PKI, non ripudiabilità, mutual auth)High security, device auth, Zero Trust, APIBrowser (import cert), curl (--cert), librerie TLS

Flusso HTTP Proxy Authentication (RFC 7235)

CLIENT → PROXY: GET https://example.com/ HTTP/1.1
                 Host: example.com

PROXY → CLIENT: HTTP/1.1 407 Proxy Authentication Required
                 Proxy-Authenticate: Basic realm="Corporate Proxy"
                 Proxy-Authenticate: NTLM
                 Proxy-Authenticate: Negotiate

CLIENT → PROXY: GET https://example.com/ HTTP/1.1
                 Host: example.com
                 Proxy-Authorization: Basic dXNlcjpwYXNz  (Base64 user:pass)
                 # OPPURE
                 Proxy-Authorization: NTLM TlRMTVNTUAABAAA...
                 # OPPURE (Kerberos SPNEGO)
                 Proxy-Authorization: Negotiate YIIGawYGKwYBBQUCoIIGXzCCBlug...

PROXY → CLIENT: HTTP/1.1 200 OK (se auth ok) + Connessione al target

Basic Authentication: semplice ma insicuro su HTTP

  • Credenziali: Base64(username:password) → Facilmente decodificabile
  • OBBLIGATORIO HTTPS end-to-end (Client ↔ Proxy) per non esporre credenziali
  • Proxy deve validare contro: File htpasswd, LDAP, AD, RADIUS, Database, PAM
  • Config Squid: auth_param basic program /usr/lib/squid/basic_ldap_auth -b "ou=users,dc=corp" -f "sAMAccountName=%s" -h ldap.corp
  • Nessun mutual auth, nessun replay protection, nessun delegation.

NTLM: Challenge-Response Microsoft

  1. Client → Proxy: Proxy-Authorization: NTLM (flags, workstation, domain)
  2. Proxy → Client: Proxy-Authenticate: NTLM (8-byte server challenge, target info, flags)
  3. Client → Proxy: Proxy-Authorization: NTLM (NTLMv2 response: HMAC-MD5(user domain password, challenge + client challenge + timestamp + target info), session key derivata)
  4. Proxy valida: Contatta Domain Controller (Netlogon Secure Channel) OPPURE ha hash NTLM locale (se proxy joined domain)

Vantaggi: Password mai in rete, mutual auth (opzionale), session key per signing/sealing.

Limiti: Solo Windows/AD, NTLMv1 rotto (disabilitare), no delegation, vulnerabile a relay attacks (NTLM Relay) se no signing/EPA.

Kerberos (SPNEGO/GSS-API): Lo standard enterprise

Prerequisiti: Client e Proxy in stesso dominio/forest AD (o trust), SPN registrato (HTTP/proxy.corp), Keytab su proxy, sincronizzazione oraria (NTP <5 min), DNS funzionante (SRV _kerberos).

Flusso SPNEGO (Negotiate)

  1. Client → Proxy: Proxy-Authorization: Negotiate
  2. Proxy decifra Ticket con sua long-term key (da keytab) → Ottiene session key
  3. Proxy decifra Authenticator con session key → Verifica timestamp (replay protection), client principal
  4. Mutual Auth: Proxy → Client: Proxy-Authenticate: Negotiate
  5. Client verifica server authenticator → Entrambi autenticati
  6. Session key stabilita → Usata per wrapping traffico (se proxy supporta) o solo auth

Delegazione (Kerberos Constrained Delegation - KCD)

Proxy (service A) ottiene ticket per conto utente verso Backend (service B):

  1. Utente autentica su Proxy (AP-REQ con flag "forwardable")
  2. Proxy usa TGT utente (forwarded) → Richiede a KDC service ticket per "HTTP/backend.corp" (S4U2Proxy)
  3. KDC verifica: Proxy ha permesso "Trusted for delegation to HTTP/backend.corp" (msDS-AllowedToDelegateTo)
  4. KDC emette service ticket per backend → Proxy lo usa per accedere a backend come l'utente originale

Potente per: SSO end-to-end, audit trail identità reale fino al backend, policy per utente su backend.

Configurazione pratica: Squid + Kerberos (AD)

# 1. Keytab su proxy
ktpass -princ HTTP/proxy.corp@CORP.LOCAL -mapuser proxy_svc -pass * -crypto AES256-SHA1 -ptype KRB5_NT_PRINCIPAL -out proxy.keytab
# Copia proxy.keytab → /etc/squid/proxy.keytab (chown squid:squid, chmod 600)

# 2. squid.conf
auth_param negotiate program /usr/lib/squid/negotiate_kerberos_auth -d -s HTTP/proxy.corp@CORP.LOCAL -k /etc/squid/proxy.keytab
auth_param negotiate children 20 startup=5 idle=10
auth_param negotiate keep_alive on
auth_param negotiate realm Corporate Proxy (Kerberos)

acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_access deny all

# 3. DNS: A record proxy.corp → IP proxy. SPN: setspn -A HTTP/proxy.corp CORP\proxy_svc
# 4. Client browser: Già usa credenziali Windows (Integrated Auth) se proxy in zona "Intranet" / "Trusted Sites"

Configurazione client: Browser e CLI

ClientBasicNTLMKerberos (SPNEGO)
Chrome/EdgeAuto (prompt)Auto se zona Intranet/TrustedAuto se zona Intranet/Trusted + SPN corretto
FirefoxAuto (prompt)about:config → network.automatic-ntlm-auth.trusted-uris = "proxy.corp"about:config → network.negotiate-auth.trusted-uris = "proxy.corp" + network.negotiate-auth.delegation-uris = "proxy.corp"
curlcurl -U user:pass -x proxy:3128 urlcurl --proxy-ntlm -U : -x proxy:3128 url (usa credenziali Windows se SSPI)curl --negotiate -U : -x proxy:3128 url (richiede GSS-API, kinit prima)
wgetwget --proxy-user=user --proxy-password=pass -e use_proxy=yes urlNon supportato nativamenteNon supportato nativamente
Python requestsrequests.get(url, proxies=..., auth=HTTPProxyAuth(user,pass))requests-ntlm librequests-kerberos / requests-gssapi lib

Sicurezza: Hardening proxy auth

  1. Disabilita Basic su HTTP: Solo su HTTPS (TLS 1.2+). Forza redirect HTTP→HTTPS per auth.
  2. Disabilita NTLMv1: Registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\LMCompatibilityLevel = 5 (Solo NTLMv2 + Session Security)
  3. EPA (Extended Protection for Authentication): Channel Binding (TLS) per NTLM/Kerberos → Previene relay attacks.
  4. Account lockout: Dopo N tentativi falliti (proxy + AD)
  5. Log auth: Successi + Fallimenti (IP, user, timestamp, metodo) → SIEM
  6. Password policy: Complessità, rotazione, no riutilizzo, MFA per account admin proxy
  7. Segmentazione: Proxy auth su VLAN management, non esposto Internet
  8. Certificati proxy: TLS valido (pubblico o PKI interna), HSTS, OCSP Stapling

Troubleshooting comune

SintomoCausa probabileVerifica / Fix
407 loop (prompt infinite)Credenziali errate, realm mismatch, client non invia authLog proxy (auth debug), curl -v per test manuale
Kerberos: "KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN"SPN non registrato / keytab mismatch / realm case-sensitivesetspn -L proxy_svc, klist -k /etc/squid/proxy.keytab, realm MAIUSCOLO
Kerberos: "Clock skew too great"Orario proxy/client/DC >5 min diffNTP sync su tutti (chrony, w32time)
NTLM: "Access denied" ma password giustaNTLMv1 disabilitato lato DC, proxy usa v1 / Relay attack bloccato / Signing richiestoLMCompatibilityLevel=5, EPA, signing richiesto
Firefox: "The proxy requires authentication" loopTrusted URIs non configurati per NTLM/Negotiateabout:config → network.negotiate-auth.trusted-uris, network.automatic-ntlm-auth.trusted-uris
Transparent proxy: auth non funzionaClient non sa che proxy c'è → Non invia Proxy-AuthorizationTransparent proxy NON supporta auth standard. Usa WPAD/PAC o config esplicita.

LinkedIn

  • --热点software