ineedcodes 1.6.1 → 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 +6 -3
  217. package/src/skills.js +30 -6
  218. package/src/ui.js +1 -1
@@ -0,0 +1,460 @@
1
+ # Solidity Vulnerability Patterns — Code Reference
2
+
3
+ > **Load trigger**: When the agent needs side-by-side vulnerable vs fixed Solidity code patterns, gas-optimization-introduced vulnerabilities, or proxy storage slot collision calculations. Assumes the main [SKILL.md](./SKILL.md) is already loaded for conceptual understanding.
4
+
5
+ ---
6
+
7
+ ## 1. REENTRANCY — VULNERABLE VS FIXED
8
+
9
+ ### 1.1 Classic Reentrancy
10
+
11
+ **Vulnerable:**
12
+ ```solidity
13
+ function withdraw() public {
14
+ uint bal = balances[msg.sender];
15
+ require(bal > 0);
16
+ (bool sent, ) = msg.sender.call{value: bal}("");
17
+ require(sent, "Failed to send");
18
+ balances[msg.sender] = 0; // state update AFTER external call
19
+ }
20
+ ```
21
+
22
+ **Fixed (Checks-Effects-Interactions):**
23
+ ```solidity
24
+ function withdraw() public {
25
+ uint bal = balances[msg.sender];
26
+ require(bal > 0);
27
+ balances[msg.sender] = 0; // state update BEFORE external call
28
+ (bool sent, ) = msg.sender.call{value: bal}("");
29
+ require(sent, "Failed to send");
30
+ }
31
+ ```
32
+
33
+ ### 1.2 Cross-Function Reentrancy
34
+
35
+ **Vulnerable:**
36
+ ```solidity
37
+ function withdraw() public {
38
+ uint bal = balances[msg.sender];
39
+ require(bal > 0);
40
+ (bool sent, ) = msg.sender.call{value: bal}("");
41
+ require(sent);
42
+ balances[msg.sender] = 0;
43
+ }
44
+
45
+ function transfer(address to, uint amount) public {
46
+ require(balances[msg.sender] >= amount);
47
+ balances[msg.sender] -= amount;
48
+ balances[to] += amount;
49
+ }
50
+ // Attacker: during withdraw callback, call transfer() with stale balance
51
+ ```
52
+
53
+ **Fixed:**
54
+ ```solidity
55
+ import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
56
+
57
+ contract Safe is ReentrancyGuard {
58
+ function withdraw() public nonReentrant { ... }
59
+ function transfer(address to, uint amount) public nonReentrant { ... }
60
+ }
61
+ ```
62
+
63
+ ### 1.3 Read-Only Reentrancy
64
+
65
+ **Vulnerable third-party contract:**
66
+ ```solidity
67
+ function getPrice() external view returns (uint) {
68
+ return pool.get_virtual_price(); // reads stale state during pool callback
69
+ }
70
+
71
+ function deposit(uint amount) external {
72
+ uint price = getPrice(); // inflated during reentrancy window
73
+ uint shares = amount * 1e18 / price;
74
+ _mint(msg.sender, shares); // mints too few shares (or too many)
75
+ }
76
+ ```
77
+
78
+ **Attacker contract:**
79
+ ```solidity
80
+ function attack() external {
81
+ pool.remove_liquidity(...); // triggers callback
82
+ }
83
+
84
+ receive() external payable {
85
+ // During callback: pool state is intermediate
86
+ // get_virtual_price() returns inflated value
87
+ vulnerableProtocol.deposit{value: 1 ether}(1 ether);
88
+ }
89
+ ```
90
+
91
+ ---
92
+
93
+ ## 2. INTEGER OVERFLOW / UNDERFLOW
94
+
95
+ ### 2.1 Pre-0.8 Balance Underflow
96
+
97
+ **Vulnerable (Solidity < 0.8):**
98
+ ```solidity
99
+ pragma solidity ^0.7.0;
100
+
101
+ function transfer(address to, uint256 amount) public {
102
+ require(balances[msg.sender] - amount >= 0); // always true for uint!
103
+ balances[msg.sender] -= amount; // underflows to ~2^256
104
+ balances[to] += amount;
105
+ }
106
+ ```
107
+
108
+ **Fixed:**
109
+ ```solidity
110
+ pragma solidity ^0.7.0;
111
+ import "@openzeppelin/contracts/math/SafeMath.sol";
112
+
113
+ function transfer(address to, uint256 amount) public {
114
+ balances[msg.sender] = balances[msg.sender].sub(amount); // reverts on underflow
115
+ balances[to] = balances[to].add(amount);
116
+ }
117
+ ```
118
+
119
+ ### 2.2 Timelock Bypass via Overflow
120
+
121
+ **Vulnerable:**
122
+ ```solidity
123
+ function increaseLockTime(uint _seconds) public {
124
+ lockTime[msg.sender] += _seconds; // overflow wraps to small value
125
+ }
126
+
127
+ function withdraw() public {
128
+ require(block.timestamp > lockTime[msg.sender]);
129
+ // ...
130
+ }
131
+ // Attack: increaseLockTime(type(uint256).max - lockTime + 1) → wraps to 0
132
+ ```
133
+
134
+ ### 2.3 Unsafe Casting (Post-0.8 Risk)
135
+
136
+ ```solidity
137
+ function processAmount(uint256 amount) external {
138
+ uint128 truncated = uint128(amount); // 0.8 does NOT revert on downcast!
139
+ // amount = 2^128 + 1 → truncated = 1
140
+ _transfer(msg.sender, truncated);
141
+ }
142
+ ```
143
+
144
+ **Fixed (Solidity ≥ 0.8.0):**
145
+ ```solidity
146
+ function processAmount(uint256 amount) external {
147
+ require(amount <= type(uint128).max, "overflow");
148
+ uint128 safe = uint128(amount);
149
+ _transfer(msg.sender, safe);
150
+ }
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 3. ACCESS CONTROL
156
+
157
+ ### 3.1 tx.origin Phishing
158
+
159
+ **Vulnerable:**
160
+ ```solidity
161
+ function transferOwnership(address newOwner) public {
162
+ require(tx.origin == owner); // tx.origin = EOA, not immediate caller
163
+ owner = newOwner;
164
+ }
165
+ ```
166
+
167
+ **Attack contract:**
168
+ ```solidity
169
+ contract PhishingAttack {
170
+ VulnerableContract target;
171
+
172
+ function attack() external {
173
+ // If the owner calls this function (tricked via phishing link),
174
+ // tx.origin == owner → passes the check
175
+ target.transferOwnership(address(this));
176
+ }
177
+ }
178
+ ```
179
+
180
+ **Fixed:**
181
+ ```solidity
182
+ function transferOwnership(address newOwner) public {
183
+ require(msg.sender == owner); // msg.sender = immediate caller
184
+ owner = newOwner;
185
+ }
186
+ ```
187
+
188
+ ### 3.2 Unprotected Selfdestruct
189
+
190
+ **Vulnerable:**
191
+ ```solidity
192
+ function destroy() external {
193
+ selfdestruct(payable(msg.sender)); // no access control
194
+ }
195
+ ```
196
+
197
+ ### 3.3 Unprotected Initializer (Proxy Pattern)
198
+
199
+ **Vulnerable:**
200
+ ```solidity
201
+ function initialize(address _owner) public {
202
+ owner = _owner; // can be called by anyone, multiple times
203
+ }
204
+ ```
205
+
206
+ **Fixed:**
207
+ ```solidity
208
+ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
209
+
210
+ function initialize(address _owner) public initializer {
211
+ owner = _owner;
212
+ }
213
+ ```
214
+
215
+ ---
216
+
217
+ ## 4. DELEGATECALL STORAGE COLLISION
218
+
219
+ ### 4.1 Proxy-Implementation Slot Mismatch
220
+
221
+ ```solidity
222
+ // Proxy contract
223
+ contract Proxy {
224
+ address public implementation; // slot 0
225
+ address public owner; // slot 1
226
+
227
+ fallback() external payable {
228
+ (bool s, ) = implementation.delegatecall(msg.data);
229
+ require(s);
230
+ }
231
+ }
232
+
233
+ // Implementation contract
234
+ contract Implementation {
235
+ uint public someValue; // slot 0 — COLLIDES with Proxy.implementation!
236
+ address public admin; // slot 1 — COLLIDES with Proxy.owner!
237
+
238
+ function setSomeValue(uint _val) public {
239
+ someValue = _val; // overwrites Proxy.implementation address!
240
+ }
241
+ }
242
+ ```
243
+
244
+ **Fixed (EIP-1967 storage slots):**
245
+ ```solidity
246
+ contract SafeProxy {
247
+ // Implementation stored at keccak256("eip1967.proxy.implementation") - 1
248
+ bytes32 private constant IMPL_SLOT =
249
+ 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
250
+
251
+ function _implementation() internal view returns (address impl) {
252
+ assembly { impl := sload(IMPL_SLOT) }
253
+ }
254
+ }
255
+ ```
256
+
257
+ ### 4.2 Function Selector Collision in Transparent Proxy
258
+
259
+ ```
260
+ admin() selector: 0xf851a440
261
+ collide_func() selector: 0xf851a440 ← same 4 bytes by coincidence
262
+ ```
263
+
264
+ Tool to check: `cast sig "functionName(argTypes)"` computes selector.
265
+
266
+ ---
267
+
268
+ ## 5. RANDOMNESS MANIPULATION
269
+
270
+ **Vulnerable:**
271
+ ```solidity
272
+ function roll() external payable {
273
+ uint random = uint(keccak256(abi.encodePacked(
274
+ block.timestamp,
275
+ block.difficulty,
276
+ msg.sender
277
+ ))) % 6;
278
+ if (random == 0) {
279
+ payable(msg.sender).transfer(address(this).balance);
280
+ }
281
+ }
282
+ ```
283
+
284
+ **Attack contract:**
285
+ ```solidity
286
+ contract AttackRoll {
287
+ function attack(VulnerableRoll target) external payable {
288
+ uint random = uint(keccak256(abi.encodePacked(
289
+ block.timestamp,
290
+ block.difficulty,
291
+ address(this)
292
+ ))) % 6;
293
+ require(random == 0, "not winning, skip");
294
+ target.roll{value: msg.value}();
295
+ }
296
+ }
297
+ ```
298
+
299
+ ---
300
+
301
+ ## 6. SIGNATURE REPLAY
302
+
303
+ **Vulnerable:**
304
+ ```solidity
305
+ function executeWithSig(address to, uint amount, bytes memory sig) external {
306
+ bytes32 hash = keccak256(abi.encodePacked(to, amount));
307
+ address signer = ECDSA.recover(hash, sig);
308
+ require(signer == owner, "invalid sig");
309
+ // no nonce → same signature can be replayed
310
+ payable(to).transfer(amount);
311
+ }
312
+ ```
313
+
314
+ **Fixed:**
315
+ ```solidity
316
+ mapping(uint256 => bool) public usedNonces;
317
+
318
+ function executeWithSig(
319
+ address to, uint amount, uint256 nonce, bytes memory sig
320
+ ) external {
321
+ require(!usedNonces[nonce], "nonce used");
322
+ bytes32 hash = keccak256(abi.encodePacked(to, amount, nonce, block.chainid, address(this)));
323
+ address signer = ECDSA.recover(hash, sig);
324
+ require(signer == owner, "invalid sig");
325
+ usedNonces[nonce] = true;
326
+ payable(to).transfer(amount);
327
+ }
328
+ ```
329
+
330
+ ---
331
+
332
+ ## 7. SELF-DESTRUCT FORCE-SEND ETH
333
+
334
+ **Vulnerable (balance-dependent logic):**
335
+ ```solidity
336
+ function isGameComplete() public view returns (bool) {
337
+ return address(this).balance == 10 ether; // exact balance check
338
+ }
339
+ ```
340
+
341
+ **Attack:**
342
+ ```solidity
343
+ contract ForceEth {
344
+ function attack(address target) external payable {
345
+ selfdestruct(payable(target));
346
+ // forces ETH into target, bypassing receive/fallback
347
+ // target.balance now != 10 ether → game logic broken
348
+ }
349
+ }
350
+ ```
351
+
352
+ **Fixed:**
353
+ ```solidity
354
+ uint public deposits; // track deposits explicitly, don't rely on balance
355
+
356
+ function isGameComplete() public view returns (bool) {
357
+ return deposits == 10 ether;
358
+ }
359
+ ```
360
+
361
+ ---
362
+
363
+ ## 8. FLASH LOAN ORACLE MANIPULATION
364
+
365
+ **Vulnerable price oracle:**
366
+ ```solidity
367
+ function getPrice(address token) public view returns (uint) {
368
+ (uint reserve0, uint reserve1, ) = pair.getReserves();
369
+ return reserve0 * 1e18 / reserve1; // spot price — manipulable in same tx
370
+ }
371
+ ```
372
+
373
+ **Attack flow:**
374
+ ```
375
+ 1. Flash borrow 10,000 ETH
376
+ 2. Swap ETH → Token on AMM (crashes token spot price)
377
+ 3. Call lending protocol that uses spot price → borrow token at deflated price
378
+ 4. Swap token back → ETH (restore price)
379
+ 5. Repay flash loan + fee
380
+ 6. Profit = borrowed tokens at deflated price - flash loan fee
381
+ ```
382
+
383
+ **Fixed (TWAP oracle):**
384
+ ```solidity
385
+ function getPrice(address token) public view returns (uint) {
386
+ // Use Uniswap V3 TWAP or Chainlink aggregator
387
+ (, int256 price, , uint256 updatedAt, ) = chainlinkFeed.latestRoundData();
388
+ require(block.timestamp - updatedAt < 3600, "stale price");
389
+ return uint256(price);
390
+ }
391
+ ```
392
+
393
+ ---
394
+
395
+ ## 9. UNCHECKED RETURN VALUE
396
+
397
+ **Vulnerable:**
398
+ ```solidity
399
+ function withdraw(uint amount) external {
400
+ payable(msg.sender).send(amount); // send() returns bool, not checked!
401
+ balances[msg.sender] -= amount; // balance decremented even if send failed
402
+ }
403
+ ```
404
+
405
+ **Fixed:**
406
+ ```solidity
407
+ function withdraw(uint amount) external {
408
+ (bool success, ) = payable(msg.sender).call{value: amount}("");
409
+ require(success, "transfer failed");
410
+ balances[msg.sender] -= amount;
411
+ }
412
+ ```
413
+
414
+ ---
415
+
416
+ ## 10. DENIAL OF SERVICE — UNEXPECTED REVERT
417
+
418
+ **Vulnerable (push pattern):**
419
+ ```solidity
420
+ address[] public recipients;
421
+
422
+ function distribute() external {
423
+ for (uint i = 0; i < recipients.length; i++) {
424
+ // If one recipient is a contract that reverts, entire distribution fails
425
+ payable(recipients[i]).transfer(1 ether);
426
+ }
427
+ }
428
+ ```
429
+
430
+ **Fixed (pull pattern):**
431
+ ```solidity
432
+ mapping(address => uint) public pendingWithdrawals;
433
+
434
+ function distribute() external {
435
+ for (uint i = 0; i < recipients.length; i++) {
436
+ pendingWithdrawals[recipients[i]] += 1 ether;
437
+ }
438
+ }
439
+
440
+ function withdraw() external {
441
+ uint amount = pendingWithdrawals[msg.sender];
442
+ pendingWithdrawals[msg.sender] = 0;
443
+ payable(msg.sender).transfer(amount);
444
+ }
445
+ ```
446
+
447
+ ---
448
+
449
+ ## 11. GAS OPTIMIZATION TRAPS
450
+
451
+ Optimizations that accidentally introduce vulnerabilities:
452
+
453
+ | Optimization | Vulnerability Introduced |
454
+ |---|---|
455
+ | `unchecked{}` loop counter | User-controlled bounds → overflow |
456
+ | Assembly `sstore` for gas savings | Bypasses Solidity's overflow checks and visibility |
457
+ | Packed storage (`uint128, uint128` in one slot) | Incorrect bit masking → value corruption |
458
+ | `immutable` used for mutable config | Cannot update → frozen misconfiguration |
459
+ | `selfdestruct` for gas refund | Contract destruction as attack vector (pre-Dencun) |
460
+ | Skipping zero-address checks | Gas saved but ownership can be burned |