Skip to content

Commit bf9a532

Browse files
committed
Test target DURATION
Signed-off-by: Sebitosh <[email protected]>
1 parent 2bf51f8 commit bf9a532

12 files changed

+248
-15
lines changed

config_tests/CONF_000_GLOBAL.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ global:
1313
log,\
1414
msg:'%{MATCHED_VAR_NAME} was caught in phase:${PHASE}$',\
1515
ver:'${VERSION}$'"
16+
- name: "SecRule for TARGETS with ACTIONS"
17+
template: |
18+
SecRule ${TARGET}$ "${OPERATOR}$ ${OPARG}$" \
19+
"id:${CURRID}$,\
20+
phase:${PHASE}$,\
21+
t:none,\
22+
log,\
23+
msg:'%{MATCHED_VAR_NAME} was caught in phase:${PHASE}$ with value %{MATCHED_VAR}',\
24+
${ACTIONS}$,\
25+
ver:'${VERSION}$'"
1626
default_tests_phase_methods:
1727
- 1: get
1828
- 2: post
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
target: DURATION
2+
rulefile: MRTS_010_DURATION.conf
3+
testfile: MRTS_010_DURATION.yaml
4+
templates:
5+
- SecRule for TARGETS with ACTIONS
6+
generation:
7+
before: |
8+
# Set starting duration marker
9+
SecAction "id:${CURRID}$,phase:1, setvar:tx.duration_marker=0"
10+
actions:
11+
- action:
12+
- setvar:tx.duration_marker=%{MATCHED_VAR} # set duration marker at matched value
13+
colkey:
14+
- - ''
15+
operator:
16+
- '@gt'
17+
oparg:
18+
- '%{tx.duration_marker}' # check on previously matched duration as we expect it to increase at each phase
19+
phase:
20+
- 1
21+
- 2
22+
- 3
23+
- 4
24+
- 5
25+
testdata:
26+
phase_methods:
27+
1: get
28+
2: post
29+
3: post
30+
4: post
31+
5: post
32+
targets:
33+
- target: ''
34+
test:
35+
data: null
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Set starting duration marker
2+
SecAction "id:100092,phase:1, setvar:tx.duration_marker=0"
3+
4+
SecRule DURATION "@gt %{tx.duration_marker}" \
5+
"id:100093,\
6+
phase:1,\
7+
t:none,\
8+
log,\
9+
msg:'%{MATCHED_VAR_NAME} was caught in phase:1 with value %{MATCHED_VAR}',\
10+
setvar:tx.duration_marker=%{MATCHED_VAR},\
11+
ver:'MRTS/0.1'"
12+
13+
SecRule DURATION "@gt %{tx.duration_marker}" \
14+
"id:100094,\
15+
phase:2,\
16+
t:none,\
17+
log,\
18+
msg:'%{MATCHED_VAR_NAME} was caught in phase:2 with value %{MATCHED_VAR}',\
19+
setvar:tx.duration_marker=%{MATCHED_VAR},\
20+
ver:'MRTS/0.1'"
21+
22+
SecRule DURATION "@gt %{tx.duration_marker}" \
23+
"id:100095,\
24+
phase:3,\
25+
t:none,\
26+
log,\
27+
msg:'%{MATCHED_VAR_NAME} was caught in phase:3 with value %{MATCHED_VAR}',\
28+
setvar:tx.duration_marker=%{MATCHED_VAR},\
29+
ver:'MRTS/0.1'"
30+
31+
SecRule DURATION "@gt %{tx.duration_marker}" \
32+
"id:100096,\
33+
phase:4,\
34+
t:none,\
35+
log,\
36+
msg:'%{MATCHED_VAR_NAME} was caught in phase:4 with value %{MATCHED_VAR}',\
37+
setvar:tx.duration_marker=%{MATCHED_VAR},\
38+
ver:'MRTS/0.1'"
39+
40+
SecRule DURATION "@gt %{tx.duration_marker}" \
41+
"id:100097,\
42+
phase:5,\
43+
t:none,\
44+
log,\
45+
msg:'%{MATCHED_VAR_NAME} was caught in phase:5 with value %{MATCHED_VAR}',\
46+
setvar:tx.duration_marker=%{MATCHED_VAR},\
47+
ver:'MRTS/0.1'"
48+

