SlideShare a Scribd company logo
A1 – Injection Attacks
Mohamed Talaat
Linkedin: https://www.linkedin.com/in/mtibrahim/
Twitter: https://twitter.com/t4144t
E-mail: Mohamed.Talaat@owasp.org
Agenda
• 1- SQL Injection
• Demo
• 2- Template Injection
• Demo
• 3- Broken Authentication
• Demo
• 4- Session Management
• Demo
What’s OWASP?
• Open Web Application Security Project aims to increase the
awareness of the application security.
• Everyone is free to participate in OWASP
• We are OWASP Egypt – Cairo Chapter
OWASP Projects
• OWASP Top 10 security vulnerabilities project
• OWASP ZAP Project
• OWASP Juice Shop
• More on the following link:
https://www.owasp.org/index.php/Category:OWASP_Project
OWASP Top 10 – Application Security Risks
How the web app works?
• 3 Tiers Model:
Browser : Presentation Tier
PHP Code : Logic Tier
SQL Code: Storage Tier
SQL Queries Types
• Static Query
• Dymanic Query
What is the type of this query?
• $dbhostname=‘127.0.0.1';
• $dbuser=‘admin';
• $dbpassword='password';
• $dbname='database';
• $connection = mysqli_connect($dbhostname, $dbuser, $dbpassword, $dbname);
$query = "SELECT Name, Description FROM Products WHERE ID='3' UNION SELECT
Username, Password FROM Accounts;";
What about this?
$id = $_GET['id'];
$connection = mysqli_connect($dbhostname, $dbuser, $dbpassword,
$dbname);
$query = "SELECT Name, Description FROM Products WHERE ID='$id';";
$results = mysqli_query($connection, $query);
display_results($results);
A1 – SQL Injection
• The first checked by hackers
• Once found, ready to be
exploited : )
Injection
• What is the SQL & Types
• Concept
• Injection Issue
• Attack
• CRUD
Injection Concept
• Identify injection point
• Finding the best technique to attack
• Data Exfiltration
SQLi Real World Scenarios
SQL Injection Scenario
Yahoo! Sports blind injection
• Stefano entered Yahoo! Web site with the following URL:
http://sports.yahoo.com/nfl/draft?year=2010&type=20&round=2
• He tried to put a comment after the year 2010 and noticed what
happen
• So it will be like this:
http://sports.yahoo.com/nfl/draft?year=2010--&type=20&round=2
SQL Injection Scenario
Yahoo! Sports blind injection
• Original Query:
SELECT * FROM PLAYERS WHERE YEAR = 2010 AND TYPE = 20 AND ROUND = 2;
• By inserting the dashes, Stefano essentially made it act like:
SELECT * FROM PLAYERS WHERE YEAR = 2010;
SQL Injection Scenario
Yahoo! Sports blind injection
• Yahoo Sport Blind Injection – Before commenting
SQL Injection Scenario
Yahoo! Sports blind injection
• Yahoo Sport Blind Injection – After commenting
SQL Injection Scenario
SQLi to RCE
• Ibrahim Raafat (Egyptian Researcher) could exploit a SQLi
vulnerability to have full control on the server.
• He was doing purchase when he noticed the following URL and tried
to inject it with SQLi payload in each parameter until one succeeded.
• Union based SQL injection in order_id parameter POST:
order_id=-116564954 union select 1337,2,3,4,5,6,7,8,9,10,11,12,13,14,15– –
&first_name=aaaa&last_name=sssss&street1=ddddddddddd&street2=ddddddd&city=fffffff&state=ff&postal
_code=12547&country_code=US&phone=45454545457&method=flickr.products.orders.setShippingAddress
&csrf=1365645560%3Acmj2m0s5jvyrpb9%kld65d65d54d54d55d45dsq&api_key=3c7ab2846f4183ecg56s96
d5d5w4e644268&format=json&hermes=1&hermesClient=1&reqId=q3oovqa&nojsoncallback=1
SQL Injection Scenario
SQLi to RCE
• He was able to read sensitive files from the web server
SQL Injection Scenario
SQLi to RCE
• And also write files to the server!
SQL Injection Scenario
SQLi to RCE
• Aaaaand the RCE
SQL Injection Scenario
SQLi to RCE
• After that he got 15K bounty
So how they did it?
Exploiting SQLi
SELECT Name, Description FROM Products WHERE ID='$id‘ and
PASSWORD=‘$password’;
Attacker input: ‘ or ‘a’=‘a #
SELECT Name, Description FROM Products WHERE ID='' OR 'a'='a#‘and
PASSWORD=‘$password’;
SQL Injection Types
• Inband:-
• Error Based Injection
• Blind Injection
• Time Based
• Boolean Based (True/false)
• Out-Of-Band
SQL Injection Types
• Error Based SQLi
SQL Injection Types
• Blind SQLi
Injection Points
• GET Parameters
• POST Parameters
• Headers
• COOKIES
What can be done with SQLi?
• Authentication Bypass
• Read file systems?
• Run system commands?
• Dump all the data?
SQL Injection Scenario
• Yahoo Sport Blind Injection
SQL Injection Prevention
• Prepared Statement Or Parameterized Query
• Stored Procedure
• Input Validation (Blacklisting or whitelisting)
SQL Injection Prevention
• Prepared Statement Or Parameterized Query
SQL Injection Prevention
• Stored Procedure
SQL Injection Prevention
• Input Validation: (Escaping) – PHP
SQL Injection Prevention
• Input Validation: Type Casting
$user_id = (int) $user_id;
Code & Command Injection
• OS Command Injection
• Code Injection
OS Command Injection - Case
OS Command Injection - Vulnerable
OS Command Injection - Protection
Code injection – case
Code Injection - Vulnerable
Code Injection - Protection
Demo – SQLi in request headers
• Perform full scan on the victim
• Finding the injection point
• Exfiltration
• Get the reassure : )
SQLmap
• A tool used to automate SQLi slow
exfiltration and to identify potential SQLi
injection points.
• Ready with a great number of scripts to
be executed
• Could be integrated with other tools such
as Burpsuite, Metasploit
SQLmap Basics
• -u : pass a URL to SQLmap
• --dbs: sort all the databases in the system
• --banner: Grap the database banner
• --threads 7: increase the number of threads in blind injections
• --tables: grap the db tables
• -T table: choose table
• --dump: dump all the data in a table of db
• --level: sets a level from 1 to 5 for the number of injection points (headers
and parameters)
• --risk: sets a level from 1 to 3 for the type of test made
• --batch: run sqlmap defaults
SQLmap Basics
• Basic Scan:
• sqlmap -u http://192.168.203.139 - - batch
• Intense Scan (Not Recommended on production):
• sqlmap -u "http://192.168.203.139" --level 5 --risk 3 --threads 7 --batch

