在 Linux 中,strings 命令用于从二进制文件(或任意文件)中提取可打印的字符串,常用于分析程序、排查文本、逆向工程等。
下面从基本用法 → 常用参数 → 实战示例逐步说明。
strings 文件名
示例:
strings a.out
作用:
从 a.out 中提取所有长度 ≥ 4 的可打印字符串(默认最小长度通常是 4)。
-n)strings -n 6 example.bin
只显示长度 ≥ 6 的字符串,过滤掉无意义的短字符。
-t)strings -t x file.bin # 十六进制偏移
strings -t d file.bin # 十进制偏移
strings -t o file.bin # 八进制偏移
示例输出:
1024 /lib64/ld-linux-x86-64.so.2
2048 usage: prog [options]
-e)strings -e l file.bin # 16-bit little endian
strings -e b file.bin # 16-bit big endian
strings -e S file.bin # 8-bit字符(默认)
常用于:
cat file.bin | strings
适合管道处理。
dd)dd if=file.bin bs=1 skip=1024 count=4096 | strings
strings /bin/ls | grep -i error
strings app | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}"
strings app | grep -E "https?://"
strings malware.bin -n 8 -t x
strings -e l program.exe
可能原因:
-n 3)-e)❌ 不能
只能看到:
strings file # 基本提取
strings -n 6 file # 最小长度
strings -t x file # 偏移地址
strings -e l file # UTF-16
strings file | grep xxx # 配合搜索
如果你有具体文件类型(ELF / PE / 固件 / 日志)或目标(找密码、找 URL、逆向),我可以给你更针对性的命令。