mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 03:10:42 +08:00
feat: 统一服务缓存 + 指纹驱动插件匹配
将 webServiceCache 扩展为通用 serviceCache,所有指纹识别结果 统一缓存,插件匹配时端口不命中则回退到服务名称匹配。 删除多余的 service_cache.go,复用已有的 ServiceInfo 体系。 补充 nil 防御、Explicit 标记、大量单元/集成/回归测试。
This commit is contained in:
@@ -176,8 +176,7 @@ func (g *Client) ProbeOSInfo(host, domain, user, pwd string, timeout int64, rdpP
|
||||
exitFlag := make(chan bool, 1)
|
||||
info = make(map[string]any)
|
||||
|
||||
targetSlice := strings.Split(g.Host, ":")
|
||||
ip := targetSlice[0]
|
||||
ip := rdpTargetHost(g.Host)
|
||||
conn, err := WrapperTcpWithTimeout("tcp", g.Host, time.Duration(timeout)*time.Second)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -273,3 +272,14 @@ loop:
|
||||
glog.Debug("loop ended, elapsed time: ", time.Since(start))
|
||||
return info
|
||||
}
|
||||
|
||||
func rdpTargetHost(target string) string {
|
||||
host, _, err := net.SplitHostPort(target)
|
||||
if err == nil {
|
||||
return host
|
||||
}
|
||||
if strings.Count(target, ":") == 1 {
|
||||
return strings.SplitN(target, ":", 2)[0]
|
||||
}
|
||||
return target
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package login
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRDPTargetHost(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
target string
|
||||
want string
|
||||
}{
|
||||
{name: "ipv4 with port", target: "192.168.1.1:3389", want: "192.168.1.1"},
|
||||
{name: "hostname with port", target: "rdp.example.com:3389", want: "rdp.example.com"},
|
||||
{name: "bracketed ipv6 with port", target: "[2001:db8::1]:3389", want: "2001:db8::1"},
|
||||
{name: "bare ipv6 without port", target: "2001:db8::1", want: "2001:db8::1"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := rdpTargetHost(tt.target); got != tt.want {
|
||||
t.Fatalf("rdpTargetHost(%q) = %q, want %q", tt.target, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user