#!/usr/bin/env bash # CWE-407 scan — Apache httpd (module graph, proxy balancer) set -euo pipefail echo "# scan=apache2 host=$(hostname) date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" cd /tmp && git clone --depth 1 https://github.com/apache/httpd apache2 2>&1 | tail -1 GRAPH_KW="topolog\|cycle\b\|reachab\|dependency\|dfs\b\|module.*order\|order.*module\|load.*order\|balancer.*node" C_MEM='apr_array_push.*==\|for.*elts\|ap_find_linked_module\|linear\|ap_array_.*find\|module.*contains' echo "# roots: /tmp/apache2/server /tmp/apache2/modules" find /tmp/apache2/server /tmp/apache2/modules -name "*.c" -o -name "*.h" 2>/dev/null | sort | while IFS= read -r f; do gl=$(grep -inE "$GRAPH_KW" "$f" 2>/dev/null | cut -d: -f1 | head -5 || true) [ -z "$gl" ] && continue while IFS= read -r ln; do s=$(( ln > 20 ? ln - 20 : 1 )); e=$(( ln + 20 )) hit=$(sed -n "${s},${e}p" "$f" 2>/dev/null | grep -iE "$C_MEM" | head -1 | sed 's/^\s*//' || true) [ -n "$hit" ] && echo "CANDIDATE ${f}:${ln} ${hit}" done <<< "$gl" done echo "# scan complete"