Skip to content

Commit 71c3f99

Browse files
authored
Merge pull request #20 from Sebitosh/uri-override
Utility change: allow manually defining URI for using reflection capability of albedo
2 parents d96606c + c527c75 commit 71c3f99

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,25 @@ The field `input.encoded_request` allows defining a whole request encoded in bas
454454
encoded_request: R0VUIC8gSFRUUC8xLjENCkhvc3Q6IGxvY2FsaG9zdA0KDQo=
455455
```
456456

457+
#### Uri
458+
459+
The field `input.uri` allows defining the uri used for the request manually. This is in particular useful for using the `/reflect` endpoint of [albedo](https://github.com/coreruleset/albedo) which allows defining what the server response should be from within the body of the post request that was sent.
460+
461+
```yaml
462+
targets:
463+
- target: ''
464+
test:
465+
data: '{"status": 201, "body": "<html>reflected-token</html>"}'
466+
input:
467+
headers:
468+
- name: Content-Type
469+
value: application/json
470+
uri: '/reflect'
471+
output:
472+
status: 201
473+
response_contains: "reflected-token"
474+
```
475+
457476
### Constants
458477
The yaml schema has a mechanism to handle global and local constants.
459478

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
target: ARGS
2+
rulefile: DEMO_008_URI_REFLECT.conf
3+
testfile: DEMO_008_URI_REFLECT.yaml
4+
templates:
5+
- SecRule for TARGETS
6+
colkey:
7+
- - ''
8+
operator:
9+
- '@contains'
10+
oparg:
11+
- foo
12+
phase:
13+
- 2
14+
testdata:
15+
phase_methods:
16+
2: post
17+
targets:
18+
- target: ''
19+
test:
20+
data: '{"status": 201, "body": "<html>reflected-token</html>"}'
21+
input:
22+
headers:
23+
- name: Content-Type
24+
value: application/json
25+
uri: '/reflect'
26+
output:
27+
status: 201
28+
response_contains: "reflected-token"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SecRule ARGS "@contains foo" \
2+
"id:100013,\
3+
phase:2,\
4+
deny,\
5+
t:none,\
6+
log,\
7+
msg:'%{MATCHED_VAR_NAME} was caught in phase:2',\
8+
ver:'MRTS/0.1'"
9+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
meta:
3+
author: MRTS generate-rules.py
4+
enabled: true
5+
name: DEMO_008_URI_REFLECT.yaml
6+
description: Desc
7+
tests:
8+
- test_title: 100013-1
9+
ruleid: 100013
10+
test_id: 1
11+
desc: 'Test case for rule 100013, #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+
Content-Type: application/json
24+
uri: /reflect
25+
version: HTTP/1.1
26+
data: '{"status": 201, "body": "<html>reflected-token</html>"}'
27+
output:
28+
status: 201
29+
response_contains: reflected-token

mrts/generate-rules.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ def genrulefromtemplate(self, tpl, current_confdata):
349349
item['stages'][0]['input']['headers'][h['name']] = h['value']
350350
if 'encoded_request' in test['test']['input']:
351351
item['stages'][0]['input']['encoded_request'] = test['test']['input']['encoded_request']
352+
if 'uri' in test['test']['input']:
353+
item['stages'][0]['input']['uri'] = test['test']['input']['uri']
352354
# overwrite default output field
353355
if 'output' in test['test']:
354356
item['stages'][0]['output'] = test['test']['output']

0 commit comments

Comments
 (0)