SlideShare a Scribd company logo
1 of 27
Download to read offline
SQL Injection
Tayyip Gören
Maltepe Üniversitesi
08.05.2020
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 1 / 27
Section 1
What is SQL?
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 2 / 27
What is a Database?
First things first. Here is a defitiniton from techtarget.com
Definition
A database is a collection of information that is organized so that it can be
easily accessed, managed and updated. Computer databases typically
contain aggregations of data records or files, containing information about
sales transactions or interactions with specific customers.
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 3 / 27
Example Table
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 4 / 27
Popular Databases
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 5 / 27
What is SQL?
SQL stands for Structured Query Language
Definition
1 SQL lets you access and manipulate databases
2 SQL became a standard of the American National Standards Institute
(ANSI) in 1986, and of the International Organization for
Standardization (ISO) in 1987
3 SQL can execute queries against a database
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 6 / 27
Section 2
What is SQL Injection
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 7 / 27
Definition
SQL injection is a code injection technique that might destroy your
database.
SQL injection is one of the most common web hacking techniques.
SQL injection is the placement of malicious code in SQL statements, via
web page input.
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 8 / 27
SQL in Web Pages
SQL injection usually occurs when you ask a user for input, like their
username/userid, and instead of a name/id, the user gives you an SQL
statement that you will unknowingly run on your database.
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 9 / 27
Look at the following example which creates a SELECT statement by
adding a variable (txtUserId) to a select string. The variable is fetched from
user input (getRequestString):
txtUserId = getRequestString("UserId");
txtSQL = "SELECT * FROM Users WHERE UserId = " + txtUserId;
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 10 / 27
The original purpose of the code was to create an SQL statement to select
a user, with a given user id.
If there is nothing to prevent a user from entering “wrong” input, the user
can enter some “smart” input like this:
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 11 / 27
Then, the SQL statement will look like this:
SELECT * FROM Users WHERE UserId = 105 OR 1=1;
The SQL above is valid and will return ALL rows from the “Users”
table, since OR 1=1 is always TRUE.
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 12 / 27
Passwords
Does the example look dangerous? What if the “Users” table contains
names and passwords?
The SQL statement above is much the same as this:
SELECT UserId, Name, Passwords FROM Users
WHERE UserId = 105 or 1=1;
The SQL above is valid and will return ALL rows from the “Users” table
which includes passwords this time, since OR 1=1 is always TRUE.
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 13 / 27
SQL Injection Based on "“=”" is Always True
Here is an example of a user login on a web site:
uName = getRequestString("username");
uPass = getRequestString("userpassword");
sql = ’SELECT * FROM Users WHERE Name ="’ + uName + ’"
AND Pass ="’ + uPass + ’"’
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 14 / 27
Result:
SELECT * FROM Users WHERE Name ="John Doe" AND Pass ="myPass"
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 15 / 27
A hacker might get access to user names and passwords in a database by
simply inserting " OR "“=” into the user name or password text box:
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 16 / 27
The code at the server will create a valid SQL statement like this:
SELECT * FROM Users WHERE Name ="" or ""=""
AND Pass ="" or ""=""
The SQL above is valid and will return all rows from the “Users” table,
since OR "“=”" is always TRUE.
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 17 / 27
SQL Injection Based on Batched SQL Statements
Most databases support batched SQL statement.
A batch of SQL statements is a group of two or more SQL statements,
separated by semicolons.
The SQL statement below will return all rows from the “Users” table, then
delete the “Suppliers” table.
SELECT * FROM Users; DROP TABLE Suppliers
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 18 / 27
Look at the following example:
txtUserId = getRequestString("UserId");
txtSQL = "SELECT * FROM Users WHERE UserId = " + txtUserId;
And the following input:
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 19 / 27
The valid SQL statement would look like this:
SELECT * FROM Users WHERE UserId = 105; DROP TABLE Suppliers;
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 20 / 27
Section 3
Protection For SQL Injection
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 21 / 27
Use SQL Parameters for Protection
To protect a web site from SQL injection, you can use SQL parameters.
SQL parameters are values that are added to an SQL query at execution
time, in a controlled manner.
ASP.NET Razor Example
txtUserId = getRequestString("UserId");
txtSQL = "SELECT * FROM Users WHERE UserId = @0";
db.Execute(txtSQL,txtUserId);
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 22 / 27
Note that parameters are represented in the SQL statement by a @ marker.
The SQL engine checks each parameter to ensure that it is correct for its
column and are treated literally, and not as part of the SQL to be executed.
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 23 / 27
Another Example In C#
txtNam = getRequestString("CustomerName");
txtAdd = getRequestString("Address");
txtCit = getRequestString("City");
txtSQL = "INSERT INTO Customers " +
"(CustomerName,Address,City) Values(@0,@1,@2)";
db.Execute(txtSQL,txtNam,txtAdd,txtCit);
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 24 / 27
INSERT INTO Statement in ASP.NET
txtNam = getRequestString("CustomerName");
txtAdd = getRequestString("Address");
txtCit = getRequestString("City");
txtSQL = "INSERT INTO Customers" +
"(CustomerName,Address,City) Values(@0,@1,@2)";
command = new SqlCommand(txtSQL);
command.Parameters.AddWithValue("@0",txtNam);
command.Parameters.AddWithValue("@1",txtAdd);
command.Parameters.AddWithValue("@2",txtCit);
command.ExecuteNonQuery();
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 25 / 27
INSERT INTO in PHP
$stmt = $dbh->prepare("INSERT INTO Customers" +
"(CustomerName,Address,City) VALUES (:nam, :add, :cit)");
$stmt->bindParam(’:nam’, $txtNam);
$stmt->bindParam(’:add’, $txtAdd);
$stmt->bindParam(’:cit’, $txtCit);
$stmt->execute();
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 26 / 27
Section 4
Thank You
Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 27 / 27

