package core import ( "context" "fmt" "github.com/shadow1ng/fscan/common" "github.com/shadow1ng/fscan/plugins/services" ) // PluginAdapter 插件适配器 // 提供从新插件系统到旧扫描接口的适配 type PluginAdapter struct{} // NewPluginAdapter 创建插件适配器 func NewPluginAdapter() *PluginAdapter { return &PluginAdapter{} } // 全局插件适配器实例 var GlobalPluginAdapter = NewPluginAdapter() // GetAllPluginNames 获取所有插件名称 func (pa *PluginAdapter) GetAllPluginNames() []string { return services.GetAllPlugins() } // PluginExists 检查插件是否存在 func (pa *PluginAdapter) PluginExists(name string) bool { plugin := services.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 := services.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.(services.Exploiter); ok && result.Username != "" { creds := services.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 方法