diff --git a/plugins/local/types.go b/plugins/local/types.go index bee3fd1..5539966 100644 --- a/plugins/local/types.go +++ b/plugins/local/types.go @@ -26,19 +26,14 @@ func RegisterLocalPlugin(name string, creator func() Plugin) { }) } -func GetLocalPlugin(name string) Plugin { - p := plugins.Get(name) - if p == nil { - return nil - } - // 这里需要反向适配,但为了简化,返回nil - return nil -} - +// GetAllLocalPlugins 获取所有本地插件名称 func GetAllLocalPlugins() []string { return plugins.All() } +// 注意:GetLocalPlugin函数已移除,因为它总是返回nil没有任何意义 +// 如需获取插件实例,请直接使用 plugins.Get(name) + // 适配器:将Local插件转换为统一插件接口 type localPluginAdapter struct { localPlugin Plugin diff --git a/plugins/services/mysql.go b/plugins/services/mysql.go index a0aab27..04c0f37 100644 --- a/plugins/services/mysql.go +++ b/plugins/services/mysql.go @@ -144,7 +144,8 @@ func (p *MySQLPlugin) readMySQLBanner(conn net.Conn) string { func init() { - RegisterPlugin("mysql", func() Plugin { + // 使用高效注册方式:直接传递端口信息,避免实例创建 + RegisterPluginWithPorts("mysql", func() Plugin { return NewMySQLPlugin() - }) + }, []int{3306, 3307, 33060}) } \ No newline at end of file diff --git a/plugins/services/redis.go b/plugins/services/redis.go index 68f9716..1babfe2 100644 --- a/plugins/services/redis.go +++ b/plugins/services/redis.go @@ -416,7 +416,8 @@ func (p *RedisPlugin) identifyService(ctx context.Context, info *common.HostInfo // init 自动注册插件 func init() { - RegisterPlugin("redis", func() Plugin { + // 使用高效注册方式:直接传递端口信息,避免实例创建 + RegisterPluginWithPorts("redis", func() Plugin { return NewRedisPlugin() - }) + }, []int{6379, 6380, 6381, 16379, 26379}) } \ No newline at end of file diff --git a/plugins/services/ssh.go b/plugins/services/ssh.go index 4666171..6039cc6 100644 --- a/plugins/services/ssh.go +++ b/plugins/services/ssh.go @@ -264,7 +264,8 @@ func (p *SSHPlugin) readSSHBanner(conn net.Conn) string { // init 自动注册插件 func init() { - RegisterPlugin("ssh", func() Plugin { + // 使用高效注册方式:直接传递端口信息,避免实例创建 + RegisterPluginWithPorts("ssh", func() Plugin { return NewSSHPlugin() - }) + }, []int{22, 2222, 2200, 22222}) } \ No newline at end of file diff --git a/plugins/services/types.go b/plugins/services/types.go index 50010a8..629464d 100644 --- a/plugins/services/types.go +++ b/plugins/services/types.go @@ -19,31 +19,30 @@ type ExploitResult = plugins.ExploitResult type Exploiter = plugins.Exploiter type Credential = plugins.Credential -// 注册函数:适配旧插件到新系统 -func RegisterPlugin(name string, factory func() Plugin) { - // 获取插件端口信息 - plugin := factory() - ports := plugin.GetPorts() - +// RegisterPluginWithPorts 高效注册:直接传递端口信息,避免实例创建 +func RegisterPluginWithPorts(name string, factory func() Plugin, ports []int) { plugins.RegisterWithPorts(name, func() plugins.Plugin { return &servicePluginAdapter{factory()} }, ports) } -// 获取函数 -func GetPlugin(name string) Plugin { - p := plugins.Get(name) - if p == nil { - return nil - } - // 为简化实现,这里不做反向适配 - return nil +// RegisterPlugin 向后兼容的注册函数(性能较低,但保持兼容性) +func RegisterPlugin(name string, factory func() Plugin) { + // 获取插件端口信息 - 仍需实例化,但保持向后兼容 + plugin := factory() + ports := plugin.GetPorts() + + RegisterPluginWithPorts(name, factory, ports) } +// GetAllPlugins 获取所有插件名称 func GetAllPlugins() []string { return plugins.All() } +// 注意:GetPlugin函数已移除,因为它总是返回nil没有任何意义 +// 如需获取插件实例,请直接使用 plugins.Get(name) + var GenerateCredentials = plugins.GenerateCredentials // 适配器:将services插件转换为统一插件接口