fscan/main.go
ZacharyZcR a7ea2f5198 feat: 完善参数互斥检查,-h/-u/-local三个参数只能指定一个
问题:
- 之前只检查了-local与-h/-u的互斥性
- 但-h和-u也应该互斥,代表不同的扫描模式
- 用户可能误用多个参数导致行为不明确

解决方案:
- 统一检查三个核心参数的互斥性
- 提供清晰的错误提示和参数说明
- 确保用户明确选择一种扫描模式

三种扫描模式:
- -h: 网络主机扫描 (端口+服务+漏洞)
- -u: Web URL扫描 (Web漏洞+内容分析)
- -local: 本地信息收集 (系统信息+痕迹清理)

测试验证:
✓ -h + -u: 正确拒绝并提示互斥
✓ -h + -local: 正确拒绝并提示互斥
✓ -u + -local: 正确拒绝并提示互斥
✓ 单独使用: 正常工作

用户体验改进:
- 清晰的错误信息
- 每个参数的功能说明
- 避免了参数冲突的困惑
2025-09-02 08:09:59 +00:00

80 lines
1.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 main
import (
"fmt"
"os"
"time"
"github.com/shadow1ng/fscan/common"
"github.com/shadow1ng/fscan/core"
// 导入统一插件系统
_ "github.com/shadow1ng/fscan/plugins/services"
_ "github.com/shadow1ng/fscan/plugins/web"
_ "github.com/shadow1ng/fscan/plugins/local"
)
func main() {
// Linus式简化直接执行删除过度工程
// 首先设置开始时间
common.StartTime = time.Now()
var info common.HostInfo
common.Flag(&info)
// 检查核心参数的互斥性:-h、-u、-local 只能指定一个
paramCount := 0
var activeParam string
if info.Host != "" {
paramCount++
activeParam = "-h"
}
if common.TargetURL != "" {
paramCount++
if activeParam != "" {
activeParam += " 和 -u"
} else {
activeParam = "-u"
}
}
if common.LocalPlugin != "" {
paramCount++
if activeParam != "" {
activeParam += " 和 -local"
} else {
activeParam = "-local"
}
}
if paramCount > 1 {
fmt.Printf("错误: 参数 %s 互斥,请只指定一个扫描目标\n", activeParam)
fmt.Printf(" -h: 网络主机扫描\n")
fmt.Printf(" -u: Web URL扫描\n")
fmt.Printf(" -local: 本地信息收集\n")
os.Exit(1)
}
// 初始化日志
common.InitLogger()
// 解析和验证参数
if err := common.Parse(&info); err != nil {
handleError("参数解析失败", err)
}
// 初始化输出系统
if err := common.InitOutput(); err != nil {
handleError("输出初始化失败", err)
}
defer common.CloseOutput()
// 执行扫描
core.RunScan(info)
}
func handleError(msg string, err error) {
common.LogError(fmt.Sprintf("%s: %v", msg, err))
os.Exit(1)
}