scripting improv
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-17 22:02:50 +02:00
parent ede4b3e78d
commit 3ca1d52972
3 changed files with 16 additions and 39 deletions

View File

@@ -1,42 +1,29 @@
#!/usr/bin/env python3
"""Minimal NFQUEUE example script.
"""Minimal NFQUEUE example: accept every packet from a queue."""
Expected argv:
argv[1] = queue number
Any extra args are optional.
"""
import logging
import signal
import sys
from typing import Optional
try:
from netfilterqueue import NetfilterQueue
except Exception as exc: # pragma: no cover
except Exception as exc:
print(f"Failed to import netfilterqueue: {exc}", file=sys.stderr)
sys.exit(2)
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
logger = logging.getLogger("hello-nfqueue")
_running = True
def _stop(_sig: int, _frame: Optional[object]) -> None:
global _running
_running = False
nfq = NetfilterQueue()
def _handle_packet(packet) -> None:
# This demo accepts all packets and logs basic metadata.
logger.info("packet id=%s len=%s", packet.get_id(), len(packet.get_payload()))
packet.accept()
def _stop(_sig, _frame) -> None:
raise SystemExit(0)
def main() -> int:
if len(sys.argv) < 2:
print("Usage: hello_nfqueue.py <qnum> [extra args...]", file=sys.stderr)
if len(sys.argv) != 2:
print("Usage: hello_nfqueue.py <qnum>", file=sys.stderr)
return 1
try:
@@ -48,19 +35,13 @@ def main() -> int:
signal.signal(signal.SIGINT, _stop)
signal.signal(signal.SIGTERM, _stop)
nfq = NetfilterQueue()
logger.info("Binding to NFQUEUE %d", qnum)
nfq.bind(qnum, _handle_packet)
try:
while _running:
nfq.run(block=True)
nfq.run()
except KeyboardInterrupt:
pass
finally:
logger.info("Unbinding NFQUEUE %d", qnum)
nfq.unbind()
return 0

View File

@@ -376,6 +376,7 @@ Type=simple
ExecStart={exec_start}
Restart=always
RestartSec=2
TimeoutStopSec=10
StandardOutput=syslog
StandardError=syslog