mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 03:10:42 +08:00
improve embedded scanner runtime
This commit is contained in:
@@ -81,6 +81,11 @@ func (b *BaseScanStrategy) IsPluginApplicableByName(pluginName string, targetHos
|
||||
return false
|
||||
}
|
||||
|
||||
// 显式指定插件时,尊重调用方选择,不再强制使用插件默认端口过滤。
|
||||
if isCustomMode {
|
||||
return b.isPluginPassesFilterType(pluginName, isCustomMode, config)
|
||||
}
|
||||
|
||||
// 检查端口匹配和过滤器类型
|
||||
return b.isPluginApplicableToPortWithHost(pluginName, targetHost, targetPort) && b.isPluginPassesFilterType(pluginName, isCustomMode, config)
|
||||
}
|
||||
|
||||
+4
-4
@@ -55,7 +55,7 @@ func CheckLive(ctx context.Context, hostslist []string, Ping bool, session *comm
|
||||
chanHosts := make(chan string, len(hostslist))
|
||||
|
||||
// 处理存活主机
|
||||
go handleAliveHosts(chanHosts, hostslist, Ping, &aliveHosts, &aliveHostsMu, existHosts, config, &livewg)
|
||||
go handleAliveHosts(chanHosts, hostslist, Ping, &aliveHosts, &aliveHostsMu, existHosts, config, session, &livewg)
|
||||
|
||||
// 根据Ping参数选择检测方式
|
||||
if Ping {
|
||||
@@ -130,7 +130,7 @@ func IsContain(items []string, item string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func handleAliveHosts(chanHosts chan string, hostslist []string, isPing bool, aliveHosts *[]string, aliveHostsMu *sync.Mutex, existHosts map[string]struct{}, config *common.Config, livewg *sync.WaitGroup) {
|
||||
func handleAliveHosts(chanHosts chan string, hostslist []string, isPing bool, aliveHosts *[]string, aliveHostsMu *sync.Mutex, existHosts map[string]struct{}, config *common.Config, session *common.ScanSession, livewg *sync.WaitGroup) {
|
||||
for ip := range chanHosts {
|
||||
if _, ok := existHosts[ip]; !ok && IsContain(hostslist, ip) {
|
||||
existHosts[ip] = struct{}{}
|
||||
@@ -155,7 +155,7 @@ func handleAliveHosts(chanHosts chan string, hostslist []string, isPing bool, al
|
||||
"protocol": protocol,
|
||||
},
|
||||
}
|
||||
_ = common.SaveResult(result)
|
||||
_ = session.SaveResult(result)
|
||||
|
||||
// 保留原有的控制台输出
|
||||
if !config.Output.Silent {
|
||||
@@ -771,7 +771,7 @@ func runTcpProbeForHosts(ctx context.Context, hosts []string, session *common.Sc
|
||||
"protocol": "TCP",
|
||||
},
|
||||
}
|
||||
_ = common.SaveResult(result)
|
||||
_ = session.SaveResult(result)
|
||||
|
||||
if !config.Output.Silent {
|
||||
common.LogInfo(i18n.Tr("host_alive", h, "TCP"))
|
||||
|
||||
+5
-5
@@ -487,7 +487,7 @@ func scanSinglePort(ctx context.Context, host string, port int, addr string, ada
|
||||
// 步骤2:记录开放端口
|
||||
atomic.AddInt64(count, 1)
|
||||
collector.Add(addr)
|
||||
saveOpenPort(host, port)
|
||||
saveOpenPort(session, host, port)
|
||||
|
||||
// 步骤3:服务识别(Scanner负责关闭连接,包括探测中可能创建的新连接)
|
||||
scanner := NewSmartPortInfoScanner(ctx, host, port, conn, timeout, config, session)
|
||||
@@ -640,8 +640,8 @@ func isConnectionClosed(err error) bool {
|
||||
}
|
||||
|
||||
// saveOpenPort 保存开放端口结果
|
||||
func saveOpenPort(host string, port int) {
|
||||
_ = common.SaveResult(&output.ScanResult{
|
||||
func saveOpenPort(session *common.ScanSession, host string, port int) {
|
||||
_ = session.SaveResult(&output.ScanResult{
|
||||
Time: time.Now(),
|
||||
Type: output.TypePort,
|
||||
Target: host,
|
||||
@@ -669,7 +669,7 @@ func processServiceResult(host string, port int, addr string, serviceInfo *Servi
|
||||
MarkAsWebService(host, port, serviceInfo)
|
||||
}
|
||||
|
||||
_ = common.SaveResult(&output.ScanResult{
|
||||
_ = session.SaveResult(&output.ScanResult{
|
||||
Time: time.Now(),
|
||||
Type: output.TypeService,
|
||||
Target: fmt.Sprintf("%s:%d", host, port),
|
||||
@@ -737,7 +737,7 @@ func tryHTTPFallbackDetection(host string, port int, addr string, config *common
|
||||
"is_web": true,
|
||||
"detected_by": "http_probe",
|
||||
}
|
||||
_ = common.SaveResult(&output.ScanResult{
|
||||
_ = session.SaveResult(&output.ScanResult{
|
||||
Time: time.Now(),
|
||||
Type: output.TypeService,
|
||||
Target: fmt.Sprintf("%s:%d", host, port),
|
||||
|
||||
+3
-3
@@ -281,7 +281,7 @@ func executeScanTask(ctx context.Context, session *common.ScanSession, pluginNam
|
||||
if result != nil {
|
||||
if result.Success {
|
||||
// 保存成功的扫描结果到文件
|
||||
savePluginResult(&target, pluginName, result)
|
||||
savePluginResult(session, &target, pluginName, result)
|
||||
} else if result.Type == plugins.ResultTypeCredential {
|
||||
// 凭据测试完成但未发现弱密码,在error级别输出提示
|
||||
common.LogError(i18n.Tr("brute_no_weak_pass", target.Host, target.Port, pluginName))
|
||||
@@ -382,7 +382,7 @@ var defaultSerializer = resultSerializer{
|
||||
}
|
||||
|
||||
// savePluginResult 保存插件扫描结果
|
||||
func savePluginResult(info *common.HostInfo, pluginName string, result *plugins.Result) {
|
||||
func savePluginResult(session *common.ScanSession, info *common.HostInfo, pluginName string, result *plugins.Result) {
|
||||
if result == nil || !result.Success || result.Skipped {
|
||||
return
|
||||
}
|
||||
@@ -402,7 +402,7 @@ func savePluginResult(info *common.HostInfo, pluginName string, result *plugins.
|
||||
|
||||
// 保存结果
|
||||
target := info.Target()
|
||||
_ = common.SaveResult(&output.ScanResult{
|
||||
_ = session.SaveResult(&output.ScanResult{
|
||||
Time: time.Now(),
|
||||
Type: serializer.outputType,
|
||||
Target: target,
|
||||
|
||||
Reference in New Issue
Block a user