add new example scripts
All checks were successful
Build and Deploy MITM Webserver / traffic_target (push) Successful in 0s
Build and Deploy MITM Webserver / build (push) Successful in 12s

This commit is contained in:
2026-04-18 11:45:15 +02:00
parent 9c982e361c
commit b5c6409f85
4 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env python3
"""Minimal NFQUEUE example: add random delay and jitter, but do not drop packets."""
import random
import signal
import sys
import time
from netfilterqueue import NetfilterQueue
# Demo tuning values.
BASE_DELAY_MS = 40
JITTER_MS = 120
nfq = NetfilterQueue()
def _handle_packet(packet) -> None:
delay_ms = BASE_DELAY_MS + random.uniform(0, JITTER_MS)
time.sleep(delay_ms / 1000.0)
packet.accept()
def _stop(_sig, _frame) -> None:
raise SystemExit(0)
def main() -> int:
if len(sys.argv) != 2:
print("Usage: chaos_delay_jitter.py <qnum>", file=sys.stderr)
return 1
try:
qnum = int(sys.argv[1])
except ValueError:
print("qnum must be an integer", file=sys.stderr)
return 1
signal.signal(signal.SIGINT, _stop)
signal.signal(signal.SIGTERM, _stop)
nfq.bind(qnum, _handle_packet)
try:
nfq.run()
except KeyboardInterrupt:
pass
finally:
nfq.unbind()
return 0
if __name__ == "__main__":
raise SystemExit(main())