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

Services
Capture
Managed Detection & Response

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

twi-managed-portal-color
Co-Managed SOC (SIEM)

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

twi-briefcase-color-svg
Advisory & Diagnostics

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

tw-laptop-data
Penetration Testing

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

twi-database-color-svg
Database Security

Prevent unauthorized access and exceed compliance requirements.

twi-email-color-svg
Email Security

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

tw-officer
Digital Forensics & Incident Response

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

tw-network
Firewall & Technology Management

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

Solutions
BY TOPIC
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
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
SpiderLabs Blog

ModSecurity 2.5 Phrase Match Operator Performance

Quite a few people have asked about the performance differences between using the regular expression (@rx) operator and using the phrase match (@pm or @pmFromFile) operator. Lately, I have been working on better methods of gathering performance statistics and want to share my findings.

The phrase match operator was added to enhance performance of matching a larger number of static phrases. For instance, you may want to look for a list of spam phrases in ARGS:

With the @rx Operator and Simple OR Expression:

SecRule ARGS \
"@rx ambien|cyclen|cyclobenzaprine|paxil|phendimetrazine|phentamine|phentermine|viagra|viagara" \
"phase:2,deny,status:403,log,alertlog,t:lowercase,msg:'Medical Spam Detected'"

With the @rx Operator and an Enhanced Expression (see Optimizing Regular Expressions):

SecRule ARGS \
"@rx (?:p(?:hen(?:t(?:er|a)m|dimetraz)ine|axil)|cycl(?:obenzaprine|en)|viaga?ra|ambien)" \
"phase:2,deny,status:403,log,alertlog,t:lowercase,msg:'Medical Spam Detected'"

With the @pm Operator:

SecRule ARGS \
"@pm ambien cyclen cyclobenzaprine paxil phendimetrazine phentamine phentermine viagra viagara" \
"phase:2,deny,status:403,log,alertlog,t:lowercase,msg:'Medical Spam Detected'"

 

To compare the performance of each of these, I used a utility I build for unit testing to execute the operators 10,000 times and took the average execution time. I generated a randomized list of 1,000 phrases between 2 and 8 characters in length. The following chart compares the processing time in milliseconds of each of the above operator types using from 0 to 200 phrases from the randomized phrase list. Each operator uses the same set of phrases. Note that this is the processing time of only the operator (no overhead of transformations, alerts or other aspects of executing the rule).

9453_5a40b961-727f-46a4-b446-2a94cf073610

As you can see, there is quite a difference in performance. The basic @rx operator performance decreases linearly as more phrases are added. While the optimized @rx operator performance does come close to leveling out, it is still slower than the @pm operator and the rule itself is quite difficult to read and maintain. In contrast, the @pm operator uses a constant, extremely low amount of processing time while the rule is easy to read and maintain.

While the @pm operator performs well, it is not very flexible and thus has limited use cases. The operator can only use static phrases (no patterns) and cannot currently be anchored (meaning it will match a partial target and/or a partial phrase in the target). If you need patterns or need to anchor matches to the beginning and/or end of the target or word boundaries, then you still must use the @rx operator. In this case an optimized regular expression is the way to go if you need the rule to perform well, which is why these are used in the Core Rules.

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