Files
fscan/common/flag_config.go
T
ZacharyZcR 4f6bb28138 fix: 修复6个运行时问题
1. 抑制 gmtls 库的 handshake error stdout 噪声
   gmtls/conn.go:1304 硬编码了 fmt.Println,在调用时临时重定向 os.Stdout

2. MySQL 3306 服务名误识别为 genetec-5400
   nmap 指纹库将 MySQL 握手包的随机 salt 误匹配,通过 banner 特征校正

3. 管道输出时自动禁用 ANSI 控制码
   检测 stdout 是否为终端,非终端时自动启用 NoColor

4. 进度条完成消息措辞精确化
   去掉冗余冒号,保持信息简洁一致

5. URL 模式跳过不必要的 TLS 探测
   用户已通过 -u 显式指定 http:// 协议时直接使用,不再做 TLS 握手

6. 无网络探测数据时降低默认重试次数
   -np 跳过存活探测后,将默认重试从 3 降到 2,加速不可达主机的超时
2026-06-14 22:23:49 +08:00

246 lines
6.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package common
import (
"os"
"time"
"github.com/shadow1ng/fscan/common/config"
"golang.org/x/term"
)
/*
flag_config.go - 命令行参数直接解析到Config
flag直接写入配置结构。
*/
// =============================================================================
// FlagVars - 命令行参数原始值
// =============================================================================
// FlagVars 存储命令行解析的原始值
// 某些字段需要类型转换(如 int64 秒 → time.Duration
type FlagVars struct {
// 目标配置
Host string
ExcludeHosts string
ExcludeHostsFile string
Ports string
ExcludePorts string
AddPorts string
HostsFile string
PortsFile string
// 扫描控制
ScanMode string
ThreadNum int
ThreadNumExplicit bool // 用户显式指定了 -t
ModuleThreadNum int
ModuleThreadNumExplicit bool
TimeoutSec int64 // 秒,需转换为 time.Duration
TimeoutExplicit bool
GlobalTimeout int64
DisablePing bool
DisableTcpProbe bool
LocalPlugin string
AliveOnly bool
DisableBrute bool
MaxRetries int
MaxRetriesExplicit bool
// 认证凭据
Username string
Password string
AddUsers string
AddPasswords string
UsersFile string
PasswordsFile string
UserPassFile string
HashFile string
HashValue string
Domain string
SSHKeyPath string
// Web扫描
TargetURL string
URLsFile string
Cookie string
UserAgent string
Accept string
WebTimeout int64 // 秒
MaxRedirects int
HTTPProxy string
Socks5Proxy string
Iface string
// POC测试
PocPath string
PocName string
PocFull bool
DNSLog bool
PocNum int
PocNumExplicit bool
DisablePocScan bool
// Redis利用
RedisFile string
RedisShell string
RedisWritePath string
RedisWriteContent string
RedisWriteFile string
DisableRedis bool
// 发包频率
PacketRateLimit int64
MaxPacketCount int64
ICMPRate float64
ICMPRateExplicit bool
// 输出控制
Outputfile string
OutputFormat string
DisableSave bool
Silent bool
NoColor bool
LogLevel string
Debug bool
DisableProgress bool
PerfStats bool
Language string
// 高级功能
Shellcode string
ReverseShellTarget string
Socks5ProxyPort int
ForwardShellPort int
PersistenceTargetFile string
WinPEFile string
KeyloggerOutputFile string
DownloadURL string
DownloadSavePath string
// 帮助
ShowHelp bool
}
// =============================================================================
// 全局 FlagVars 实例(仅在解析阶段使用)
// =============================================================================
var flagVars = &FlagVars{}
// GetFlagVars 获取解析后的命令行参数(供 parse.go 等使用)
func GetFlagVars() *FlagVars {
return flagVars
}
// =============================================================================
// BuildConfigFromFlags - 从 FlagVars 构建 Config
// =============================================================================
// BuildConfigFromFlags 从命令行参数构建配置对象
func BuildConfigFromFlags(fv *FlagVars) *Config {
return &Config{
// 高频字段
Timeout: time.Duration(fv.TimeoutSec) * time.Second,
TimeoutExplicit: fv.TimeoutExplicit,
ThreadNum: fv.ThreadNum,
ThreadNumExplicit: fv.ThreadNumExplicit,
ModuleThreadNum: fv.ModuleThreadNum,
ModuleThreadNumExplicit: fv.ModuleThreadNumExplicit,
DisableBrute: fv.DisableBrute,
DisablePing: fv.DisablePing,
DisableTcpProbe: fv.DisableTcpProbe,
// 扫描模式
Mode: fv.ScanMode,
LocalMode: fv.LocalPlugin != "",
LocalPlugin: fv.LocalPlugin,
AliveOnly: fv.AliveOnly,
MaxRetries: fv.MaxRetries,
MaxRetriesExplicit: fv.MaxRetriesExplicit,
// 高级功能
Shellcode: fv.Shellcode,
LocalPluginsList: nil, // 后续解析
DNSLog: fv.DNSLog,
PersistenceTargetFile: fv.PersistenceTargetFile,
WinPEFile: fv.WinPEFile,
PortMap: clonePortMap(config.DefaultPortMap),
DefaultMap: cloneStringSlice(config.DefaultProbeMap),
// SOCKS5代理端口
Socks5ProxyPort: fv.Socks5ProxyPort,
// 分组配置
Credentials: CredentialConfig{
Username: fv.Username,
Password: fv.Password,
Domain: fv.Domain,
Userdict: cloneStringSliceMap(config.DefaultUserDict),
Passwords: cloneStringSlice(config.DefaultPasswords),
UserPassPairs: nil, // 后续解析
SSHKeyPath: fv.SSHKeyPath,
},
Network: NetworkConfig{
HTTPProxy: fv.HTTPProxy,
Socks5Proxy: fv.Socks5Proxy,
Iface: fv.Iface,
WebTimeout: time.Duration(fv.WebTimeout) * time.Second,
MaxRedirects: fv.MaxRedirects,
PacketRateLimit: fv.PacketRateLimit,
MaxPacketCount: fv.MaxPacketCount,
ICMPRate: fv.ICMPRate,
ICMPRateExplicit: fv.ICMPRateExplicit,
},
Output: OutputConfig{
File: fv.Outputfile,
Format: fv.OutputFormat,
DisableSave: fv.DisableSave,
NoColor: fv.NoColor || !isStdoutTerminal(),
Silent: fv.Silent,
DisableProgress: fv.DisableProgress,
ShowProgress: !fv.DisableProgress,
LogLevel: fv.LogLevel,
Language: fv.Language,
PerfStats: fv.PerfStats,
},
POC: POCConfig{
PocPath: fv.PocPath,
PocName: fv.PocName,
Full: fv.PocFull,
Num: fv.PocNum,
NumExplicit: fv.PocNumExplicit,
Disabled: fv.DisablePocScan,
},
Redis: RedisConfig{
Disabled: fv.DisableRedis,
File: fv.RedisFile,
Shell: fv.RedisShell,
WritePath: fv.RedisWritePath,
WriteContent: fv.RedisWriteContent,
WriteFile: fv.RedisWriteFile,
},
HTTP: HTTPConfig{
Cookie: fv.Cookie,
UserAgent: fv.UserAgent,
Accept: fv.Accept,
},
LocalExploit: LocalExploitConfig{
ReverseShellTarget: fv.ReverseShellTarget,
ForwardShellPort: fv.ForwardShellPort,
KeyloggerOutputFile: fv.KeyloggerOutputFile,
DownloadURL: fv.DownloadURL,
DownloadSavePath: fv.DownloadSavePath,
},
Target: TargetConfig{
Ports: fv.Ports,
ExcludePorts: fv.ExcludePorts,
},
}
}
func isStdoutTerminal() bool {
return term.IsTerminal(int(os.Stdout.Fd()))
}