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,497 @@
1
+ ---
2
+ name: lattice-crypto-attacks
3
+ description: >-
4
+ Lattice-based cryptanalysis playbook. Use when attacking RSA via Coppersmith
5
+ small roots, recovering DSA/ECDSA nonces from bias, solving knapsack
6
+ problems, or applying LLL/BKZ reduction to cryptographic constructions.gated: true
7
+ ---
8
+
9
+ # SKILL: Lattice-Based Cryptanalysis — Expert Attack Playbook
10
+
11
+ > **AI LOAD INSTRUCTION**: Expert lattice techniques for CTF and cryptanalysis. Covers LLL/BKZ reduction, Coppersmith's method (univariate and multivariate), Hidden Number Problem for DSA/ECDSA nonce recovery, knapsack attacks, and NTRU analysis. Base models often fail to construct the correct attack lattice (wrong dimensions, missing scaling factors) or misapply Coppersmith bounds.
12
+
13
+ ## 0. RELATED ROUTING
14
+
15
+ - [rsa-attack-techniques](../rsa-attack-techniques/SKILL.md) for RSA-specific attacks that use lattice methods (Coppersmith, Boneh-Durfee)
16
+ - [symmetric-cipher-attacks](../symmetric-cipher-attacks/SKILL.md) for LCG state recovery via lattice
17
+ - [classical-cipher-analysis](../classical-cipher-analysis/SKILL.md) when lattice methods apply to classical cipher analysis
18
+
19
+ ### Quick application guide
20
+
21
+ | Problem Type | Lattice Technique | Key Parameter |
22
+ |---|---|---|
23
+ | RSA small roots | Coppersmith (LLL on polynomial lattice) | Root bound X < N^(1/e) |
24
+ | RSA small d | Boneh-Durfee (multivariate Coppersmith) | d < N^0.292 |
25
+ | DSA/ECDSA nonce bias | Hidden Number Problem → CVP | Bias bits known |
26
+ | Knapsack cipher | Low-density lattice attack | Density < 0.9408 |
27
+ | LCG truncated output | CVP on recurrence lattice | Unknown bits per output |
28
+ | Subset sum | LLL reduction on knapsack lattice | Element size vs count |
29
+ | NTRU key recovery | Lattice reduction on NTRU lattice | Dimension and key size |
30
+
31
+ ---
32
+
33
+ ## 1. LATTICE FUNDAMENTALS
34
+
35
+ ### 1.1 Definitions
36
+
37
+ A **lattice** L is the set of all integer linear combinations of basis vectors:
38
+
39
+ ```
40
+ L = { a₁·b₁ + a₂·b₂ + ... + aₙ·bₙ | aᵢ ∈ ℤ }
41
+ ```
42
+
43
+ where b₁, ..., bₙ are linearly independent vectors in ℝᵐ.
44
+
45
+ **Key problems**:
46
+ - **SVP** (Shortest Vector Problem): Find the shortest non-zero vector in L
47
+ - **CVP** (Closest Vector Problem): Given target t, find v ∈ L closest to t
48
+ - **SVP is NP-hard** in general, but LLL finds an approximately short vector in polynomial time
49
+
50
+ ### 1.2 Lattice Quality Metrics
51
+
52
+ ```
53
+ Determinant: det(L) = |det(B)| where B is the basis matrix
54
+ Gaussian heuristic: shortest vector ≈ √(n/(2πe)) · det(L)^(1/n)
55
+ ```
56
+
57
+ ---
58
+
59
+ ## 2. LLL ALGORITHM
60
+
61
+ ### 2.1 What LLL Does
62
+
63
+ Takes a lattice basis B and produces a **reduced basis** B' where:
64
+ - Vectors are nearly orthogonal
65
+ - First vector is approximately short (within 2^((n-1)/2) factor of SVP)
66
+ - Runs in polynomial time: O(n^5 · d · log³ B) where d = dimension, B = max entry size
67
+
68
+ ### 2.2 SageMath Usage
69
+
70
+ ```python
71
+ # SageMath
72
+ M = matrix(ZZ, [
73
+ [1, 0, 0, large_value_1],
74
+ [0, 1, 0, large_value_2],
75
+ [0, 0, 1, large_value_3],
76
+ [0, 0, 0, modulus],
77
+ ])
78
+
79
+ L = M.LLL()
80
+ # Short vectors in L reveal the solution
81
+ short_vector = L[0] # first row is typically shortest
82
+ ```
83
+
84
+ ### 2.3 Python (fpylll)
85
+
86
+ ```python
87
+ from fpylll import IntegerMatrix, LLL
88
+
89
+ n = 4
90
+ A = IntegerMatrix(n, n)
91
+ # Fill matrix A...
92
+ A[0] = (1, 0, 0, large_value_1)
93
+ A[1] = (0, 1, 0, large_value_2)
94
+ A[2] = (0, 0, 1, large_value_3)
95
+ A[3] = (0, 0, 0, modulus)
96
+
97
+ LLL.reduction(A)
98
+ print(A[0]) # shortest vector
99
+ ```
100
+
101
+ ---
102
+
103
+ ## 3. BKZ (BLOCK KORKINE-ZOLOTAREV)
104
+
105
+ ### 3.1 Comparison with LLL
106
+
107
+ | Property | LLL | BKZ-β |
108
+ |---|---|---|
109
+ | Quality | 2^((n-1)/2) approximation | 2^(n/(β-1)) approximation |
110
+ | Speed | Polynomial | Exponential in β |
111
+ | Block size | Fixed (2) | Configurable β |
112
+ | Best for | Quick reduction | High-quality reduction |
113
+
114
+ ### 3.2 Usage
115
+
116
+ ```python
117
+ # SageMath
118
+ M = matrix(ZZ, [...])
119
+ L = M.BKZ(block_size=20) # β = 20
120
+
121
+ # fpylll
122
+ from fpylll import BKZ
123
+ BKZ.reduction(A, BKZ.Param(block_size=20))
124
+ ```
125
+
126
+ Rule of thumb: start with LLL, increase to BKZ if needed. BKZ block size 20-40 is usually sufficient for CTF.
127
+
128
+ ---
129
+
130
+ ## 4. COPPERSMITH'S METHOD
131
+
132
+ ### 4.1 Univariate Case
133
+
134
+ Given f(x) ≡ 0 (mod N) with small root |x₀| < X, find x₀.
135
+
136
+ **Bound**: X < N^(1/d) where d = degree of f.
137
+
138
+ ```python
139
+ # SageMath — built-in small_roots
140
+ N = ...
141
+ R.<x> = PolynomialRing(Zmod(N))
142
+ f = x^3 + a*x^2 + b*x + c # known polynomial
143
+ roots = f.small_roots(X=2^100, beta=1.0, epsilon=1/30)
144
+ ```
145
+
146
+ **Parameters**:
147
+ - `X`: upper bound on the root
148
+ - `beta`: N = p^beta (beta=1.0 for modular root of N itself; beta=0.5 for root mod unknown factor p ≈ √N)
149
+ - `epsilon`: smaller = better results but slower (try 1/30 to 1/100)
150
+
151
+ ### 4.2 Stereotyped Message Attack (RSA)
152
+
153
+ ```python
154
+ # SageMath
155
+ n, e, c = ... # RSA parameters
156
+ known_msb = ... # known upper portion of message
157
+
158
+ R.<x> = PolynomialRing(Zmod(n))
159
+ f = (known_msb + x)^e - c
160
+
161
+ # x represents the unknown lower bits
162
+ X = 2^(unknown_bit_count)
163
+ roots = f.small_roots(X=X, beta=1.0)
164
+ if roots:
165
+ m = known_msb + int(roots[0])
166
+ ```
167
+
168
+ ### 4.3 Partial Key Exposure (Factor p)
169
+
170
+ Known MSBs of p: `p = p_known + x` where x is small.
171
+
172
+ ```python
173
+ # SageMath
174
+ n = ...
175
+ p_known = ... # known upper bits of p
176
+
177
+ R.<x> = PolynomialRing(Zmod(n))
178
+ f = p_known + x
179
+ roots = f.small_roots(X=2^unknown_bits, beta=0.5)
180
+ # beta=0.5 because p ≈ √n
181
+ if roots:
182
+ p = p_known + int(roots[0])
183
+ q = n // p
184
+ ```
185
+
186
+ ### 4.4 Multivariate Coppersmith (Howgrave-Graham)
187
+
188
+ For f(x, y) ≡ 0 (mod N):
189
+ - No polynomial-time algorithm guaranteed
190
+ - Heuristic methods work in practice
191
+ - Used in Boneh-Durfee for RSA small d
192
+
193
+ ```python
194
+ # SageMath — Boneh-Durfee
195
+ # e*d ≡ 1 (mod phi) where phi = (p-1)(q-1)
196
+ # Rewrite: e*d = 1 + k*((n+1) - (p+q))
197
+ # Let x = k, y = (p+q), both small relative to n
198
+
199
+ R.<x, y> = PolynomialRing(ZZ)
200
+ A = (n + 1) // 2
201
+ f = 1 + x * (A + y) # mod e
202
+
203
+ # Build shift polynomials and construct lattice
204
+ # Apply LLL to find small (x₀, y₀)
205
+ ```
206
+
207
+ ---
208
+
209
+ ## 5. HIDDEN NUMBER PROBLEM (HNP) — DSA/ECDSA NONCE RECOVERY
210
+
211
+ ### 5.1 Problem Statement
212
+
213
+ Given: signatures (rᵢ, sᵢ) where nonces kᵢ have known bias (leaked MSBs or LSBs).
214
+
215
+ DSA equation: `s = k⁻¹(H(m) + xr) mod q`
216
+
217
+ Rearranged: `k = s⁻¹(H(m) + xr) mod q`
218
+
219
+ If partial bits of k are known: reduces to CVP on a lattice.
220
+
221
+ ### 5.2 Attack Setup
222
+
223
+ ```python
224
+ # SageMath
225
+ def ecdsa_nonce_attack(signatures, q, known_bits, bit_position='msb'):
226
+ """
227
+ signatures: list of (r, s, hash, known_nonce_bits)
228
+ q: curve order
229
+ known_bits: number of known bits per nonce
230
+ """
231
+ n = len(signatures)
232
+
233
+ # Build lattice
234
+ B = 2^(q.nbits() - known_bits) # bound on unknown part
235
+ M = matrix(QQ, n + 2, n + 2)
236
+
237
+ for i in range(n):
238
+ r_i, s_i, h_i, a_i = signatures[i]
239
+ t_i = Integer(inverse_mod(s_i, q) * r_i % q)
240
+ u_i = Integer(inverse_mod(s_i, q) * h_i % q)
241
+
242
+ M[i, i] = q
243
+ M[n, i] = t_i
244
+ M[n+1, i] = u_i - a_i # a_i = known nonce bits
245
+
246
+ M[n, n] = B / q
247
+ M[n+1, n+1] = B
248
+
249
+ # LLL reduction
250
+ L = M.LLL()
251
+
252
+ # Find row containing the private key x
253
+ for row in L:
254
+ x_candidate = Integer(row[n] * q / B) % q
255
+ # Verify x_candidate against one signature
256
+ if verify_private_key(x_candidate, signatures[0], q):
257
+ return x_candidate
258
+
259
+ return None
260
+ ```
261
+
262
+ ### 5.3 Practical Nonce Bias Sources
263
+
264
+ | Source | Leaked Bits | Required Signatures |
265
+ |---|---|---|
266
+ | MSB bias (always 0) | 1 bit | ~100 signatures |
267
+ | k generated with wrong length | Variable | ~50 signatures |
268
+ | Timing side channel | 1-4 bits | 20-100 signatures |
269
+ | Insecure PRNG | Many | Few |
270
+ | Reused nonce (k₁ = k₂) | All | 2 signatures |
271
+
272
+ For **reused nonce** (simplest case):
273
+
274
+ ```python
275
+ def ecdsa_reused_nonce(r, s1, s2, h1, h2, q):
276
+ """Recover private key when nonce k is reused."""
277
+ # s1 - s2 = k⁻¹(h1 - h2) mod q (since r is same)
278
+ k = ((h1 - h2) * inverse_mod(s1 - s2, q)) % q
279
+ x = ((s1 * k - h1) * inverse_mod(r, q)) % q
280
+ return x, k
281
+ ```
282
+
283
+ ---
284
+
285
+ ## 6. KNAPSACK / SUBSET SUM ATTACKS
286
+
287
+ ### 6.1 Low-Density Attack
288
+
289
+ Knapsack: given weights a₁,...,aₙ and target S, find x₁,...,xₙ ∈ {0,1} such that Σxᵢaᵢ = S.
290
+
291
+ **Density** d = n / max(log₂ aᵢ). If d < 0.9408, lattice attack works.
292
+
293
+ ```python
294
+ # SageMath
295
+ def knapsack_lattice(weights, target):
296
+ """Solve subset sum via LLL lattice attack."""
297
+ n = len(weights)
298
+
299
+ # Build lattice (Lagarias-Odlyzko style)
300
+ N = ceil(sqrt(n) / 2) # scaling factor
301
+ M = matrix(ZZ, n + 1, n + 1)
302
+
303
+ for i in range(n):
304
+ M[i, i] = 1
305
+ M[i, n] = N * weights[i]
306
+ M[n, n] = N * target
307
+
308
+ # Alternative: CJLOSS embedding
309
+ M2 = matrix(ZZ, n + 1, n + 2)
310
+ for i in range(n):
311
+ M2[i, i] = 1
312
+ M2[i, n + 1] = N * weights[i]
313
+ M2[n, n] = 1
314
+ M2[n, n + 1] = N * (-target)
315
+
316
+ L = M2.LLL()
317
+
318
+ # Look for short vector with entries in {0, 1, -1}
319
+ for row in L:
320
+ if all(v in (0, 1) for v in row[:n]):
321
+ solution = list(row[:n])
322
+ if sum(solution[i] * weights[i] for i in range(n)) == target:
323
+ return solution
324
+
325
+ return None
326
+ ```
327
+
328
+ ---
329
+
330
+ ## 7. NTRU CRYPTANALYSIS
331
+
332
+ ### 7.1 NTRU Lattice
333
+
334
+ ```python
335
+ # SageMath
336
+ def ntru_lattice_attack(h, q, N):
337
+ """
338
+ Construct NTRU lattice for key recovery.
339
+ h = public key polynomial (mod q)
340
+ q = modulus
341
+ N = dimension
342
+ """
343
+ # NTRU lattice:
344
+ # | qI 0 |
345
+ # | H I |
346
+ # where H is the circulant matrix of h
347
+
348
+ H = matrix(ZZ, N, N)
349
+ for i in range(N):
350
+ for j in range(N):
351
+ H[i, j] = h[(j - i) % N]
352
+
353
+ M = block_matrix([
354
+ [q * identity_matrix(N), zero_matrix(N)],
355
+ [H, identity_matrix(N)]
356
+ ])
357
+
358
+ L = M.LLL()
359
+
360
+ # Short vector in reduced basis = (f, g) private key
361
+ for row in L:
362
+ f = vector(row[:N])
363
+ g = vector(row[N:])
364
+ if f.norm() < q and g.norm() < q:
365
+ return f, g
366
+
367
+ return None
368
+ ```
369
+
370
+ ---
371
+
372
+ ## 8. CONSTRUCTING ATTACK LATTICES — METHODOLOGY
373
+
374
+ ### 8.1 General Recipe
375
+
376
+ ```
377
+ 1. Express the cryptographic problem as:
378
+ "Find small x such that f(x) ≡ 0 (mod N)"
379
+ or "Find x close to target t in some lattice L"
380
+
381
+ 2. Choose lattice type:
382
+ ├─ Polynomial lattice → Coppersmith-style
383
+ ├─ Modular lattice → HNP-style CVP
384
+ └─ Knapsack lattice → subset sum / CJLOSS
385
+
386
+ 3. Determine dimensions:
387
+ └─ More dimensions = better approximation but slower
388
+
389
+ 4. Set scaling factors:
390
+ └─ Balance the rows so short vector has roughly equal entries
391
+ └─ Common: multiply by N/X where X is the root bound
392
+
393
+ 5. Apply reduction:
394
+ ├─ LLL first (fast, usually sufficient)
395
+ └─ BKZ if LLL fails (increase block size: 20, 30, 40)
396
+
397
+ 6. Extract solution:
398
+ └─ Check reduced basis rows for valid solutions
399
+ ```
400
+
401
+ ### 8.2 Embedding Technique (CVP → SVP)
402
+
403
+ Transform CVP into SVP by embedding the target into the lattice:
404
+
405
+ ```python
406
+ # SageMath
407
+ def cvp_to_svp(basis_matrix, target, scale=1):
408
+ """Convert CVP to SVP via Kannan's embedding."""
409
+ n = basis_matrix.nrows()
410
+ m = basis_matrix.ncols()
411
+
412
+ # Augment matrix
413
+ M = matrix(ZZ, n + 1, m + 1)
414
+ for i in range(n):
415
+ for j in range(m):
416
+ M[i, j] = basis_matrix[i, j]
417
+ M[i, m] = 0
418
+
419
+ for j in range(m):
420
+ M[n, j] = target[j]
421
+ M[n, m] = scale # scaling factor (try 1, then adjust)
422
+
423
+ L = M.LLL()
424
+
425
+ # Look for row with last entry = ±scale
426
+ for row in L:
427
+ if abs(row[m]) == scale:
428
+ return vector(target) - vector(row[:m]) * (row[m] // abs(row[m]))
429
+
430
+ return None
431
+ ```
432
+
433
+ ### 8.3 Dimension Selection Guide
434
+
435
+ | Problem | Typical Dimension | Notes |
436
+ |---|---|---|
437
+ | Coppersmith univariate (degree d) | d × m where m ≈ 1/ε | Larger m = smaller root bound |
438
+ | HNP with n signatures | n + 2 | n ≥ known_bits_ratio × q_bits |
439
+ | Knapsack with n weights | n + 1 or n + 2 | Depends on density |
440
+ | LCG with n outputs | n + 1 | More outputs = easier |
441
+ | Boneh-Durfee | (m+1)(m+2)/2 | m = parameter depth |
442
+
443
+ ---
444
+
445
+ ## 9. DECISION TREE
446
+
447
+ ```
448
+ Lattice approach needed — which construction?
449
+
450
+ ├─ RSA-related?
451
+ │ ├─ Small unknown part of message → Coppersmith univariate
452
+ │ │ └─ Check: unknown_bits < n_bits / e
453
+ │ ├─ Partial factor knowledge → Coppersmith mod p
454
+ │ │ └─ Use beta=0.5, X=2^unknown_bits
455
+ │ ├─ Small private exponent d → Boneh-Durfee
456
+ │ │ └─ Check: d < N^0.292
457
+ │ └─ Multiple related equations → multivariate Coppersmith
458
+
459
+ ├─ DSA/ECDSA-related?
460
+ │ ├─ Reused nonce → direct algebraic recovery (no lattice needed)
461
+ │ ├─ Partial nonce leakage → HNP → CVP lattice
462
+ │ │ └─ Need enough signatures: n ≥ q_bits / leaked_bits
463
+ │ └─ Nonce bias → statistical HNP → larger lattice
464
+
465
+ ├─ Knapsack / subset sum?
466
+ │ ├─ Low density (d < 0.9408) → CJLOSS lattice attack
467
+ │ ├─ High density → lattice attack unlikely to work
468
+ │ └─ Super-increasing → greedy algorithm (no lattice needed)
469
+
470
+ ├─ LCG / PRNG?
471
+ │ ├─ Full outputs known → algebraic recovery (no lattice)
472
+ │ ├─ Truncated outputs → CVP on recurrence lattice
473
+ │ └─ Unknown modulus → use GCD of output differences
474
+
475
+ ├─ NTRU?
476
+ │ └─ Build circulant lattice → LLL/BKZ for short key vector
477
+
478
+ └─ Custom problem?
479
+ ├─ Express as "find small root of polynomial mod N" → Coppersmith
480
+ ├─ Express as "find lattice point close to target" → CVP
481
+ ├─ Express as "find short vector in lattice" → SVP / LLL
482
+ └─ If none fit → probably not a lattice problem
483
+ ```
484
+
485
+ ---
486
+
487
+ ## 10. COMMON PITFALLS
488
+
489
+ | Pitfall | Symptom | Fix |
490
+ |---|---|---|
491
+ | Root bound too large | `small_roots()` returns empty | Reduce X, increase epsilon, verify bound satisfies Coppersmith criterion |
492
+ | Wrong scaling | LLL finds irrelevant short vector | Scale columns so target vector has balanced entries |
493
+ | Insufficient dimension | Solution not in reduced basis | Increase m parameter (more shift polynomials) |
494
+ | Wrong beta | Coppersmith doesn't find factor | beta=0.5 for half-size factor, beta=1.0 for full modulus |
495
+ | Too few signatures (HNP) | Lattice attack fails | Collect more signatures with nonce bias |
496
+ | BKZ block size too small | Solution not short enough | Increase block size (try 25, 30, 40) |
497
+ | Integer overflow | SageMath crashes | Use ZZ ring explicitly, avoid mixing QQ and ZZ |