SlideShare a Scribd company logo
Advances in secure
(ASP).NET development break the hackers' spirit
Alexandre Herzog
IT Security Analyst – Compass Security AG

Application Security Forum - 2013
Western Switzerland
15-16 octobre 2013 - Y-Parc / Yverdon-les-Bains
http://www.appsec-forum.ch
2

Agenda





Introduction to .NET
Configuration of (ASP).NET applications
New features of (ASP).NET 4.5
Key security points of application lifecycle
– Development
– Deployment
– Operations
– Third party component review
3

Aim of this talk
 Discover the (ASP).NET framework and its
limitations
 Give you a set of points to observe for your next
(ASP).NET application release
 No discussion about the code
 The focus is on applications, not infrastructure
nor Microsoft’s Security Development Lifecycle.
 This talk won’t be too technical,
just enough to cover these points
4

Bio of Alexandre Herzog
 Vaudois exilé d’abord en Valais, then Wellington
(NZ) und jetzt Zürich
 Mainly worked for banks as sysadmin / developer
 Just finished my MAS in Information Security (LU)
 Author of several security advisory
– Including CVE-2013-1330 patched in MS13-067

 Currently working as IT Security Analyst for
Compass Security AG in Bern & Rapperswil/Jona
5

Agenda





Introduction to .NET
Configuration of (ASP).NET applications
New features of (ASP).NET 4.5
Key security points of application lifecycle
– Development
– Deployment
– Operations
– Third party component review
6

Introduction to .NET
The .NET Framework is a development platform for building
apps for Windows, Windows Phone, Windows Server, and
Windows Azure.
It consists of the common language runtime (CLR) and the
.NET Framework class library, which includes
classes, interfaces, and value types that support an extensive
range of technologies.
The .NET Framework provides a managed execution
environment, simplified development and deployment, and
integration with a variety of programming
languages, including Visual Basic and Visual C#.
[MS_DotNet_Def]
7

Introduction to .NET
The .NET Framework is a development platform for building
apps for Windows, Windows Phone, Windows Server, and
Windows Azure.
It consists of the common language runtime (CLR) and the is
This framework
.NET Framework class library, which includes installed by default
classes, interfaces, and value types that support on any Windows
an extensive
device. It’s also
range of technologies.
used for Silverlight.
The .NET Framework provides a managed execution
environment, simplified development and deployment, and
integration with a variety of programming
languages, including Visual Basic and Visual C#.
[MS_DotNet_Def]
8

Introduction to .NET
The .NET Framework is a development platform for building
apps for Windows, Windows Phone, Windows Server, and
Windows Azure.
It consists of the common language runtime (CLR) and the
.NET Framework class library, which includes
classes, interfaces, and value types that support an extensive
range of technologies.
The .NET Framework provides a managed execution
environment, simplified development and deployment, and
integration with a variety of programming
languages, including Visual Basic and Visual C#.
[MS_DotNet_Def]
[Wiki_Components]
9

Introduction to .NET
The .NET Framework is a development platform for building
apps for Windows, Windows Phone, Windows Server, and
Windows Azure.
It consists of the common language runtime (CLR) and the
.NET Framework class library, which includes
Enhances the security (e.g. no
classes, interfaces, and value types that support an extensive
buffer overflow is possible).
range of technologies.
The .NET Framework provides a managed execution
environment, simplified development and deployment, and
integration with a variety of programming
languages, including Visual Basic and Visual C#.
[MS_DotNet_Def]
10

Introduction to .NET
The .NET Framework is a development platform for building
apps for Windows, Windows Phone, Windows Server, and
Windows Azure.
It consists of the common language runtime (CLR) and the
.NET Framework class library, which includes also compile
You can
F#, IronPython, extensive
classes, interfaces, and value types that support an IronRuby, J#
etc…
range of technologies.
[Wiki_IL_Lang]
The .NET Framework provides a managed execution
environment, simplified development and deployment, and
integration with a variety of programming
languages, including Visual Basic and Visual C#.
[MS_DotNet_Def]
11

Introduction to .NET
 Sounds like Java!
 Yes, because
– It’s byte code => the code can be reversed
– Multiplatform (can also run on Linux using Mono)

 No, because
– Different versioning scheme
• All versions of .NET but 1.0 are still supported
• Supported versions get security patches (1.1, 2.0, 3.0, 3.5, 4.0, 4.5)

– The .NET framework is pre-installed on Windows
12

Introduction to .NET
 .NET also features runtime Trust Level
– An app running with Trust Level set to medium cannot
e.g. access the registry or files outside the app’s folder
[MS_Trust]

– This is not related to the Windows Mandatory Integrity
Control (MIC)

 Close interaction of ASP.NET with IIS
 .NET is not (yet?) as targeted / vulnerable as Java
 You can compile .NET code on any Windows device
13

Agenda





Introduction to .NET
Configuration of (ASP).NET applications
New features of (ASP).NET 4.5
Key security points of application lifecycle
– Development
– Deployment
– Operations
– Third party component review
14

