SlideShare a Scribd company logo
*

    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

What's hot

seminar report on Sql injection
seminar report on Sql injectionseminar report on Sql injection
seminar report on Sql injection
Jawhar Ali
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injection
ashish20012
 
Sql injection - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testing
Napendra Singh
 
SQL Injections (Part 1)
SQL Injections (Part 1)SQL Injections (Part 1)
SQL Injections (Part 1)
n|u - The Open Security Community
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
Mentorcs
 
Sql injection
Sql injectionSql injection
Sql injection
Nikunj Dhameliya
 
Sql Injection - Vulnerability and Security
Sql Injection - Vulnerability and SecuritySql Injection - Vulnerability and Security
Sql Injection - Vulnerability and Security
Sandip Chaudhari
 
Sql injections - with example
Sql injections - with exampleSql injections - with example
Sql injections - with example
Prateek Chauhan
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
Sayed Ahmad Naweed
 
Sql injection
Sql injectionSql injection
Sql injection
Nuruzzaman Milon
 
Sql injection
Sql injectionSql injection
Sql injection
Sasha-Leigh Garret
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
Asish Kumar Rath
 
Sql injection
Sql injectionSql injection
Sql injection
Mehul Boghra
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
Anoop T
 
Sqlmap
SqlmapSqlmap
Sql injection attack
Sql injection attackSql injection attack
Sql injection attack
RajKumar Rampelli
 
Sql injection
Sql injectionSql injection
Sql injection
Pallavi Biswas
 
SQL injection
SQL injectionSQL injection
SQL injection
Raj Parmar
 
Advanced SQL Injection
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injection
amiable_indian
 
Sql injection in cybersecurity
Sql injection in cybersecuritySql injection in cybersecurity
Sql injection in cybersecurity
Sanad Bhowmik
 

What's hot (20)

seminar report on Sql injection
seminar report on Sql injectionseminar report on Sql injection
seminar report on Sql injection
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injection
 
Sql injection - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testing
 
SQL Injections (Part 1)
SQL Injections (Part 1)SQL Injections (Part 1)
SQL Injections (Part 1)
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
 
Sql injection
Sql injectionSql injection
Sql injection
 
Sql Injection - Vulnerability and Security
Sql Injection - Vulnerability and SecuritySql Injection - Vulnerability and Security
Sql Injection - Vulnerability and Security
 
Sql injections - with example
Sql injections - with exampleSql injections - with example
Sql injections - with example
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
 
Sqlmap
SqlmapSqlmap
Sqlmap
 
Sql injection attack
Sql injection attackSql injection attack
Sql injection attack
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL injection
SQL injectionSQL injection
SQL injection
 
Advanced SQL Injection
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injection
 
Sql injection in cybersecurity
Sql injection in cybersecuritySql injection in cybersecurity
Sql injection in cybersecurity
 

Similar to Sql injection

Advanced sql injection 1
Advanced sql injection 1Advanced sql injection 1
Advanced sql injection 1
Karunakar Singh Thakur
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
Nitish Kumar
 
SQL Injection Attacks
SQL Injection AttacksSQL Injection Attacks
SQL Injection Attacks
Compare Infobase Limited
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
Kumar
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
chaitanya Lotankar
 
Sq linjection
Sq linjectionSq linjection
Php login system with admin features evolt
Php login system with admin features   evoltPhp login system with admin features   evolt
Php login system with admin features evolt
GIMT
 
References - sql injection
References - sql injection References - sql injection
References - sql injection
Mohammed
 
References
References References
References
Mohammed
 
Chapter 14 sql injection
Chapter 14 sql injectionChapter 14 sql injection
Chapter 14 sql injection
newbie2019
 
General Principles of Web Security
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Security
jemond
 
Hack your db before the hackers do
Hack your db before the hackers doHack your db before the hackers do
Hack your db before the hackers do
fangjiafu
 
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
Eoin Keary
 
SQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQLSQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQL
Pradeep Kumar
 
Code injection and green sql
Code injection and green sqlCode injection and green sql
Code injection and green sql
Kaustav Sengupta
 
Greensql2007
Greensql2007Greensql2007
Greensql2007
Kaustav Sengupta
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
Wenonah Abadilla
 
Asp
AspAsp
Oracle training in_hyderabad
Oracle training in_hyderabadOracle training in_hyderabad
Oracle training in_hyderabad
Kelly Technologies
 
Web application security
Web application securityWeb application security
Web application security
www.netgains.org
 

Similar to Sql injection (20)

Advanced sql injection 1
Advanced sql injection 1Advanced sql injection 1
Advanced sql injection 1
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
SQL Injection Attacks
SQL Injection AttacksSQL Injection Attacks
SQL Injection Attacks
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
Sq linjection
Sq linjectionSq linjection
Sq linjection
 
Php login system with admin features evolt
Php login system with admin features   evoltPhp login system with admin features   evolt
Php login system with admin features evolt
 
References - sql injection
References - sql injection References - sql injection
References - sql injection
 
References
References References
References
 
Chapter 14 sql injection
Chapter 14 sql injectionChapter 14 sql injection
Chapter 14 sql injection
 
General Principles of Web Security
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Security
 
Hack your db before the hackers do
Hack your db before the hackers doHack your db before the hackers do
Hack your db before the hackers do
 
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
 
SQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQLSQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQL
 
Code injection and green sql
Code injection and green sqlCode injection and green sql
Code injection and green sql
 
Greensql2007
Greensql2007Greensql2007
Greensql2007
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
 
Asp
AspAsp
Asp
 
Oracle training in_hyderabad
Oracle training in_hyderabadOracle training in_hyderabad
Oracle training in_hyderabad
 
Web application security
Web application securityWeb application security
Web application security
 

Recently uploaded

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
Claudio Di Ciccio
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 

Recently uploaded (20)

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 

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. *