{% extends "introduction/base.html" %} {% load static %} {% block content %} {% block title %}
SQL injection errors occur when: Data enters a program from an untrusted source. The data used to dynamically construct a SQL query The main consequences are:
This lab helps you to exploit the common type of sql injection vulnerability, caused due to the lack of
input validation and directly exposing input into the query.
The user on accessing the lab is given a log in page . The user has to try to login in as admin.
SQL Injection vulnerability can be identified by injecting a ' in any of the fields. If it
results in an SQL error, SQL injection vulnerability is identified
Exploiting SQL Injection Vulnerability
anything' OR '1' ='1
The website logs a user in by checking the entered username and password against the ones stored in the
database. If they match, the user is logged in.
Lets first analyse the sql query used to compare the username and password in the database.
"SELECT * FROM introduction_login WHERE user='"+name+"'AND password='"+password+"'"
The name and password parameters are the ones you give as input, which is directly inserted into the
query.
Why the error?
When we inserted a ' in the input it threw an error , this is because the sql query was not
balanced and it threw an error.
SELECT * FROM introduction_login WHERE user='admin' AND password='''
The query quotes in the password field are unbalanced, this can be balanced by adding another quote to
it.
Lets just plug our payload into the query and see what it looks like.
SELECT * FROM introduction_login WHERE user='admin' AND password='anything' OR '1' ='1'
Now the query means select username = admin where password is anything OR '1'='1' .
'1'='1' will always result in TRUE and the query fetches the user with name admin and
password=TRUE.
Thus allowing us to login in as admin.