Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.

Commit 5f60c3b

Browse files
committed
Fix bypass in 931130
Don't rely on beginsWith as it might allow attackers to create subdomains matching the prefix. Add tests to cover this and other cases. The latter fixes #1404.
1 parent d390c92 commit 5f60c3b

File tree

2 files changed

+105
-3
lines changed

2 files changed

+105
-3
lines changed

rules/REQUEST-931-APPLICATION-ATTACK-RFI.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ SecRule TX:EXECUTING_PARANOIA_LEVEL "@lt 2" "id:931014,phase:2,pass,nolog,skipAf
101101
# -= Paranoia Level 2 =- (apply only when tx.executing_paranoia_level is sufficiently high: 2 or higher)
102102
#
103103

104-
SecRule ARGS "@rx ^(?i:file|ftps?|https?)://(.*)$" \
104+
SecRule ARGS "@rx ^(?i:file|ftps?|https?)://([^/]*).*$" \
105105
"id:931130,\
106106
phase:2,\
107107
block,\
@@ -119,9 +119,9 @@ SecRule ARGS "@rx ^(?i:file|ftps?|https?)://(.*)$" \
119119
ctl:auditLogParts=+E,\
120120
ver:'OWASP_CRS/3.2.0',\
121121
severity:'CRITICAL',\
122-
setvar:'tx.rfi_parameter_%{MATCHED_VAR_NAME}=%{tx.1}',\
122+
setvar:'tx.rfi_parameter_%{MATCHED_VAR_NAME}=.%{tx.1}',\
123123
chain"
124-
SecRule TX:/rfi_parameter_.*/ "!@beginsWith %{request_headers.host}" \
124+
SecRule TX:/rfi_parameter_.*/ "!@endsWith .%{request_headers.host}" \
125125
"setvar:'tx.rfi_score=+%{tx.critical_anomaly_score}',\
126126
setvar:'tx.anomaly_score_pl2=+%{tx.critical_anomaly_score}'"
127127

util/regression-tests/tests/REQUEST-931-APPLICATION-ATTACK-RFI/931130.yaml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,105 @@
8989
version: HTTP/1.1
9090
output:
9191
log_contains: id "931130"
92+
-
93+
test_title: 931130-6
94+
desc: Partial match
95+
stages:
96+
-
97+
stage:
98+
input:
99+
dest_addr: 127.0.0.1
100+
headers:
101+
User-Agent: "ModSecurity CRS 3 Tests"
102+
Host: example.com
103+
method: GET
104+
port: 80
105+
uri: /?x=https://evilexample.com/
106+
version: HTTP/1.1
107+
output:
108+
log_contains: id "931130"
109+
-
110+
test_title: 931130-7
111+
desc: Mismatching domains
112+
stages:
113+
-
114+
stage:
115+
input:
116+
dest_addr: 127.0.0.1
117+
headers:
118+
User-Agent: "ModSecurity CRS 3 Tests"
119+
Host: example.com
120+
method: GET
121+
port: 80
122+
uri: /?x=https://example.com.evil.com/
123+
version: HTTP/1.1
124+
output:
125+
log_contains: id "931130"
126+
-
127+
test_title: 931130-8
128+
desc: Mismatching ports
129+
stages:
130+
-
131+
stage:
132+
input:
133+
dest_addr: 127.0.0.1
134+
headers:
135+
User-Agent: "ModSecurity CRS 3 Tests"
136+
Host: example.com
137+
method: GET
138+
port: 80
139+
uri: /?x=https://example.com:1234/
140+
version: HTTP/1.1
141+
output:
142+
log_contains: id "931130"
143+
-
144+
test_title: 931130-9
145+
desc: Matching hosts
146+
stages:
147+
-
148+
stage:
149+
input:
150+
dest_addr: 127.0.0.1
151+
headers:
152+
User-Agent: "ModSecurity CRS 3 Tests"
153+
Host: example.com
154+
method: GET
155+
port: 80
156+
uri: /?x=https://example.com/
157+
version: HTTP/1.1
158+
output:
159+
no_log_contains: id "931130"
160+
-
161+
test_title: 931130-10
162+
desc: Matching hosts and ports
163+
stages:
164+
-
165+
stage:
166+
input:
167+
dest_addr: 127.0.0.1
168+
headers:
169+
User-Agent: "ModSecurity CRS 3 Tests"
170+
Host: example.com
171+
method: GET
172+
port: 80
173+
uri: /?x=https://example.com:1234/
174+
version: HTTP/1.1
175+
output:
176+
log_contains: id "931130"
177+
-
178+
test_title: 931130-11
179+
desc: Subdomains
180+
stages:
181+
-
182+
stage:
183+
input:
184+
dest_addr: 127.0.0.1
185+
headers:
186+
User-Agent: "ModSecurity CRS 3 Tests"
187+
Host: example.com
188+
method: GET
189+
port: 80
190+
uri: /?x=http://www.example.com/some/path
191+
version: HTTP/1.1
192+
output:
193+
no_log_contains: id "931130"

0 commit comments

Comments
 (0)