SlideShare a Scribd company logo
SQL Injection
What is an SQL Injection?
• SQL injection is a technique for exploiting
applications that use relational databases as their
back end.
• SQL Injection arises because the fields available
for user input allow SQL statements to pass
through and query the database directly.
• SQL injection use the fact that many of these
applications concatenate the fixed part of SQL
statement with user-supplied data that forms
WHERE predicates or additional sub-queries.
How and where a SQL injection
occurs?
• SQL injection errors occur when:
– Data enters a program from an untrusted source.
– The data used to dynamically construct a SQL query.
• In most cases, SQL injection is detected by placing meta
characters in data inputs used by web applications.
• Susceptible locations are
– login pages,
– form fields,
– search pages,
– shopping carts and
– query string parameter values.
SQL injection categories
• Two categories:
– Depending on the exposure of database
information (passive)
• SQL errors
• Blind SQL injection for excessive data retrieval
– The alteration of the database information
• Exploiting default stored procedures used by different
backend database servers
• Modification of backend database is possible
SQL Query Poisoning
• How the database query is processed in the
backend?
– URL:
http://www.example.com/product.php?id= 9
– Database query:
SELECT * FROM product_detail WHERE id = 9
• Root cause of all SQL query poisoning is lack of
input sanitization
Detecting SQL errors
• Inject meta characters like ' , " , ; in parameters
• Query gets terminated prematurely …
Detecting SQL errors
Detecting SQL errors
• Try and force error messages from backend
database servers
• This gives us an idea how query is being
created and used
• Change data type of the value passed in
parameter
• Inject meta characters to check for premature
query termination
Extending SQL queries
• Retrieve all rows
 “ OR 1=1”
• Use multiple / stacked / batched queries
 “;SELECT …”
• Execute stored procedures
 “;EXEC”
– Stored procedures, if known, and accessible, can
also be invoked.
– For example Microsoft SQL Server’s extended
stored procedures.
Information retrieval using SQL queries
Information retrieval using SQL queries
Information retrieval using SQL queries
Information retrieval using SQL queries
Blind SQL injection
• If the application does not return error messages,
it may still be susceptible to “blind”
SQL injection.
• Application is sending custom error page which is
not revealing any signature by which we can
deduce potential SQL flaw.
• Nearly identical to the normal SQLi, the only
difference being the way the data is retrieved
from the database.
• Can be exploited by writing queries after “AND”
clause
SQL injection – Checks
• 1’ OR ‘1’=‘1 – to retrieve all rows
• 1’ AND ‘1’=‘1  true, 1’ AND ‘1’=‘2  false in case of
blind SQL injection
• http://www.thecompany.com/pressRelease.jsp?pressRel
easeID=5 AND ascii(lower(substring((SELECT TOP 1 name
FROM sysobjects WHERE xtype='U'), 2, 1))) > 109 - to
retrieve table name character by character
• 1 AND SELECT @@version – database version
• 1 AND ExtractValue(1, CONCAT(0x5c, (SELECT
@@datadir))) – useful to overcome MySQL error
messages

More Related Content

PPTX
Sql Injection
PPTX
SQLi for Security Champions
PDF
SQL INJECTIONS EVERY TESTER NEEDS TO KNOW
PPTX
SQL Injections (Part 1)
PPTX
SQL Injection attack
PPT
Sql injection attacks
PPTX
Sql injection - security testing
Sql Injection
SQLi for Security Champions
SQL INJECTIONS EVERY TESTER NEEDS TO KNOW
SQL Injections (Part 1)
SQL Injection attack
Sql injection attacks
Sql injection - security testing

What's hot (20)

