-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenerator.ps1
More file actions
283 lines (256 loc) · 13.3 KB
/
generator.ps1
File metadata and controls
283 lines (256 loc) · 13.3 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
271
272
273
274
275
276
277
278
279
280
281
282
283
<#
.SYNOPSIS
AdaptixC2 unified template generator.
.DESCRIPTION
Root entry-point that dispatches to the appropriate sub-generator:
1) Agent - scaffold a new agent extender
2) Listener - scaffold a new listener extender
3) Protocol - create a new wire-protocol definition
4) Crypto - create/swap the crypto implementation of an existing protocol
Each option forwards to its dedicated generator under agent/, listener/,
or protocols/. All parameters are passed through so both interactive and
non-interactive modes work.
.PARAMETER Mode
Directly select the generator: "agent", "listener", "protocol", "crypto".
When omitted an interactive menu is shown.
.PARAMETER OutputDir
Directory where generated extenders are written.
Forwarded to agent/listener generators. Default: ADAPTIX_OUTPUT_DIR env var, or ./output.
.PARAMETER Language
Implant language for agent generation: "go" (default), "cpp", or "rust".
Only used with -Mode agent. Forwarded to the agent sub-generator.
.PARAMETER Toolchain
Build toolchain for agent generation (e.g. "go-garble", "mingw", "cargo").
Only used with -Mode agent. When omitted the toolchain is auto-detected from language.
.EXAMPLE
.\generator.ps1
.EXAMPLE
.\generator.ps1 -Mode agent
.EXAMPLE
.\generator.ps1 -Mode agent -OutputDir ..\my-adaptix\extenders
.EXAMPLE
.\generator.ps1 -Mode agent -Language cpp -Toolchain mingw
#>
param(
[ValidateSet("agent","listener","service","wrapper","protocol","crypto","delete","")]
[string]$Mode = "",
[string]$OutputDir = "",
[ValidateSet("go","cpp","rust","")]
[string]$Language = "",
[string]$Toolchain = ""
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# ─── UI helpers ────────────────────────────────────────────────────────────────
function Write-CyberBanner {
Write-Host ""
Write-Host "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓" -ForegroundColor DarkGreen
Write-Host "┃ █████╗ ██████╗ █████╗ ██████╗ ████████╗██╗██╗ ██╗ ██████╗██████╗ ┃" -ForegroundColor DarkGreen
Write-Host "┃ ██╔══██╗██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██║╚██╗██╔╝██╔════╝╚════██╗ ┃" -ForegroundColor DarkGreen
Write-Host "┃ ███████║██║ ██║███████║██████╔╝ ██║ ██║ ╚███╔╝ ██║ █████╔╝ ┃" -ForegroundColor Green
Write-Host "┃ ██╔══██║██║ ██║██╔══██║██╔═══╝ ██║ ██║ ██╔██╗ ██║ ██╔═══╝ ┃" -ForegroundColor Green
Write-Host "┃ ██║ ██║██████╔╝██║ ██║██║ ██║ ██║██╔╝ ██╗╚██████╗███████╗ ┃" -ForegroundColor DarkGreen
Write-Host "┃ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚══════╝ ┃" -ForegroundColor DarkGreen
Write-Host "┃ ┃" -ForegroundColor DarkGreen
Write-Host "┃ Template Generator // agents • listeners • services ┃" -ForegroundColor Green
Write-Host "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛" -ForegroundColor DarkGreen
Write-Host ""
}
function Write-CyberSection([string]$Title) {
Write-Host "[:: $Title ::]" -ForegroundColor Cyan
}
function Write-CyberHint([string]$Message) {
Write-Host " $Message" -ForegroundColor DarkGray
}
function Write-CyberMenu([string]$Prompt, [array]$Items) {
Write-CyberSection $Prompt
Write-Host ""
for ($i = 0; $i -lt $Items.Count; $i++) {
$item = $Items[$i]
$index = "[{0}]" -f ($i + 1)
Write-Host " $index" -ForegroundColor Green -NoNewline
Write-Host " $($item.Label)" -ForegroundColor Cyan -NoNewline
if ($item.ContainsKey('Tag') -and -not [string]::IsNullOrWhiteSpace($item.Tag)) {
Write-Host " <$($item.Tag)>" -ForegroundColor DarkGreen -NoNewline
}
Write-Host ""
Write-CyberHint $item.Desc
}
Write-Host ""
}
function Read-Choice([string]$Prompt, [int]$Min, [int]$Max) {
$raw = Read-Host $Prompt
$value = 0
if (-not [int]::TryParse($raw, [ref]$value) -or $value -lt $Min -or $value -gt $Max) {
Write-Host "[-] Invalid choice." -ForegroundColor Red
exit 1
}
return $value
}
function Write-LaunchMessage([string]$Name) {
Write-Host "[>] Launching $Name..." -ForegroundColor Cyan
Write-Host ""
}
Write-CyberBanner
# ─── Mode selection ─────────────────────────────────────────────────────────────
$modes = @(
@{ Key = "agent"; Label = "Generate Agent"; Desc = "Scaffold a new agent extender"; Tag = "GO/CPP/RUST" },
@{ Key = "listener"; Label = "Generate Listener"; Desc = "Scaffold a new listener extender"; Tag = "TRANSPORT" },
@{ Key = "service"; Label = "Generate Service"; Desc = "Scaffold a new service extender"; Tag = "HOOKS" },
@{ Key = "wrapper"; Label = "Generate Wrapper"; Desc = "Scaffold a service with wrapper pipeline mode enabled"; Tag = "PIPELINE" },
@{ Key = "protocol"; Label = "Create Protocol"; Desc = "Create a new wire-protocol definition"; Tag = "WIRE" },
@{ Key = "crypto"; Label = "Create Crypto"; Desc = "Generate or replace the crypto template for a protocol"; Tag = "CRYPTO" },
@{ Key = "delete"; Label = "Delete"; Desc = "Remove a crypto template, protocol, or generated output"; Tag = "CLEANUP" }
)
if ([string]::IsNullOrEmpty($Mode)) {
Write-CyberMenu "Select generation mode" $modes
$idx = Read-Choice "Select option" 1 $modes.Count
$Mode = $modes[$idx - 1].Key
}
# ─── Dispatch ───────────────────────────────────────────────────────────────────
# Collect remaining arguments to forward
$fwdArgs = @{}
foreach ($key in $PSBoundParameters.Keys) {
if ($key -ne 'Mode') {
$fwdArgs[$key] = $PSBoundParameters[$key]
}
}
# Also forward any unbound positional arguments
$extraArgs = @()
if ($args.Count -gt 0) {
$extraArgs = $args
}
switch ($Mode) {
"agent" {
$target = Join-Path $ScriptDir "agent\generator.ps1"
Write-LaunchMessage "Agent Generator"
& $target @fwdArgs @extraArgs
}
"listener" {
$target = Join-Path $ScriptDir "listener\generator.ps1"
Write-LaunchMessage "Listener Generator"
& $target @fwdArgs @extraArgs
}
"service" {
$target = Join-Path $ScriptDir "service\generator.ps1"
Write-LaunchMessage "Service Generator"
& $target @fwdArgs @extraArgs
}
"wrapper" {
$target = Join-Path $ScriptDir "service\generator.ps1"
Write-LaunchMessage "Service Generator (wrapper mode)"
& $target -Wrapper @fwdArgs @extraArgs
}
"protocol" {
$target = Join-Path $ScriptDir "protocols\generator.ps1"
Write-LaunchMessage "Protocol Generator"
& $target @fwdArgs @extraArgs
}
"crypto" {
$target = Join-Path $ScriptDir "protocols\crypto_generator.ps1"
Write-LaunchMessage "Crypto Generator"
& $target @fwdArgs @extraArgs
}
"delete" {
$deleteModes = @(
@{ Key = "1"; Label = "Crypto template"; Desc = "Remove a crypto .go.tmpl from _crypto/"; Tag = "WIPE" },
@{ Key = "2"; Label = "Protocol"; Desc = "Remove an entire protocol definition"; Tag = "PURGE" },
@{ Key = "3"; Label = "Generated output"; Desc = "Remove a generated project from output/"; Tag = "SCRUB" }
)
Write-CyberMenu "Select deletion target" $deleteModes
$delChoice = [string](Read-Choice "Select option" 1 $deleteModes.Count)
switch ($delChoice) {
"1" {
# ── Delete crypto template ──
$cryptoDir = Join-Path $ScriptDir "protocols\_crypto"
$items = @()
if (Test-Path $cryptoDir) {
$items = @(Get-ChildItem -Path $cryptoDir -Filter "*.go.tmpl" | Sort-Object Name)
}
if ($items.Count -eq 0) {
Write-Host "[-] No crypto templates found." -ForegroundColor Red; exit 1
}
Write-CyberSection "Available crypto templates"
Write-Host ""
for ($i = 0; $i -lt $items.Count; $i++) {
$key = $items[$i].BaseName -replace '\.go$', ''
Write-Host " [$($i+1)] $key" -ForegroundColor Cyan
}
Write-Host ""
$pIdx = Read-Choice "Select crypto to delete" 1 $items.Count
$target = $items[$pIdx - 1]
$targetName = $target.BaseName -replace '\.go$', ''
$confirm = Read-Host "Delete crypto '$targetName'? [y/N]"
if ($confirm -ne 'y') { Write-Host "Cancelled."; exit 0 }
Remove-Item -Path $target.FullName -Force
Write-Host ""
Write-Host "[+] Deleted crypto template: _crypto/$($target.Name)" -ForegroundColor Green
Write-Host ""
}
"2" {
# ── Delete protocol ──
$protoBase = Join-Path $ScriptDir "protocols"
$protected = @('_scaffold', '_crypto')
$items = @()
Get-ChildItem -Path $protoBase -Directory | Where-Object {
$_.Name -notin $protected -and (Test-Path (Join-Path $_.FullName 'meta.yaml'))
} | Sort-Object Name | ForEach-Object { $items += $_ }
if ($items.Count -eq 0) {
Write-Host "[-] No deletable protocols found." -ForegroundColor Red; exit 1
}
Write-CyberSection "Available protocols"
Write-Host ""
for ($i = 0; $i -lt $items.Count; $i++) {
Write-Host " [$($i+1)] $($items[$i].Name)" -ForegroundColor Cyan
}
Write-Host ""
$pIdx = Read-Choice "Select protocol to delete" 1 $items.Count
$target = $items[$pIdx - 1]
$confirm = Read-Host "Delete protocol '$($target.Name)' and all its files? [y/N]"
if ($confirm -ne 'y') { Write-Host "Cancelled."; exit 0 }
Remove-Item -Path $target.FullName -Recurse -Force
Write-Host ""
Write-Host "[+] Deleted protocol: $($target.Name)/" -ForegroundColor Green
Write-Host ""
}
"3" {
# ── Delete generated output ──
$outDir = $OutputDir
if ([string]::IsNullOrEmpty($outDir)) {
$outDir = $env:ADAPTIX_OUTPUT_DIR
}
if ([string]::IsNullOrEmpty($outDir)) {
$outDir = Join-Path $ScriptDir "output"
}
if (-not (Test-Path $outDir)) {
Write-Host "[-] Output directory not found: $outDir" -ForegroundColor Red; exit 1
}
$items = @(Get-ChildItem -Path $outDir -Directory | Sort-Object Name)
if ($items.Count -eq 0) {
Write-Host "[-] No generated projects found in $outDir" -ForegroundColor Red; exit 1
}
Write-CyberSection "Generated projects in ${outDir}"
Write-Host ""
for ($i = 0; $i -lt $items.Count; $i++) {
Write-Host " [$($i+1)] $($items[$i].Name)" -ForegroundColor Cyan
}
Write-Host ""
$pIdx = Read-Choice "Select project to delete" 1 $items.Count
$target = $items[$pIdx - 1]
$confirm = Read-Host "Delete '$($target.Name)' and all its contents? [y/N]"
if ($confirm -ne 'y') { Write-Host "Cancelled."; exit 0 }
Remove-Item -Path $target.FullName -Recurse -Force
Write-Host ""
Write-Host "[+] Deleted: $($target.Name)/" -ForegroundColor Green
Write-Host ""
}
default {
Write-Host "[-] Invalid choice." -ForegroundColor Red; exit 1
}
}
}
default {
Write-Host "[-] Unknown mode: $Mode" -ForegroundColor Red
exit 1
}
}