More Related Content

What's hot

Sql injection attack
Sql injection attackSql injection attack
Sql injection attackRaghav Bisht
 
Time-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy QueriesTime-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy QueriesChema Alonso
 
Time-Based Blind SQL Injection
Time-Based Blind SQL InjectionTime-Based Blind SQL Injection
Time-Based Blind SQL Injectionmatt_presson
 
Time-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesTime-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesChema Alonso
 
Microsoft Information Protection Implementation using C# and PowerShell
Microsoft Information Protection Implementation using C# and PowerShellMicrosoft Information Protection Implementation using C# and PowerShell
Microsoft Information Protection Implementation using C# and PowerShellAditya Sharma
 
3 bus208222 4.0_en_industrial_it_quality_control_theory_of_operation_guide
3 bus208222 4.0_en_industrial_it_quality_control_theory_of_operation_guide3 bus208222 4.0_en_industrial_it_quality_control_theory_of_operation_guide
3 bus208222 4.0_en_industrial_it_quality_control_theory_of_operation_guidedogo101
 
Advanced SQL Injection: Attacks
Advanced SQL Injection: Attacks Advanced SQL Injection: Attacks
Advanced SQL Injection: Attacks Nuno Loureiro
 
SQL Injection Tutorial
SQL Injection TutorialSQL Injection Tutorial
SQL Injection TutorialMagno Logan
 
Dependency rejection and TDD without Mocks
Dependency rejection and TDD without MocksDependency rejection and TDD without Mocks
Dependency rejection and TDD without MocksAntya Dev
 
DREAM Principles & User Guide 1.0
DREAM Principles & User Guide 1.0DREAM Principles & User Guide 1.0
DREAM Principles & User Guide 1.0Marcus Drost
 

What's hot (20)

Sql injection attack
Sql injection attackSql injection attack
Sql injection attack
 
Time-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy QueriesTime-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy Queries
 
Time-Based Blind SQL Injection
Time-Based Blind SQL InjectionTime-Based Blind SQL Injection
Time-Based Blind SQL Injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
Time-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesTime-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy Queries
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
 
Microsoft Information Protection Implementation using C# and PowerShell
Microsoft Information Protection Implementation using C# and PowerShellMicrosoft Information Protection Implementation using C# and PowerShell
Microsoft Information Protection Implementation using C# and PowerShell
 
3 bus208222 4.0_en_industrial_it_quality_control_theory_of_operation_guide
3 bus208222 4.0_en_industrial_it_quality_control_theory_of_operation_guide3 bus208222 4.0_en_industrial_it_quality_control_theory_of_operation_guide
3 bus208222 4.0_en_industrial_it_quality_control_theory_of_operation_guide
 
Advanced SQL Injection: Attacks
Advanced SQL Injection: Attacks Advanced SQL Injection: Attacks
Advanced SQL Injection: Attacks
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
 
SQL Injection Tutorial
SQL Injection TutorialSQL Injection Tutorial
SQL Injection Tutorial
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL Injection in JAVA
SQL Injection in JAVASQL Injection in JAVA
SQL Injection in JAVA
 
Test magic - iAuto Heal for test automation
Test magic -  iAuto Heal for test automationTest magic -  iAuto Heal for test automation
Test magic - iAuto Heal for test automation
 
Sql Injection V.2
Sql Injection V.2Sql Injection V.2
Sql Injection V.2
 
Dependency rejection and TDD without Mocks
Dependency rejection and TDD without MocksDependency rejection and TDD without Mocks
Dependency rejection and TDD without Mocks
 