More Related Content

PDF
Securing AEM webapps by hacking them
PDF
Top 10 Web Application vulnerabilities
PPTX
Sql injections - with example
PDF
Sql Injection - Vulnerability and Security
PDF
OWASP Top 10 - 2017
PDF
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
PPTX
Secure Code Warrior - Os command injection
PPT
Introduction to Web Application Penetration Testing
Securing AEM webapps by hacking them
Top 10 Web Application vulnerabilities
Sql injections - with example
Sql Injection - Vulnerability and Security
OWASP Top 10 - 2017
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
Secure Code Warrior - Os command injection
Introduction to Web Application Penetration Testing

What's hot (20)

PPTX
Bug Bounty 101
PPTX
seminar report on Sql injection
PPTX
Sql injection
PPTX
Owasp Top 10 A1: Injection
PDF
OWASP API Security Top 10 Examples
PDF
DNS exfiltration using sqlmap
PPTX
SSRF exploit the trust relationship
PPTX
XSS - Do you know EVERYTHING?
PPTX
Cross Site Scripting: Prevention and Detection(XSS)
PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
ODP
Top 10 Web Security Vulnerabilities
PDF
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
PPTX
Bug Bounty #Defconlucknow2016
PPTX
Ppt on sql injection
PPT
SQL Injection
PPTX
SQL Injections - A Powerpoint Presentation
PDF
sqlmap internals
PPTX
Pentesting ReST API
PDF
Hacking Adobe Experience Manager sites
PPTX
Sql injection - security testing
Bug Bounty 101
seminar report on Sql injection
Sql injection
Owasp Top 10 A1: Injection
OWASP API Security Top 10 Examples
DNS exfiltration using sqlmap
SSRF exploit the trust relationship
XSS - Do you know EVERYTHING?
Cross Site Scripting: Prevention and Detection(XSS)
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
Top 10 Web Security Vulnerabilities
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
Bug Bounty #Defconlucknow2016
Ppt on sql injection
SQL Injection
SQL Injections - A Powerpoint Presentation
sqlmap internals
Pentesting ReST API
Hacking Adobe Experience Manager sites
Sql injection - security testing
Ad

