SlideShare uma empresa Scribd logo
1 de 34
Mozilla
Security
Learning Center
SQL Injection
Intro

 • Michael Coates
 • Infrastructure Security
 • mcoates@mozilla.com - @_mwc

 • Questions / comments during presentation?
 • Use IRC at air.mozilla.org
Agenda



• Business risk of XSS
• Understanding the vulnerability
• Attack scenarios
• Mitigation techniques
Agenda



• Business risk of SQL Injection
• Understanding the vulnerability
• Attack scenarios
• Mitigation techniques
Risks of SQL Injection

 • Injection attacks (SQL, LDAP, OS, etc) - #1 Issue on OWASP Top 10
 • Impact: Vulnerability allows attacker to change intent of SQL
    statement

 • Business Impact:
  • Theft of sensitive/PII data (account data, password hashes)
  • Data Corruption
  • Unauthorized application/feature access
  • Inject other attacks (XSS) into databases
SQL Injection in the News
Setup



• http://people.mozilla.org/~mcoates/
  WebSecurityLab.html#installation

• http://bit.ly/MozLab
• Download Virtual Box, OWASP Broken Web App VM
Agenda



• Business risk of SQL Injection
• Understanding the vulnerability
• Attack scenarios
• Mitigation techniques
Fundamental Problem

• User controlled data improperly used with SQL statements
• Example Vulnerable Query:
  sqlQ = “Select user from UserTable where name= '+username
  + ' and pass = '+password+ ' ”


    Login: ___
                            My username is o’malley ?
    Pass: ____
Fundamental Problem

• User controlled data improperly used with SQL statements
• o’malley scenario
  Select user from UserTable where name= 'o'malley' and pass = 'foo'

• Result: Error, syntax is not valid


               Error: Invalid syntax
Agenda



• Business risk of SQL Injection
• Understanding the vulnerability
• Attack scenarios
• Mitigation techniques
SQL Attack Examples


• Basic SQL Injection Tests:
    OR 1=1 --
    ' OR '1'= '1'--
•   Select user from UserTable where   name= 'joe' and pass = ' ' OR '1'= '1'-- '

• Looks for username of joe and password of (blank || TRUE)
Variations

 • SQL Injection
  • Error message or different text returned based on SQL
      statement results

   • Example: Error message, db data displayed in page
 • Blind SQL Injection
  • No visible response to user indicating success of fail of
      query
Blind SQL Injection



 • Use time of results to deduce boolean
 • Injected SQL uses IF statements and delays to enumerate
   data, 1 char at a time
Blind SQL Examples

   mysql> select * from example;
   +----+-----------------+------+
   | id | name                  | age |
   +----+-----------------+------+
   | 1 | Timmy Mellowman | 23 |
                                  Text|
   | 2 | Sandy Smith            | 21
   +----+-----------------+------+
   2 rows in set (0.00 sec)
Blind SQL Examples

• mysql> SELECT IF( name = 'Sandy Smith',
   BENCHMARK(1000000,MD5( 'x' )),NULL) FROM example;

  • Command line result - 2 rows in set (5.25 sec)
• mysql> SELECT IF( name = 'Joe Bob',
   BENCHMARK(1000000,MD5( 'x' )),NULL) FROM example;

  • Command line result - 2 rows in set (0.00 sec)
• The actual data returned is not important the delay indicates
   True of False
                        +----+-----------------+------+
                        | 1 | Timmy Mellowman | 23 |
                        | 2 | Sandy Smith            | 21 |
                        +----+-----------------+------+
Blind SQL Injection


 • mysql> select headerName from header_store UNION select
    IF(SUBSTRING(name,
    1,1)='T',BENCHMARK(1000000,MD5( 'x' )),'y') from example
    where age=23 limit 1;

   • 1 row in set (6.01 sec)
 • Test if the first character of "name" from the example table
    (where age=23) is the letter T.


                +----+-----------------+------+
                | 1 | Timmy Mellowman | 23 |
WebGoat
• Click First Link - OWASP WebGoat version 5.3.x
• Username / Password is guest / guest
Setup



• http://people.mozilla.org/~mcoates/
  WebSecurityLab.html#installation

• http://bit.ly/MozLab
• Download Virtual Box, OWASP Broken Web App VM
Using A Proxy

• Burp - Configure to listen on 8080
 • Ensure “loopback only” is checked (will be by default)
Set Firefox Proxy

 • Set Firefox proxy to 8080
  • Preferences
      -> Advanced
      -> Network
      -> Settings

 • Set HTTP Proxy
 • Important - clear
    “No Proxy for” line
Confirm Setup Works

