SVG Security Analysis Toolkit to Detect Malicious Scripts Hidden in SVG Files
As attackers increasingly exploit Scalable Vector Graphics (SVG) for covert code injection, security researchers encounter challenges in detecting obfuscated payloads within these assets. The SVG Security Analysis Toolkit by HackingLZ provides a…
As attackers increasingly exploit Scalable Vector Graphics (SVG) for covert code injection, security researchers encounter challenges in detecting obfuscated payloads within these assets. The SVG Security Analysis Toolkit by HackingLZ provides a comprehensive solution, comprising four Python-based tools designed to uncover hidden scripts, decode obfuscated URLs, and verify protection mechanisms, without exposing analysts to unsafe execution environments.
The toolkit includes extract.py and extract_dynamic.py, which work together for static and dynamic analysis:
extract.py: A static SVG URL extractor that performs pattern-based analysis without executing any code. It detects and decodes XOR-encrypted payloads using String.fromCharCode patterns, Base64-encoded URLs, and character arithmetic schemes. extract_dynamic.py: Executes embedded JavaScript within a sandbox using box-js to capture final URL constructions. Key features include an advanced hook system for monitoring location.assign(), window.open(), AJAX calls, final URL prioritization, and ActiveX/WScript support for Windows-specific script monitoring.
The toolkit also includes cf_probe.py and encoder.py:
It detects and decodes XOR-encrypted payloads using String.fromCharCode patterns, Base64-encoded URLs, and character arithmetic schemes.
cf_probe.py: Detects Cloudflare protection by scanning HTTP and meta-refresh redirects for challenges, identifying Turnstile via data-sitekey attributes, scanning linked JavaScript for CAPTCHA systems, and reporting CF headers like CF-Ray. encoder.py: Generates realistic obfuscated SVG samples for security teams to validate their detection pipelines, supporting six obfuscation patterns, including XOR + ES6 Proxy and Hex-encoded Function Constructor scripts.
For maximum coverage and safety, HackingLZ recommends the following analysis sequence:
Generate Test Cases: encoder.py --random-all -o test_cases/ Static Analysis: python3 extract.py -i test_cases/*.svg -v Dynamic Analysis: python3 extract_dynamic.py -i test_cases/ -o dynamic_results/ Protection Verification: python3 cf_probe.py -i malicious_urls.txt
The SVG Security Analysis Toolkit enables defenders to effectively counter evasive SVG-based phishing and malware campaigns by combining static string decoding, sandboxed script execution, protection detection, and controlled test data generation.
Based on reporting by Cyber Security News.