Similar to OWASP Top 10 - Day 1 - A1 injection attacks (20)

PPTX
SANS @Night Talk: SQL Injection Exploited
PPTX
Plant_Ecommerce_Security_Presentation.pptx
PDF
Not so blind SQL Injection
PPTX
Ten Commandments of Secure Coding - OWASP Top Ten Proactive Controls
PPTX
Ten Commandments of Secure Coding
PDF
SAP (in)security: New and best
PDF
SQL Injection Attack Guide for ethical hacking
PDF
Owasp advanced mobile-application-code-review-techniques-v0.2
PDF
Hacking sites for fun and profit
PPTX
The OWASP Zed Attack Proxy
PDF
Ceh v5 module 14 sql injection
PPTX
CSS 17: NYC - Protecting your Web Applications
PPTX
Vulnerabilities in modern web applications
PDF
Css sf azure_8-9-17-protecting_web_apps_stephen coty_al
PDF
CSS17: Houston - Protecting Web Apps
PPTX
Java application security the hard way - a workshop for the serious developer
PPS
Security testing
PPTX
Sql Injection
PPTX
Top 10 Web Application Security Risks - Murat Lostar @ ISACA EUROCACS 2013
PPTX
Spa Secure Coding Guide
SANS @Night Talk: SQL Injection Exploited
Plant_Ecommerce_Security_Presentation.pptx
Not so blind SQL Injection
Ten Commandments of Secure Coding - OWASP Top Ten Proactive Controls
Ten Commandments of Secure Coding
SAP (in)security: New and best
SQL Injection Attack Guide for ethical hacking
Owasp advanced mobile-application-code-review-techniques-v0.2
Hacking sites for fun and profit
The OWASP Zed Attack Proxy
Ceh v5 module 14 sql injection
CSS 17: NYC - Protecting your Web Applications
Vulnerabilities in modern web applications
Css sf azure_8-9-17-protecting_web_apps_stephen coty_al
CSS17: Houston - Protecting Web Apps
Java application security the hard way - a workshop for the serious developer
Security testing
Sql Injection
Top 10 Web Application Security Risks - Murat Lostar @ ISACA EUROCACS 2013
Spa Secure Coding Guide
Ad

Recently uploaded (20)

PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Pre independence Education in Inndia.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Lesson notes of climatology university.
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Computing-Curriculum for Schools in Ghana
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
01-Introduction-to-Information-Management.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
master seminar digital applications in india
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
O5-L3 Freight Transport Ops (International) V1.pdf
Pharma ospi slides which help in ospi learning
Pre independence Education in Inndia.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Lesson notes of climatology university.
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Structure & Organelles in detailed.
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial disease of the cardiovascular and lymphatic systems
Computing-Curriculum for Schools in Ghana
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
VCE English Exam - Section C Student Revision Booklet
01-Introduction-to-Information-Management.pdf
RMMM.pdf make it easy to upload and study
102 student loan defaulters named and shamed – Is someone you know on the list?
master seminar digital applications in india
Renaissance Architecture: A Journey from Faith to Humanism

