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

迁移所有本地插件到统一Plugin接口架构: - socks5proxy/systemdservice: 网络代理和Linux服务持久化 - winregistry/winservice/winschtask/winstartup/winwmi: Windows持久化套件 - 所有插件消除BaseLocalPlugin继承,统一使用Plugin接口 - 保持原有功能完整性,支持跨平台编译标记 - 删除过度设计的继承体系,实现直接简洁实现
112 lines
2.5 KiB
Go
112 lines
2.5 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"sync"
|
|
|
|
"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密钥数据
|
|
}
|
|
|
|
// 插件注册表
|
|
var (
|
|
pluginRegistry = make(map[string]func() Plugin)
|
|
pluginMutex sync.RWMutex
|
|
)
|
|
|
|
// RegisterPlugin 注册插件
|
|
func RegisterPlugin(name string, factory func() Plugin) {
|
|
pluginMutex.Lock()
|
|
defer pluginMutex.Unlock()
|
|
pluginRegistry[name] = factory
|
|
}
|
|
|
|
// GetPlugin 获取插件实例
|
|
func GetPlugin(name string) Plugin {
|
|
pluginMutex.RLock()
|
|
defer pluginMutex.RUnlock()
|
|
|
|
factory, exists := pluginRegistry[name]
|
|
if !exists {
|
|
return nil
|
|
}
|
|
return factory()
|
|
}
|
|
|
|
// GetAllPlugins 获取所有已注册插件的名称
|
|
func GetAllPlugins() []string {
|
|
pluginMutex.RLock()
|
|
defer pluginMutex.RUnlock()
|
|
|
|
var plugins []string
|
|
for name := range pluginRegistry {
|
|
plugins = append(plugins, name)
|
|
}
|
|
return plugins
|
|
}
|
|
|
|
// GenerateCredentials 生成测试凭据(统一使用全局凭据系统)
|
|
//
|
|
// 重构说明:消除了插件各自定义凭据的过度设计
|
|
// 现在统一使用 common.Userdict 和 common.Passwords 全局配置
|
|
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
|
|
} |