Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More
Get access to immediate incident response assistance.
Get access to immediate incident response assistance.
Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More
This blog post has also been posted on the Microsoft Security Research and Defense site:
By:
Vulnerabilities in on-line services, like cross-site scripting, cross-site request forgery, or even information disclosure, are important areas of focus for the Microsoft Security Response Center (MSRC). Over the last few years Microsoft has developed a number of tools capable of mitigating selected web specific vulnerabilities (for example, UrlScan). To help on this front we have participated in a community effort to bring the popular open source module ModSecurity to the IIS platform. Yesterday at Black Hat Las Vegas, we have announced the availability of an RC version and we expect that stable release will be available soon.
Although the source code of ModSecurity's IIS components is fully published and the binary building process is publicly described (see mod_security/iis/winbuild/howto.txt in SourceForge repository), it is highly not recommended to self-build the module for non-research or non-development purpose.
A standard MSI installer of ModSecurity for IIS 7 and later versions is available from SourceForge files repository of ModSecurity project and in the future designated maintainers will be keeping it updated with latest patches and minor versions of the module.
The IIS installer does not interfere with currently running web applications. This means that the installation process must be followed by an application pool restart or recycling in order to load the new module into the application pool process. For the RC version of the module the restart/recycle step is also highly recommended each time a ModSecurity configuration file has been changed:
After successful load of the module into the application pool process a series of informational events is recorded in the application event log:
Runtime messages and notifications generated during the operational phase, both coming from the user-defined rules and system specific events or errors, are sent to the same application event log repository.
To apply a ModSecurity configuration file to a web application or a path, one has to use IIS configuration schema extension, like in the example below:
<?xml version="1.0" encoding="UTF-8"?><configuration> <system.webServer> <ModSecurity enabled="true" configFile="c:\inetpub\wwwroot\test.conf" /> </system.webServer></configuration>
The c:\inetpub\wwwroot\test.conf config file is a regular ModSecurity configuration containing the same directives as used on the Apache web server.
The most common application of ModSecurity is a protection layer called "virtual patching" (see Resources section, [5]). Using two recent vulnerabilities as an example we would like to show how this layer can be specified in an environment with IIS server running with ModSecurity.
In December 2011 a vulnerability was addressed in ASP.NET that allowed attackers to cause excessive processor load on most ASP.NET web applications. The hash collision issue required attacker to send a large (typically 1MB or 4MB) POST request to the server, with tens of thousands of arguments with specially crafted names. There are at least four ways to mitigate this kind of attack:
The approach of checking for the presence of repetitive payload is the most sophisticated one and it can be implemented in ModSecurity using the following chain of rules:
SecRule &ARGS "@ge 1000" "chain,id:1234,phase:2,t:none,deny,msg:'Possible Hash DoS Attack Identified.',tag:'http://blogs.technet.com/b/srd/archive/2011/12/27/more‑information‑about‑the‑december‑2011‑asp‑net‑vulnerability.aspx?Redirected=true'" SecRule REQUEST_BODY "^\w*?=(.*?)&\w*?=(.*?)&\w*?=(.*?)&\w*?=(.*?)&" "chain,capture" SecRule TX:1 "@streq %{tx.2}" "chain,setvar:tx.hash_dos_match=+1" SecRule TX:2 "@streq %{tx.3}" "chain,setvar:tx.hash_dos_match=+1" SecRule TX:3 "@streq %{tx.4}" "chain,setvar:tx.hash_dos_match=+1" SecRule TX:HASH_DOS_MATCH "@eq 3"
When this rule is loaded into an IIS server configuration and the attack is launched on the protected path, the Windows application event log will record an access denied message from ModSecurity:
At the same time the attacker will see HTTP response 403, stopping the attack before it reaches ASP.NET vulnerable component.
In July 2012, Microsoft patched a classic case of reflected cross-site scripting vulnerability in Microsoft SharePoint 2010. For the attacks to exploit the vulnerability it was enough to trick user into clicking on a malicious URL, like the one below:
http://sharepoint/_layouts/scriptresx.ashx?culture=en‑us&name=SP.JSGrid.Res&rev=laygpE0lqaosnkB4iqx6mA%3D%3D§ions=All<script>alert('Hacked!!!')</script>z
The script injected by the attacker could gain access to the entire data set available to the victim through the hacked SharePoint server.
One possible way to block this attack is a whitelist approach: let the URL with sections argument that does contain only valid characters pass through, while block all other URLs. Below is a ModSecurity rule implementing this approach for alphanumeric characters:
SecRule REQUEST_FILENAME "@contains /_layouts/scriptresx.ashx" "chain,phase:1,block,msg:'SharePoint Sections Param Violation - Illegal Chars" SecRule ARGS:sections "!@rx ^\w+$"
The rule included through ModSecurity config file into the SharePoint web.config file, generates the following event when any invalid character (indicating possible attack attempt) is discovered in the corresponding SharePoint URL:
We encourage you to download and try out the tool. If you have any feedback on your experiences with the tool, you can reach us at switech@microsoft.com or on the ModSecurity Users Mail-list.
The following people have contributed to the multi-platform effort of ModSecurity:
We would like to thank: Wade Hilmo and Nazim Lala, members of the Microsoft's IIS team , for their support and help in solving many technical problems.
[1] ModSecurity home page: http://www.modsecurity.org/
[2] OWASP Core Rule Set for ModSecurity: https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project
[3] http://blog.modsecurity.org/files/enough_with_default_allow_r1_draft.pdf
[4] http://www.modsecurity.org/documentation/Securing_Web_Services_with_ModSecurity_2.0.pdf
Trustwave is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.
Copyright © 2024 Trustwave Holdings, Inc. All rights reserved.