Security in .NET Framework

25
Security in .NET Framework Sergey Baidachni MCT, MCSD, MCDBA

description

Security in .NET Framework. Sergey Baidachni MCT, MCSD, MCDBA. Overview. Introduction Code Access Security Add-on features in .NET Best Practices New Microsoft Exams Books for reading. Introduction. Security Needs Example (poor practices) Best Practices. Example (try it). - PowerPoint PPT Presentation

Transcript of Security in .NET Framework

Page 1: Security in .NET Framework

Security in .NET Framework

Sergey BaidachniMCT, MCSD, MCDBA

Page 2: Security in .NET Framework

Overview Introduction Code Access Security Add-on features in .NET Best Practices New Microsoft Exams Books for reading

Page 3: Security in .NET Framework

Introduction Security Needs Example (poor practices) Best Practices

Page 4: Security in .NET Framework

Example (try it)“Select count(*) from UserTableWhere Login=‘”+login+ “‘ and password=‘”+pwd+ “‘”

Login – sbadPassword – 123’456

Page 5: Security in .NET Framework

Example (compilation error)“Select count(*) from UserTableWhere Login=‘sbad’ and password=‘123’456’”

Page 6: Security in .NET Framework

Example“Select count(*) from UserTableWhere Login=‘sbad’ and password=‘123’ shutdown --’”

Where is your SQL Server? It would be good if a hacker would have decided to study only one command, and namely that one of ”shutdown”...

Page 7: Security in .NET Framework

Best Practices Parameters using

SqlCommand comm=new SqlCommand(“select count(*) from UserTable Where Login=@par1 and

password=@par2”,conn);

comm.Parameters.Add(“@par1”,SqlDbType.VarChar,20).Value=logincomm.Parameters.Add(“@par2”,SqlDbType.VarChar,20).Value=pwd

Stored procedures using

Page 8: Security in .NET Framework

Code Access Security Least Privilege Evidence Permissions Declarative Permissions Imperative Permissions

Page 9: Security in .NET Framework

Least Privilege

How much money can they steal if you have none?

Page 10: Security in .NET Framework

Evidence

Can you lend me some bank

money?

I would be more than glad, by I am debarred

from any access

Page 11: Security in .NET Framework

Permissions

Lend me some bank money

I would be glad to, but I have asked the bank not to give me

money

Page 12: Security in .NET Framework

Declarative Permissions Stack Walk Demand minimal permissions

[assembly:FileIOPermission(SecurityAction.RequestMinimum, Read=@”c:\a.txt”)]

Reject redundant permissions [assembly:FileIOPermission(SecurityAction.RequestRefuse,

Unrestricted=true)]

Request unnecessary permissions [assembly:FileIOPermission(SecurityAction.RequestOptional,

Unrestricted=true)]

Caspol –resolveperm myassembly.exe

Page 13: Security in .NET Framework

Imperative Permissions Demand and Assert Deny and PermitOnly LinkDemand while using

SuppressUnmanagedCodeSecurityAttribute

Page 14: Security in .NET Framework

Add-on features in .NET Form-Based Authentication Role-Based Security Microsoft Passport

Page 15: Security in .NET Framework

Security? Login? Password? Authentication

You can enter, but don’t handle anything with your hands!

Authorization Ok, you can do it.

Page 16: Security in .NET Framework

Client requests page

Authorized

ASP.NET Forms Authentication

Not Authenticated

Authenticated

Logon Page(Users enter their credentials)

Authenticated

Authentication Cookie

Authorized

Not Authenticated

Access Denied

RequestedSecure Page

IIS

Username

PasswordSomeone

***********

SubmitSubmit

1111 2222

3333

44446666

55557777

Form-based authentication

Page 17: Security in .NET Framework

Form-based authentication (How?) Modify the config file

<system.web>

<authentication mode="Forms"><forms name=".namesuffix" loginUrl="login.aspx" />

</authentication></system.web>

Create method for authenticate FormsAuthentication.Authenticate FormsAuthentication.RedirectFromLoginPage

Page 18: Security in .NET Framework

Role-based security Identity and Principals Windows Identity and Principal General Identity and Principal Custom Identity and Principal

Page 19: Security in .NET Framework

Identity and Principals Check identity of the user

Check the role of the user

Username = FredUsername = FredUsername = FredUsername = Fred

Administrator

Manager

Role = ManagerRole = ManagerRole = ManagerRole = Manager

Page 20: Security in .NET Framework

Identity and Principals in .NET Framework

Identity Windows identity (WindowsIdentity) Generic identity (GeneralIdentity) Custom identity (IIdentity)

Principals Windows principal (WindowsPrincipal) Generic principal (GeneralPrincipal) Custom principal (IPrincipal)

Page 21: Security in .NET Framework

Microsoft Passport How it works Benefits www.passport.com

Page 22: Security in .NET Framework

How Microsoft Passport Works

Website.msftWebsite.msft

ClientClient

Passport.comPassport.com

The client requests a page from the host1111

2222

3333

4444

5555

The site redirects the client to Passport.com

The client is redirected and logs on to Passport.com

Passport returns a cookie with the ticket information

6666

The client accesses the host, this time with ticket information

The host returns a Web Form and possibly a new cookie that it can read and write

Page 23: Security in .NET Framework

Best Practices Strong Names Access Modifiers Trace Disable Custom Error Messages Use Register

Page 24: Security in .NET Framework

New Microsoft Exam 70-340 – Implementing Security for

Applications with Microsoft Visual C# .NET 70-330 – Implementing Security for

Applications with Microsoft Visual Basic .NET

Page 25: Security in .NET Framework

Books for reading Writing Secure Code

by Michael Howard, David LeBlanc

Designing Secure Web-Based Applications for Microsoft Windows 2000 by Michael Howard