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