Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Services
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Security
Unlock the full power of Microsoft Security
Offensive Security
Solutions to maximize your security ROI
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats

Announcing the availability of ModSecurity extension for IIS

This blog post has also been posted on the Microsoft Security Research and Defense site:

By:

  • Greg Wroblewski, Microsoft Security Engineering Center
  • Ryan Barnett, Trustwave SpiderLabs

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.

Installation

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.

Configuration

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:

8589_30a1b2eb-1722-4bfe-a09a-0f8d4330e4ab

After successful load of the module into the application pool process a series of informational events is recorded in the application event log:

11205_ae3ad6e7-45e4-40fc-9116-913725d4e0de

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.

Examples of Protection

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.

CVE-2011-3414

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:

  • Restrict the request body size.
  • Restrict the number of arguments.
  • Identify repetitive payloads.
  • Check arguments names against PoC data.

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:

11625_c2a9943e-3cc5-4dfd-aefa-89db497fe8b7

At the same time the attacker will see HTTP response 403, stopping the attack before it reaches ASP.NET vulnerable component.

CVE-2012-1859

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&sections=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:

11726_c741aeab-b8bb-49bf-9e3d-cf31523dac91

Feedback

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.

Acknowledgments

The following people have contributed to the multi-platform effort of ModSecurity:

  • Microsoft – ModSecurity Port for IIS
    • Greg Wroblewski – Senior Security Developer
    • Suha Can – Security Researcher / Developer
  • Trustwave - ModSecurity
    • Ziv Mador – Director of Security Research
    • Ryan Barnett – Security Researcher Lead
    • Breno Pinto – ModSecurity Researcher & Developer
  • Open community - Security Port for Nginx
    • Alan Silva - Security Software Engineer at Locaweb

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.

Resources

[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

[5] https://www.blackhat.com/presentations/bh-dc-09/Barnett/BlackHat-DC-09-Barnett-WAF-Patching-Challenge-Whitepaper.pdf

ABOUT TRUSTWAVE

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.

Latest Intelligence

Discover how our specialists can tailor a security program to fit the needs of
your organization.

Request a Demo