mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-25 12:41:53 +08:00
fix web result protocol output (#577)
This commit is contained in:
+9
-1
@@ -3,6 +3,7 @@ package core
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
@@ -340,9 +341,16 @@ var resultSerializers = map[plugins.ResultType]resultSerializer{
|
||||
plugins.ResultTypeWeb: {
|
||||
outputType: output.TypeService,
|
||||
getStatus: func(_ *plugins.Result, _ *common.HostInfo) string { return "web" },
|
||||
fillDetail: func(_ *plugins.Result, info *common.HostInfo, d map[string]interface{}) {
|
||||
fillDetail: func(r *plugins.Result, info *common.HostInfo, d map[string]interface{}) {
|
||||
d["is_web"] = true
|
||||
d["port"] = info.Port
|
||||
if r.Output == "" {
|
||||
return
|
||||
}
|
||||
d["url"] = r.Output
|
||||
if parsed, err := url.Parse(r.Output); err == nil && (parsed.Scheme == "http" || parsed.Scheme == "https") {
|
||||
d["protocol"] = parsed.Scheme
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/shadow1ng/fscan/common"
|
||||
"github.com/shadow1ng/fscan/plugins"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -35,6 +36,26 @@ scanner_test.go - Scanner核心逻辑测试
|
||||
// 核心逻辑测试:策略选择
|
||||
// =============================================================================
|
||||
|
||||
func TestWebResultSerializerPreservesDetectedProtocol(t *testing.T) {
|
||||
serializer := resultSerializers[plugins.ResultTypeWeb]
|
||||
details := map[string]interface{}{}
|
||||
result := &plugins.Result{
|
||||
Type: plugins.ResultTypeWeb,
|
||||
Success: true,
|
||||
Output: "https://192.168.1.1:8443",
|
||||
}
|
||||
info := &common.HostInfo{Host: "192.168.1.1", Port: 8443}
|
||||
|
||||
serializer.fillDetail(result, info, details)
|
||||
|
||||
if details["protocol"] != "https" {
|
||||
t.Fatalf("protocol = %v, 期望 https", details["protocol"])
|
||||
}
|
||||
if details["url"] != "https://192.168.1.1:8443" {
|
||||
t.Fatalf("url = %v, 期望检测出的URL", details["url"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestSelectStrategy 测试策略选择逻辑
|
||||
func TestSelectStrategy(t *testing.T) {
|
||||
// 保存原始配置
|
||||
|
||||
Reference in New Issue
Block a user