5
Most read
6
Most read
*

    HEMENDRA KUMAR
        (0806413042)
The ability to inject SQL
 commands into the database
            engine
through an existing application

                *
                2
* Many web applications take user input from a form
* Often this user input is used literally in the
 construction of a SQL query submitted to a database.
 For example:
  * SELECT productdata FROM table WHERE   productname =
    „user input product name‟;


* A SQL injection attack involves placing SQL statements
 in the user input




                             *
* It is probably the most common Website
  vulnerability today!
* It is a flaw in "web application" development,
  it is not a DB or web server problem
  * Most programmers are still not aware of this problem
  * A lot of the tutorials & demo “templates” are vulnerable
  * Even worse, a lot of solutions posted on the Internet are
    not good enough
* In pen tests over 60% of web applications are
 vulnerable to SQL Injection



             *
                                 4
* Almost all SQL databases and programming languages are
 potentially vulnerable
  * MS SQL Server, Oracle, MySQL, Postgres, DB2, MS Access, Sybase,
    Informix, etc
* Accessed through applications developed using:
  * Perl and CGI scripts that access databases
  * ASP, JSP, PHP
  * XML, XSL and XSQL
  * Javascript
  * VB, MFC, and other ODBC-based tools and APIs
  * DB specific Web-based applications and API‟s
  * Reports and DB Applications
  * 3 and 4GL-based languages (C, OCI, Pro*C, and COBOL)
  * many more

                                   *
                               5
Common vulnerable login query
  SELECT * FROM users
  WHERE login = 'victor'
  AND password = '123'
(If it returns something then login!)
ASP/MS SQL Server login syntax
  var sql = "SELECT * FROM users
  WHERE login = '" + formusr +
  "' AND password = '" + formpwd + "'";


                       *
                             6
formusr = ' or 1=1 – –
formpwd = anything

Final query would look like this:
  SELECT * FROM users
  WHERE username = ' ' or 1=1
  – – AND password = 'anything'

               *
                          7
* It closes the string parameter
* Everything after is considered part of the SQL
  command
* Misleading Internet suggestions include:
  * Escape it! : replace ' with ' '
* String fields are very common but there are
 other types of fields:
  * Numeric
  * Dates



                           *
                             8
SELECT * FROM clients
WHERE account = 12345678
AND pin = 1111

PHP/MySQL login syntax
$sql = "SELECT * FROM clients WHERE " .
"account = $formacct AND " .
"pin = $formpin";



          *
                          9
$formacct = 1 or 1=1 #
$formpin = 1111


Final query would look like this:
  SELECT * FROM clients
  WHERE account = 1 or 1=1
  # AND pin = 1111

             *
                          10
* ' or " character String Indicators
* -- or #       single-line comment
* /*…*/         multiple-line comment
*+              addition, concatenate (or space in
  url)
* ||            (double pipe) concatenate
*%              wildcard attribute indicator
* ?Param1=foo&Param2=bar URL Parameters
* PRINT         useful as non transactional command
* @variable local variable
* @@variable global variable
* waitfor delay '0:0:10' time delay


                         *
                             11
* Using SQL injections, attackers can:
  * Add new data to the database
    * Perform an INSERT in the injected SQL
  * Modify data currently in the database

    * Perform an UPDATE in the injected SQL
  * Often can gain access to other user‟s system
    capabilities by obtaining their password




                     *
* Use provided functions for escaping strings
  * Many attacks can be avoided by simply using the SQL
    string escaping mechanism
    * „  ‟   and “  ”
  * mysql_real_escape_string() is the preferred function for
    this
* No quotes
  * Consider:
    * SELECT fields FROM table WHERE id = 23 OR 1=1
    * No quotes here!



                                     *
* Check syntax of input for validity
  * Many classes of input have fixed languages
    * Email addresses, dates, part numbers, etc.
    * Verify that the input is a valid string in the language
    * Sometime languages allow problematic characters (e.g., „*‟ in
      email addresses); may decide to not allow these
    * If you can exclude quotes and semicolons that‟s good
  * Not always possible: consider the name Bill O‟Reilly
    * Want to allow the use of single quotes in names
* Have length limits on input
  * Many SQL injection attacks depend on entering long strings



                      *
* Scan query string for undesirable word combinations
 that indicate SQL statements
  * INSERT, DROP, etc.
  * If you see these, can check against SQL syntax to see if
   they represent a statement or valid user input
