模拟sql注入

  1. 使用原生sql语句编写login登录逻辑
class LoginUnsafeView(View):
    def get(self, request):
        return render(request, "login.html", {})

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

        import MySQLdb
        conn = MySQLdb.connect(host='127.0.0.1', user='root', passwd="root", db="mxonline", charset='utf8')
        cursor = conn.cursor()
        sql_select = "select * from users_userprofile where email='{0}' and password='{1}'".format(user_name, pass_word)

        result = cursor.execute(sql_select)
        for row in cursor.fetchall():
            # 查询到用户
            pass
        print 'login end'

 

编写url

django中安全sql注入等

页面登录测试

django中安全sql注入等

随意输入aaa/aaa,可以看到是不可能登录成功的

django中安全sql注入等

登录框输入 ' OR 1 = 1#
空格单引号  'or 1=1#

可以看到sql语句拼凑成功绕过验证

django中安全sql注入等

相关文章:

  • 2021-07-02
  • 2022-12-23
  • 2022-01-11
  • 2021-06-05
  • 2022-01-25
  • 2021-09-30
  • 2022-12-23
  • 2021-08-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2022-01-01
  • 2021-04-20
  • 2022-02-01
相关资源
相似解决方案