mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-24 04:01:52 +08:00
feat: 统一服务缓存 + 指纹驱动插件匹配
将 webServiceCache 扩展为通用 serviceCache,所有指纹识别结果 统一缓存,插件匹配时端口不命中则回退到服务名称匹配。 删除多余的 service_cache.go,复用已有的 ServiceInfo 体系。 补充 nil 防御、Explicit 标记、大量单元/集成/回归测试。
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ldapURL(host string, port int) string {
|
||||
return fmt.Sprintf("ldap://%s", net.JoinHostPort(host, strconv.Itoa(port)))
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package local
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestLDAPURLUsesJoinHostPort(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
host string
|
||||
port int
|
||||
want string
|
||||
}{
|
||||
{name: "hostname", host: "dc.example.local", port: 389, want: "ldap://dc.example.local:389"},
|
||||
{name: "ipv4", host: "192.168.1.10", port: 389, want: "ldap://192.168.1.10:389"},
|
||||
{name: "ipv6", host: "2001:db8::10", port: 389, want: "ldap://[2001:db8::10]:389"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := ldapURL(tt.host, tt.port); got != tt.want {
|
||||
t.Fatalf("ldapURL(%q, %d) = %q, want %q", tt.host, tt.port, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -82,10 +82,10 @@ func (p *SystemInfoPlugin) connectToDomain(domain string) (*domainInfo, error) {
|
||||
}
|
||||
defer func() { _ = client.Close() }()
|
||||
|
||||
conn, err := ldap.DialURL(fmt.Sprintf("ldap://%s:389", dcHost))
|
||||
conn, err := ldap.DialURL(ldapURL(dcHost, 389))
|
||||
if err != nil {
|
||||
if ipv4, resolveErr := resolveIPv4(dcHost); resolveErr == nil {
|
||||
conn, err = ldap.DialURL(fmt.Sprintf("ldap://%s:389", ipv4))
|
||||
conn, err = ldap.DialURL(ldapURL(ipv4, 389))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("LDAP dial: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user