Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Security SQL Injection, XSS, CSRF, Parameter Tampering, DoS Attacks, Session Hijacking SoftUni Team Technical Trainers Software University

Similar presentations


Presentation on theme: "Web Security SQL Injection, XSS, CSRF, Parameter Tampering, DoS Attacks, Session Hijacking SoftUni Team Technical Trainers Software University"— Presentation transcript:

1 Web Security SQL Injection, XSS, CSRF, Parameter Tampering, DoS Attacks, Session Hijacking SoftUni Team Technical Trainers Software University http://softuni.bg

2 Table of Contents 1.Web Security Main Concepts 2.SQL Injection 3.Cross-Site Scripting (XSS) 4.Cross-Site Request Forgery (CSRF/XSRF) 5.Parameter Tempering 6.Session Hijacking 7.DoS/DDoS Attacks 2

3 Web Security Main Concepts

4 4  Is Software Security a Feature?  Most people consider software security as a necessary feature of a product  Is Security Vulnerability a Bug?  If the software "failed" and allowed a hacker to see personal info, most users would consider that a software bug Feature or Bug

5 Reasons for Failures  Software failures usually happen spontaneously  Without intentional mischief  Failures can be result of malicious attacks  For the Challenge/Prestige  Curiosity driven  Aiming to use resources  Vandalizing  Stealing 5

6 6  Maximum Simplicity  More complicated – greater chance for mistakes  Secure the Weakest Link  Hackers attack where the weakest link is  Limit the Publicly Available Resources  Incorrect Until Proven Correct  Consider each user input as incorrect  The Principle of the "Weakest Privilege"  Security in Errors (Remain stable)  Provide Constant Defense (also use backups) Golden Rules!

7 SQL Injection What is SQL Injection and How to Prevent It?

8 8  Try the following queries:  '  crashes  ' or ''='  Login with any user  '; INSERT INTO Messages(MessageText, MessageDate) VALUES ('Hacked!!!', '1.1.1980')--  injects a message What is SQL Injection? $loginQuery = "SELECT * FROM users WHERE username='{$_POST['user']}' AND WHERE username='{$_POST['user']}' AND password='{$_POST['pass']}'"; password='{$_POST['pass']}'"; $result = mysql_query($loginQuery);

9 9  The following SQL commands are executed:  Usual search (no SQL injection):  SQL-injected search (matches all records):  SQL-injected INSERT command: How Does SQL Injection Work? SELECT * FROM Messages WHERE MessageText LIKE '%nakov%'" SELECT * FROM Messages WHERE MessageText LIKE '%%'" SELECT * FROM Messages WHERE MessageText LIKE '%'; INSERT INTO Messages(MessageText, MessageDate) VALUES ('Hacked!!!', '1.1.1980') --%'" SELECT * FROM Messages WHERE MessageText LIKE '%' or 1=1 --%'"

10 10  Original SQL Query:  Setting username to John & password to ' OR '1'= '1 produces  Result: If a user Admin exists – he is logged in without password Another SQL Injection Example String sqlQuery = SELECT * FROM user WHERE name = 'Admin' AND pass='' OR '1'='1' String sqlQuery = "SELECT * FROM user WHERE name = '" + username + "' AND pass='" + password + "'"

11 11  Ways to prevent the SQL injection:  SQL-escape all data coming from the user:  Not recommended: use as last resort only!  Preferred approach:  Use ORM  Use parameterized queries Preventing SQL Injection

12 SQL Injection and Prevention Live Demo

13 Cross Site Scripting (XSS) What is XSS and How to Prevent It? …

14 14  Cross-Site Scripting ( XSS ) is a common security vulnerability in Web applications  Web application is let to display a JavaScript code that is executed at the client's browser  Crackers could take control over sessions, cookies, passwords, and other private data  How to prevent from XSS?  Validate the user input (built-in in ASP.NET)  Perform HTML escaping when displaying text data in a Web control XSS Attack

15 XSS  Cross-site scripting attack  Cookie theft  Account hijacking  Modify content  Modify user settings  Download malware  Submit CRSF attack  Password prompt 15 Submits script on an unsafe form Execute the script on visiting the page