PPTX
SQL Injections - A Powerpoint Presentation
PDF
(ATS6-DEV04) Building Web MashUp applications that include Accelrys Applicati...
PPTX
Sql injection
PPTX
SQL INJECTION
PDF
jdbc
PPTX
Sql injections
PDF
CNIT 127: L9: Web Templates and .NET
PDF
Getting Started with Oracle APEX
PPTX
20180929 jssug 10_a5_sql_mk2
PPTX
Sql injection
PPT
Sql injection
PPTX
Ultimate Free SQL Server Toolkit
PDF
CNIT 129S: 11: Attacking Application Logic
PPTX
Sql injection
PPTX
Ppt on sql injection
PPTX
Intro sql/plsql
PPTX
Sql injection
PDF
CNIT 129S: 10: Attacking Back-End Components
PPTX
Spring MVC 5 & Hibernate 5 Integration
PPT
Jdbc drivers
SQL Injections - A Powerpoint Presentation
(ATS6-DEV04) Building Web MashUp applications that include Accelrys Applicati...
Sql injection
SQL INJECTION
jdbc
Sql injections
CNIT 127: L9: Web Templates and .NET
Getting Started with Oracle APEX
20180929 jssug 10_a5_sql_mk2
Sql injection
Sql injection
Ultimate Free SQL Server Toolkit
CNIT 129S: 11: Attacking Application Logic
Sql injection
Ppt on sql injection
Intro sql/plsql
Sql injection
CNIT 129S: 10: Attacking Back-End Components
Spring MVC 5 & Hibernate 5 Integration
Jdbc drivers
Ad

Viewers also liked (20)

PPTX
Sql Injection attacks and prevention
PDF
SQL Complete Tutorial. All Topics Covered
PPTX
Threat modeling librarian freedom conference
PPTX
03. sql and other injection module v17
PPT
Introduction to SQL Injection
PPTX
Sql injection
PPTX
SQL Injection Attacks cs586
PPT
Sql Injection Attacks Siddhesh
PPT
Sql injection attack
PDF
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
PPTX
Sql Injection and Entity Frameworks
DOCX
Types of sql injection attacks
PPT
D:\Technical\Ppt\Sql Injection
PPTX
Sql injection
PPT
Web application attacks using Sql injection and countermasures
PPTX
SQL Injection
PPT
SQL Injection
PPT
Advanced Sql Injection ENG
PDF
Sql Injection Myths and Fallacies
PDF
How to Become a Thought Leader in Your Niche
Sql Injection attacks and prevention
SQL Complete Tutorial. All Topics Covered
Threat modeling librarian freedom conference
03. sql and other injection module v17
Introduction to SQL Injection
Sql injection
SQL Injection Attacks cs586
Sql Injection Attacks Siddhesh
Sql injection attack
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
Sql Injection and Entity Frameworks
Types of sql injection attacks
D:\Technical\Ppt\Sql Injection
Sql injection
Web application attacks using Sql injection and countermasures
SQL Injection
SQL Injection
Advanced Sql Injection ENG
Sql Injection Myths and Fallacies
How to Become a Thought Leader in Your Niche
Ad

Similar to SQL injection (20)

PPTX
SQL Injection Stegnography in Pen Testing
PPTX
SQL Injection in JAVA
PPT
SQL injection basics
PDF
SQL Injection Attack Guide for ethical hacking
PPTX
cgbhjjjjjjjnmmmkmmmmmmkkkkkkTutorial5.pptx
PPTX
csf_ppt.pptx
PPTX
seminar report on Sql injection
PPTX
Sql injection
PDF
Web & Wireless Hacking
PPT
SQL injection and buffer overflows are hacking techniques used to exploit wea...
PDF
World2016_T5_S5_SQLServerFunctionalOverview
PDF
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
PPTX
SQL Injection
PPTX
Web application security part 01
PDF
CNIT 129S Ch 9: Attacking Data Stores (Part 2 of 2)
PPTX
SQLMap-Automating-the-Hunt-for-Hidden-Injection-Flaws.pdf.pptx
PPTX
kjkl.pptxsdfdsafsadfsdagsadfsadfasdggasdf
PDF
Using ELK Explore Defect Data
PDF
UsingELKExploreDefectData
PPTX
SQL Injection Sql Injection Typesagdsgdsgdsgbdshfdshbfdshbfdshbfdhsh
SQL Injection Stegnography in Pen Testing
SQL Injection in JAVA
SQL injection basics
SQL Injection Attack Guide for ethical hacking
cgbhjjjjjjjnmmmkmmmmmmkkkkkkTutorial5.pptx
csf_ppt.pptx
seminar report on Sql injection
Sql injection
Web & Wireless Hacking
SQL injection and buffer overflows are hacking techniques used to exploit wea...
World2016_T5_S5_SQLServerFunctionalOverview
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
SQL Injection
Web application security part 01
CNIT 129S Ch 9: Attacking Data Stores (Part 2 of 2)
SQLMap-Automating-the-Hunt-for-Hidden-Injection-Flaws.pdf.pptx
kjkl.pptxsdfdsafsadfsdagsadfsadfasdggasdf
Using ELK Explore Defect Data
UsingELKExploreDefectData
SQL Injection Sql Injection Typesagdsgdsgdsgbdshfdshbfdshbfdshbfdhsh