Config of (ASP).NET applications
 Typical configuration
– Proxy settings
– Cryptographic keys
– Cookie settings
– Compilation details
– Error handling
– Retail mode
– Trust level
– Database connections

– ViewState parameters
– Trace configuration
– Request validation
– Application settings
–…
– See
•
•
•

[MS_AspNet_config]
[MS_Net_config]
[HL_Decompile]
15

Config of (ASP).NET applications
 Configuration is based on .config files
 For .NET executables, the config hierarchy is
– Server level config (machine.config)
– Application specific config ([AppName].exe.config)
– Optional user settings (roaming.config & user.config)
16

Config of (ASP).NET applications
 Configuration is based on .config files
 For .NET executables, the config hierarchy is
– Server level config (machine.config)
– Application specific config ([AppName].exe.config)
– Optional user settings (roaming.config & user.config)

 Do not use Group Policy Preferences to distribute
configurations in your Windows domain!
– For more details see [CSNC_GPP]
17

Config of (ASP).NET applications
 Config hierarchy for ASP.NET code
– Server level config (machine.config & web.config)
– Web site (web.config)
– ASP.NET application and subfolders (web.config)
– Further details available in [ASPNET_config]

 IIS configuration is also involved for ASP.NET code
• %windir%system32inetsrvconfigApplicationHost.config
18

Config of (ASP).NET applications

Source:
[CP_net_config]
19

Config of (ASP).NET applications
 The configuration can be locked at any level
[MS_lock_config]

 The configuration on the server level is
dependent of the .NET version and CPU
architecture
• %systemroot%Microsoft.NETFramework[64][version]CO
NFIG

 It is possible to encrypt sections of the
configuration file (only useful for web.config files)
[MS_enc_config]
20

Config of (ASP).NET applications
 Why encrypt the configuration file?
– Limits the impact of file inclusion issues or leaking
code / configuration files
– An attacker first needs to execute a command on the
web server before being the config is in clear text

 Recommended sections to encrypt
– <MachineKey />
– <ConnectionStrings />
– Any other settings where keys, passwords or endpoint
information is stored
21

Agenda





Introduction to .NET
Configuration of (ASP).NET applications
New features of (ASP).NET 4.5
Key security points of application lifecycle
– Development
– Deployment
– Operations
– Third party component review
22

New features of (ASP).NET 4.5
 Microsoft is continuously improving .NET
– Task based async model
– Enhanced Strong Naming for Windows Store apps
– WebSockets, etc

 Especially security relevant is that
– The standalone Anti-XSS library is now integrated
– Several changes occurred in the handling of
cryptography
23

New features of (ASP).NET 4.5
 Why such crypto improvements in version 4.5?
– “Cryptography in the Web: The Case of Cryptographic
Design Flaws in ASP.NET” research of [Duong_Rizzo]
– Padding oracle attack patched by Microsoft for all
versions in MS10-070
– All details of these changes in (ASP).NET 4.5 are
described in [MS_Improv_1] to [MS_Improv_3]
24

New features of (ASP).NET 4.5
 Visible impact of (ASP).NET 4.5
– Several changes are opt-in
• Action is required!

– ViewState fields will be encrypted
– Some compatibility with ASP.NET 2.0 may/will be lost
25

New features of (ASP).NET 4.5
 Extract of the appendix of this talk:
26

New features of (ASP).NET 4.5
 Do these changes justify migration to .NET 4.5?
– YES absolutely
– Several defence in-depth mechanisms were added
27

Agenda





Introduction to .NET
Configuration of (ASP).NET applications
New features of (ASP).NET 4.5
Key security points of application lifecycle
– Development
– Deployment
– Operations
– Third party component review
28

Key security points of app lifecycle >

Development
Why not use this opportunity to start setting up a
Security Development Lifecycle for your apps?
[MS_SDL]
29

Key security points of app lifecycle >

Development
Why not use this opportunity to start setting up a
Security Development Lifecycle for your apps?
[MS_SDL]

Source http://www.microsoft.com/security/sdl/
30

Key security points of app lifecycle >

Development
Why not use this opportunity to start setting up a
Security Development Lifecycle for your apps?
[MS_SDL]

Source http://www.microsoft.com/security/sdl/
31

Key security points of app lifecycle >

Development
 Develop on .NET 4.5 (especially for web apps) and
for a medium trust level whenever possible
 Use the free Microsoft SDL tools while developing
– FxCop [MS_FxCop] & CATNET [MS_CATNET]

 Do not turn off security features
– Request Validation, ViewState MAC, …

 Do not rely on client side only validation or
include/hide secrets in client side applications
 Teach best practices to your developers…
32

Key security points of app lifecycle >

Deployment
 Lock down the server and app configuration
 Consider an obfuscator for your client side apps
– Executable or Silverlight only

 Do not use GPPs to distribute configurations!
 Consider reducing the trust level of your app
whenever possible
 Perform a general server hardening (OS & IIS)
– Again, this “infrastructure” part is not covered here
33

