D=/root/scans # xml FILE EXPR: run a Python expression on the root of an nmap XML file; # p(N) is port N's state, svc(N) its service element. xml() { python3 -c ' import sys, xml.etree.ElementTree as ET r = ET.parse(sys.argv[1]).getroot() def port(n): for p in r.iter("port"): if p.get("protocol") == "tcp" and p.get("portid") == str(n): return p def p(n): x = port(n) return x.find("state").get("state") if x is not None else None def svc(n): x = port(n) return x.find("service") if x is not None else None sys.exit(0 if eval(sys.argv[2]) else 1) ' "$1" "$2" 2>/dev/null } target() { grep -q 'addr="10\.99\.0\.1"' "$1"; } # rc PORT: curl's exit code from the peer (28 is a timeout, 7 refused). rc() { in_peer curl -s -o /dev/null --max-time 3 "http://10.99.0.1:$1/"; echo $?; } nginx_version() { nginx -v 2>&1 | sed 's|.*/||; s| .*||'; } task 1 "A baseline SYN scan in /root/scans/before.*" need "nmap is installed" 'command -v nmap' need "before.nmap, before.gnmap and before.xml exist" '[ -s $D/before.nmap ] && [ -s $D/before.gnmap ] && [ -s $D/before.xml ]' need "before.xml is a SYN scan of 10.99.0.1" 'target $D/before.xml && grep -q "