mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Improvements, bug fixes and cleanup from Tom Donavan
This commit is contained in:
@@ -1,181 +1,191 @@
|
||||
============================================================
|
||||
Build notes for Windows from Tom Donovan
|
||||
============================================================
|
||||
These are the raw build notes from Tom Donovan for building
|
||||
ModSecurity 2.5.12 with Apache httpd 2.2.14 on Windows. Some
|
||||
day these should be incorporated into the official docs, but
|
||||
there has not yet been time, so they are included here in
|
||||
their raw format for now.
|
||||
============================================================
|
||||
=====================================================================
|
||||
MOD_SECURITY 2.6 Command-line Build notes for Windows 4/2/2011
|
||||
=====================================================================
|
||||
|
||||
I build Apache 2.2.14 from source in C:\work\httpd-2.2.14
|
||||
I have a VC9 build of Apache 2.2.14 installed in C:\Apache2214
|
||||
PREREQUISITES:
|
||||
|
||||
My PATH includes VC9 and CMAKE 2.6
|
||||
Microsoft Visual Studio C++ tested with Visual Studio 2008 (aka VC9)
|
||||
|
||||
BEFORE BUILDING - if OpenSSL and Zlib support is desired in LIBXML2 and CURL
|
||||
CMake build system from: http://www.cmake.org/ tested with CMake v2.8.0
|
||||
|
||||
REM #### set an env variable to my Apache build directory
|
||||
SET HTTPD_BUILD=C:\work\httpd-2.2.14
|
||||
Apache 2.2.x from: http://httpd.apache.org/ tested with Apache 2.2.17
|
||||
Apache must be built from source using the same Visual Studio compiler as mod_security.
|
||||
|
||||
REM #### ensure that CURL and LIBXML2 can find the OpenSSL and Zlib includes and libraries that Apache was built with
|
||||
SET INCLUDE=%INCLUDE%;%HTTPD_BUILD%\srclib\openssl\inc32;%HTTPD_BUILD%\srclib\zlib
|
||||
SET LIB=%LIB%;%HTTPD_BUILD%\srclib\openssl\out32dll;%HTTPD_BUILD%\srclib\zlib
|
||||
PCRE Perl Compatible Regular Expression library from: http://www.pcre.org/ tested with PCRE v8.12
|
||||
|
||||
REM #### ensure that CURL doesn't use the static zlib library: zlib.lib. Force it to use zdll.lib instead, which points to zlib1.dll
|
||||
IF EXIST %HTTPD_BUILD%\srclib\zlib\zlib.lib DEL %HTTPD_BUILD%\srclib\zlib\zlib.lib
|
||||
LibXML2 from: http://xmlsoft.org/ tested with LibXML2 v2.7.7
|
||||
Note that LibXML2 v2.7.8 does not build correctly for Windows
|
||||
|
||||
BUILD PCRE-7.9
|
||||
Lua Scripting Language from: http://www.lua.org/ tested with Lua v5.1.4
|
||||
|
||||
Downloaded pcre-7.9.tar.gz from ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
|
||||
untar'd into C:\work\ creating C:\work\pcre-7.9
|
||||
cURL multiprotocol file transfer library from: http://curl.haxx.se/ tested with cURL v7.21.4
|
||||
|
||||
CD C:\work\pcre-7.9
|
||||
|
||||
BEFORE BUILDING
|
||||
|
||||
The directory where you build software from source ( C:\work in this exmaple)
|
||||
must contain the Apache source you used to build the Apache web serverand the mod_security source
|
||||
|
||||
Apache source is in C:\work\httpd-2.2.17 in this example.
|
||||
Apache has been installed to C:\Apache2217 in this example.
|
||||
Mod_security source is in C:\work\mod_security in this example.
|
||||
|
||||
Download and untar the prerequite library sources:
|
||||
|
||||
Download pcre-8.12.tar.gz from ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
|
||||
untar it into C:\work\ creating C:\work\pcre-8.12
|
||||
|
||||
Download libxml2-2.7.7.tar.gz from ftp://xmlsoft.org/libxml2/
|
||||
untar it into C:\work\ creating C:\work\libxml2-2.7.7
|
||||
|
||||
Download lua-5.1.4.tar.gz from http://www.lua.org/ftp/
|
||||
untar it into C:\work\ creating C:\work\lua-5.1.4
|
||||
|
||||
Download curl-7.21.4.tar.gz from http://curl.haxx.se/download.html
|
||||
untar it into C:\work\ creating C:\work\curl-7.21.4
|
||||
|
||||
Setup your build environment:
|
||||
|
||||
The PATH environment variable must include the Visual Studio variables as set by vsvars32.bat
|
||||
The PATH environment variable must also include the CMAKE bin\ directory
|
||||
|
||||
Set an environment variable to the Apache source code directory:
|
||||
|
||||
SET HTTPD_BUILD=C:\work\httpd-2.2.17
|
||||
|
||||
If OpenSSL and Zlib support were included when you built Apache 2.2, and you want them available to LIBXML2 and CURL
|
||||
|
||||
Ensure that cURL and libXML2 can find the OpenSSL and Zlib includes and libraries that Apache was built with.
|
||||
|
||||
SET INCLUDE=%INCLUDE%;%HTTPD_BUILD%\srclib\openssl\inc32;%HTTPD_BUILD%\srclib\zlib
|
||||
SET LIB=%LIB%;%HTTPD_BUILD%\srclib\openssl\out32dll;%HTTPD_BUILD%\srclib\zlib
|
||||
|
||||
Ensure that cURL and libXML2 don't use the static zlib library: zlib.lib.
|
||||
Force cURL and libXML2 to use zdll.lib instead, requiring zlib1.dll at runtime:
|
||||
|
||||
IF EXIST %HTTPD_BUILD%\srclib\zlib\zlib.lib DEL %HTTPD_BUILD%\srclib\zlib\zlib.lib
|
||||
|
||||
BUILD PCRE-8.12
|
||||
|
||||
CD C:\work\pcre-8.12
|
||||
CMAKE -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=True
|
||||
NMAKE
|
||||
|
||||
BUILD LIBXML2-2.7.6
|
||||
BUILD LIBXML2-2.7.7 (note: the more recent version: 2.7.8 does not build correctly on Windows)
|
||||
|
||||
Downloaded libxml2-2.7.6.tar.gz from ftp://xmlsoft.org/libxml2/
|
||||
untar'd into C:\work\ creating C:\work\libxml2-2.7.6
|
||||
|
||||
CD C:\work\libxml2-2.7.6\win32
|
||||
CD C:\work\libxml2-2.7.7\win32
|
||||
CSCRIPT configure.js iconv=no vcmanifest=yes zlib=yes
|
||||
NMAKE -f Makefile.msvc
|
||||
|
||||
BUILD LUA-5.1.4
|
||||
|
||||
Downloaded lua-5.1.4.tar.gz from http://www.lua.org/ftp/
|
||||
untar'd into C:\work\ creating C:\work\lua-5.1.4
|
||||
|
||||
CD C:\work\lua-5.1.4\src
|
||||
CL /Ox /arch:SSE2 /GF /GL /Gy /FD /EHsc /MD /Zi /TC /wd4005 /D "_MBCS" /D "LUA_CORE" /D "LUA_BUILD_AS_DLL" /D "_CRT_SECURE_NO_WARNINGS" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_WIN32" /D "_WINDLL" /c *.c
|
||||
DEL lua.obj luac.obj
|
||||
LINK /DLL /LTCG /DEBUG /OUT:lua5.1.dll *.obj
|
||||
IF EXIST lua5.1.dll.manifest MT -manifest lua5.1.dll.manifest -outputresource:lua5.1.dll;2
|
||||
|
||||
BUILD CURL-7.20.0
|
||||
Downloaded curl-7.20.0.tar.gz from http://curl.haxx.se/download.html
|
||||
untar'd into C:\work\ creating C:\work\curl-7.20.0
|
||||
|
||||
CD C:\work\curl-7.20.0
|
||||
|
||||
*** Fixed Bug: https://sourceforge.net/tracker/?func=detail&aid=2951269&group_id=976&atid=100976 ***
|
||||
Edited the file include\curl\curlbuild.h.cmake near line 160 - put double-quotes around all CURL_FORMAT* values.
|
||||
e.g. change: ${CURL_FORMAT_CURL_OFF_T} to: "${CURL_FORMAT_CURL_OFF_T}"
|
||||
|
||||
/* curl_off_t formatting string directive without "%" conversion specifier. */
|
||||
#cmakedefine CURL_FORMAT_CURL_OFF_T "${CURL_FORMAT_CURL_OFF_T}"
|
||||
|
||||
/* unsigned curl_off_t formatting string without "%" conversion specifier. */
|
||||
#cmakedefine CURL_FORMAT_CURL_OFF_TU "${CURL_FORMAT_CURL_OFF_TU}"
|
||||
|
||||
/* curl_off_t formatting string directive with "%" conversion specifier. */
|
||||
#cmakedefine CURL_FORMAT_OFF_T "${CURL_FORMAT_OFF_T}"
|
||||
BUILD CURL-7.21.4
|
||||
|
||||
CD C:\work\curl-7.21.4
|
||||
CMAKE -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=True -DCURL_ZLIB=True
|
||||
|
||||
NMAKE
|
||||
|
||||
BUILD MOD_SECURITY-2.5.12
|
||||
BUILD MOD_SECURITY-2.6
|
||||
|
||||
Edited the top of C:\work\mod_security-2.5.12\apache2\Makefile.win and set my local paths
|
||||
(note that pcre.lib is not in $(PCRE)\LibR as it is in the original Makefile.win )
|
||||
CD C:\work\mod_security\apache2
|
||||
NMAKE -f Makefile.win APACHE=C:\Apache2217 PCRE=C:\work\pcre-8.12 LIBXML2=C:\work\libxml2-2.7.7 LUA=C:\work\lua-5.1.4\src
|
||||
|
||||
# Path to Apache httpd installation
|
||||
BASE = C:\Apache2214
|
||||
INSTALL MOD_SECURITY AND RUN APACHE
|
||||
|
||||
# Paths to required libraries
|
||||
LIBXML2 = C:\work\libxml2-2.7.6
|
||||
LUA = C:\work\lua-5.1.4\src
|
||||
PCRE = C:\work\pcre-7.9
|
||||
Copy these five files to C:\Apache2217\bin:
|
||||
C:\work\pcre-8.12\pcre.dll C:\Apache2217\bin\
|
||||
C:\work\lua-5.1.4\src\lua5.1.dll C:\Apache2217\bin\
|
||||
C:\work\libxml2-2.7.7\win32\bin.msvc\libxml2.dll C:\Apache2217\bin\
|
||||
C:\work\curl-7.21.4\libcurl.dll C:\Apache2217\bin\
|
||||
C:\work\mod_security\apache2\mlogc-src\mlogc.exe
|
||||
|
||||
# Linking libraries
|
||||
LIBS = $(BASE)\lib\libhttpd.lib \
|
||||
$(BASE)\lib\libapr-1.lib \
|
||||
$(BASE)\lib\libaprutil-1.lib \
|
||||
$(PCRE)\pcre.lib \
|
||||
$(LIBXML2)\win32\bin.msvc\libxml2.lib \
|
||||
$(LUA)\lua5.1.lib \
|
||||
wsock32.lib
|
||||
Copy this one file to C:\Apache2217\modules:
|
||||
|
||||
CD C:\work\mod_security-2.5.12\apache2
|
||||
NMAKE -f Makefile.win
|
||||
C:\work\mod_security\apache2\mod_security2.so
|
||||
|
||||
BUILD MOD_SECURITY-2.5.12 MLOGC program
|
||||
You may also copy C:\work\curl-7.21.4\curl.exe to C:\Apache2217\bin, if you want to use the cURL command-line program.
|
||||
|
||||
Edited the top of C:\work\mod_security-2.5.12\apache2\mlogc-src\Makefile.win and set my local paths
|
||||
Download the core rules from http://sourceforge.net/projects/mod-security/files/modsecurity-crs/0-CURRENT/
|
||||
and unzip them into C:\Apache2217\conf\modsecurity_crs
|
||||
|
||||
# Path to Apache httpd installation
|
||||
BASE = C:\Apache2214
|
||||
Add configuration directives to your Apache conf\httpd.conf:
|
||||
|
||||
# Paths to required libraries
|
||||
PCRE = C:\work\pcre-7.9
|
||||
CURL = C:\work\curl-7.20.0
|
||||
# mod_security requires mod_unique_id
|
||||
LoadModule unique_id_module modules/mod_unique_id.so
|
||||
|
||||
# Linking libraries
|
||||
LIBS = $(BASE)\lib\libapr-1.lib \
|
||||
$(BASE)\lib\libaprutil-1.lib \
|
||||
$(PCRE)\pcre.lib \
|
||||
$(CURL)\libcurl_imp.lib \
|
||||
wsock32.lib
|
||||
# mod_security
|
||||
LoadModule security2_module modules/mod_security2.so
|
||||
<IfModule security2_module>
|
||||
SecRuleEngine On
|
||||
SecDataDir logs
|
||||
Include conf/modsecurity_crs/*.conf
|
||||
Include conf/modsecurity_crs/base_rules/*.conf
|
||||
SecAuditEngine RelevantOnly
|
||||
SecAuditLogRelevantStatus "^(?:5|4\d[^4])"
|
||||
SecAuditLogType Serial
|
||||
SecAuditLogParts ABCDEFGHZ
|
||||
SecAuditLog logs/modsecurity.log
|
||||
</IfModule>
|
||||
|
||||
|
||||
CD C:\work\mod_security-2.5.12\apache2\mlogc-src
|
||||
NMAKE -f Makefile.win
|
||||
==============================================================================================
|
||||
OPTIONAL: BUILD AND CONFIGURE THE MOD_SECURITY-2.6 MLOGC piped-logging program
|
||||
|
||||
INSTALL AND RUN
|
||||
Edit the top of C:\work\mod_security\apache2\mlogc-src\Makefile.win and set your local paths
|
||||
|
||||
Copied these five files to C:\Apache2214\bin:
|
||||
C:\work\pcre-7.9\pcre.dll
|
||||
C:\work\lua-5.1.4\src\lua5.1.dll
|
||||
C:\work\libxml2-2.7.6\win32\bin.msvc\libxml2.dll
|
||||
C:\work\curl-7.20.0\libcurl.dll
|
||||
C:\work\mod_security-2.5.12\apache2\mlogc-src\mlogc.exe
|
||||
# Path to Apache httpd installation
|
||||
BASE = C:\Apache2217
|
||||
|
||||
Copied this one file to C:\Apache2214\modules:
|
||||
# Paths to required libraries
|
||||
PCRE = C:\work\pcre-8.12
|
||||
CURL = C:\work\curl-7.21.4
|
||||
|
||||
C:\work\mod_security-2.5.12\apache2\mod_security2.so
|
||||
# Linking libraries
|
||||
LIBS = $(BASE)\lib\libapr-1.lib \
|
||||
$(BASE)\lib\libaprutil-1.lib \
|
||||
$(PCRE)\pcre.lib \
|
||||
$(CURL)\libcurl_imp.lib \
|
||||
wsock32.lib
|
||||
|
||||
You could also copy C:\work\curl-7.20.0\\curl.exe to C:\Apache2214\bin, if you want to use the cURL command-line.
|
||||
Build the mlogc.exe program:
|
||||
|
||||
Downloaded the core rules from http://sourceforge.net/projects/mod-security/files/modsecurity-crs/0-CURRENT/
|
||||
and unzipped them in C:\Apache2214\conf\modsecurity_crs
|
||||
CD C:\work\mod_security_trunk\mlogc
|
||||
NMAKE -f Makefile.win
|
||||
|
||||
Added this to my conf\httpd.conf:
|
||||
Copy mlocg.exe to C:\Apache2217\bin\
|
||||
|
||||
LoadModule unique_id_module modules/mod_unique_id.so
|
||||
LoadModule security2_module modules/mod_security2.so
|
||||
<IfModule security2_module>
|
||||
Include conf/modsecurity_crs/*.conf
|
||||
Include conf/modsecurity_crs/base_rules/*.conf
|
||||
SecDataDir logs
|
||||
SecAuditEngine RelevantOnly
|
||||
SecAuditLogRelevantStatus "^(?:5|4\d[^4])"
|
||||
SecAuditLogType Concurrent
|
||||
SecAuditLogParts ABCDEFGHZ
|
||||
SecAuditLogStorageDir logs/data/
|
||||
SecAuditLog "|bin/mlogc.exe"
|
||||
</IfModule>
|
||||
Create a new command file C:\Apache2217\bin\mlogc.bat with one line:
|
||||
|
||||
My conf\mlogc.conf has this:
|
||||
CollectorRoot "C:/Apache2214/logs"
|
||||
ConsoleURI "https://localhost:8888/rpc/auditLogReceiver"
|
||||
SensorUsername "test"
|
||||
SensorPassword "testtest"
|
||||
LogStorageDir "data"
|
||||
TransactionLog "mlogc-transaction.log"
|
||||
QueuePath "mlogc-queue.log"
|
||||
ErrorLog "mlogc-error.log"
|
||||
LockFile "mlogc.lck"
|
||||
KeepEntries 0
|
||||
ErrorLogLevel 2
|
||||
MaxConnections 10
|
||||
MaxWorkerRequests 1000
|
||||
TransactionDelay 50
|
||||
StartupDelay 5000
|
||||
CheckpointInterval 15
|
||||
ServerErrorTimeout 60
|
||||
C:\Apache2217\bin\mlogc.exe C:\Apache2217\conf\mlogc.conf
|
||||
|
||||
Create a new configuration file C:\Apache2217\conf\mlogc.conf to control the piped-logging program mlogc.exe.
|
||||
Here is an example conf\mlogc.conf:
|
||||
|
||||
Mod_security appears to work OK with the "ModSecurity Community Console".
|
||||
CollectorRoot "C:/Apache2217/logs"
|
||||
ConsoleURI "https://localhost:8888/rpc/auditLogReceiver"
|
||||
SensorUsername "test"
|
||||
SensorPassword "testtest"
|
||||
LogStorageDir "data"
|
||||
TransactionLog "mlogc-transaction.log"
|
||||
QueuePath "mlogc-queue.log"
|
||||
ErrorLog "mlogc-error.log"
|
||||
LockFile "mlogc.lck"
|
||||
KeepEntries 0
|
||||
ErrorLogLevel 2
|
||||
MaxConnections 10
|
||||
MaxWorkerRequests 1000
|
||||
TransactionDelay 50
|
||||
StartupDelay 5000
|
||||
CheckpointInterval 15
|
||||
ServerErrorTimeout 60
|
||||
|
||||
Change the SecAuditLog directive in conf\httpd.conf to pipe the log data to mlogc
|
||||
instead of writing them to a file:
|
||||
|
||||
SecAuditLog |C:/Apache2217/bin/mlogc.bat
|
||||
|
Reference in New Issue
Block a user