温馨提示×

如何用linux strings查病毒

小樊
36
2026-09-14 14:39:32
栏目: 智能运维

在 Linux 下,strings 本身不能直接杀毒或判定病毒,但它是一个非常有用的初步分析工具,用来从二进制文件中提取可读字符串,帮助你发现可疑线索。

下面按「思路 + 实战命令 + 判断要点」来说明。


一、strings 能做什么(和不能做什么)

✅ 能做的

  • 查看程序中嵌入的:
    • URL / IP
    • 命令名(如 /bin/sh, wget, curl
    • 文件名(/etc/rc.local, cron
    • 作者痕迹、加密字符串
  • 快速判断一个文件“像不像”恶意程序

❌ 不能做的

  • 不能解码加密/混淆代码
  • 不能证明“一定是病毒”
  • 不能替代 clamavrkhunter 等专用工具

二、基础用法

1️⃣ 提取字符串

strings suspicious_file

2️⃣ 只看长度 ≥ 6 的字符串(更干净)

strings -n 6 suspicious_file

3️⃣ 结合 grep 查关键字(重点)

strings suspicious_file | grep -Ei "wget|curl|/bin/sh|/etc|base64|http"

三、常见“危险信号”关键词

如果你在 strings 输出中看到这些,要高度怀疑

网络连接

http://
https://
wget
curl
socket
connect

执行命令

/bin/sh
/bin/bash
system(
execve

持久化痕迹

/etc/cron
crontab
rc.local
systemd
ssh authorized_keys

反分析

gdb
ptrace
anti-debug
vmware

四、实战示例

示例 1:检查一个未知 ELF 文件

file unknown_bin
strings -n 6 unknown_bin | grep -Ei "http|wget|/bin/sh|passwd"

示例 2:扫描当前目录所有可执行文件

for f in *; do
  if file "$f" | grep -q ELF; then
    echo "=== $f ==="
    strings -n 6 "$f" | grep -Ei "wget|curl|/bin/sh"
  fi
done

示例 3:从内存或日志中提取(进阶)

strings /var/log/syslog | grep -i "curl"

五、配合其他工具更靠谱

strings 只是第一步,建议组合使用:

# 查杀毒
clamscan -r /path

# 查 rootkit
rkhunter --check

# 查进程
ps aux | grep -i suspicious

六、重要安全建议

  • ❌ 不要在生产服务器直接运行未知文件
  • ✅ 在 沙箱 / 虚拟机 中分析
  • ✅ 用 strings 看“意图”,不是“结论”

如果你愿意,可以把:

  • 文件类型
  • strings 的部分输出
  • 或具体怀疑场景(如挖矿、后门)

发给我,我可以帮你逐行分析是否像病毒

0