SlideShare uma empresa Scribd logo
1 de 25
SQL Injection
     101


     SQLi
SQLi



                      Jason Pubal
                          Contact Information




Website
www.intellavis.com/blog
                                       Social
                                       www.linkedin.com/in/pubal
E-Mail                                 Twitter: @pubal
jpubal@gmail.com
SQLi



SQL Injection
        Outline
   OWASP Top 10
   Web Architecture

   What is SQLi?
     Detecting SQLi



   Exploiting SQLi

    Preventing SQLi
SQLi
SQLi
SQLi



            Web Application Basics

                                                         SELECT *FROM productsWHERE category=‘balls’
Get www.MyAwesomeStore.com/buystuff.php?category=balls




                                                                                                       baseballs
                                                                                                       soccer balls
                                                                                                       basketballs
                                                                                                       blue balls
                                                                                                       tennis balls
SQLi




//connect to database
$conn = mysql_connect(“localhost”, “username”, “password”);

//build sql statement
$query = “SELECT userid FROM AppUsers WHERE user=
‘$_POST[“username”]’ “ .
“AND password = ‘$_POST[“password”]’ “ ;

//run query
$result = mysql_query($query);

//ensure a user was returned
$numrows = mysql_num_rows($result);

if ($numrows != 0){
header(“Location: admin.php”);
}else{
die(‘Incorrect username or password.’)
}
SQLi




SELECT userid
FROM AppUsers
WHERE user = ‘jsmith’
 AND password = ‘kitteh’ ;
SQLi




SELECT userid
FROM AppUsers
WHERE user = ‘jsmith’
 AND password = ‘anything’ OR ‘1’ = ‘1’ ;
SQLi




//connect to database$conn = mysql_connect(“localhost”,
“username”, “password”);
//build sql statement$query = “SELECT userid FROM AppUsers
WHERE user= ‘$_POST[“username”]’ “ .“AND password =
‘$_POST[“password”]’ “ ;
//run query$result = mysql_query($query);
//ensure a user was returned$numrows = mysql_num_rows($result);
if ($numrows != 0){header(“Location: admin.php”);}else{die(‘Incorrect
username or password.’)}
SQLi



                                    Impact
•Authentication Bypass: This attack allows an attacker to log on to an application without
supplying a valid username and password.

•Information Disclosure: This attack allows an attacker to obtain sensitive information that
is contained in a database.

•Alter Data: This attack involves the alteration of the contents of a database. This can be
used to deface a web page. It can also be used to insert malicious content, like JavaScript
malware.

•Delete Data: This attack allows an attacker to delete information with the intent to cause
harm or delete log or audit information that is contained in a database.

•Remote Command Execution: Performing command execution through a database can
allow an attacker to compromise the host operating system. These attacks often leverage an
existing, predefined stored procedure for host operating system command execution.
SQLi



Vulnerable Sites
  WhiteHat Security Statistics Report
SQLi



Web Application Attacks
       Web Hacking Incident DB

                      Body Text
SQLi



                     Detecting SQLi
Testing by Inference                              Special Characters

•If I see this, then this is probably             -- Comment everything after
happening at the back end.                        /* Begin comment
                                                  */ End Comment
                                                  ‘   Mark beginning/end of string
Try to break the application.                     ;   End of SQL statement
                                                  “   Delimit identifiers
•Find the Inputs likely to be generating
dynamic SQL.
•Use Input that will create invalid SQL.          Type Issues
•See if you get errors!
                                                  use strings instead of numbers
                                                  add unexpected spaces
SQLi



SQLi Errors
SQLi



Detecting SQLi
        Other Signs



       HTTP 500 Status

   Custom Application Errors

            Timing

   Differences in Web Page
SQLi



Manual Testing
SQLi



Manual Testing
SQLi



Automated Testing
     Browser Plugins
SQLi



Automated Testing
  Web Application Vulnerability Scanner
SQLi



Automated Testing
  Web Application Vulnerability Scanner
SQLi



Exploitation
    SQLMAP
SQLi



Preventing SQLi
SQLi



              Sources / Tools Used
More about SQLi
OWASP - https://www.owasp.org/index.php/SQL_Injection
SQL Injection Attacks and Defense (Amazon) - http://goo.gl/KSUAl

Web Application Vulnerability Scanners
ZAP – http://code.google.com/p/zaproxy/
w3af – http://w3af.sourceforge.net/

Browser Plugins
Tamper Data – https://addons.mozilla.org/en-US/firefox/addon/tamper-data/
SQL Inject Me – https://addons.mozilla.org/en-US/firefox/addon/sql-inject-me/

Vulnerable Web Applications
OWASP Broken Web Apps – http://code.google.com/p/owaspbwa/
The BodgeIt Store – http://code.google.com/p/bodgeit/
Damn Vulnerable Web Application – http://www.dvwa.co.uk/

