在 Linux 下,strings 命令用来从二进制文件(可执行文件、库、core dump 等)中提取可打印字符串。结合脚本使用,可以自动化分析、过滤、统计或批量处理多个文件。
下面从基础用法 → 脚本结合方式 → 实战示例逐步说明。
strings file.bin
常用参数:
-n N:只显示长度 ≥ N 的字符串-e encoding:指定字符编码(如 s, l, b, B)-f:显示文件名-a:扫描整个文件(默认已接近全扫)示例:
strings -n 6 binary | grep PASSWORD
#!/bin/bash
for f in /usr/bin/*; do
echo "=== $f ==="
strings "$f" | grep -i "version"
done
strings app | awk 'length > 8' | sort | uniq -c | sort -nr
用途:
if strings "$1" | grep -q "DEBUG"; then
echo "包含 DEBUG 信息"
fi
strings binary | grep -Eo "https?://[a-zA-Z0-9./_-]+"
strings binary | grep -Eo "[0-9]{1,3}(\.[0-9]{1,3}){3}"
#!/bin/bash
DIR="$1"
KEYWORDS="password|secret|token|key"
find "$DIR" -type f -executable -exec sh -c '
f="$1"
matches=$(strings "$f" | grep -Ei "$2")
if [ -n "$matches" ]; then
echo "[!] $f"
echo "$matches"
fi
' _ {} "$KEYWORDS" \;
#!/bin/bash
for bin in "$@"; do
ver=$(strings "$bin" | grep -i "version" | head -n 1)
echo "$bin -> $ver"
done
strings challenge | grep -i "flag{"
strings challenge | strings -n 4 | grep -E "flag|key|secret"
strings binary | grep main
objdump -d binary | grep "call"
或用 file 判断类型:
file "$1" | grep -q ELF && strings "$1"
strings 不能解密,只能看明文cat-n 减少噪声如果你有具体使用场景(比如逆向、取证、安全扫描、日志分析),我可以帮你写一套完整脚本。