• Refresh Web Browser - it should hang
• Go to Burp -> Proxy -> Intercept (they are highlighted)
• Click “Forward” for all messages
• Should now see page in browser
Confirm Setup Works

• Intercept is on
 • Each request will be caught by proxy
 • Requires you to hit forward each time
• Intercept is off
 • Requests sent through proxy automatically
 • Logged in tab “proxy”->”history”
“Hello World” of Proxies
 • Lesson: General->Http Basic
 • Objective:
  • Enter your name into text box
  • Intercept with proxy & change entered name to different
      value

   • Receive response & observe modified value is reversed
              Joe               Sue


 Attacker’s   euS               euS
                    Web Proxy                Web Server
 Browser
SQL Injection

 • Problem: User controlled data improperly used with SQL
    statements

 • Impact: Arbitrary SQL Execution, Data Corruption, Data Theft
 • Basic SQL Injection Tests:
    OR 1=1 --
    ' OR '1'= '1'--

 • Example Vulnerable Query:
    sqlQ = “Select user from UserTable where name= '+username+
    ' and pass = '+password+ ' ”
Lab! - SQL Lesson
SQL Injection
 • Lesson: Injection Flaws -> Lab: SQL Injection -> Stage
    1: String SQL Injection

 • Proxy Needed
 • Objective: Bypass the login page by inserting
    “control” characters. Login as “Neville” w/o
    knowledge of the password
SQL Injection

 • HTTP Post
    employee_id=112&password=x' OR '1'='1&action=Login

 • Vulnerable SQL
    Select user from UserTable where name= '+username+ ' and
    pass = '+password+ '
    Select user from UserTable where name= '112' and
    pass = 'x' OR '1'='1'

 • Result: ... name = ' 112 ' and pass = 'x ' OR TRUE
Agenda



• Business risk of SQL Injection
• Understanding the vulnerability
• Attack scenarios
• Mitigation techniques
SQL Injection


 • Parameterized Queries
   No confusion with control characters


 • Input Validation
   Are special characters needed for most fields?
   What about non-printable characters %00-%0A?
   Just a layer of defense - remember o’malley example
Parameterized Query


• HTTP Post
   employee_id=112&password=x' OR '1'='1&action=Login

• Parameterized Query
   Look for employee_id 112 with password of x' OR '1'='1

• Result: Login fail - password is foo not x' OR '1'='1
Language Examples


• User data + string concatenation == SQL injection disaster
• DJANGO
 • Model Query API-> Safe
 • raw() manager -> Dangerous, Avoid!
• Java
   String query = "SELECT account_balance FROM user_data WHERE user_name = ? ";

    PreparedStatement pstmt = connection.prepareStatement( query );
    pstmt.setString( 1, custname);
    ResultSet results = pstmt.executeQuery( );
Additional Resources


• OWASP SQL Prevention Cheat Sheet
 • https://www.owasp.org/index.php/
    SQL_Injection_Prevention_Cheat_Sheet

• 10 Minute Crash Course
 • Episode 3 - http://www.youtube.com/user/
    AppsecTutorialSeries
Questions


• Next Events
• Aug 24 - CEF Logging for Attack Aware Applications
• Aug 25 - OWASP Bay Area Chapter Meeting
• https://wiki.mozilla.org/index.php?
   title=WebAppSec#Schedule

Mais conteúdo relacionado

Mais procurados

A Brief Introduction in SQL Injection
A Brief Introduction in SQL InjectionA Brief Introduction in SQL Injection
A Brief Introduction in SQL Injection
Sina Manavi
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injection
ashish20012
 

Mais procurados (20)

Sql Injection and XSS
Sql Injection and XSSSql Injection and XSS
Sql Injection and XSS
 
A Brief Introduction in SQL Injection
A Brief Introduction in SQL InjectionA Brief Introduction in SQL Injection
A Brief Introduction in SQL Injection
 
SQL Injections - A Powerpoint Presentation
SQL Injections - A Powerpoint PresentationSQL Injections - A Powerpoint Presentation
SQL Injections - A Powerpoint Presentation
 
D:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql InjectionD:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql Injection
 
Sql Injection Attacks Siddhesh
Sql Injection Attacks SiddheshSql Injection Attacks Siddhesh
Sql Injection Attacks Siddhesh
 
Sql Injection - Vulnerability and Security
Sql Injection - Vulnerability and SecuritySql Injection - Vulnerability and Security
Sql Injection - Vulnerability and Security
 
Sql injection - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testing
 
What is advanced SQL Injection? Infographic
What is advanced SQL Injection? InfographicWhat is advanced SQL Injection? Infographic
What is advanced SQL Injection? Infographic
 
