diff options
| author | daniel <daniel@planethacker.net> | 2025-05-06 16:57:32 -0700 |
|---|---|---|
| committer | daniel <daniel@planethacker.net> | 2025-05-06 16:57:32 -0700 |
| commit | 2278df1493e064c197913e49b5d1935942d83448 (patch) | |
| tree | 42f06ab2f76e2ddf228bafbb03f79621975a4534 /misc/server_example.py | |
initial import
Diffstat (limited to 'misc/server_example.py')
| -rw-r--r-- | misc/server_example.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/misc/server_example.py b/misc/server_example.py new file mode 100644 index 0000000..4b53315 --- /dev/null +++ b/misc/server_example.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +# +# basic example showing how to use noawareness data +# +# - set up webhook as you see fit +# - configure your logging search engine to ingest noawareness.log +# - point noawareness agents at this host to collect logs centrally +# + +import socket +import json +import logging +import requests + +# Configuration +UDP_PORT = 55555 +LOG_FILE = "noawareness.log" +DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/your/webhook/url" +TRIGGER_MD5 = "foo" + +# Setup logging to just log raw messages +logging.basicConfig(filename=LOG_FILE, level=logging.INFO, format="%(message)s") + +# Create UDP socket +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +sock.bind(("0.0.0.0", UDP_PORT)) +print(f"Listening on UDP port {UDP_PORT}...") + +def send_discord_alert(message): + payload = {"content": message} + try: + requests.post(DISCORD_WEBHOOK_URL, json=payload) + except requests.RequestException: + pass + +while True: + try: + data, _ = sock.recvfrom(65535) + message = data.decode("utf-8", errors="ignore").strip() + logging.info(message) + + try: + parsed = json.loads(message) + if parsed.get("md5") == TRIGGER_MD5: + send_discord_alert(f"Trigger match: md5 == {TRIGGER_MD5}") + except json.JSONDecodeError: + pass + + except KeyboardInterrupt: + break |
