53
Hacker, you shall not pass! Web application secure development Cláudio André | claudioandre (at) gmail.com | @clviper

Hacker, you shall not pass!

Embed Size (px)

Citation preview

Page 1: Hacker, you shall not pass!

Hacker, you shall not pass!Web application secure development

Cláudio André | claudioandre (at) gmail.com | @clviper

Page 2: Hacker, you shall not pass!

whoami

● 10+ years working in Information Systems

● Penetration Tester @

● Web applications, Mobile applications and Infrastructure

● Blog: security.claudio.pt

Page 3: Hacker, you shall not pass!
Page 4: Hacker, you shall not pass!

SPECIALLY T

Page 5: Hacker, you shall not pass!

SQL Injection

● SQL query manipulation via input data from

client;

https://www.owasp.org/index.php/SQL_Injection

Page 6: Hacker, you shall not pass!

SQL Injection

● SQL query manipulation via input data from

client;

● String concatenation;

https://www.owasp.org/index.php/SQL_Injection

Page 7: Hacker, you shall not pass!

SQL Injection

select name from users where user = ‘admin’

and password = ‘ubberpa$$w0rd’

https://www.owasp.org/index.php/SQL_Injection

Page 8: Hacker, you shall not pass!

SQL Injection

select name from users where user = ‘admin’

and password = ‘ubberpa$$w0rd’

select name from users where user = ‘admin’

and password = ‘xpto’ or 1=1--’

https://www.owasp.org/index.php/SQL_Injection

Page 9: Hacker, you shall not pass!

SQL Injection Demo

Page 10: Hacker, you shall not pass!

Fixing SQL Injection

● Use of prepared statements (Parameterized

Queries)

https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet

Page 11: Hacker, you shall not pass!

Fixing SQL Injection

● Use of prepared statements (Parameterized

Queries)

https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet

Page 12: Hacker, you shall not pass!

Cross Site Scripting (XSS)

● Injection of malicious scripts via input data

from the client;

https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29

Page 13: Hacker, you shall not pass!

Cross Site Scripting (XSS)

● Injection of malicious scripts via input data

from the client;

● Script reflection on the page;

https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29

Page 14: Hacker, you shall not pass!

Cross Site Scripting (XSS)

● Injection of malicious scripts via input data

from the client;

● Script reflection on the page;

● Reflected, Stored and DOM based;

https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29

Page 15: Hacker, you shall not pass!

Cross Site Scripting (XSS)

Request: http://vulnerablesite.local/index?name=Guest

Response:

<html>

<body>

<div>

Hello Guest

</div>

</body>

</html>

https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29

Page 16: Hacker, you shall not pass!

Cross Site Scripting (XSS)

Request: http://vulnerablesite.local/index?name=<script>alert(“xss”)</script>

Response:

<html>

<body>

<div>

Hello <script>alert(“xss”)</script>

</div>

</body>

</html>

https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29

Page 17: Hacker, you shall not pass!

Cross Site Scripting (XSS)

Request: http://vulnerablesite.local/index?name=<script>alert(“xss”)</script>

Response:

<html>

<body>

<div>

Hello <script>alert(“xss”)</script>

</div>

</body>

</html>

https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29

Page 18: Hacker, you shall not pass!

Cross Site Scripting (XSS) Demo

Page 19: Hacker, you shall not pass!

Fixing XSS

● Not straightforward;

● Start with HTML Escape and Attribute

Escape.

https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet

Page 20: Hacker, you shall not pass!

Cross Site Request Forgery (CSRF)

● Force user to execute unwanted actions on

a web application;

https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28

Page 21: Hacker, you shall not pass!

Cross Site Request Forgery (CSRF)

● Force user to execute unwanted actions on

a web application;

● Session Riding;

https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28

Page 22: Hacker, you shall not pass!

Cross Site Request Forgery (CSRF)

● Force user to execute unwanted actions on

a web application;

● Session Riding;

● Phishing Attacks

https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28

Page 23: Hacker, you shall not pass!

Cross Site Request Forgery (CSRF)

Request:

http://vulnerablesite.local/changepassword?newpwd=MyS3cr3tPa$$word

https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28

Page 24: Hacker, you shall not pass!

Cross Site Request Forgery (CSRF)

Request:

http://vulnerablesite.local/changepassword?newpwd=MyS3cr3tPa$$word

Attack:

<img src=”http://vulnerablesite.local/changepassword?newpwd=owned”>

https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28

Page 25: Hacker, you shall not pass!

Cross Site Request Forgery (CSRF) Demo

Page 26: Hacker, you shall not pass!

Fixing CSRF

● Synchronizer Token Pattern

https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet

