mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-25 04:31:52 +08:00
fix web result protocol output (#577)
This commit is contained in:
+15
-14
@@ -196,13 +196,7 @@ func (w *TXTWriter) formatWebServiceLine(result *ScanResult) string {
|
||||
}
|
||||
}
|
||||
|
||||
protocol := "http"
|
||||
service := w.getDetailStr(result, "service")
|
||||
if service == "https" || strings.Contains(target, ":443") {
|
||||
protocol = "https"
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s://%s", protocol, target)
|
||||
url := fmt.Sprintf("%s://%s", w.webProtocol(result, target), target)
|
||||
title := w.getDetailStr(result, "title")
|
||||
status := w.getDetail(result, "status")
|
||||
server := w.getDetailStr(result, "server")
|
||||
@@ -375,13 +369,7 @@ func (w *TXTWriter) writeWebServices() {
|
||||
}
|
||||
}
|
||||
|
||||
protocol := "http"
|
||||
service := w.getDetailStr(result, "service")
|
||||
if service == "https" || strings.Contains(target, ":443") {
|
||||
protocol = "https"
|
||||
}
|
||||
|
||||
urls = append(urls, fmt.Sprintf("%s://%s", protocol, target))
|
||||
urls = append(urls, fmt.Sprintf("%s://%s", w.webProtocol(result, target), target))
|
||||
}
|
||||
|
||||
if len(urls) == 0 {
|
||||
@@ -410,6 +398,19 @@ func (w *TXTWriter) isWebService(result *ScanResult) bool {
|
||||
return service == "http" || service == "https"
|
||||
}
|
||||
|
||||
func (w *TXTWriter) webProtocol(result *ScanResult, target string) string {
|
||||
protocol := strings.ToLower(w.getDetailStr(result, "protocol"))
|
||||
if protocol == "http" || protocol == "https" {
|
||||
return protocol
|
||||
}
|
||||
|
||||
service := strings.ToLower(w.getDetailStr(result, "service"))
|
||||
if service == "https" || strings.Contains(target, ":443") {
|
||||
return "https"
|
||||
}
|
||||
return "http"
|
||||
}
|
||||
|
||||
// GetFormat 获取格式类型
|
||||
func (w *TXTWriter) GetFormat() Format {
|
||||
return FormatTXT
|
||||
|
||||
@@ -1230,6 +1230,44 @@ func TestCSVWriter_WebServiceFields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTXTWriter_WebServiceProtocolFromDetails(t *testing.T) {
|
||||
dir := createTestDir(t)
|
||||
filePath := filepath.Join(dir, "test_web_protocol.txt")
|
||||
|
||||
writer, err := NewTXTWriter(filePath)
|
||||
if err != nil {
|
||||
t.Fatalf("创建TXTWriter失败: %v", err)
|
||||
}
|
||||
|
||||
result := createTestResult(
|
||||
TypeService,
|
||||
"192.168.1.1:8443",
|
||||
"web",
|
||||
map[string]interface{}{
|
||||
"plugin": "webtitle",
|
||||
"is_web": true,
|
||||
"port": 8443,
|
||||
"protocol": "https",
|
||||
"title": "Home",
|
||||
"status": 200,
|
||||
},
|
||||
)
|
||||
if err := writer.Write(result); err != nil {
|
||||
t.Fatalf("Write()失败: %v", err)
|
||||
}
|
||||
if err := writer.Close(); err != nil {
|
||||
t.Fatalf("Close()失败: %v", err)
|
||||
}
|
||||
|
||||
content := readFileContent(t, filePath)
|
||||
if !strings.Contains(content, "https://192.168.1.1:8443") {
|
||||
t.Fatalf("TXT输出缺少HTTPS URL,内容:\n%s", content)
|
||||
}
|
||||
if strings.Contains(content, "http://192.168.1.1:8443") {
|
||||
t.Fatalf("TXT输出不应把HTTPS目标降级为HTTP,内容:\n%s", content)
|
||||
}
|
||||
}
|
||||
|
||||
// TestJSONWriter_FlushAndFormat 测试JSON的Flush和GetFormat
|
||||
func TestJSONWriter_FlushAndFormat(t *testing.T) {
|
||||
dir := createTestDir(t)
|
||||
|
||||
Reference in New Issue
Block a user