Web Security: SQL Injection
Web Security: SQL InjectionWeb Security: SQL Injection
Web Security: SQL Injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL Injections (Part 1)
SQL Injections (Part 1)SQL Injections (Part 1)
SQL Injections (Part 1)
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injection
 
OWASP Top 10 - Day 1 - A1 injection attacks
OWASP Top 10 - Day 1 - A1 injection attacksOWASP Top 10 - Day 1 - A1 injection attacks
OWASP Top 10 - Day 1 - A1 injection attacks
 
Sql injection
Sql injectionSql injection
Sql injection
 
C days2015
C days2015C days2015
C days2015
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
Web application penetration using SQLMAP.
Web application penetration using SQLMAP.Web application penetration using SQLMAP.
Web application penetration using SQLMAP.
 
How to identify and prevent SQL injection
How to identify and prevent SQL injection  How to identify and prevent SQL injection
How to identify and prevent SQL injection
 
Full MSSQL Injection PWNage
Full MSSQL Injection PWNageFull MSSQL Injection PWNage
Full MSSQL Injection PWNage
 

Destaque

Destaque (8)

Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!
 
Vulnerable Active Record: A tale of SQL Injection in PHP Framework
Vulnerable Active Record: A tale of SQL Injection in PHP FrameworkVulnerable Active Record: A tale of SQL Injection in PHP Framework
Vulnerable Active Record: A tale of SQL Injection in PHP Framework
 
SQL Injection Defense in Python
SQL Injection Defense in PythonSQL Injection Defense in Python
SQL Injection Defense in Python
 
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya MorimotoSQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
 
Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)
 
Sql, Sql Injection ve Sqlmap Kullanımı
Sql, Sql Injection ve Sqlmap KullanımıSql, Sql Injection ve Sqlmap Kullanımı
Sql, Sql Injection ve Sqlmap Kullanımı
 
Alphorm.com Formation CEHV9 III
Alphorm.com Formation CEHV9 IIIAlphorm.com Formation CEHV9 III
Alphorm.com Formation CEHV9 III
 
Hacking the Web
Hacking the WebHacking the Web
Hacking the Web
 

Semelhante a SQL Injection - Mozilla Security Learning Center

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
 

Semelhante a SQL Injection - Mozilla Security Learning Center (20)

SQL Injection in JAVA
SQL Injection in JAVASQL Injection in JAVA
SQL Injection in JAVA
 
Unique Features of SQL Injection in PHP Assignment
Unique Features of SQL Injection in PHP AssignmentUnique Features of SQL Injection in PHP Assignment
Unique Features of SQL Injection in PHP Assignment
 
CNIT 129S Ch 9: Attacking Data Stores (Part 2 of 2)
CNIT 129S Ch 9: Attacking Data Stores (Part 2 of 2)CNIT 129S Ch 9: Attacking Data Stores (Part 2 of 2)
CNIT 129S Ch 9: Attacking Data Stores (Part 2 of 2)
 
ShmooCON 2009 : Re-playing with (Blind) SQL Injection
ShmooCON 2009 : Re-playing with (Blind) SQL InjectionShmooCON 2009 : Re-playing with (Blind) SQL Injection
ShmooCON 2009 : Re-playing with (Blind) SQL Injection
 
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
 
Ch 9 Attacking Data Stores (Part 2)
Ch 9 Attacking Data Stores (Part 2)Ch 9 Attacking Data Stores (Part 2)
Ch 9 Attacking Data Stores (Part 2)
 
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 201510 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
 
Sql injection presentation
Sql injection presentationSql injection presentation
Sql injection presentation
 
Sql
SqlSql
Sql
 
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
 
Practical Approach towards SQLi ppt
Practical Approach towards SQLi pptPractical Approach towards SQLi ppt
Practical Approach towards SQLi ppt
 
SQL Injection and DoS
SQL Injection and DoSSQL Injection and DoS
SQL Injection and DoS
 
Sql Injection
Sql InjectionSql Injection
Sql Injection
 
Locking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxLocking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptx
 
Fluentd 20150918 no_demo_public
Fluentd 20150918 no_demo_publicFluentd 20150918 no_demo_public
Fluentd 20150918 no_demo_public
 
Php Security - OWASP
Php  Security - OWASPPhp  Security - OWASP
Php Security - OWASP
 
Secure software development presentation
Secure software development presentationSecure software development presentation
Secure software development presentation
 
Not so blind SQL Injection
Not so blind SQL InjectionNot so blind SQL Injection
Not so blind SQL Injection
 
Code injection
Code injectionCode injection
Code injection
 
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
 

