mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-24 04:01:52 +08:00
简化输出格式
This commit is contained in:
+3
-3
@@ -97,7 +97,7 @@ func probeWithICMP(hostslist []string, chanHosts chan string) {
|
||||
}
|
||||
|
||||
Common.LogError(Common.GetText("icmp_listen_failed", err))
|
||||
Common.LogInfo(Common.GetText("trying_no_listen_icmp"))
|
||||
Common.LogBase(Common.GetText("trying_no_listen_icmp"))
|
||||
|
||||
// 尝试无监听ICMP探测
|
||||
conn2, err := net.DialTimeout("ip4:icmp", "127.0.0.1", 3*time.Second)
|
||||
@@ -108,8 +108,8 @@ func probeWithICMP(hostslist []string, chanHosts chan string) {
|
||||
}
|
||||
|
||||
Common.LogError(Common.GetText("icmp_connect_failed", err))
|
||||
Common.LogInfo(Common.GetText("insufficient_privileges"))
|
||||
Common.LogInfo(Common.GetText("switching_to_ping"))
|
||||
Common.LogBase(Common.GetText("insufficient_privileges"))
|
||||
Common.LogBase(Common.GetText("switching_to_ping"))
|
||||
|
||||
// 降级使用ping探测
|
||||
RunPing(hostslist, chanHosts)
|
||||
|
||||
+8
-6
@@ -19,7 +19,7 @@ type Addr struct {
|
||||
// ScanResult 扫描结果
|
||||
type ScanResult struct {
|
||||
Address string // IP地址
|
||||
Port int // 端口号
|
||||
Port int // 端口号
|
||||
Service *ServiceInfo // 服务信息
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func PortScan(hostslist []string, ports string, timeout int64) []string {
|
||||
|
||||
// 初始化并发控制
|
||||
workers := Common.ThreadNum
|
||||
addrs := make(chan Addr, 100) // 待扫描地址通道
|
||||
addrs := make(chan Addr, 100) // 待扫描地址通道
|
||||
scanResults := make(chan ScanResult, 100) // 扫描结果通道
|
||||
var wg sync.WaitGroup
|
||||
var workerWg sync.WaitGroup
|
||||
@@ -120,7 +120,7 @@ func PortConnect(addr Addr, results chan<- ScanResult, timeout int64, wg *sync.W
|
||||
|
||||
// 记录开放端口
|
||||
address := fmt.Sprintf("%s:%d", addr.ip, addr.port)
|
||||
Common.LogSuccess(fmt.Sprintf("端口开放 %s", address))
|
||||
Common.LogInfo(fmt.Sprintf("端口开放 %s", address))
|
||||
|
||||
// 保存端口扫描结果
|
||||
portResult := &Common.ScanResult{
|
||||
@@ -145,7 +145,6 @@ func PortConnect(addr Addr, results chan<- ScanResult, timeout int64, wg *sync.W
|
||||
scanner := NewPortInfoScanner(addr.ip, addr.port, conn, time.Duration(timeout)*time.Second)
|
||||
if serviceInfo, err := scanner.Identify(); err == nil {
|
||||
result.Service = serviceInfo
|
||||
|
||||
// 构造服务识别日志
|
||||
var logMsg strings.Builder
|
||||
logMsg.WriteString(fmt.Sprintf("服务识别 %s => ", address))
|
||||
@@ -202,8 +201,11 @@ func PortConnect(addr Addr, results chan<- ScanResult, timeout int64, wg *sync.W
|
||||
Details: details,
|
||||
}
|
||||
Common.SaveResult(serviceResult)
|
||||
|
||||
Common.LogSuccess(logMsg.String())
|
||||
if serviceInfo.Name != "unknown" {
|
||||
Common.LogSuccess(logMsg.String())
|
||||
} else {
|
||||
Common.LogDebug(logMsg.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -22,7 +22,7 @@ var (
|
||||
// Scan 执行扫描主流程
|
||||
// info: 主机信息结构体,包含扫描目标的基本信息
|
||||
func Scan(info Common.HostInfo) {
|
||||
Common.LogInfo("开始信息扫描")
|
||||
Common.LogBase("开始信息扫描")
|
||||
|
||||
// 初始化HTTP客户端配置
|
||||
lib.Inithttp()
|
||||
@@ -55,7 +55,7 @@ func Scan(info Common.HostInfo) {
|
||||
// ch: 并发控制通道
|
||||
// wg: 等待组
|
||||
func executeLocalScan(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup) {
|
||||
Common.LogInfo("执行本地信息收集")
|
||||
Common.LogBase("执行本地信息收集")
|
||||
|
||||
// 获取本地模式支持的插件列表
|
||||
validLocalPlugins := getValidPlugins(Common.ModeLocal)
|
||||
@@ -68,10 +68,10 @@ func executeLocalScan(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGrou
|
||||
|
||||
// 输出使用的插件信息
|
||||
if Common.ScanMode == Common.ModeLocal {
|
||||
Common.LogInfo("使用全部本地插件")
|
||||
Common.LogBase("使用全部本地插件")
|
||||
Common.ParseScanMode(Common.ScanMode)
|
||||
} else {
|
||||
Common.LogInfo(fmt.Sprintf("使用插件: %s", Common.ScanMode))
|
||||
Common.LogBase(fmt.Sprintf("使用插件: %s", Common.ScanMode))
|
||||
}
|
||||
|
||||
// 执行扫描任务
|
||||
@@ -83,7 +83,7 @@ func executeLocalScan(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGrou
|
||||
// ch: 并发控制通道
|
||||
// wg: 等待组
|
||||
func executeWebScan(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup) {
|
||||
Common.LogInfo("开始Web扫描")
|
||||
Common.LogBase("开始Web扫描")
|
||||
|
||||
// 获取Web模式支持的插件列表
|
||||
validWebPlugins := getValidPlugins(Common.ModeWeb)
|
||||
@@ -108,10 +108,10 @@ func executeWebScan(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup)
|
||||
|
||||
// 输出使用的插件信息
|
||||
if Common.ScanMode == Common.ModeWeb {
|
||||
Common.LogInfo("使用全部Web插件")
|
||||
Common.LogBase("使用全部Web插件")
|
||||
Common.ParseScanMode(Common.ScanMode)
|
||||
} else {
|
||||
Common.LogInfo(fmt.Sprintf("使用插件: %s", Common.ScanMode))
|
||||
Common.LogBase(fmt.Sprintf("使用插件: %s", Common.ScanMode))
|
||||
}
|
||||
|
||||
// 执行扫描任务
|
||||
@@ -136,7 +136,7 @@ func executeHostScan(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup
|
||||
return
|
||||
}
|
||||
|
||||
Common.LogInfo("开始主机扫描")
|
||||
Common.LogBase("开始主机扫描")
|
||||
executeScan(hosts, info, ch, wg)
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func executeScan(hosts []string, info Common.HostInfo, ch *chan struct{}, wg *sy
|
||||
// 检查主机存活性
|
||||
if shouldPingScan(hosts) {
|
||||
hosts = CheckLive(hosts, Common.UsePing)
|
||||
Common.LogInfo(fmt.Sprintf("存活主机数量: %d", len(hosts)))
|
||||
Common.LogBase(fmt.Sprintf("存活主机数量: %d", len(hosts)))
|
||||
if Common.IsICMPScan() {
|
||||
return
|
||||
}
|
||||
@@ -195,7 +195,7 @@ func executeScan(hosts []string, info Common.HostInfo, ch *chan struct{}, wg *sy
|
||||
|
||||
// 执行漏洞扫描
|
||||
if len(targetInfos) > 0 {
|
||||
Common.LogInfo("开始漏洞扫描")
|
||||
Common.LogBase("开始漏洞扫描")
|
||||
executeScans(targetInfos, ch, wg)
|
||||
}
|
||||
}
|
||||
@@ -218,7 +218,7 @@ func getAlivePorts(hosts []string) []string {
|
||||
alivePorts = NoPortScan(hosts, Common.Ports)
|
||||
} else if len(hosts) > 0 {
|
||||
alivePorts = PortScan(hosts, Common.Ports, Common.Timeout)
|
||||
Common.LogInfo(fmt.Sprintf("存活端口数量: %d", len(alivePorts)))
|
||||
Common.LogBase(fmt.Sprintf("存活端口数量: %d", len(alivePorts)))
|
||||
if Common.IsPortScan() {
|
||||
return nil
|
||||
}
|
||||
@@ -229,7 +229,7 @@ func getAlivePorts(hosts []string) []string {
|
||||
alivePorts = append(alivePorts, Common.HostPort...)
|
||||
alivePorts = Common.RemoveDuplicate(alivePorts)
|
||||
Common.HostPort = nil
|
||||
Common.LogInfo(fmt.Sprintf("存活端口数量: %d", len(alivePorts)))
|
||||
Common.LogBase(fmt.Sprintf("存活端口数量: %d", len(alivePorts)))
|
||||
}
|
||||
|
||||
return alivePorts
|
||||
@@ -307,7 +307,7 @@ func executeScans(targets []Common.HostInfo, ch *chan struct{}, wg *sync.WaitGro
|
||||
|
||||
// 处理插件列表
|
||||
finalPlugins := getUniquePlugins(loadedPlugins)
|
||||
Common.LogInfo(fmt.Sprintf("加载的插件: %s", strings.Join(finalPlugins, ", ")))
|
||||
Common.LogBase(fmt.Sprintf("加载的插件: %s", strings.Join(finalPlugins, ", ")))
|
||||
|
||||
// 初始化进度条
|
||||
initializeProgressBar(actualTasks)
|
||||
@@ -406,7 +406,7 @@ func finishScan(wg *sync.WaitGroup) {
|
||||
Common.ProgressBar.Finish()
|
||||
fmt.Println()
|
||||
}
|
||||
Common.LogSuccess(fmt.Sprintf("扫描已完成: %v/%v", Common.End, Common.Num))
|
||||
Common.LogBase(fmt.Sprintf("扫描已完成: %v/%v", Common.End, Common.Num))
|
||||
}
|
||||
|
||||
// Mutex 用于保护共享资源的并发访问
|
||||
@@ -445,7 +445,7 @@ func ScanFunc(name *string, info *Common.HostInfo) {
|
||||
|
||||
plugin, exists := Common.PluginManager[*name]
|
||||
if !exists {
|
||||
Common.LogInfo(fmt.Sprintf("扫描类型 %v 无对应插件,已跳过", *name))
|
||||
Common.LogBase(fmt.Sprintf("扫描类型 %v 无对应插件,已跳过", *name))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user