11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2: <strong>Threats</strong> <strong>and</strong> Countermeasures 25The following section examines these vulnerabilities in detail, including what makesthese vulnerabilities possible.Buffer OverflowsBuffer overflow vulnerabilities can lead to denial of service attacks or code injection.A denial of service attack causes a process crash;. code injection alters the programexecution address to run an attacker’s injected code. The following code fragmentillustrates a common example of a buffer overflow vulnerability.void SomeFunction( char *pszInput ){char szBuffer[10];// Input is copied straight into the buffer when no type checking is performedstrcpy(szBuffer, pszInput);. . .}Managed .NET code is not susceptible to this problem because array bounds areautomatically checked whenever an array is accessed. This makes the threat of bufferoverflow attacks on managed code much less of an issue. It is still a concern,however, especially where managed code calls unmanaged APIs or COM objects.Countermeasures to help prevent buffer overflows include:● Perform thorough input validation. This is the first line of defense against bufferoverflows. Although a bug may exist in your application that permits expectedinput to reach beyond the bounds of a container, unexpected input will be theprimary cause of this vulnerability. Constrain input by validating it for type,length, format <strong>and</strong> range.● When possible, limit your application’s use of unmanaged code, <strong>and</strong> thoroughlyinspect the unmanaged APIs to ensure that input is properly validated.● Inspect the managed code that calls the unmanaged API to ensure that onlyappropriate values can be passed as parameters to the unmanaged API.● Use the /GS flag to compile code developed with the Microsoft Visual C++ ®development system. The /GS flag causes the compiler to inject security checksinto the compiled code. This is not a fail-proof solution or a replacement for yourspecific validation code; it does, however, protect your code from commonlyknown buffer overflow attacks. For more information, see the .NET FrameworkProduct documentation http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vclrfGSBuffer<strong>Security</strong>.asp <strong>and</strong> Microsoft Knowledge Basearticle 325483 “<strong>Web</strong>Cast: Compiler <strong>Security</strong> Checks: The –GS compiler switch.”

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!