Page 27: Hacker, you shall not pass!

Fixing CSRF

● Synchronizer Token Pattern

https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet

Page 28: Hacker, you shall not pass!

Triple A

● Authentication

● Authorization

● Access Control

Page 29: Hacker, you shall not pass!

Some best practices on Authentication

● NO PLAIN TEXT!!! Use of strong

cryptographic algorithms;

https://www.owasp.org/index.php/Authentication_Cheat_Sheet

Page 30: Hacker, you shall not pass!

Some best practices on Authentication

● NO PLAIN TEXT!!! Use of strong

cryptographic algorithms;

● No limit for character set and max lengths;

https://www.owasp.org/index.php/Authentication_Cheat_Sheet

Page 31: Hacker, you shall not pass!

Some best practices on Authentication

● NO PLAIN TEXT!!! Use of strong

cryptographic algorithms;

● No limit for character set and max lengths;

● Enforce strong password policy;

https://www.owasp.org/index.php/Authentication_Cheat_Sheet

Page 32: Hacker, you shall not pass!

Some best practices on Authentication

● Prevent Brute-Force Attacks. Implement

Captcha.

https://www.owasp.org/index.php/Authentication_Cheat_Sheet

Page 33: Hacker, you shall not pass!

Some best practices on Authentication

● Prevent Brute-Force Attacks. Implement

Captcha.

● Normalize error messages;

https://www.owasp.org/index.php/Authentication_Cheat_Sheet

Page 34: Hacker, you shall not pass!

Access Control

● Vertical Access Control Attack

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Page 35: Hacker, you shall not pass!

Access Control

● Vertical Access Control Attack

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Request: http://vulnerablesite.local/mainPage

Page 36: Hacker, you shall not pass!

Access Control

● Vertical Access Control Attack

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Request: http://vulnerablesite.local/mainPage

Request: http://vulnerablesite.local/adminPage

Page 37: Hacker, you shall not pass!

Access Control

● Horizontal Access Control Attack

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Page 38: Hacker, you shall not pass!

Access Control

● Horizontal Access Control Attack

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Request: http://vulnerablesite.local/getUserProfile?id=1337

Page 39: Hacker, you shall not pass!

Access Control

● Horizontal Access Control Attack

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Request: http://vulnerablesite.local/getUserProfile?id=1337

Request: http://vulnerablesite.local/getUserProfile?id=1338

Page 40: Hacker, you shall not pass!

Access Control

● Business Logic Access Control Attack

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Page 41: Hacker, you shall not pass!

Access Control

● Business Logic Access Control Attack

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

http://vulnerablesite.local/shop?action=chooseFormat

http://vulnerablesite.local/shop?action=makePayment

http://vulnerablesite.local/shop?action=downloadMovie

Page 42: Hacker, you shall not pass!

Some best practices on Access Control

● Implement roles and permissions

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Page 43: Hacker, you shall not pass!

Some best practices on Access Control

● Implement roles and permissions

● Perform authorization validation on all

pages.

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Page 44: Hacker, you shall not pass!

Some best practices on Access Control

● Implement roles and permissions

● Perform authorization validation on all

pages.

● Data-Context access controls

https://www.owasp.org/index.php/Access_Control_Cheat_Sheet

Page 45: Hacker, you shall not pass!

Open Web Application Security Project (OWASP)

● Not-for-profit charitable organization focused

on improving the security of software;

Page 46: Hacker, you shall not pass!

Open Web Application Security Project (OWASP)

● Not-for-profit charitable organization focused

on improving the security of software;

● Best practices;

Page 47: Hacker, you shall not pass!

Open Web Application Security Project (OWASP)

● Not-for-profit charitable organization focused

on improving the security of software;

● Best practices;

● OWASP Top 10;

Page 48: Hacker, you shall not pass!

OWASP TOP 10

https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project

Page 49: Hacker, you shall not pass!

OWASP Vulnerable Web Applications Directory

● Vulnerable web applications for web dev,

security auditors and pentesters.

● Offline, Online, Virtual Machines and ISOs.

https://www.owasp.org/index.php/OWASP_Vulnerable_Web_Applications_Directory_Project#tab=Main

Page 50: Hacker, you shall not pass!

Portswigger Burp Suite

● Integrated platform for web application

security tests.

Page 51: Hacker, you shall not pass!

Portswigger Burp Suite

● Integrated platform for web application

security tests.

● Has free version and is cross platform.

Page 52: Hacker, you shall not pass!

Portswigger Burp Suite

● Integrated platform for web application

security tests.

● Has free version and is cross platform.

● Not only for infosec guys. Devs should use

it.

Page 53: Hacker, you shall not pass!