Skip to content

Commit 2bf51f8

Browse files
authored
Merge pull request #21 from Sebitosh/infrastructure-apache2-modsec2
Utility change: infrastructure for apache2 with modsec2 on ubuntu
2 parents d022bce + 8c710f3 commit 2bf51f8

File tree

208 files changed

+3205
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+3205
-4
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,46 @@ SecAction "id:100020,phase:2 pass, setenv:'after=789'"
697697
```
698698

699699
## Run the tool
700+
### Run the entire toolchain
701+
702+
#### Required:
703+
* [albedo](https://github.com/coreruleset/albedo)
704+
* [go-ftw](https://github.com/coreruleset/go-ftw)
705+
* apache2 with the modsecurity and proxy modules for using the `apache2_ubuntu` + ModSecurity V2 infrastructure
706+
707+
To run the tests on a provided configuration, run the tool:
708+
709+
~~~bash
710+
$ ./mrts/mrts.py
711+
usage: mrts.py [-h] -i /path/to/infra/ -r /path/to/mrts/*.yaml -e /path/to/mrts/rules/ -t /path/to/mrts/tests/ [-c]
712+
[-f /path/to/mrts/ftw.mrts.config.yaml] [-v]
713+
mrts.py: error: the following arguments are required: -i/--infrastructure, -r/--rulesdef, -e/--expdir, -t/--testdir
714+
~~~
715+
716+
As you can see there are few command line arguments.
717+
* `-i` - WAF infrastructure files
718+
* `-r` - rules definition files
719+
* `-e` - export directory where rules will be written
720+
* `-t` - export test directory where tests will be written
721+
* `-c` - clean previously generated rule and test files
722+
* `-f` - `go-ftw` custom configuration file, if you don't want to use the default file provided in the infrastructure directory
723+
* `-v` - verbose output
724+
725+
For running without a custom `go-ftw` configuration, run the `mrts.py` script from the root directory of the project (or else provide a ftw configuration file with a correct relative path).
726+
727+
~~~bash
728+
$ ./mrts/mrts.py -i config_infra/apache2_ubuntu/ -r config_tests/ -e generated/rules/ -t generated/tests/regression/tests/
729+
Generate rules and tests
730+
Launch backend
731+
Launch infrastructure
732+
Executing test set...
733+
🎉🎉🎉 Success: test set passed
734+
Backend shutdown
735+
Infrastructure shutdown
736+
MRTS completed
737+
~~~
738+
739+
### Rule and test generation
700740

701741
To generate the rules and their tests, run the tool:
702742

config_infra/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
logfile: 'config_infra/apache2_ubuntu/infra/log/error.log'
2+
logmarkerheadername: 'X-MRTS-TEST'
3+
logtype:
4+
name: 'apache'
5+
timeregex: '\[([A-Z][a-z]{2} [A-z][a-z]{2} \d{1,2} \d{1,2}\:\d{1,2}\:\d{1,2}\.\d+? \d{4})\]'
6+
timeformat: 'ddd MMM DD HH:mm:ss.S YYYY'
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# This is the main Apache server configuration file. It contains the
2+
# configuration directives that give the server its instructions.
3+
# See http://httpd.apache.org/docs/2.4/ for detailed information about
4+
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
5+
# hints.
6+
#
7+
#
8+
# Summary of how the Apache 2 configuration works in Debian:
9+
# The Apache 2 web server configuration in Debian is quite different to
10+
# upstream's suggested way to configure the web server. This is because Debian's
11+
# default Apache2 installation attempts to make adding and removing modules,
12+
# virtual hosts, and extra configuration directives as flexible as possible, in
13+
# order to make automating the changes and administering the server as easy as
14+
# possible.
15+
16+
# It is split into several files forming the configuration hierarchy outlined
17+
# below, all located in the /etc/apache2/ directory:
18+
#
19+
# /etc/apache2/
20+
# |-- apache2.conf
21+
# | `-- ports.conf
22+
# |-- mods-enabled
23+
# | |-- *.load
24+
# | `-- *.conf
25+
# |-- conf-enabled
26+
# | `-- *.conf
27+
# `-- sites-enabled
28+
# `-- *.conf
29+
#
30+
#
31+
# * apache2.conf is the main configuration file (this file). It puts the pieces
32+
# together by including all remaining configuration files when starting up the
33+
# web server.
34+
#
35+
# * ports.conf is always included from the main configuration file. It is
36+
# supposed to determine listening ports for incoming connections which can be
37+
# customized anytime.
38+
#
39+
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
40+
# directories contain particular configuration snippets which manage modules,
41+
# global configuration fragments, or virtual host configurations,
42+
# respectively.
43+
#
44+
# They are activated by symlinking available configuration files from their
45+
# respective *-available/ counterparts. These should be managed by using our
46+
# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
47+
# their respective man pages for detailed information.
48+
#
49+
# * The binary is called apache2. Due to the use of environment variables, in
50+
# the default configuration, apache2 needs to be started/stopped with
51+
# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
52+
# work with the default configuration.
53+
54+
55+
# Global configuration
56+
#
57+
58+
#
59+
# ServerRoot: The top of the directory tree under which the server's
60+
# configuration, error, and log files are kept.
61+
#
62+
# NOTE! If you intend to place this on an NFS (or otherwise network)
63+
# mounted filesystem then please read the Mutex documentation (available
64+
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
65+
# you will save yourself a lot of trouble.
66+
#
67+
# Do NOT add a slash at the end of the directory path.
68+
#
69+
#ServerRoot "/etc/apache2"
70+
71+
#
72+
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
73+
#
74+
#Mutex file:${APACHE_LOCK_DIR} default
75+
76+
#
77+
# The directory where shm and other runtime files will be stored.
78+
#
79+
80+
DefaultRuntimeDir ${APACHE_RUN_DIR}
81+
82+
#
83+
# PidFile: The file in which the server should record its process
84+
# identification number when it starts.
85+
# This needs to be set in /etc/apache2/envvars
86+
#
87+
PidFile run/apache2.pid
88+
89+
#
90+
# Timeout: The number of seconds before receives and sends time out.
91+
#
92+
Timeout 300
93+
94+
#
95+
# KeepAlive: Whether or not to allow persistent connections (more than
96+
# one request per connection). Set to "Off" to deactivate.
97+
#
98+
KeepAlive On
99+
100+
#
101+
# MaxKeepAliveRequests: The maximum number of requests to allow
102+
# during a persistent connection. Set to 0 to allow an unlimited amount.
103+
# We recommend you leave this number high, for maximum performance.
104+
#
105+
MaxKeepAliveRequests 100
106+
107+
#
108+
# KeepAliveTimeout: Number of seconds to wait for the next request from the
109+
# same client on the same connection.
110+
#
111+
KeepAliveTimeout 5
112+
113+
114+
# These need to be set in /etc/apache2/envvars
115+
User ${APACHE_RUN_USER}
116+
Group ${APACHE_RUN_GROUP}
117+
118+
#
119+
# HostnameLookups: Log the names of clients or just their IP addresses
120+
# e.g., www.apache.org (on) or 204.62.129.132 (off).
121+
# The default is off because it'd be overall better for the net if people
122+
# had to knowingly turn this feature on, since enabling it means that
123+
# each client request will result in AT LEAST one lookup request to the
124+
# nameserver.
125+
#
126+
HostnameLookups Off
127+
128+
# ErrorLog: The location of the error log file.
129+
# If you do not specify an ErrorLog directive within a <VirtualHost>
130+
# container, error messages relating to that virtual host will be
131+
# logged here. If you *do* define an error logfile for a <VirtualHost>
132+
# container, that host's errors will be logged there and not here.
133+
#
134+
135+
ErrorLog log/error.log
136+
137+
#
138+
# LogLevel: Control the severity of messages logged to the error_log.
139+
# Available values: trace8, ..., trace1, debug, info, notice, warn,
140+
# error, crit, alert, emerg.
141+
# It is also possible to configure the log level for particular modules, e.g.
142+
# "LogLevel info ssl:warn"
143+
#
144+
LogLevel warn
145+
146+
# Include module configuration:
147+
IncludeOptional mods-enabled/*.load
148+
IncludeOptional mods-enabled/*.conf
149+
150+
# Include list of ports to listen on
151+
Include ports.conf
152+
153+
154+
# Sets the default security model of the Apache2 HTTPD server. It does
155+
# not allow access to the root filesystem outside of /usr/share and /var/www.
156+
# The former is used by web applications packaged in Debian,
157+
# the latter may be used for local directories served by the web server. If
158+
# your system is serving content from a sub-directory in /srv you must allow
159+
# access here, or in any related virtual host.
160+
<Directory />
161+
Options FollowSymLinks
162+
AllowOverride None
163+
Require all denied
164+
</Directory>
165+
166+
<Directory /usr/share>
167+
AllowOverride None
168+
Require all granted
169+
</Directory>
170+
171+
<Directory /var/www/>
172+
Options Indexes FollowSymLinks
173+
AllowOverride None
174+
Require all granted
175+
</Directory>
176+
177+
#<Directory /srv/>
178+
# Options Indexes FollowSymLinks
179+
# AllowOverride None
180+
# Require all granted
181+
#</Directory>
182+
183+
184+
185+
186+
# AccessFileName: The name of the file to look for in each directory
187+
# for additional configuration directives. See also the AllowOverride
188+
# directive.
189+
#
190+
AccessFileName .htaccess
191+
192+
#
193+
# The following lines prevent .htaccess and .htpasswd files from being
194+
# viewed by Web clients.
195+
#
196+
<FilesMatch "^\.ht">
197+
Require all denied
198+
</FilesMatch>
199+
200+
201+
#
202+
# The following directives define some format nicknames for use with
203+
# a CustomLog directive.
204+
#
205+
# These deviate from the Common Log Format definitions in that they use %O
206+
# (the actual bytes sent including headers) instead of %b (the size of the
207+
# requested file), because the latter makes it impossible to detect partial
208+
# requests.
209+
#
210+
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
211+
# Use mod_remoteip instead.
212+
#
213+
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
214+
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
215+
LogFormat "%h %l %u %t \"%r\" %>s %O" common
216+
LogFormat "%{Referer}i -> %U" referer
217+
LogFormat "%{User-agent}i" agent
218+
219+
# Include of directories ignores editors' and dpkg's backup files,
220+
# see README.Debian for details.
221+
222+
# Include generic snippets of statements
223+
IncludeOptional conf-enabled/*.conf
224+
225+
# Include the virtual host configurations:
226+
IncludeOptional sites-enabled/*.conf
227+
228+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Read the documentation before enabling AddDefaultCharset.
2+
# In general, it is only a good idea if you know that all your files
3+
# have this encoding. It will override any encoding given in the files
4+
# in meta http-equiv or xml encoding tags.
5+
6+
#AddDefaultCharset UTF-8
7+
8+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Customizable error responses come in three flavors:
2+
# 1) plain text
3+
# 2) local redirects
4+
# 3) external redirects
5+
#
6+
# Some examples:
7+
#ErrorDocument 500 "The server made a boo boo."
8+
#ErrorDocument 404 /missing.html
9+
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
10+
#ErrorDocument 402 http://www.example.com/subscription_info.html
11+
#
12+
13+
#
14+
# Putting this all together, we can internationalize error responses.
15+
#
16+
# We use Alias to redirect any /error/HTTP_<error>.html.var response to
17+
# our collection of by-error message multi-language collections. We use
18+
# includes to substitute the appropriate text.
19+
#
20+
# You can modify the messages' appearance without changing any of the
21+
# default HTTP_<error>.html.var files by adding the line:
22+
#
23+
#Alias /error/include/ "/your/include/path/"
24+
#
25+
# which allows you to create your own set of files by starting with the
26+
# /usr/share/apache2/error/include/ files and copying them to /your/include/path/,
27+
# even on a per-VirtualHost basis. If you include the Alias in the global server
28+
# context, is has to come _before_ the 'Alias /error/ ...' line.
29+
#
30+
# The default include files will display your Apache version number and your
31+
# ServerAdmin email address regardless of the setting of ServerSignature.
32+
#
33+
# WARNING: The configuration below will NOT work out of the box if you have a
34+
# SetHandler directive in a <Location /> context somewhere. Adding
35+
# the following three lines AFTER the <Location /> context should
36+
# make it work in most cases:
37+
# <Location /error/>
38+
# SetHandler none
39+
# </Location>
40+
#
41+
# The internationalized error documents require mod_alias, mod_include
42+
# and mod_negotiation. To activate them, uncomment the following 37 lines.
43+
44+
#<IfModule mod_negotiation.c>
45+
# <IfModule mod_include.c>
46+
# <IfModule mod_alias.c>
47+
#
48+
# Alias /error/ "/usr/share/apache2/error/"
49+
#
50+
# <Directory "/usr/share/apache2/error">
51+
# Options IncludesNoExec
52+
# AddOutputFilter Includes html
53+
# AddHandler type-map var
54+
# Order allow,deny
55+
# Allow from all
56+
# LanguagePriority en cs de es fr it nl sv pt-br ro
57+
# ForceLanguagePriority Prefer Fallback
58+
# </Directory>
59+
#
60+
# ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
61+
# ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
62+
# ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
63+
# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
64+
# ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
65+
# ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
66+
# ErrorDocument 410 /error/HTTP_GONE.html.var
67+
# ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
68+
# ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
69+
# ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
70+
# ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
71+
# ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
72+
# ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
73+
# ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
74+
# ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
75+
# ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
76+
# ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
77+
# </IfModule>
78+
# </IfModule>
79+
#</IfModule>
80+
81+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Define an access log for VirtualHosts that don't define their own logfile
2+
CustomLog log/other_vhosts_access.log vhost_combined
3+
4+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

0 commit comments

Comments
 (0)