package core import ( "net/url" "regexp" "strings" ) // decode percent-decodes s up to twice (double encoding is a common evasion). func decode(s string) string { for i := 0; i < 2; i++ { d, err := url.QueryUnescape(s) if err != nil || d == s { break } s = d } return s } // Class is the verdict on one web request. type Class struct { Cat Category // Soft: a scanner/exploit probe the server answered with 2xx/3xx. It may be // a false positive (SPA fallback, documentation page), so it weighs little. Soft bool // Strong: a high confidence exploit attempt that was refused (4xx/5xx). Strong bool // Weak: only a weak exploit marker (cmd=, |sh, eval(...)) matched. The runner // promotes it to an exploit when the User-Agent is an attack tool. Weak bool } var strongMarkers = []string{ "../", "..\\", "..;/", "%2e%2e", "/etc/passwd", "/etc/shadow", "/proc/self", "${jndi:", "= 400 if hasAny(strongMarkers, raw, dec) || shellRe.MatchString(dec) { return Class{Cat: Exploit, Soft: !refused, Strong: refused} } path := dec if i := strings.IndexAny(path, "?#"); i >= 0 { path = path[:i] } if isBrute(method, path, status) { return Class{Cat: BruteForce} } if isScanner(path, status) { return Class{Cat: Scanner, Soft: !refused} } c := Class{Cat: OK} if status >= 400 && status < 500 { c.Cat = NotFound } c.Weak = hasAny(weakMarkers, raw, dec) return c } // ClassifyHTTP returns only the category of Classify. func ClassifyHTTP(method, rawPath string, status int) Category { return Classify(method, rawPath, status).Cat }