SlideShare a Scribd company logo
SQL Injection Attacks By Komal Arora
How a dynamic website works... Programming Language in the Front-end and DATABASE in the backend. Queries are used to store or retrieve data
How do we make a secure Dynamic website? Javascript Validations.... Server side validations..... No script tags should be allowed.... And Avoid SQL injections....
What is a SQL Injection  ATTACK? Many web applications take user input from a Form •  Often this user input is used literally in the construction of a SQL query submitted to a database. For example: –  SELECT productdata FROM table WHERE productname = ‘user input product name’; •  A SQL injection attack involves placing SQL statements in the user input
An Example SQL Injection Attack Product Search:  blah‘ OR ‘1’ = ‘1' •  This input is put directly into the SQL statement within the Web application: –  $query = “SELECT prodinfo FROM prodtable WHERE prodname = ‘” . $_POST[‘prod_search’] . “’”; Creates the following SQL: –  SELECT prodinfo FROM prodtable WHERE prodname = ‘blah‘ OR 1x1 = 1x1 –  Attacker has now successfully caused the entire database to be returned.
Another example What if the attacker had instead entered:– blah‘; DROP TABLE prodinfo;  •  Results in the following SQL: –  SELECT prodinfo FROM prodtable WHERE prodname = ‘blah’; DROP TABLE prodinfo; --’ –  Note how comment (--) consumes the final quote •  Causes the entire database to be deleted –  Depends on knowledge of table name –  This is sometimes exposed to the user in debug code called during a database error –  Use non-obvious table names, and never expose them to user
Other injection possibilities Using SQL injections, attackers can: –  Add new data to the database •  Selling someone else's items on an eCommerce site •  Perform an INSERT in the injected SQL –  Modify data currently in the database •  Could be very costly to have an expensive item suddenly be deeply ‘discounted’ •  Perform an UPDATE in the injected SQL –  Often can gain access to other user’s system capabilities by obtaining their password
Defenses Check syntax of input for validity Do not allow problematic characters (e.g., ‘*’ ,'=' in user input)‏ •  If you can exclude quotes and semicolons that’s good –  Not always possible: consider the name Bill O’Reilly •  Have length limits on input –  Many SQL injection attacks depend on entering long strings
More... Scan query string for undesirable word combinations that indicate SQL statements –  INSERT, DROP, etc. –  If you see these, can check against SQL syntax to see if they represent a statement or valid user input •  Limit database permissions and segregate users –  If you’re only reading the database, connect to database as a user that only has read permissions –  Never connect as a database administrator in your web application
Configure database error reporting –  Default error reporting often gives away information that is valuable for attackers (table name, field name, etc.)‏ –  Configure so that this information is never exposed to a user •  If possible, use bound variables $sth = $dbh->prepare("SELECT email, userid FROM members WHERE email = ?;"); $sth->execute($email);
How we can do it in CodeIgniter? Escaping Queries It's a very good security practice to escape your data before submitting it into your database.  mysql_real_escape_string() calls MySQL’s library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ‘, ” .
Examples... $this->db->escape()  This function determines the data type so that it can escape only string data. It also automatically adds single quotes around the data so you don't have to: $sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")"; $this->db->escape_str()  This function escapes the data passed to it, regardless of type. Most of the time you'll use the above function rather than this one. Use the function like this: $sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')"; $this->db->escape_like_str()  This method should be used when strings are to be used in LIKE conditions so that LIKE wildcards ('%', '_') in the string are also properly escaped. $search = '20% raise'; $sql = "SELECT id FROM table WHERE column LIKE '%".$this->db->escape_like_str($search)."%'";
Query Bindings Bindings enable you to simplify your query syntax by letting the system put the queries together for you. Consider the following example: $sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";  $this->db->query($sql, array(3, 'live', 'Rick')); The question marks in the query are automatically replaced with the values in the array in the second parameter of the query function. The secondary benefit of using binds is that the values are automatically escaped, producing safer queries. You don't have to remember to manually escape data; the engine does it automatically for you.

More Related Content

What's hot (20)

PDF
Understanding and testing restful web services
mwinteringham
 
PPTX
Rest API
Rohana K Amarakoon
 
PPTX
QA Lab: тестирование ПО. Владимир Гарбуз: "Application Security 101"
GeeksLab Odessa
 
PDF
Object Oriented Programming with Laravel - Session 4
Shahrzad Peyman
 
PPTX
ASP.NET Web API and HTTP Fundamentals
Ido Flatow
 
PPT
External Data Access with jQuery
Doncho Minkov
 
PDF
Input validation slides of web application workshop
Payampardaz
 
PPT
AJAX
ARJUN
 
PDF
The never-ending REST API design debate
Restlet
 
