Presentation is loading. Please wait.

Presentation is loading. Please wait.

Securing MVC.NET Web Applications Andrew Wilson. 오 안녕하세요 !!!! Senior Software Consultant Obsessed security guy OWASP co-lead Long walks on the beach desert.

Similar presentations


Presentation on theme: "Securing MVC.NET Web Applications Andrew Wilson. 오 안녕하세요 !!!! Senior Software Consultant Obsessed security guy OWASP co-lead Long walks on the beach desert."— Presentation transcript:

1 Securing MVC.NET Web Applications Andrew Wilson

2 오 안녕하세요 !!!! Senior Software Consultant Obsessed security guy OWASP co-lead Long walks on the beach desert Drinking IPA in the rain

3 Overview Microsoft SDL Introduction to OWASP – OWASP Projects – Top 10 Security problems Microsoft Framework Security Components Summary Further Reading

4 Brief Rant Lists are generic, your problems aren’t Narrows the field of vision Simple face on a complex problem Top 10 gets you started in the right direction Secure development processes gets you the rest the way

5 Brief Review of SDL Defined security process from MS History lesson of what worked and didn’t Low cost of entry (free) You need a Secure Development Lifecycle It might be too big for your needs

6 Tools WebScarab is free, and hence awesome Burp Suite is free, and also awesome Burp Suite Pro is not free, but it’s the most awesomest of them all.

7 Introduction to OWASP Focused on improving security of applications OWASP Projects Include: – Developer & Tester Guides – SAMM (Software Assurance Maturity Model) OWASP Tools – WebScarab, Live CD, WebGoat, ESAPI

8 OWASP Top 10

9 Injection Attacks Tricking an application into including unintended commands in the data sent to an interpreter Injection means… Take strings and interpret them as commands SQL, OS Shell, LDAP, XPath, Hibernate, etc… Interpreters… Many applications still susceptible (really don’t know why) Even though it’s usually very simple to avoid SQL injection is still quite common Usually severe. Entire database can usually be read or modified May also allow full database schema, or account access, or even OS level access Typical Impact

10 Injection Attacks Illustrated Firewall Hardened OS Web Server App Server Firewall Databases Legacy Systems Web Services Directories Human Resrcs Billing Custom Code APPLICATION ATTACK Network Layer Application Layer Accounts Finance Administration Transactions Communication Knowledge Mgmt E-Commerce Bus. Functions HTTP request  SQL query  DB Table   HTTP response   "SELECT * FROM accounts WHERE acct=‘’ OR 1=1-- ’" Account Summary Acct:5424-6066-2134-4334 Acct:4128-7574-3921-0192 Acct:5424-9383-2039-4029 Acct:4128-0004-1234-0293 Account: SKU: Account: SKU: 1. Application presents a form to the attacker 2. Attacker sends an attack in the form data 3. Application forwards attack to the database in a SQL query 4. Database runs query containing attack and sends encrypted results back to application 5. Application decrypts data as normal and sends results to the user

11 Pop Quiz! Q: Is.NET a compiled language or is it an interpreted one? A: Yes!

12 Injection Defense This is the single hardest problem in web security. Data. Common Approaches include: – White Listing – Black Listing – Encoding Once you identify something is wrong… What do you do next?

13 Injection Vectors Html input data Javascript itself Reflection attacks are injection based (because they attack the reflection / interrupter) XML attacks against web services JIT attacks (what the world?) LDAP & SQL

14 MS-AntiXSS Encoding MethodShould Be Used If …Example/Pattern HtmlEncode Untrusted input is used in HTML output except when assigning to an HTML attribute. Click Here [Untrusted input] HtmlAttributeEncode Untrusted input is used as an HTML attribute JavaScriptEncode Untrusted input is used within a JavaScript context … [Untrusted input] … UrlEncode Untrusted input is used in a URL (such as a value in a querystring) Click Here! VisualBasicScriptEncode Untrusted input is used within a Visual Basic Script context … [Untrusted input] … XmlEncode Untrusted input is used in XML output, except when assigning to an XML attribute [Untrusted input] XmlAttributeEncode Untrusted input is used as an XML attribute Some Text

15 XSS Attacks Raw data from attacker is sent to an innocent user’s browser Occurs any time… Stored in database Reflected from web input (form field, hidden field, URL, etc…) Sent directly into rich JavaScript client Raw data… Try this in your browser – javascript:alert(document.cookie) Virtually every web application has this problem Steal user’s session, steal sensitive data, rewrite web page, redirect user to phishing or malware site Most Severe: Install XSS proxy which allows attacker to observe and direct all user’s behavior on vulnerable site and force user to other sites Typical Impact

16 XSS Illustrated Application with stored XSS vulnerability 3 2 Attacker enters a malicious script into a web page that stores the data on the server Victim views page – sees attacker profile Script silently sends attacker Victim’s session cookie Script runs inside victim’s browser with full access to the DOM and cookies Custom Code Accounts Finance Administration Transactions Communication Knowledge Mgmt E-Commerce Bus. Functions Attacker sets the trap – update my profile 1

