SlideShare une entreprise Scribd logo
1  sur  13
SQL Injection Attacks By Komal Arora
How a dynamic website works... ,[object Object],[object Object]
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: 00, , ,  ‘, ” .
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.

Contenu connexe

Tendances

Object Oriented Programming with Laravel - Session 4
Object Oriented Programming with Laravel - Session 4Object Oriented Programming with Laravel - Session 4
Object Oriented Programming with Laravel - Session 4
Shahrzad Peyman
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
Doncho Minkov
 
AJAX
AJAXAJAX
AJAX
ARJUN
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2
Shahrzad Peyman
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
Shahrzad Peyman
 
Object Oriented Programming with Laravel - Session 5
Object Oriented Programming with Laravel - Session 5Object Oriented Programming with Laravel - Session 5
Object Oriented Programming with Laravel - Session 5
Shahrzad Peyman
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 
Ibm tivoli access manager for e business junctions and links redp4621
Ibm tivoli access manager for e business junctions and links redp4621Ibm tivoli access manager for e business junctions and links redp4621
Ibm tivoli access manager for e business junctions and links redp4621
Banking at Ho Chi Minh city
 

Tendances (20)

Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web services
 
Rest API
Rest APIRest API
Rest API
 
QA Lab: тестирование ПО. Владимир Гарбуз: "Application Security 101"
QA Lab: тестирование ПО. Владимир Гарбуз: "Application Security 101"QA Lab: тестирование ПО. Владимир Гарбуз: "Application Security 101"
QA Lab: тестирование ПО. Владимир Гарбуз: "Application Security 101"
 
Object Oriented Programming with Laravel - Session 4
Object Oriented Programming with Laravel - Session 4Object Oriented Programming with Laravel - Session 4
Object Oriented Programming with Laravel - Session 4
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
 
Input validation slides of web application workshop
Input validation slides of web application workshopInput validation slides of web application workshop
Input validation slides of web application workshop
 
AJAX
AJAXAJAX
AJAX
 
The never-ending REST API design debate
The never-ending REST API design debateThe never-ending REST API design debate
The never-ending REST API design debate
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
 
Object Oriented Programming with Laravel - Session 5
Object Oriented Programming with Laravel - Session 5Object Oriented Programming with Laravel - Session 5
Object Oriented Programming with Laravel - Session 5
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
Securing Your Web Server
Securing Your Web ServerSecuring Your Web Server
Securing Your Web Server
 
The Internet as Web Services: introduction to ReST
The Internet as Web Services: introduction to ReSTThe Internet as Web Services: introduction to ReST
The Internet as Web Services: introduction to ReST
 
Ibm tivoli access manager for e business junctions and links redp4621
Ibm tivoli access manager for e business junctions and links redp4621Ibm tivoli access manager for e business junctions and links redp4621
Ibm tivoli access manager for e business junctions and links redp4621
 

En vedette

Nuclear cemeteries
Nuclear cemeteriesNuclear cemeteries
Nuclear cemeteries
Carol Lopez
 
Presentación inglés
Presentación inglésPresentación inglés
Presentación inglés
Carol Lopez
 
UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...
UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...
UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...
Timothy Ledoux, MSCS, CISSO, CPTE
 
Information Security and Privacy
Information Security and PrivacyInformation Security and Privacy
Information Security and Privacy
Anika Tasnim Hafiz
 

En vedette (20)

Nuclear cemeteries
Nuclear cemeteriesNuclear cemeteries
Nuclear cemeteries
 
Software Development Life Cycle Part II
Software Development Life Cycle Part IISoftware Development Life Cycle Part II
Software Development Life Cycle Part II
 
Social Media Integration
Social Media IntegrationSocial Media Integration
Social Media Integration
 
Presentación inglés
Presentación inglésPresentación inglés
Presentación inglés
 
An Analysis of the Privacy and Security Risks of Android VPN Permission-enabl...
An Analysis of the Privacy and Security Risks of Android VPN Permission-enabl...An Analysis of the Privacy and Security Risks of Android VPN Permission-enabl...
An Analysis of the Privacy and Security Risks of Android VPN Permission-enabl...
 
Mobile app privacy
Mobile app privacyMobile app privacy
Mobile app privacy
 
UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...
UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...
UCB Corporate Compliance Training - Module 5 Gramm-Leach-Bliley-Act (GLBA)-Ti...
 
