📦 EqualifyEverything / dockerized-wappalyzer

📄 fingerprint_cookies.go · 56 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56package wappalyzer

import (
	"strings"
)

// checkCookies checks if the cookies for a target match the fingerprints
// and returns the matched IDs if any.
func (s *Wappalyze) checkCookies(cookies []string) []string {
	// Normalize the cookies for further processing
	normalized := s.normalizeCookies(cookies)

	technologies := s.fingerprints.matchMapString(normalized, cookiesPart)
	return technologies
}

const keyValuePairLength = 2

// normalizeCookies normalizes the cookies and returns an
// easily parsed format that can be processed upon.
func (s *Wappalyze) normalizeCookies(cookies []string) map[string]string {
	normalized := make(map[string]string)

	for _, part := range cookies {
		parts := strings.SplitN(strings.Trim(part, " "), "=", keyValuePairLength)
		if len(parts) < keyValuePairLength {
			continue
		}
		normalized[parts[0]] = parts[1]
	}
	return normalized
}

// findSetCookie finds the set cookie header from the normalized headers
func (s *Wappalyze) findSetCookie(headers map[string]string) []string {
	value, ok := headers["set-cookie"]
	if !ok {
		return nil
	}

	var values []string
	for _, v := range strings.Split(value, " ") {
		if v == "" {
			continue
		}
		if strings.Contains(v, ",") {
			values = append(values, strings.Split(v, ",")...)
		} else if strings.Contains(v, ";") {
			values = append(values, strings.Split(v, ";")...)
		} else {
			values = append(values, v)
		}
	}
	return values
}