|
| 1 | +# OWASP Top 10 - Wellington Meetup 2016/11/29 |
| 2 | + |
| 3 | +Notes from the Wellington meetup on November 29th 2016, discussing the OWASP Top 10 Edition 2013 (2017 is in draft at the time of writing). |
| 4 | + |
| 5 | +Check the [OWASP Top 10 Cheat Sheet](https://www.owasp.org/index.php/OWASP_Top_Ten_Cheat_Sheet) online for the latest version. |
| 6 | + |
| 7 | +Check the [DVWA](dvwa.org.nz) (Damn Vulnerable Web Application) which is specifically designed to teach vulnerabilities. |
| 8 | + |
| 9 | +## A1 - Injections |
| 10 | + |
| 11 | +Vulnerabilities: |
| 12 | + |
| 13 | +- Full Read/Write access to the DB. |
| 14 | +- Escalation of privileges. |
| 15 | + |
| 16 | +Prevention: |
| 17 | + |
| 18 | +- Use parameterises queries |
| 19 | +- Use your ORM |
| 20 | + |
| 21 | +Verify: |
| 22 | + |
| 23 | +- Put a `'` in your input fields. If it breaks, you're vulnerable. |
| 24 | +- Use [sqlmap](http://sqlmap.org/), an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of database servers. |
| 25 | + |
| 26 | +## A2 - Weak authentication and session management |
| 27 | + |
| 28 | +HTTP is stateless so we use cookies to remember who someone is. |
| 29 | + |
| 30 | +Vulnerabilities: |
| 31 | + |
| 32 | +- Credentials could be stored insecurely on the server. |
| 33 | +- Cookies can be guessed or stolen (control of session, logging in as another user) |
| 34 | +- General logic might be flawed. |
| 35 | + |
| 36 | +## A3 - XSS (Cross Site Scripting) |
| 37 | + |
| 38 | +Mixing untrusted data within a webpage. If an attacker can add its own script to a page, he can alter the way it behaves. |
| 39 | + |
| 40 | +Vulnerabilities: |
| 41 | + |
| 42 | +- Runs JS on the user's browser |
| 43 | +- Proxy commands through their computer |
| 44 | +- Trick them into performing an action |
| 45 | +- Redirect to phishing or malware |
| 46 | + |
| 47 | +Where: |
| 48 | + |
| 49 | +- HTML, when displaying user input on the page |
| 50 | + - Form input |
| 51 | + - URI parameters |
| 52 | +- CSS, when allowing a user to set custom colours |
| 53 | +- JS, when loading data |
| 54 | +- HTML attributes, escaping function aren't the same for single or double quotes (i.e. your escaping function should match what your front-end use) |
| 55 | + |
| 56 | +Prevention: |
| 57 | + |
| 58 | +- Don't display user input if possible, otherwise: |
| 59 | + - Whitelist during input validation |
| 60 | + - Output encode all user supplied data. |
| 61 | +- See [OWASP XSS Prevention Check Sheet](www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet) |
| 62 | +- Set the right [CSP](https://content-security-policy.com/) (Content Security Policy) headers |
| 63 | + |
| 64 | +Verify: |
| 65 | + |
| 66 | +- Put a `<` in your input fields or url params which are later displayed. If it is shown unescaped, you are vulnerable. |
| 67 | +- Use [BeEF](http://beefproject.com/), a browser exploitation framework project. |
| 68 | + |
| 69 | +## A4 - Insecure Direct Object References |
| 70 | + |
| 71 | +Vulnerabilities: |
| 72 | + |
| 73 | +- Accessing objects you're not supposed to by modifying the URI attributes. |
| 74 | + |
| 75 | +Prevention: |
| 76 | + |
| 77 | +- Whitelist rather than blacklist. It's easier to maintain. |
| 78 | +- Don't trust user input |
| 79 | +- Verify permissions |
| 80 | +- Consider mapping database IDs to a temporaty ID per user (see ESAPI) |
| 81 | + |
| 82 | +## A5 - Security Misconfiguration |
| 83 | + |
| 84 | +Software, server platform out of date or misconfigured. |
| 85 | + |
| 86 | +## A6 - Sensitive Data Exposure |
| 87 | + |
| 88 | +Missing encryption allows man in the middle attack. |
| 89 | + |
| 90 | +Prevention: |
| 91 | + |
| 92 | +- Use HTTPS |
| 93 | +- Use [HSTS](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security) |
| 94 | + - a web security policy mechanism which helps to protect websites against protocol downgrade attacks and cookie hijacking; it allows web servers to declare that web browsers (or other complying user agents) should only interact with it using secure HTTPS connections,[1] and never via the insecure HTTP protocol |
| 95 | +- Use [key pinning](https://en.wikipedia.org/wiki/HTTP_Public_Key_Pinning) |
| 96 | + - a security mechanism which allows HTTPS websites to resist impersonation by attackers using mis-issued or otherwise fraudulent certificates. |
| 97 | +- Only collect what you need |
| 98 | +- Use standard strong algorithm |
| 99 | +- Generate, distribute and protect keys properly |
| 100 | + |
| 101 | +## A7 - Missing Function Level Access Control |
| 102 | + |
| 103 | +Failing to perform access checks on both client and server |
| 104 | + |
| 105 | +Prevention: |
| 106 | +- Do authorisation checks on `GET` and `POST` |
| 107 | +- Block functions from certain users |
| 108 | +- Users, role or claims-based permission. |
| 109 | +- Whitelist rather than blacklist. |
| 110 | + |
| 111 | +## A8 - Cross Site Request Forgery |
| 112 | + |
| 113 | +Forcing a user's browser to make a request. |
| 114 | + |
| 115 | +User access bad website which makes a request to target website and all credentials are passed through with the request |
| 116 | + |
| 117 | +Prevention: |
| 118 | + |
| 119 | +- Don't change data on `GET`, it should be idempotent |
| 120 | +- CSRF works when the attacker knows everything |
| 121 | + - Include something unknown in the form like a CSRF token |
| 122 | + |
| 123 | +## A9 - Using Components with Known Vulnerabilities |
| 124 | + |
| 125 | +Out of date components |
| 126 | + |
| 127 | +Prevention: |
| 128 | + |
| 129 | +- Keep components up to date |
| 130 | +- Catalogue components you depend on |
| 131 | +- Follow security bulletins |
| 132 | + |
| 133 | +Verify: |
| 134 | +- [Retire.js](http://requirejs.org/) or [david](https://david-dm.org/) for JavaScript |
| 135 | +- Use `pip list --outdated` for Python |
| 136 | + |
| 137 | +## 10 - Unvalidated Redirects and Forwards |
| 138 | + |
| 139 | +Redirecting the browser to an unsafe url; typically, when using a `nextUrl` on a login page. |
| 140 | + |
| 141 | +Prevention: |
| 142 | + |
| 143 | +- Have a whitelist of what it is allowed to redirect to |
| 144 | +- Have regular expression to only allow internal urls |
| 145 | + |
| 146 | +# Frameworks |
| 147 | + |
| 148 | +Frameworks are a great way to migitate those risks as most of those issues have been resolved already. |
| 149 | + |
| 150 | +## How to choose a framework? |
| 151 | + |
| 152 | +- Choose a well known and well maintained (no abandonware) framework (it was originally phrased "something new" but we disagree with that) |
| 153 | +- Familiarise yourself with built-in protection |
| 154 | +- Build common code that new dev will leverage |
| 155 | + |
| 156 | +See [OWASP Framework Security Matrix](https://www.owasp.org/index.php/Category:Framework_Security_Matrix) (still WIP) to check what each framework protects you against. |
| 157 | + |
| 158 | +# Q&A |
| 159 | + |
| 160 | + |
| 161 | +## Is there a way to scan your application? |
| 162 | + |
| 163 | +There are some code scanners (like [Fortify](https://en.wikipedia.org/wiki/Fortify_Software)) but those solutions are usually expensive. |
| 164 | + |
| 165 | +Linters normally catch stylistic issues but might catch basic security issues as well. |
| 166 | + |
| 167 | +Use the [OWASP Zed Attack Proxy](https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project) to pentest your app. |
| 168 | + |
| 169 | +## User Input |
| 170 | + |
| 171 | +It is well known that you should trust user input and sanitise it. |
| 172 | + |
| 173 | +However, user input should be handled carefully even when it comes from your database. You might think that because it comes from the database it is safe, but you can never be too sure of how it was saved. |
| 174 | + |
| 175 | +## Browsers |
| 176 | + |
| 177 | +Vendors play their parts: |
| 178 | + |
| 179 | +- Key pinning was actually introduced by browsers. |
| 180 | +- The browser will block script that appears in the url and in the page. |
| 181 | +- From January 2017, Chrome will [flag non HTTPS pages with password or credit-card fields as non-secure](https://security.googleblog.com/2016/09/moving-towards-more-secure-web.html). |
0 commit comments