在 Debian(以及一般的 Linux)环境下,strings 命令常用于从二进制文件、核心转储、固件等中提取可打印字符串。结合脚本使用,可以实现自动化分析、批量处理、过滤关键信息等。
下面从基本用法 → 脚本结合方式 → 实战示例三个层面说明。
strings file
strings -n 6 file # 只显示长度 ≥6 的字符串
strings -e l file # 指定编码(l=16-bit little endian)
strings -a file # 扫描整个文件
最常见方式:
#!/bin/bash
for f in /bin/*; do
echo "=== $f ==="
strings "$f" | grep -i "version"
done
strings binary | grep -E "PASSWORD|TOKEN|KEY"
或排序去重:
strings binary | sort | uniq -c | sort -nr
适合做复杂分析:
import subprocess
result = subprocess.run(
["strings", "binary"],
capture_output=True,
text=True
)
for line in result.stdout.splitlines():
if "error" in line.lower():
print(line)
strings binary > strings.txt
python analyze.py strings.txt
#!/bin/bash
PKG_DIR=/usr/bin
for bin in "$PKG_DIR"/*; do
if file "$bin" | grep -q "ELF"; then
echo "== $bin =="
strings "$bin" | grep -i "usage\|help\|version"
fi
done
strings -n 8 app | grep -iE "password|secret|apikey|token"
find /opt -type f -executable \
-exec sh -c 'strings "$1" | grep -q "DEBUG" && echo "$1"' _ {} \;
dpkg-deb -x package.deb outdir
strings outdir/usr/bin/* | less
-n 提高最小长度strings -e s binary # 7-bit
strings -e b binary # 16-bit
grep 或 head| 场景 | 用法 |
|---|---|
| 逆向分析 | strings + grep |
| 安全审计 | 查找密钥/路径 |
| 软件版本识别 | grep version |
| 批量扫描 | shell + find |
| 自动化分析 | Python 调用 |
如果你有具体使用场景(例如:分析某个 Debian 服务、固件、恶意软件、ELF 文件),可以告诉我,我可以给你写一套完整脚本。