Blame ext/README

Packit 284210
Custom ModSecurity Modules
Packit 284210
--------------------------
Packit 284210
Packit 284210
This directory contains three examples how you can extend
Packit 284210
ModSecurity without having to touch it directly, simply
Packit 284210
by creating custom Apache modules.
Packit 284210
Packit 284210
NOTE: ModSecurity must be compiled with API support
Packit 284210
      to use this feature (the API is enabled by default,
Packit 284210
      but it will have been disabled if you used -DNO_MODSEC_API).
Packit 284210
Packit 284210
Packit 284210
Building the Example Custom Modules
Packit 284210
-----------------------------------
Packit 284210
Packit 284210
1) Example custom transformation function module
Packit 284210
Packit 284210
Module mod_tfn_reverse.c creates a custom transformation
Packit 284210
function "reverse" that reverses the content it receives
Packit 284210
on input.
Packit 284210
Packit 284210
# Compile as a normal user
Packit 284210
  apxs -I<MODSECURITY_SOURCE_CODE> -I/usr/include/libxml2 \
Packit 284210
       -ca mod_tfn_reverse.c
Packit 284210
Packit 284210
  # Install as superuser
Packit 284210
  sudo apxs -i mod_tfn_reverse.la
Packit 284210
Packit 284210
Packit 284210
2) Example custom operator module
Packit 284210
Packit 284210
Module mod_op_strstr.c creates a custom operator "strstr"
Packit 284210
that implements fast matching using the Boyer-Moore-Horspool
Packit 284210
algorithm.
Packit 284210
Packit 284210
  # Compile as a normal user
Packit 284210
  apxs -I<MODSECURITY_SOURCE_CODE> -I/usr/include/libxml2 \
Packit 284210
       -ca mod_op_strstr.c
Packit 284210
Packit 284210
  # Install as superuser
Packit 284210
  sudo apxs -i mod_op_strstr.la
Packit 284210
Packit 284210
Packit 284210
3) Example custom target variable module
Packit 284210
Packit 284210
Module mod_var_remote_addr_port.c creates a custom variable "REMOTE_ADDR_PORT"
Packit 284210
that combines the REMOTE_ADDR and REMOTE_PORT into a.b.c.d:port format.
Packit 284210
Packit 284210
  # Compile as a normal user
Packit 284210
  apxs -I<MODSECURITY_SOURCE_CODE> -I/usr/include/libxml2 \
Packit 284210
       -ca mod_var_remote_addr_port.c
Packit 284210
Packit 284210
  # Install as superuser
Packit 284210
  sudo apxs -i mod_var_remote_addr_port.la
Packit 284210
Packit 284210
Packit 284210
3) Example custom request body parser module
Packit 284210
Packit 284210
Module mod_reqbody_example.c creates a custom request body parser named
Packit 284210
"EXAMPLE".  It does noting in particular, but shows the basic structure
Packit 284210
of such a module.
Packit 284210
Packit 284210
  # Compile as a normal user
Packit 284210
  apxs -I<MODSECURITY_SOURCE_CODE> -I/usr/include/libxml2 \
Packit 284210
       -ca mod_reqbody_example.c
Packit 284210
Packit 284210
  # Install as superuser
Packit 284210
  sudo apxs -i mod_var_remote_addr_port.la
Packit 284210
Packit 284210
  # Write a phase 1 rule to set the parser
Packit 284210
  SecAction "phase:1,pass,nolog,ctl:requestBodyProcessor=EXAMPLE"
Packit 284210
Packit 284210
Packit 284210
Using the Modules
Packit 284210
-----------------
Packit 284210
Packit 284210
Once 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.
Packit 284210
Packit 284210
  # Load ModSecurity
Packit 284210
  LoadModule security2_module modules/mod_security2.so
Packit 284210
Packit 284210
  # Load ModSecurity custom modules
Packit 284210
  LoadModule tfn_reverse_module modules/mod_tfn_reverse.so
Packit 284210
  LoadModule op_strstr_module modules/mod_op_strstr.so
Packit 284210
  LoadModule var_remote_addr_port_module modules/mod_var_remote_addr_port.so
Packit 284210
Packit 284210
  # All three custom var/op/tfn used
Packit 284210
  SecRule REMOTE_ADDR_PORT "@strstr 1.2.3.4:5678" "t:reverse"
Packit 284210