github.com/chainreactors/fingers@v1.2.1/nmap/type-fingerprint.go (about) 1 package gonmap 2 3 import "github.com/chainreactors/fingers/common" 4 5 type FingerPrint struct { 6 ProbeName string `json:"probe_name,omitempty"` 7 MatchRegexString string `json:"match_regex,omitempty"` 8 9 Service string `json:"service,omitempty"` 10 ProductName string `json:"product_name,omitempty"` 11 Version string `json:"version,omitempty"` 12 Info string `json:"info,omitempty"` 13 Hostname string `json:"hostname,omitempty"` 14 OperatingSystem string `json:"operating_system,omitempty"` 15 DeviceType string `json:"device_type,omitempty"` 16 17 // CPE信息,支持多个CPE条目 18 CPEs []string `json:"cpes,omitempty"` 19 // 解析后的CPE属性 20 CPEAttributes []*common.Attributes `json:"cpe_attributes,omitempty"` 21 // p/vendorproductname/ 22 // v/version/ 23 // i/info/ 24 // h/hostname/ 25 // o/operatingsystem/ 26 // d/devicetype/ 27 // c/cpe/ - CPE信息 28 } 29 30 // ToFrameworks 将FingerPrint转换为多个common.Framework,支持多个CPE app 31 func (fp *FingerPrint) ToFrameworks() []*common.Framework { 32 if fp.Service == "" { 33 return nil 34 } 35 36 var frameworks []*common.Framework 37 38 // 修复协议名称 39 service := FixProtocol(fp.Service) 40 41 // 如果有CPE app类型的属性,为每个创建一个Framework 42 appCPEAttrs := fp.getAppCPEAttributes() 43 44 if len(appCPEAttrs) > 0 { 45 // 为每个app类型的CPE创建Framework 46 for _, attr := range appCPEAttrs { 47 framework := common.NewFramework(service, common.FrameFromNmap) 48 fp.populateFramework(framework, attr) 49 frameworks = append(frameworks, framework) 50 } 51 } else { 52 // 没有CPE app信息,创建基本的Framework 53 framework := common.NewFramework(service, common.FrameFromNmap) 54 fp.populateFramework(framework, nil) 55 frameworks = append(frameworks, framework) 56 } 57 58 return frameworks 59 } 60 61 // getAppCPEAttributes 获取所有app类型的CPE属性 62 func (fp *FingerPrint) getAppCPEAttributes() []*common.Attributes { 63 var appAttrs []*common.Attributes 64 for _, attr := range fp.CPEAttributes { 65 if attr != nil && attr.Part == "a" { // 只关心application类型 66 appAttrs = append(appAttrs, attr) 67 } 68 } 69 return appAttrs 70 } 71 72 // populateFramework 填充Framework的信息 73 func (fp *FingerPrint) populateFramework(framework *common.Framework, cpeAttr *common.Attributes) { 74 // 优先使用CPE属性,其次使用FingerPrint属性 75 if cpeAttr != nil { 76 // 使用CPE中的产品和版本信息 77 if cpeAttr.Product != "" { 78 framework.Product = cpeAttr.Product 79 } 80 if cpeAttr.Version != "" { 81 framework.Version = cpeAttr.Version 82 } 83 // 将厂商信息添加到标签中 84 if cpeAttr.Vendor != "" { 85 framework.Tags = append(framework.Tags, "vendor:"+cpeAttr.Vendor) 86 } 87 } else { 88 // 使用FingerPrint中的基本信息 89 if fp.ProductName != "" { 90 framework.Product = fp.ProductName 91 } 92 if fp.Version != "" { 93 framework.Version = fp.Version 94 } 95 } 96 97 // 添加其他信息到标签 98 if fp.Info != "" { 99 framework.Tags = append(framework.Tags, fp.Info) 100 } 101 if fp.Hostname != "" { 102 framework.Tags = append(framework.Tags, "hostname:"+fp.Hostname) 103 } 104 if fp.DeviceType != "" { 105 framework.Tags = append(framework.Tags, "device:"+fp.DeviceType) 106 } 107 108 // 将所有CPE字符串添加到标签中(只保留app类型的) 109 for i, cpe := range fp.CPEs { 110 if i < len(fp.CPEAttributes) && fp.CPEAttributes[i] != nil && fp.CPEAttributes[i].Part == "a" { 111 framework.Tags = append(framework.Tags, "cpe:"+cpe) 112 } 113 } 114 115 // 标记为主动扫描结果 116 framework.Froms = map[common.From]bool{common.FrameFromACTIVE: true} 117 }