Sql injection ( http://etabz.blogspot.com/2014/11/sql-injection.html )
Sql injection ( http://etabz.blogspot.com/2014/11/sql-injection.html )Sql injection ( http://etabz.blogspot.com/2014/11/sql-injection.html )
Sql injection ( http://etabz.blogspot.com/2014/11/sql-injection.html )
 
Apps and Privacy
Apps and PrivacyApps and Privacy
Apps and Privacy
 
VPN Types, Vulnerabilities & Solutions - Tareq Hanaysha
VPN Types, Vulnerabilities & Solutions - Tareq HanayshaVPN Types, Vulnerabilities & Solutions - Tareq Hanaysha
VPN Types, Vulnerabilities & Solutions - Tareq Hanaysha
 
Storage in the Windows Azure Platform - ericnel
Storage in the Windows Azure Platform - ericnelStorage in the Windows Azure Platform - ericnel
Storage in the Windows Azure Platform - ericnel
 
Information Security and Privacy
Information Security and PrivacyInformation Security and Privacy
Information Security and Privacy
 
App Privacy
App PrivacyApp Privacy
App Privacy
 
Secure Data Sharing in Cloud (SDSC)
Secure Data Sharing in Cloud (SDSC)Secure Data Sharing in Cloud (SDSC)
Secure Data Sharing in Cloud (SDSC)
 
Sql Injection attacks and prevention
Sql Injection attacks and preventionSql Injection attacks and prevention
Sql Injection attacks and prevention
 
Cloud Computing Security Issues
Cloud Computing Security Issues Cloud Computing Security Issues
Cloud Computing Security Issues
 
Cloud Computing Security
Cloud Computing SecurityCloud Computing Security
Cloud Computing Security
 
OSI Model of Networking
OSI Model of NetworkingOSI Model of Networking
OSI Model of Networking
 
Cloud security ppt
Cloud security pptCloud security ppt
Cloud security ppt
 
Privacy and mobile apps - status 2013 Belgium
Privacy and mobile apps - status 2013 BelgiumPrivacy and mobile apps - status 2013 Belgium
Privacy and mobile apps - status 2013 Belgium
 

Similaire à SQL Injection Attacks

Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
Kumar
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
Nitish Kumar
 
Advanced Sql Injection ENG
Advanced Sql Injection ENGAdvanced Sql Injection ENG
Advanced Sql Injection ENG
Dmitry Evteev
 
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
 
12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index
webhostingguy
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injection
ashish20012
 
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
 

Similaire à SQL Injection Attacks (20)

Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
SQL Injection in PHP
SQL Injection in PHPSQL Injection in PHP
SQL Injection in PHP
 
D:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql InjectionD:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql Injection
 
Advanced Sql Injection ENG
Advanced Sql Injection ENGAdvanced Sql Injection ENG
Advanced Sql Injection ENG
 
A Brief Introduction in SQL Injection
A Brief Introduction in SQL InjectionA Brief Introduction in SQL Injection
A Brief Introduction in SQL Injection
 
12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index
 
Security.ppt
Security.pptSecurity.ppt
Security.ppt
 
Sql injection
Sql injectionSql injection
Sql injection
 
Asp
AspAsp
Asp
 
Greensql2007
Greensql2007Greensql2007
Greensql2007
 
Code injection and green sql
Code injection and green sqlCode injection and green sql
Code injection and green sql
 
A Brief Introduction About Sql Injection in PHP and MYSQL
A Brief Introduction About Sql Injection in PHP and MYSQLA Brief Introduction About Sql Injection in PHP and MYSQL
A Brief Introduction About Sql Injection in PHP and MYSQL
 
Ppt on sql injection
Ppt on sql injectionPpt on sql injection
Ppt on sql injection
 
Web Security 101
Web Security 101Web Security 101
Web Security 101
 
Sql Injection Attacks Siddhesh
Sql Injection Attacks SiddheshSql Injection Attacks Siddhesh
Sql Injection Attacks Siddhesh
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)Sqli
 
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
 
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
 

Plus de Compare Infobase Limited

How to increase effective CTR, CPC and e CPM of website?
How to increase effective CTR, CPC and e CPM of website?How to increase effective CTR, CPC and e CPM of website?
How to increase effective CTR, CPC and e CPM of website?
Compare Infobase Limited
 
How do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML TricksHow do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML Tricks
Compare Infobase Limited
 
50 Social Media Breakfasts - An Amazing Journey!
50 Social Media Breakfasts - An Amazing Journey!50 Social Media Breakfasts - An Amazing Journey!
50 Social Media Breakfasts - An Amazing Journey!
Compare Infobase Limited
 

Plus de Compare Infobase Limited (20)

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

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
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
 

Dernier (20)

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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

SQL Injection Attacks

  • 1. SQL Injection Attacks By Komal Arora
  • 2.
  • 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: 00, , , ‘, ” .
  • 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.