Add timestamped logging, clean up old logs, add .gitignore

This commit is contained in:
creinky committed 2026-11-08 20:34:08 -07:00
1 parent cc6aae0122
commit ed0e58af7c
5 files changed
+62 -7257

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
# Log files (timestamped)
server_*.log
implant_*.log
# Old log files
server.log
implant.log
# Python artifacts
__pycache__/
*.pyc
*.pyo
# Virtual environment
.venv/
venv/
-7114
View File
File diff suppressed because it is too large. Load diff
+28 -15
View File
@@ -18,10 +18,23 @@ import socket
import subprocess
import argparse
import random
import logging
from datetime import datetime
from urllib.request import urlopen, Request
from urllib.error import URLError
# Setup timestamped logging
log_filename = f"implant_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.log"
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s [%(levelname)s] %(message)s',
handlers=[
logging.FileHandler(log_filename),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
def get_local_ip():
"""Get the local IP address of this host."""
@@ -156,14 +169,14 @@ def beacon(mcp_url, implant_id, api_key=None):
commands = body.get("commands", [])
if commands:
print(f"[{implant_id}] Received {len(commands)} command(s)")
logger.info(f"[{implant_id}] Received {len(commands)} command(s)")
for cmd in commands:
request_id = cmd["request_id"]
cmd_type = cmd["type"]
params = cmd["params"]
print(f" Executing {cmd_type} (request {request_id})")
logger.info(f" Executing {cmd_type} (request {request_id})")
# Execute the appropriate command
if cmd_type == "nmap_scan":
@@ -199,17 +212,17 @@ def beacon(mcp_url, implant_id, api_key=None):
try:
with urlopen(report_req, timeout=10) as resp:
print(f" Result reported for {request_id}")
logger.info(f" Result reported for {request_id}")
except Exception as e:
print(f" Failed to report result: {e}")
logger.warning(f" Failed to report result: {e}")
return True
except URLError as e:
print(f"[{implant_id}] Beacon failed: {e}")
logger.error(f"[{implant_id}] Beacon failed: {e}")
return False
except Exception as e:
print(f"[{implant_id}] Unexpected error: {e}")
logger.error(f"[{implant_id}] Unexpected error: {e}")
return False
@@ -224,25 +237,25 @@ def main():
implant_id = args.id
api_key = args.api_key or os.environ.get("IMPLANT_API_KEY", None)
print(f"=== Agentic Pentest Implant ===")
print(f"Implant ID: {implant_id}")
print(f"MCP Server: {mcp_url}")
print(f"Base beacon interval: {args.interval}s (with time-aware jitter)")
logger.info("=== Agentic Pentest Implant ===")
logger.info(f"Implant ID: {implant_id}")
logger.info(f"MCP Server: {mcp_url}")
logger.info(f"Base beacon interval: {args.interval}s (with time-aware jitter)")
if api_key:
print(f"API Key: {'*' * len(api_key)}")
print(f"Local IP: {get_local_ip()}")
print("================================\n")
logger.info(f"API Key: {'*' * len(api_key)}")
logger.info(f"Local IP: {get_local_ip()}")
logger.info("================================")
while True:
success = beacon(mcp_url, implant_id, api_key)
if not success:
print("Retrying in 5 seconds...")
logger.info("Retrying in 5 seconds...")
time.sleep(5)
# Calculate next interval with jitter
next_interval = get_beacon_interval(args.interval)
bh_status = "business hours" if is_business_hours() else "off-hours"
print(f"Next beacon in {next_interval}s ({bh_status})")
logger.debug(f"Next beacon in {next_interval}s ({bh_status})")
# Sleep until next beacon
for _ in range(next_interval):
-124
View File
@@ -1,124 +0,0 @@
╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ │
│ ▄▀▀ ▄▀█ █▀▀ ▀█▀ █▀▄▀█ █▀▀ █▀█ │
│ █▀ █▀█ ▄▄█ █ █ ▀ █ █▄▄ █▀▀ │
│ │
│ │
│ │
│ FastMCP 4.1.6 │
│ https://gofastmcp.com │
│ │
│ 🖥 Server: agentic-pentest-mcp, 4.1.6 │
│ 🚀 Deploy free: https://horizon.prefect.io │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯
[11/04/26 00:52:04] INFO Starting MCP server transport.py:358
'agentic-pentest-mcp' with
transport 'http' on
http://0.0.0.0:8000/mcp
INFO: Started server process [85710]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
Implant check-in server listening on :8001
Starting agentic-pentest MCP server on http://0.0.0.0:8000
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
INFO: 127.0.0.1:45218 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:45218 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:45218 - "POST /mcp HTTP/1.1" 200 OK
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
INFO: 127.0.0.1:44676 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:44676 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:44676 - "POST /mcp HTTP/1.1" 200 OK
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
INFO: 127.0.0.1:56444 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:56444 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:56444 - "POST /mcp HTTP/1.1" 200 OK
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
INFO: 127.0.0.1:49028 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:49028 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:49028 - "POST /mcp HTTP/1.1" 200 OK
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /report_result HTTP/1.1" 200 -
INFO: 127.0.0.1:49028 - "POST /mcp HTTP/1.1" 200 OK
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
INFO: 127.0.0.1:41040 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:41040 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:41040 - "POST /mcp HTTP/1.1" 200 OK
INFO: 127.0.0.1:41040 - "POST /mcp HTTP/1.1" 200 OK
[Implant HTTP] "POST /check_in HTTP/1.1" 200 -
[Implant HTTP] "POST /report_result HTTP/1.1" 200 -
INFO: 127.0.0.1:41040 - "POST /mcp HTTP/1.1" 200 OK
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [85710]
+18 -4
View File
@@ -13,9 +13,23 @@ import json
import time
import uuid
import random
import logging
from datetime import datetime
from collections import defaultdict, deque
from fastmcp import FastMCP
# Setup timestamped logging
log_filename = f"server_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.log"
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s [%(levelname)s] %(message)s',
handlers=[
logging.FileHandler(log_filename),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
# Configuration
IMPLANT_URL = os.environ.get("IMPLANT_URL", "http://localhost:9000")
BEACON_TIMEOUT = 300 # Seconds before an implant is considered offline (5 min)
@@ -337,7 +351,7 @@ class ImplantCheckInHandler(BaseHTTPRequestHandler):
self.end_headers()
def log_message(self, format, *args):
print(f"[Implant HTTP] {format % args}")
logger.info(f"[Implant HTTP] {format % args}")
def start_implant_http_server(port=8001):
@@ -345,7 +359,7 @@ def start_implant_http_server(port=8001):
httpd = HTTPServer(("0.0.0.0", port), ImplantCheckInHandler)
thread = threading.Thread(target=httpd.serve_forever, daemon=True)
thread.start()
print(f"Implant check-in server listening on :{port}")
logger.info(f"Implant check-in server listening on :{port}")
return httpd
@@ -357,8 +371,8 @@ if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "--http":
port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000
print(f"Starting agentic-pentest MCP server on http://0.0.0.0:{port}")
logger.info(f"Starting agentic-pentest MCP server on http://0.0.0.0:{port}")
server.run(transport="http", host="0.0.0.0", port=port)
else:
print("Starting agentic-pentest MCP server (stdio transport)")
logger.info("Starting agentic-pentest MCP server (stdio transport)")
server.run()