DREAM Principles & User Guide 1.0
DREAM Principles & User Guide 1.0DREAM Principles & User Guide 1.0
DREAM Principles & User Guide 1.0
 
HomeAlone Project
HomeAlone ProjectHomeAlone Project
HomeAlone Project
 
2nd-Order-SQLi-Josh
2nd-Order-SQLi-Josh2nd-Order-SQLi-Josh
2nd-Order-SQLi-Josh
 

Similar to Sql Injection

Code injection and green sql
Code injection and green sqlCode injection and green sql
Code injection and green sqlKaustav Sengupta
 
Chapter 14 sql injection
Chapter 14 sql injectionChapter 14 sql injection
Chapter 14 sql injectionnewbie2019
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL InjectionsHaim Michael
 
D:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql InjectionD:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql Injectionavishkarm
 
SQL Injection in PHP
SQL Injection in PHPSQL Injection in PHP
SQL Injection in PHPDave Ross
 
SQL interview questions jeetendra mandal - part 5
SQL interview questions jeetendra mandal - part 5SQL interview questions jeetendra mandal - part 5
SQL interview questions jeetendra mandal - part 5jeetendra mandal
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injectionashish20012
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLLukas Eder
 
Php & Web Security - PHPXperts 2009
Php & Web Security - PHPXperts 2009Php & Web Security - PHPXperts 2009
Php & Web Security - PHPXperts 2009mirahman
 
03. sql and other injection module v17
03. sql and other injection module v1703. sql and other injection module v17
03. sql and other injection module v17Eoin Keary
 
Best Way to Write SQL in Java
Best Way to Write SQL in JavaBest Way to Write SQL in Java
Best Way to Write SQL in JavaGerger
 
References - sql injection
References - sql injection References - sql injection
References - sql injection Mohammed
 

Similar to Sql Injection (20)

Code injection and green sql
Code injection and green sqlCode injection and green sql
Code injection and green sql
 
Sql injection
Sql injectionSql injection
Sql injection
 
Chapter 14 sql injection
Chapter 14 sql injectionChapter 14 sql injection
Chapter 14 sql injection
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL Injections
 
D:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql InjectionD:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql Injection
 
Web application security
Web application securityWeb application security
Web application security
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL Injection Attacks
SQL Injection AttacksSQL Injection Attacks
SQL Injection Attacks
 
SQL Injection in PHP
SQL Injection in PHPSQL Injection in PHP
SQL Injection in PHP
 
SQL interview questions jeetendra mandal - part 5
SQL interview questions jeetendra mandal - part 5SQL interview questions jeetendra mandal - part 5
SQL interview questions jeetendra mandal - part 5
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injection
 
Ijcet 06 10_005
Ijcet 06 10_005Ijcet 06 10_005
Ijcet 06 10_005
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQL
 
Php & Web Security - PHPXperts 2009
Php & Web Security - PHPXperts 2009Php & Web Security - PHPXperts 2009
Php & Web Security - PHPXperts 2009
 
03. sql and other injection module v17
03. sql and other injection module v1703. sql and other injection module v17
03. sql and other injection module v17
 
Database security issues
Database security issuesDatabase security issues
Database security issues
 
Sql injection
Sql injectionSql injection
Sql injection
 
Best Way to Write SQL in Java
Best Way to Write SQL in JavaBest Way to Write SQL in Java
Best Way to Write SQL in Java
 
Sql security
Sql securitySql security
Sql security
 
References - sql injection
References - sql injection References - sql injection
References - sql injection
 

Recently uploaded

Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.CarlotaBedoya1
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445ruhi
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663Call Girls Mumbai
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 

Recently uploaded (20)

Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 