Mais de Michael Coates

Security in an Interconnected and Complex World of Software
Security in an Interconnected and Complex World of SoftwareSecurity in an Interconnected and Complex World of Software
Security in an Interconnected and Complex World of Software
Michael Coates
 
2013 michael coates-javaone
2013 michael coates-javaone2013 michael coates-javaone
2013 michael coates-javaone
Michael Coates
 

Mais de Michael Coates (10)

Self Defending Applications
Self Defending ApplicationsSelf Defending Applications
Self Defending Applications
 
Security in an Interconnected and Complex World of Software
Security in an Interconnected and Complex World of SoftwareSecurity in an Interconnected and Complex World of Software
Security in an Interconnected and Complex World of Software
 
Devbeat Conference - Developer First Security
Devbeat Conference - Developer First SecurityDevbeat Conference - Developer First Security
Devbeat Conference - Developer First Security
 
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAPVirtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
 
2013 michael coates-javaone
2013 michael coates-javaone2013 michael coates-javaone
2013 michael coates-javaone
 
Sf startup-security
Sf startup-securitySf startup-security
Sf startup-security
 
Bug Bounty Programs For The Web
Bug Bounty Programs For The WebBug Bounty Programs For The Web
Bug Bounty Programs For The Web
 
Cross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning CenterCross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning Center
 
Real Time Application Defenses - The Reality of AppSensor & ESAPI
Real Time Application Defenses - The Reality of AppSensor & ESAPIReal Time Application Defenses - The Reality of AppSensor & ESAPI
Real Time Application Defenses - The Reality of AppSensor & ESAPI
 
SSL Screw Ups
SSL Screw UpsSSL Screw Ups
SSL Screw Ups
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

