修复默认扫描 POC 结果缺失 #586
测试构建 / 代码检查 (push) Has been cancelled
测试构建 / 单元测试和构建 (push) Has been cancelled
测试构建 / 构建验证 (push) Has been cancelled

This commit is contained in:
ZacharyZcR
2026-06-04 14:41:49 +08:00
parent 68f990d20b
commit 4198c1abc8
5 changed files with 125 additions and 40 deletions
+21 -18
View File
@@ -140,6 +140,9 @@ func (b *BaseScanStrategy) isPluginApplicableToPortWithHost(pluginName string, t
}
func (b *BaseScanStrategy) isPluginApplicableToPort(pluginName string, targetPort int) bool {
if b.isWebPlugin(pluginName) {
return true
}
return b.isPluginApplicableToPortWithHost(pluginName, "", targetPort)
}
@@ -253,32 +256,32 @@ func (b *BaseScanStrategy) getPluginsByFilterType() []string {
filteredPlugins = append(filteredPlugins, pluginName)
}
}
// 确保 webtitle 在 webpoc 之前执行,避免指纹识别竞态
sort.Slice(filteredPlugins, func(i, j int) bool {
// webtitle 必须在 webpoc 之前
if filteredPlugins[i] == "webtitle" {
return true
}
if filteredPlugins[j] == "webtitle" {
return false
}
if filteredPlugins[i] == "webpoc" {
return false
}
if filteredPlugins[j] == "webpoc" {
return true
}
// 其他插件保持字母顺序
return filteredPlugins[i] < filteredPlugins[j]
})
default:
// 无过滤器:返回所有插件
filteredPlugins = allPlugins
}
orderWebPlugins(filteredPlugins)
return filteredPlugins
}
func orderWebPlugins(pluginNames []string) {
sort.SliceStable(pluginNames, func(i, j int) bool {
return webPluginOrder(pluginNames[i]) < webPluginOrder(pluginNames[j])
})
}
func webPluginOrder(pluginName string) int {
switch pluginName {
case "webtitle":
return 0
case "webpoc":
return 2
default:
return 1
}
}
// parsePluginList 解析插件列表字符串
func parsePluginList(pluginStr string) []string {
if pluginStr == "" {
+11
View File
@@ -261,6 +261,17 @@ func slicesEqual(a, b []string) bool {
return true
}
func TestOrderWebPlugins(t *testing.T) {
plugins := []string{"ssh", "webpoc", "redis", "webtitle", "mysql"}
orderWebPlugins(plugins)
expected := []string{"webtitle", "ssh", "redis", "mysql", "webpoc"}
if !slicesEqual(plugins, expected) {
t.Fatalf("orderWebPlugins = %#v, want %#v", plugins, expected)
}
}
// TestNewBaseScanStrategy 测试构造函数
func TestNewBaseScanStrategy(t *testing.T) {
tests := []struct {
+1 -1
View File
@@ -516,7 +516,6 @@ func scanSinglePort(ctx context.Context, host string, port int, addr string, ada
// 步骤2:记录开放端口
count.Add(1)
collector.Add(addr)
saveOpenPort(session, host, port)
// 步骤3:服务识别(Scanner负责关闭连接,包括探测中可能创建的新连接)
@@ -535,6 +534,7 @@ func scanSinglePort(ctx context.Context, host string, port int, addr string, ada
// 步骤4:处理结果
processServiceResult(ctx, host, port, addr, serviceInfo, config, session)
collector.Add(addr)
}
// handleConnectionFailure 处理连接失败