Add per-service customization, stealth hardening, and BYOS support
- HTTP: configurable server_header, response_code, fake_app presets (apache/nginx/wordpress/phpmyadmin/iis), extra_headers, custom_body, static files directory mount - SSH/Cowrie: configurable kernel_version, hardware_platform, ssh_banner, and users/passwords via COWRIE_USERDB_ENTRIES; switched to build mode so cowrie.cfg.j2 persona fields and userdb.txt generation work - SMTP: configurable banner and MTA hostname - MySQL: configurable version string in protocol greeting - Redis: configurable redis_version and os string in INFO response - BYOS: [custom-*] INI sections define bring-your-own Docker services - Stealth: rename all *_honeypot.py → server.py; replace HONEYPOT_NAME env var with NODE_NAME across all 22+ service templates and plugins; strip "honeypot" from all in-container file content - Config: DeckyConfig.service_config dict; INI [decky-N.svc] subsections; composer passes service_cfg to compose_fragment - 350 tests passing (100%) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
142
templates/k8s/server.py
Normal file
142
templates/k8s/server.py
Normal file
@@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Kubernetes APIserver.
|
||||
Serves a fake K8s REST API on port 6443 (HTTPS-ish, plain HTTP) and 8080.
|
||||
Responds to recon endpoints (/version, /api, /apis, /api/v1/namespaces,
|
||||
/api/v1/pods) with plausible but fake data. Logs all requests as JSON.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from flask import Flask, request
|
||||
|
||||
NODE_NAME = os.environ.get("NODE_NAME", "k8s-master")
|
||||
LOG_TARGET = os.environ.get("LOG_TARGET", "")
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
_VERSION = {
|
||||
"major": "1",
|
||||
"minor": "27",
|
||||
"gitVersion": "v1.27.4",
|
||||
"gitCommit": "fa3d7990104d7c1f16943a67f11b154b71f6a132",
|
||||
"gitTreeState": "clean",
|
||||
"buildDate": "2023-07-19T12:14:46Z",
|
||||
"goVersion": "go1.20.6",
|
||||
"compiler": "gc",
|
||||
"platform": "linux/amd64",
|
||||
}
|
||||
|
||||
_API_VERSIONS = {
|
||||
"kind": "APIVersions",
|
||||
"versions": ["v1"],
|
||||
"serverAddressByClientCIDRs": [{"clientCIDR": "0.0.0.0/0", "serverAddress": f"{NODE_NAME}:6443"}],
|
||||
}
|
||||
|
||||
_NAMESPACES = {
|
||||
"kind": "NamespaceList",
|
||||
"apiVersion": "v1",
|
||||
"items": [
|
||||
{"metadata": {"name": "default"}},
|
||||
{"metadata": {"name": "kube-system"}},
|
||||
{"metadata": {"name": "production"}},
|
||||
],
|
||||
}
|
||||
|
||||
_PODS = {
|
||||
"kind": "PodList",
|
||||
"apiVersion": "v1",
|
||||
"items": [
|
||||
{"metadata": {"name": "webapp-6d5f8b9-xk2p7", "namespace": "production"},
|
||||
"status": {"phase": "Running"}},
|
||||
],
|
||||
}
|
||||
|
||||
_SECRETS = {
|
||||
"kind": "Status",
|
||||
"apiVersion": "v1",
|
||||
"status": "Failure",
|
||||
"message": "secrets is forbidden: User \"system:anonymous\" cannot list resource \"secrets\"",
|
||||
"reason": "Forbidden",
|
||||
"code": 403,
|
||||
}
|
||||
|
||||
|
||||
def _forward(event: dict) -> None:
|
||||
if not LOG_TARGET:
|
||||
return
|
||||
try:
|
||||
host, port = LOG_TARGET.rsplit(":", 1)
|
||||
with socket.create_connection((host, int(port)), timeout=3) as s:
|
||||
s.sendall((json.dumps(event) + "\n").encode())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _log(event_type: str, **kwargs) -> None:
|
||||
event = {
|
||||
"ts": datetime.now(timezone.utc).isoformat(),
|
||||
"service": "k8s",
|
||||
"host": NODE_NAME,
|
||||
"event": event_type,
|
||||
**kwargs,
|
||||
}
|
||||
print(json.dumps(event), flush=True)
|
||||
_forward(event)
|
||||
|
||||
|
||||
@app.before_request
|
||||
def log_request():
|
||||
_log(
|
||||
"request",
|
||||
method=request.method,
|
||||
path=request.path,
|
||||
remote_addr=request.remote_addr,
|
||||
auth=request.headers.get("Authorization", ""),
|
||||
body=request.get_data(as_text=True)[:512],
|
||||
)
|
||||
|
||||
|
||||
@app.route("/version")
|
||||
def version():
|
||||
return app.response_class(json.dumps(_VERSION), mimetype="application/json")
|
||||
|
||||
|
||||
@app.route("/api")
|
||||
def api():
|
||||
return app.response_class(json.dumps(_API_VERSIONS), mimetype="application/json")
|
||||
|
||||
|
||||
@app.route("/api/v1/namespaces")
|
||||
def namespaces():
|
||||
return app.response_class(json.dumps(_NAMESPACES), mimetype="application/json")
|
||||
|
||||
|
||||
@app.route("/api/v1/pods")
|
||||
@app.route("/api/v1/namespaces/<ns>/pods")
|
||||
def pods(ns="default"):
|
||||
return app.response_class(json.dumps(_PODS), mimetype="application/json")
|
||||
|
||||
|
||||
@app.route("/api/v1/secrets")
|
||||
@app.route("/api/v1/namespaces/<ns>/secrets")
|
||||
def secrets(ns="default"):
|
||||
return app.response_class(json.dumps(_SECRETS), status=403, mimetype="application/json")
|
||||
|
||||
|
||||
@app.route("/", defaults={"path": ""})
|
||||
@app.route("/<path:path>", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
||||
def catch_all(path):
|
||||
return app.response_class(
|
||||
json.dumps({"kind": "Status", "status": "Failure", "code": 404}),
|
||||
status=404,
|
||||
mimetype="application/json",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
_log("startup", msg=f"Kubernetes API server starting as {NODE_NAME}")
|
||||
app.run(host="0.0.0.0", port=6443, debug=False)
|
||||
Reference in New Issue
Block a user