SQL Exploitation
SQLMAP - http://sqlmap.org/

Collections of Tools
Backtrack – http://www.backtrack-linux.org/
Mantra – http://getmantra.com/
THANK YOU FOR
   COMING




          Contact Info:

          jpubal@gmail.com
          www.intellavis.com/blog
          Twitter: @pubal

Mais conteúdo relacionado

Mais procurados

Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0
Rakesh Kachhadiya
 
jQtouch, Building Awesome Webapps
jQtouch, Building Awesome WebappsjQtouch, Building Awesome Webapps
jQtouch, Building Awesome Webapps
Home
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Masashi Shibata
 

Mais procurados (10)

Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0
 
jQtouch, Building Awesome Webapps
jQtouch, Building Awesome WebappsjQtouch, Building Awesome Webapps
jQtouch, Building Awesome Webapps
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp Orlando
 
AWS Elastic Beanstalk
AWS Elastic BeanstalkAWS Elastic Beanstalk
AWS Elastic Beanstalk
 
iWebkit
iWebkitiWebkit
iWebkit
 
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value)3
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value)32. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value)3
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value)3
 
Ionic tabs template explained
Ionic tabs template explainedIonic tabs template explained
Ionic tabs template explained
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
Embracing Capybara
Embracing CapybaraEmbracing Capybara
Embracing Capybara
 

Destaque

Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity Frameworks
Rich Helton
 

Destaque (20)

Sql Injection attacks and prevention
Sql Injection attacks and preventionSql Injection attacks and prevention
Sql Injection attacks and prevention
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
 
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
 
Threat modeling librarian freedom conference
Threat modeling   librarian freedom conferenceThreat modeling   librarian freedom conference
Threat modeling librarian freedom conference
 
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 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 - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testing
 
SQL Injection Attacks cs586
SQL Injection Attacks cs586SQL Injection Attacks cs586
SQL Injection Attacks cs586
 
Sql Injection Attacks Siddhesh
Sql Injection Attacks SiddheshSql Injection Attacks Siddhesh
Sql Injection Attacks Siddhesh
 
Sql injection attack
Sql injection attackSql injection attack
Sql injection attack
 
Sql injection
Sql injectionSql injection
Sql injection
 
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
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity Frameworks
 
D:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql InjectionD:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql Injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
Web application attacks using Sql injection and countermasures
Web application attacks using Sql injection and countermasuresWeb application attacks using Sql injection and countermasures
Web application attacks using Sql injection and countermasures
 

Semelhante a Introduction to SQL Injection

Web application security
Web application securityWeb application security
Web application security
Vikas Thange
 

Semelhante a Introduction to SQL Injection (20)

SANS @Night Talk: SQL Injection Exploited
SANS @Night Talk: SQL Injection ExploitedSANS @Night Talk: SQL Injection Exploited
SANS @Night Talk: SQL Injection Exploited
 
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
 
SQL injection Colombo Cybersecurity Meetup
SQL injection Colombo Cybersecurity MeetupSQL injection Colombo Cybersecurity Meetup
SQL injection Colombo Cybersecurity Meetup
 
SQL Injection in PHP
SQL Injection in PHPSQL Injection in PHP
SQL Injection in PHP
 
Sql Injection V.2
Sql Injection V.2Sql Injection V.2
Sql Injection V.2
 
ASP.NET Web Security
ASP.NET Web SecurityASP.NET Web Security
ASP.NET Web Security
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
Sql injection
Sql injectionSql injection
Sql injection
 
Web application security
Web application securityWeb application security
Web application security
 
Web application security
Web application securityWeb application security
Web application security
 
Owasp Top 10 A1: Injection
Owasp Top 10 A1: InjectionOwasp Top 10 A1: Injection
Owasp Top 10 A1: Injection
 
SQL Injection in JAVA
SQL Injection in JAVASQL Injection in JAVA
SQL Injection in JAVA
 
STATE OF THE ART AUTHENTICATION MIT JAVA EE 8
STATE OF THE ART AUTHENTICATION MIT JAVA EE 8STATE OF THE ART AUTHENTICATION MIT JAVA EE 8
STATE OF THE ART AUTHENTICATION MIT JAVA EE 8
 
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
 
SQL Injection Attacks
SQL Injection AttacksSQL Injection Attacks
SQL Injection Attacks
 
Sq li
Sq liSq li
Sq li
 
State of the art authentication mit Java EE 8
State of the art authentication mit Java EE 8State of the art authentication mit Java EE 8
State of the art authentication mit Java EE 8
 
Drupal Security Seminar
Drupal Security SeminarDrupal Security Seminar
Drupal Security Seminar
 
4 andrii kudiurov - web application security 101
4   andrii kudiurov - web application security 1014   andrii kudiurov - web application security 101
4 andrii kudiurov - web application security 101
 
