You are on page 1of 9

Mini Project on Information and Cyber Security: SQL

(Structured Query Language) Injection

Members:

Ekta Bhosale (Roll No-153 and PRN no. 71627738H)

Virangni Gaikwad (Roll No-156 and PRN no. 71627571G)

Ankita Istalkar (Roll No-160 and PRN no. 71627750G)

Rajashri Tapkir (Roll No-161 and PRN no. 71627815E)

Title:-
Apply SQL (Structured Query Language) Injection to demonstrate that user
should never click random links to avoid any attacks.

Problem Statement:-
To developed two separate web pages for implementing XSS and SQL
injections attacks.

Theory :-
What is SQL Injection
SQL injection, also known as SQLI, is a common attack vector
that uses malicious SQL code for back end database manipulation to access
information that was not intended to be displayed. This information may
include any number of items, including sensitive company data, user lists or
private customer details.
SQL injection is a code injection technique, used to attack data-driven
applications, in which nefarious SQL statements are inserted into an entry
field for execution (e.g. to dump the database contents to the attacker). SQL
injection must exploit a security vulnerability in an application's software, for
example, when user input is either incorrectly filtered for string literal escape
characters embedded in SQL statements or user input is not strongly typed
and unexpectedly executed. SQL injection is mostly known as an attack
vector for websites but can be used to attack any type of SQL database.
The impact SQL injection can have on a business is far reaching. A
successful attack may result in the unauthorized viewing of user lists, the
deletion of entire tables and, in certain cases, the attacker gaining
administrative rights to a database, all of which are highly detrimental to a
business.
SQL injection attacks allow attackers to spoof identity, tamper with
existing data, cause repudiation issues such as voiding transactions or
changing balances, allow the complete disclosure of all data on the system,
destroy the data or make it otherwise unavailable, and become administrators
of the database server.

SQL Injection Attack Architecture:-


What Are SQL Queries
SQL is a standardized language used to access and manipulate databases to
build customizable data views for each user. SQL queries are used to execute
commands, such as data retrieval, updates and record removal. Different SQL
elements implement these tasks, for example, queries using the SELECT
statement to retrieve data, based on user-provided parameters.

SQL Injection Example:-


An attacker wishing to execute SQL injection manipulates a
standard SQL query to exploit non-validated input vulnerabilities in a
database. There are many ways that this attack vector can be executed,
several of which will be shown here to provide you with a general idea about
how SQLI works.
For example:-

Why Is an SQL Injection Attack Performed


To make an SQL Injection attack, an attacker must first find
vulnerable user inputs within the web page or web application. A web page or
web application that has an SQL Injection vulnerability uses such user input
directly in an SQL query. The attacker can create input content. Such content
is often called a malicious payload and is the key part of the attack. After the
attacker sends this content, malicious SQL commands are executed in the
database.

How SQL injections work:-


An attacker needs to find an input that includes SQL queries within the web
application to run vicious SQL queries adjacent to the database server. In
order, for an SQL injection to take place the website need to directly include
user input within SQL statement.
An attacker can insert SQL injection in such a way, from the username and
password database input that would alter the SQL statements being executed
by the SQL database server. Once the query is executed the result will be
processed. An attacker can then insert a payload in SQL query and run
opposite to the database server. The pseudo code to authenticate the user from
server side:
"
# Define POST variables uname = request.POST['username'] passwd =
request.POST['password']
# SQL query vulnerable to SQLi sql = "SELECT id FROM users WHERE
username='" + uname + "' AND password='" + passwd + "'"
# Execute the SQL statement database.execute(sql)"
SELECT id FROM users WHERE username='username' AND
password='password' OR 1=1'
The code is the simple example to insert the username and password in the
username table database. An attacker can control over the rest of SQL query
database execution.

Risk factors
Platform that can be affected from SQL injections
 SQL language
 Any platform that supports SQL.

Main Consequences
 Confidentiality
 Authorization
 Integrity
 Authenticity
How to Prevent an SQL Injection
The only sure way to prevent SQL Injection attacks is input
validation and parameterized queries including prepared statements. The
application code should never use the input directly. The developer must
sanitize all input, not only web form inputs such as login forms.
They must remove potential malicious code elements such as
single quotes. It is also a good idea to turn off the visibility of database errors
on your production sites. Database errors can be used with SQL Injection to
gain information about your database.
If you discover an SQL Injection vulnerability, for example using
an Acunetix scan, you may be unable to fix it immediately. For example, the
vulnerability may be in open source code. In such cases, you can use a web
application firewall to sanitize your input temporarily.
To learn how to prevent SQL Injection attacks in the PHP
language, see: Preventing SQL Injection Vulnerabilities in PHP Applications
and Fixing Them. To find out how to do it in many other different
programming languages, refer to the Bobby Tables guide to preventing SQL
Injection.

