Skip to content

Reverse Engineering / Authorized Penetration Testing / Security Research Skill Router Pack AI-powered routing + On-demand toolchain bootstrapping + Self-evolving knowledge base Supports Claude Code, Kiro, Cursor, Cline, and other AI coding clients 逆向/渗透/安全技能路由包 - AI 自动路由 + 按需自举工具链 + 自动进化经验库 | 支持 Claude Code / Kiro / Cursor / Cline 等代码 AI 客户端

Shell

test(kali): keep pwntools regression hermetic

zhaoxuya5207ccec6ceb68e
diff --git a/kali/scripts/test-pwntools-discovery.sh b/kali/scripts/test-pwntools-discovery.sh
index ae49229..f9f3eff 100755
--- a/kali/scripts/test-pwntools-discovery.sh
+++ b/kali/scripts/test-pwntools-discovery.sh
@@ -4,6 +4,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
REFRESH="$SCRIPT_DIR/refresh-tool-index.sh"
+DISCOVERY="$SCRIPT_DIR/lib/tool-discovery.sh"
BOOTSTRAP="$SCRIPT_DIR/bootstrap-reverse.sh"
REAL_BASH="$(command -v bash)"
REAL_PYTHON="$(command -v python3)"
@@ -12,13 +13,42 @@ trap 'rm -rf "$SCRATCH"' EXIT
BIN_DIR="$SCRATCH/bin"
HOME_DIR="$SCRATCH/home"
+FIXTURE_SCRIPTS="$SCRATCH/fixture/kali/scripts"
OUTPUT_MD="$SCRATCH/tool-index.md"
OUTPUT_JSON="$SCRATCH/tool-index.json"
-mkdir -p "$BIN_DIR" "$HOME_DIR"
+mkdir -p "$BIN_DIR" "$HOME_DIR" "$FIXTURE_SCRIPTS/lib"
+
+# Exercise a byte-for-byte copy of the production refresh path and discovery
+# catalog, changing only the port probe in the temporary copy. This prevents
+# localhost connections while preserving the real discovery implementation.
+cp "$REFRESH" "$FIXTURE_SCRIPTS/refresh-tool-index.sh"
+cp "$DISCOVERY" "$FIXTURE_SCRIPTS/lib/tool-discovery.sh"
+"$REAL_PYTHON" - "$FIXTURE_SCRIPTS/lib/tool-discovery.sh" <<'PY'
+import sys
+from pathlib import Path
+
+path = Path(sys.argv[1])
+lines = path.read_text(encoding="utf-8").splitlines(keepends=True)
+starts = [index for index, line in enumerate(lines) if line.rstrip("\r\n") == "test_tcp_port() {"]
+if len(starts) != 1:
+ raise SystemExit(f"expected exactly one test_tcp_port function, found {len(starts)}")
+
+start = starts[0]
+ends = [index for index in range(start + 1, len(lines)) if lines[index].rstrip("\r\n") == "}"]
+if not ends:
+ raise SystemExit("could not find the end of test_tcp_port")
+end = ends[0]
+if end - start > 20:
+ raise SystemExit("test_tcp_port is no longer the expected short function")
+
+lines[start : end + 1] = ["test_tcp_port() {\n", " return 1\n", "}\n"]
+path.write_text("".join(lines), encoding="utf-8")
+PY
+REFRESH="$FIXTURE_SCRIPTS/refresh-tool-index.sh"
# Keep discovery hermetic: expose only the host utilities required by the real
# refresh script. In particular, no host security tools can leak into results.
-for name in date dirname head jq uname; do
+for name in bash date dirname head mktemp python3 uname; do
source_path="$(command -v "$name")" || {
echo "required test dependency not found: $name" >&2
exit 1
@@ -26,6 +56,14 @@ for name in date dirname head jq uname; do
ln -s "$source_path" "$BIN_DIR/$name"
done
+HAVE_JQ=false
+if source_path="$(command -v jq 2>/dev/null)"; then
+ ln -s "$source_path" "$BIN_DIR/jq"
+ HAVE_JQ=true
+else
+ echo "SKIP: jq is unavailable; JSON-only pwntools assertions will not run" >&2
+fi
+
cat > "$BIN_DIR/pwn" <<'STUB'
#!/bin/bash
if [[ "${1:-}" == "--version" ]]; then
@@ -40,7 +78,8 @@ chmod +x "$BIN_DIR/pwn"
env PATH="$BIN_DIR" HOME="$HOME_DIR" \
"$REAL_BASH" "$REFRESH" "$OUTPUT_MD" "$OUTPUT_JSON" >/dev/null
-"$REAL_PYTHON" - "$OUTPUT_JSON" "$BIN_DIR/pwn" <<'PY'
+if [[ "$HAVE_JQ" == "true" ]]; then
+ "$REAL_PYTHON" - "$OUTPUT_JSON" "$BIN_DIR/pwn" <<'PY'
import json
import os
import sys
@@ -59,6 +98,7 @@ assert pwntools.get("version") == "Pwntools 4.15.0", (
f"expected pwntools version 'Pwntools 4.15.0', got {pwntools.get('version')!r}"
)
PY
+fi
"$REAL_PYTHON" - "$OUTPUT_MD" <<'PY'
import sys