17 Defense Encoding your variables Built in XSS defensive bits in MVC.net Anti-XSS library What are the attack vectors? – Cookies – Url – Querystring – Post Variables – HTTP Request Headers – JSON / XML payloads

18 Broken Auth & Session Management Means credentials have to go with every request Should use SSL for everything requiring authentication HTTP is a “stateless” protocol SESSION ID used to track state since HTTP doesn’t and it is just as good as credentials to an attacker SESSION ID is typically exposed on the network, in browser, in logs, … Session management flaws Change my password, remember my password, forgot my password, secret question, logout, email address, etc… Beware the side-doors User accounts compromised or user sessions hijacked Typical Impact

19 Broken Auth Illustrated Custom Code Accounts Finance Administration Transactions Communication Knowledge Mgmt E-Commerce Bus. Functions 1 User sends credentials 2 Site uses URL rewriting (i.e., put session in URL) 3 User clicks on a link to http://www.hacker.com in a forumhttp://www.hacker.com www.boi.com?JSESSIONID=9FA1DB9EA... 4 Hacker checks referer logs on www.hacker.comwww.hacker.com and finds user’s JSESSIONID Hacker uses JSESSIONID and takes over victim’s account

20 Defense (Bad news) ASP.NET has no built in countermeasures RegenerateExpiredSessionId doesn’t work the way you’d expect MS has no plans to fix this (yet)

21 Defense Set your web.config to not allow sessions to be stored for cookieless browsers. Set your sessions data ONLY in secure pages Password reset is mostly a logical bug Be wary of relationships that can be faked Regenerate Login once logged in Don’t leak the sessionId (if possible)

22 Insecure Direct Object Reference This is part of enforcing proper “Authorization”, along with A7 – Failure to Restrict URL Access How do you protect access to your data? Only listing the ‘authorized’ objects for the current user, or Hiding the object references in hidden fields … and then not enforcing these restrictions on the server side This is called presentation layer access control, and doesn’t work Attacker simply tampers with parameter value A common mistake … Users are able to access unauthorized files or data Typical Impact

23 Direct Object Reference Illustrated https://www.onlinebank.com/user?acct=6065 Attacker notices his acct parameter is 6065 ?acct=6065 He modifies it to a nearby number ?acct=6066 Attacker views the victim’s account information

24 Defense Rutroh! This is how MVC is structured! Don’t bind to ID’s that can be enumerated? Accept it as loss? Rewrite the URIs! (IIS) Secure the URIs!

25 CSRF Attacks An attack where the victim’s browser is tricked into issuing a command to a vulnerable web application Vulnerability is caused by browsers automatically including user authentication data (session ID, IP address, Windows domain credentials, …) with each request Cross Site Request Forgery What if a hacker could steer your mouse and get you to click on links in your online banking application? What could they make you do? Imagine… Initiate transactions (transfer funds, logout user, close account) Access sensitive data Change account details Typical Impact

26 CSRF Illustrated 3 2 Attacker sets the trap on some website on the internet (or simply via an e-mail) 1 While logged into vulnerable site, victim views attacker site Vulnerable site sees legitimate request from victim and performs the action requested tag loaded by browser – sends GET request (including credentials) to vulnerable site Custom Code Accounts Finance Administration Transactions Communication Knowledge Mgmt E-Commerce Bus. Functions Hidden tag contains attack against vulnerable site Application with CSRF vulnerability

27 Defense Protect valuable actions with CAPTCHA Validation of Headers (Weak-Sauce) Expire session, offer logout options New JSON exposure Protect the website with CSRF Tokens – Built into MVC.NET – Implementation is more difficult than it seems

28 Security Misconfigurations Everywhere from the OS up through the App Server Don’t forget all the libraries you are using!! Web applications rely on a secure foundation Think of all the places your source code goes Security should not require secret source code Is your source code a secret? All credentials should change in production CM must extend to all parts of the application Install backdoor through missing OS or server patch XSS flaw exploits due to missing application framework patches Unauthorized access to default accounts, application functionality or data, or unused but accessible functionality due to poor server configuration Typical Impact

29 Security Misconfig Illustrated Hardened OS Web Server App Server Framework App Configuration Custom Code Accounts Finance Administration Transactions Communication Knowledge Mgmt E-Commerce Bus. Functions Test Servers QA Servers Source Control Development Database Insider

30 Defense Cassini is a LIAR, do not trust it! ASP.NET won’t serve particular types of files by default: – DON’T RENAME THEM! Web.config.bak WILL be served! – Don’t allow directory browsing Don’t let developers know secure connection strings to production if you can avoid it.

31 Insecure Cryptographic Storage Failure to identify all sensitive data Failure to identify all the places that this sensitive data gets stored Databases, files, directories, log files, backups, etc. Failure to properly protect this data in every location Storing sensitive data insecurely Attackers access or modify confidential or private information e.g, credit cards, health care records, financial data (yours or your customers) Attackers extract secrets to use in additional attacks Company embarrassment, customer dissatisfaction, and loss of trust Expense of cleaning up the incident, such as forensics, sending apology letters, reissuing thousands of credit cards, providing identity theft insurance Business gets sued and/or fined Typical Impact

