#!/bin/bash # Security testing for Pulse # Tests authentication, authorization, input validation, etc. set -e PULSE_URL=${1:-http://localhost:7655} API_TOKEN=${2:-""} RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' echo "================================================" echo "SECURITY TESTING" echo "================================================" VULNERABILITIES=0 test_security() { local test_name="$1" local command="$2" local expected="$3" echo -n "$test_name: " RESULT=$(eval "$command" 2>/dev/null || echo "ERROR") if [[ "$RESULT" == *"$expected"* ]]; then echo -e "${GREEN}✓ Secure${NC}" else echo -e "${RED}✗ VULNERABLE${NC}" ((VULNERABILITIES++)) fi } echo "" echo "1. AUTHENTICATION BYPASS ATTEMPTS" echo "=================================" test_security "Empty auth header" \ "curl -s -H 'X-API-Token: ' $PULSE_URL/api/state | head -1" \ "Authentication required" test_security "Null token" \ "curl -s -H 'X-API-Token: null' $PULSE_URL/api/state | head -1" \ "Authentication required" test_security "SQL injection in token" \ "curl -s -H \"X-API-Token: ' OR '1'='1\" $PULSE_URL/api/state | head -1" \ "Authentication required" test_security "Command injection in token" \ "curl -s -H 'X-API-Token: \$(whoami)' $PULSE_URL/api/state | head -1" \ "Authentication required" test_security "Path traversal in token" \ "curl -s -H 'X-API-Token: ../../etc/passwd' $PULSE_URL/api/state | head -1" \ "Authentication required" echo "" echo "2. PATH TRAVERSAL ATTEMPTS" echo "==========================" test_security "Path traversal in URL" \ "curl -s -o /dev/null -w '%{http_code}' $PULSE_URL/../../../etc/passwd" \ "401" # 401 is fine - auth blocks before path processing test_security "Double URL encoding" \ "curl -s -o /dev/null -w '%{http_code}' $PULSE_URL/%252e%252e%252f%252e%252e%252fetc%252fpasswd" \ "401" # 401 is secure - auth blocks first test_security "Null byte injection" \ "curl -s -o /dev/null -w '%{http_code}' '$PULSE_URL/api/health%00.json'" \ "401" # Expected - auth required echo "" echo "3. XSS ATTEMPTS" echo "===============" test_security "XSS in query parameter" \ "curl -s '$PULSE_URL/api/health?test=' | grep -c '' $PULSE_URL | grep -c '' | grep -c '