Building 70 Projects ranging from beginner to advanced so anyone can — learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company 👇
Go aicertificationcloud-engineeringcybercybersecuritycybersecurity-analystcybersecurity-certificationcybersecurity-certificationscybersecurity-educationcybersecurity-jobscybersecurity-portfoliocybersecurity-projectscybersecurity-toolsgrchackinglearningpentestingproject-repositoryprojetcspython
#!/usr/bin/env bash
# ©AngelaMos | 2026
# m10-gate.sh
set -euo pipefail
# shellcheck source=scripts/magma-guard.sh
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/magma-guard.sh"
WORK="${MAGMA_WORK:-/opt/magma-work}"
OUT_ROOT="$WORK/out/libpng"
SEEDS="$WORK/libpng/corpus/libpng_read_fuzzer"
GATE="$WORK/m10"
FINDINGS="$GATE/findings"
DB="$GATE/lisdex.sqlite"
EMPTY="$GATE/empty"
SANDBOX="$GATE/sandbox"
GATE_LOG="$GATE/stage.log"
CAMPAIGN_LOG="$GATE/campaign.log"
SERVE_LOG="$GATE/serve.log"
INSTALL_LOG="$GATE/install.log"
LISDEX_BIN="${CARGO_TARGET_DIR:-/cargo-target}/debug/lisdex"
TARGET="$OUT_ROOT/afl/lisdex_libpng_read"
CMPLOG="$OUT_ROOT/cmplog/lisdex_libpng_read"
GATE_DURATION="${LISDEX_M10_DURATION:-180}"
GATE_PORT="${LISDEX_M10_PORT:-47231}"
DASH_MANIFEST="crates/lisdex-dashboard/Cargo.toml"
DASH_SRC="crates/lisdex-dashboard/src"
LEARN="learn"
LEARN_DOCS=(00-OVERVIEW.md 01-CONCEPTS.md 02-ARCHITECTURE.md 03-IMPLEMENTATION.md 04-CHALLENGES.md)
ANALYSIS_SYMBOLS=("classify" "group_crashes" "SanitizerReport" "plot::parse" "stack_hash" "libcasr" "rusqlite")
FAILURES=0
SERVE_PID=""
log() { printf '\n[m10] %s\n' "$1"; }
die() { printf '\n[m10] FAIL: %s\n' "$1" >&2; exit 1; }
pass() { printf ' PASS %s\n' "$1"; }
fail() { printf ' FAIL %s\n' "$1"; FAILURES=$((FAILURES + 1)); }
stop_server() { [ -n "$SERVE_PID" ] && kill "$SERVE_PID" 2>/dev/null; return 0; }
trap stop_server EXIT
if [ "${1:-}" = "reset" ]; then
log "resetting $GATE"
rm -rf "$GATE"
fi
[ -x "$TARGET" ] || die "magma libpng not built; run: just magma-libpng"
require_harness_current "$OUT_ROOT"
[ -f "$DASH_MANIFEST" ] || die "run this from the project root; $DASH_MANIFEST not found"
mkdir -p "$GATE" "$EMPTY"
log "stage 1/8: build lisdex"
cargo build -p lisdex
[ -x "$LISDEX_BIN" ] || die "lisdex binary not found at $LISDEX_BIN"
log "stage 2/8: the console is a view, exactly like the panel"
LINKED="$(awk '/^\[dependencies\]/{on=1;next} /^\[/{on=0} on' "$DASH_MANIFEST" \
| grep -oE '^lisdex-[a-z]+' | sort -u | tr '\n' ' ' | sed 's/ $//')"
if [ "$LINKED" = "lisdex-monitor" ]; then
pass "lisdex-dashboard links exactly one lisdex crate: $LINKED"
else
fail "lisdex-dashboard links [$LINKED]; a pure view must link only lisdex-monitor"
fi
CONSOLE_HITS=0
for symbol in "${ANALYSIS_SYMBOLS[@]}"; do
HITS="$(grep -rF -- "$symbol" "$DASH_SRC" | grep -c . || true)"
[ "$HITS" -ne 0 ] && CONSOLE_HITS=$((CONSOLE_HITS + 1))
done
if [ "$CONSOLE_HITS" -eq 0 ]; then
pass "the console's source names no analysis symbol"
else
fail "the console mentions $CONSOLE_HITS analysis symbol(s); analysis belongs in the model"
fi
log "stage 3/8: the console answers for itself"
if cargo test -p lisdex-dashboard > "$GATE_LOG" 2>&1; then
TESTS="$(grep -oE 'test result: ok\. [0-9]+' "$GATE_LOG" | grep -oE '[0-9]+' | paste -sd+ | bc)"
pass "lisdex-dashboard: $TESTS tests"
else
fail "lisdex-dashboard tests (see $GATE_LOG)"
fi
log "stage 4/8: a real campaign for the console to serve (${GATE_DURATION}s)"
if [ ! -f "$DB" ]; then
rm -rf "$FINDINGS"
"$LISDEX_BIN" fuzz --target "$TARGET" --cmplog "$CMPLOG" --seeds "$SEEDS" \
--findings "$FINDINGS" --db "$DB" --duration "$GATE_DURATION" \
> "$CAMPAIGN_LOG" 2>&1 || die "campaign failed (see $CAMPAIGN_LOG)"
else
log "reusing the campaign already at $DB"
fi
log "stage 5/8: lisdex serve is live and answers over HTTP"
"$LISDEX_BIN" serve --db "$DB" --findings "$FINDINGS" \
--host 127.0.0.1 --port "$GATE_PORT" > "$SERVE_LOG" 2>&1 &
SERVE_PID=$!
WAITED=0
until curl -fsS -o /dev/null "http://127.0.0.1:${GATE_PORT}/" 2>/dev/null; do
sleep 1
WAITED=$((WAITED + 1))
[ "$WAITED" -gt 30 ] && die "console never came up (see $SERVE_LOG)"
done
pass "the console answered on 127.0.0.1:${GATE_PORT} after ${WAITED}s"
PAGE="$GATE/console.html"
curl -fsS "http://127.0.0.1:${GATE_PORT}/" -o "$PAGE"
if grep -q '<title>lisdex console</title>' "$PAGE"; then
pass "it serves the console page"
else
fail "the page served is not the console"
fi
if grep -qE 'src="http|src="//|href="http|href="//|@import' "$PAGE"; then
fail "the console page loads an asset off this machine"
else
pass "the console page loads nothing from the network"
fi
SNAP="$GATE/snapshot.json"
curl -fsS "http://127.0.0.1:${GATE_PORT}/api/snapshot" -o "$SNAP"
if python3 -c "import json,sys; json.load(open('$SNAP'))" 2>/dev/null; then
pass "the snapshot endpoint answers with valid JSON"
else
fail "the snapshot endpoint did not answer with valid JSON"
fi
log "stage 6/8: the console agrees with the tools it is a view over"
CLI_CRASHES="$("$LISDEX_BIN" crashes --db "$DB" --campaign 1 | grep -c 'stack_hash' || true)"
CLI_BUGS="$("$LISDEX_BIN" crashes --db "$DB" --campaign 1 \
| grep -oE 'stack_hash [0-9a-f]+' | sort -u | grep -c . || true)"
CLI_PEAK="$("$LISDEX_BIN" coverage --findings "$FINDINGS" | awk '/curve_peak_edges/ {print $2}')"
read -r WEB_CRASHES WEB_BUGS WEB_PEAK WEB_TARGET <<EOF
$(python3 -c "
import json
d = json.load(open('$SNAP'))
s = d['summary']
print(s['total_crashes'], s['distinct_bugs'], s['peak_edges'], d['campaign']['target'])
")
EOF
if [ "$CLI_CRASHES" -gt 0 ]; then
pass "the campaign persisted $CLI_CRASHES crash(es), so the comparison is not vacuous"
else
fail "no crash was persisted; the comparison below proves nothing"
fi
[ "$WEB_CRASHES" = "$CLI_CRASHES" ] \
&& pass "crash count agrees with 'lisdex crashes': $WEB_CRASHES" \
|| fail "console shows $WEB_CRASHES crashes, 'lisdex crashes' reports $CLI_CRASHES"
[ "$WEB_BUGS" = "$CLI_BUGS" ] \
&& pass "distinct-bug count agrees with 'lisdex crashes': $WEB_BUGS" \
|| fail "console shows $WEB_BUGS bugs, 'lisdex crashes' reports $CLI_BUGS"
[ "$WEB_PEAK" = "$CLI_PEAK" ] \
&& pass "peak edges agrees with 'lisdex coverage': $WEB_PEAK" \
|| fail "console shows $WEB_PEAK peak edges, 'lisdex coverage' reports $CLI_PEAK"
EMPTY_SNAP="$GATE/empty.json"
"$LISDEX_BIN" serve --db "$EMPTY/none.sqlite" --findings "$EMPTY" \
--host 127.0.0.1 --port "$((GATE_PORT + 1))" > /dev/null 2>&1 &
EMPTY_PID=$!
sleep 2
curl -fsS "http://127.0.0.1:$((GATE_PORT + 1))/api/snapshot" -o "$EMPTY_SNAP" 2>/dev/null || true
kill "$EMPTY_PID" 2>/dev/null || true
if [ -s "$EMPTY_SNAP" ] && ! grep -q "$WEB_TARGET" "$EMPTY_SNAP"; then
pass "an empty console names no target, so the live one really read from disk"
else
fail "the empty console served the numbers of a real campaign, or did not answer"
fi
stop_server
SERVE_PID=""
log "stage 7/8: install.sh takes a clean prefix to a runnable lisdex"
rm -rf "$SANDBOX"
mkdir -p "$SANDBOX"
if HOME="$SANDBOX" LISDEX_INSTALL_DIR="$SANDBOX/bin" \
CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-/cargo-target}-rel" \
bash install.sh --skip-afl > "$INSTALL_LOG" 2>&1; then
pass "install.sh completed"
else
fail "install.sh failed (see $INSTALL_LOG)"
fi
if [ -x "$SANDBOX/bin/lisdex" ]; then
pass "a binary landed in the prefix"
else
fail "no binary at $SANDBOX/bin/lisdex"
fi
AFL_PROBE="$GATE/afl-version-probe.sh"
awk '/^afl_version\(\) \{/,/^\}/' install.sh > "$AFL_PROBE"
if ! command -v afl-fuzz >/dev/null 2>&1; then
fail "no afl-fuzz here, so the afl_version probe below cannot discriminate"
elif [ ! -s "$AFL_PROBE" ]; then
fail "could not extract afl_version from install.sh; the probe would pass vacuously"
elif bash -c "set -euo pipefail; . '$AFL_PROBE'; v=\"\$(afl_version)\"; [ -n \"\$v\" ]" 2>/dev/null; then
pass "afl_version returns a version and survives set -euo pipefail"
else
fail "afl_version kills the shell under pipefail, and --skip-afl hides that from the install above"
fi
INSTALLED_VERSION="$(PATH="$SANDBOX/bin:$PATH" lisdex --version 2>/dev/null || true)"
if [ -n "$INSTALLED_VERSION" ]; then
pass "it runs by its bare name: $INSTALLED_VERSION"
else
fail "the installed binary does not run by its bare name"
fi
if echo "$INSTALLED_VERSION" | grep -qE '0\.0\.0'; then
fail "the shipped binary reports version 0.0.0"
else
pass "it reports a real version"
fi
if grep -qE '^export PATH=' "$SANDBOX/.bash_profile" 2>/dev/null \
|| grep -qE '^export PATH=' "$SANDBOX/.bashrc" 2>/dev/null; then
pass "install.sh wired the prefix onto PATH"
else
fail "install.sh did not wire PATH, so a fresh shell would not find lisdex"
fi
if bash uninstall.sh --prefix "$SANDBOX/bin" > /dev/null 2>&1 && [ ! -e "$SANDBOX/bin/lisdex" ]; then
pass "uninstall.sh removes what install.sh placed"
else
fail "uninstall.sh did not remove the binary"
fi
log "stage 8/8: the public docs are complete and their links resolve"
for doc in "${LEARN_DOCS[@]}"; do
if [ -s "$LEARN/$doc" ]; then
pass "learn/$doc"
else
fail "learn/$doc is missing or empty"
fi
done
[ -s README.md ] && pass "README.md" || fail "README.md is missing or empty"
BROKEN=""
while IFS= read -r link; do
case "$link" in
http*|\#*) continue ;;
esac
[ -e "$link" ] || BROKEN="$BROKEN $link"
done < <(grep -ohE '\]\([^)#]+\)' README.md "$LEARN"/*.md | sed -E 's/^\]\(//; s/\)$//' | sort -u)
if [ -z "$BROKEN" ]; then
pass "every relative link in README.md and learn/ resolves"
else
fail "broken relative link(s):$BROKEN"
fi
if grep -rqE 'lisdex surface --source' README.md "$LEARN"/*.md install.sh; then
fail "the docs show 'surface --source', which is not the flag the CLI takes"
else
pass "the documented commands match the CLI's own usage"
fi
log "RESULT"
if [ "$FAILURES" -eq 0 ]; then
printf '\n[m10] M10 EXIT GATE PASSED\n'
printf ' CHECK 1 the web console is a view over the model, like the panel\n'
printf ' CHECK 2 lisdex serve answers over HTTP and loads nothing off this machine\n'
printf ' CHECK 3 its counts equal what lisdex crashes and lisdex coverage report\n'
printf ' CHECK 4 install.sh yields a lisdex that runs by its bare name, and uninstalls\n'
printf ' CHECK 5 learn/ 00-04 and the README are complete and their links resolve\n'
exit 0
fi
printf '\n[m10] M10 EXIT GATE FAILED: %s check(s)\n' "$FAILURES" >&2
exit 1