16 16  HTML escaping is the act of replacing special characters with their HTML entities  Escaped characters are interpreted as character data instead of mark up  Typical characters to escape  – start / end of HTML tag  & – start of character entity reference  ', " – text in single / double quotes  … What is HTML Escaping?

17 17  Each character could be presented as HTML entity escaping sequence  Numeric character references:  ' λ ' is λ, &#x03BB ; or &#X03bb ;  Named HTML entities:  ' λ ' is λ  ' < ' is <  ' > ' is >  ' & ' is &  " (double quote) is " HTML Character Escaping

18 18  HTML encodes a string and returns the encoded (html-safe) string Example (in PHP): HTML Output: Web browser renders the following: How to Encode HTML Entities? echo htmlentities("The image tag: "); The image tag: <img> The image tag: The image tag: echo htmlspecialchars("The image tag: ");

19 HTML Escaping Live Demo

20 Cross-Site Request Forgery What is CSRF and How to Prevent It?

21 21  Cross-Site Request Forgery (CSRF / XSRF) is a web security attack over the HTTP protocol  Allows executing unauthorized commands on behalf of some authenticated user  E.g. to transfer some money in a bank system  The user has valid permissions to execute the requested command  The attacker uses these permissions to send a forged HTTP request unbeknownst to the user  Through a link / site / web form that the user is allured to open What is CSRF?

22 22  How does CSRF work? 1. The user has a valid authentication cookie for the site victim.org (remembered in the browser) 2. The attacker asks the user to visit some evil site, e.g. http://evilsite.comhttp://evilsite.com 3. The evil site sends HTTP GET / POST to victim.org and does something evil  Through a JavaScript AJAX request  Using the browser's authentication cookie 4. The victim.org performs the unauthorized command on behalf of the authenticated user CSRF Explained

23 23  Cross-site request forgery attack CSRF Evil.com MySite.com User Login Authentication cookie Submit data on behalf of User

24 Cross-Site Request Forgery Live Demo

25 25  To prevent CSRF attacks in PHP apps use random generated tokens  Put hidden field with random generated token in the HTML forms:  Verify anti-CSRF token in each controller action that should be protected: Prevent CSRF in PHP </form> if (!isset($_POST['formToken']) || $_POST['formToken'] != $_SESSION['formToken']) { throw new Exception('Invalid request!'); throw new Exception('Invalid request!'); exit; } exit; } $_SESSION['formToken'] = uniqid(mt_rand(), true);

26 Anti-CSRF in MVC Apps Live Demo

27 Parameter Tampering What is Parameter Tampering and How to Prevent It?

28 What is Parameter Tampering?  What is Parameter Tampering?  Malicious user alters the HTTP request parameters in unexpected way  Altered query string (in GET requests)  Altered request body (form fields in POST requests)  Altered cookies (e.g. authentication cookie)  Skipped data validation at the client-side  Injected parameter in MVC apps 28

29 Parameter Tampering Live Demo

30 Session Hijacking

31 1.Capture a valid token session using a sniffer 2.Use the valid session token to gain unauthorized access to the server  Always use SSL when sending sensitive data!  You should use Man in the Middle attack to sniff the session token Session Hijacking

32 DoS (DDoS) Attacks What is Denial-of-Service attack? 32

33 33  Semantic URL attacks  URL Manipulation  Man in the Middle (MiTM)  Brute force (use CAPTCHA!)  Insufficient Access Control  Error messages can reveal information  Phishing  Security flows in other software you are using  Social Engineering Other Threats

34 ? ? ? ? ? ? ? ? ? Web Security https://softuni.bg/courses/web-development-basics/

35 License  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International 35

36 Free Trainings @ Software University  Software University Foundation – softuni.orgsoftuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg softuni.bg  Software University @ Facebook  facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity  Software University @ YouTube  youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bgforum.softuni.bg


Download ppt "Web Security SQL Injection, XSS, CSRF, Parameter Tampering, DoS Attacks, Session Hijacking SoftUni Team Technical Trainers Software University"

Similar presentations


Ads by Google