Developer InformationThere are three main ways to extend ModSecurity functionality: We will outline all three methods below.Community Developer SupportCommunity developer support for ModSecurity is available on the mod-security-developers mailing list. You must subscribe first in order to post. The list archives are available as Developer Archives, Modify the ModSecurity Source CodeIf you are planning to develop ModSecurity code, you should be familiar with the following:
If you would like to directly contribute source code patches/updates to the ModSecurity SVN Source Code Repository, please follow these steps:
Cloning the SVN RepositoryIf you would like to test out new features that are available in development releases, just follow these steps to sync with the SourceForge SVN repository:
Building Custom ModSecurity ModulesThe ModSecurity archive includes some example module extensions in the
You can also review a community contributed transformation function module from Marc Stern called t:cmdLine. This functionaliy has since been directly integrated into the ModSecurity v2.6 code but this module is a great example of extending ModSecurity using modules. NOTE: ModSecurity must be compiled with API support to use this feature (do not use -DNO_MODSEC_API).Building the Example Custom Modules1) Example custom transformation function moduleModule mod_tfn_reverse.c creates a custom transformation function "reverse" that reverses the content it receives on input. # Compile as a normal user apxs -ca mod_tfn_reverse.c # Install as superuser sudo apxs -i mod_tfn_reverse.la2) Example custom operator module Module mod_op_strstr.c creates a custom operator "strstr" that implements fast matching using the Boyer-Moore-Horspool algorithm. Compiling this module is more involved because it requires access to ModSecurity structures. # Compile as a normal user apxs -I3) Example custom target variable module Module mod_var_remote_addr_port.c creates a custom variable "REMOTE_ADDR_PORT" that combines the REMOTE_ADDR and REMOTE_PORT into a.b.c.d:port format. Compiling this module is more involved because it requires access to ModSecurity structures. # Compile as a normal user apxs -I Using the ModulesOnce the modules are built and installed, you load them like any other Apache module, but they must be loaded *after* the mod_security2.so module. # Load ModSecurity LoadModule security2_module modules/mod_security2.so # Load ModSecurity custom modules LoadModule tfn_reverse_module modules/mod_tfn_reverse.so LoadModule op_strstr_module modules/mod_op_strstr.so LoadModule var_remote_addr_port_module modules/mod_var_remote_addr_port.so # All three custom var/op/tfn used SecRule REMOTE_ADDR_PORT "@strstr 8765:4.3.2.1" "t:reverse" Utilize the Lua APIIf you find that the standard SecRule rules language is not adequate for your situation, you may look to utilize the Lua API by either using the SecRuleScript directive or by using the exec action with Lua script (.lua extension). You should read the Lua Reference Manaul documentation. Here are links to various community use-cases for ModSecurity+Lua:
|
JIRA Tickets
Submit a Feature Request, Improvement or Bug |
