在 Linux 中,strings 和 grep 经常配合使用,用来从二进制文件或数据中抽取可打印字符串,并筛选感兴趣的内容。下面从常见用法到实战示例逐步说明。
strings file | grep "keyword"
示例:在二进制程序中查找字符串 password
strings /bin/ls | grep password
strings file | grep -E "user|pass|token"
strings file | grep -i "error"
strings file | grep -n "main"
strings * | grep "API_KEY"
或更安全的方式:
for f in *; do
echo "== $f =="
strings "$f" | grep "secret"
done
findfind . -type f -exec strings {} \; | grep "DEBUG"
或只搜索可执行文件:
find . -type f -executable -exec strings {} \; | grep "version"
strings file | grep -A3 -B2 "config"
strings file | grep -o "http://[a-zA-Z0-9./]+"
strings -n 6 file | grep "token"
strings /proc/kcore | grep "root"
(⚠️ 需要权限,且可能很大)
strings malware.bin | grep -E "http|ftp|\.exe|cmd"
| 场景 | 命令示例 |
|---|---|
| 分析二进制配置 | `strings app |
| 提取 URL | `strings file |
| 逆向辅助 | `strings lib.so |
| 日志/内存分析 | `strings core.dump |
如果你有具体文件类型或想找的内容(比如 ELF、固件、内存 dump、恶意样本),我可以给你更精确的命令。