Key security points of app lifecycle >

Operations
 Run ASP.NET 4.5 with medium trust apps[MS_Trust_expl]
 Encrypt sensitive sections of the web.config file
 Manage the cryptographic keys you use!
– Web.config encryption & ASP.NET features (Machine Key)

 Patch the server & configure IIS adequately
 Communicate
– Be ready in case of a (security) incident
– All technical stakeholders should come together…
34

Key security points of app lifecycle >

Third party component review
 The same recipes apply:
– As it’s just byte code, let’s decompile the application!
Loi sur le droit d’auteur
Art. 21 Décryptage de logiciels
1 La personne autorisée à utiliser un logiciel peut se procurer, par le décryptage
du code du programme, des informations sur des interfaces avec des
programmes développés de manière indépendante. Elle peut opérer elle-même
ou mandater un tiers.
2 Les informations sur des interfaces obtenues par le décryptage du code du
programme ne peuvent être utilisées que pour développer, entretenir et utiliser
des logiciels interopérables, pourvu qu'une telle utilisation ne porte pas atteinte
à l'exploitation normale du programme ni ne cause un préjudice injustifié aux
intérêts légitimes de l'ayant droit.
35

Key security points of app lifecycle >

Third party component review
 The same recipes apply:
– Audit source code & configuration
– Audit assemblies with static analysis tools
– Run the component with the lowest possible trust
level
– Regenerate all keys / secrets shipped by the vendor

 Manage the component by
– Monitoring for security patches
– Update it periodically
36

Agenda





Introduction to .NET
Configuration of (ASP).NET applications
New features of (ASP).NET 4.5
Key security points of application lifecycle
– Development
– Deployment
– Operations
– Third party component review
37

Conclusion
 Top security issues in .NET include
– Application information leak

Solved by configuration
(server or app)
Static code analysis
No secrets in the code!
Consider an obfuscator

• Verbose error messages
• Secrets stored within the code (executable or Silverlight)

– Injections

Education of devs, code
review & static analysis

• SQL injections due to unsafe database requests

– Unsafe application settings
• Unencrypted communication
• Unsafe distribution of credentials

Education of
devs, code and config
review
No secrets in the code!
Rely on Windows auth.
when possible
38

Conclusion
 Top security issues in ASP.NET include
– Application information leak
• Secrets stored in the ViewState
• Verbose error messages

– Unsafe application settings
• Session cookie parameters
• Request validation disabled
• Unencrypted configuration file

– Injections

Configure this field to
be encrypted or
migrate to ASP.NET 4.5
Hardening / lockdown
of the configuration
(server or app)
Static code analysis
Encryption of
configuration file
Education of devs, code
review & static analysis

• XSS due to user inputs in JS or HTML attributes
• SQL injections due to unsafe database requests
39

Conclusion
 .NET is a secure framework following
the SD3+C principle[MS_SD3C]:
– Secure by Design, Secure by Default, Secure in
Deployment, and Communications

 Your applications can also benefit from this
security during their lifecycle
 This talk focused on application security
– You still have to harden your infrastructure (OS & IIS)!
40

Questions?
41

Danke/Merci/Thank you!
Contact:
alexandre.herzog@csnc.ch
Company blog
LinkedIn
G+

http://blog.csnc.ch/

Slides

http://slideshare.net/ASF-WS/presentations

http://ch.linkedin.com/in/alexandreherzog/
https://plus.google.com/u/1/109572456864701444940/
42

References (1/2)












[MS_DotNet_Def] http://msdn.microsoft.com/en-us/library/w0x726c2.aspx
[Wiki_Components]
http://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/DotNet.svg/250px-DotNet.svg.png
[Wiki_IL_Lang] http://en.wikipedia.org/wiki/Category:.NET_programming_languages
[ASPNET_config] http://msdn.microsoft.com/en-Us/library/ms178685.aspx
[CP_net_config] http://www.codeproject.com/Articles/19675/Cracking-the-Mysteries-of-NET-2-0Configuration
[CSNC_GPP] http://blog.csnc.ch/2012/04/exploit-credentials-stored-in-windows-group-policypreferences/
[HL_Decompile] http://media.hackinglab.com/largefiles/7205/Paper_DisassembleDotNetClient_v2.0.pdf
[MS_lock_config] http://msdn.microsoft.com/en-us/library/ms228167(v=vs.100).aspx
[MS_AspNet_config] http://msdn.microsoft.com/en-us/library/zeshe0eb(v=vs.85).aspx
[MS_Net_config] http://msdn.microsoft.com/en-us/library/1fk1t1t0.aspx
[Duong_Rizzo] http://www.ieee-security.org/TC/SP2011/PAPERS/2011/paper030.pdf
43

References (2/2)














