github.com/chainreactors/fingers@v1.2.1/wappalyzer/fingerprint_cookies.go (about) 1 package wappalyzer 2 3 import ( 4 "github.com/chainreactors/fingers/common" 5 "strings" 6 ) 7 8 // checkCookies checks if the cookies for a target match the fingerprints 9 // and returns the matched IDs if any. 10 func (engine *Wappalyze) checkCookies(cookies []string) common.Frameworks { 11 // Normalize the cookies for further processing 12 normalized := engine.normalizeCookies(cookies) 13 14 technologies := engine.fingerprints.matchMapString(normalized, cookiesPart) 15 return technologies 16 } 17 18 const keyValuePairLength = 2 19 20 // normalizeCookies normalizes the cookies and returns an 21 // easily parsed format that can be processed upon. 22 func (engine *Wappalyze) normalizeCookies(cookies []string) map[string]string { 23 normalized := make(map[string]string) 24 25 for _, part := range cookies { 26 parts := strings.SplitN(strings.Trim(part, " "), "=", keyValuePairLength) 27 if len(parts) < keyValuePairLength { 28 continue 29 } 30 normalized[parts[0]] = parts[1] 31 } 32 return normalized 33 } 34 35 // findSetCookie finds the set cookie header from the normalized headers 36 func (engine *Wappalyze) findSetCookie(headers map[string]string) []string { 37 value, ok := headers["set-cookie"] 38 if !ok { 39 return nil 40 } 41 42 var values []string 43 for _, v := range strings.Split(value, " ") { 44 if v == "" { 45 continue 46 } 47 if strings.Contains(v, ",") { 48 values = append(values, strings.Split(v, ",")...) 49 } else if strings.Contains(v, ";") { 50 values = append(values, strings.Split(v, ";")...) 51 } else { 52 values = append(values, v) 53 } 54 } 55 return values 56 }