我正在尝试做一个程序,将允许我提交一个网站上的用户名和密码。为此,我使用的是运行在localhost:8080上的DVWA
(该死的易受攻击的Web应用程序)
但每当我尝试发送post请求时,它总是返回一个错误
csrf token is incorrect
这是我的密码:
import requests
url = 'http://192.168.43.1:8080/login.php'
data_dict = {"username": "admin", "password": "password", "Login": "Login"}
response = requests.post(url, data_dict)
print(response.text)
您需要首先对该URL发出GET请求,并从响应中解析正确的“CSRF”值(在本例中为
user_token
)。从响应HTML中,您可以找到隐藏值:另外,您似乎需要将第一个
GET
请求中的cookie包含在下一个请求中——这可以通过使用request.Session()对象自动完成。您可以通过第一个响应中的print(resp.cookies)
来查看cookie下面是修改后的代码。我正在使用BeautifulSoup库解析html—它找到正确的输入字段,并从中获取值
POST
方法随后在user_token
参数中使用此值相关问题 更多 >
编程相关推荐