Bonjour,
J'essaye de m'authentifier via une requête POST sur une page login:pwd mais j'obtiens en retour le message : CSRF token is incorrect
Pour ce faire j'avais tout d'abord vérifier ce qui était envoyer vers le serveur en mettant un proxy en local:
POST /DVWA/login.php HTTP/1.1
Host: 192.168.1.1
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://192.168.1.1/DVWA/login.php
Cookie: security=impossible; PHPSESSID=ts5ukkrqubipdpl78ikh0udgc2
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 88
username=admin&password=password&Login=Login&user_token=4b15ab58a05f70ec713bca21d807f0a6
Voici mon code:
Je comprend pas pq j'obtiens cette erreur alors que le token que je récupère est identique à celui envoyé par le serveur ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 mport requests URL='http://192.168.1.1/DVWA/login.php' session = requests.Session() session.get(URL) #cookie recovering cookies = session.cookies.get_dict() user_token = requests.get(URL).text print user_token #we look for the the position of the work 'token' in the string start_index = user_token.find('token') #I add +14 to parse at the beginning of the token value start_index=start_index+14 #each character of the string is lined feeded #I use the line feed as separator to reaasemble the string #I use +32 because the token is 32 character long anti_csrf = user_token[start_index:start_index+32].split('\n')[0] #I encapsulate my value in quotes anti_csrf="'"+anti_csrf+"'" print "\nANTI-CSRF token recovered:" print anti_csrf #data to send via POST METHOD data = {'username':'admin','password':'password','user_token':anti_csrf,'Login':'Login'} #authenticate on the website auth = requests.post(URL, cookies=cookies, data=data) print auth.text
Peut-être je l'envois mal ?
Cdlt
Partager