mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-25 12:41:53 +08:00
显示 Web 服务识别 URL
This commit is contained in:
+30
-2
@@ -420,10 +420,14 @@ func matchFold(a, b string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// buildServiceLogMessage 构建服务识别的日志信息
|
// buildServiceLogMessage 构建服务识别的日志信息
|
||||||
// 格式: addr service [Product:xxx ||Version:xxx] Banner:(xxx)
|
// 格式: addr-or-url service [Product:xxx ||Version:xxx] Banner:(xxx)
|
||||||
func buildServiceLogMessage(addr string, serviceInfo *ServiceInfo, isWeb bool) string {
|
func buildServiceLogMessage(addr string, serviceInfo *ServiceInfo, isWeb bool) string {
|
||||||
var msg strings.Builder
|
var msg strings.Builder
|
||||||
fmt.Fprintf(&msg, "%-21s", addr)
|
displayTarget := addr
|
||||||
|
if isWeb {
|
||||||
|
displayTarget = buildWebServiceURL(addr, serviceInfo)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(&msg, "%-30s", displayTarget)
|
||||||
|
|
||||||
if serviceInfo.Name != "unknown" {
|
if serviceInfo.Name != "unknown" {
|
||||||
fmt.Fprintf(&msg, " %-8s", serviceInfo.Name)
|
fmt.Fprintf(&msg, " %-8s", serviceInfo.Name)
|
||||||
@@ -453,6 +457,30 @@ func buildServiceLogMessage(addr string, serviceInfo *ServiceInfo, isWeb bool) s
|
|||||||
return msg.String()
|
return msg.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildWebServiceURL(addr string, serviceInfo *ServiceInfo) string {
|
||||||
|
protocol := "http"
|
||||||
|
serviceName := ""
|
||||||
|
if serviceInfo != nil {
|
||||||
|
serviceName = strings.ToLower(serviceInfo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(serviceName, "https") || strings.Contains(serviceName, "ssl") || strings.Contains(serviceName, "tls") {
|
||||||
|
protocol = "https"
|
||||||
|
}
|
||||||
|
|
||||||
|
host, port, err := net.SplitHostPort(addr)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Sprintf("%s://%s", protocol, addr)
|
||||||
|
}
|
||||||
|
if protocol == "http" && port == "80" {
|
||||||
|
return fmt.Sprintf("http://%s", host)
|
||||||
|
}
|
||||||
|
if protocol == "https" && port == "443" {
|
||||||
|
return fmt.Sprintf("https://%s", host)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s://%s", protocol, net.JoinHostPort(host, port))
|
||||||
|
}
|
||||||
|
|
||||||
// scanSinglePort 扫描单个端口并进行服务识别(重构后的简洁版本)
|
// scanSinglePort 扫描单个端口并进行服务识别(重构后的简洁版本)
|
||||||
func scanSinglePort(ctx context.Context, host string, port int, addr string, adaptiveTO *AdaptiveTimeout, count *atomic.Int64, collector *resultCollector, failedCollector *failedPortCollector, session *common.ScanSession) {
|
func scanSinglePort(ctx context.Context, host string, port int, addr string, adaptiveTO *AdaptiveTimeout, count *atomic.Int64, collector *resultCollector, failedCollector *failedPortCollector, session *common.ScanSession) {
|
||||||
config := session.Config
|
config := session.Config
|
||||||
|
|||||||
+25
-1
@@ -478,7 +478,31 @@ func TestBuildServiceLogMessage(t *testing.T) {
|
|||||||
Extras: map[string]string{},
|
Extras: map[string]string{},
|
||||||
},
|
},
|
||||||
isWeb: true,
|
isWeb: true,
|
||||||
wantContain: []string{"192.168.1.1:80", "http", "1.1"},
|
wantContain: []string{"http://192.168.1.1", "http", "1.1"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "非标准端口HTTP服务显示URL",
|
||||||
|
addr: "192.168.1.1:8080",
|
||||||
|
serviceInfo: &ServiceInfo{
|
||||||
|
Name: "http",
|
||||||
|
Version: "1.1",
|
||||||
|
Banner: "",
|
||||||
|
Extras: map[string]string{},
|
||||||
|
},
|
||||||
|
isWeb: true,
|
||||||
|
wantContain: []string{"http://192.168.1.1:8080", "http", "1.1"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "HTTPS服务显示HTTPS URL",
|
||||||
|
addr: "192.168.1.1:443",
|
||||||
|
serviceInfo: &ServiceInfo{
|
||||||
|
Name: "https",
|
||||||
|
Version: "1.1",
|
||||||
|
Banner: "",
|
||||||
|
Extras: map[string]string{},
|
||||||
|
},
|
||||||
|
isWeb: true,
|
||||||
|
wantContain: []string{"https://192.168.1.1", "https", "1.1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "带Banner的SSH服务",
|
name: "带Banner的SSH服务",
|
||||||
|
|||||||
Reference in New Issue
Block a user