mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 03:10:42 +08:00
端口扫描识别到 8881 上运行 SSH,但 SSH 插件只注册了 [22,2222,2200,22222], 端口不匹配导致插件不执行。 新增服务名称缓存:端口扫描阶段记录 host:port → serviceName, 插件匹配时端口不命中则回退到服务名称匹配。
37 lines
932 B
Go
37 lines
932 B
Go
package core
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// 服务识别缓存:host:port → 服务名称
|
|
// 端口扫描阶段写入,插件匹配阶段读取
|
|
// 解决非标准端口上的服务无法匹配对应插件的问题
|
|
var (
|
|
serviceNameCache = make(map[string]string)
|
|
serviceCacheMu sync.RWMutex
|
|
)
|
|
|
|
// MarkServiceName 记录端口上识别到的服务名称
|
|
func MarkServiceName(host string, port int, serviceName string) {
|
|
if serviceName == "" || serviceName == "unknown" {
|
|
return
|
|
}
|
|
key := net.JoinHostPort(host, strconv.Itoa(port))
|
|
serviceCacheMu.Lock()
|
|
serviceNameCache[key] = strings.ToLower(serviceName)
|
|
serviceCacheMu.Unlock()
|
|
}
|
|
|
|
// GetServiceName 查询端口上的服务名称
|
|
func GetServiceName(host string, port int) (string, bool) {
|
|
key := net.JoinHostPort(host, strconv.Itoa(port))
|
|
serviceCacheMu.RLock()
|
|
name, ok := serviceNameCache[key]
|
|
serviceCacheMu.RUnlock()
|
|
return name, ok
|
|
}
|