Django 开发 MxOnline 项目笔记 -- 第12章

2018-03-09  本文已影响70人  江湖十年
  1. sql 注入攻击


    01.png
# apps/users/views.py

class LoginUnSafeView(View):
    """
    不安全的登录类视图测试,
    不使用 django 的 login 来验证数据,
    """
    def get(self, request):
        context = {}
        return render(request, "login.html", context)

    def post(self, request):
        user_name = request.POST.get("username", "")
        user_password = request.POST.get("password", "")

        import pymysql
        conn = pymysql.connect(host="127.0.0.1", port=3306, user="pythonic", passwd="pythonic", db="mxonline", charset="utf8")
        cursor = conn.cursor()
        sql_select = "select * from users_userprofile where email='{0}' and password='{1}'".format(user_name, user_password)
        result = cursor.execute(sql_select)


        for row in cursor.fetchall():
            # 查询到用户, 执行用户登录的逻辑
            pass

        # 未查询到用户, 执行的代码
        print("test")

# apps/users/urls.py

from users.views import LoginUnSafeView


urlpatterns = [
    ...
    path("login/", LoginUnSafeView.as_view(), name="login"),
]

03.png 05.png 07.png
  1. xss 攻击


    08.png
10.png 11.png
  1. csrf 攻击


    12.png
13.png
上一篇 下一篇

猜你喜欢

热点阅读