mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00

将复杂的三文件插件架构(connector/exploiter/plugin)重构为简化的单文件插件架构, 大幅减少代码重复和维护成本,提升插件开发效率。 主要改进: • 将每个服务插件从3个文件简化为1个文件 • 删除过度设计的工厂模式、适配器模式等抽象层 • 消除plugins/services/、plugins/adapters/、plugins/base/复杂目录结构 • 实现直接的插件注册机制,提升系统简洁性 • 保持完全向后兼容,所有扫描功能和输出格式不变 重构统计: • 删除文件:100+个复杂架构文件 • 新增文件:20个简化的单文件插件 • 代码减少:每个插件减少60-80%代码量 • 功能增强:所有插件包含完整扫描和利用功能 已重构插件: MySQL, SSH, Redis, MongoDB, PostgreSQL, MSSQL, Oracle, Neo4j, Memcached, RabbitMQ, ActiveMQ, Cassandra, FTP, Kafka, LDAP, Rsync, SMTP, SNMP, Telnet, VNC 验证通过: 新系统编译运行正常,所有插件功能验证通过
105 lines
2.9 KiB
Go
105 lines
2.9 KiB
Go
package plugins
|
|
|
|
import (
|
|
"context"
|
|
"github.com/shadow1ng/fscan/common"
|
|
)
|
|
|
|
// =============================================================================
|
|
// 简化的插件基础架构 - 删除所有过度设计
|
|
// =============================================================================
|
|
|
|
// Plugin 插件接口 - 只保留必要的方法
|
|
type Plugin interface {
|
|
GetName() string
|
|
GetPorts() []int
|
|
Scan(ctx context.Context, info *common.HostInfo) *ScanResult
|
|
}
|
|
|
|
// Exploiter 利用器接口 - 可选实现,用于有利用功能的插件
|
|
type Exploiter interface {
|
|
Exploit(ctx context.Context, info *common.HostInfo, creds Credential) *ExploitResult
|
|
}
|
|
|
|
// ScanResult 扫描结果 - 删除所有冗余字段
|
|
type ScanResult struct {
|
|
Success bool // 扫描是否成功
|
|
Service string // 服务类型
|
|
Username string // 发现的用户名(弱密码)
|
|
Password string // 发现的密码(弱密码)
|
|
Banner string // 服务版本信息
|
|
Error error // 错误信息(如果失败)
|
|
}
|
|
|
|
// ExploitResult 利用结果 - 仅有利用功能的插件需要
|
|
type ExploitResult struct {
|
|
Success bool // 利用是否成功
|
|
Output string // 命令执行输出或操作结果
|
|
Error error // 错误信息
|
|
}
|
|
|
|
// Credential 凭据结构 - 只保留必要字段
|
|
type Credential struct {
|
|
Username string
|
|
Password string
|
|
KeyData []byte // SSH私钥等二进制数据
|
|
}
|
|
|
|
// =============================================================================
|
|
// 简化的注册系统 - 删除工厂模式垃圾
|
|
// =============================================================================
|
|
|
|
// PluginCreator 插件创建函数类型
|
|
type PluginCreator func() Plugin
|
|
|
|
// 全局插件注册表
|
|
var registry = make(map[string]PluginCreator)
|
|
|
|
// RegisterPlugin 注册插件 - 直接注册函数,不要工厂
|
|
func RegisterPlugin(name string, creator PluginCreator) {
|
|
registry[name] = creator
|
|
}
|
|
|
|
// GetPlugin 获取插件实例
|
|
func GetPlugin(name string) Plugin {
|
|
if creator, exists := registry[name]; exists {
|
|
return creator()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetAllPlugins 获取所有已注册插件名称
|
|
func GetAllPlugins() []string {
|
|
names := make([]string, 0, len(registry))
|
|
for name := range registry {
|
|
names = append(names, name)
|
|
}
|
|
return names
|
|
}
|
|
|
|
// =============================================================================
|
|
// 通用辅助函数
|
|
// =============================================================================
|
|
|
|
// GenerateCredentials 生成测试凭据列表
|
|
func GenerateCredentials(service string) []Credential {
|
|
// 获取用户名字典
|
|
usernames := common.Userdict[service]
|
|
if len(usernames) == 0 {
|
|
// 默认用户名
|
|
usernames = []string{"root", "admin", service}
|
|
}
|
|
|
|
// 生成用户名密码组合
|
|
var credentials []Credential
|
|
for _, username := range usernames {
|
|
for _, password := range common.Passwords {
|
|
credentials = append(credentials, Credential{
|
|
Username: username,
|
|
Password: password,
|
|
})
|
|
}
|
|
}
|
|
|
|
return credentials
|
|
} |