dimeko/malsmug
GitHub: dimeko/malsmug
一款结合动态沙箱执行与静态 AST 分析的恶意 JavaScript 代码检测与分析工具。
Stars: 7 | Forks: 0
#### malsmug:JavaScript 分析器
`malsmug` 是一个用于 JavaScript 文件的动态分析器。静态分析组件目前正处于构建和设计阶段。它主要侧重于在沙箱中运行 JavaScript 文件,记录相关的入侵指标(IoC),最后将它们发送到主应用程序进行进一步分析。最终输出是一系列发现结果,可帮助判定给定的 JavaScript 文件是否为恶意文件。
架构图:

在构建之前,我们必须设置 nightly 构建器,以便能够使用 `oxc`
```
rustup override set nightly --path .
# 需要比 1.94.0 更新的 rust 才能安装 sqlx-cli
rustup update
# 安装 sqlx-cli 以管理数据库
cargo install sqlx-cli
```
构建 RabbitMQ 和沙箱/消费者镜像:
```
cp .env.example .env
docker compose build
```
主应用程序用法:
用法:
```
$ cargo run -- --help
Usage: malsmug [OPTIONS] --bindhost --bindport
Options:
--bindhost
--bindport
-v, --verbose
-d, --debug
-h, --help Print help
```
要运行完整的应用程序,请按给定的顺序执行以下步骤:
1. 启动 RabbitMQ:
docker compose up rabbitmq
2. 启动主应用程序:
cargo sqlx database create
cargo sqlx migrate run
cargo sqlx prepare
cargo run -- --bindhost 127.0.0.1 --bindport 11234 -v -d
3. 启动消费者/沙箱容器
# LOG_LEVEL = debug | info | warn | error
docker compose run -e LOG_LEVEL=debug sandbox
最后,所有程序都已运行。现在您可以向应用程序 API 提交文件,并同步获取分析结果。
- 提交文件进行分析
- `file_for_analysis`:本地 JavaScript 文件的路径
- `bait_websites`:以逗号分隔的网站列表,用于测试您的样本
- `dynamic_analysis`:执行动态分析
- `static_analysis`:执行静态分析
curl --location 'http://127.0.0.1:11234/analyse-file' \
--form 'file_for_analysis=@"/file/for/analysis/local-path/file.js"' \
--form 'bait_websites="https://facebook.com,https://google.com,https://cnn.com"' \
--form 'dynamic_analysis="true"'
response:
{
"r": {
"msg": "file was submitted",
"file_hash": "879a49c8feeb647fd906e5bb6bb1375352f5677c5cd2546a57093edaa7bce8b9",
"file_analysis_report_uid": "1ecee8d4-cab7-4a50-8767-6ca21c0e2557"
}
}
- 提交页面进行分析
- `page_for_analysis`:您想要分析的可疑页面
curl --location 'http://127.0.0.1:11234/analyse-file' \
--form 'page_for_analysis="https://malicious.com"'
response:
{
"r": {
"msg": "file was submitted",
"file_hash": "879a49c8feeb647fd906e5bb6bb1375352f5677c5cd2546a57093edaa7bce8b9",
"file_analysis_report_uid": "1ecee8d4-cab7-4a50-8767-6ca21c0e2557"
}
}
- 根据特定的文件哈希获取分析报告:
curl --location --request GET 'http://127.0.0.1:11234/get-file-reports/879a49c8feeb647fd906e5bb6bb1375352f5dd5c5cd2546a57093edaa7bce8b9'
response:
{
"r": {
"file_reports": [
{
"uid": "56827f93-41f4-4003-b519-7275a5e00251",
"name": "suspocious_file.js",
"file_hash": "879a49c8feeb647fd906e5bb6bb1375352f5677c5cd2546a57093edaa7bce8b9",
"file_name": "suspocious_file.js",
"file_extension": "js",
"last_analysis_id": "17961f76-d721-4ceb-b38e-bcbbc8ee6783",
"has_been_analysed": true,
"dynamic_analysis": true,
"static_analysis": true,
"severity": 8,
"bait_websites": [
"https://facebook.com",
"https://google.com",
"https://cnn.com"
],
"findings": [
{
"type": "Dynamic",
"executed_on": "https://google.com",
"severity": "High",
"poc": "//bad.websites.com/js?i=&ran=bad-bad-bad",
"title": "bad reputation url called"
},
{
"type": "Static",
"executed_on": "",
"severity": "Moderate",
"poc": "",
"title": "html element adhoc write to dom"
},
{
"type": "Static",
"executed_on": "",
"severity": "High",
"poc": "execScript",
"title": "execution of known suspicious commands"
},
]
}
]
}
}
- 通过 UID 删除分析报告:
curl --location --request DELETE 'http://127.0.0.1:11234/delete-file-report/:file_analysis_report_uid'
response:
{
"r": {
"file_reports_deleted": 1
}
}
- 通过哈希删除分析报告:
curl --location --request DELETE 'http://127.0.0.1:11234/delete-file-reports/ada64db98cef41e0e385ca1553aajc160a868d03b4318be5abb26f4d4310b6c1'
response:
{
"r": {
"file_reports_deleted": 17
}
}
#### 静态分析 IoC
- 包含 eval 的表达式 (AST)
- 包含 execScript 的表达式 (AST)
- 调用 `document.write` 且参数可能为 HTML 元素(正则表达式或 AST)
`oxc` 抽象语法树中的一些标识符:
- 静态成员表达式函数调用:`CallExpression -> callee:StaticMemberExpression -> object: Identifier . property: IdentifierName -> arguments: Vec[BinaryExpression (rec)]`
- 计算成员表达式函数调用:`CallExpression -> callee:ComputedMemberExpression -> object: Identifier . property: IdentifierName -> arguments: Vec[BinaryExpression (rec)]`
#### 动态分析 IoC
- 调用 `cookie.get`
- 调用 `cookie.set`
- 调用 `localStorage.getItems`
- 调用 `localStorage.setItems`
- 调用 `document.write`
- 调用 `window.eval`
- 调用 `window.execScript`
- 调用 `document.addEventListener`
- 创建可能触发网络调用的新 HTML 元素
- 较低的域名信誉评分
- 通过 HTTP 请求发送的可疑表单输入数据
标签:Docker, Rust, 可视化界面, 安全, 安全防御评估, 恶意代码分析, 沙箱, 网络流量审计, 请求拦截, 超时处理, 通知系统, 配置文件