温馨提示×

如何批量用ubuntu strings

小樊
48
2026-09-18 13:32:43
栏目: 智能运维

在 Ubuntu 下,strings 常用于从二进制文件中提取可打印字符串。如果你想批量处理多个文件,可以结合 Shell 命令来实现。

下面按常见场景给你几种做法。


一、对一个目录下的所有文件批量 strings

1. 处理当前目录所有文件

for f in *; do
    echo "==== $f ===="
    strings "$f"
done

2. 只处理二进制文件(推荐)

for f in *; do
    if file "$f" | grep -q "ELF"; then
        echo "==== $f ===="
        strings "$f"
    fi
done

二、递归处理子目录(find)

1. 递归所有文件

find . -type f -exec strings {} \;

2. 递归并标注文件名

find . -type f -exec sh -c 'echo "==== $1 ===="; strings "$1"' _ {} \;

3. 只处理 ELF 文件

find . -type f -exec sh -c '
    if file "$1" | grep -q "ELF"; then
        echo "==== $1 ===="
        strings "$1"
    fi
' _ {} \;

三、把结果输出到文件(批量分析常用)

find . -type f -name "*.so" -o -name "*bin" | while read f; do
    strings "$f" > "$f.strings.txt"
done

或统一输出:

find . -type f -exec strings {} \; > all_strings.txt

四、常用 strings 参数(很实用)

strings -n 6 file        # 只显示长度 ≥6 的字符串
strings -e l file        # 16-bit little endian
strings -e b file        # 16-bit big endian
strings -t x file        # 显示字符串偏移(十六进制)

批量示例:

find . -type f -exec strings -n 6 -t x {} \;

五、高级:xargs 加速(文件多时)

find . -type f -print0 | xargs -0 -P 4 strings
  • -P 4:4 个并行进程

六、典型使用场景

  • 逆向分析 / CTF
  • 提取二进制中的路径、URL、密钥
  • 排查恶意程序

如果你能告诉我:

  • ELF / PE / 固件 / 任意文件
  • 是否需要 去重 / 过滤关键字 / 输出格式

我可以给你更精确的批量脚本。

0