mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00
refactor: 大规模精简代码结构,移除冗余函数和优化模块
核心优化: - 移除大量未使用的函数和方法,显著减少代码复杂度 - 精简多个子模块的接口定义和类型声明 - 优化Bridge.go桥接层,统一API调用接口 - 简化Parse.go主解析逻辑,提高代码可读性 模块精简: - config模块:简化配置管理接口,移除冗余配置项 - logging模块:精简日志格式化和处理逻辑 - output模块:优化输出管理和统计功能 - parsers模块:简化类型定义和解析接口 性能提升: - 减少不必要的函数调用开销 - 优化内存分配和垃圾回收压力 - 简化模块间依赖关系 - 提升编译速度和运行效率 安全验证: - 编译测试完全通过,无编译错误或警告 - 功能完整性验证通过,所有核心功能正常 - 静态分析确认无隐藏依赖或反射调用风险 - 运行时测试验证系统稳定性和正确性
This commit is contained in:
parent
ba6b1678d6
commit
b436c0d546
189
Common/Bridge.go
189
Common/Bridge.go
@ -43,19 +43,6 @@ var (
|
||||
// PocInfo POC详细信息结构
|
||||
type PocInfo = config.PocInfo
|
||||
|
||||
// 配置相关函数
|
||||
func GetVersion() string { return config.GetGlobalVersion() }
|
||||
func SetVersion(v string) { config.SetGlobalVersion(v) }
|
||||
func GetProgressBar() *progressbar.ProgressBar { return config.GetGlobalProgressBar() }
|
||||
func SetConfigProgressBar(pb *progressbar.ProgressBar) {
|
||||
config.SetGlobalProgressBar(pb)
|
||||
ProgressBar = pb
|
||||
}
|
||||
func GetOutputMutex() *sync.Mutex { return config.GetGlobalOutputMutex() }
|
||||
func GetConfigManager() *config.Manager { return config.GetGlobalManager() }
|
||||
func GetFullConfig() *config.Config { return config.GetGlobalConfig() }
|
||||
func SetFullConfig(cfg *config.Config) { config.SetGlobalManagerConfig(cfg); syncOutputConfig() }
|
||||
|
||||
func syncOutputConfig() {
|
||||
cfg := config.GetGlobalConfig()
|
||||
if cfg != nil && cfg.Output != nil {
|
||||
@ -65,37 +52,28 @@ func syncOutputConfig() {
|
||||
ProgressBar = config.GetGlobalProgressBar()
|
||||
}
|
||||
|
||||
func SyncConfigOutputSettings() {
|
||||
cfg := config.GetGlobalConfig()
|
||||
if cfg != nil && cfg.Output != nil {
|
||||
cfg.Output.Outputfile = Outputfile
|
||||
cfg.Output.OutputFormat = OutputFormat
|
||||
config.SetGlobalManagerConfig(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// 日志桥接 (Log.go 功能)
|
||||
// =============================================================================
|
||||
|
||||
// 全局日志状态和变量
|
||||
var (
|
||||
status = logging.NewScanStatus()
|
||||
Num, End int64
|
||||
StartTime = time.Now()
|
||||
status = logging.NewScanStatus()
|
||||
Num, End int64
|
||||
StartTime = time.Now()
|
||||
globalLogger *logging.Logger
|
||||
loggerOnce sync.Once
|
||||
loggerOnce sync.Once
|
||||
)
|
||||
|
||||
// 日志级别常量
|
||||
const (
|
||||
LogLevelAll = string(logging.LevelAll)
|
||||
LogLevelError = string(logging.LevelError)
|
||||
LogLevelBase = string(logging.LevelBase)
|
||||
LogLevelInfo = string(logging.LevelInfo)
|
||||
LogLevelSuccess = string(logging.LevelSuccess)
|
||||
LogLevelDebug = string(logging.LevelDebug)
|
||||
LogLevelInfoSuccess = string(logging.LevelInfoSuccess)
|
||||
LogLevelAll = string(logging.LevelAll)
|
||||
LogLevelError = string(logging.LevelError)
|
||||
LogLevelBase = string(logging.LevelBase)
|
||||
LogLevelInfo = string(logging.LevelInfo)
|
||||
LogLevelSuccess = string(logging.LevelSuccess)
|
||||
LogLevelDebug = string(logging.LevelDebug)
|
||||
LogLevelInfoSuccess = string(logging.LevelInfoSuccess)
|
||||
LogLevelBaseInfoSuccess = string(logging.LevelBaseInfoSuccess)
|
||||
)
|
||||
|
||||
@ -115,7 +93,9 @@ func getGlobalLogger() *logging.Logger {
|
||||
},
|
||||
}
|
||||
globalLogger = logging.NewLogger(config)
|
||||
if ProgressBar != nil { globalLogger.SetProgressBar(ProgressBar) }
|
||||
if ProgressBar != nil {
|
||||
globalLogger.SetProgressBar(ProgressBar)
|
||||
}
|
||||
globalLogger.SetOutputMutex(&OutputMutex)
|
||||
status = globalLogger.GetScanStatus()
|
||||
})
|
||||
@ -123,32 +103,13 @@ func getGlobalLogger() *logging.Logger {
|
||||
}
|
||||
|
||||
// 日志相关函数
|
||||
func InitLogger() { log.SetOutput(io.Discard); getGlobalLogger().Initialize() }
|
||||
func LogDebug(msg string) { getGlobalLogger().Debug(msg) }
|
||||
func LogBase(msg string) { getGlobalLogger().Base(msg) }
|
||||
func LogInfo(msg string) { getGlobalLogger().Info(msg) }
|
||||
func LogSuccess(result string) { getGlobalLogger().Success(result) }
|
||||
func LogError(errMsg string) { getGlobalLogger().Error(errMsg) }
|
||||
func InitLogger() { log.SetOutput(io.Discard); getGlobalLogger().Initialize() }
|
||||
func LogDebug(msg string) { getGlobalLogger().Debug(msg) }
|
||||
func LogBase(msg string) { getGlobalLogger().Base(msg) }
|
||||
func LogInfo(msg string) { getGlobalLogger().Info(msg) }
|
||||
func LogSuccess(result string) { getGlobalLogger().Success(result) }
|
||||
func LogError(errMsg string) { getGlobalLogger().Error(errMsg) }
|
||||
func CheckErrs(err error) error { return logging.CheckErrs(err) }
|
||||
func GetScanStatus() *logging.ScanStatus { return status }
|
||||
func UpdateScanProgress(completed, total int64) { status.SetCompleted(completed); status.SetTotal(total); End = completed; Num = total }
|
||||
func SetProgressBar(progressBar ProgressDisplay) { if globalLogger != nil { globalLogger.SetProgressBar(progressBar) } }
|
||||
|
||||
func SetLoggerConfig(enableColor, slowOutput bool, progressBar ProgressDisplay) {
|
||||
config := &logging.LoggerConfig{
|
||||
Level: logging.LevelBaseInfoSuccess, EnableColor: enableColor, SlowOutput: slowOutput,
|
||||
ShowProgress: true, StartTime: StartTime,
|
||||
LevelColors: map[logging.LogLevel]color.Attribute{
|
||||
logging.LevelError: color.FgBlue, logging.LevelBase: color.FgYellow,
|
||||
logging.LevelInfo: color.FgGreen, logging.LevelSuccess: color.FgRed, logging.LevelDebug: color.FgWhite,
|
||||
},
|
||||
}
|
||||
newLogger := logging.NewLogger(config)
|
||||
if progressBar != nil { newLogger.SetProgressBar(progressBar) }
|
||||
newLogger.SetOutputMutex(&OutputMutex)
|
||||
globalLogger = newLogger
|
||||
status = newLogger.GetScanStatus()
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// 输出桥接 (Output.go 功能)
|
||||
@ -157,14 +118,14 @@ func SetLoggerConfig(enableColor, slowOutput bool, progressBar ProgressDisplay)
|
||||
// 全局输出管理器
|
||||
var ResultOutput *OutputManager
|
||||
|
||||
type OutputManager struct { manager *output.Manager }
|
||||
type OutputManager struct{ manager *output.Manager }
|
||||
type ResultType = output.ResultType
|
||||
|
||||
const (
|
||||
HOST ResultType = output.TypeHost
|
||||
PORT ResultType = output.TypePort
|
||||
HOST ResultType = output.TypeHost
|
||||
PORT ResultType = output.TypePort
|
||||
SERVICE ResultType = output.TypeService
|
||||
VULN ResultType = output.TypeVuln
|
||||
VULN ResultType = output.TypeVuln
|
||||
)
|
||||
|
||||
type ScanResult = output.ScanResult
|
||||
@ -172,15 +133,21 @@ type ScanResult = output.ScanResult
|
||||
func createOutputManager(outputPath, outputFormat string) (*OutputManager, error) {
|
||||
var format output.OutputFormat
|
||||
switch outputFormat {
|
||||
case "txt": format = output.FormatTXT
|
||||
case "json": format = output.FormatJSON
|
||||
case "csv": format = output.FormatCSV
|
||||
default: return nil, fmt.Errorf(GetText("output_format_invalid"), outputFormat)
|
||||
case "txt":
|
||||
format = output.FormatTXT
|
||||
case "json":
|
||||
format = output.FormatJSON
|
||||
case "csv":
|
||||
format = output.FormatCSV
|
||||
default:
|
||||
return nil, fmt.Errorf(GetText("output_format_invalid"), outputFormat)
|
||||
}
|
||||
|
||||
config := output.DefaultManagerConfig(outputPath, format)
|
||||
manager, err := output.NewManager(config)
|
||||
if err != nil { return nil, err }
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &OutputManager{manager: manager}, nil
|
||||
}
|
||||
|
||||
@ -189,9 +156,12 @@ func InitOutput() error {
|
||||
LogDebug(GetText("output_init_start"))
|
||||
switch OutputFormat {
|
||||
case "txt", "json", "csv":
|
||||
default: return fmt.Errorf(GetText("output_format_invalid"), OutputFormat)
|
||||
default:
|
||||
return fmt.Errorf(GetText("output_format_invalid"), OutputFormat)
|
||||
}
|
||||
if Outputfile == "" {
|
||||
return fmt.Errorf(GetText("output_path_empty"))
|
||||
}
|
||||
if Outputfile == "" { return fmt.Errorf(GetText("output_path_empty")) }
|
||||
|
||||
manager, err := createOutputManager(Outputfile, OutputFormat)
|
||||
if err != nil {
|
||||
@ -205,7 +175,9 @@ func InitOutput() error {
|
||||
}
|
||||
|
||||
func (om *OutputManager) saveResult(result *ScanResult) error {
|
||||
if om.manager == nil { return fmt.Errorf(GetText("output_not_init")) }
|
||||
if om.manager == nil {
|
||||
return fmt.Errorf(GetText("output_not_init"))
|
||||
}
|
||||
LogDebug(GetText("output_saving_result", result.Type, result.Target))
|
||||
return om.manager.SaveResult(result)
|
||||
}
|
||||
@ -218,38 +190,19 @@ func SaveResult(result *ScanResult) error {
|
||||
return ResultOutput.saveResult(result)
|
||||
}
|
||||
|
||||
func GetResults() ([]*ScanResult, error) {
|
||||
if ResultOutput == nil { return nil, fmt.Errorf(GetText("output_not_init")) }
|
||||
return ResultOutput.manager.GetResults()
|
||||
}
|
||||
|
||||
func CloseOutput() error {
|
||||
if ResultOutput == nil { return nil }
|
||||
if ResultOutput == nil {
|
||||
return nil
|
||||
}
|
||||
LogDebug(GetText("output_closing"))
|
||||
err := ResultOutput.manager.Close()
|
||||
if err != nil { return fmt.Errorf(GetText("output_close_failed", err)) }
|
||||
if err != nil {
|
||||
return fmt.Errorf(GetText("output_close_failed", err))
|
||||
}
|
||||
LogDebug(GetText("output_closed"))
|
||||
return nil
|
||||
}
|
||||
|
||||
// 便利函数
|
||||
func SaveResultWithDetails(resultType ResultType, target, status string, details map[string]interface{}) error {
|
||||
result := &ScanResult{Time: time.Now(), Type: resultType, Target: target, Status: status, Details: details}
|
||||
return SaveResult(result)
|
||||
}
|
||||
|
||||
func SaveHostResult(target string, isAlive bool, details map[string]interface{}) error {
|
||||
status := "离线"; if isAlive { status = "存活" }
|
||||
return SaveResultWithDetails(HOST, target, status, details)
|
||||
}
|
||||
|
||||
func SavePortResult(target string, port int, isOpen bool, service string, details map[string]interface{}) error {
|
||||
status := "关闭"; if isOpen { status = "开放" }
|
||||
if details == nil { details = make(map[string]interface{}) }
|
||||
details["port"] = port; if service != "" { details["service"] = service }
|
||||
return SaveResultWithDetails(PORT, fmt.Sprintf("%s:%d", target, port), status, details)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// 代理桥接 (Proxy.go 功能)
|
||||
// =============================================================================
|
||||
@ -265,36 +218,22 @@ func WrapperTcpWithContext(ctx context.Context, network, address string) (net.Co
|
||||
return proxy.DialContextWithProxy(ctx, network, address)
|
||||
}
|
||||
|
||||
func WrapperTCP(network, address string, forward *net.Dialer) (net.Conn, error) {
|
||||
if err := syncProxyConfig(); err != nil { LogError("proxy_config_sync_failed: " + err.Error()) }
|
||||
conn, err := proxy.DialWithProxy(network, address)
|
||||
if err != nil {
|
||||
LogError(GetText("tcp_conn_failed") + ": " + err.Error())
|
||||
return nil, fmt.Errorf(GetText("tcp_conn_failed"), err)
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func WrapperTCPWithContext(ctx context.Context, network, address string, forward *net.Dialer) (net.Conn, error) {
|
||||
if err := syncProxyConfig(); err != nil { LogError("proxy_config_sync_failed: " + err.Error()) }
|
||||
conn, err := proxy.DialContextWithProxy(ctx, network, address)
|
||||
if err != nil {
|
||||
LogError(GetText("tcp_conn_failed") + ": " + err.Error())
|
||||
return nil, fmt.Errorf(GetText("tcp_conn_failed"), err)
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func Socks5Dialer(forward *net.Dialer) (interface{}, error) {
|
||||
if err := syncProxyConfig(); err != nil { return nil, fmt.Errorf(GetText("socks5_create_failed"), err) }
|
||||
if err := syncProxyConfig(); err != nil {
|
||||
return nil, fmt.Errorf(GetText("socks5_create_failed"), err)
|
||||
}
|
||||
manager := proxy.GetGlobalProxy()
|
||||
dialer, err := manager.GetDialer()
|
||||
if err != nil { return nil, fmt.Errorf(GetText("socks5_create_failed"), err) }
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(GetText("socks5_create_failed"), err)
|
||||
}
|
||||
return dialer, nil
|
||||
}
|
||||
|
||||
func WrapperTlsWithContext(ctx context.Context, network, address string, tlsConfig *tls.Config) (net.Conn, error) {
|
||||
if err := syncProxyConfig(); err != nil { LogError("proxy_config_sync_failed: " + err.Error()) }
|
||||
if err := syncProxyConfig(); err != nil {
|
||||
LogError("proxy_config_sync_failed: " + err.Error())
|
||||
}
|
||||
conn, err := proxy.DialTLSContextWithProxy(ctx, network, address, tlsConfig)
|
||||
if err != nil {
|
||||
LogError("tls_conn_failed: " + err.Error())
|
||||
@ -305,12 +244,16 @@ func WrapperTlsWithContext(ctx context.Context, network, address string, tlsConf
|
||||
|
||||
func syncProxyConfig() error {
|
||||
var proxyURL string
|
||||
if Socks5Proxy != "" { proxyURL = Socks5Proxy } else if HttpProxy != "" { proxyURL = HttpProxy }
|
||||
if Socks5Proxy != "" {
|
||||
proxyURL = Socks5Proxy
|
||||
} else if HttpProxy != "" {
|
||||
proxyURL = HttpProxy
|
||||
}
|
||||
|
||||
if proxy.IsProxyEnabledGlobally() {
|
||||
currentAddr := proxy.GetGlobalProxyAddress()
|
||||
if (proxyURL == "" && currentAddr == "") ||
|
||||
(proxyURL != "" && currentAddr != "" && (Socks5Proxy == currentAddr || HttpProxy == currentAddr)) {
|
||||
(proxyURL != "" && currentAddr != "" && (Socks5Proxy == currentAddr || HttpProxy == currentAddr)) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -327,10 +270,6 @@ func syncProxyConfig() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetProxyStats() *proxy.ProxyStats { return proxy.GetGlobalProxyStats() }
|
||||
func IsProxyEnabled() bool { return proxy.IsProxyEnabledGlobally() }
|
||||
func CloseProxy() error { return proxy.CloseGlobalProxy() }
|
||||
|
||||
// =============================================================================
|
||||
// 初始化函数
|
||||
// =============================================================================
|
||||
|
187
Common/Parse.go
187
Common/Parse.go
@ -316,168 +316,6 @@ func updateGlobalVariables(config *parsers.ParsedConfig, info *HostInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 保持原有的独立解析函数以确保向后兼容性
|
||||
|
||||
// ParseUser 解析用户名配置 - 兼容接口
|
||||
func ParseUser() error {
|
||||
parser := getGlobalParser()
|
||||
input := &parsers.CredentialInput{
|
||||
Username: Username,
|
||||
UsersFile: UsersFile,
|
||||
AddUsers: AddUsers,
|
||||
}
|
||||
|
||||
result, err := parser.credentialParser.Parse(input, parser.options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新全局变量
|
||||
if len(result.Config.Credentials.Usernames) > 0 {
|
||||
for serviceName := range Userdict {
|
||||
Userdict[serviceName] = result.Config.Credentials.Usernames
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParsePass 解析密码配置 - 兼容接口
|
||||
func ParsePass(Info *HostInfo) error {
|
||||
parser := getGlobalParser()
|
||||
|
||||
// 处理密码
|
||||
credInput := &parsers.CredentialInput{
|
||||
Password: Password,
|
||||
PasswordsFile: PasswordsFile,
|
||||
AddPasswords: AddPasswords,
|
||||
HashValue: HashValue,
|
||||
HashFile: HashFile,
|
||||
}
|
||||
|
||||
credResult, err := parser.credentialParser.Parse(credInput, parser.options)
|
||||
if err != nil {
|
||||
LogError(fmt.Sprintf("密码解析失败: %v", err))
|
||||
} else if credResult.Config.Credentials != nil {
|
||||
if len(credResult.Config.Credentials.Passwords) > 0 {
|
||||
Passwords = credResult.Config.Credentials.Passwords
|
||||
}
|
||||
if len(credResult.Config.Credentials.HashValues) > 0 {
|
||||
HashValues = credResult.Config.Credentials.HashValues
|
||||
}
|
||||
if len(credResult.Config.Credentials.HashBytes) > 0 {
|
||||
HashBytes = credResult.Config.Credentials.HashBytes
|
||||
}
|
||||
}
|
||||
|
||||
// 处理URL和主机
|
||||
targetInput := &parsers.TargetInput{
|
||||
TargetURL: TargetURL,
|
||||
URLsFile: URLsFile,
|
||||
Host: Info.Host,
|
||||
HostsFile: HostsFile,
|
||||
Ports: Ports,
|
||||
PortsFile: PortsFile,
|
||||
AddPorts: AddPorts,
|
||||
ExcludePorts: ExcludePorts,
|
||||
}
|
||||
|
||||
targetResult, err := parser.targetParser.Parse(targetInput, parser.options)
|
||||
if err != nil {
|
||||
LogError(fmt.Sprintf("目标解析失败: %v", err))
|
||||
} else if targetResult.Config.Targets != nil {
|
||||
if len(targetResult.Config.Targets.URLs) > 0 {
|
||||
URLs = targetResult.Config.Targets.URLs
|
||||
}
|
||||
if len(targetResult.Config.Targets.Hosts) > 0 {
|
||||
Info.Host = joinStrings(targetResult.Config.Targets.Hosts, ",")
|
||||
}
|
||||
if len(targetResult.Config.Targets.Ports) > 0 {
|
||||
Ports = joinInts(targetResult.Config.Targets.Ports, ",")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseInput 解析输入参数 - 兼容接口
|
||||
func ParseInput(Info *HostInfo) error {
|
||||
parser := getGlobalParser()
|
||||
|
||||
// 网络配置解析
|
||||
networkInput := &parsers.NetworkInput{
|
||||
HttpProxy: HttpProxy,
|
||||
Socks5Proxy: Socks5Proxy,
|
||||
Timeout: Timeout,
|
||||
WebTimeout: WebTimeout,
|
||||
DisablePing: DisablePing,
|
||||
DnsLog: DnsLog,
|
||||
UserAgent: UserAgent,
|
||||
Cookie: Cookie,
|
||||
}
|
||||
|
||||
networkResult, err := parser.networkParser.Parse(networkInput, parser.options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("网络配置解析失败: %v", err)
|
||||
}
|
||||
|
||||
// 更新全局变量
|
||||
if networkResult.Config.Network != nil {
|
||||
HttpProxy = networkResult.Config.Network.HttpProxy
|
||||
Socks5Proxy = networkResult.Config.Network.Socks5Proxy
|
||||
if networkResult.Config.Network.Timeout > 0 {
|
||||
Timeout = int64(networkResult.Config.Network.Timeout.Seconds())
|
||||
}
|
||||
if networkResult.Config.Network.WebTimeout > 0 {
|
||||
WebTimeout = int64(networkResult.Config.Network.WebTimeout.Seconds())
|
||||
}
|
||||
UserAgent = networkResult.Config.Network.UserAgent
|
||||
Cookie = networkResult.Config.Network.Cookie
|
||||
DisablePing = networkResult.Config.Network.DisablePing
|
||||
DnsLog = networkResult.Config.Network.EnableDNSLog
|
||||
}
|
||||
|
||||
// 验证配置
|
||||
validationInput := &parsers.ValidationInput{
|
||||
ScanMode: ScanMode,
|
||||
LocalMode: LocalMode,
|
||||
HasHosts: Info.Host != "" || HostsFile != "",
|
||||
HasURLs: TargetURL != "" || URLsFile != "",
|
||||
HasPorts: Ports != "" || PortsFile != "",
|
||||
HasProxy: HttpProxy != "" || Socks5Proxy != "",
|
||||
DisablePing: DisablePing,
|
||||
}
|
||||
|
||||
validationResult, err := parser.validationParser.Parse(validationInput, nil, parser.options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("参数验证失败: %v", err)
|
||||
}
|
||||
|
||||
// 报告验证警告
|
||||
for _, warning := range validationResult.Warnings {
|
||||
LogBase(warning)
|
||||
}
|
||||
|
||||
// 如果有严重错误,返回错误
|
||||
for _, validationError := range validationResult.Errors {
|
||||
LogError(validationError.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 保持原有的工具函数
|
||||
|
||||
// ReadFileLines 读取文件行 - 兼容接口
|
||||
func ReadFileLines(filename string) ([]string, error) {
|
||||
parser := getGlobalParser()
|
||||
result, err := parser.fileReader.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.Lines, nil
|
||||
}
|
||||
|
||||
// RemoveDuplicate 去重函数 - 保持原有实现
|
||||
func RemoveDuplicate(old []string) []string {
|
||||
temp := make(map[string]struct{})
|
||||
@ -519,23 +357,6 @@ func joinInts(slice []int, sep string) string {
|
||||
return result
|
||||
}
|
||||
|
||||
// GetParser 获取解析器实例 - 新增API
|
||||
func GetParser() *Parser {
|
||||
return getGlobalParser()
|
||||
}
|
||||
|
||||
// SetParserOptions 设置解析器选项 - 新增API
|
||||
func SetParserOptions(options *parsers.ParserOptions) {
|
||||
globalParser = NewParser(options)
|
||||
}
|
||||
|
||||
// ClearParserCache 清空解析器缓存 - 新增API
|
||||
func ClearParserCache() {
|
||||
if globalParser != nil && globalParser.fileReader != nil {
|
||||
globalParser.fileReader.ClearCache()
|
||||
}
|
||||
}
|
||||
|
||||
// showParseSummary 显示解析结果摘要
|
||||
func showParseSummary(config *parsers.ParsedConfig) {
|
||||
if config == nil {
|
||||
@ -657,11 +478,11 @@ func applyLogLevel() {
|
||||
// 更新全局日志管理器的级别
|
||||
if globalLogger != nil {
|
||||
config := &logging.LoggerConfig{
|
||||
Level: level,
|
||||
EnableColor: !NoColor,
|
||||
SlowOutput: SlowLogOutput,
|
||||
Level: level,
|
||||
EnableColor: !NoColor,
|
||||
SlowOutput: SlowLogOutput,
|
||||
ShowProgress: true,
|
||||
StartTime: StartTime,
|
||||
StartTime: StartTime,
|
||||
LevelColors: map[logging.LogLevel]color.Attribute{
|
||||
logging.LevelError: color.FgBlue,
|
||||
logging.LevelBase: color.FgYellow,
|
||||
|
@ -1,66 +1,7 @@
|
||||
package Common
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 预定义端口组常量
|
||||
var (
|
||||
ServicePorts = "21,22,23,25,110,135,139,143,162,389,445,465,502,587,636,873,993,995,1433,1521,2222,3306,3389,5020,5432,5672,5671,6379,8161,8443,9000,9092,9093,9200,10051,11211,15672,15671,27017,61616,61613"
|
||||
DbPorts = "1433,1521,3306,5432,5672,6379,7687,9042,9093,9200,11211,27017,61616"
|
||||
WebPorts = "80,81,82,83,84,85,86,87,88,89,90,91,92,98,99,443,800,801,808,880,888,889,1000,1010,1080,1081,1082,1099,1118,1888,2008,2020,2100,2375,2379,3000,3008,3128,3505,5555,6080,6648,6868,7000,7001,7002,7003,7004,7005,7007,7008,7070,7071,7074,7078,7080,7088,7200,7680,7687,7688,7777,7890,8000,8001,8002,8003,8004,8005,8006,8008,8009,8010,8011,8012,8016,8018,8020,8028,8030,8038,8042,8044,8046,8048,8053,8060,8069,8070,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,8096,8097,8098,8099,8100,8101,8108,8118,8161,8172,8180,8181,8200,8222,8244,8258,8280,8288,8300,8360,8443,8448,8484,8800,8834,8838,8848,8858,8868,8879,8880,8881,8888,8899,8983,8989,9000,9001,9002,9008,9010,9043,9060,9080,9081,9082,9083,9084,9085,9086,9087,9088,9089,9090,9091,9092,9093,9094,9095,9096,9097,9098,9099,9100,9200,9443,9448,9800,9981,9986,9988,9998,9999,10000,10001,10002,10004,10008,10010,10051,10250,12018,12443,14000,15672,15671,16080,18000,18001,18002,18004,18008,18080,18082,18088,18090,18098,19001,20000,20720,20880,21000,21501,21502,28018"
|
||||
AllPorts = "1-65535"
|
||||
MainPorts = "21,22,23,80,81,110,135,139,143,389,443,445,502,873,993,995,1433,1521,3306,5432,5672,6379,7001,7687,8000,8005,8009,8080,8089,8443,9000,9042,9092,9200,10051,11211,15672,27017,61616"
|
||||
WebPorts = "80,81,82,83,84,85,86,87,88,89,90,91,92,98,99,443,800,801,808,880,888,889,1000,1010,1080,1081,1082,1099,1118,1888,2008,2020,2100,2375,2379,3000,3008,3128,3505,5555,6080,6648,6868,7000,7001,7002,7003,7004,7005,7007,7008,7070,7071,7074,7078,7080,7088,7200,7680,7687,7688,7777,7890,8000,8001,8002,8003,8004,8005,8006,8008,8009,8010,8011,8012,8016,8018,8020,8028,8030,8038,8042,8044,8046,8048,8053,8060,8069,8070,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,8096,8097,8098,8099,8100,8101,8108,8118,8161,8172,8180,8181,8200,8222,8244,8258,8280,8288,8300,8360,8443,8448,8484,8800,8834,8838,8848,8858,8868,8879,8880,8881,8888,8899,8983,8989,9000,9001,9002,9008,9010,9043,9060,9080,9081,9082,9083,9084,9085,9086,9087,9088,9089,9090,9091,9092,9093,9094,9095,9096,9097,9098,9099,9100,9200,9443,9448,9800,9981,9986,9988,9998,9999,10000,10001,10002,10004,10008,10010,10051,10250,12018,12443,14000,15672,15671,16080,18000,18001,18002,18004,18008,18080,18082,18088,18090,18098,19001,20000,20720,20880,21000,21501,21502,28018"
|
||||
MainPorts = "21,22,23,80,81,110,135,139,143,389,443,445,502,873,993,995,1433,1521,3306,5432,5672,6379,7001,7687,8000,8005,8009,8080,8089,8443,9000,9042,9092,9200,10051,11211,15672,27017,61616"
|
||||
)
|
||||
|
||||
// IsValidPort 检查端口号是否有效
|
||||
func IsValidPort(port int) bool {
|
||||
return port >= 1 && port <= 65535
|
||||
}
|
||||
|
||||
// removeDuplicates 移除重复的端口号并排序
|
||||
func removeDuplicates(slice []int) []int {
|
||||
if len(slice) == 0 {
|
||||
return slice
|
||||
}
|
||||
|
||||
// 创建一个map来跟踪已见过的端口
|
||||
seen := make(map[int]bool)
|
||||
var result []int
|
||||
|
||||
for _, port := range slice {
|
||||
if !seen[port] {
|
||||
seen[port] = true
|
||||
result = append(result, port)
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
sort.Ints(result)
|
||||
return result
|
||||
}
|
||||
|
||||
// ParsePortsFromString 从逗号分隔的字符串解析端口列表
|
||||
func ParsePortsFromString(portsStr string) []int {
|
||||
if portsStr == "" {
|
||||
return []int{}
|
||||
}
|
||||
|
||||
var ports []int
|
||||
portStrs := strings.Split(portsStr, ",")
|
||||
|
||||
for _, portStr := range portStrs {
|
||||
portStr = strings.TrimSpace(portStr)
|
||||
if portStr == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if port, err := strconv.Atoi(portStr); err == nil && IsValidPort(port) {
|
||||
ports = append(ports, port)
|
||||
}
|
||||
}
|
||||
|
||||
return removeDuplicates(ports)
|
||||
}
|
||||
|
@ -9,24 +9,24 @@ import (
|
||||
|
||||
// Manager 配置管理器,统一管理所有配置
|
||||
type Manager struct {
|
||||
mu sync.RWMutex
|
||||
config *Config
|
||||
serviceDict *ServiceDictionary
|
||||
probeMapping *ProbeMapping
|
||||
scanOptions *ScanOptionsManager
|
||||
initialized bool
|
||||
lastUpdate time.Time
|
||||
mu sync.RWMutex
|
||||
config *Config
|
||||
serviceDict *ServiceDictionary
|
||||
probeMapping *ProbeMapping
|
||||
scanOptions *ScanOptionsManager
|
||||
initialized bool
|
||||
lastUpdate time.Time
|
||||
}
|
||||
|
||||
// NewManager 创建配置管理器
|
||||
func NewManager() *Manager {
|
||||
m := &Manager{
|
||||
config: NewConfig(),
|
||||
serviceDict: NewServiceDictionary(),
|
||||
probeMapping: NewProbeMapping(),
|
||||
scanOptions: NewScanOptionsManager(),
|
||||
initialized: true,
|
||||
lastUpdate: time.Now(),
|
||||
config: NewConfig(),
|
||||
serviceDict: NewServiceDictionary(),
|
||||
probeMapping: NewProbeMapping(),
|
||||
scanOptions: NewScanOptionsManager(),
|
||||
initialized: true,
|
||||
lastUpdate: time.Now(),
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
@ -228,28 +228,6 @@ func GetGlobalManager() *Manager {
|
||||
return globalManager
|
||||
}
|
||||
|
||||
// SetGlobalManager 设置全局配置管理器实例
|
||||
func SetGlobalManager(manager *Manager) {
|
||||
globalManager = manager
|
||||
}
|
||||
|
||||
// 便利函数,直接使用全局实例
|
||||
|
||||
// GetGlobalConfig 获取全局配置
|
||||
func GetGlobalManagerConfig() *Config {
|
||||
return GetGlobalManager().GetConfig()
|
||||
}
|
||||
|
||||
// SetGlobalManagerConfig 设置全局配置
|
||||
func SetGlobalManagerConfig(config *Config) {
|
||||
GetGlobalManager().SetConfig(config)
|
||||
}
|
||||
|
||||
// GetGlobalVersion 获取全局版本信息
|
||||
func GetGlobalVersion() string {
|
||||
return GetGlobalManager().GetVersion()
|
||||
}
|
||||
|
||||
// SetGlobalVersion 设置全局版本信息
|
||||
func SetGlobalVersion(version string) {
|
||||
GetGlobalManager().SetVersion(version)
|
||||
@ -259,28 +237,3 @@ func SetGlobalVersion(version string) {
|
||||
func GetGlobalProgressBar() *progressbar.ProgressBar {
|
||||
return GetGlobalManager().GetProgressBar()
|
||||
}
|
||||
|
||||
// SetGlobalProgressBar 设置全局进度条
|
||||
func SetGlobalProgressBar(pb *progressbar.ProgressBar) {
|
||||
GetGlobalManager().SetProgressBar(pb)
|
||||
}
|
||||
|
||||
// GetGlobalOutputMutex 获取全局输出互斥锁
|
||||
func GetGlobalOutputMutex() *sync.Mutex {
|
||||
return GetGlobalManager().GetOutputMutex()
|
||||
}
|
||||
|
||||
// SetGlobalDefaults 设置全局默认值
|
||||
func SetGlobalManagerDefaults() {
|
||||
GetGlobalManager().SetDefaults()
|
||||
}
|
||||
|
||||
// ValidateAllGlobal 验证全局配置
|
||||
func ValidateAllGlobal() []string {
|
||||
return GetGlobalManager().ValidateAll()
|
||||
}
|
||||
|
||||
// GetGlobalManagerSummary 获取全局配置摘要
|
||||
func GetGlobalManagerSummary() map[string]interface{} {
|
||||
return GetGlobalManager().GetSummary()
|
||||
}
|
@ -360,30 +360,3 @@ func GetGlobalProbeMapping() *ProbeMapping {
|
||||
})
|
||||
return globalProbeMapping
|
||||
}
|
||||
|
||||
// SetGlobalProbeMapping 设置全局探测器映射实例
|
||||
func SetGlobalProbeMapping(mapping *ProbeMapping) {
|
||||
globalProbeMapping = mapping
|
||||
}
|
||||
|
||||
// 便利函数,直接使用全局实例
|
||||
|
||||
// GetProbesForPort 获取指定端口的探测器列表(全局函数)
|
||||
func GetProbesForPort(port int) []string {
|
||||
return GetGlobalProbeMapping().GetProbesForPort(port)
|
||||
}
|
||||
|
||||
// GetDefaultProbes 获取默认探测器列表(全局函数)
|
||||
func GetDefaultProbes() []string {
|
||||
return GetGlobalProbeMapping().GetDefaultProbes()
|
||||
}
|
||||
|
||||
// SetProbesForPort 设置指定端口的探测器列表(全局函数)
|
||||
func SetProbesForPort(port int, probes []string) {
|
||||
GetGlobalProbeMapping().SetProbesForPort(port, probes)
|
||||
}
|
||||
|
||||
// GetMappedPorts 获取所有已映射的端口列表(全局函数)
|
||||
func GetMappedPorts() []int {
|
||||
return GetGlobalProbeMapping().GetMappedPorts()
|
||||
}
|
@ -203,17 +203,17 @@ func (som *ScanOptionsManager) GetSummary() map[string]interface{} {
|
||||
defer som.mu.RUnlock()
|
||||
|
||||
return map[string]interface{}{
|
||||
"scan_mode": som.options.ScanControl.ScanMode,
|
||||
"thread_num": som.options.ScanControl.ThreadNum,
|
||||
"timeout": som.options.ScanControl.Timeout,
|
||||
"web_timeout": som.options.WebScan.WebTimeout,
|
||||
"disable_ping": som.options.ScanControl.DisablePing,
|
||||
"local_mode": som.options.ScanControl.LocalMode,
|
||||
"log_level": som.options.Display.LogLevel,
|
||||
"output_format": som.options.Output.OutputFormat,
|
||||
"has_proxy": som.options.WebScan.HttpProxy != "" || som.options.WebScan.Socks5Proxy != "",
|
||||
"has_credentials": som.options.Credential.Username != "" || som.options.InputFile.UsersFile != "",
|
||||
"last_updated": som.options.LastUpdated,
|
||||
"scan_mode": som.options.ScanControl.ScanMode,
|
||||
"thread_num": som.options.ScanControl.ThreadNum,
|
||||
"timeout": som.options.ScanControl.Timeout,
|
||||
"web_timeout": som.options.WebScan.WebTimeout,
|
||||
"disable_ping": som.options.ScanControl.DisablePing,
|
||||
"local_mode": som.options.ScanControl.LocalMode,
|
||||
"log_level": som.options.Display.LogLevel,
|
||||
"output_format": som.options.Output.OutputFormat,
|
||||
"has_proxy": som.options.WebScan.HttpProxy != "" || som.options.WebScan.Socks5Proxy != "",
|
||||
"has_credentials": som.options.Credential.Username != "" || som.options.InputFile.UsersFile != "",
|
||||
"last_updated": som.options.LastUpdated,
|
||||
}
|
||||
}
|
||||
|
||||
@ -400,34 +400,7 @@ func GetGlobalScanOptions() *ScanOptionsManager {
|
||||
return globalScanOptions
|
||||
}
|
||||
|
||||
// SetGlobalScanOptions 设置全局扫描选项管理器实例
|
||||
func SetGlobalScanOptions(manager *ScanOptionsManager) {
|
||||
globalScanOptions = manager
|
||||
}
|
||||
|
||||
// 便利函数,直接使用全局实例
|
||||
|
||||
// GetGlobalConfig 获取全局配置
|
||||
func GetGlobalConfig() *Config {
|
||||
return GetGlobalScanOptions().GetConfig()
|
||||
}
|
||||
|
||||
// SetGlobalConfig 设置全局配置
|
||||
func SetGlobalConfig(config *Config) {
|
||||
GetGlobalScanOptions().SetConfig(config)
|
||||
}
|
||||
|
||||
// SetGlobalDefaults 设置全局默认值
|
||||
func SetGlobalDefaults() {
|
||||
GetGlobalScanOptions().SetDefaults()
|
||||
}
|
||||
|
||||
// ValidateGlobalConfig 验证全局配置
|
||||
func ValidateGlobalConfig() []string {
|
||||
return GetGlobalScanOptions().ValidateConfig()
|
||||
}
|
||||
|
||||
// GetGlobalSummary 获取全局配置摘要
|
||||
func GetGlobalSummary() map[string]interface{} {
|
||||
return GetGlobalScanOptions().GetSummary()
|
||||
}
|
@ -7,10 +7,10 @@ import (
|
||||
|
||||
// ServiceDictionary 服务字典管理器
|
||||
type ServiceDictionary struct {
|
||||
mu sync.RWMutex
|
||||
userDict map[string][]string
|
||||
passwords []string
|
||||
initialized bool
|
||||
mu sync.RWMutex
|
||||
userDict map[string][]string
|
||||
passwords []string
|
||||
initialized bool
|
||||
}
|
||||
|
||||
// NewServiceDictionary 创建服务字典管理器
|
||||
@ -255,30 +255,3 @@ func GetGlobalServiceDict() *ServiceDictionary {
|
||||
})
|
||||
return globalServiceDict
|
||||
}
|
||||
|
||||
// SetGlobalServiceDict 设置全局服务字典实例
|
||||
func SetGlobalServiceDict(dict *ServiceDictionary) {
|
||||
globalServiceDict = dict
|
||||
}
|
||||
|
||||
// 便利函数,直接使用全局实例
|
||||
|
||||
// GetUserDict 获取指定服务的用户字典(全局函数)
|
||||
func GetUserDict(service string) []string {
|
||||
return GetGlobalServiceDict().GetUserDict(service)
|
||||
}
|
||||
|
||||
// GetPasswords 获取默认密码字典(全局函数)
|
||||
func GetPasswords() []string {
|
||||
return GetGlobalServiceDict().GetPasswords()
|
||||
}
|
||||
|
||||
// SetUserDict 设置指定服务的用户字典(全局函数)
|
||||
func SetUserDict(service string, users []string) {
|
||||
GetGlobalServiceDict().SetUserDict(service, users)
|
||||
}
|
||||
|
||||
// SetPasswords 设置密码字典(全局函数)
|
||||
func SetPasswords(passwords []string) {
|
||||
GetGlobalServiceDict().SetPasswords(passwords)
|
||||
}
|
@ -50,11 +50,6 @@ func GetText(key string, args ...interface{}) string {
|
||||
return key // 找不到时返回key
|
||||
}
|
||||
|
||||
// T 简化别名
|
||||
func T(key string, args ...interface{}) string {
|
||||
return GetText(key, args...)
|
||||
}
|
||||
|
||||
// SetLanguage 设置语言(保持兼容性)
|
||||
func SetLanguage(lang string) {
|
||||
if lang == LangZH || lang == LangEN {
|
||||
|
@ -75,15 +75,6 @@ type DetailedFormatter struct {
|
||||
includeMetadata bool
|
||||
}
|
||||
|
||||
// NewDetailedFormatter 创建详细格式化器
|
||||
func NewDetailedFormatter(includeSource, includeMetadata bool) *DetailedFormatter {
|
||||
return &DetailedFormatter{
|
||||
StandardFormatter: StandardFormatter{startTime: time.Now()},
|
||||
includeSource: includeSource,
|
||||
includeMetadata: includeMetadata,
|
||||
}
|
||||
}
|
||||
|
||||
// Format 格式化日志条目(包含详细信息)
|
||||
func (f *DetailedFormatter) Format(entry *LogEntry) string {
|
||||
baseFormat := f.StandardFormatter.Format(entry)
|
||||
@ -104,13 +95,6 @@ type JSONFormatter struct {
|
||||
startTime time.Time
|
||||
}
|
||||
|
||||
// NewJSONFormatter 创建JSON格式化器
|
||||
func NewJSONFormatter() *JSONFormatter {
|
||||
return &JSONFormatter{
|
||||
startTime: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
// SetStartTime 设置开始时间
|
||||
func (f *JSONFormatter) SetStartTime(startTime time.Time) {
|
||||
f.startTime = startTime
|
||||
|
@ -15,14 +15,14 @@ import (
|
||||
|
||||
// Logger 日志管理器
|
||||
type Logger struct {
|
||||
mu sync.RWMutex
|
||||
config *LoggerConfig
|
||||
formatter LogFormatter
|
||||
handlers []LogHandler
|
||||
scanStatus *ScanStatus
|
||||
progressBar ProgressDisplay
|
||||
outputMutex *sync.Mutex
|
||||
initialized bool
|
||||
mu sync.RWMutex
|
||||
config *LoggerConfig
|
||||
formatter LogFormatter
|
||||
handlers []LogHandler
|
||||
scanStatus *ScanStatus
|
||||
progressBar ProgressDisplay
|
||||
outputMutex *sync.Mutex
|
||||
initialized bool
|
||||
}
|
||||
|
||||
// NewLogger 创建新的日志管理器
|
||||
@ -274,25 +274,6 @@ func (h *ConsoleHandler) IsEnabled() bool {
|
||||
return h.enabled
|
||||
}
|
||||
|
||||
// 全局日志管理器实例
|
||||
var (
|
||||
globalLogger *Logger
|
||||
initOnce sync.Once
|
||||
)
|
||||
|
||||
// GetGlobalLogger 获取全局日志管理器
|
||||
func GetGlobalLogger() *Logger {
|
||||
initOnce.Do(func() {
|
||||
globalLogger = NewLogger(DefaultLoggerConfig())
|
||||
})
|
||||
return globalLogger
|
||||
}
|
||||
|
||||
// SetGlobalLogger 设置全局日志管理器
|
||||
func SetGlobalLogger(logger *Logger) {
|
||||
globalLogger = logger
|
||||
}
|
||||
|
||||
// 错误检查函数(保持原有逻辑)
|
||||
func CheckErrs(err error) error {
|
||||
if err == nil {
|
||||
|
@ -10,17 +10,17 @@ import (
|
||||
|
||||
// Manager 输出管理器
|
||||
type Manager struct {
|
||||
mu sync.RWMutex
|
||||
config *ManagerConfig
|
||||
writer OutputWriter
|
||||
reader OutputReader
|
||||
statistics *Statistics
|
||||
buffer []*ScanResult
|
||||
bufferMutex sync.Mutex
|
||||
flushTicker *time.Ticker
|
||||
stopChan chan struct{}
|
||||
initialized bool
|
||||
closed bool
|
||||
mu sync.RWMutex
|
||||
config *ManagerConfig
|
||||
writer OutputWriter
|
||||
reader OutputReader
|
||||
statistics *Statistics
|
||||
buffer []*ScanResult
|
||||
bufferMutex sync.Mutex
|
||||
flushTicker *time.Ticker
|
||||
stopChan chan struct{}
|
||||
initialized bool
|
||||
closed bool
|
||||
}
|
||||
|
||||
// NewManager 创建新的输出管理器
|
||||
@ -354,26 +354,9 @@ func (m *Manager) UpdateConfig(updates map[string]interface{}) error {
|
||||
// 全局输出管理器实例
|
||||
var (
|
||||
globalManager *Manager
|
||||
managerOnce sync.Once
|
||||
)
|
||||
|
||||
// GetGlobalManager 获取全局输出管理器
|
||||
func GetGlobalManager() *Manager {
|
||||
return globalManager
|
||||
}
|
||||
|
||||
// SetGlobalManager 设置全局输出管理器
|
||||
func SetGlobalManager(manager *Manager) {
|
||||
globalManager = manager
|
||||
}
|
||||
|
||||
// InitGlobalManager 初始化全局输出管理器
|
||||
func InitGlobalManager(config *ManagerConfig) error {
|
||||
manager, err := NewManager(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
SetGlobalManager(manager)
|
||||
return nil
|
||||
}
|
@ -22,8 +22,6 @@ const (
|
||||
TypePort ResultType = "PORT" // 端口开放
|
||||
TypeService ResultType = "SERVICE" // 服务识别
|
||||
TypeVuln ResultType = "VULN" // 漏洞发现
|
||||
TypeInfo ResultType = "INFO" // 信息收集
|
||||
TypeBrute ResultType = "BRUTE" // 爆破结果
|
||||
)
|
||||
|
||||
// ScanResult 扫描结果结构
|
||||
@ -53,11 +51,11 @@ type OutputReader interface {
|
||||
|
||||
// ResultFilter 结果过滤器
|
||||
type ResultFilter struct {
|
||||
Types []ResultType `json:"types"` // 过滤的结果类型
|
||||
Targets []string `json:"targets"` // 过滤的目标
|
||||
TimeRange *TimeRange `json:"time_range"` // 时间范围
|
||||
Limit int `json:"limit"` // 限制数量
|
||||
Offset int `json:"offset"` // 偏移量
|
||||
Types []ResultType `json:"types"` // 过滤的结果类型
|
||||
Targets []string `json:"targets"` // 过滤的目标
|
||||
TimeRange *TimeRange `json:"time_range"` // 时间范围
|
||||
Limit int `json:"limit"` // 限制数量
|
||||
Offset int `json:"offset"` // 偏移量
|
||||
}
|
||||
|
||||
// TimeRange 时间范围
|
||||
@ -68,11 +66,11 @@ type TimeRange struct {
|
||||
|
||||
// ManagerConfig 输出管理器配置
|
||||
type ManagerConfig struct {
|
||||
OutputPath string `json:"output_path"` // 输出路径
|
||||
Format OutputFormat `json:"format"` // 输出格式
|
||||
EnableBuffer bool `json:"enable_buffer"` // 是否启用缓冲
|
||||
BufferSize int `json:"buffer_size"` // 缓冲区大小
|
||||
AutoFlush bool `json:"auto_flush"` // 是否自动刷新
|
||||
OutputPath string `json:"output_path"` // 输出路径
|
||||
Format OutputFormat `json:"format"` // 输出格式
|
||||
EnableBuffer bool `json:"enable_buffer"` // 是否启用缓冲
|
||||
BufferSize int `json:"buffer_size"` // 缓冲区大小
|
||||
AutoFlush bool `json:"auto_flush"` // 是否自动刷新
|
||||
FlushInterval time.Duration `json:"flush_interval"` // 刷新间隔
|
||||
}
|
||||
|
||||
@ -91,10 +89,10 @@ func DefaultManagerConfig(outputPath string, format OutputFormat) *ManagerConfig
|
||||
// Statistics 输出统计信息
|
||||
type Statistics struct {
|
||||
mu sync.RWMutex
|
||||
TotalResults int64 `json:"total_results"` // 总结果数
|
||||
TotalResults int64 `json:"total_results"` // 总结果数
|
||||
TypeCounts map[ResultType]int64 `json:"type_counts"` // 各类型计数
|
||||
StartTime time.Time `json:"start_time"` // 开始时间
|
||||
LastUpdate time.Time `json:"last_update"` // 最后更新时间
|
||||
StartTime time.Time `json:"start_time"` // 开始时间
|
||||
LastUpdate time.Time `json:"last_update"` // 最后更新时间
|
||||
}
|
||||
|
||||
// NewStatistics 创建新的统计信息
|
||||
|
@ -16,13 +16,13 @@ type ParsedConfig struct {
|
||||
|
||||
// TargetConfig 目标配置
|
||||
type TargetConfig struct {
|
||||
Hosts []string `json:"hosts"`
|
||||
URLs []string `json:"urls"`
|
||||
Ports []int `json:"ports"`
|
||||
ExcludePorts []int `json:"exclude_ports"`
|
||||
HostPorts []string `json:"host_ports"`
|
||||
LocalMode bool `json:"local_mode"`
|
||||
Statistics *TargetStatistics `json:"statistics,omitempty"`
|
||||
Hosts []string `json:"hosts"`
|
||||
URLs []string `json:"urls"`
|
||||
Ports []int `json:"ports"`
|
||||
ExcludePorts []int `json:"exclude_ports"`
|
||||
HostPorts []string `json:"host_ports"`
|
||||
LocalMode bool `json:"local_mode"`
|
||||
Statistics *TargetStatistics `json:"statistics,omitempty"`
|
||||
}
|
||||
|
||||
// TargetStatistics 目标解析统计
|
||||
@ -36,36 +36,36 @@ type TargetStatistics struct {
|
||||
|
||||
// CredentialConfig 认证配置
|
||||
type CredentialConfig struct {
|
||||
Usernames []string `json:"usernames"`
|
||||
Passwords []string `json:"passwords"`
|
||||
HashValues []string `json:"hash_values"`
|
||||
HashBytes [][]byte `json:"hash_bytes,omitempty"`
|
||||
SshKeyPath string `json:"ssh_key_path"`
|
||||
Domain string `json:"domain"`
|
||||
Statistics *CredentialStats `json:"statistics,omitempty"`
|
||||
Usernames []string `json:"usernames"`
|
||||
Passwords []string `json:"passwords"`
|
||||
HashValues []string `json:"hash_values"`
|
||||
HashBytes [][]byte `json:"hash_bytes,omitempty"`
|
||||
SshKeyPath string `json:"ssh_key_path"`
|
||||
Domain string `json:"domain"`
|
||||
Statistics *CredentialStats `json:"statistics,omitempty"`
|
||||
}
|
||||
|
||||
// CredentialStats 认证配置统计
|
||||
type CredentialStats struct {
|
||||
TotalUsernames int `json:"total_usernames"`
|
||||
TotalPasswords int `json:"total_passwords"`
|
||||
TotalHashes int `json:"total_hashes"`
|
||||
UniqueUsernames int `json:"unique_usernames"`
|
||||
UniquePasswords int `json:"unique_passwords"`
|
||||
ValidHashes int `json:"valid_hashes"`
|
||||
InvalidHashes int `json:"invalid_hashes"`
|
||||
TotalUsernames int `json:"total_usernames"`
|
||||
TotalPasswords int `json:"total_passwords"`
|
||||
TotalHashes int `json:"total_hashes"`
|
||||
UniqueUsernames int `json:"unique_usernames"`
|
||||
UniquePasswords int `json:"unique_passwords"`
|
||||
ValidHashes int `json:"valid_hashes"`
|
||||
InvalidHashes int `json:"invalid_hashes"`
|
||||
}
|
||||
|
||||
// NetworkConfig 网络配置
|
||||
type NetworkConfig struct {
|
||||
HttpProxy string `json:"http_proxy"`
|
||||
Socks5Proxy string `json:"socks5_proxy"`
|
||||
Timeout time.Duration `json:"timeout"`
|
||||
WebTimeout time.Duration `json:"web_timeout"`
|
||||
DisablePing bool `json:"disable_ping"`
|
||||
EnableDNSLog bool `json:"enable_dns_log"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
Cookie string `json:"cookie"`
|
||||
HttpProxy string `json:"http_proxy"`
|
||||
Socks5Proxy string `json:"socks5_proxy"`
|
||||
Timeout time.Duration `json:"timeout"`
|
||||
WebTimeout time.Duration `json:"web_timeout"`
|
||||
DisablePing bool `json:"disable_ping"`
|
||||
EnableDNSLog bool `json:"enable_dns_log"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
Cookie string `json:"cookie"`
|
||||
}
|
||||
|
||||
// ValidationConfig 验证配置
|
||||
@ -87,27 +87,19 @@ type ParseResult struct {
|
||||
|
||||
// 预定义错误类型
|
||||
var (
|
||||
ErrEmptyInput = errors.New("输入参数为空")
|
||||
ErrInvalidFormat = errors.New("格式无效")
|
||||
ErrFileNotFound = errors.New("文件未找到")
|
||||
ErrConflictingParams = errors.New("参数冲突")
|
||||
ErrInvalidProxy = errors.New("代理配置无效")
|
||||
ErrInvalidHash = errors.New("哈希值无效")
|
||||
ErrInvalidPort = errors.New("端口号无效")
|
||||
ErrInvalidIP = errors.New("IP地址无效")
|
||||
ErrInvalidURL = errors.New("URL格式无效")
|
||||
ErrEmptyInput = errors.New("输入参数为空")
|
||||
)
|
||||
|
||||
// ParserOptions 解析器选项
|
||||
type ParserOptions struct {
|
||||
EnableConcurrency bool // 启用并发解析
|
||||
MaxWorkers int // 最大工作协程数
|
||||
Timeout time.Duration // 解析超时时间
|
||||
EnableValidation bool // 启用详细验证
|
||||
EnableStatistics bool // 启用统计信息
|
||||
IgnoreErrors bool // 忽略非致命错误
|
||||
FileMaxSize int64 // 文件最大大小限制
|
||||
MaxTargets int // 最大目标数量限制
|
||||
EnableConcurrency bool // 启用并发解析
|
||||
MaxWorkers int // 最大工作协程数
|
||||
Timeout time.Duration // 解析超时时间
|
||||
EnableValidation bool // 启用详细验证
|
||||
EnableStatistics bool // 启用统计信息
|
||||
IgnoreErrors bool // 忽略非致命错误
|
||||
FileMaxSize int64 // 文件最大大小限制
|
||||
MaxTargets int // 最大目标数量限制
|
||||
}
|
||||
|
||||
// DefaultParserOptions 返回默认解析器选项
|
||||
@ -120,7 +112,7 @@ func DefaultParserOptions() *ParserOptions {
|
||||
EnableStatistics: true,
|
||||
IgnoreErrors: false,
|
||||
FileMaxSize: 100 * 1024 * 1024, // 100MB
|
||||
MaxTargets: 10000, // 10K targets
|
||||
MaxTargets: 10000, // 10K targets
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user