SQL injection

  • 2. What is an SQL Injection? • SQL injection is a technique for exploiting applications that use relational databases as their back end. • SQL Injection arises because the fields available for user input allow SQL statements to pass through and query the database directly. • SQL injection use the fact that many of these applications concatenate the fixed part of SQL statement with user-supplied data that forms WHERE predicates or additional sub-queries.
  • 3. How and where a SQL injection occurs? • SQL injection errors occur when: – Data enters a program from an untrusted source. – The data used to dynamically construct a SQL query. • In most cases, SQL injection is detected by placing meta characters in data inputs used by web applications. • Susceptible locations are – login pages, – form fields, – search pages, – shopping carts and – query string parameter values.
  • 4. SQL injection categories • Two categories: – Depending on the exposure of database information (passive) • SQL errors • Blind SQL injection for excessive data retrieval – The alteration of the database information • Exploiting default stored procedures used by different backend database servers • Modification of backend database is possible
  • 5. SQL Query Poisoning • How the database query is processed in the backend? – URL: http://www.example.com/product.php?id= 9 – Database query: SELECT * FROM product_detail WHERE id = 9 • Root cause of all SQL query poisoning is lack of input sanitization
  • 6. Detecting SQL errors • Inject meta characters like ' , " , ; in parameters
  • 7. • Query gets terminated prematurely … Detecting SQL errors
  • 8. Detecting SQL errors • Try and force error messages from backend database servers • This gives us an idea how query is being created and used • Change data type of the value passed in parameter • Inject meta characters to check for premature query termination
  • 9. Extending SQL queries • Retrieve all rows  “ OR 1=1” • Use multiple / stacked / batched queries  “;SELECT …” • Execute stored procedures  “;EXEC” – Stored procedures, if known, and accessible, can also be invoked. – For example Microsoft SQL Server’s extended stored procedures.
  • 14. Blind SQL injection • If the application does not return error messages, it may still be susceptible to “blind” SQL injection. • Application is sending custom error page which is not revealing any signature by which we can deduce potential SQL flaw. • Nearly identical to the normal SQLi, the only difference being the way the data is retrieved from the database. • Can be exploited by writing queries after “AND” clause
  • 15. SQL injection – Checks • 1’ OR ‘1’=‘1 – to retrieve all rows • 1’ AND ‘1’=‘1  true, 1’ AND ‘1’=‘2  false in case of blind SQL injection • http://www.thecompany.com/pressRelease.jsp?pressRel easeID=5 AND ascii(lower(substring((SELECT TOP 1 name FROM sysobjects WHERE xtype='U'), 2, 1))) > 109 - to retrieve table name character by character • 1 AND SELECT @@version – database version • 1 AND ExtractValue(1, CONCAT(0x5c, (SELECT @@datadir))) – useful to overcome MySQL error messages

Editor's Notes

  • #3: Various backend databse servers used by the application – MySQL, MSSQL, Oracle, Postgre, Sybase, Informix etc.
  • #13: The UNION operator is used in SQL injections to join a query, purposely forged by the tester, to the original query. The result of the forged query will be joined to the result of the original query, allowing the tester to obtain the values of fields of other tables