generated/rules/MRTS_110_XML.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
SecRule XML:/* "@beginsWith foo" \
2-
"id:100092,\
2+
"id:100098,\
33
phase:2,\
44
deny,\
55
t:none,\
@@ -8,7 +8,7 @@ SecRule XML:/* "@beginsWith foo" \
88
ver:'MRTS/0.1'"
99

1010
SecRule XML:/* "@beginsWith foo" \
11-
"id:100093,\
11+
"id:100099,\
1212
phase:3,\
1313
deny,\
1414
t:none,\
@@ -17,7 +17,7 @@ SecRule XML:/* "@beginsWith foo" \
1717
ver:'MRTS/0.1'"
1818

1919
SecRule XML:/* "@beginsWith foo" \
20-
"id:100094,\
20+
"id:100100,\
2121
phase:4,\
2222
deny,\
2323
t:none,\
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
meta:
3+
author: MRTS generate-rules.py
4+
enabled: true
5+
name: MRTS_010_DURATION.yaml
6+
description: Desc
7+
tests:
8+
- test_title: 100093-1
9+
ruleid: 100093
10+
test_id: 1
11+
desc: 'Test case for rule 100093, #1'
12+
stages:
13+
- description: Send request
14+
input:
15+
dest_addr: 127.0.0.1
16+
port: 80
17+
protocol: http
18+
method: GET
19+
headers:
20+
User-Agent: OWASP MRTS test agent
21+
Host: localhost
22+
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
23+
uri: /
24+
version: HTTP/1.1
25+
output:
26+
log:
27+
expect_ids:
28+
- 100093
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
meta:
3+
author: MRTS generate-rules.py
4+
enabled: true
5+
name: MRTS_010_DURATION.yaml
6+
description: Desc
7+
tests:
8+
- test_title: 100094-1
9+
ruleid: 100094
10+
test_id: 1
11+
desc: 'Test case for rule 100094, #1'
12+
stages:
13+
- description: Send request
14+
input:
15+
dest_addr: 127.0.0.1
16+
port: 80
17+
protocol: http
18+
method: POST
19+
headers:
20+
User-Agent: OWASP MRTS test agent
21+
Host: localhost
22+
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
23+
uri: /post
24+
version: HTTP/1.1
25+
output:
26+
log:
27+
expect_ids:
28+
- 100094
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
meta:
3+
author: MRTS generate-rules.py
4+
enabled: true
5+
name: MRTS_010_DURATION.yaml
6+
description: Desc
7+
tests:
8+
- test_title: 100095-1
9+
ruleid: 100095
10+
test_id: 1
11+
desc: 'Test case for rule 100095, #1'
12+
stages:
13+
- description: Send request
14+
input:
15+
dest_addr: 127.0.0.1
16+
port: 80
17+
protocol: http
18+
method: POST
19+
headers:
20+
User-Agent: OWASP MRTS test agent
21+
Host: localhost
22+
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
23+
uri: /post
24+
version: HTTP/1.1
25+
output:
26+
log:
27+
expect_ids:
28+
- 100095
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
meta:
3+
author: MRTS generate-rules.py
4+
enabled: true
5+
name: MRTS_010_DURATION.yaml
6+
description: Desc
7+
tests:
8+
- test_title: 100096-1
9+
ruleid: 100096
10+
test_id: 1
11+
desc: 'Test case for rule 100096, #1'
12+
stages:
13+
- description: Send request
14+
input:
15+
dest_addr: 127.0.0.1
16+
port: 80
17+
protocol: http
18+
method: POST
19+
headers:
20+
User-Agent: OWASP MRTS test agent
21+
Host: localhost
22+
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
23+
uri: /post
24+
version: HTTP/1.1
25+
output:
26+
log:
27+
expect_ids:
28+
- 100096
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
meta:
3+
author: MRTS generate-rules.py
4+
enabled: true
5+
name: MRTS_010_DURATION.yaml
6+
description: Desc
7+
tests:
8+
- test_title: 100097-1
9+
ruleid: 100097
10+
test_id: 1
11+
desc: 'Test case for rule 100097, #1'
12+
stages:
13+
- description: Send request
14+
input:
15+
dest_addr: 127.0.0.1
16+
port: 80
17+
protocol: http
18+
method: POST
19+
headers:
20+
User-Agent: OWASP MRTS test agent
21+
Host: localhost
22+
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
23+
uri: /post
24+
version: HTTP/1.1
25+
output:
26+
log:
27+
expect_ids:
28+
- 100097

generated/tests/regression/tests/MRTS_110_XML_100092.yaml renamed to generated/tests/regression/tests/MRTS_110_XML_100098.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ meta:
55
name: MRTS_110_XML.yaml
66
description: Desc
77
tests:
8-
- test_title: 100092-1
9-
ruleid: 100092
8+
- test_title: 100098-1
9+
ruleid: 100098
1010
test_id: 1
11-
desc: 'Test case for rule 100092, #1'
11+
desc: 'Test case for rule 100098, #1'
1212
stages:
1313
- description: Send request
1414
input:
@@ -27,4 +27,4 @@ tests:
2727
output:
2828
log:
2929
expect_ids:
30-
- 100092
30+
- 100098

0 commit comments

Comments
 (0)