fscan/Plugins/base/interfaces.go
ZacharyZcR 43f210ffc6 feat: 实现新一代插件注册系统完全替代传统手动注册模式
- 重构插件注册架构采用现代工厂模式和自动发现机制
- 新增完整的插件元数据管理系统支持版本能力标签等信息
- 实现智能插件适配器提供向后兼容的桥接功能
- 建立MySQL Redis SSH三个标准插件作为新架构参考实现
- 优化插件扫描逻辑支持按端口按类型的智能查询和过滤
- 添加国际化支持和完善的文档体系
- 代码量减少67%维护成本大幅降低扩展性显著提升

新架构特点:
- 零配置插件注册import即用
- 工厂模式延迟初始化和依赖注入
- 丰富元数据系统和能力声明
- 完全解耦的模块化设计
- 面向未来的可扩展架构

测试验证: MySQL和Redis插件功能完整包括弱密码检测未授权访问检测和自动利用攻击
2025-08-07 11:28:34 +08:00

162 lines
5.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package base
import (
"context"
"github.com/shadow1ng/fscan/common"
)
// =============================================================================
// 核心接口定义
// =============================================================================
// Scanner 扫描器接口 - 负责发现和识别服务
type Scanner interface {
// Scan 执行扫描操作
Scan(ctx context.Context, info *common.HostInfo) (*ScanResult, error)
// GetName 获取扫描器名称
GetName() string
// GetCapabilities 获取扫描器支持的能力
GetCapabilities() []Capability
}
// Exploiter 利用器接口 - 负责各种攻击利用
type Exploiter interface {
// Exploit 执行利用操作
Exploit(ctx context.Context, info *common.HostInfo, creds *Credential) (*ExploitResult, error)
// GetExploitMethods 获取支持的利用方法
GetExploitMethods() []ExploitMethod
// IsExploitSupported 检查是否支持指定的利用方法
IsExploitSupported(method ExploitType) bool
}
// Plugin 完整插件接口 - 组合扫描和利用功能
type Plugin interface {
Scanner
Exploiter
// Initialize 初始化插件
Initialize() error
// GetMetadata 获取插件元数据
GetMetadata() *PluginMetadata
}
// =============================================================================
// 支持类型定义
// =============================================================================
// Capability 插件能力类型
type Capability string
const (
CapWeakPassword Capability = "weak_password" // 弱密码检测
CapUnauthorized Capability = "unauthorized" // 未授权访问
CapSQLInjection Capability = "sql_injection" // SQL注入
CapCommandExecution Capability = "command_execution" // 命令执行
CapFileUpload Capability = "file_upload" // 文件上传
CapFileWrite Capability = "file_write" // 文件写入
CapPrivilegeEsc Capability = "privilege_esc" // 提权
CapDataExtraction Capability = "data_extraction" // 数据提取
CapDenialOfService Capability = "denial_of_service" // 拒绝服务
CapInformationLeak Capability = "information_leak" // 信息泄露
)
// ExploitType 利用类型
type ExploitType string
const (
ExploitWeakPassword ExploitType = "weak_password"
ExploitUnauthorized ExploitType = "unauthorized"
ExploitSQLInjection ExploitType = "sql_injection"
ExploitCommandExec ExploitType = "command_exec"
ExploitFileWrite ExploitType = "file_write"
ExploitPrivilegeEsc ExploitType = "privilege_esc"
ExploitDataExtraction ExploitType = "data_extraction"
)
// ExploitMethod 利用方法定义
type ExploitMethod struct {
Type ExploitType // 利用类型
Name string // 方法名称
Description string // 描述
Priority int // 优先级1-1010最高
Conditions []string // 前置条件
Handler ExploitHandler // 处理函数
}
// ExploitHandler 利用处理函数类型
type ExploitHandler func(ctx context.Context, info *common.HostInfo, creds *Credential) (*ExploitResult, error)
// =============================================================================
// 数据结构定义
// =============================================================================
// PluginMetadata 插件元数据
type PluginMetadata struct {
Name string // 插件名称
Version string // 版本
Author string // 作者
Description string // 描述
Category string // 分类service/web/local
Ports []int // 默认端口
Protocols []string // 支持的协议
Tags []string // 标签
}
// Credential 通用凭据结构
type Credential struct {
Username string // 用户名
Password string // 密码
Domain string // 域名用于AD等
KeyData []byte // 密钥数据SSH私钥等
Token string // 令牌
Extra map[string]string // 扩展字段
}
// ScanResult 扫描结果
type ScanResult struct {
Success bool // 是否成功
Error error // 错误信息
Service string // 服务类型
Version string // 版本信息
Banner string // 服务横幅
Credentials []*Credential // 发现的凭据
Vulnerabilities []Vulnerability // 发现的漏洞
Extra map[string]interface{} // 扩展信息
}
// ExploitResult 利用结果
type ExploitResult struct {
Success bool // 是否成功
Error error // 错误信息
Type ExploitType // 利用类型
Method string // 利用方法
Output string // 命令输出或结果
Files []string // 创建/修改的文件
Shell *ShellInfo // 获得的Shell信息
Data map[string]interface{} // 提取的数据
Extra map[string]interface{} // 扩展信息
}
// Vulnerability 漏洞信息
type Vulnerability struct {
ID string // 漏洞ID (CVE等)
Name string // 漏洞名称
Severity string // 严重程度
Description string // 描述
References []string // 参考链接
}
// ShellInfo Shell信息
type ShellInfo struct {
Type string // Shell类型reverse/bind/webshell
Host string // 连接主机
Port int // 连接端口
User string // 运行用户
OS string // 操作系统
Privileges string // 权限级别
}