
Agente Adaptix C2 che utilizza il linker PIC Crystal Palace e il sistema di moduli PICO
Un agente C2 per Adaptix realizzato con Crystal Palace — un linker PIC (Position Independent Code) personalizzato e il sistema di moduli PICO. Dimostra come costruire agenti shellcode modulari in cui ogni componente (transport, tasks, obfuscation) è un blob PICO separato caricato a runtime.
Questo agente non include tecniche di evasione e non è pensato per essere utilizzato così com'è in operazioni reali. È un'implementazione di riferimento per costruire agenti con Crystal Palace e il sistema di moduli PICO.
Crystal Palace è un linker PIC che riceve oggetti COFF compilati e produce eseguibili position-independent. Concetti chiave:
make pic +gofirst) — Lo shellcode eseguibile principale. Contiene il codice di bootstrap, il resolver DFR e i marker di sezione in cui vengono collegati i moduli PICO. Viene chiamato direttamente dal loader.make object) — Blob di codice autonomi con sezioni di codice e dati proprie. Caricati a runtime tramite PicoLoad() da libtcg. Ogni PICO ha un punto di ingresso (go()) richiamabile tramite puntatore a funzione.MODULE$Function (es. KERNEL32$VirtualAlloc) con chiamate a resolve(mod_hash, func_hash) usando l'hashing ROR13. Nessuna tabella di importazione. Tutti gli argomenti stringa (nomi di DLL, nomi di funzioni) vengono costruiti sullo stack come array di char per evitare testo in chiaro nel binario.entry_module, transport_module, ecc.) tramite la direttiva link nel file .spec.{LoadLibraryA, GetProcAddress} passata a PicoLoad() per consentire ai moduli PICO di risolvere i propri simboli DFR.C source → mingw-gcc → COFF objects → Crystal Palace link → raw PIC shellcode → loader (Exe/Dll/Svc)
Il file .spec definisce come Crystal Palace collega tutto:
x64:
load "Bin/obj/main.x64.o" # Core PIC
make pic +gofirst
foreach %LIBS: mergelib %_ # Merge libtcg
load "Bin/obj/entry.x64.o" # Entry PICO
make object
load "Bin/obj/crypto.x64.o" # merge crypto into entry
merge
load "Bin/obj/packer.x64.o" # merge packer into entry
merge
export
link "entry_module" # link at section marker
load "Bin/obj/transport.x64.o" # Transport PICO
make object
mergelib "lib/LibWinHttp/..."
export
link "transport_module"
... # task_module, obfuscation_module
dfr "resolve" "ror13" # resolve all DFR symbols
export
Core PIC (main.c)
│
├── resolve() DFR bridge → libtcg hash lookup
├── AllocateAndLoadModule() PicoLoad each PICO into shared RWX region
│
└── calls entry module go() with pointers to all other modules
│
├── Entry Module (entry.c)
│ MvState, checkin, transact (RC4 wire format), task loop
│
├── Transport Module (transport.c)
│ HTTP/HTTPS POST via LibWinHttp
│
├── Task Module (tasks.c)
│ Command dispatch: whoami (0x30), sleep (0x20), exit (0x10)
│
└── Obfuscation Module (obfuscation.c)
Ekko sleep — timer-queue ROP chain that encrypts module memory
with RC4 (SystemFunction033) during sleep, decrypts on wake
┌─────────────────────────────┐
│ Shared RWX Region │ VirtualAlloc(PAGE_EXECUTE_READWRITE)
│ ├── Entry code │ PicoLoad → code here
│ ├── Transport code │
│ ├── Task code │
│ └── Obfuscation code │
├─────────────────────────────┤
│ Entry data (RW) │ PicoLoad → data here (separate alloc)
│ Transport data (RW) │
│ Task data (RW) │
│ Obfuscation data (RW) │
├─────────────────────────────┤
│ Core PIC (freed after boot) │ Original shellcode, freed by entry module
└─────────────────────────────┘
La regione RWX condivisa è ciò che Ekko cifra/decifra durante i cicli di sleep.
Tutto il traffico è cifrato con RC4 (cifrario a flusso, chiave da 16 byte).
Send: [36B agent_id][RC4(payload)][16B key (first checkin only)]
Receive: [36B agent_id][RC4(response)]
src_beacon/Source/
├── main.c Core PIC — DFR resolver, module loading, bootstrap
├── entry.c Entry PICO — agent state, checkin, task loop, transact
├── transport.c Transport PICO — HTTP POST via LibWinHttp
├── tasks.c Task PICO — whoami/sleep/exit dispatch
├── obfuscation.c Obfuscation PICO — Ekko sleep (timer-queue ROP + RC4)
├── crypto.c RC4 stream cipher (merged into entry PICO)
├── packer.c Binary packer BE / parser LE (merged into entry PICO)
└── includes/
├── config.h Build-time defines (UUID, sleep, callback host/port/uri/ssl)
├── crypto.h RC4 API
├── packer.h PackBuf / Parser API
├── tcg.h Crystal Palace libtcg (PicoLoad, findModuleByHash, etc.)
└── HTTP.h LibWinHttp API
| Comando | ID | Descrizione |
|---|
x86_64-w64-mingw32-gcc (compilatore incrociato MinGW)./setup.sh --ax ../AdaptixC2
whoami, sleep, exit dalla console di Adaptix
whoami | 0x30 | Restituisce COMPUTER\username |
sleep <seconds> | 0x20 | Aggiorna l'intervallo di callback |
exit thread|process | 0x10 | Termina l'agente |