TL;DR
- 目的:Investigate supply chain attack artifacts including trojanized software updates, compromised build pipelines, and sideloaded dependencies to…
- 适用:辅助/通用
- 输入:样本文件/二进制/HASH
- 输出:IOC 列表 + 行为分析
- 红线:样本在隔离沙箱中执行;禁止连接生产网络
- 关联:上游:003-src-session-start → 下游:174-analyzing-sbom-for-supply-chain-vulnerabilities, 173-analyzing-network-packets-with-scapy, 175-analyzing-security-logs-with-splunk
Analyzing Supply Chain Malware Artifacts
Overview
Supply chain attacks compromise legitimate software distribution channels to deliver malware through trusted update mechanisms. Notable examples include SolarWinds SUNBURST (2020, affecting 18,000+ customers), 3CX SmoothOperator (2023, a cascading supply chain attack originating from Trading Technologies), and numerous npm/PyPI package poisoning campaigns. Analysis involves comparing trojanized binaries against legitimate versions, identifying injected code in build artifacts, examining code signing anomalies, and tracing the infection chain from initial compromise through payload delivery. As of 2025, supply chain attacks account for 30% of all breaches, a 100% increase from prior years.
When to Use
- When investigating security incidents that require analyzing supply chain malware artifacts
- When building detection rules or threat hunting queries for this domain
- When SOC analysts need structured procedures for this analysis type
- When validating security monitoring coverage for related attack techniques
Prerequisites
- Python 3.9+ with
pefile, ssdeep, hashlib
- Binary diff tools (BinDiff, Diaphora)
- Code signing verification tools (sigcheck, codesign)
- Software composition analysis (SCA) tools
- Access to legitimate software versions for comparison
- Package repository monitoring (npm, PyPI, NuGet)
Workflow
Step 1: Binary Comparison Analysis
#!/usr/bin/env python3
"""Compare trojanized binary against legitimate version."""
import hashlib
import pefile
import sys
import json
def compare_pe_files(legitimate_path, suspect_path):
"""Compare PE file structures between legitimate and suspect versions."""
legit_pe = pefile.PE(legitimate_path)
suspect_pe = pefile.PE(suspect_path)
report = {"differences": [], "suspicious_sections": [], "import_changes": []}
# Compare sections
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}
# Find new or modified sections
for name, props in suspect_sections.items():
if name not in legit_sections:
report["suspicious_sections"].append({
"name": name, "reason": "New section not in legitimate version",
"size": props["size"], "entropy": round(props["entropy"], 2),
})
elif abs(props["size"] - legit_sections[name]["size"]) > 1024:
report["suspicious_sections"].append({
"name": name, "reason": "Section size significantly changed",
"legit_size": legit_sections[name]["size"],
"suspect_size": props["size"],
})
# Compare imports
legit_imports = set()
if hasattr(legit_pe, 'DIRECTORY_ENTRY_IMPORT'):
for entry in legit_pe.DIRECTORY_ENTRY_IMPORT:
for imp in entry.imports:
if imp.name:
legit_imports.add(f"{entry.dll.decode()}!{imp.name.decode()}")
suspect_imports = set()
if hasattr(suspect_pe, 'DIRECTORY_ENTRY_IMPORT'):
for entry in suspect_pe.DIRECTORY_ENTRY_IMPORT:
for imp in entry.imports:
if imp.name:
suspect_imports.add(f"{entry.dll.decode()}!{imp.name.decode()}")
new_imports = suspect_imports - legit_imports
if new_imports:
report["import_changes"] = list(new_imports)
# Check code signing
report["legit_signed"] = bool(legit_pe.OPTIONAL_HEADER.DATA_DIRECTORY[4].Size)
report["suspect_signed"] = bool(suspect_pe.OPTIONAL_HEADER.DATA_DIRECTORY[4].Size)
return report
def hash_file(filepath):
"""Calculate multiple hashes for a file."""
hashes = {}
with open(filepath, 'rb') as f:
data = f.read()
for algo in ['md5', 'sha1', 'sha256']:
h = hashlib.new(algo)
h.update(data)
hashes[algo] = h.hexdigest()
return hashes
if __name__ == "__main__":
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} <legitimate_binary> <suspect_binary>")
sys.exit(1)
report = compare_pe_files(sys.argv[1], sys.argv[2])
print(json.dumps(report, indent=2))
Validation Criteria
- Trojanized components identified through binary diffing
- Injected code isolated and analyzed separately
- Code signing anomalies documented
- Infection timeline reconstructed from build artifacts
- Downstream impact scope assessed across affected systems
- IOCs extracted for detection and blocking
References
1---2name: analyzing-supply-chain-malware-artifacts3description: Perform analyzing supply chain malware artifacts assessment during authorized security testing. Use this skill when indicators of the vulnerability class are present in the target environment.4license: Apache-2.05---67## TL;DR89- **目的**:Investigate supply chain attack artifacts including trojanized software updates, compromised build pipelines, and sideloaded dependencies to…10- **适用**:辅助/通用11- **输入**:样本文件/二进制/HASH12- **输出**:IOC 列表 + 行为分析13- **红线**:样本在隔离沙箱中执行;禁止连接生产网络14- **关联**:上游:003-src-session-start → 下游:174-analyzing-sbom-for-supply-chain-vulnerabilities, 173-analyzing-network-packets-with-scapy, 175-analyzing-security-logs-with-splunk1516# Analyzing Supply Chain Malware Artifacts1718## Overview1920Supply chain attacks compromise legitimate software distribution channels to deliver malware through trusted update mechanisms. Notable examples include SolarWinds SUNBURST (2020, affecting 18,000+ customers), 3CX SmoothOperator (2023, a cascading supply chain attack originating from Trading Technologies), and numerous npm/PyPI package poisoning campaigns. Analysis involves comparing trojanized binaries against legitimate versions, identifying injected code in build artifacts, examining code signing anomalies, and tracing the infection chain from initial compromise through payload delivery. As of 2025, supply chain attacks account for 30% of all breaches, a 100% increase from prior years.212223## When to Use2425- When investigating security incidents that require analyzing supply chain malware artifacts26- When building detection rules or threat hunting queries for this domain27- When SOC analysts need structured procedures for this analysis type28- When validating security monitoring coverage for related attack techniques2930## Prerequisites3132- Python 3.9+ with `pefile`, `ssdeep`, `hashlib`33- Binary diff tools (BinDiff, Diaphora)34- Code signing verification tools (sigcheck, codesign)35- Software composition analysis (SCA) tools36- Access to legitimate software versions for comparison37- Package repository monitoring (npm, PyPI, NuGet)3839## Workflow4041### Step 1: Binary Comparison Analysis4243```python44#!/usr/bin/env python345"""Compare trojanized binary against legitimate version."""46import hashlib47import pefile48import sys49import json505152def compare_pe_files(legitimate_path, suspect_path):53 """Compare PE file structures between legitimate and suspect versions."""54 legit_pe = pefile.PE(legitimate_path)55 suspect_pe = pefile.PE(suspect_path)5657 report = {"differences": [], "suspicious_sections": [], "import_changes": []}5859 # Compare sections60 legit_sections = {s.Name.rstrip(b'\x00').decode(): {61 "size": s.SizeOfRawData,62 "entropy": s.get_entropy(),63 "characteristics": s.Characteristics,64 } for s in legit_pe.sections}6566 suspect_sections = {s.Name.rstrip(b'\x00').decode(): {67 "size": s.SizeOfRawData,68 "entropy": s.get_entropy(),69 "characteristics": s.Characteristics,70 } for s in suspect_pe.sections}7172 # Find new or modified sections73 for name, props in suspect_sections.items():74 if name not in legit_sections:75 report["suspicious_sections"].append({76 "name": name, "reason": "New section not in legitimate version",77 "size": props["size"], "entropy": round(props["entropy"], 2),78 })79 elif abs(props["size"] - legit_sections[name]["size"]) > 1024:80 report["suspicious_sections"].append({81 "name": name, "reason": "Section size significantly changed",82 "legit_size": legit_sections[name]["size"],83 "suspect_size": props["size"],84 })8586 # Compare imports87 legit_imports = set()88 if hasattr(legit_pe, 'DIRECTORY_ENTRY_IMPORT'):89 for entry in legit_pe.DIRECTORY_ENTRY_IMPORT:90 for imp in entry.imports:91 if imp.name:92 legit_imports.add(f"{entry.dll.decode()}!{imp.name.decode()}")9394 suspect_imports = set()95 if hasattr(suspect_pe, 'DIRECTORY_ENTRY_IMPORT'):96 for entry in suspect_pe.DIRECTORY_ENTRY_IMPORT:97 for imp in entry.imports:98 if imp.name:99 suspect_imports.add(f"{entry.dll.decode()}!{imp.name.decode()}")100101 new_imports = suspect_imports - legit_imports102 if new_imports:103 report["import_changes"] = list(new_imports)104105 # Check code signing106 report["legit_signed"] = bool(legit_pe.OPTIONAL_HEADER.DATA_DIRECTORY[4].Size)107 report["suspect_signed"] = bool(suspect_pe.OPTIONAL_HEADER.DATA_DIRECTORY[4].Size)108109 return report110111112def hash_file(filepath):113 """Calculate multiple hashes for a file."""114 hashes = {}115 with open(filepath, 'rb') as f:116 data = f.read()117 for algo in ['md5', 'sha1', 'sha256']:118 h = hashlib.new(algo)119 h.update(data)120 hashes[algo] = h.hexdigest()121 return hashes122123124if __name__ == "__main__":125 if len(sys.argv) < 3:126 print(f"Usage: {sys.argv[0]} <legitimate_binary> <suspect_binary>")127 sys.exit(1)128 report = compare_pe_files(sys.argv[1], sys.argv[2])129 print(json.dumps(report, indent=2))130```131132## Validation Criteria133134- Trojanized components identified through binary diffing135- Injected code isolated and analyzed separately136- Code signing anomalies documented137- Infection timeline reconstructed from build artifacts138- Downstream impact scope assessed across affected systems139- IOCs extracted for detection and blocking140141## References142143- [ReversingLabs - 3CX Supply Chain Analysis](https://www.reversinglabs.com/blog/what-went-wrong-with-the-3cx-software-supply-chain-attack-and-how-it-could-have-been-prevented)144- [Fortinet - SolarWinds Supply Chain Attack](https://www.fortinet.com/resources/cyberglossary/solarwinds-cyber-attack)145- [Picus - 3CX SmoothOperator Analysis](https://www.picussecurity.com/resource/blog/smoothoperator-analysis-of-3cxdesktopapp-supply-chain-attack)146- [MITRE ATT&CK T1195 - Supply Chain Compromise](https://attack.mitre.org/techniques/T1195/)