an introduction to application security in asp.net ... · • reference connection strings...

32
An Introduction to Application Security In ASP.NET Environments Houston .NET User Group February 23 rd , 2006

Upload: others

Post on 09-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

An Introduction to Application Security In ASP.NET Environments

Houston .NET User Group

February 23rd, 2006

Page 2: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

1

Overview

• Background• What is Application Security and Why Is It Important?• Examples• ASP.NET Specific Examples• What is New in .NET 2.0?• Resources and Conclusions

Page 3: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

2

Background

• Denim Group– Texas-based consultancy– Microsoft Gold Certified Partner– Custom software development– Systems integration– Application security

• Management Team Experience– Large-scale software development– Air Force information warfare– Client service for DoD, Big 4, Fortune 500

• Myself: Dan Cornell– Microsoft Certified Solution Developer– Java 2 Certified Programmer

Page 4: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

3

What is Application Security and Why is it Important?• Application Security Defined• Fit with General Information Security Landscape• Why Does Application Security Matter

Page 5: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

4

Application Security Defined

• Ensuring that custom application code performs as expected under the entire range of possible inputs

• Goals:– Confidentiality– Integrity– Availability

• Relationship to Software Quality Assurance– Really a sub-area of SQA– SQA typically verifies that software does what it is supposed to do– Application security is concerned that software does not do what it should

not do

Page 6: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

5

Software Implementation – Perfect World

Intended Functionality

Actual Functionality

Page 7: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

6

Software Implementation – Real WorldIntended Functionality

Actual Functionality

BugsBuilt

Features

UnintendedAnd UndocumentedFunctionality

Page 8: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

7

Information Security

• Software Development: “Build” Culture– Features, functions and timelines

• Information Security: “Measure” Culture– Audit, assess and maintain

• Application security applies information security principles to custom software development efforts

• Many traditional information security practitioners are ill-equipped to mitigate application security issues

Page 9: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

8

Why Does This Matter?

• Business-critical web applications are Internet-facing– An increasing number of assets are exposed

• Most applications have serious flaws– Foundstone (McAfee) and @Stake (Symantec) studies

• The regulator environment has changed– Sarbanes Oxley– GLB– California SB-1386

Page 10: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

9

OWASP Top 10 Critical Web Application Security Vulnerabilities• Unvalidated Input• Broken Access Control• Broken Authentication and Authorization• Cross Site Scripting (XSS)• Buffer Overflows• Injection Flaws• Improper Error Handling• Insecure Storage• Denial of Service• Insecure Configuration Managementhttp://www.owasp.org/documentation/topten.html

Page 11: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

10

Examples

• Hidden parameter tampering• Cookie manipulation• SQL injection

Page 12: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

11

Hidden Parameter Tampering

• Price information is stored in hidden HTML form field • Assumption: hidden field won’t be edited• Attacker edits price parameter• Attacker submits altered web page with new “price”• Application trusts the price parameter from the user• Still widespread in many web stores

Page 13: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

12

The Attack

Page 14: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

13

The Result

Page 15: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

14

Cookie Manipulation

• Browser cookie is used to store user identity information• Assumption: cookies are set by server side code, handled by

the browser automatically and not manipulated by users• Attacker alters cookie• Application trusts the browser cookie and allows attacker to

assume identity of another user

Page 16: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

15

The Attack

Page 17: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

16

The Attack

Page 18: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

17

The Result

Page 19: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

18

SQL Injection

• SQL statements are created from a combination of static text and user inputs

• Assumption: users will enter well-formed inputs• Attacker crafts a custom input to hijack control of the SQL

interpreter and execute arbitrary code• Very common flaw with tremendous security implications

Page 20: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

19

The Attack

string username = Request[“username”];string password = Request[“password”];string sql = “SELECT * FROM User WHERE username =

‘” + username + “’ AND password = ‘” + password + “’”;

SqlCommand cmd = new SqlCommand(sql);IDataReader reader = cmd.ExecuteReader();

Page 21: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

20

The Attack

• Specially crafted input contains SQL control characters

Page 22: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

21

The Attack

• Malicious user sends in a username parameter of:Dcornell’; DROP DATABASE Ecommerce; --

SQL Executed is:SELECT * FROM User WHERE username = ‘Dcornell’;

DROP DATABASE Ecommerce; -- AND password = ‘whocares’

• Attacker can execute arbitrary database queries with the same permissions as the application

– View sensitive data– Modify data– Destroy data

Page 23: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

22

ASP.NET Specific Examples

• Access Control– Authentication– Authorization

• Input Validation– ASP.NET validation– SQL injection– Cross Site Scripting (XSS)– Buffer Overflows

Page 24: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

23

Access Control

• Authentication– HTTP Basic– Windows– Forms

• Available in ASP.NET 1.1• Much improved in ASP.NET 2.0 – lots of ready-made controls• See: http://www.sitepoint.com/article/asp-net-2-security

• Authorization– Control access to pages:

• NTFS: FileAuthorizationModule• web.config: UrlAuthorizationModule• See: http://msdn.microsoft.com/library/default.asp?url=/library/en-

us/cpguide/html/cpconaspnetauthorization.asp– Imperative security: Page.User.IsInRole(“roleName”)

Page 25: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

24

Input Validation

• ASP.NET Validation• SQL Injection• Cross Site Scripting (XSS)• Buffer Overflows

Page 26: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

25

ASP.NET Validation

• Perform both client-side and server-side validation• RequiredFieldValidator requires that a field be present

– Other validators will pass through blank inputs, so often you must use two validators

• Other examples of Validators include:– CompareValidator– RangeValidator– RegularExpressionValidator– CustomValidator

• Validators display error messages in-place• ValidationSummary object used to display a summary of all

errors from validators on a page

Page 27: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

26

SQL Injection

• As seen before, this is the result of creating SQL queries by combining static text and unfiltered user inputs

• To prevent attacks, use proper escaping for potentially hostile inputs:

– Stored procedures (CommandType.StoredProcedure)– Parameterized queries– Be sure to actually escape malicious data

Page 28: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

27

Cross Site Scripting (XSS)

• ASP.NET framework provides pretty good protection against some XSS attacks

– This is an example of blacklisting inputs rather than whitelisting inputs

• Underlying problem is a failure to properly escape special HTML characters

• Most ASP.NET controls provide this– Literals do not– Use a Label instead when possible– Or use HttpServerUtility.HtmlEncode method

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpServerUtilityClassHtmlEncodeTopic1.asp

Page 29: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

28

Buffer Overflows

• Managed code should typically be fine– This can give a false sense of security

• Legacy COM components– Can still contain buffer overflows– “Seamless” .NET/COM integration makes these sneaky– Wrap potentially dangerous calls

Page 30: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

29

What is New in .NET 2.0?

• Reference connection strings contained in machine.config• Encrypt sections of .config files with machine key• Easier access to DPAPI functions from .NET• Forms Authentication improvements (mentioned earlier)• SecureString class• More…

Page 31: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

30

Resources

• OWASP www.owasp.org– Top 10– Guide– WebGoat training tool– WebScarab penetration testing tool (proxy)– Discussion lists

• MSDN msdn.microsoft.com/security

Page 32: An Introduction to Application Security In ASP.NET ... · • Reference connection strings contained in machine.config • Encrypt sections of .config files with machine key • Easier

31

Questions

Dan [email protected]

Denim Group, Ltd.www.denimgroup.com