Types of SQL Injection (SQLi)


SQL Injection can be used in a range of ways to cause serious
problems. By levering SQL Injection, an attacker could bypass
authentication, access, modify and delete data within a database. In some
cases, SQL Injection can even be used to execute commands on the operating
system, potentially allowing an attacker to escalate to more damaging attacks
inside of a network that sits behind a firewall.
SQL Injection can be classified into three major categories – In-
band SQLi, Inferential SQLi and Out-of-band SQLi.

1) In-band SQLi (Classic SQLi)


In-band SQL Injection is the most common and easy-to-exploit of SQL
Injection attacks. In-band SQL Injection occurs when an attacker is able to
use the same communication channel to both launch the attack and gather
results.
The two most common types of in-band SQL Injection are Error-based
SQLi and Union-based SQLi.

a) Error-based SQLi
Error-based SQLi is an in-band SQL Injection technique that relies on error
messages thrown by the database server to obtain information about the structure of the
database. In some cases, error-based SQL injection alone is enough for an attacker to
enumerate an entire database. While errors are very useful during the development phase
of a web application, they should be disabled on a live site, or logged to a file with
restricted access instead.

b) Union-based SQLi
Union-based SQLi is an in-band SQL injection technique that leverages the
UNION SQL operator to combine the results of two or more SELECT statements into a
single result which is then returned as part of the HTTP response.

2) Inferential SQLi (Blind SQLi)


Inferential SQL Injection, unlike in-band SQLi, may take longer for an
attacker to exploit, however, it is just as dangerous as any other form of SQL
Injection. In an inferential SQLi attack, no data is actually transferred via the
web application and the attacker would not be able to see the result of an
attack in-band (which is why such attacks are commonly referred to as “blind
SQL Injection attacks”). Instead, an attacker is able to reconstruct the
database structure by sending payloads, observing the web application’s
response and the resulting behavior of the database server.
The two types of inferential SQL Injection are Blind-boolean-based
SQLi and Blind-time-based SQLi.

a) Boolean-based (content-based) Blind SQLi


Boolean-based SQL Injection is an inferential SQL Injection technique that relies on
sending an SQL query to the database which forces the application to return a different
result depending on whether the query returns a TRUE or FALSE result.
Depending on the result, the content within the HTTP response will change, or remain
the same. This allows an attacker to infer if the payload used returned true or false, even
though no data from the database is returned. This attack is typically slow (especially on
large databases) since an attacker would need to enumerate a database, character by
character.

b) Time-based Blind SQLi


Time-based SQL Injection is an inferential SQL Injection technique that relies on
sending an SQL query to the database which forces the database to wait for a specified
amount of time (in seconds) before responding. The response time will indicate to the
attacker whether the result of the query is TRUE or FALSE.
Depending on the result, an HTTP response will be returned with a delay, or returned
immediately. This allows an attacker to infer if the payload used returned true or false,
even though no data from the database is returned. This attack is typically slow
(especially on large databases) since an attacker would need to enumerate a database
character by character.

3) Out-of-band SQLi
Out-of-band SQL Injection is not very common, mostly because it
depends on features being enabled on the database server being used by the
web application. Out-of-band SQL Injection occurs when an attacker is
unable to use the same channel to launch the attack and gather results.
Out-of-band techniques, offer an attacker an alternative to inferential
time-based techniques, especially if the server responses are not very stable
(making an inferential time-based attack unreliable).
Out-of-band SQLi techniques would rely on the database server’s
ability to make DNS or HTTP requests to deliver data to an attacker. Such is
the case with Microsoft SQL Server’s xp_dirtree command, which can be
used to make DNS requests to a server an attacker controls; as well as Oracle
Database’s UTL_HTTP package, which can be used to send HTTP requests
from SQL and PL/SQL to a server an attacker controls.

Conclusion :-
We have developed two separate web pages for implementing XSS and SQL
injections attacks.
In first webpage we have implemented a normal form for user information. In
this insecure web page we implemented PHP program that successfully
implements SQL and XSS attacks. With this page one can implement the
attacks by putting queries in forms. By this we can access whole database
information.
In opposite to that in secure webpage no one can implement SQL injections
and XSS attacks as attacks have been disabled. There is also external attack
that can be performed if user clicks on reload link given. This is to
demonstrate that user should never click random links to avoid any attacks.

You might also like