package plugins import ( "context" "strings" "sync" "github.com/shadow1ng/fscan/common" ) // Plugin 统一插件接口 - 消除过度设计 // // Linus哲学:"好代码没有特殊情况" // 之前:3个不同的接口做同样的事情 // 现在:1个接口统治所有插件 type Plugin interface { Name() string Scan(ctx context.Context, info *common.HostInfo) *Result } // Result 统一结果结构 - 合并所有类型 type Result struct { Success bool Service string Username string Password string Banner string Output string // web/local插件使用 Error error // Web插件字段 Title string // 网页标题 Status int // HTTP状态码 Server string // 服务器信息 Length int // 响应长度 VulInfo string // 漏洞信息 } // Exploiter 利用接口 - 保持向后兼容 type Exploiter interface { Exploit(ctx context.Context, info *common.HostInfo, creds Credential) *ExploitResult } // ExploitResult 利用结果 type ExploitResult struct { Success bool Output string Error error } // Credential 认证凭据 type Credential struct { Username string Password string KeyData []byte } // 全局插件注册表 - 一个数据结构解决所有问题 var ( plugins = make(map[string]func() Plugin) mutex sync.RWMutex ) // Register 注册插件 - 一个函数统治所有注册 func Register(name string, factory func() Plugin) { mutex.Lock() defer mutex.Unlock() plugins[name] = factory } // Get 获取插件实例 func Get(name string) Plugin { mutex.RLock() defer mutex.RUnlock() if factory, exists := plugins[name]; exists { return factory() } return nil } // All 获取所有插件名称 func All() []string { mutex.RLock() defer mutex.RUnlock() names := make([]string, 0, len(plugins)) for name := range plugins { names = append(names, name) } return names } // GenerateCredentials 生成测试凭据 - 从services包移到这里统一管理 func GenerateCredentials(service string) []Credential { users := common.Userdict[service] if len(users) == 0 { users = []string{"admin", "root", "administrator", "user", "guest", ""} } passwords := common.Passwords if len(passwords) == 0 { passwords = []string{"", "admin", "root", "password", "123456"} } var credentials []Credential for _, user := range users { for _, pass := range passwords { actualPass := strings.Replace(pass, "{user}", user, -1) credentials = append(credentials, Credential{ Username: user, Password: actualPass, }) } } return credentials }