OWASP Top 10 - Day 1 - A1 injection attacks

  • 1. A1 – Injection Attacks Mohamed Talaat Linkedin: https://www.linkedin.com/in/mtibrahim/ Twitter: https://twitter.com/t4144t E-mail: Mohamed.Talaat@owasp.org
  • 2. Agenda • 1- SQL Injection • Demo • 2- Template Injection • Demo • 3- Broken Authentication • Demo • 4- Session Management • Demo
  • 3. What’s OWASP? • Open Web Application Security Project aims to increase the awareness of the application security. • Everyone is free to participate in OWASP • We are OWASP Egypt – Cairo Chapter
  • 4. OWASP Projects • OWASP Top 10 security vulnerabilities project • OWASP ZAP Project • OWASP Juice Shop • More on the following link: https://www.owasp.org/index.php/Category:OWASP_Project
  • 5. OWASP Top 10 – Application Security Risks
  • 6. How the web app works? • 3 Tiers Model:
  • 8. PHP Code : Logic Tier
  • 10. SQL Queries Types • Static Query • Dymanic Query
  • 11. What is the type of this query? • $dbhostname=‘127.0.0.1'; • $dbuser=‘admin'; • $dbpassword='password'; • $dbname='database'; • $connection = mysqli_connect($dbhostname, $dbuser, $dbpassword, $dbname); $query = "SELECT Name, Description FROM Products WHERE ID='3' UNION SELECT Username, Password FROM Accounts;";
  • 12. What about this? $id = $_GET['id']; $connection = mysqli_connect($dbhostname, $dbuser, $dbpassword, $dbname); $query = "SELECT Name, Description FROM Products WHERE ID='$id';"; $results = mysqli_query($connection, $query); display_results($results);
  • 13. A1 – SQL Injection • The first checked by hackers • Once found, ready to be exploited : )
  • 14. Injection • What is the SQL & Types • Concept • Injection Issue • Attack • CRUD
  • 15. Injection Concept • Identify injection point • Finding the best technique to attack • Data Exfiltration
  • 16. SQLi Real World Scenarios
  • 17. SQL Injection Scenario Yahoo! Sports blind injection • Stefano entered Yahoo! Web site with the following URL: http://sports.yahoo.com/nfl/draft?year=2010&type=20&round=2 • He tried to put a comment after the year 2010 and noticed what happen • So it will be like this: http://sports.yahoo.com/nfl/draft?year=2010--&type=20&round=2
  • 18. SQL Injection Scenario Yahoo! Sports blind injection • Original Query: SELECT * FROM PLAYERS WHERE YEAR = 2010 AND TYPE = 20 AND ROUND = 2; • By inserting the dashes, Stefano essentially made it act like: SELECT * FROM PLAYERS WHERE YEAR = 2010;
  • 19. SQL Injection Scenario Yahoo! Sports blind injection • Yahoo Sport Blind Injection – Before commenting
  • 20. SQL Injection Scenario Yahoo! Sports blind injection • Yahoo Sport Blind Injection – After commenting
  • 21. SQL Injection Scenario SQLi to RCE • Ibrahim Raafat (Egyptian Researcher) could exploit a SQLi vulnerability to have full control on the server. • He was doing purchase when he noticed the following URL and tried to inject it with SQLi payload in each parameter until one succeeded. • Union based SQL injection in order_id parameter POST: order_id=-116564954 union select 1337,2,3,4,5,6,7,8,9,10,11,12,13,14,15– – &first_name=aaaa&last_name=sssss&street1=ddddddddddd&street2=ddddddd&city=fffffff&state=ff&postal _code=12547&country_code=US&phone=45454545457&method=flickr.products.orders.setShippingAddress &csrf=1365645560%3Acmj2m0s5jvyrpb9%kld65d65d54d54d55d45dsq&api_key=3c7ab2846f4183ecg56s96 d5d5w4e644268&format=json&hermes=1&hermesClient=1&reqId=q3oovqa&nojsoncallback=1
  • 22. SQL Injection Scenario SQLi to RCE • He was able to read sensitive files from the web server
  • 23. SQL Injection Scenario SQLi to RCE • And also write files to the server!
  • 24. SQL Injection Scenario SQLi to RCE • Aaaaand the RCE
  • 25. SQL Injection Scenario SQLi to RCE • After that he got 15K bounty
  • 26. So how they did it?
  • 27. Exploiting SQLi SELECT Name, Description FROM Products WHERE ID='$id‘ and PASSWORD=‘$password’; Attacker input: ‘ or ‘a’=‘a # SELECT Name, Description FROM Products WHERE ID='' OR 'a'='a#‘and PASSWORD=‘$password’;
  • 28. SQL Injection Types • Inband:- • Error Based Injection • Blind Injection • Time Based • Boolean Based (True/false) • Out-Of-Band
  • 29. SQL Injection Types • Error Based SQLi
  • 31. Injection Points • GET Parameters • POST Parameters • Headers • COOKIES
  • 32. What can be done with SQLi? • Authentication Bypass • Read file systems? • Run system commands? • Dump all the data?
  • 33. SQL Injection Scenario • Yahoo Sport Blind Injection
  • 34. SQL Injection Prevention • Prepared Statement Or Parameterized Query • Stored Procedure • Input Validation (Blacklisting or whitelisting)
  • 35. SQL Injection Prevention • Prepared Statement Or Parameterized Query
  • 36. SQL Injection Prevention • Stored Procedure
  • 37. SQL Injection Prevention • Input Validation: (Escaping) – PHP
  • 38. SQL Injection Prevention • Input Validation: Type Casting $user_id = (int) $user_id;
  • 39. Code & Command Injection • OS Command Injection • Code Injection
  • 41. OS Command Injection - Vulnerable
  • 42. OS Command Injection - Protection
  • 44. Code Injection - Vulnerable
  • 45. Code Injection - Protection
  • 46. Demo – SQLi in request headers • Perform full scan on the victim • Finding the injection point • Exfiltration • Get the reassure : )
  • 47. SQLmap • A tool used to automate SQLi slow exfiltration and to identify potential SQLi injection points. • Ready with a great number of scripts to be executed • Could be integrated with other tools such as Burpsuite, Metasploit
  • 48. SQLmap Basics • -u : pass a URL to SQLmap • --dbs: sort all the databases in the system • --banner: Grap the database banner • --threads 7: increase the number of threads in blind injections • --tables: grap the db tables • -T table: choose table • --dump: dump all the data in a table of db • --level: sets a level from 1 to 5 for the number of injection points (headers and parameters) • --risk: sets a level from 1 to 3 for the type of test made • --batch: run sqlmap defaults
  • 49. SQLmap Basics • Basic Scan: • sqlmap -u http://192.168.203.139 - - batch • Intense Scan (Not Recommended on production): • sqlmap -u "http://192.168.203.139" --level 5 --risk 3 --threads 7 --batch

Editor's Notes

  • #7: Presentation Tier: View to the user Translates the user requests to HTTP request – sends it to the logic tier Rendering HTML Code to graphical view Logic Tier: Web server which stores the code of the app Middleware which makes the processing tasks Loads, compiles, executes scripts Translates the HTTP request to Database query and sends it to the storage tier Storage: Execute database query Then the logic tier pulls the result back, formats it, sends it back to the presentation tier
  • #15: The injection issue is the lack of the sanitization for user input (Much confidence) The attack leverages from the ability of an attacker to inject a malicious SQL/ database queries to the logic tier in order to execute it at the database and returns the result to the attacker. CRUD: Create, Read, Update, Delete