Surajit-Samanta/MalwareLens_AI

GitHub: Surajit-Samanta/MalwareLens_AI

MalwareLens AI 是一个基于双模型(RF+MLP)的恶意软件静态分析分诊工作台,提供分类、优先级划分、行为映射、攻击活动聚类和 YARA 规则起草功能。

Stars: 0 | Forks: 0

# MalwareLens AI 一个专为 AICS-108(智能恶意软件分析)构建的静态分析恶意软件分诊工作台。 它接收工程化的文件特征,并通过 Random Forest 基线和 scikit-learn MLP 对其进行处理,以将样本标记为类似恶意或类似良性,分配 P1/P2/P3 优先级,将高风险信号映射到 MBC/MITRE ATT&CK 行为类别,将样本聚类为可能的攻击活动,并自动起草可审查的 YARA 风格检测规则。 ## 功能 - **合成语料库生成** — 包含 6 个家族的 2,400 条合成记录(良性 + 5 个类似恶意家族),每条记录包含 22 个工程化特征。 - **双模型训练** — Random Forest 基线 + scikit-learn 深度 MLP,两者均封装 在 `StandardScaler` pipeline 中,并输出指标/混淆矩阵。 - **单样本分诊** — 对单个样本进行分类、恶意概率评估、优先级划分,以及 映射到 MBC/ATT&CK 的行为信号分析。 - **攻击活动聚类** — 在特征空间上使用 PCA + KMeans 将样本分组为 可能的攻击活动,并保存散点图和集群/家族细分图。 - **AI 辅助 YARA 规则生成** — 根据样本的 特征字符串起草可审查的 `.yar` 规则(明确标记为在实际投入运行前需要人工审查)。 - **真实数据交叉验证(高级扩展)** — 将 EMBER2018/2024 原始特征 记录映射到本项目的 schema 中,以便可以针对真实的静态特征运行相同的训练/评估 pipeline, 而不仅仅是合成数据。 ## 项目结构 ``` MalwareLens_AI/ ├── data │   ├── malwarelens_synthetic_features.csv │   ├── malwarelens_synthetic_features.csv:Zone.Identifier │   ├── malwarelens_synthetic_features.csv:Zone.Identifier:Zone.Identifier │   └── safe_samples │   ├── benign_admin.json │   ├── benign_admin.json:Zone.Identifier │   ├── benign_admin.json:Zone.Identifier:Zone.Identifier │   ├── botnet_like.json │   ├── botnet_like.json:Zone.Identifier │   ├── botnet_like.json:Zone.Identifier:Zone.Identifier │   ├── dropper_like.json │   ├── dropper_like.json:Zone.Identifier │   ├── dropper_like.json:Zone.Identifier:Zone.Identifier │   ├── infostealer_like.json │   ├── infostealer_like.json:Zone.Identifier │   ├── infostealer_like.json:Zone.Identifier:Zone.Identifier │   ├── loader_like.json │   ├── loader_like.json:Zone.Identifier │   ├── loader_like.json:Zone.Identifier:Zone.Identifier │   ├── ransomware_like.json │   ├── ransomware_like.json:Zone.Identifier │   └── ransomware_like.json:Zone.Identifier:Zone.Identifier ├── malwarelens_ai │   ├── analyze_sample.py │   ├── analyze_sample.py:Zone.Identifier │   ├── analyze_sample.py:Zone.Identifier:Zone.Identifier │   ├── cluster_campaigns.py │   ├── cluster_campaigns.py:Zone.Identifier │   ├── cluster_campaigns.py:Zone.Identifier:Zone.Identifier │   ├── config.py │   ├── config.py:Zone.Identifier │   ├── config.py:Zone.Identifier:Zone.Identifier │   ├── feature_extract_safe.py │   ├── feature_extract_safe.py:Zone.Identifier │   ├── feature_extract_safe.py:Zone.Identifier:Zone.Identifier │   ├── generate_rules.py │   ├── generate_rules.py:Zone.Identifier │   ├── generate_rules.py:Zone.Identifier:Zone.Identifier │   ├── __init__.py │   ├── __init__.py:Zone.Identifier │   ├── __init__.py:Zone.Identifier:Zone.Identifier │   ├── __pycache__ │   │   ├── analyze_sample.cpython-313.pyc │   │   ├── analyze_sample.cpython-313.pyc:Zone.Identifier │   │   ├── analyze_sample.cpython-313.pyc:Zone.Identifier:Zone.Identifier │   │   ├── cluster_campaigns.cpython-313.pyc │   │   ├── cluster_campaigns.cpython-313.pyc:Zone.Identifier │   │   ├── cluster_campaigns.cpython-313.pyc:Zone.Identifier:Zone.Identifier │   │   ├── config.cpython-313.pyc │   │   ├── config.cpython-313.pyc:Zone.Identifier │   │   ├── config.cpython-313.pyc:Zone.Identifier:Zone.Identifier │   │   ├── feature_extract_safe.cpython-313.pyc │   │   ├── feature_extract_safe.cpython-313.pyc:Zone.Identifier │   │   ├── feature_extract_safe.cpython-313.pyc:Zone.Identifier:Zone.Identifier │   │   ├── generate_rules.cpython-313.pyc │   │   ├── generate_rules.cpython-313.pyc:Zone.Identifier │   │   ├── generate_rules.cpython-313.pyc:Zone.Identifier:Zone.Identifier │   │   ├── __init__.cpython-313.pyc │   │   ├── __init__.cpython-313.pyc:Zone.Identifier │   │   ├── __init__.cpython-313.pyc:Zone.Identifier:Zone.Identifier │   │   ├── synthetic_corpus.cpython-313.pyc │   │   ├── synthetic_corpus.cpython-313.pyc:Zone.Identifier │   │   ├── synthetic_corpus.cpython-313.pyc:Zone.Identifier:Zone.Identifier │   │   ├── train_models.cpython-313.pyc │   │   ├── train_models.cpython-313.pyc:Zone.Identifier │   │   └── train_models.cpython-313.pyc:Zone.Identifier:Zone.Identifier │   ├── synthetic_corpus.py │   ├── synthetic_corpus.py:Zone.Identifier │   ├── synthetic_corpus.py:Zone.Identifier:Zone.Identifier │   ├── train_models.py │   ├── train_models.py:Zone.Identifier │   └── train_models.py:Zone.Identifier:Zone.Identifier ├── models │   ├── deep_mlp.joblib │   ├── deep_mlp.joblib:Zone.Identifier │   ├── deep_mlp.joblib:Zone.Identifier:Zone.Identifier │   ├── static_rf.joblib │   ├── static_rf.joblib:Zone.Identifier │   └── static_rf.joblib:Zone.Identifier:Zone.Identifier ├── notebooks │   ├── README_Notebooks.md │   ├── README_Notebooks.md:Zone.Identifier │   └── README_Notebooks.md:Zone.Identifier:Zone.Identifier ├── reports │   ├── analysis_report.json │   ├── analysis_report.json:Zone.Identifier │   ├── analysis_report.json:Zone.Identifier:Zone.Identifier │   ├── analysis_report.md │   ├── analysis_report.md:Zone.Identifier │   ├── analysis_report.md:Zone.Identifier:Zone.Identifier │   ├── campaign_clusters.png │   ├── campaign_clusters.png:Zone.Identifier │   ├── campaign_clusters.png:Zone.Identifier:Zone.Identifier │   ├── cluster_assignments.csv │   ├── cluster_assignments.csv:Zone.Identifier │   ├── cluster_assignments.csv:Zone.Identifier:Zone.Identifier │   ├── cluster_summary.json │   ├── cluster_summary.json:Zone.Identifier │   ├── cluster_summary.json:Zone.Identifier:Zone.Identifier │   ├── confusion_matrix.png │   ├── confusion_matrix.png:Zone.Identifier │   ├── confusion_matrix.png:Zone.Identifier:Zone.Identifier │   ├── metrics.json │   ├── metrics.json:Zone.Identifier │   └── metrics.json:Zone.Identifier:Zone.Identifier ├── rules │   ├── ai_assisted_triage.yar │   ├── ai_assisted_triage.yar:Zone.Identifier │   └── ai_assisted_triage.yar:Zone.Identifier:Zone.Identifier ├── scripts │ ├── __pycache__ │ │   ├── run_full_demo.cpython-313.pyc │ │   ├── run_full_demo.cpython-313.pyc:Zone.Identifier │ │   └── run_full_demo.cpython-313.pyc:Zone.Identifier:Zone.Identifier │ ├── run_full_demo.py │ ├── run_full_demo.py:Zone.Identifier │ ├── run_full_demo.py:Zone.Identifier:Zone.Identifier │ ├── run_full_demo.sh │ ├── run_full_demo.sh:Zone.Identifier │ └── run_full_demo.sh:Zone.Identifier:Zone.Identifier ├──LICENSE ├── README.md └── requirements.txt ``` ## 设置 ``` git clone https://github.com/Surajit-Samanta/MalwareLens_AI.git cd MalwareLens_AI python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt # YARA 是原生二进制文件,而不是 pip 包——请单独安装: sudo apt install -y yara # Debian/Ubuntu ``` ## 用法 ``` # 1. 生成合成语料库 + safe_samples/*.json python -m malwarelens_ai.synthetic_corpus # 2. 训练两个模型 python -m malwarelens_ai.train_models # 3. 分析单个样本 python -m malwarelens_ai.analyze_sample data/safe_samples/infostealer_like.json # 4. 聚类为可能的攻击活动 python -m malwarelens_ai.cluster_campaigns # 5. 生成 YARA 草案规则并检查 python -m malwarelens_ai.generate_rules data/safe_samples/ransomware_like.json yara rules/ai_assisted_triage.yar data/safe_samples/ransomware_like.json # 或者一次性运行步骤 1-5: python scripts/run_full_demo.py ``` ### 高级扩展:与真实 EMBER 数据进行交叉验证 ``` # 获取 EMBER2018 原始特征:https://github.com/elastic/ember # 获取 EMBER2024(通过 thrember):https://github.com/FutureComputing4AI/EMBER2024/ # 将一个 EMBER .jsonl 分片转换为本项目的特征 schema python -m malwarelens_ai.ember_corpus data/ember2018/train_features_0.jsonl 20000 # 在其上进行训练(如果两者都需要,请先备份您经过合成训练的模型/指标) python -c "from malwarelens_ai.train_models import train; train(csv_path='data/ember_features.csv')" # 或者直接针对已训练的模型批量分析多条 EMBER 记录 python -m malwarelens_ai.analyze_jsonl data/ember_2017_2/test_features.jsonl --limit 200 ``` ### 使用你自己的真实文件 ``` python -m malwarelens_ai.custom_corpus build data/my_malicious_like/ --label 1 python -m malwarelens_ai.custom_corpus build data/my_benign_like/ --label 0 --append python -c "from malwarelens_ai.train_models import train; train(csv_path='data/my_dataset.csv')" ``` ## 已知局限 - **合成数据极易区分。** 每个家族都是一个固定的基础特征 向量加上高斯噪声,因此两个模型在合成 数据集分割上的准确率/F1/AUC 均达到 ~1.0 —— 这是生成器造成的可分离性假象, 并不能证明其在真实世界中的检测能力。 - **EMBER 特征一致性差距。** 22 个项目特征中只有 8 个在 EMBER 的原始 schema 中具有真正的 对应项;其余 14 个(`ip_count`、 `base64_blob_count`、`powershell_hint_count`、`anti_analysis_hint_count` 以及一些 API 类别计数)对于派生自 EMBER 的记录默认为 `0`。 - **`MBC_MAP` 仅涵盖 5 个硬编码的特征类别** — 这些 键之外的任何恶意行为都永远不会被暴露出来。 - **`analyze_sample.py` 的 `strings_of_interest`** 假定 `obj['strings']` 是一个列表。如果 输入原始 EMBER 记录(其 `strings` 是一个统计字典),它会默默返回 字典的键名而不是真实的字符串内容 —— 请先使用 `ember_corpus.py` / `analyze_jsonl.py` 转换 EMBER 记录。 - **`sha256` 仅对真实文件是真实的。** 合成样本使用占位符 字符串(`synthetic-{family}-0001`),而不是实际的哈希值。 - **非确定性的重复运行。** 每次运行都会重新训练模型;如果不持久化 固定的模型工件,同一样本在不同运行中报告的 概率可能会发生微小变化。 ## 许可证 MIT — 请参阅 [LICENSE](LICENSE)。
标签:Apex, DAST, Python, YARA, 云安全监控, 云资产可视化, 威胁情报, 开发者工具, 恶意软件分析, 无后门, 机器学习, 逆向工具, 静态分析