
A comprehensive browser extension (.xpi) malware scanner which checks for many common malware tricks like:, credential-stealers obfuscation tactics, steganography, base64 payloads, zip-tricks, remote-code execution, polyglot tricks, meta data tricks in an attempt to give the analysist information about where deeper analysis is needed.
一款命令行工具,用于分析Firefox扩展文件(.xpi),检测恶意软件、混淆、隐藏载荷、隐写术以及其他用于绕过扩展审查团队的恶意代码技术。
extension-scanner.py 会解压Firefox扩展,并对其内部每个文件执行一系列安全检查,最终生成一份按严重性分级、带有颜色编码的报告。
| 类别 | 检查内容 |
|---|---|
| 权限 | 危险或过于宽泛的权限(nativeMessaging、<all_urls>、debugger、desktopCapture等) |
| 内容安全策略 | unsafe-inline、unsafe-eval、CSP中的远程脚本源 |
| JavaScript混淆 | eval()、atob()、Function()构造函数滥用、十六进制转义序列、split/join/reverse重组、编码字符串字面量、带字符串参数的setTimeout |
| 可疑URL | 硬编码的外部域名,分类为已知恶意(命中黑名单 → HIGH)、未知(未在白名单中 → MEDIUM)、已知安全(白名单中 → 抑制)。运行--update-blocklist可从URLhaus和Peter Lowe的列表刷新域名黑名单。 |
| 凭据与密钥 | 硬编码的API密钥、令牌(AWS、GitHub、Slack、Google)、密码、私钥和IP地址 |
| Base64载荷 | 解码嵌入的base64数据块,并扫描其中是否包含可执行文件、脚本和网络代码 |
| PNG隐写 | 检测PNG IEND后追加的数据,并自动解码尾部(base64、zlib、gzip及其组合);解码后的载荷会递归扫描JavaScript混淆、凭据和可疑URL。同时检测未知数据块类型、LSB通道异常以及异常高的像素熵 |
| 文件元数据 | 魔数检测可执行文件(.exe、.elf、.dylib)、双扩展名(如photo.png.js)、可疑文件名(keylog、miner、wallet) |
| 多格式文件 | 同时有效于两种格式的文件(如HTML + ZIP) |
| ZIP技巧 | 路径遍历条目、文件名中的空字节、可能欺骗解析器的重复条目、携带载荷的ZIP注释 |
| 远程代码 | 从远程URL加载的后台页面或Service Worker |
| 高熵 | 熵值异常高的文件或字符串字面量(很可能是加密或压缩的载荷) |
| API滥用 | 浏览器扩展API调用,指示数据窃取或外泄:cookies.getAll({})、tabs.query({})、history.search、键盘监听器、剪贴板读取、scripting.executeScript带动态函数。当数据收集调用与出站网络发送在同一文件中成对出现时,升级为CRITICAL。 |
| 隐藏元素 | 动态创建的不可见iframe(display:none、零尺寸)注入到DOM中——静默的联盟营销ping或C2通道。通过new Image().src指向外部URL的追踪像素。 |
CRITICAL — 几乎肯定为恶意;需立即调查HIGH — 高度可疑;需仔细审查MEDIUM — 存在潜在风险;需结合上下文审查LOW — 轻微问题;仅供参考INFO — 元数据(哈希、文件大小等)python3.11、python3.12或python3.13**python3-venv** — 如果使用虚拟环境,则为必需使用虚拟环境:
sudo apt install python3 python3-venv
git clone https://github.com/ernos/extension-scanner.git
cd extension-scanner
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
**python3-numpy** — 推荐用于隐写分析,系统级安装(否则使用pip install -r requirements.txt)git clone https://github.com/ernos/extension-scanner.git
cd extension-scanner
chmod +x extension-scanner.py
mkdir -p ~/.local/share/bin
ln -s $PWD/extension-scanner.py ~/.local/share/bin/extension-scanner
# 用于LSB隐写分析(可选但推荐)
pip install pillow numpy
# 选项1. 仅当前用户:
# 启用bash补全,简化使用(TAB自动补全命令)
mkdir -p ~/.local/share/bash-completion/completions
cp extension-scanner-completions ~/.local/share/bash-completion/completions
echo "source ~/.local/share/bash-completion/completions/extension-scanner-completions" >> ~/.bashrc
# 选项2. 为所有用户全局启用补全(应从.bashrc自动加载)
cp extension-scanner-completions /usr/share/bash-completion/completions
如果未安装Pillow/NumPy,工具仍可运行——仅跳过LSB和像素熵检查,并打印一条警告信息。
usage: xpiscanner [-h] [--update-blocklist] [--min-severity {CRITICAL,HIGH,MEDIUM,LOW,INFO}] [--json] [--compact] [-v] [-m] [--scans CHECK [CHECK ...]]
[targets ...]
Firefox Extension Scanner - Scans XPI files for security risks and malware indicators
positional arguments:
targets One or more XPI files or directories containing XPIs to analyze
options:
-h, --help show this help message and exit
--update-blocklist, --update, -u
Fetch fresh domain blocklists from URLhaus and Peter Lowe's list, merge with the bundled snapshot, and saves to
/home/peb/projects/Firefox-Extensions/extension-scanner/blocklist.json. Exits after updating.
--min-severity {CRITICAL,HIGH,MEDIUM,LOW,INFO}
Minimum severity to display (CRITICAL, HIGH, MEDIUM, LOW, INFO; default: INFO)
--json Output results as JSON instead of formatted text
--compact, -c Print each finding on 1-2 lines instead of the default 3-line format
-v, --verbose Enable verbose output: show additional context for findings
-m, --manifest Show full extension manifest for each target
--scans, -s CHECK [CHECK ...]
Limit analysis to specific check types. Choices: anti-analysis, api-abuse, credentials, cross-file,
file-meta, hidden-elements, obfuscation, payloads, permissions, polyglot, remote-code,
signatures, steganography, time-bomb, zip-tricks. Omit to run all checks (default).
extension-scanner.py — Analyze Firefox (and other browsers) extension XPI files for security risks and malware indicators.
Read README.md for information on how to interpret findings, limitations, and best practices for use.
This tool is intended for security researchers, analysts, and advanced users who want to perform a
comprehensive static analysis of browser extensions. It should work well for other browsers as well,
but this has only been tested on firefox.
Usage:
python3 extension-scanner.py [OPTIONS] targets...
Targets can be individual .xpi files or directories containing .xpi files. Use glob patterns (e.g. *.xpi) for convenience.
Available check types:
permissions Dangerous/broad manifest permissions and CSP issues
remote-code Background pages or service workers loaded from remote URLs
obfuscation eval/atob/encoding tricks, suspicious URLs, high-entropy strings
payloads Base64-encoded blobs decoded and scanned for executables/scripts
steganography PNG appended data (auto-decoded via base64/zlib/gzip), unknown chunks, LSB channel analysis
credentials Hardcoded API keys, tokens, passwords, private keys, IP addresses
file-meta Magic bytes, double extensions, suspicious filenames, file entropy
polyglot Files valid in two formats simultaneously (e.g. HTML+ZIP)
zip-tricks Path traversal, null bytes, duplicate entries, ZIP comments
cross-file HTML class tokens cross-referenced against JS localStorage keys
signatures Known strings from confirmed malicious extension families (qingcaila, YTMP4, etc.)
api-abuse Browser API calls indicating data theft or exfiltration (cookies, tabs, history, keylogger, clipboard, executeScript)
hidden-elements Invisible iframes, zero-dimension element injection, tracking pixels (new Image().src)
time-bomb Long-delay setTimeout, Date.now() gates, localStorage install-date checks, Math.random() gates
anti-analysis navigator.webdriver, zero-size window, bare debugger statement, performance.now() timing
Examples:
python3 extension-scanner.py extension.xpi
python3 extension-scanner.py *.xpi
python3 extension-scanner.py /path/to/extensions/
python3 extension-scanner.py a.xpi b.xpi --min-severity HIGH
python3 extension-scanner.py ext.xpi --scans obfuscation payloads
python3 extension-scanner.py ext.xpi --s steganography zip-tricks file-meta
python3 extension-scanner.py ext.xpi --verbose
python3 extension-scanner.py --update-blocklist
python3 extension-scanner.py --manifest
Tips:
- Make sure to source scanner-completions.sh from your .bashrc or .zshrc to enable tab completion for --scans categories and target file paths.
- Use --min-severity to focus on the most critical findings first.
- Use --scans to limit the analysis to specific categories of checks if you're looking for something specific or want to speed up the scan.
- Review the full manifest with --manifest for context on permissions, content scripts, and other extension metadata that can help interpret findings.
- Regularly update the blocklist with --update-blocklist to ensure the latest malicious domains are included in the checks.
Credits:
Developed by Ernos @ https://www.yourdev.net
Email: max at yourdev.net
GitHub: https://www.github.com/ernos/extension-scanner
════════════════════════════════════════════════════════════════════════════
XPI ANALYZER — example.xpi
════════════════════════════════════════════════════════════════════════════
Overall verdict: HIGH RISK
Findings: 1 CRITICAL 3 HIGH 2 MEDIUM 1 LOW
── CRITICAL ────────────────────────────────────────────────────────────
[CRITICAL ] [JS_OBFUSCATION] content.js
eval() call — can execute arbitrary code from strings
Evidence: var x = eval(atob("dmFyIGE9MTs…"))
── HIGH ────────────────────────────────────────────────────────────────
[HIGH ] [PERMISSION] manifest.json
Dangerous permission: 'nativeMessaging' — Can spawn native OS …
Evidence: permissions: ['nativeMessaging', 'storage', '<all_urls>']
…
当分析多个文件时,各个报告之后会打印一个对比表格,将所有扩展并排显示。
| 码 | 含义 |
|---|---|
0 | 无CRITICAL或HIGH发现 |
1 | 至少一个HIGH发现 |
2 | 至少一个CRITICAL发现 |
这使得它易于在CI管道或Shell脚本中使用:
python3 extension-scanner.py extension.xpi --min-severity HIGH
if [ $? -eq 2 ]; then echo "CRITICAL issues found!"; fi
HIGH发现。Maximilian Cornett
https://www.yourdev.net https://www.github.com/ernos
GNU General Public License - 本工具仅用于安全研究和防御性分析。
| 定时炸弹 | setTimeout/setInterval延迟≥5分钟;Date.now()算术门控;localStorage安装日期检查,在首次运行数天后激活行为;Math.random()阈值门控,仅在部分页面加载时触发。 |
| 反分析 | navigator.webdriver检查;零宽/高窗口比较;裸debugger语句;performance.now()算术用于基于计时的沙箱检测。 |
| 标志 | 描述 |
|---|
--update-blocklist | 从URLhaus和Peter Lowe的广告/恶意服务器列表获取最新的域名名单,与捆绑的快照合并,并保存到脚本旁边的blocklist.json。更新后退出。 |
targets | 一个或多个.xpi文件或目录 |
--min-severity | 过滤输出:CRITICAL、HIGH、MEDIUM、LOW、INFO(默认:INFO) |
--json | 以JSON文档而非可读报告形式输出发现 |
--verbose 或 -v | 打印manifest.json内容,并包含可疑模式周围5行左右的代码 |
--checks | 仅扫描指定的检查类别(见下文) |
| 可用的检查类别 | 类别中的检查描述 |
|---|
| permissions | 危险/宽泛的清单权限和CSP问题 |
| remote-code | 从远程URL加载的后台页面或Service Worker |
| obfuscation | eval/atob/编码技巧、可疑URL、高熵字符串 |
| payloads | 解码Base64编码的数据块并扫描可执行文件/脚本 |
| steganography | PNG追加数据、未知数据块、LSB通道分析 |
| credentials | 硬编码的API密钥、令牌、密码、私钥、IP地址 |
| file-meta | 魔数、双扩展名、可疑文件名、文件熵 |
| polyglot | 同时有效于两种格式的文件(如HTML+ZIP) |
| zip-tricks | 路径遍历、空字节、重复条目、ZIP注释 |
| cross-file | HTML类令牌与JS localStorage键的交叉引用 |
| api-abuse | 指示数据窃取或外泄的浏览器API调用(cookies、tabs、history、键盘、剪贴板)。当数据收集+网络发送出现在同一文件中时升级为CRITICAL。 |
| hidden-elements | 不可见iframe注入和追踪像素。当iframe隐藏并追加到DOM时升级为HIGH。 |
| time-bomb | 长延迟setTimeout、Date.now()算术门控、localStorage安装日期、Math.random()阈值。 |
| anti-analysis | navigator.webdriver、零尺寸窗口、裸debugger语句、performance.now()算术。 |