Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
magika — 快速且准确的AI驱动文件内容类型检测 | Kitploit
工具/GitHubGitHub/google/magika
通用工具静态分析代码分析取证分析恶意软件分析机器学习
GitHubgoogle/magika

magika

快速且准确的AI驱动文件内容类型检测

查看仓库
17.9k1.1k23天前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享
网站

Magika

image NPM Version image image Go Version

OpenSSF Best Practices CodeQL Actions status PyPI Monthly Downloads PyPI Downloads

Magika 是一款基于 AI 的新型文件类型检测工具,依靠深度学习的最新进展提供精确的检测。在幕后,Magika 使用了一个定制的高度优化模型,该模型仅重约几 MB,即使在单个 CPU 上运行,也能在毫秒内实现精准的文件识别。Magika 在包含约 1 亿个样本、覆盖 200 多种内容类型(包括二进制和文本文件格式)的数据集上进行了训练和评估,在我们的测试集上达到了平均约 99% 的准确率。

以下是 Magika 命令行输出的示例:

Magika 被大规模用于提升 Google 用户的安全性,通过将 Gmail、Drive 和 Safe Browsing 的文件路由到适当的安全和内容策略扫描器,每周处理数千亿样本。Magika 也已集成到 VirusTotal(示例)和 abuse.ch(示例)中。

更多背景信息可阅读我们在 Google 的 OSS 博客上发布的首篇公告,查阅 Magika 网站,以及阅读我们的 研究论文,该论文已被 IEEE/ACM 国际软件工程大会 (ICSE) 2025 收录。

你也可以无需安装,直接使用我们的 网页演示 来体验 Magika,该演示在浏览器中本地运行!

亮点

  • 提供用 Rust 编写的命令行工具、Python API,以及 Rust、JavaScript/TypeScript 的额外绑定(带有实验性的 npm 包,该包用于驱动我们的 网页演示)和 GoLang 绑定(开发中)。
  • 在包含约 1 亿个文件、覆盖 200 多种内容类型 的数据集上进行了训练和评估。
  • 在我们的测试集上,Magika 达到了约 99% 的平均精确率和召回率,优于现有方法——尤其是在文本内容类型上。
  • 模型加载完成后(一次性开销),每个文件的推理时间约为 5 毫秒,即使在单个 CPU 上运行也是如此。
  • 你可以同时调用 Magika 处理数千个文件。也可以使用 -r 递归扫描目录。
  • 推理时间近乎恒定,与文件大小无关;Magika 仅使用文件内容的有限子集。
  • Magika 使用按内容类型设置的阈值系统,决定是“信任”模型的预测,还是返回通用标签,例如“通用文本文档”或“未知二进制数据”。
  • 通过不同的预测模式,如 high-confidence、medium-confidence 和 best-guess,可以控制对错误的容忍度。
  • 客户端和绑定已经开源,更多内容即将推出!

目录

  1. 入门指南
    1. 安装
    2. 快速启动
  2. 文档
  3. 安全漏洞
  4. 许可证
  5. 免责声明

Getting Started

Installation

命令行工具

Magika 提供了用 Rust 编写的 CLI,可通过多种方式安装。

通过 magika Python 包:

root@kitploit:~
pipx install magika

通过 brew(macOS / Linux):

root@kitploit:~
brew install magika

通过安装脚本:

root@kitploit:~
curl -LsSf https://securityresearch.google/magika/install.sh | sh

或:

root@kitploit:~
powershell -ExecutionPolicy Bypass -c "irm https://securityresearch.google/magika/install.ps1 | iex"

通过 magika-cli Rust 包:

root@kitploit:~
cargo install --locked magika-cli

Python 包

root@kitploit:~
pip install magika

JavaScript 包

root@kitploit:~
npm install magika

Quick Start

以下是一些快速示例,帮助你快速上手。

要了解 Magika 的内部工作机制,请参阅 Magika 网站上的 核心概念 部分。

