-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathquickstart.py
More file actions
271 lines (220 loc) · 9.41 KB
/
quickstart.py
File metadata and controls
271 lines (220 loc) · 9.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/env python3
"""
Ankou C2 Quick Start Script
Generates configuration files with matching keys for server and relay.
No external dependencies - works on Linux and Windows with standard Python 3.
"""
import os
import re
import secrets
import sys
GREEN = '\033[92m'
RESET = '\033[0m'
def generate_random_hex(length):
"""Generate a random hex string of specified length."""
return secrets.token_hex(length)
def generate_random_key(length):
"""Generate a random key of specified byte length."""
return secrets.token_hex(length)
def create_server_config(jwt_secret, hmac_key, registration_key):
"""Create the server/ankou.config file."""
config_path = os.path.join("server", "ankou.config")
config_content = f"""# Ankou Server Configuration
# Auto-generated by quickstart.py
JWT_SECRET={jwt_secret}
HMAC_KEY={hmac_key}
REGISTRATION_KEY={registration_key}
"""
with open(config_path, "w") as f:
f.write(config_content)
print(f"[+] Created {config_path}")
return config_path
def create_server_json_config(operator_host, operator_port, relay_host, relay_port):
"""Create the server/server_config.json file."""
config_path = os.path.join("server", "server_config.json")
config_content = f"""{{
"relay": {{
"host": "{relay_host}",
"port": {relay_port},
"description": "Agent relay communication endpoint (REST API for agent tasking)"
}},
"operator": {{
"host": "{operator_host}",
"port": {operator_port},
"description": "Operator console endpoint (WebSocket/GraphQL for frontend)"
}}
}}
"""
with open(config_path, "w") as f:
f.write(config_content)
print(f"[+] Created {config_path}")
return config_path
def create_relay_config(agent_hmac_key, server_hmac_key, upstream_url, listen_addr):
"""Create the ghost-relay/relay.config file."""
# Ensure ghost-relay directory exists
relay_dir = "ghost-relay"
if not os.path.exists(relay_dir):
os.makedirs(relay_dir, exist_ok=True)
config_path = os.path.join(relay_dir, "relay.config")
try:
config_content = f"""# Ghost Relay Configuration
# Auto-generated by quickstart.py
#
# The relay sits between agents and the C2 server, providing protocol translation
# and an additional layer of authentication.
# Upstream C2 server URL (where to forward agent traffic)
UPSTREAM_URL={upstream_url}
# HMAC key for validating agent requests (must match agents)
AGENT_HMAC_KEY={agent_hmac_key}
# HMAC key for relay -> C2 authentication (must match server HMAC_KEY)
SERVER_HMAC_KEY={server_hmac_key}
# Listen address for relay protocols (where agents connect)
LISTEN_ADDR={listen_addr}
"""
with open(config_path, "w") as f:
f.write(config_content)
print(f"[+] Created {config_path}")
return config_path
except Exception as e:
print(f"[ERROR] Failed to create relay config: {e}")
raise
def parse_agent_hmac_key(config_path):
"""Parse AGENT_HMAC_KEY from relay config file."""
try:
with open(config_path, "r") as f:
content = f.read()
# Match AGENT_HMAC_KEY=value (value is hex, so alphanumeric)
match = re.search(r'AGENT_HMAC_KEY=([a-fA-F0-9]+)', content)
if match:
return match.group(1)
else:
return None
except (IOError, OSError):
return None
def prompt_with_default(prompt_text, default_value):
"""Prompt user for input with a default value."""
user_input = input(f"{prompt_text} [{default_value}]: ").strip()
return user_input if user_input else default_value
def print_banner():
banner = r"""
('-. .-') _ .-. .-')
( OO ).-. ( OO ) )\ ( OO )
/ . --. /,--./ ,--,' ,--. ,--. .-'),-----. ,--. ,--.
| \-. \ | \ | |\ | .' / ( OO' .-. ' | | | |
.-'-' | || \| | )| /, / | | | | | | | .-')
\| |_.' || . |/ | ' _)\_) | |\| | | |_|( OO )
| .-. || |\ | | . \ \ | | | | | | | `-' /
| | | || | \ | | |\ \ `' '-' '(' '-'(_.-'
`--' `--'`--' `--' `--' '--' `-----' `-----'
"""
print(banner)
def main():
print_banner()
print("\n[*] Ankou C2 Framework Configuration\n")
# Check if we're in the right directory
if not os.path.exists("server") or not os.path.exists("ghost-relay"):
print("[ERROR] This script must be run from the ankou-bot root directory!")
print(" Expected structure: ankou-bot/")
print(" ├── server/")
print(" ├── ghost-relay/")
print(" └── quickstart.py")
sys.exit(1)
# Prompt for network configuration
print("Configure network settings (press Enter to use defaults):\n")
c2_operator_interface = prompt_with_default("C2 operator interface", "0.0.0.0")
c2_operator_port = prompt_with_default("C2 operator port", "8443")
c2_relay_bind = prompt_with_default("C2 relay bind", "127.0.0.1")
c2_relay_port = prompt_with_default("C2 relay port", "8444")
relay_implant_interface = prompt_with_default("Relay Implant Interface", "0.0.0.0")
relay_c2_upstream = prompt_with_default("Relay C2 Upstream", "127.0.0.1")
relay_c2_upstream_port = prompt_with_default("Relay C2 Upstream port", c2_relay_port)
# Build full upstream URL
upstream_url = f"https://{relay_c2_upstream}:{relay_c2_upstream_port}"
# Validate ports
try:
c2_operator_port = int(c2_operator_port)
c2_relay_port = int(c2_relay_port)
relay_c2_upstream_port = int(relay_c2_upstream_port)
if not (1 <= c2_operator_port <= 65535 and 1 <= c2_relay_port <= 65535 and 1 <= relay_c2_upstream_port <= 65535):
raise ValueError("Ports must be between 1 and 65535")
except ValueError as e:
print(f"\n[ERROR] Invalid port number: {e}")
sys.exit(1)
# Generate cryptographic keys
print("\n[*] Generating cryptographic keys...")
jwt_secret = generate_random_key(64)
server_hmac_key = generate_random_key(32)
agent_hmac_key = generate_random_key(32)
registration_key = generate_random_hex(16)
print("[+] Generated JWT secret (128 chars)")
print("[+] Generated server HMAC key (64 chars)")
print("[+] Generated agent HMAC key (64 chars)")
print(f"[+] Generated registration key (32 chars)")
print()
# Create server configs
print("[*] Creating server configuration files...")
create_server_config(jwt_secret, server_hmac_key, registration_key)
create_server_json_config(c2_operator_interface, c2_operator_port, c2_relay_bind, c2_relay_port)
print()
# Create relay config
print("[*] Creating relay configuration file...")
relay_config_path = create_relay_config(agent_hmac_key, server_hmac_key, upstream_url, relay_implant_interface)
print()
# Parse AGENT_HMAC_KEY from relay config for display
parsed_agent_hmac_key = parse_agent_hmac_key(relay_config_path)
if parsed_agent_hmac_key is None:
print("[WARNING] Could not parse AGENT_HMAC_KEY from relay config")
parsed_agent_hmac_key = agent_hmac_key # Fallback to the generated key
# Print summary
print("=" * 70)
print("[SUCCESS] Configuration complete!")
print("=" * 70)
print()
print("Configuration Summary:")
print(f" • Registration Key: {GREEN}{registration_key}{RESET}")
print(f" • Agent HMAC Key: {GREEN}{parsed_agent_hmac_key}{RESET}")
print(f" • C2 operator interface: https://{c2_operator_interface}:{c2_operator_port}")
print(f" • C2 relay bind: https://{c2_relay_bind}:{c2_relay_port}")
print(f" • Relay Implant Interface: {relay_implant_interface} (all protocols)")
print(f" • Relay C2 Upstream: {upstream_url}")
print()
print("Next Steps:")
print()
print(" 1. Start the C2 server:")
print(" cd server")
print(" go run .")
print()
print(" 2. Start the ghost relay (in a new terminal):")
print(" cd ghost-relay")
print(" go run .")
print()
print(" 3. Launch the Electron operator client from Github Releases or:")
print(" cd frontend")
print(" npm install; npm run build; npm run electron")
print()
if c2_operator_interface == "0.0.0.0":
print(" • Connect to https://<your-ip>:" + str(c2_operator_port))
else:
print(f" • Connect to https://{c2_operator_interface}:{c2_operator_port}")
print(" • Use the registration key from the Configuration Summary above")
print()
print(" 4. Build and deploy agents:")
print(" cd agents/geist")
print(" ./build.sh # or build.bat on Windows")
print()
print("Tips:")
print(" • The server generates TLS certificates automatically")
print(" • The relay also generates TLS certificates automatically")
print(" • Keep your registration key safe - you'll need it for first login")
print(" • All keys are cryptographically secure random values")
print()
print("=" * 70)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n\n[ERROR] Aborted by user")
sys.exit(1)
except Exception as e:
print(f"\n[ERROR] {e}")
sys.exit(1)