| name | analyzing-supply-chain-malware-artifacts |
| description | 调查供应链攻击工件,包括被木马化的软件更新、被攻陷的构建流水线和侧载的依赖项,以识别入侵向量和攻陷范围。 |
| domain | cybersecurity |
| subdomain | malware-analysis |
| tags | ["supply-chain","malware-analysis","trojanized-software","solarwinds","3cx","dependency-confusion","software-integrity"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
分析供应链恶意软件工件
概述
供应链攻击通过破坏合法软件分发渠道,借助受信任的更新机制投递恶意软件。典型案例包括 SolarWinds SUNBURST(2020 年,影响 18,000 多个客户)、3CX SmoothOperator(2023 年,一起源自 Trading Technologies 的级联供应链攻击)以及大量 npm/PyPI 包投毒活动。分析工作涉及:将木马化二进制文件与合法版本进行比对、识别构建工件中的注入代码、检查代码签名异常,以及追踪从初始攻陷到载荷投递的感染链。截至 2025 年,供应链攻击占所有违规事件的 30%,较前几年增加了 100%。
前置条件
- Python 3.9+,安装
pefile、ssdeep、hashlib
- 二进制对比工具(BinDiff、Diaphora)
- 代码签名验证工具(sigcheck、codesign)
- 软件成分分析(SCA)工具
- 访问合法软件版本以供比对
- 包仓库监控(npm、PyPI、NuGet)
操作步骤
步骤 1:二进制比对分析
"""比对木马化二进制文件与合法版本。"""
import hashlib
import pefile
import sys
import json
def compare_pe_files(legitimate_path, suspect_path):
"""比对合法版本与可疑版本之间的 PE 文件结构。"""
legit_pe = pefile.PE(legitimate_path)
suspect_pe = pefile.PE(suspect_path)
report = {"differences": [], "suspicious_sections": [], "import_changes": []}
legit_sections = {s.Name.rstrip(b'\x00').decode(): {
"size": s.SizeOfRawData,
"entropy": s.get_entropy(),
"characteristics": s.Characteristics,
} for s in legit_pe.sections}
suspect_sections = {s.Name.rstrip(b'\x00').decode(): {
"size": s.SizeOfRawData,
"entropy": s.get_entropy(),
"characteristics": s.Characteristics,
} for s in suspect_pe.sections}
for name, props in suspect_sections.items():
if name not in legit_sections:
report["suspicious_sections"].append({
"name": name, "reason": "合法版本中不存在的新节",
"size": props["size"], "entropy": round(props["entropy"], 2),
})
elif (props[] - legit_sections[name][]) > :
report[].append({
: name, : ,
: legit_sections[name][],
: props[],
})
legit_imports = ()
(legit_pe, ):
entry legit_pe.DIRECTORY_ENTRY_IMPORT:
imp entry.imports:
imp.name:
legit_imports.add()
suspect_imports = ()
(suspect_pe, ):
entry suspect_pe.DIRECTORY_ENTRY_IMPORT:
imp entry.imports:
imp.name:
suspect_imports.add()
new_imports = suspect_imports - legit_imports
new_imports:
report[] = (new_imports)
report[] = (legit_pe.OPTIONAL_HEADER.DATA_DIRECTORY[].Size)
report[] = (suspect_pe.OPTIONAL_HEADER.DATA_DIRECTORY[].Size)
report
():
hashes = {}
(filepath, ) f:
data = f.read()
algo [, , ]:
h = hashlib.new(algo)
h.update(data)
hashes[algo] = h.hexdigest()
hashes
__name__ == :
(sys.argv) < :
()
sys.exit()
report = compare_pe_files(sys.argv[], sys.argv[])
(json.dumps(report, indent=, ensure_ascii=))
验证标准
- 通过二进制对比识别出被木马化的组件
- 注入的代码被隔离并单独分析
- 代码签名异常已记录
- 从构建工件重建感染时间线
- 评估对受影响系统的下游影响范围
- 提取 IoC 用于检测和封锁
参考资料