[MS_Improv_1] http://blogs.msdn.com/b/webdev/archive/2012/10/22/cryptographicimprovements-in-asp-net-4-5-pt-1.aspx
[MS_Improv_2] http://blogs.msdn.com/b/webdev/archive/2012/10/23/cryptographicimprovements-in-asp-net-4-5-pt-2.aspx
[MS_Improv_3] http://blogs.msdn.com/b/webdev/archive/2012/10/24/cryptographicimprovements-in-asp-net-4-5-pt-3.aspx
[MS_enc_config] http://msdn.microsoft.com/en-us/library/dtkwfdky(v=VS.100).aspx
[MS_SD3C] http://msdn.microsoft.com/en-us/library/ms995349.aspx
[MS_SDL] http://www.microsoft.com/security/sdl/default.aspx
[MS_FxCop] http://www.microsoft.com/en-us/download/details.aspx?id=6544
[MS_CATNET] http://www.microsoft.com/en-us/download/details.aspx?id=5570
[MS_Trust] http://msdn.microsoft.com/en-us/library/tkscy493(v=vs.85).aspx
[MS_Trust_expl] http://msdn.microsoft.com/En-Us/library/wyts434y.aspx
[MS_Run_45] http://blogs.msdn.com/b/webdev/archive/2012/11/19/all-about-httpruntimetargetframework.aspx
[MS_Trust_HowTo] http://msdn.microsoft.com/en-us/library/ff648344.aspx
44

Configuration checklist
 This checklist is by no means complete. It’s just
the starting point of your configuration journey…
 Depending on your situation, you may want to
configure these settings on a server (e.g.
machine.config) and lock them or on an
application level (web.config)
45

Configuration checklist
 List of configuration which should be forced on an
integration / production server
 In the machine.config for all .NET versions
[…]
<system.web>
<deployment retail="true" />
<pages viewStateEncryptionMode="Always" />
<httpCookies httpOnlyCookies="true" requireSSL="true" />
</system.web>
<authentication>
<forms requireSSL= true" />
</authentication>
[…]
46

Configuration checklist
 List of settings which are secure by default. They
should not be disabled in configuration or code:
– For the <pages> configuration section
• Property enableEventValidation should stay true
• Property enableViewStateMac should stay true
• Property validateRequest should stay true

– For the <forms> configuration section
• Property enableCrossAppRedirects should stay disabled
• Property protection should stay all
47

Configuration checklist
 List of settings which are secure by default. They
should not be disabled in configuration or code:
– For the <trace> configuration section
• Property enabled should stay false

– For the <customErrors> configuration section
• Property mode should stay RemoteOnly or On

– For the <compilation> configuration section
• Property debug should stay false

 All these properties are set to a safe value if
<system.web><deployment retail="true" />
48

Configuration checklist
 If you run ASP.NET 4.5
– Ensure section <httpRuntime> enables all new feature
with attribute targetFramework="4.5"[MS_Run_45]
– Once done, ensure the following config sections are
either absent or set to the following values:
• <machineKey compatibilityMode="Framework45" />
• <compilation targetFramework="4.5" />
• <pages controlRenderingCompatibilityVersion="4.5"/>

– Configure AntiXSS to be the default encoding routine
<httpRuntime […] encoderType="System.Web.Security.AntiXss.
AntiXssEncoder,System.Web, Version=4.0.0.0, Culture=neutral, Pu
blicKeyToken=b03f5f7f11d50a3a" />
49

Configuration checklist
 Trust level and their impact [MS_Trust_HowTo]
– Example of a web app running with medium trust
<system.web>
<trust level="Medium" originUrl="" />
</system.web>

– This web application would not be able to
•
•
•
•
•
•
•
•

Call unmanaged code.
Call serviced components.
Write to the event log.
Access Microsoft Message Queuing queues.
Access ODBC, OleDb, or Oracle data sources.
Access files outside the application directory.
Access the registry.
Make network or Web service calls
(allowed URLs can be defined)

Restrictions due to high
trust level
Additional restrictions
due to medium trust level

More Related Content

