github.com/chainreactors/fingers@v1.2.1/nmap/gonmap.go (about) 1 package gonmap 2 3 import ( 4 "regexp" 5 "strings" 6 ) 7 8 // r["PROBE"] 总探针数、r["MATCH"] 总指纹数 、r["USED_PROBE"] 已使用探针数、r["USED_MATCH"] 已使用指纹数 9 // 全局模式已移除,只支持实例模式,使用 NewWithData 创建实例 10 11 // NewWithData 使用指定的数据初始化 Nmap 实例 12 func NewWithData(probesData, servicesData []byte) *Nmap { 13 //初始化NMAP探针库 14 n := &Nmap{ 15 exclude: emptyPortList, 16 probeNameMap: make(map[string]*Probe), 17 rarityProbeMap: make(map[int][]*Probe), 18 portProbeMap: make(map[int]ProbeList), 19 20 sslSecondProbeMap: []string{"TCP_TerminalServerCookie", "TCP_TerminalServer"}, 21 sslProbeMap: []string{"TCP_TLSSessionReq", "TCP_SSLSessionReq", "TCP_SSLv23SessionReq"}, 22 } 23 for i := 0; i <= 65535; i++ { 24 n.portProbeMap[i] = []string{} 25 } 26 27 // 初始化ServicesData - 从bytes加载(已解压缩) 28 n.loadServicesFromBytes(servicesData) 29 30 // 从提供的数据加载探针数据(已解压缩) 31 n.loadProbesFromBytes(probesData) 32 33 //修复fallback 34 n.fixFallback() 35 36 // 自定义指纹 (使用实例方法) 37 n.addCustomMatches() 38 39 // 优化探针 (使用实例方法) 40 n.optimizeProbes() 41 42 return n 43 } 44 45 var regexpFirstNum = regexp.MustCompile(`^\d`) 46 47 func FixProtocol(oldProtocol string) string { 48 //进行最后输出修饰 49 if oldProtocol == "ssl/http" { 50 return "https" 51 } 52 if oldProtocol == "http-proxy" { 53 return "http" 54 } 55 if oldProtocol == "ms-wbt-server" { 56 return "rdp" 57 } 58 if oldProtocol == "microsoft-ds" { 59 return "smb" 60 } 61 if oldProtocol == "netbios-ssn" { 62 return "netbios" 63 } 64 if oldProtocol == "oracle-tns" { 65 return "oracle" 66 } 67 if oldProtocol == "msrpc" { 68 return "rpc" 69 } 70 if oldProtocol == "ms-sql-s" { 71 return "mssql" 72 } 73 if oldProtocol == "domain" { 74 return "dns" 75 } 76 if oldProtocol == "svnserve" { 77 return "svn" 78 } 79 if oldProtocol == "ibm-db2" { 80 return "db2" 81 } 82 if oldProtocol == "socks-proxy" { 83 return "socks5" 84 } 85 if len(oldProtocol) > 4 { 86 if oldProtocol[:4] == "ssl/" { 87 return oldProtocol[4:] + "-ssl" 88 } 89 } 90 if regexpFirstNum.MatchString(oldProtocol) { 91 oldProtocol = "S" + oldProtocol 92 } 93 oldProtocol = strings.ReplaceAll(oldProtocol, "_", "-") 94 return oldProtocol 95 }