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 验证通过: 新系统编译运行正常,所有插件功能验证通过
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package core
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/shadow1ng/fscan/common"
|
|
"github.com/shadow1ng/fscan/plugins"
|
|
)
|
|
|
|
// PluginAdapter 插件适配器
|
|
// 提供从新插件系统到旧扫描接口的适配
|
|
type PluginAdapter struct{}
|
|
|
|
// NewPluginAdapter 创建插件适配器
|
|
func NewPluginAdapter() *PluginAdapter {
|
|
return &PluginAdapter{}
|
|
}
|
|
|
|
// 全局插件适配器实例
|
|
var GlobalPluginAdapter = NewPluginAdapter()
|
|
|
|
// GetAllPluginNames 获取所有插件名称
|
|
func (pa *PluginAdapter) GetAllPluginNames() []string {
|
|
return plugins.GetAllPlugins()
|
|
}
|
|
|
|
// PluginExists 检查插件是否存在
|
|
func (pa *PluginAdapter) PluginExists(name string) bool {
|
|
plugin := plugins.GetPlugin(name)
|
|
return plugin != nil
|
|
}
|
|
|
|
// 已移除未使用的 GetPluginPorts 方法
|
|
|
|
// 已移除未使用的 GetPluginsByPort 方法
|
|
|
|
// 已移除未使用的 GetPluginsByType 方法
|
|
|
|
// ScanWithPlugin 使用插件进行扫描
|
|
func (pa *PluginAdapter) ScanWithPlugin(pluginName string, info *common.HostInfo) error {
|
|
common.LogDebug(fmt.Sprintf("使用新插件架构扫描: %s", pluginName))
|
|
|
|
// 获取插件实例
|
|
plugin := plugins.GetPlugin(pluginName)
|
|
if plugin == nil {
|
|
return fmt.Errorf("插件 %s 不存在", pluginName)
|
|
}
|
|
|
|
// 执行扫描
|
|
result := plugin.Scan(context.Background(), info)
|
|
|
|
// 处理扫描结果
|
|
if result == nil {
|
|
common.LogDebug(fmt.Sprintf("插件 %s 返回了空结果", pluginName))
|
|
} else if result.Success {
|
|
common.LogDebug(fmt.Sprintf("插件 %s 扫描成功", pluginName))
|
|
|
|
// 如果插件支持利用功能且发现了弱密码,执行利用
|
|
if exploiter, ok := plugin.(plugins.Exploiter); ok && result.Username != "" {
|
|
creds := plugins.Credential{
|
|
Username: result.Username,
|
|
Password: result.Password,
|
|
}
|
|
exploitResult := exploiter.Exploit(context.Background(), info, creds)
|
|
if exploitResult != nil && exploitResult.Success {
|
|
common.LogDebug(fmt.Sprintf("插件 %s 利用成功", pluginName))
|
|
}
|
|
}
|
|
} else {
|
|
common.LogDebug(fmt.Sprintf("插件 %s 扫描失败: %v", pluginName, result.Error))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// 已移除未使用的 FilterPluginsByType 方法
|
|
|
|
// 已移除未使用的 GetServicePlugins 方法
|
|
|
|
// 已移除未使用的 GetWebPlugins 方法
|
|
|
|
// 已移除未使用的 GetLocalPlugins 方法
|