40 lines
No EOL
1.1 KiB
Bash
Executable file
40 lines
No EOL
1.1 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# Simple test script for HTTP/1.1 Host header compliance
|
|
# Usage: ./test_host_compliance.sh [IP] [PORT]
|
|
|
|
IP=${1:-"127.0.0.1"}
|
|
PORT=${2:-"6996"}
|
|
|
|
echo "Targeting server at $IP:$PORT"
|
|
|
|
test_req() {
|
|
NAME="$1"
|
|
PAYLOAD="$2"
|
|
EXPECTED="$3"
|
|
|
|
echo -n "Test: $NAME ... "
|
|
# Send payload, wait max 1s for response
|
|
RESP=$(printf "$PAYLOAD" | nc -w 1 $IP $PORT 2>/dev/null | head -n 1)
|
|
|
|
if echo "$RESP" | grep -q "$EXPECTED"; then
|
|
echo "PASS"
|
|
else
|
|
echo "FAIL (Expected '$EXPECTED', got '$RESP')"
|
|
fi
|
|
}
|
|
|
|
# 1. Valid Request
|
|
test_req "Valid Request" "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n" "200 OK"
|
|
|
|
# 2. Missing Host Header
|
|
test_req "Missing Host" "GET / HTTP/1.1\r\n\r\n" "400 Bad Request"
|
|
|
|
# 3. Empty Host Header
|
|
test_req "Empty Host" "GET / HTTP/1.1\r\nHost:\r\n\r\n" "400 Bad Request"
|
|
|
|
# 4. Multiple Host Headers
|
|
test_req "Multiple Hosts" "GET / HTTP/1.1\r\nHost: a\r\nHost: b\r\n\r\n" "400 Bad Request"
|
|
|
|
# 5. Bad Protocol Version (Should be 505 now with the fix)
|
|
test_req "Bad Protocol (HTTP/1.0)" "GET / HTTP/1.0\r\nHost: localhost\r\n\r\n" "505" |