fix: CSRF extraction looks for specific zoraxy.csrf.Token

This commit is contained in:
Claus Lohmar 2026-07-08 09:28:54 +01:00
parent 94ae185d47
commit e52b7e6915

View file

@ -35,8 +35,7 @@ func main() {
body, _ := io.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
resp.Body.Close() resp.Body.Close()
re := regexp.MustCompile(`content="([^"]+)"`) csrf := extractCSRF(string(body))
csrf := extractCSRF(string(body), re)
if csrf == "" { if csrf == "" {
fmt.Fprintf(os.Stderr, "FAIL: could not extract CSRF token\n") fmt.Fprintf(os.Stderr, "FAIL: could not extract CSRF token\n")
os.Exit(1) os.Exit(1)
@ -106,7 +105,7 @@ func main() {
} }
b, _ := io.ReadAll(resp.Body) b, _ := io.ReadAll(resp.Body)
resp.Body.Close() resp.Body.Close()
csrf = extractCSRF(string(b), re) csrf = extractCSRF(string(b))
if csrf == "" { if csrf == "" {
fmt.Printf("WARN: %s no CSRF token\n", domain) fmt.Printf("WARN: %s no CSRF token\n", domain)
continue continue
@ -138,21 +137,16 @@ func main() {
} }
} }
func extractCSRF(html string, re *regexp.Regexp) string { func extractCSRF(html string) string {
match := re.FindAllStringSubmatch(html, -1)
for _, m := range match {
if len(m) > 1 && len(m[1]) > 20 {
return m[1]
}
}
// Try looking for the specific zoraxy.csrf.Token pattern
idx := strings.Index(html, "zoraxy.csrf.Token") idx := strings.Index(html, "zoraxy.csrf.Token")
if idx >= 0 { if idx < 0 {
sub := html[idx:] return ""
m := re.FindStringSubmatch(sub) }
if len(m) > 1 { sub := html[idx:]
return m[1] re := regexp.MustCompile(`content="([^"]+)"`)
} m := re.FindStringSubmatch(sub)
if len(m) > 1 {
return m[1]
} }
return "" return ""
} }