32 Insecure Cryptographic Storage Illustrated Custom Code Accounts Finance Administration Transactions Communication Knowledge Mgmt E-Commerce Bus. Functions 1 Victim enters credit card number in form 2 Error handler logs CC details because merchant gateway is unavailable 4 Malicious insider steals 4 million credit card numbers Log files 3 Logs are accessible to all members of IT staff for debugging purposes

33 Defense Are you encrypting sensitive information w/ SQL Server 2008? Are you storing sensitive information in places you ought not to? Logs, emails, etc.. What are you encrypting in the database

34 URL Access This is part of enforcing proper “authorization”, along with A4 – Insecure Direct Object References How do you protect access to URLs (pages)? Displaying only authorized links and menu choices This is called presentation layer access control, and doesn’t work Attacker simply forges direct access to ‘unauthorized’ pages A common mistake … Attackers invoke functions and services they’re not authorized for Access other user’s accounts and data Perform privileged actions Typical Impact

35 Failure to Restrict URL Access Illustrated Attacker notices the URL indicates his role /user/getAccounts He modifies it to another directory (role) /admin/getAccounts, or /manager/getAccounts Attacker views more accounts than just their own

36 Defense Use [Authorization] headers where appropriate Use Web.Config where appropriate Consider using Role filters and [Permission.Demand] attributes over features Consider: Who owns this, who can maintain it, how high up the chain can they call? Don’t forget all your super rad JSON stuff! Service calls need security love too!

37 Insufficient Transport Layer Protection Failure to identify all sensitive data Failure to identify all the places that this sensitive data is sent On the web, to backend databases, to business partners, internal communications Failure to properly protect this data in every location Transmitting sensitive data insecurely Attackers access or modify confidential or private information e.g, credit cards, health care records, financial data (yours or your customers) Attackers extract secrets to use in additional attacks Company embarrassment, customer dissatisfaction, and loss of trust Expense of cleaning up the incident Business gets sued and/or fined Typical Impact

38 Insufficient Transport Layer Protection Illustrated Custom Code Employees Business Partners External Victim Backend Systems External Attacker 1 External attacker steals credentials and data off network 2 Internal attacker steals credentials and data from internal network Internal Attacker

39 Defense Use awesome certificates (aka, 3 rd party verified, non-expired) Set them UP CORRECTLY (validate) Insecure landing page Don’t use redirects, use HTTPS only Insecure Content Attacks Use Strong encryption

40 Unvalidated Redirects & Forwards And frequently include user supplied parameters in the destination URL If they aren’t validated, attacker can send victim to a site of their choice Web application redirects are very common They internally send the request to a new page in the same application Sometimes parameters define the target page If not validated, attacker may be able to use unvalidated forward to bypass authentication or authorization checks Forwards ( aka Transfer in.NET ) are common too Redirect victim to phishing or malware site Attacker’s request is forwarded past security checks, allowing unauthorized function or data access Typical Impact

41 Unvalidated Redirect Illustrated 3 2 Attacker sends attack to victim via email or webpage From: Internal Revenue Service Subject: Your Unclaimed Tax Refund Our records show you have an unclaimed federal tax refund. Please click here to initiate your claim. 1 Application redirects victim to attacker’s site Request sent to vulnerable site, including attacker’s destination site as parameter. Redirect sends victim to attacker site Custom Code Accounts Finance Administration Transactions Communication Knowledge Mgmt E-Commerce Bus. Functions 4 Evil site installs malware on victim, or phish’s for private information Victim clicks link containing unvalidated parameter Evil Site http://www.irs.gov/taxrefund/claim.jsp?year=2006 &http://www.irs.gov/taxrefund/claim.jsp?year=2006 & … &dest=www.evilsite.com… &dest=www.evilsite.com

42 Defense Don’t do that! If you have to, use some variable to control location, not user supplied code Be wary of Response.Redirect! The action may still performed even if the site is redirected!

43 Other.NET Framework Components Monitoring / health frameworks SecureStrings Encryption: Built in frameworks Data leaking: – Viewstate encryption – Errors and error handling

44 More stuff Awareness of what is publicly indexed Developer comments Robots.txt Crossdomain.xml

45 Summary Out of the box, MVC.NET is the easiest defendable web application framework I have ever used. ASP.NET comes with many built in components that can really help you out (if utilized) Bad code can be written in any language. Don’t do that

46 QA? Twitter: awilsong Blog: http://pinvoke.wordpress.comhttp://pinvoke.wordpress.com Email: pinvoke@doublethunk.orgpinvoke@doublethunk.org


Download ppt "Securing MVC.NET Web Applications Andrew Wilson. 오 안녕하세요 !!!! Senior Software Consultant Obsessed security guy OWASP co-lead Long walks on the beach desert."

Similar presentations


Ads by Google