Skip to content

Latest commit

 

History

History
93 lines (73 loc) · 3.32 KB

architecture.md

File metadata and controls

93 lines (73 loc) · 3.32 KB

Cerberus 系统架构

1. 总体架构

Cerberus 采用 Python + C++ 混合架构。这种设计旨在结合 Python 的开发效率与 C++ 的执行性能。

graph TD
    User[用户] --> CLI[命令行接口 (Python)]
    User --> WebUI[Web 界面 (Python/JS) *计划中*]
    
    subgraph "Python Layer (控制与逻辑)"
        CLI --> Controller[核心控制器]
        WebUI --> Controller
        Controller --> PluginMgr[插件管理器]
        Controller --> ReportGen[报告生成器]
        Controller --> ConfigMgr[配置管理器]
    end
    
    subgraph "Binding Layer (PyBind11)"
        Interface[C++ 扩展接口]
    end
    
    subgraph "C++ Layer (高性能核心)"
        Controller --调用--> Interface
        Interface --> CoreEngine[核心引擎]
        CoreEngine --> NetScanner[网络扫描器]
        CoreEngine --> ProtoParser[协议解析器]
        CoreEngine --> ThreadPool[线程池]
    end
    
    PluginMgr --加载--> Plugins[自定义插件集]
    NetScanner --网络流量--> Target[目标系统]
Loading

2. 模块详解

2.1 Python 层 (应用层)

Python 层是用户交互的入口,负责编排任务、管理配置和处理结果。

  • cerberus.main: 程序入口,解析命令行参数。
  • Plugin Manager: 动态加载 plugins/ 目录下的 Python 脚本,使系统功能可扩展。
  • Data Processor: 对扫描结果进行清洗、去重和格式化。

2.2 C++ 层 (核心层)

C++ 层作为 Python 的扩展模块存在 (_cerberus),处理性能敏感的操作。

  • Cerberus Class: 暴露给 Python 的主要接口类。
  • Network Scanner: 使用原始套接字或异步 I/O (Asio) 进行高速端口扫描 (SYN/ACK)。
  • Concurrency: 内部维护线程池,避免 Python GIL 对网络 I/O 的限制。

2.3 交互机制

  • 使用 pybind11 将 C++ 类和函数映射为 Python 对象。
  • 数据传递:
    • Python -> C++: 传递配置参数、目标 IP 列表等 (std::vector, std::string)。
    • C++ -> Python: 返回扫描结果结构体 (通过 pybind11 转换为 Python dict 或自定义对象)。

3. 目录结构设计

Cerberus/
├── cerberus/               # Python 包
│   ├── core/               # Python 核心逻辑
│   ├── plugins/            # 插件目录
│   ├── utils/              # 工具函数
│   └── web/                # Web UI 代码 (未来)
├── cpp/                    # C++ 源码
│   ├── include/            # 头文件
│   └── src/                # 源文件
│       ├── engine/         # 扫描引擎实现
│       └── bindings/       # PyBind11 绑定代码
├── docs/                   # 项目文档
└── tests/                  # 测试用例

4. 扩展性设计

插件系统

Cerberus 将定义一个标准的 BasePlugin 类。用户只需继承该类并实现 run() 方法,即可添加新的检测功能。

# 插件示例
class MyPlugin(BasePlugin):
    def info(self):
        return {"name": "Example", "version": "1.0"}
        
    def run(self, target):
        # 执行检测逻辑
        pass

数据流

  1. 用户输入目标 -> 2. Python 解析并生成任务 -> 3. 调用 C++ 接口执行扫描 -> 4. C++ 返回原始数据 -> 5. Python 插件进一步分析 -> 6. 生成报告。