* Limit database permissions and segregate users
  * If you‟re only reading the database, connect to database
   as a user that only has read permissions
  * Never connect as a database administrator in your web
   application




            *
*Configure database error reporting
  * Default error reporting often gives away information
   that is valuable for attackers (table name, field name,
   etc.)
  * Configure so that this information is never exposed to a
   user


*If possible, use bound variables
  * Some libraries allow you to bind inputs to variables
   inside a SQL statement




                         *
*

More Related Content

PPTX
Ppt on sql injection
PPT
Sql injection
PPTX
Sql Injection attacks and prevention
PPTX
Sql injection - security testing
PPTX
Sql injections - with example
PPT
Sql injection
PPTX
SQL injection prevention techniques
PPT
A Brief Introduction in SQL Injection
Ppt on sql injection
Sql injection
Sql Injection attacks and prevention
Sql injection - security testing
Sql injections - with example
Sql injection
SQL injection prevention techniques
A Brief Introduction in SQL Injection

What's hot (20)

PPT
SQL Injection
PPTX
SQL Injections - A Powerpoint Presentation
PPTX
seminar report on Sql injection
PPT
Sql injection attack
PPTX
Sql injection
PPTX
SQL Injection
PPT
Sql injection
PPTX
SQL INJECTION
PPTX
Sql injection
PDF
What is SQL Injection Attack | How to prevent SQL Injection Attacks? | Cybers...
PDF
How to identify and prevent SQL injection
PPTX
Sql injection in cybersecurity
PPTX
PPTX
SQL Injections (Part 1)
PPTX
SQL injection
PPTX
Sql injection
PDF
ORM2Pwn: Exploiting injections in Hibernate ORM
PPTX
Sql injection
PPTX
Deep understanding on Cross-Site Scripting and SQL Injection
SQL Injection
SQL Injections - A Powerpoint Presentation
seminar report on Sql injection
Sql injection attack
Sql injection
SQL Injection
Sql injection
SQL INJECTION
Sql injection
What is SQL Injection Attack | How to prevent SQL Injection Attacks? | Cybers...
How to identify and prevent SQL injection
Sql injection in cybersecurity
SQL Injections (Part 1)
SQL injection
Sql injection
ORM2Pwn: Exploiting injections in Hibernate ORM
Sql injection
Deep understanding on Cross-Site Scripting and SQL Injection
Ad

Similar to Sql injection (20)

PPT
Advanced sql injection 1
PPT
Sql injection attacks
PPT
SQL Injection Attacks
PPT
Sql injection attacks
PPT
Sql injection attacks
PDF
Php login system with admin features evolt
PPTX
References
PPTX
References - sql injection
PDF
Chapter 14 sql injection
PPT
General Principles of Web Security
PDF
Hack your db before the hackers do
PPTX
03. sql and other injection module v17
PPTX
SQL Injection in action with PHP and MySQL
PPTX
Code injection and green sql
PPTX
Greensql2007
PPTX
SQL Injection
PDF
PDF
Oracle training in_hyderabad
PPSX
Web application security
Advanced sql injection 1
Sql injection attacks
SQL Injection Attacks
Sql injection attacks
Sql injection attacks
Php login system with admin features evolt
References
References - sql injection
Chapter 14 sql injection
General Principles of Web Security
Hack your db before the hackers do
03. sql and other injection module v17
SQL Injection in action with PHP and MySQL
Code injection and green sql
Greensql2007
SQL Injection
Oracle training in_hyderabad
Web application security
Ad

Recently uploaded (20)

PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPTX
The various Industrial Revolutions .pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
2018-HIPAA-Renewal-Training for executives
DOCX
search engine optimization ppt fir known well about this
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Five Habits of High-Impact Board Members
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
The various Industrial Revolutions .pptx
Enhancing emotion recognition model for a student engagement use case through...
Final SEM Unit 1 for mit wpu at pune .pptx
Taming the Chaos: How to Turn Unstructured Data into Decisions
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Consumable AI The What, Why & How for Small Teams.pdf
Flame analysis and combustion estimation using large language and vision assi...
A contest of sentiment analysis: k-nearest neighbor versus neural network
2018-HIPAA-Renewal-Training for executives
search engine optimization ppt fir known well about this
1 - Historical Antecedents, Social Consideration.pdf
Five Habits of High-Impact Board Members
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Custom Battery Pack Design Considerations for Performance and Safety
A proposed approach for plagiarism detection in Myanmar Unicode text
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
UiPath Agentic Automation session 1: RPA to Agents
OpenACC and Open Hackathons Monthly Highlights July 2025