Sql Injection

  • 1. SQL Injection Tayyip Gören Maltepe Üniversitesi 08.05.2020 Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 1 / 27
  • 2. Section 1 What is SQL? Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 2 / 27
  • 3. What is a Database? First things first. Here is a defitiniton from techtarget.com Definition A database is a collection of information that is organized so that it can be easily accessed, managed and updated. Computer databases typically contain aggregations of data records or files, containing information about sales transactions or interactions with specific customers. Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 3 / 27
  • 4. Example Table Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 4 / 27
  • 5. Popular Databases Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 5 / 27
  • 6. What is SQL? SQL stands for Structured Query Language Definition 1 SQL lets you access and manipulate databases 2 SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987 3 SQL can execute queries against a database Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 6 / 27
  • 7. Section 2 What is SQL Injection Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 7 / 27
  • 8. Definition SQL injection is a code injection technique that might destroy your database. SQL injection is one of the most common web hacking techniques. SQL injection is the placement of malicious code in SQL statements, via web page input. Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 8 / 27
  • 9. SQL in Web Pages SQL injection usually occurs when you ask a user for input, like their username/userid, and instead of a name/id, the user gives you an SQL statement that you will unknowingly run on your database. Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 9 / 27
  • 10. Look at the following example which creates a SELECT statement by adding a variable (txtUserId) to a select string. The variable is fetched from user input (getRequestString): txtUserId = getRequestString("UserId"); txtSQL = "SELECT * FROM Users WHERE UserId = " + txtUserId; Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 10 / 27
  • 11. The original purpose of the code was to create an SQL statement to select a user, with a given user id. If there is nothing to prevent a user from entering “wrong” input, the user can enter some “smart” input like this: Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 11 / 27
  • 12. Then, the SQL statement will look like this: SELECT * FROM Users WHERE UserId = 105 OR 1=1; The SQL above is valid and will return ALL rows from the “Users” table, since OR 1=1 is always TRUE. Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 12 / 27
  • 13. Passwords Does the example look dangerous? What if the “Users” table contains names and passwords? The SQL statement above is much the same as this: SELECT UserId, Name, Passwords FROM Users WHERE UserId = 105 or 1=1; The SQL above is valid and will return ALL rows from the “Users” table which includes passwords this time, since OR 1=1 is always TRUE. Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 13 / 27
  • 14. SQL Injection Based on "“=”" is Always True Here is an example of a user login on a web site: uName = getRequestString("username"); uPass = getRequestString("userpassword"); sql = ’SELECT * FROM Users WHERE Name ="’ + uName + ’" AND Pass ="’ + uPass + ’"’ Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 14 / 27
  • 15. Result: SELECT * FROM Users WHERE Name ="John Doe" AND Pass ="myPass" Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 15 / 27
  • 16. A hacker might get access to user names and passwords in a database by simply inserting " OR "“=” into the user name or password text box: Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 16 / 27
  • 17. The code at the server will create a valid SQL statement like this: SELECT * FROM Users WHERE Name ="" or ""="" AND Pass ="" or ""="" The SQL above is valid and will return all rows from the “Users” table, since OR "“=”" is always TRUE. Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 17 / 27
  • 18. SQL Injection Based on Batched SQL Statements Most databases support batched SQL statement. A batch of SQL statements is a group of two or more SQL statements, separated by semicolons. The SQL statement below will return all rows from the “Users” table, then delete the “Suppliers” table. SELECT * FROM Users; DROP TABLE Suppliers Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 18 / 27
  • 19. Look at the following example: txtUserId = getRequestString("UserId"); txtSQL = "SELECT * FROM Users WHERE UserId = " + txtUserId; And the following input: Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 19 / 27
  • 20. The valid SQL statement would look like this: SELECT * FROM Users WHERE UserId = 105; DROP TABLE Suppliers; Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 20 / 27
  • 21. Section 3 Protection For SQL Injection Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 21 / 27
  • 22. Use SQL Parameters for Protection To protect a web site from SQL injection, you can use SQL parameters. SQL parameters are values that are added to an SQL query at execution time, in a controlled manner. ASP.NET Razor Example txtUserId = getRequestString("UserId"); txtSQL = "SELECT * FROM Users WHERE UserId = @0"; db.Execute(txtSQL,txtUserId); Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 22 / 27
  • 23. Note that parameters are represented in the SQL statement by a @ marker. The SQL engine checks each parameter to ensure that it is correct for its column and are treated literally, and not as part of the SQL to be executed. Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 23 / 27
  • 24. Another Example In C# txtNam = getRequestString("CustomerName"); txtAdd = getRequestString("Address"); txtCit = getRequestString("City"); txtSQL = "INSERT INTO Customers " + "(CustomerName,Address,City) Values(@0,@1,@2)"; db.Execute(txtSQL,txtNam,txtAdd,txtCit); Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 24 / 27
  • 25. INSERT INTO Statement in ASP.NET txtNam = getRequestString("CustomerName"); txtAdd = getRequestString("Address"); txtCit = getRequestString("City"); txtSQL = "INSERT INTO Customers" + "(CustomerName,Address,City) Values(@0,@1,@2)"; command = new SqlCommand(txtSQL); command.Parameters.AddWithValue("@0",txtNam); command.Parameters.AddWithValue("@1",txtAdd); command.Parameters.AddWithValue("@2",txtCit); command.ExecuteNonQuery(); Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 25 / 27
  • 26. INSERT INTO in PHP $stmt = $dbh->prepare("INSERT INTO Customers" + "(CustomerName,Address,City) VALUES (:nam, :add, :cit)"); $stmt->bindParam(’:nam’, $txtNam); $stmt->bindParam(’:add’, $txtAdd); $stmt->bindParam(’:cit’, $txtCit); $stmt->execute(); Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 26 / 27
  • 27. Section 4 Thank You Tayyip Gören (Maltepe Üniversitesi) SQL Injection 08.05.2020 27 / 27