You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-60Lines changed: 59 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,28 @@
1
1
ftwrunner
2
2
=========
3
3
4
-
Welcome to the `ftwrunner` documentation. I'ld try to show this tool to every ModSecurity users, who's interesting about the rules and its tests.
4
+
Welcome to the `ftwrunner` documentation. I'd try to show this tool to every ModSecurity user who's interested in the rules and their tests.
5
5
6
6
Motivation
7
7
==========
8
8
9
-
I help to maintain the code of [ModSecurity](https://modsecurity.org) (especially the [libmodsecurity3](https://github.com/owasp-modsecurity/ModSecurity)). A most important goal that get the state that the [CRS](https://coreruleset.org) can work together with libmodsecurity3, without errors: false positives and not working rules.
9
+
I help to maintain the code of [ModSecurity](https://modsecurity.org) (especially the [libmodsecurity3](https://github.com/owasp-modsecurity/ModSecurity)). The most important goal is to get the status where the [CRS](https://coreruleset.org) can work together with libmodsecurity3 without errors: false positives and not working rules.
10
10
11
-
[CRS](https://github.com/coreruleset/coreruleset) has a very good tool to test all of the rules, it's called [go-ftw](https://github.com/coreruleset/go-ftw), but it works only with a supported webserver - consequently a HTTP server is required. Go-ftw uses [sets of tests](https://github.com/coreruleset/coreruleset/tree/main/tests/regression/tests), which are divided to different sections, represented the attack type. Each section has a multiple test files, which represented the rules: every file named by the rule id. And finally, all ruleset has one or more test.
11
+
[CRS](https://github.com/coreruleset/coreruleset) has a very good tool to test all of the rules, it's called [go-ftw](https://github.com/coreruleset/go-ftw), but it works only with a supported webserver - consequently a HTTP server is required. Go-ftw uses [sets of tests](https://github.com/coreruleset/coreruleset/tree/main/tests/regression/tests), which are divided into different sections representing the attack type. Each section has multiple test files, which represented the rules: every file named by the rule id. And finally, each rules has one or more tests.
12
12
13
-
These tests were written in [YAML](https://yaml.org/) format. The used schema is well documented on [ftw-tests-schema](https://github.com/coreruleset/ftw-tests-schema)
13
+
These tests were written in [YAML](https://yaml.org/) format. The used schema is well documented on [ftw-tests-schema](https://github.com/coreruleset/ftw-tests-schema).
14
14
15
+
Libmodsecurity3 has been written in C++ and - therefore as a library - has an [API](https://github.com/owasp-modsecurity/ModSecurity#simple-example-using-c). The library has an own regression test framework, but mostly it's useful to test the different functions one by one.
15
16
16
-
Libmodsecurity3 has written in C++, and - therefore as a library - has an [API](https://github.com/owasp-modsecurity/ModSecurity#simple-example-using-c). The library has an own regression test framework, but mostly it's useful to tests the different functions one by one.
17
+
As I wrote, my main goal is to adjust the libmodsecurity3 code to use those rules, so I needed a tool, which I can use to test the whole ruleset without any other external distractions, eg. webserver responses, other behaviors, etc...
17
18
18
-
As I wrote, my main goal is to adjusting the libmodsecurity3 code to use those rules, so I needed a tool, which I can test with the whole ruleset without any other external distractions, eg. webserver responses, other behaviors, etc...
19
+
At first time, I made a very ugly HTTP server, but it just generated more problems rather than solved them.
19
20
20
-
At first time, I've made a very ugly HTTP server, but it just generated more problems rather than taken away them.
21
-
22
-
Then the idea came - use the API, but not through the HTTP: inject the existing YAML tests to API directly.
21
+
Then the final idea came - use the API, but not through the HTTP: inject the existing YAML tests to API directly.
23
22
24
23
That is why this tool was created.
25
24
26
-
In version v1.0 I added [Coraza](https://github.com/corazawaf/coraza) support too, through [libcoraza](https://github.com/corazawaf/libcoraza), and I completely rewrited the whole tool in pure C.
25
+
In version v1.0 I added [Coraza](https://github.com/corazawaf/coraza) support too, through [libcoraza](https://github.com/corazawaf/libcoraza) and I completely rewrote the whole tool in pure C.
and - as I wrote above - an installed libmodsecurity3 and/or libcoraza.
48
47
49
-
(Note: unfortunately libcoraza is a very beta state at the moment, and it does not work.)
48
+
(Note: unfortunately libcoraza is a very beta status at the moment and it does not work.)
50
49
51
-
*Note: Debian 10 and Debian 11 contains the libmodsecurity3 package, but since it released, there are so much modification in the code, so I **strongly suggest** that you get a clone with git, and compile it for yourself. Optionally, you can use our Debian repository: [https://modsecurity.digitalwave.hu](https://modsecurity.digitalwave.hu)*
50
+
*Note: Debian 10 and Debian 11 contain the libmodsecurity3 package, but since it has been released, there are many modifications in the code, so I **strongly suggest** that you get a clone with git and compile it for yourself. Optionally, you can use our Debian repository: [https://modsecurity.digitalwave.hu](https://modsecurity.digitalwave.hu)*
52
51
53
52
Compile the code
54
53
================
55
54
56
-
It's simple, grab the code, and type this commands:
55
+
It's simple: grab the code and type this commands:
57
56
58
57
```
59
58
$ autoreconf --install
60
59
$ ./configure
61
60
```
62
61
63
-
At the and of `./configure`, you will get a report:
62
+
At the and of `./configure` you will get a report:
This will be installed to /usr/local/bin directory.
95
94
96
-
If everything was right, a new file created until`src/` in your project directory with name `ftwrunner`. Copy it to where you want to use, eg. to your project dir:
95
+
If everything was right, a new file was created under`src/` in your project directory with name `ftwrunner`. Copy it where you want to use it, eg. to your project dir:
97
96
```
98
97
$ cp src/ftwrunner .
99
98
```
100
99
101
-
How does it work
102
-
================
100
+
How it works
101
+
============
103
102
104
103
Prepare the configuration file
105
104
------------------------------
106
105
107
-
In the source directory, there is a configuration file, called `ftwrunner.yaml.example`. `ftwrunner` doesn't need that, but I think it helps your work. If you want to use that, make a copy from that:
106
+
In the source directory, there is a configuration file called `ftwrunner.yaml.example`. `ftwrunner` doesn't need that, but I think it helps your work. If you want to use that, make a copy from it:
108
107
```
109
108
$ cp ftwrunner.yaml.example ftwrunner.yaml
110
109
```
111
-
and edit the options what you found there. Here is the content:
110
+
and edit the options you found there. Here is the content:
If you run `ftwrunner`, it's also try to open this file first, and if it done, uses the variables. There are two mandatory variable: `modsecurity_config` and `ftwtest_root`. Both of them can be overwritten with the command line arguments. As I wrote, you don't need this file with this name, but you can pass to `ftwrunner` another one with cli argument `-c /path/to/config.yaml`.
119
+
If you run `ftwrunner`, it tries to open this file first and if it is done, `ftwrunner`uses the variables. There are two mandatory variables: `modsecurity_config` and `ftwtest_root`. Both of them can be overwritten with the command line arguments. As I wrote, you don't need this file with this name, but you can pass to `ftwrunner` another one with cli argument `-c /path/to/config.yaml`.
121
120
122
121
Content of config file
123
122
----------------------
124
123
125
-
I suppose you use separated config files, at least your WAF config. When `ftwrunner` runs, it reads the whole config as your web server, so if your debug.log/audit.log is turned on, `ftwrunner` also wants to write it.
124
+
I suppose you use separated config files, at least your WAF config. When `ftwrunner` runs, it reads the whole config as your web server, so if your debug.log/audit.log is turned on, `ftwrunner` also wants to write them.
126
125
127
-
The best what you can do is make a single config file what you pass to `ftwrun`, and through that file the runner includes the other ones. This config file can be `modsecurity_includes.conf`.
126
+
The best what you can do is to make a single config file you pass to `ftwrunner` and through that file the runner includes the other ones. This config file can be `modsecurity_includes.conf`.
128
127
129
-
Make a copy of your `modsecurity.conf` or `coraza.conf`. Make any modifications what you want (turn on/off the logs, change the log paths, and so on.)
128
+
Make a copy of your `modsecurity.conf` or `coraza.conf`. Make any modifications you want (turn on/off the logs, change the log paths, and so on.)
130
129
131
130
Put the name of this file into `modsecurity_includes.conf`:
132
131
@@ -136,7 +135,7 @@ include modsecurity.conf
136
135
include coraza.conf
137
136
```
138
137
139
-
Then find the file which loads your CRS setup file, before and after loaders, and the rules. Put that file too into the `modsecurity_includes.conf`. Now your file looks like this:
138
+
Then find the file which loads your CRS setup file, before and after loaders and the rules. Put that file also into the `modsecurity_includes.conf`. Now your file looks like this:
140
139
141
140
```
142
141
$ cat modsecurity_includes.conf
@@ -153,20 +152,20 @@ include /path/to/coreruleset/rules/*.conf
153
152
include /path/to/crs/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
154
153
```
155
154
156
-
**AGAIN: if you set up the debug in that config (`SecDebugLog /var/log/nginx/modsec_debug.log`), libmodsecurity3 wants to open it when it starts, so you have to give the permissions to the user what you run, or use a copy and change this variable, or turn off debug log. No, you don't want to run it as root.**
155
+
**AGAIN: if you set up the debug in that config (`SecDebugLog /var/log/nginx/modsec_debug.log`), libmodsecurity3 wants to open it when it starts, so you have to give the permissions to the user who runs it or use a copy and change this variable or turn off debug log. No, you don't want to run it as root.**
157
156
158
-
**Also please make sure if you copy your `modsecurity.conf`, that you copy the `unicode.mapping` file too.**
157
+
**Also please make sure that you copied your `modsecurity.conf` and the `unicode.mapping` file, too.**
159
158
160
159
You can overwrite the `modsecurity_config: modsecurity_include.conf` variable with cli argument `-m /path/to/config`.
161
160
162
-
`ftwtest_root` - path to your regression tests root directory. It's depend on your config, version, etc... and also can be overwriten with a cli argument `-f /path/to/coreruleset/tests/regression/tests`.
161
+
`ftwtest_root` - path to your regression tests root directory. It depends on your config, version, etc... and also can be overwriten with a cli argument `-f /path/to/coreruleset/tests/regression/tests`.
163
162
164
-
Note, that it's generally useful if you don't want to run all tests in that directory, just a subset. Here is an example:
163
+
Note that it's generally useful if you don't want to run all tests in that directory, just a subset. Here is an example:
`test_whitelist` - this is **not** a mandatory option, but can be useful to lists the tests titles, what you know that will FAILED. You can place a comment after the test title with a `#`, see example:
168
+
`test_whitelist` - this is **not** a mandatory option, but can be useful to list the tests titles that you know will be FAILED. You can place a comment after the test title with a `#`, see example:
170
169
171
170
```
172
171
test_whitelist:
@@ -182,7 +181,7 @@ test_whitelist:
182
181
Command line options
183
182
--------------------
184
183
185
-
With the command line options you can overwrite the two mandatory options above, and can extend the functions. See them:
184
+
With the command line options you can overwrite the two mandatory options above and can extend the functions. See them:
186
185
187
186
`-h` - gives a short help
188
187
@@ -217,27 +216,27 @@ this command will run the test only for rule id `942380` with test title `942380
217
216
Output
218
217
------
219
218
220
-
The tests runs one after one. The rules are sorted, the first test is the lower. A set of test will skipped, if the yaml file `meta` section contains `enabled: false`. In this case, you will see just this line:
219
+
The tests run one after one. The rules are sorted, the first test is the lowest title. Sume test will be omitted if the yaml file `meta` section contains `enabled: false`. In this case, you will see just this line:
221
220
222
221
```
223
222
920250.yaml: tests not enabled in file, skipping...
224
223
```
225
224
226
-
Otherwise, the tests will runs.
225
+
Otherwise, the tests will run.
227
226
228
-
*Note, that this tests will not counts anywhere at final summary.*
227
+
*Note, that these tests will not be counted anywhere at final summary.*
229
228
230
-
`ftwrunner` can evaulates only those tests, which checks the error log. If the original `ftw` expects the HTTP status code or any HTTP error, then it can't catch it, so if the test output expects `status` or `expects_error`, then it will be SKIPPED. There is an another criteria to run the test: if the test input section gives `raw_request` or `encoded_request`, then test also will SKIPPED - these keywords are not implemented yet. If a test SKIPPED, then the the reason will showed.
229
+
`ftwrunner` can evaulate only those tests, which checks the error log. If the original `ftw` expects the HTTP status code or any HTTP error, then it can't catch it, so if the test output expects `status` or `expects_error`, then it will be SKIPPED. There is an another criterium to run the test: if the test input section gives `raw_request` or `encoded_request`, then test also will be SKIPPED - these keywords are not implemented yet. If a test is SKIPPED, then the the reason will be showed.
231
230
232
231
The runned tests can generate three main types of output:
233
232
234
-
* SKIPPED - see criterias above; note, that the reason will showed, why test skipped
235
-
* PASSED - if the output of request with given data matched the result(s) (eg. `log_contains` pattern found in the generated log lines, or `no_log_contains` pattern not found in that), then the test passed
233
+
* SKIPPED - see criteria above; note, that the reason will be showed, why the test was skipped
234
+
* PASSED - if the output of request with given data matched the result(s) (eg. `log_contains` pattern found in the generated log lines, or `no_log_contains` pattern not found in that), then the test is PASSED
236
235
* FAILED - if none of them above
237
236
238
-
There are two mutations of the results PASSED and FAILED: if a test PASSED, but you listed it in your `test_whitelist`, then the output will `PASSED - WHITELISTED`. This is important, because you will informed that the bug eliminated. You will also noticed if the test FAILED, but that's expected by a know reason, eg: `FAILED - WHITELISTED`.
237
+
There are two mutations of the results PASSED and FAILED: if a test is PASSED, but you listed it in your `test_whitelist`, then the output will be `PASSED - WHITELISTED`. This is important, because you will be informed that the bug was eliminated. You will be also noticed if the test was FAILED, but that's expected by a known reason, eg: `FAILED - WHITELISTED`.
239
238
240
-
When the all tests finished, `ftwrunner` will inform you with a summary:
239
+
When the all tests are finished, `ftwrunner` will inform you with a summary:
241
240
242
241
```
243
242
SUMMARY:
@@ -251,9 +250,9 @@ TOTAL: 18
251
250
===============================
252
251
```
253
252
254
-
From this table, you can see how many test was PASSED, FAILED, SKIPPED. The whitelisted failed tests will showed separately.
253
+
From this sheet you can see how many tests were PASSED, FAILED or SKIPPED. The whitelisted failed tests will be shown separately.
255
254
256
-
If there are one or more failed test, the summary will extended with the list of those:
255
+
If there are one or more failed tests, the summary will be extended with the list of those:
257
256
258
257
```
259
258
SUMMARY:
@@ -269,39 +268,42 @@ TOTAL: 18
269
268
FAILED TESTS: 944110-15, 944110-16
270
269
```
271
270
272
-
It can helps you if you run a whole set of tests (actually it's more, that 2000), and then you can check them one by one.
271
+
It can help you if you run a whole set of tests (actually there's more than 2000) and then you can check them one by one.
273
272
274
273
Return value
275
274
------------
276
275
277
-
When `ftwrunner` terminates, the return value will be 0 if there isn't any error or failed test. If the error occurred until the run (eg. your config file not found, can't open the debug.log, ...), the return value vill be less than 0 (usually -1). If there were one or more failed test, the return value will be greather than 0, it will the number of failed test. See the example above:
276
+
When `ftwrunner` terminates, the return value will be 0 if there isn't any error or failed test. If the error occurred while running (eg. your config file is not found or can't open the debug.log, ...), the return value will be different from 0 (usually 1). If there were one or more failed tests, the return value will be greater than 0, it will be the number of failed tests. See the example above:
`ftwunner` can help to discover memory leaks in the library. It's highly recommended to make a minimal configuration (eg. only 1 rule) and make a test for that rule. Then you will see only the specific place where the memleak occurrs.
304
+
`ftwunner` can help you to detect memory leaks in the library. It's highly recommended to create a minimal configuration (eg. only 1 rule) and run a test with that rule. Then you will only see the place where the memleak occurrs.
Theoretically you must get a `no leaks are possible`answer from Valgrind:
396
+
In theory, you should get a `no leaks are possible`response from Valgrind:
395
397
```
396
398
...
397
399
==359704==
@@ -404,13 +406,10 @@ Theoretically you must get a `no leaks are possible` answer from Valgrind:
404
406
==359704== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
405
407
```
406
408
407
-
408
-
409
-
410
409
Reporting issues
411
410
================
412
411
413
-
If you ran an unexpected behavior, found a bug, or have a feature request, just open an issue here, or drop an e-mail to us: modsecurity at digitalwave dot hu.
412
+
If you experience unexpected behavior, find a bug, or need a feature, just open an issue here or write us an email: modsecurity at digitalwave dot hu.
0 commit comments