23 - Pentesting Telnet
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
基本信息
Telnet 是一种网络协议,为用户提供了一种不安全的方式来通过网络访问计算机。
默认端口: 23
23/tcp open telnet
Enumeration
Banner Grabbing
nc -vn <IP> 23
所有有趣的枚举可以通过 nmap:
nmap -n -sV -Pn --script "*telnet* and safe" -p 23 <IP>
The script telnet-ntlm-info.nse will obtain NTLM info (Windows versions).
From the telnet RFC: 在 TELNET 协议中存在各种“options”,这些 options 可以通过“DO、DON’T、WILL、WON’T”结构协商,从而允许客户端和服务器就更复杂(或不同)的 TELNET 连接约定达成一致。此类选项可能包括更改字符集、回显模式等。
我知道可以枚举这些选项,但我不知道如何操作,如果你知道请告诉我。
枚举 Telnet 选项 / 功能
Telnet 使用 IAC + DO/DONT/WILL/WONT 协商来启用选项。你可以通过捕获初始协商过程并探测特定功能来观察受支持的选项。
Nmap 选项/功能 探测
# 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>
The telnet-encryption script checks whether the ENCRYPT option is supported; some implementations historically handled this option incorrectly and were vulnerable, but the script only checks support.
telnet-ntlm-info discloses NTLM metadata (NetBIOS/DNS/OS build) when Microsoft Telnet NTLM is enabled.
telnet-brute is an NSE brute-force auditor for Telnet.
Brute force
配置文件
/etc/inetd.conf
/etc/xinetd.d/telnet
/etc/xinetd.d/stelnet
HackTricks 自动命令
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'
最近的漏洞 (2022-2026)
- CVE-2024-45698 – D-Link Wi-Fi 6 routers (DIR-X4860): telnet 服务中的不当输入验证允许远程攻击者使用硬编码凭证登录并注入操作系统命令;已在固件 1.04B05 或更高版本修复。
- CVE-2023-40478 – NETGEAR RAX30: 基于栈的缓冲区溢出发生在 Telnet CLI 的
passwd命令中,允许网络邻近的以 root 身份的代码执行;需要身份验证,但可以被绕过。 - CVE-2022-39028 – GNU inetutils telnetd: 一个两字节序列(
0xff 0xf7/0xff 0xf8)可以在telnetd中触发 NULL 指针解引用,重复崩溃可能导致 inetd 禁用该服务(DoS)。
在漏洞分类期间请记住这些 CVE —— 如果目标运行未修补的固件或旧版 inetutils Telnet 守护进程,你可能会有直接的 code-execution 路径或造成破坏性的 DoS。
CVE-2026-24061 — GNU Inetutils telnetd auth bypass (Critical)
摘要: GNU Inetutils 中的 telnetd 直至 2.7 允许通过将 USER 环境变量设置为 -f root 实现 remote authentication bypass,从而导致未认证的 root 访问。
根本原因: 参数注入 (CWE-88),因为 telnetd 在未做清理的情况下将客户端提供的 USER 环境变量转发给 login。
影响范围: GNU Inetutils telnetd 版本 1.9.3–2.7 受影响(发布于 2026年1月21日)。
缓解措施
- Patch/upgrade 受影响的软件包并立即升级(例如,Debian 的修复在
2:2.4-2+deb12u2、2:2.6-3+deb13u1和2:2.7-2)。 - Disable Telnet 或在打补丁期间将访问限制在受信任的管理网络内。
Sniffing Credentials & Man-in-the-Middle
Telnet 以明文传输所有内容,包括凭证。有两种快速捕获它们的方法:
# 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)
对于主动 MITM,结合 ARP spoofing(例如 arpspoof/ettercap)和相同的 sniffing filters,以在交换网络上收集密码。
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
Most IoT botnets (Mirai variants) still scan port 23 with small default-credential dictionaries—mirroring that logic can quickly identify weak devices.
利用与后利用
Metasploit 有几个有用的模块:
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.
After a shell is obtained remember that TTYs are usually dumb; upgrade with python -c 'import pty;pty.spawn("/bin/bash")' or use the HackTricks TTY tricks.
强化与检测 (Blue team 部分)
- 优先使用 SSH,并完全禁用 Telnet 服务。
- 如果 Telnet 是必需的,仅绑定到管理 VLAN,强制实施 ACL,并使用 TCP wrappers (
/etc/hosts.allow) 包裹守护进程。 - 用
ssl-telnet或telnetd-ssl替换 legacytelnetd实现以添加传输加密,但 这只保护传输中的数据——password-guessing remains trivial。 - 监控到端口 23 的出站流量;被攻破的设备常常通过 Telnet 发起 reverse shells 以绕过严格的 HTTP 出口过滤。
参考
- D-Link Advisory – CVE-2024-45698 Critical Telnet RCE.
- NVD – CVE-2022-39028 inetutils
telnetdDoS. - NVD – CVE-2026-24061.
- Canadian Centre for Cyber Security Alert AL26-002 (CVE-2026-24061).
- Debian Security Tracker – CVE-2026-24061 fixed versions.
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。


