Lighttpd: mod_security via mod_magnet

In most large enterprises there is a requirement to comply with various standards. The hot potato in the Ecommerce space at the moment (and has been for a few years!) is PCI-DSS.

At $WORK we have to comply with PCI-DSS with the full audit and similar occurring due to the number of transactions we perform. Recently we’ve deployed lighttpd for one of our platforms, which has caused an issue for our Information Security Officers and Compliance staff.

PCI-DSS 6.6 requires EITHER a Code review to be preformed, which whilst this may seem to be an easy task, when you’re talking about complex enterprise applications following a very……… agile development process it’s not always an option. The other option is to use a WAF (Web Application Firewall). Now there are multiple products available that sit upstream and perform this task. There is however an issue if you use SSL for your traffic. Most WAF will not do the SSL decryption / reencryption between the client and server (effectively becoming a Man in the Middle). There are however a few products which do this, F5 networks’ ASM being one that springs to mind. Unfortunately this isn’t always an option due to licensing fees and similar. An alternative is to run a WAF on the server its self. A common module for this is Mod_Security for Apache. Unfortunately, a similar module does not exist for Lighttpd.

In response to $WORKs requirement for this I’ve used mod_magnet to run a small lua script to emulate the functionality of mod_security (to an extent at least!). Please note that mod_magent is blocking, so will cause any requests to be blocked until the mod_magnet script has completed, so be very careful with the script, and ensure that it’s not causing any lag in a test environment, prior to deploying into live!

Below is a copy of an early version of the script (most of the mod_security rules that we have are specific to work, so are not being included for various reasons), however I’ll post updates to this soon.

/etc/lighttpd/mod_sec.lua

The following needs to be added to lighttpd.conf to attach this LUA script via mod magnet

*Update – 23 Aug 09* Updated to return code even if one test passes*

Comments or suggestions are appreciated!

Published by

Welby

Welby McRoberts is Lead Infrastrucure engineer at a large managed hosting & cloud computing company working on large-scale deployments and solutions. Follow Welby on Twitter @welbymcroberts or his Personal Site

8 thoughts on “Lighttpd: mod_security via mod_magnet”

  1. I think you made a little mistake at the end of your script. The value of ret is overwritten the second time thus the request is *not* dropped if the user agent check is succesful.
    You need to check ret after the function call to SQLInjection.

  2. Hi Joschi

    Thanks for this, I'll get this example updated some time this week, the script in use at $WORK is much more complex than this example and has this fix already in place.

  3. Thank you very much! Now I can feel better about making the leap from Apache. Much appreciated… Patiently awaiting the updated example 🙂

  4. @Alex : This is just an example, which as you say has flaws such as the case changes, and infact if you encode the string the same result will occur. Its by no means 'production' ready, its was more of an example for others to use and expand on 🙂

  5. Do you find that the more complex and full-blown version of this script you use at $WORK gives you acceptable performance? I like the possibilities that mod_magnet offers but the fact that it is completely blocking makes me a little bit nervous about writing long and complicated security scripts for it.

    1. I’ve since moved from that $WORK, but as such we didn’t notice any major issues with performance. My advise is always however to test, test and test again!

Leave a Reply

Your email address will not be published. Required fields are marked *