SQL Injection - Mozilla Security Learning Center

  • 2. Intro • Michael Coates • Infrastructure Security • mcoates@mozilla.com - @_mwc • Questions / comments during presentation? • Use IRC at air.mozilla.org
  • 3. Agenda • Business risk of XSS • Understanding the vulnerability • Attack scenarios • Mitigation techniques
  • 4. Agenda • Business risk of SQL Injection • Understanding the vulnerability • Attack scenarios • Mitigation techniques
  • 5. Risks of SQL Injection • Injection attacks (SQL, LDAP, OS, etc) - #1 Issue on OWASP Top 10 • Impact: Vulnerability allows attacker to change intent of SQL statement • Business Impact: • Theft of sensitive/PII data (account data, password hashes) • Data Corruption • Unauthorized application/feature access • Inject other attacks (XSS) into databases
  • 6. SQL Injection in the News
  • 7. Setup • http://people.mozilla.org/~mcoates/ WebSecurityLab.html#installation • http://bit.ly/MozLab • Download Virtual Box, OWASP Broken Web App VM
  • 8. Agenda • Business risk of SQL Injection • Understanding the vulnerability • Attack scenarios • Mitigation techniques
  • 9. Fundamental Problem • User controlled data improperly used with SQL statements • Example Vulnerable Query: sqlQ = “Select user from UserTable where name= '+username + ' and pass = '+password+ ' ” Login: ___ My username is o’malley ? Pass: ____
  • 10. Fundamental Problem • User controlled data improperly used with SQL statements • o’malley scenario Select user from UserTable where name= 'o'malley' and pass = 'foo' • Result: Error, syntax is not valid Error: Invalid syntax
  • 11. Agenda • Business risk of SQL Injection • Understanding the vulnerability • Attack scenarios • Mitigation techniques
  • 12. SQL Attack Examples • Basic SQL Injection Tests: OR 1=1 -- ' OR '1'= '1'-- • Select user from UserTable where name= 'joe' and pass = ' ' OR '1'= '1'-- ' • Looks for username of joe and password of (blank || TRUE)
  • 13. Variations • SQL Injection • Error message or different text returned based on SQL statement results • Example: Error message, db data displayed in page • Blind SQL Injection • No visible response to user indicating success of fail of query
  • 14. Blind SQL Injection • Use time of results to deduce boolean • Injected SQL uses IF statements and delays to enumerate data, 1 char at a time
  • 15. Blind SQL Examples mysql> select * from example; +----+-----------------+------+ | id | name | age | +----+-----------------+------+ | 1 | Timmy Mellowman | 23 | Text| | 2 | Sandy Smith | 21 +----+-----------------+------+ 2 rows in set (0.00 sec)
  • 16. Blind SQL Examples • mysql> SELECT IF( name = 'Sandy Smith', BENCHMARK(1000000,MD5( 'x' )),NULL) FROM example; • Command line result - 2 rows in set (5.25 sec) • mysql> SELECT IF( name = 'Joe Bob', BENCHMARK(1000000,MD5( 'x' )),NULL) FROM example; • Command line result - 2 rows in set (0.00 sec) • The actual data returned is not important the delay indicates True of False +----+-----------------+------+ | 1 | Timmy Mellowman | 23 | | 2 | Sandy Smith | 21 | +----+-----------------+------+
  • 17. Blind SQL Injection • mysql> select headerName from header_store UNION select IF(SUBSTRING(name, 1,1)='T',BENCHMARK(1000000,MD5( 'x' )),'y') from example where age=23 limit 1; • 1 row in set (6.01 sec) • Test if the first character of "name" from the example table (where age=23) is the letter T. +----+-----------------+------+ | 1 | Timmy Mellowman | 23 |
  • 18. WebGoat • Click First Link - OWASP WebGoat version 5.3.x • Username / Password is guest / guest
  • 19. Setup • http://people.mozilla.org/~mcoates/ WebSecurityLab.html#installation • http://bit.ly/MozLab • Download Virtual Box, OWASP Broken Web App VM
  • 20. Using A Proxy • Burp - Configure to listen on 8080 • Ensure “loopback only” is checked (will be by default)
  • 21. Set Firefox Proxy • Set Firefox proxy to 8080 • Preferences -> Advanced -> Network -> Settings • Set HTTP Proxy • Important - clear “No Proxy for” line
  • 22. Confirm Setup Works • Refresh Web Browser - it should hang • Go to Burp -> Proxy -> Intercept (they are highlighted) • Click “Forward” for all messages • Should now see page in browser
  • 23. Confirm Setup Works • Intercept is on • Each request will be caught by proxy • Requires you to hit forward each time • Intercept is off • Requests sent through proxy automatically • Logged in tab “proxy”->”history”
  • 24. “Hello World” of Proxies • Lesson: General->Http Basic • Objective: • Enter your name into text box • Intercept with proxy & change entered name to different value • Receive response & observe modified value is reversed Joe Sue Attacker’s euS euS Web Proxy Web Server Browser
  • 25. SQL Injection • Problem: User controlled data improperly used with SQL statements • Impact: Arbitrary SQL Execution, Data Corruption, Data Theft • Basic SQL Injection Tests: OR 1=1 -- ' OR '1'= '1'-- • Example Vulnerable Query: sqlQ = “Select user from UserTable where name= '+username+ ' and pass = '+password+ ' ”
  • 26. Lab! - SQL Lesson
  • 27. SQL Injection • Lesson: Injection Flaws -> Lab: SQL Injection -> Stage 1: String SQL Injection • Proxy Needed • Objective: Bypass the login page by inserting “control” characters. Login as “Neville” w/o knowledge of the password
  • 28. SQL Injection • HTTP Post employee_id=112&password=x' OR '1'='1&action=Login • Vulnerable SQL Select user from UserTable where name= '+username+ ' and pass = '+password+ ' Select user from UserTable where name= '112' and pass = 'x' OR '1'='1' • Result: ... name = ' 112 ' and pass = 'x ' OR TRUE
  • 29. Agenda • Business risk of SQL Injection • Understanding the vulnerability • Attack scenarios • Mitigation techniques
  • 30. SQL Injection • Parameterized Queries No confusion with control characters • Input Validation Are special characters needed for most fields? What about non-printable characters %00-%0A? Just a layer of defense - remember o’malley example
  • 31. Parameterized Query • HTTP Post employee_id=112&password=x' OR '1'='1&action=Login • Parameterized Query Look for employee_id 112 with password of x' OR '1'='1 • Result: Login fail - password is foo not x' OR '1'='1
  • 32. Language Examples • User data + string concatenation == SQL injection disaster • DJANGO • Model Query API-> Safe • raw() manager -> Dangerous, Avoid! • Java String query = "SELECT account_balance FROM user_data WHERE user_name = ? "; PreparedStatement pstmt = connection.prepareStatement( query ); pstmt.setString( 1, custname); ResultSet results = pstmt.executeQuery( );
  • 33. Additional Resources • OWASP SQL Prevention Cheat Sheet • https://www.owasp.org/index.php/ SQL_Injection_Prevention_Cheat_Sheet • 10 Minute Crash Course • Episode 3 - http://www.youtube.com/user/ AppsecTutorialSeries
  • 34. Questions • Next Events • Aug 24 - CEF Logging for Attack Aware Applications • Aug 25 - OWASP Bay Area Chapter Meeting • https://wiki.mozilla.org/index.php? title=WebAppSec#Schedule

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n