ASFWS 2013 - Advances in secure (ASP).NET development – break the hackers’ spirit par Alexandre Herzog

  • 1. Advances in secure (ASP).NET development break the hackers' spirit Alexandre Herzog IT Security Analyst – Compass Security AG Application Security Forum - 2013 Western Switzerland 15-16 octobre 2013 - Y-Parc / Yverdon-les-Bains http://www.appsec-forum.ch
  • 2. 2 Agenda     Introduction to .NET Configuration of (ASP).NET applications New features of (ASP).NET 4.5 Key security points of application lifecycle – Development – Deployment – Operations – Third party component review
  • 3. 3 Aim of this talk  Discover the (ASP).NET framework and its limitations  Give you a set of points to observe for your next (ASP).NET application release  No discussion about the code  The focus is on applications, not infrastructure nor Microsoft’s Security Development Lifecycle.  This talk won’t be too technical, just enough to cover these points
  • 4. 4 Bio of Alexandre Herzog  Vaudois exilé d’abord en Valais, then Wellington (NZ) und jetzt Zürich  Mainly worked for banks as sysadmin / developer  Just finished my MAS in Information Security (LU)  Author of several security advisory – Including CVE-2013-1330 patched in MS13-067  Currently working as IT Security Analyst for Compass Security AG in Bern & Rapperswil/Jona
  • 5. 5 Agenda     Introduction to .NET Configuration of (ASP).NET applications New features of (ASP).NET 4.5 Key security points of application lifecycle – Development – Deployment – Operations – Third party component review
  • 6. 6 Introduction to .NET The .NET Framework is a development platform for building apps for Windows, Windows Phone, Windows Server, and Windows Azure. It consists of the common language runtime (CLR) and the .NET Framework class library, which includes classes, interfaces, and value types that support an extensive range of technologies. The .NET Framework provides a managed execution environment, simplified development and deployment, and integration with a variety of programming languages, including Visual Basic and Visual C#. [MS_DotNet_Def]
  • 7. 7 Introduction to .NET The .NET Framework is a development platform for building apps for Windows, Windows Phone, Windows Server, and Windows Azure. It consists of the common language runtime (CLR) and the is This framework .NET Framework class library, which includes installed by default classes, interfaces, and value types that support on any Windows an extensive device. It’s also range of technologies. used for Silverlight. The .NET Framework provides a managed execution environment, simplified development and deployment, and integration with a variety of programming languages, including Visual Basic and Visual C#. [MS_DotNet_Def]
  • 8. 8 Introduction to .NET The .NET Framework is a development platform for building apps for Windows, Windows Phone, Windows Server, and Windows Azure. It consists of the common language runtime (CLR) and the .NET Framework class library, which includes classes, interfaces, and value types that support an extensive range of technologies. The .NET Framework provides a managed execution environment, simplified development and deployment, and integration with a variety of programming languages, including Visual Basic and Visual C#. [MS_DotNet_Def] [Wiki_Components]
  • 9. 9 Introduction to .NET The .NET Framework is a development platform for building apps for Windows, Windows Phone, Windows Server, and Windows Azure. It consists of the common language runtime (CLR) and the .NET Framework class library, which includes Enhances the security (e.g. no classes, interfaces, and value types that support an extensive buffer overflow is possible). range of technologies. The .NET Framework provides a managed execution environment, simplified development and deployment, and integration with a variety of programming languages, including Visual Basic and Visual C#. [MS_DotNet_Def]
  • 10. 10 Introduction to .NET The .NET Framework is a development platform for building apps for Windows, Windows Phone, Windows Server, and Windows Azure. It consists of the common language runtime (CLR) and the .NET Framework class library, which includes also compile You can F#, IronPython, extensive classes, interfaces, and value types that support an IronRuby, J# etc… range of technologies. [Wiki_IL_Lang] The .NET Framework provides a managed execution environment, simplified development and deployment, and integration with a variety of programming languages, including Visual Basic and Visual C#. [MS_DotNet_Def]
  • 11. 11 Introduction to .NET  Sounds like Java!  Yes, because – It’s byte code => the code can be reversed – Multiplatform (can also run on Linux using Mono)  No, because – Different versioning scheme • All versions of .NET but 1.0 are still supported • Supported versions get security patches (1.1, 2.0, 3.0, 3.5, 4.0, 4.5) – The .NET framework is pre-installed on Windows
  • 12. 12 Introduction to .NET  .NET also features runtime Trust Level – An app running with Trust Level set to medium cannot e.g. access the registry or files outside the app’s folder [MS_Trust] – This is not related to the Windows Mandatory Integrity Control (MIC)  Close interaction of ASP.NET with IIS  .NET is not (yet?) as targeted / vulnerable as Java  You can compile .NET code on any Windows device
  • 13. 13 Agenda     Introduction to .NET Configuration of (ASP).NET applications New features of (ASP).NET 4.5 Key security points of application lifecycle – Development – Deployment – Operations – Third party component review
  • 14. 14 Config of (ASP).NET applications  Typical configuration – Proxy settings – Cryptographic keys – Cookie settings – Compilation details – Error handling – Retail mode – Trust level – Database connections – ViewState parameters – Trace configuration – Request validation – Application settings –… – See • • • [MS_AspNet_config] [MS_Net_config] [HL_Decompile]
  • 15. 15 Config of (ASP).NET applications  Configuration is based on .config files  For .NET executables, the config hierarchy is – Server level config (machine.config) – Application specific config ([AppName].exe.config) – Optional user settings (roaming.config & user.config)
  • 16. 16 Config of (ASP).NET applications  Configuration is based on .config files  For .NET executables, the config hierarchy is – Server level config (machine.config) – Application specific config ([AppName].exe.config) – Optional user settings (roaming.config & user.config)  Do not use Group Policy Preferences to distribute configurations in your Windows domain! – For more details see [CSNC_GPP]
  • 17. 17 Config of (ASP).NET applications  Config hierarchy for ASP.NET code – Server level config (machine.config & web.config) – Web site (web.config) – ASP.NET application and subfolders (web.config) – Further details available in [ASPNET_config]  IIS configuration is also involved for ASP.NET code • %windir%system32inetsrvconfigApplicationHost.config
  • 18. 18 Config of (ASP).NET applications Source: [CP_net_config]
  • 19. 19 Config of (ASP).NET applications  The configuration can be locked at any level [MS_lock_config]  The configuration on the server level is dependent of the .NET version and CPU architecture • %systemroot%Microsoft.NETFramework[64][version]CO NFIG  It is possible to encrypt sections of the configuration file (only useful for web.config files) [MS_enc_config]
  • 20. 20 Config of (ASP).NET applications  Why encrypt the configuration file? – Limits the impact of file inclusion issues or leaking code / configuration files – An attacker first needs to execute a command on the web server before being the config is in clear text  Recommended sections to encrypt – <MachineKey /> – <ConnectionStrings /> – Any other settings where keys, passwords or endpoint information is stored
  • 21. 21 Agenda     Introduction to .NET Configuration of (ASP).NET applications New features of (ASP).NET 4.5 Key security points of application lifecycle – Development – Deployment – Operations – Third party component review
  • 22. 22 New features of (ASP).NET 4.5  Microsoft is continuously improving .NET – Task based async model – Enhanced Strong Naming for Windows Store apps – WebSockets, etc  Especially security relevant is that – The standalone Anti-XSS library is now integrated – Several changes occurred in the handling of cryptography
  • 23. 23 New features of (ASP).NET 4.5  Why such crypto improvements in version 4.5? – “Cryptography in the Web: The Case of Cryptographic Design Flaws in ASP.NET” research of [Duong_Rizzo] – Padding oracle attack patched by Microsoft for all versions in MS10-070 – All details of these changes in (ASP).NET 4.5 are described in [MS_Improv_1] to [MS_Improv_3]
  • 24. 24 New features of (ASP).NET 4.5  Visible impact of (ASP).NET 4.5 – Several changes are opt-in • Action is required! – ViewState fields will be encrypted – Some compatibility with ASP.NET 2.0 may/will be lost
  • 25. 25 New features of (ASP).NET 4.5  Extract of the appendix of this talk:
  • 26. 26 New features of (ASP).NET 4.5  Do these changes justify migration to .NET 4.5? – YES absolutely – Several defence in-depth mechanisms were added
  • 27. 27 Agenda     Introduction to .NET Configuration of (ASP).NET applications New features of (ASP).NET 4.5 Key security points of application lifecycle – Development – Deployment – Operations – Third party component review
  • 28. 28 Key security points of app lifecycle > Development Why not use this opportunity to start setting up a Security Development Lifecycle for your apps? [MS_SDL]
  • 29. 29 Key security points of app lifecycle > Development Why not use this opportunity to start setting up a Security Development Lifecycle for your apps? [MS_SDL] Source http://www.microsoft.com/security/sdl/
  • 30. 30 Key security points of app lifecycle > Development Why not use this opportunity to start setting up a Security Development Lifecycle for your apps? [MS_SDL] Source http://www.microsoft.com/security/sdl/
  • 31. 31 Key security points of app lifecycle > Development  Develop on .NET 4.5 (especially for web apps) and for a medium trust level whenever possible  Use the free Microsoft SDL tools while developing – FxCop [MS_FxCop] & CATNET [MS_CATNET]  Do not turn off security features – Request Validation, ViewState MAC, …  Do not rely on client side only validation or include/hide secrets in client side applications  Teach best practices to your developers…
  • 32. 32 Key security points of app lifecycle > Deployment  Lock down the server and app configuration  Consider an obfuscator for your client side apps – Executable or Silverlight only  Do not use GPPs to distribute configurations!  Consider reducing the trust level of your app whenever possible  Perform a general server hardening (OS & IIS) – Again, this “infrastructure” part is not covered here
  • 33. 33 Key security points of app lifecycle > Operations  Run ASP.NET 4.5 with medium trust apps[MS_Trust_expl]  Encrypt sensitive sections of the web.config file  Manage the cryptographic keys you use! – Web.config encryption & ASP.NET features (Machine Key)  Patch the server & configure IIS adequately  Communicate – Be ready in case of a (security) incident – All technical stakeholders should come together…
  • 34. 34 Key security points of app lifecycle > Third party component review  The same recipes apply: – As it’s just byte code, let’s decompile the application! Loi sur le droit d’auteur Art. 21 Décryptage de logiciels 1 La personne autorisée à utiliser un logiciel peut se procurer, par le décryptage du code du programme, des informations sur des interfaces avec des programmes développés de manière indépendante. Elle peut opérer elle-même ou mandater un tiers. 2 Les informations sur des interfaces obtenues par le décryptage du code du programme ne peuvent être utilisées que pour développer, entretenir et utiliser des logiciels interopérables, pourvu qu'une telle utilisation ne porte pas atteinte à l'exploitation normale du programme ni ne cause un préjudice injustifié aux intérêts légitimes de l'ayant droit.
  • 35. 35 Key security points of app lifecycle > Third party component review  The same recipes apply: – Audit source code & configuration – Audit assemblies with static analysis tools – Run the component with the lowest possible trust level – Regenerate all keys / secrets shipped by the vendor  Manage the component by – Monitoring for security patches – Update it periodically
  • 36. 36 Agenda     Introduction to .NET Configuration of (ASP).NET applications New features of (ASP).NET 4.5 Key security points of application lifecycle – Development – Deployment – Operations – Third party component review
  • 37. 37 Conclusion  Top security issues in .NET include – Application information leak Solved by configuration (server or app) Static code analysis No secrets in the code! Consider an obfuscator • Verbose error messages • Secrets stored within the code (executable or Silverlight) – Injections Education of devs, code review & static analysis • SQL injections due to unsafe database requests – Unsafe application settings • Unencrypted communication • Unsafe distribution of credentials Education of devs, code and config review No secrets in the code! Rely on Windows auth. when possible
  • 38. 38 Conclusion  Top security issues in ASP.NET include – Application information leak • Secrets stored in the ViewState • Verbose error messages – Unsafe application settings • Session cookie parameters • Request validation disabled • Unencrypted configuration file – Injections Configure this field to be encrypted or migrate to ASP.NET 4.5 Hardening / lockdown of the configuration (server or app) Static code analysis Encryption of configuration file Education of devs, code review & static analysis • XSS due to user inputs in JS or HTML attributes • SQL injections due to unsafe database requests
  • 39. 39 Conclusion  .NET is a secure framework following the SD3+C principle[MS_SD3C]: – Secure by Design, Secure by Default, Secure in Deployment, and Communications  Your applications can also benefit from this security during their lifecycle  This talk focused on application security – You still have to harden your infrastructure (OS & IIS)!
  • 42. 42 References (1/2)            [MS_DotNet_Def] http://msdn.microsoft.com/en-us/library/w0x726c2.aspx [Wiki_Components] http://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/DotNet.svg/250px-DotNet.svg.png [Wiki_IL_Lang] http://en.wikipedia.org/wiki/Category:.NET_programming_languages [ASPNET_config] http://msdn.microsoft.com/en-Us/library/ms178685.aspx [CP_net_config] http://www.codeproject.com/Articles/19675/Cracking-the-Mysteries-of-NET-2-0Configuration [CSNC_GPP] http://blog.csnc.ch/2012/04/exploit-credentials-stored-in-windows-group-policypreferences/ [HL_Decompile] http://media.hackinglab.com/largefiles/7205/Paper_DisassembleDotNetClient_v2.0.pdf [MS_lock_config] http://msdn.microsoft.com/en-us/library/ms228167(v=vs.100).aspx [MS_AspNet_config] http://msdn.microsoft.com/en-us/library/zeshe0eb(v=vs.85).aspx [MS_Net_config] http://msdn.microsoft.com/en-us/library/1fk1t1t0.aspx [Duong_Rizzo] http://www.ieee-security.org/TC/SP2011/PAPERS/2011/paper030.pdf
  • 43. 43 References (2/2)             [MS_Improv_1] http://blogs.msdn.com/b/webdev/archive/2012/10/22/cryptographicimprovements-in-asp-net-4-5-pt-1.aspx [MS_Improv_2] http://blogs.msdn.com/b/webdev/archive/2012/10/23/cryptographicimprovements-in-asp-net-4-5-pt-2.aspx [MS_Improv_3] http://blogs.msdn.com/b/webdev/archive/2012/10/24/cryptographicimprovements-in-asp-net-4-5-pt-3.aspx [MS_enc_config] http://msdn.microsoft.com/en-us/library/dtkwfdky(v=VS.100).aspx [MS_SD3C] http://msdn.microsoft.com/en-us/library/ms995349.aspx [MS_SDL] http://www.microsoft.com/security/sdl/default.aspx [MS_FxCop] http://www.microsoft.com/en-us/download/details.aspx?id=6544 [MS_CATNET] http://www.microsoft.com/en-us/download/details.aspx?id=5570 [MS_Trust] http://msdn.microsoft.com/en-us/library/tkscy493(v=vs.85).aspx [MS_Trust_expl] http://msdn.microsoft.com/En-Us/library/wyts434y.aspx [MS_Run_45] http://blogs.msdn.com/b/webdev/archive/2012/11/19/all-about-httpruntimetargetframework.aspx [MS_Trust_HowTo] http://msdn.microsoft.com/en-us/library/ff648344.aspx
  • 44. 44 Configuration checklist  This checklist is by no means complete. It’s just the starting point of your configuration journey…  Depending on your situation, you may want to configure these settings on a server (e.g. machine.config) and lock them or on an application level (web.config)
  • 45. 45 Configuration checklist  List of configuration which should be forced on an integration / production server  In the machine.config for all .NET versions […] <system.web> <deployment retail="true" /> <pages viewStateEncryptionMode="Always" /> <httpCookies httpOnlyCookies="true" requireSSL="true" /> </system.web> <authentication> <forms requireSSL= true" /> </authentication> […]
  • 46. 46 Configuration checklist  List of settings which are secure by default. They should not be disabled in configuration or code: – For the <pages> configuration section • Property enableEventValidation should stay true • Property enableViewStateMac should stay true • Property validateRequest should stay true – For the <forms> configuration section • Property enableCrossAppRedirects should stay disabled • Property protection should stay all
  • 47. 47 Configuration checklist  List of settings which are secure by default. They should not be disabled in configuration or code: – For the <trace> configuration section • Property enabled should stay false – For the <customErrors> configuration section • Property mode should stay RemoteOnly or On – For the <compilation> configuration section • Property debug should stay false  All these properties are set to a safe value if <system.web><deployment retail="true" />
  • 48. 48 Configuration checklist  If you run ASP.NET 4.5 – Ensure section <httpRuntime> enables all new feature with attribute targetFramework="4.5"[MS_Run_45] – Once done, ensure the following config sections are either absent or set to the following values: • <machineKey compatibilityMode="Framework45" /> • <compilation targetFramework="4.5" /> • <pages controlRenderingCompatibilityVersion="4.5"/> – Configure AntiXSS to be the default encoding routine <httpRuntime […] encoderType="System.Web.Security.AntiXss. AntiXssEncoder,System.Web, Version=4.0.0.0, Culture=neutral, Pu blicKeyToken=b03f5f7f11d50a3a" />
  • 49. 49 Configuration checklist  Trust level and their impact [MS_Trust_HowTo] – Example of a web app running with medium trust <system.web> <trust level="Medium" originUrl="" /> </system.web> – This web application would not be able to • • • • • • • • Call unmanaged code. Call serviced components. Write to the event log. Access Microsoft Message Queuing queues. Access ODBC, OleDb, or Oracle data sources. Access files outside the application directory. Access the registry. Make network or Web service calls (allowed URLs can be defined) Restrictions due to high trust level Additional restrictions due to medium trust level

