strings
2026/5/29工具工具逆向工程strings大约 3 分钟
strings
是什么
strings 用来从二进制文件中提取可见字符串。
逆向和 Misc 题中,它常用于第一轮快速观察:
- 成功/失败提示
- flag 片段
- URL、路径、命令
- 加密常量
- 函数名或调试信息
安装与配置
Linux 通常自带。如果没有:
sudo apt install binutilsWindows 可使用 Sysinternals strings、Git Bash、WSL 或 CTF 工具包。
基本用法
提取字符串
strings challenge搜索关键词
strings challenge | grep -i "flag\|key\|pass\|correct\|wrong"指定最小长度
strings -n 4 challenge
strings -n 8 challenge显示偏移
strings -t x challenge更多选项
指定编码
# ASCII (默认)
strings -e l challenge
# UTF-16 小端
strings -e L challenge
# UTF-16 大端
strings -e B challenge
# UTF-8
strings -e s challenge扫描整个文件
strings -a challenge默认只扫描可加载的段,-a 扫描整个文件。
输出为单行
strings challenge | tr '\n' ' '限制输出数量
strings challenge | head -50
strings challenge | tail -20正则过滤
# 使用 grep
strings challenge | grep -E "^[a-zA-Z0-9]{32}$" # 32 位十六进制
strings challenge | grep -E "flag\{.*\}" # flag 格式
strings challenge | grep -E "http" # URL从标准输入读取
cat challenge | strings
echo "some data" | strings扫描进程内存
# 扫描进程
strings /proc/<pid>/mem
# 扫描 core dump
strings core.<pid>输出为十六进制
strings -t x challenge
strings -t d challenge # 十进制偏移
strings -t o challenge # 八进制偏移扫描特定范围
# 从特定偏移开始
dd if=challenge bs=1 skip=1024 | strings
# 扫描特定大小
dd if=challenge bs=1 count=4096 | strings编码检测
自动检测
# 使用 file 命令
file challenge
# 使用 chardet
pip install chardet
chardet challenge常见编码
ASCII: 基本英文字符
UTF-8: 可变长度 Unicode
UTF-16: 16 位 Unicode
UTF-16LE: 小端 UTF-16
UTF-16BE: 大端 UTF-16
Latin-1: 西欧字符
GBK: 中文字符中文字符串
# UTF-8 中文
strings -e s challenge
# GBK 中文
strings -e l challenge
# 使用 iconv 转换
iconv -f GBK -t UTF-8 challenge | stringsCTF常用技巧
逆向第一步
file challenge
strings -a challenge | head
strings -a challenge | grep -i "flag\|check\|verify\|correct\|wrong"找交叉引用线索
strings 找到可疑字符串后,在 IDA/Ghidra 中搜索该字符串并查看 xref。
不要被假 flag 骗
看到 flag{...} 不一定是真结果,可能是诱饵、格式提示或错误分支。
常见搜索关键词
flag
key
password
secret
admin
correct
wrong
success
fail
check
verify
encrypt
decrypt
http
https
ftp
ssh批量分析
#!/bin/bash
# 批量提取字符串并搜索
for f in *.bin; do
echo "=== $f ==="
strings -a "$f" | grep -i "flag\|key\|pass"
done自动化脚本
#!/usr/bin/env python3
import subprocess
import sys
def extract_strings(filename, min_length=4):
"""提取字符串"""
result = subprocess.run(
["strings", "-n", str(min_length), filename],
capture_output=True, text=True
)
return result.stdout.splitlines()
def search_patterns(strings_list, patterns):
"""搜索模式"""
results = []
for s in strings_list:
for p in patterns:
if p.lower() in s.lower():
results.append(s)
break
return results
if __name__ == "__main__":
filename = sys.argv[1]
strings_list = extract_strings(filename)
patterns = ["flag", "key", "password", "secret", "http"]
results = search_patterns(strings_list, patterns)
for r in results:
print(r)提取 URL
strings challenge | grep -E "https?://"提取邮箱
strings challenge | grep -E "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"提取 IP 地址
strings challenge | grep -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"常见问题
什么都没有
可能被加壳、压缩、加密,或字符串是宽字符/运行时生成。
中文乱码
strings 对编码支持有限。尝试 -el 或用十六进制/专用工具看。
有字符串但找不到逻辑
进入 IDA/Ghidra 查引用,而不是只停留在命令行输出。
输出太多
# 限制长度
strings -n 10 challenge
# 使用更精确的过滤
strings challenge | grep -E "^flag\{"
# 限制输出行数
strings challenge | head -100字符串被拆分
1. 尝试不同最小长度
2. 尝试不同编码
3. 使用十六进制查看
4. 分析内存布局关联
- 字符串、交叉引用与控制流
- 逆向题的最小分析闭环
- IDA Pro
- Ghidra
- Detect It Easy