Individuare porte in ascolto (listening) e connessioni attive su Windows
Sapere quali porte TCP/UDP sono aperte su un server è essenziale per: hardening (chiudere porte inutili), troubleshooting (conflitti porte, firewall), inventario servizi, compliance (PCI-DSS, ISO 27001). Ecco gli strumenti nativi e migliori pratiche.
1. netstat (classico, nativo)
# Porte in ascolto (TCP + UDP) con PID e nome processo
netstat -ano | findstr :LISTENING
# Tutte le connessioni stabilite (ESTABLISHED)
netstat -ano | findstr ESTABLISHED
# Solo UDP in ascolto
netstat -ano -p UDP
# Output leggibile con nomi processo (richiede admin per PID → nome)
netstat -abno
Colonne: Proto, Local Address, Foreign Address, State, PID.
2. PowerShell (moderno, oggetti, scriptabile)
# Porte TCP in ascolto con processo
Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess, @{Name='ProcessName';Expression={(Get-Process -Id $_.OwningProcess).ProcessName}} | Sort-Object LocalPort
# Porte UDP in ascolto
Get-NetUDPEndpoint | Select-Object LocalAddress, LocalPort, OwningProcess, @{Name='ProcessName';Expression={(Get-Process -Id $_.OwningProcess).ProcessName}}
# Esportare CSV
Get-NetTCPConnection -State Listen | Export-Csv -Path C:\temp\listening_ports.csv -NoTypeInformation
3. Resource Monitor (GUI, nativo)
- Win+R →
resmon→ Invio. - Scheda Rete → Porte in ascolto / Connessioni.
- Mostra: Immagine (processo), PID, Porta, Indirizzo, Stato. Clic destro → "Termina processo" se necessario.
4. nmap (standard industriale, da macchina remota)
# Scan porte TCP comuni (top 1000) su target
nmap -sS -T4 192.168.1.50
# Scan tutte le 65535 porte TCP
nmap -p- -T4 192.168.1.50
# Scan UDP (lento, serve root/admin)
nmap -sU -T4 --top-ports 100 192.168.1.50
# Identificazione servizio/versione
nmap -sV 192.168.1.50
nmap vede il server "dall'esterno" — include regole firewall perimetrali, a differenza di netstat locale.
5. PowerShell: mappare PID → servizio Windows
# Per un PID specifico (es. 1234)
Get-WmiObject Win32_Service -Filter "ProcessId = 1234" | Select-Object Name, DisplayName, StartMode, State
# Oppure per tutti i servizi con PID
Get-WmiObject Win32_Service | Where-Object {$_.ProcessId -ne $null} | Select-Object Name, DisplayName, ProcessId, State
Interpretazione porte comuni
| Porta | Servizio tipico | Azione se inaspettata |
|---|---|---|
| 22 | SSH | Verificare chiavi, disabilitare password auth |
| 25/587/465 | SMTP | Solo se server mail legittimo |
| 53 | DNS | Solo se DNS server autoritativo/ricorsivo |
| 80/443 | HTTP/HTTPS | Web server — verificare virtual host |
| 135/139/445 | RPC/SMB | Condivisione file — limitare a LAN, disabilitare SMBv1 |
| 3306/5432/1433 | MySQL/PostgreSQL/SQL Server | Solo localhost o VPN, mai 0.0.0.0 |
| 3389 | RDP | Solo VPN + NLA + account limitati |
| 5900/5901 | VNC | Cifrare (SSH tunnel) o disabilitare |
| 8080/8443/9000 | App server (Tomcat, Jenkins, Node) | Verificare necessità esposizione |
Salvare output per audit
netstat -abno > C:\audit\ports_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt
# PowerShell:
Get-NetTCPConnection -State Listen | Export-Csv -Path "C:\audit\ports_$(Get-Date -Format yyyyMMdd).csv"
Best practice
- Eseguire come Amministratore per vedere tutti i PID/processi.
- Confrontare netstat locale vs nmap remoto → differenze = firewall perimetrale o host-based.
- Documentare porte aperte legittime nel System Security Plan.
- Chiudere porte inutili: disabilitare servizi, Windows Firewall (regole inbound block), disinstallare software.
- Come configurare un server proxy per superare le restrizioni di rete
- Come installare e configurare altoparlanti wireless sul laptop
- --热点software