23 - Pentesting Telnet

Tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks

Informazioni di base

Telnet è un protocollo di rete che fornisce agli utenti un modo non sicuro per accedere a un computer attraverso una rete.

Porta predefinita: 23

23/tcp open  telnet

Enumeration

nc -vn <IP> 23

Tutta l’enumerazione interessante può essere eseguita con nmap:

nmap -n -sV -Pn --script "*telnet* and safe" -p 23 <IP>

Lo script telnet-ntlm-info.nse otterrà informazioni NTLM (versioni di Windows).

From the telnet RFC: Nel Protocollo TELNET ci sono varie “opzioni” che saranno sancite e possono essere usate con la struttura “DO, DON’T, WILL, WON’T” per permettere a client e server di accordarsi per usare un insieme di convenzioni più elaborate (o forse semplicemente diverse) per la loro connessione TELNET. Tali opzioni possono includere la modifica del set di caratteri, della modalità echo, ecc.

So che è possibile enumerare queste opzioni ma non so come, quindi fatemi sapere se sapete come.

Enumerare le opzioni / funzionalità di Telnet

Telnet usa IAC + DO/DONT/WILL/WONT per negoziare l’abilitazione delle opzioni. Puoi osservare le opzioni supportate catturando la negoziazione iniziale e sondando funzionalità specifiche.

Probe Nmap per opzioni/funzionalità

# Detect support for the Telnet ENCRYPT option
nmap -p 23 --script telnet-encryption <IP>

# Enumerate Microsoft Telnet NTLM info (NetBIOS/DNS/OS build)
nmap -p 23 --script telnet-ntlm-info <IP>

# Brute-force via NSE (alternative to Hydra/Medusa)
nmap -p 23 --script telnet-brute --script-args userdb=users.txt,passdb=pass.txt <IP>

Lo script telnet-encryption verifica se l’opzione ENCRYPT è supportata; alcune implementazioni in passato gestivano questa opzione in modo errato ed erano vulnerabili, ma lo script si limita a verificare il supporto. telnet-ntlm-info rivela metadati NTLM (NetBIOS/DNS/OS build) quando Microsoft Telnet NTLM è abilitato. telnet-brute è un auditor NSE di brute-force per Telnet.

Brute force

File di configurazione

/etc/inetd.conf
/etc/xinetd.d/telnet
/etc/xinetd.d/stelnet

HackTricks Comandi Automatici

Protocol_Name: Telnet    #Protocol Abbreviation if there is one.
Port_Number:  23     #Comma separated if there is more than one.
Protocol_Description: Telnet          #Protocol Abbreviation Spelled out

Entry_1:
Name: Notes
Description: Notes for t=Telnet
Note: |
wireshark to hear creds being passed
tcp.port == 23 and ip.addr != myip

https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-telnet.html

Entry_2:
Name: Banner Grab
Description: Grab Telnet Banner
Command: nc -vn {IP} 23

Entry_3:
Name: Nmap with scripts
Description: Run nmap scripts for telnet
Command: nmap -n -sV -Pn --script "*telnet*" -p 23 {IP}

Entry_4:
Name: consoleless mfs enumeration
Description: Telnet enumeration without the need to run msfconsole
Note: sourced from https://github.com/carlospolop/legion
Command: msfconsole -q -x 'use auxiliary/scanner/telnet/telnet_version; set RHOSTS {IP}; set RPORT 23; run; exit' && msfconsole -q -x 'use auxiliary/scanner/telnet/brocade_enable_login; set RHOSTS {IP}; set RPORT 23; run; exit' && msfconsole -q -x 'use auxiliary/scanner/telnet/telnet_encrypt_overflow; set RHOSTS {IP}; set RPORT 23; run; exit' && msfconsole -q -x 'use auxiliary/scanner/telnet/telnet_ruggedcom; set RHOSTS {IP}; set RPORT 23; run; exit'

Vulnerabilità recenti (2022-2026)

  • CVE-2024-45698 – D-Link Wi-Fi 6 routers (DIR-X4860): Una convalida degli input inadeguata nel servizio telnet permette ad attaccanti remoti di effettuare il login usando credenziali hard-coded e iniettare comandi OS; corretto dal firmware 1.04B05 o successivi.
  • CVE-2023-40478 – NETGEAR RAX30: Buffer overflow basato sullo stack nel comando Telnet CLI passwd consente l’esecuzione di codice come root da network-adjacent; è richiesta autenticazione ma può essere bypassata.
  • CVE-2022-39028 – GNU inetutils telnetd: Una sequenza di due byte (0xff 0xf7 / 0xff 0xf8) può causare una dereferenziazione di un puntatore NULL in telnetd, e crash ripetuti possono portare inetd a disabilitare il servizio (DoS).