命令行工具示例

root@kitploit:~
% cd tests_data/basic && magika -r * | head
asm/code.asm: Assembly (code)
batch/simple.bat: DOS batch file (code)
c/code.c: C source (code)
css/code.css: CSS source (code)
csv/magika_test.csv: CSV document (code)
dockerfile/Dockerfile: Dockerfile (code)
docx/doc.docx: Microsoft Word 2007+ document (document)
docx/magika_test.docx: Microsoft Word 2007+ document (document)
eml/sample.eml: RFC 822 mail (text)
empty/empty_file: Empty file (inode)
root@kitploit:~
% magika ./tests_data/basic/python/code.py --json
[
  {
    "path": "./tests_data/basic/python/code.py",
    "result": {
      "status": "ok",
      "value": {
        "dl": {
          "description": "Python source",
          "extensions": [
            "py",
            "pyi"
          ],
          "group": "code",
          "is_text": true,
          "label": "python",
          "mime_type": "text/x-python"
        },
        "output": {
          "description": "Python source",
          "extensions": [
            "py",
            "pyi"
          ],
          "group": "code",
          "is_text": true,
          "label": "python",
          "mime_type": "text/x-python"
        },
        "score": 0.996999979019165
      }
    }
  }
]
root@kitploit:~
% cat tests_data/basic/ini/doc.ini | magika -
-: INI configuration file (text)
root@kitploit:~
% magika --help
Determines file content types using AI

Usage: magika [OPTIONS] [PATH]...

Arguments:
  [PATH]...
          List of paths to the files to analyze.

          Use a dash (-) to read from standard input (can only be used once).

Options:
  -r, --recursive
          Identifies files within directories instead of identifying the directory itself

      --no-dereference
          Identifies symbolic links as is instead of identifying their content by following them

      --colors
          Prints with colors regardless of terminal support

      --no-colors
          Prints without colors regardless of terminal support

  -s, --output-score
          Prints the prediction score in addition to the content type

  -i, --mime-type
          Prints the MIME type instead of the content type description

  -l, --label
          Prints a simple label instead of the content type description

      --json
          Prints in JSON format

      --jsonl
          Prints in JSONL format

      --format <CUSTOM>
          Prints using a custom format (use --help for details).

          The following placeholders are supported:

            %p  The file path
            %l  The unique label identifying the content type
            %d  The description of the content type
            %g  The group of the content type
            %m  The MIME type of the content type
            %e  Possible file extensions for the content type
            %s  The score of the content type for the file
            %S  The score of the content type for the file in percent
            %b  The model output if overruled (empty otherwise)
            %%  A literal %

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

更多 CLI 示例和文档,请访问 https://crates.io/crates/magika-cli。

Python 示例

root@kitploit:~
>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_bytes(b'function log(msg) {console.log(msg);}')
>>> print(res.output.label)
javascript
root@kitploit:~
>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_path('./tests_data/basic/ini/doc.ini')
>>> print(res.output.label)
ini
root@kitploit:~
>>> from magika import Magika
>>> m = Magika()
>>> with open('./tests_data/basic/ini/doc.ini', 'rb') as f:
>>>     res = m.identify_stream(f)
>>> print(res.output.label)
ini

更多 Python 模块示例和文档,请参阅 Python Magika 模块 部分。

Documentation

请查阅 Magika 网站 获取关于以下内容的详细文档:

  • 核心概念
    • Magika 的工作原理
    • 模型与内容类型
    • 预测模式
    • 理解输出
  • CLI 与绑定(Python 模块、JavaScript 模块等)
  • 贡献指南
  • 常见问题
  • 等等

Security Vulnerabilities

请直接通过 [email protected] 联系我们。

License

Apache 2.0;详细信息请参见 LICENSE。

Disclaimer

本项目并非 Google 的官方项目。Google 不提供任何支持,并且 Google 特此声明不对其质量、适销性或特定用途的适用性承担任何保证。

下载工具