From a5ec06de2c2bb71bbd16050512e08b5b05749163 Mon Sep 17 00:00:00 2001 From: Thierry FOURNIER Date: Mon, 10 Apr 2017 23:47:23 +0200 Subject: [PATCH] MINOR: Add ModSecurity wrapper as contrib This patch contains a base for a modsecurity wrapper in HAProxy using SPOE. --- contrib/modsecurity/Makefile | 45 + contrib/modsecurity/README | 132 ++ contrib/modsecurity/modsec_wrapper.c | 639 +++++++++ contrib/modsecurity/modsec_wrapper.h | 34 + contrib/modsecurity/spoa.c | 1916 ++++++++++++++++++++++++++ contrib/modsecurity/spoa.h | 53 + 6 files changed, 2819 insertions(+) create mode 100644 contrib/modsecurity/Makefile create mode 100644 contrib/modsecurity/README create mode 100644 contrib/modsecurity/modsec_wrapper.c create mode 100644 contrib/modsecurity/modsec_wrapper.h create mode 100644 contrib/modsecurity/spoa.c create mode 100644 contrib/modsecurity/spoa.h diff --git a/contrib/modsecurity/Makefile b/contrib/modsecurity/Makefile new file mode 100644 index 000000000..72956f9e9 --- /dev/null +++ b/contrib/modsecurity/Makefile @@ -0,0 +1,45 @@ +DESTDIR = +PREFIX = /usr/local +BINDIR = $(PREFIX)/bin + +CC = gcc +LD = $(CC) + +ifeq ($(MODSEC_INC),) +MODSEC_INC := modsecurity-2.9.1/INSTALL/include +endif + +ifeq ($(MODSEC_LIB),) +MODSEC_LIB := modsecurity-2.9.1/INSTALL/lib +endif + +ifeq ($(APACHE2_INC),) +APACHE2_INC := /usr/include/apache2 +endif + +ifeq ($(APR_INC),) +APR_INC := /usr/include/apr-1.0 +endif + +ifeq ($(LIBXML_INC),) +LIBXML_INC := /usr/include/libxml2 +endif + +CFLAGS = -g -Wall -pthread +LDFLAGS = -lpthread -levent -levent_pthreads -lcurl -lapr-1 -laprutil-1 -lxml2 -lpcre -lyajl +INCS += -I../../include -I../../ebtree -I$(MODSEC_INC) -I$(APACHE2_INC) -I$(APR_INC) -I$(LIBXML_INC) +LIBS = + +OBJS = spoa.o modsec_wrapper.o + +modsecurity: $(OBJS) + $(LD) $(LDFLAGS) $(LIBS) -o $@ $^ $(MODSEC_LIB)/standalone.a + +install: modsecurity + install modsecurity $(DESTDIR)$(BINDIR) + +clean: + rm -f modsecurity $(OBJS) + +%.o: %.c + $(CC) $(CFLAGS) $(INCS) -c -o $@ $< diff --git a/contrib/modsecurity/README b/contrib/modsecurity/README new file mode 100644 index 000000000..21ff37ef2 --- /dev/null +++ b/contrib/modsecurity/README @@ -0,0 +1,132 @@ +ModSecurity for HAProxy +----------------------- + +This is a third party deamon whoch speaks SPOE. It give requests send by HAProxy +to ModSecurity and returns the verdict. + + Compilation +--------------- + +You must compile ModSecurity in standalone mode. Below an example for +ModSecurity-2.9.1. Note that ModSecurity depends the Apache APR. I assume that +the Apache dependencies are installed on the system. + + ./configure \ + --prefix=$PWD/INSTALL \ + --disable-apache2-module \ + --enable-standalone-module \ + --enable-pcre-study \ + --without-lua \ + --enable-pcre-jit + make + make -C standalone install + mkdir -p $PWD/INSTALL/include + cp standalone/*.h $PWD/INSTALL/include + cp apache2/*.h $PWD/INSTALL/include + +Note that this compilation method works, but is a litle bit rustic. I cant +deal with Lua, I supposed that is a dependecies problem on my computer. + + Start the service +--------------------- + +After you have compiled it, to start the service, you just need to use "spoa" +binary: + + $> ./modsecurity -h + Usage: ./spoa [-h] [-d] [-p ] [-n ] [-f ] + -h Print this message + -d Enable the debug mode + -f Modsecurity configuration file + -m Specify the maximum frame size (default : 16384) + -p Specify the port to listen on (default: 12345) + -n Specify the number of workers (default: 5) + -c Enable the support of the specified capability + -t