Sql injection

  • 1. * HEMENDRA KUMAR (0806413042)
  • 2. The ability to inject SQL commands into the database engine through an existing application * 2
  • 3. * Many web applications take user input from a form * Often this user input is used literally in the construction of a SQL query submitted to a database. For example: * SELECT productdata FROM table WHERE productname = „user input product name‟; * A SQL injection attack involves placing SQL statements in the user input *
  • 4. * It is probably the most common Website vulnerability today! * It is a flaw in "web application" development, it is not a DB or web server problem * Most programmers are still not aware of this problem * A lot of the tutorials & demo “templates” are vulnerable * Even worse, a lot of solutions posted on the Internet are not good enough * In pen tests over 60% of web applications are vulnerable to SQL Injection * 4
  • 5. * Almost all SQL databases and programming languages are potentially vulnerable * MS SQL Server, Oracle, MySQL, Postgres, DB2, MS Access, Sybase, Informix, etc * Accessed through applications developed using: * Perl and CGI scripts that access databases * ASP, JSP, PHP * XML, XSL and XSQL * Javascript * VB, MFC, and other ODBC-based tools and APIs * DB specific Web-based applications and API‟s * Reports and DB Applications * 3 and 4GL-based languages (C, OCI, Pro*C, and COBOL) * many more * 5
  • 6. Common vulnerable login query SELECT * FROM users WHERE login = 'victor' AND password = '123' (If it returns something then login!) ASP/MS SQL Server login syntax var sql = "SELECT * FROM users WHERE login = '" + formusr + "' AND password = '" + formpwd + "'"; * 6
  • 7. formusr = ' or 1=1 – – formpwd = anything Final query would look like this: SELECT * FROM users WHERE username = ' ' or 1=1 – – AND password = 'anything' * 7
  • 8. * It closes the string parameter * Everything after is considered part of the SQL command * Misleading Internet suggestions include: * Escape it! : replace ' with ' ' * String fields are very common but there are other types of fields: * Numeric * Dates * 8
  • 9. SELECT * FROM clients WHERE account = 12345678 AND pin = 1111 PHP/MySQL login syntax $sql = "SELECT * FROM clients WHERE " . "account = $formacct AND " . "pin = $formpin"; * 9
  • 10. $formacct = 1 or 1=1 # $formpin = 1111 Final query would look like this: SELECT * FROM clients WHERE account = 1 or 1=1 # AND pin = 1111 * 10
  • 11. * ' or " character String Indicators * -- or # single-line comment * /*…*/ multiple-line comment *+ addition, concatenate (or space in url) * || (double pipe) concatenate *% wildcard attribute indicator * ?Param1=foo&Param2=bar URL Parameters * PRINT useful as non transactional command * @variable local variable * @@variable global variable * waitfor delay '0:0:10' time delay * 11
  • 12. * Using SQL injections, attackers can: * Add new data to the database * Perform an INSERT in the injected SQL * Modify data currently in the database * Perform an UPDATE in the injected SQL * Often can gain access to other user‟s system capabilities by obtaining their password *
  • 13. * Use provided functions for escaping strings * Many attacks can be avoided by simply using the SQL string escaping mechanism * „  ‟ and “  ” * mysql_real_escape_string() is the preferred function for this * No quotes * Consider: * SELECT fields FROM table WHERE id = 23 OR 1=1 * No quotes here! *
  • 14. * Check syntax of input for validity * Many classes of input have fixed languages * Email addresses, dates, part numbers, etc. * Verify that the input is a valid string in the language * Sometime languages allow problematic characters (e.g., „*‟ in email addresses); may decide to not allow these * If you can exclude quotes and semicolons that‟s good * Not always possible: consider the name Bill O‟Reilly * Want to allow the use of single quotes in names * Have length limits on input * Many SQL injection attacks depend on entering long strings *
  • 15. * Scan query string for undesirable word combinations that indicate SQL statements * INSERT, DROP, etc. * If you see these, can check against SQL syntax to see if they represent a statement or valid user input * Limit database permissions and segregate users * If you‟re only reading the database, connect to database as a user that only has read permissions * Never connect as a database administrator in your web application *
  • 16. *Configure database error reporting * Default error reporting often gives away information that is valuable for attackers (table name, field name, etc.) * Configure so that this information is never exposed to a user *If possible, use bound variables * Some libraries allow you to bind inputs to variables inside a SQL statement *
  • 17. *