django 登录验证视图
[Python] 纯文本查看 复制代码 def login_view(request):
user = None
if request.method == "GET":
# 漏洞
print(request.session['username'])
if request.session.get('username') and request.session.get('userid'):
return HttpResponse("已经登录")
return render(request, "user/login.html")
elif request.method == "POST":
username = request.POST.get('username', None)
password = request.POST.get('password', None)
try:
user = User.objects.get(username=username)
except Exception as err:
print(f'--login user err:{err}')
return HttpResponse('用户名或者密码不匹配')
m = hashlib.md5()
m.update(password.encode())
if user.password == m.hexdigest():
request.session['username'] = username
request.session['userid'] = user.id
else:
return HttpResponse('用户名或者密码不匹配')
resp = HttpResponse('登录成功')
if 'remember' in request.POST:
resp.set_cookie('username', username, 60*60*24*3)
resp.set_cookie('userid', user.id, 60*60*24*3)
return resp
python requests 库获取session 值后,轻松突破这个验证!!!代码如下:
[Python] 纯文本查看 复制代码 data = {"sessionid" : "ontpw9i4q6wh361b2lksm3lcz6hix92q"}
res = requests.get('http://127.0.0.1:8008/user/login', cookies = data)
print(res.content.decode())
print(res.cookies)
求大佬讲讲可靠方法! |