Editor's Notes

  1. Why no code? Because it’s language dependentSeveral references and examples are provided in the appendixWho is technical related in the room?
  2. Master ofAdvanced StudiesSAPMicrosoftNevisProxy / SESOpen source softwareVulnerabilities in Microsoft SharePoint Server Could Allow Remote Code Execution
  3. Max 04:00
  4. Provides memory management (no pointers, free etc)Provides thread and exception handlingGarbage collectionCombination of various .NET languages in a projectAdvantages of managed code: http://stackoverflow.com/questions/5325668/managed-code-advantages
  5. Site webExecutablesServicesSilverlightPlugin pour Office…
  6. Provides memory management (no pointers, free etc)Provides thread and exception handlingGarbage collectionCombination of various .NET languages in a projectAdvantages of managed code: http://stackoverflow.com/questions/5325668/managed-code-advantages
  7. Provides memory management (no pointers, free etc)Provides thread and exception handlingGarbage collectionCombination of various .NET languages in a projectAdvantages of managed code: http://stackoverflow.com/questions/5325668/managed-code-advantages
  8. Provides memory management (no pointers, free etc)Provides thread and exception handlingGarbage collectionCombination of various .NET languages in a projectAdvantages of managed code: http://stackoverflow.com/questions/5325668/managed-code-advantages
  9. Max 12:00
  10. enableViewStateMac, validateRequest, viewStateEncryptionMode, &lt;machineKeycompatibilityMode=&quot;Framework20SP1&quot; /&gt;
  11. We can discuss if this enhances the integrity of the file. Yes for an unskilled attacker (not able to change a given config) but this feature could also be used to backdoor a configuration (e.g. decrypt web.config, alter config with backdoor, encrypt web.config).
  12. Max 19:00
  13. Added entropyKey derivationPurpose of encryptionAbility to write your own crypto provider for a variety of usage…
  14. Added entropyKey derivationPurpose of encryptionAbility to write your own crypto provider for a variety of usage…
  15. Added entropyKey derivationPurpose of encryptionAbility to write your own crypto provider for a variety of usage…
  16. Added entropyKey derivationPurpose of encryptionAbility to write your own crypto provider for a variety of usage…
  17. ASP.NET 4.5 does not run on Windows 2003, only Windows 2008Windows 2003 R2 will end its support in July 2015 and IIS 7.0 / 7.5 is recommended anyway…
  18. Max 25:00
  19. Microsoft SDL Conformsto ISO/IEC 27034-1:2011SO/IEC 27034 provides guidance for a risk based and continuously improving software security management system applied across the application lifecycle.
  20. Microsoft SDL Conformsto ISO/IEC 27034-1:2011SO/IEC 27034 provides guidance for a risk based and continuously improving software security management system applied across the application lifecycle.
  21. Microsoft SDL Conformsto ISO/IEC 27034-1:2011SO/IEC 27034 provides guidance for a risk based and continuously improving software security management system applied across the application lifecycle.
  22. Max 35:00
  23. It’s here where you break the hacker’s spirit.
  24. It’s here where you break the hacker’s spirit.