Tieni a mente queste CVE durante la triage delle vulnerabilità — se il target esegue un firmware non patchato o un daemon Telnet inetutils legacy potresti avere un percorso diretto verso code-execution o un DoS distruttivo.

CVE-2026-24061 — GNU Inetutils telnetd auth bypass (Critical)

Sommario: telnetd in GNU Inetutils fino a 2.7 permette remote authentication bypass tramite una variabile d’ambiente USER con valore -f root, risultando in accesso root non autenticato.
Causa principale: argument injection (CWE-88) perché telnetd inoltra la variabile d’ambiente USER fornita dal client a login senza sanitizzazione.
Ambito: GNU Inetutils telnetd versioni 1.9.3–2.7 sono affette (pubblicato 21 gennaio 2026).

Mitigazioni

  • Patch/upgrade i pacchetti interessati immediatamente (ad es., le correzioni Debian sono in 2:2.4-2+deb12u2, 2:2.6-3+deb13u1 e 2:2.7-2).
  • Disabilitare Telnet o limitare l’accesso alle reti di management fidate durante l’applicazione della patch.

Sniffing Credentials & Man-in-the-Middle

Telnet trasmette tutto, incluse le credenziali, in clear-text. Due metodi rapidi per catturarle:

# Live capture with tcpdump (print ASCII)
sudo tcpdump -i eth0 -A 'tcp port 23 and not src host $(hostname -I | cut -d" " -f1)'

# Wireshark display filter
tcp.port == 23 && (telnet.data || telnet.option)

Per un MITM attivo, combina ARP spoofing (es. arpspoof/ettercap) con gli stessi filtri di sniffing per raccogliere password su reti switched.

Automated Brute-force / Password Spraying

# Hydra (stop at first valid login)
hydra -L users.txt -P rockyou.txt -t 4 -f telnet://<IP>

# Ncrack (drop to interactive session on success)
ncrack -p 23 --user admin -P common-pass.txt --connection-limit 4 <IP>

# Medusa (parallel hosts)
medusa -M telnet -h targets.txt -U users.txt -P passwords.txt -t 6 -f

La maggior parte degli IoT botnets (Mirai variants) continua a scanare port 23 con piccoli default-credential dictionaries—replicare questa logica può identificare rapidamente dispositivi deboli.

Exploitation & Post-Exploitation

Metasploit ha diversi moduli utili:

  • auxiliary/scanner/telnet/telnet_version – banner & option enumeration.
  • auxiliary/scanner/telnet/brute_telnet – multithreaded bruteforce.
  • auxiliary/scanner/telnet/telnet_encrypt_overflow – RCE against vulnerable Solaris 9/10 Telnet (option ENCRYPT handling).
  • exploit/linux/mips/netgear_telnetenable – enables telnet service with a crafted packet on many NETGEAR routers.

Dopo aver ottenuto una shell, ricorda che i TTYs sono solitamente limitati; migliorala con python -c 'import pty;pty.spawn("/bin/bash")' o usa HackTricks TTY tricks.

Hardening & Detection (Blue team corner)

  1. Preferisci SSH e disabilita completamente il servizio Telnet.
  2. Se Telnet è richiesto, bindalo alle management VLANs solo, applica ACLs e incapsula il daemon con TCP wrappers (/etc/hosts.allow).
  3. Sostituisci le implementazioni legacy telnetd con ssl-telnet o telnetd-ssl per aggiungere cifratura del trasporto, ma questo protegge solo i dati in transito—password-guessing rimane banale.
  4. Monitora traffico outbound verso port 23; le compromissioni spesso generano reverse shells over Telnet per bypassare strict-HTTP egress filters.

Riferimenti

  • D-Link Advisory – CVE-2024-45698 Critical Telnet RCE.
  • NVD – CVE-2022-39028 inetutils telnetd DoS.
  • NVD – CVE-2026-24061.
  • Canadian Centre for Cyber Security Alert AL26-002 (CVE-2026-24061).
  • Debian Security Tracker – CVE-2026-24061 fixed versions.

Tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks