Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

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.

Microsoft Exchange Server Attacks
Stay protected against emerging threats
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
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
SpiderLabs Blog

ModSecurity 2: Variables, Collections and Transaction Scoring

Variables and collections are concepts new to ModSecurity 2. ModSecurity 1.x does allow you to use the "setvar" and "setnote" actions to create, change, or remove the request environment variables and request notes (request notes are an Apache facility that can be used to communicate with other modules). In v2 the concept was further extended with the introduction of transaction variables.

Variables are grouped into a collection, which is essentially a separate name space you can work with. Transaction variables are part of the transaction collection, which is a built-in collection called "TX". This collection is created automatically in the request initialisation phase and thus always available to your rules. It is also automatically deleted at the end of each request. ModSecurity 2 also supports persistent collections (variables placed in them will be available to you across requests) but in order to use them you have to manage them manually. This is something I will cover in a separate blog post shortly.

Collection variables are manipulated with the "setvar" action. To create a new variable simply assign value to it. To delete it, prefix the name with an exclamation mark. You must prefix each variable name with the name of the collection it belongs to.

setvar:tx.score=10 setvar:!tx.score

There are two variable types: strings and counters. Strings are just text; you can create them, access them, or delete them. Counters are positive integers. In addition to the operations supported by the sting variable type, counters can be incremented or decremented.

setvar:tx.score=+5 setvar:tx.score=-10

Transaction variables allow you to employ a fundamentally different approach in your rule sets. In ModSecurity 1.9.x. you could either interrupt a transaction or issue a warning. In ModSecurity 2 you can use scoring-based rule sets. The idea is to assign a score to every transaction and set it to zero initially. Then you write a series of rules to inspect transactions. But you don't want the rules to interrupt transactions straight away. Instead, you want them to just increment the transaction score. At the end of your rule set you can evaluate the transaction score and decide what to do with the transaction. Here is a complete example:

# A series of rules to evaluate transaction SecRule ARGS KEYWORD1 pass,setvar:tx.score=+5 SecRule ARGS KEYWORD2 pass,setvar:tx.score=+5 SecRule ARGS KEYWORD3 pass,setvar:tx.score=+5 SecRule ARGS KEYWORD4 pass,setvar:tx.score=+5   # Decide what to do with transaction SecRule TX:SCORE "@gt 15" deny 

Latest SpiderLabs Blogs

Welcome to Adventures in Cybersecurity: The Defender Series

I’m happy to say I’m done chasing Microsoft certifications (AZ104/AZ500/SC100), and as a result, I’ve had the time to put some effort into a blog series that hopefully will entertain and inform you...

Read More

Trustwave SpiderLabs: Insights and Solutions to Defend Educational Institutions Against Cyber Threats

Security teams responsible for defending educational institutions at higher education and primary school levels often find themselves facing harsh lessons from threat actors who exploit the numerous...

Read More

Breakdown of Tycoon Phishing-as-a-Service System

Just weeks after Trustwave SpiderLabs reported on the Greatness phishing-as-a-service (PaaS) framework, SpiderLabs’ Email Security team is tracking another PaaS called Tycoon Group.

Read More