PPT
Introduction to the Web API
Brad Genereaux
 
PDF
Object Oriented Programming with Laravel - Session 2
Shahrzad Peyman
 
PPT
ASP.NET 12 - State Management
Randy Connolly
 
PPT
Understanding REST
Nitin Pande
 
PPT
Entity frameworks101
Rich Helton
 
PDF
Object Oriented Programming with Laravel - Session 6
Shahrzad Peyman
 
PDF
Object Oriented Programming with Laravel - Session 5
Shahrzad Peyman
 
PDF
<img src="../i/r_14.png" />
tutorialsruby
 
PPT
Securing Your Web Server
manugoel2003
 
ODP
The Internet as Web Services: introduction to ReST
Bruno Kessler Foundation
 
PDF
Ibm tivoli access manager for e business junctions and links redp4621
Banking at Ho Chi Minh city
 
Understanding and testing restful web services
mwinteringham
 
QA Lab: тестирование ПО. Владимир Гарбуз: "Application Security 101"
GeeksLab Odessa
 
Object Oriented Programming with Laravel - Session 4
Shahrzad Peyman
 
ASP.NET Web API and HTTP Fundamentals
Ido Flatow
 
External Data Access with jQuery
Doncho Minkov
 
Input validation slides of web application workshop
Payampardaz
 
AJAX
ARJUN
 
The never-ending REST API design debate
Restlet
 
Introduction to the Web API
Brad Genereaux
 
Object Oriented Programming with Laravel - Session 2
Shahrzad Peyman
 
ASP.NET 12 - State Management
Randy Connolly
 
Understanding REST
Nitin Pande
 
Entity frameworks101
Rich Helton
 
Object Oriented Programming with Laravel - Session 6
Shahrzad Peyman
 
Object Oriented Programming with Laravel - Session 5
Shahrzad Peyman
 
<img src="../i/r_14.png" />
tutorialsruby
 
Securing Your Web Server
manugoel2003
 
The Internet as Web Services: introduction to ReST
Bruno Kessler Foundation
 
Ibm tivoli access manager for e business junctions and links redp4621
Banking at Ho Chi Minh city
 

Viewers also liked (20)

ODP
Nuclear cemeteries
Carol Lopez
 
PPT
Software Development Life Cycle Part II
Compare Infobase Limited
 
PPT
Social Media Integration
Compare Infobase Limited
 
ODP
Presentación inglés
Carol Lopez
 
PPTX
An Analysis of the Privacy and Security Risks of Android VPN Permission-enabl...
Narseo Rodriguez
 
PPTX
Mobile app privacy
Leo Lau
 
PDF
UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...
Timothy Ledoux, MSCS, CISSO, CPTE
 
PPTX
Sql injection ( http://etabz.blogspot.com/2014/11/sql-injection.html )
Ehtisham Ullah
 
PDF
Apps and Privacy
Thomas Müller
 
PPTX
VPN Types, Vulnerabilities & Solutions - Tareq Hanaysha
Hanaysha
 
PPTX
Storage in the Windows Azure Platform - ericnel
ukdpe
 
PPTX
Information Security and Privacy
Anika Tasnim Hafiz
 
PPTX
App Privacy
ConnectSafely
 
PPT
Secure Data Sharing in Cloud (SDSC)
Jishnu Pradeep
 
PPTX
Sql Injection attacks and prevention
helloanand
 
PPT
Cloud Computing Security Issues
Discover Cloud Computing
 
PPTX
Cloud Computing Security
Ninh Nguyen
 
PPTX
Cloud security ppt
Venkatesh Chary
 
PPTX
Privacy and mobile apps - status 2013 Belgium
Mobile Monday Brussels
 
PPTX
Data security in cloud computing
Prince Chandu
 
Nuclear cemeteries
Carol Lopez
 
Software Development Life Cycle Part II
Compare Infobase Limited
 
Social Media Integration
Compare Infobase Limited
 
Presentación inglés
Carol Lopez
 
An Analysis of the Privacy and Security Risks of Android VPN Permission-enabl...
Narseo Rodriguez
 
Mobile app privacy
Leo Lau
 
UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...
Timothy Ledoux, MSCS, CISSO, CPTE
 
Sql injection ( http://etabz.blogspot.com/2014/11/sql-injection.html )
Ehtisham Ullah
 
Apps and Privacy
Thomas Müller
 
VPN Types, Vulnerabilities & Solutions - Tareq Hanaysha
Hanaysha
 
Storage in the Windows Azure Platform - ericnel
ukdpe
 
Information Security and Privacy
Anika Tasnim Hafiz
 
App Privacy
ConnectSafely
 
Secure Data Sharing in Cloud (SDSC)
Jishnu Pradeep
 
Sql Injection attacks and prevention
helloanand
 
Cloud Computing Security Issues
Discover Cloud Computing
 
Cloud Computing Security
Ninh Nguyen
 
Cloud security ppt
Venkatesh Chary
 
Privacy and mobile apps - status 2013 Belgium
Mobile Monday Brussels
 
Data security in cloud computing
Prince Chandu
 
Ad

Similar to SQL Injection Attacks (20)

PPT
Sql injection attacks
chaitanya Lotankar
 
PPT
Sql injection attacks
Kumar
 
PPT
Sql injection attacks
Nitish Kumar
 
PPT
SQL Injection in PHP
Dave Ross
 
PPT
D:\Technical\Ppt\Sql Injection
avishkarm
 
PPT
Advanced Sql Injection ENG
Dmitry Evteev
 
PPT
A Brief Introduction in SQL Injection
Sina Manavi
 
PPT
12-security.ppt - PHP and Arabic Language - Index
webhostingguy
 
PPT
Security.ppt
webhostingguy
 
PPTX
Sql injection
Mehul Boghra
 
PDF
Asp
Adil Jafri
 
PPTX
Code injection and green sql
Kaustav Sengupta
 
PPTX
Greensql2007
Kaustav Sengupta
 
PDF
A Brief Introduction About Sql Injection in PHP and MYSQL
kobaitari
 
PPTX
Ppt on sql injection
ashish20012
 
PDF
Web Security 101
Michael Peters
 
PPT
Sql Injection Attacks Siddhesh
Siddhesh Bhobe
 
PPTX
Playing With (B)Sqli
Chema Alonso
 
PPTX
03. sql and other injection module v17
Eoin Keary
 
PDF
Hack your db before the hackers do
fangjiafu
 
Sql injection attacks
chaitanya Lotankar
 
Sql injection attacks
Kumar
 
Sql injection attacks
Nitish Kumar
 
SQL Injection in PHP
Dave Ross
 
D:\Technical\Ppt\Sql Injection
avishkarm
 
Advanced Sql Injection ENG
Dmitry Evteev
 
A Brief Introduction in SQL Injection
Sina Manavi
 
12-security.ppt - PHP and Arabic Language - Index
webhostingguy
 
Security.ppt
webhostingguy
 
Sql injection
Mehul Boghra
 
Code injection and green sql
Kaustav Sengupta
 
Greensql2007
Kaustav Sengupta
 
A Brief Introduction About Sql Injection in PHP and MYSQL
kobaitari
 
Ppt on sql injection
ashish20012
 
Web Security 101
Michael Peters
 
Sql Injection Attacks Siddhesh
Siddhesh Bhobe
 
Playing With (B)Sqli
Chema Alonso
 
03. sql and other injection module v17
Eoin Keary
 
Hack your db before the hackers do
fangjiafu
 
Ad

More from Compare Infobase Limited (20)

PPT
Dos and Don't during Monsoon!
Compare Infobase Limited
 
PPT
Intellectual Property Rights : A Primer
Compare Infobase Limited
 
PPT
CIL initiative against Corruption
Compare Infobase Limited
 
PPT
Cloud Computing
Compare Infobase Limited
 
PPT
Arrays in PHP
Compare Infobase Limited
 
PPT
Storage and Storage Devices
Compare Infobase Limited
 
PPT
World No Tobacco Day
Compare Infobase Limited
 
PPT
Tips for Effective Online Marketing
Compare Infobase Limited
 
PPT
iOS Application Development
Compare Infobase Limited
 
PPT
Have a safe Summer!
Compare Infobase Limited
 
PPT
Introduction to Android Environment
Compare Infobase Limited
 
PPT
MySQL Functions
Compare Infobase Limited
 
PPT
Excel with Excel
Compare Infobase Limited
 
PPT
Software Development Life Cycle (SDLC)
Compare Infobase Limited
 
PPT
How to increase effective CTR, CPC and e CPM of website?
Compare Infobase Limited
 
PPT
How do speed up web pages? CSS & HTML Tricks
Compare Infobase Limited
 
PPT
Steps for Effective Keyword Research
Compare Infobase Limited
 
PPT
50 Social Media Breakfasts - An Amazing Journey!
Compare Infobase Limited
 
Dos and Don't during Monsoon!
Compare Infobase Limited
 
Intellectual Property Rights : A Primer
Compare Infobase Limited
 
CIL initiative against Corruption
Compare Infobase Limited
 
Cloud Computing
Compare Infobase Limited
 
Storage and Storage Devices
Compare Infobase Limited
 
World No Tobacco Day
Compare Infobase Limited
 
Tips for Effective Online Marketing
Compare Infobase Limited
 
iOS Application Development
Compare Infobase Limited
 
Have a safe Summer!
Compare Infobase Limited
 
Introduction to Android Environment
Compare Infobase Limited
 
MySQL Functions
Compare Infobase Limited
 
Excel with Excel
Compare Infobase Limited
 
Software Development Life Cycle (SDLC)
Compare Infobase Limited
 
How to increase effective CTR, CPC and e CPM of website?
Compare Infobase Limited
 
How do speed up web pages? CSS & HTML Tricks
Compare Infobase Limited
 
Steps for Effective Keyword Research
Compare Infobase Limited
 
50 Social Media Breakfasts - An Amazing Journey!
Compare Infobase Limited
 

Recently uploaded (20)

PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
July Patch Tuesday
Ivanti
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 

SQL Injection Attacks

  • 1. SQL Injection Attacks By Komal Arora
  • 2. How a dynamic website works... Programming Language in the Front-end and DATABASE in the backend. Queries are used to store or retrieve data
  • 3. How do we make a secure Dynamic website? Javascript Validations.... Server side validations..... No script tags should be allowed.... And Avoid SQL injections....
  • 4. What is a SQL Injection ATTACK? Many web applications take user input from a Form • Often this user input is used literally in the construction of a SQL query submitted to a database. For example: – SELECT productdata FROM table WHERE productname = ‘user input product name’; • A SQL injection attack involves placing SQL statements in the user input
  • 5. An Example SQL Injection Attack Product Search: blah‘ OR ‘1’ = ‘1' • This input is put directly into the SQL statement within the Web application: – $query = “SELECT prodinfo FROM prodtable WHERE prodname = ‘” . $_POST[‘prod_search’] . “’”; Creates the following SQL: – SELECT prodinfo FROM prodtable WHERE prodname = ‘blah‘ OR 1x1 = 1x1 – Attacker has now successfully caused the entire database to be returned.
  • 6. Another example What if the attacker had instead entered:– blah‘; DROP TABLE prodinfo; • Results in the following SQL: – SELECT prodinfo FROM prodtable WHERE prodname = ‘blah’; DROP TABLE prodinfo; --’ – Note how comment (--) consumes the final quote • Causes the entire database to be deleted – Depends on knowledge of table name – This is sometimes exposed to the user in debug code called during a database error – Use non-obvious table names, and never expose them to user
  • 7. Other injection possibilities Using SQL injections, attackers can: – Add new data to the database • Selling someone else's items on an eCommerce site • Perform an INSERT in the injected SQL – Modify data currently in the database • Could be very costly to have an expensive item suddenly be deeply ‘discounted’ • Perform an UPDATE in the injected SQL – Often can gain access to other user’s system capabilities by obtaining their password
  • 8. Defenses Check syntax of input for validity Do not allow problematic characters (e.g., ‘*’ ,'=' in user input)‏ • If you can exclude quotes and semicolons that’s good – Not always possible: consider the name Bill O’Reilly • Have length limits on input – Many SQL injection attacks depend on entering long strings
  • 9. More... Scan query string for undesirable word combinations that indicate SQL statements – INSERT, DROP, etc. – If you see these, can check against SQL syntax to see if they represent a statement or valid user input • Limit database permissions and segregate users – If you’re only reading the database, connect to database as a user that only has read permissions – Never connect as a database administrator in your web application
  • 10. Configure database error reporting – Default error reporting often gives away information that is valuable for attackers (table name, field name, etc.)‏ – Configure so that this information is never exposed to a user • If possible, use bound variables $sth = $dbh->prepare("SELECT email, userid FROM members WHERE email = ?;"); $sth->execute($email);
  • 11. How we can do it in CodeIgniter? Escaping Queries It's a very good security practice to escape your data before submitting it into your database. mysql_real_escape_string() calls MySQL’s library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ‘, ” .
  • 12. Examples... $this->db->escape() This function determines the data type so that it can escape only string data. It also automatically adds single quotes around the data so you don't have to: $sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")"; $this->db->escape_str() This function escapes the data passed to it, regardless of type. Most of the time you'll use the above function rather than this one. Use the function like this: $sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')"; $this->db->escape_like_str() This method should be used when strings are to be used in LIKE conditions so that LIKE wildcards ('%', '_') in the string are also properly escaped. $search = '20% raise'; $sql = "SELECT id FROM table WHERE column LIKE '%".$this->db->escape_like_str($search)."%'";
  • 13. Query Bindings Bindings enable you to simplify your query syntax by letting the system put the queries together for you. Consider the following example: $sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?"; $this->db->query($sql, array(3, 'live', 'Rick')); The question marks in the query are automatically replaced with the values in the array in the second parameter of the query function. The secondary benefit of using binds is that the values are automatically escaped, producing safer queries. You don't have to remember to manually escape data; the engine does it automatically for you.