Web Security 101
Web Security 101Web Security 101
Web Security 101
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+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@
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+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...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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...
 

Introduction to SQL Injection

  • 1. SQL Injection 101 SQLi
  • 2. SQLi Jason Pubal Contact Information Website www.intellavis.com/blog Social www.linkedin.com/in/pubal E-Mail Twitter: @pubal jpubal@gmail.com
  • 3. SQLi SQL Injection Outline OWASP Top 10 Web Architecture What is SQLi? Detecting SQLi Exploiting SQLi Preventing SQLi
  • 6. SQLi Web Application Basics SELECT *FROM productsWHERE category=‘balls’ Get www.MyAwesomeStore.com/buystuff.php?category=balls baseballs soccer balls basketballs blue balls tennis balls
  • 7. SQLi //connect to database $conn = mysql_connect(“localhost”, “username”, “password”); //build sql statement $query = “SELECT userid FROM AppUsers WHERE user= ‘$_POST[“username”]’ “ . “AND password = ‘$_POST[“password”]’ “ ; //run query $result = mysql_query($query); //ensure a user was returned $numrows = mysql_num_rows($result); if ($numrows != 0){ header(“Location: admin.php”); }else{ die(‘Incorrect username or password.’) }
  • 8. SQLi SELECT userid FROM AppUsers WHERE user = ‘jsmith’ AND password = ‘kitteh’ ;
  • 9. SQLi SELECT userid FROM AppUsers WHERE user = ‘jsmith’ AND password = ‘anything’ OR ‘1’ = ‘1’ ;
  • 10. SQLi //connect to database$conn = mysql_connect(“localhost”, “username”, “password”); //build sql statement$query = “SELECT userid FROM AppUsers WHERE user= ‘$_POST[“username”]’ “ .“AND password = ‘$_POST[“password”]’ “ ; //run query$result = mysql_query($query); //ensure a user was returned$numrows = mysql_num_rows($result); if ($numrows != 0){header(“Location: admin.php”);}else{die(‘Incorrect username or password.’)}
  • 11. SQLi Impact •Authentication Bypass: This attack allows an attacker to log on to an application without supplying a valid username and password. •Information Disclosure: This attack allows an attacker to obtain sensitive information that is contained in a database. •Alter Data: This attack involves the alteration of the contents of a database. This can be used to deface a web page. It can also be used to insert malicious content, like JavaScript malware. •Delete Data: This attack allows an attacker to delete information with the intent to cause harm or delete log or audit information that is contained in a database. •Remote Command Execution: Performing command execution through a database can allow an attacker to compromise the host operating system. These attacks often leverage an existing, predefined stored procedure for host operating system command execution.
  • 12. SQLi Vulnerable Sites WhiteHat Security Statistics Report
  • 13. SQLi Web Application Attacks Web Hacking Incident DB Body Text
  • 14. SQLi Detecting SQLi Testing by Inference Special Characters •If I see this, then this is probably -- Comment everything after happening at the back end. /* Begin comment */ End Comment ‘ Mark beginning/end of string Try to break the application. ; End of SQL statement “ Delimit identifiers •Find the Inputs likely to be generating dynamic SQL. •Use Input that will create invalid SQL. Type Issues •See if you get errors! use strings instead of numbers add unexpected spaces
  • 16. SQLi Detecting SQLi Other Signs HTTP 500 Status Custom Application Errors Timing Differences in Web Page
  • 19. SQLi Automated Testing Browser Plugins
  • 20. SQLi Automated Testing Web Application Vulnerability Scanner
  • 21. SQLi Automated Testing Web Application Vulnerability Scanner
  • 24. SQLi Sources / Tools Used More about SQLi OWASP - https://www.owasp.org/index.php/SQL_Injection SQL Injection Attacks and Defense (Amazon) - http://goo.gl/KSUAl Web Application Vulnerability Scanners ZAP – http://code.google.com/p/zaproxy/ w3af – http://w3af.sourceforge.net/ Browser Plugins Tamper Data – https://addons.mozilla.org/en-US/firefox/addon/tamper-data/ SQL Inject Me – https://addons.mozilla.org/en-US/firefox/addon/sql-inject-me/ Vulnerable Web Applications OWASP Broken Web Apps – http://code.google.com/p/owaspbwa/ The BodgeIt Store – http://code.google.com/p/bodgeit/ Damn Vulnerable Web Application – http://www.dvwa.co.uk/ SQL Exploitation SQLMAP - http://sqlmap.org/ Collections of Tools Backtrack – http://www.backtrack-linux.org/ Mantra – http://getmantra.com/
  • 25. THANK YOU FOR COMING Contact Info: jpubal@gmail.com www.intellavis.com/blog Twitter: @pubal