项目作者: jcmoraisjr

项目描述 :
HAProxy agent for ModSecurity web application firewall
高级语言: Dockerfile
项目地址: git://github.com/jcmoraisjr/modsecurity-spoa.git
创建时间: 2018-05-26T18:22:48Z
项目社区:https://github.com/jcmoraisjr/modsecurity-spoa

开源协议:Apache License 2.0

下载


HAProxy agent for ModSecurity

HAProxy agent (SPOA)
for ModSecurity web application firewall
(WAF).

Docker Repository on Quay

SPOP and HAProxy Version

The current SPOP version is v2, used since modsecurity-spoa v0.4. This agent version works on HAProxy 1.8.10 and newer.

SPOP v1 is used on modsecurity-spoa v0.1 to v0.3. This agent version works on HAProxy up to 1.8.9.

Agent Configuration

Command line syntax:

  1. $ docker run -p 12345:12345 quay.io/jcmoraisjr/modsecurity-spoa [options] [-- <config-file1> [<config-file2> ...] ]

config-files can be used either after -- (see above) or from -f option (see below).
The only difference is that the later supports only one filename. All config-files found
will be used, included in the same order as they have been declared.

Customize the Configuration Files

In order to use the default configuration in your customization, you should copy the following files from the image:

  1. docker create --name modsec quay.io/jcmoraisjr/modsecurity-spoa
  2. docker cp modsec:/etc/modsecurity .
  3. docker rm modsec

Download and customize the configuration files for either the ModSecurity repository or from OWASP repository.
Use the copied files from the previous code section in your run command:

  1. docker run -p 12345:12345 -v $PWD/modsecurity:/etc/modsecurity quay.io/jcmoraisjr/modsecurity-spoa -n 1

If you do not want to include the default configuration files and only use the configuration files (ex./ custom-config.conf) that you design, leave out the copied default configuration files from before in your run command:

  1. docker run -p 12345:12345 -v $PWD/modsecurity:/etc/modsecurity quay.io/jcmoraisjr/modsecurity-spoa -n 1 -- /etc/modsecurity/custom-config.conf

Running without Config Files

If no config-file is declared, the following will be used:

  • /etc/modsecurity/modsecurity.conf: ModSecurity recommended config, from ModSecurity repository
    • Changes: SecRuleEngine, changed from DetectionOnly to On
  • /etc/modsecurity/owasp-modsecurity-crs.conf: Generic attack detection rules for ModSecurity, from OWASP ModSecurity CRS repository
    • Changes: SecDefaultAction, phase:1 and phase:2, changed from log,auditlog,pass to log,noauditlog,deny,status:403

Options are: (from modsecurity agent -h)

  1. -h Print this message
  2. -d Enable the debug mode
  3. -f <config-file> ModSecurity configuration file
  4. -m <max-frame-size> Specify the maximum frame size (default : 16384)
  5. -p <port> Specify the port to listen on (default : 12345)
  6. -n <num-workers> Specify the number of workers (default : 10)
  7. -c <capability> Enable the support of the specified capability
  8. -t <time> Set a delay to process a message (default: 0)
  9. The value is specified in milliseconds by default,
  10. but can be in any other unit if the number is suffixed
  11. by a unit (us, ms, s)
  12. Supported capabilities: fragmentation, pipelining, async

HAProxy configuration

Configure modsecurity-spoa as a HAProxy SPOE agent. See also SPOE filter
doc
and SPOE spec.

Changes to haproxy.cfg - change 127.0.0.1:12345 below to the
modsecurity-spoa endpoint:

  1. frontend httpfront
  2. mode http
  3. ...
  4. filter spoe engine modsecurity config /etc/haproxy/spoe-modsecurity.conf
  5. http-request deny if { var(txn.modsec.code) -m int gt 0 }
  6. ...
  7. backend spoe-modsecurity
  8. mode tcp
  9. server modsec-spoa1 127.0.0.1:12345

Create a /etc/haproxy/spoe-modsecurity.conf:

  1. [modsecurity]
  2. spoe-agent modsecurity-agent
  3. messages check-request
  4. option var-prefix modsec
  5. timeout hello 100ms
  6. timeout idle 30s
  7. timeout processing 1s
  8. use-backend spoe-modsecurity
  9. spoe-message check-request
  10. args unique-id method path query req.ver req.hdrs_bin req.body_size req.body
  11. event on-frontend-http-request

Test with docker

  1. (cd ./test && ./run.sh)