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,437 @@
1
+ ---
2
+ name: rsa-attack-techniques
3
+ description: >-
4
+ RSA attack playbook for CTF and real-world cryptanalysis. Use when given
5
+ RSA parameters (n, e, c) and need to recover plaintext by exploiting
6
+ weak keys, small exponents, shared factors, or padding oracles.gated: true
7
+ ---
8
+
9
+ # SKILL: RSA Attack Techniques — Expert Cryptanalysis Playbook
10
+
11
+ > **AI LOAD INSTRUCTION**: Expert RSA attack techniques for CTF and authorized security assessments. Covers factorization attacks, small exponent exploits, lattice-based approaches (Wiener/Boneh-Durfee/Coppersmith), broadcast attacks, common modulus, padding oracles, and fault attacks. Base models often suggest attacks that don't match the given parameters or miss the correct attack selection based on what's known.
12
+
13
+ ## 0. RELATED ROUTING
14
+
15
+ - [lattice-crypto-attacks](../lattice-crypto-attacks/SKILL.md) for deep lattice theory behind Coppersmith/Boneh-Durfee
16
+ - [hash-attack-techniques](../hash-attack-techniques/SKILL.md) when RSA signature forgery involves hash weaknesses
17
+ - [symmetric-cipher-attacks](../symmetric-cipher-attacks/SKILL.md) when RSA protects a symmetric key (hybrid encryption)
18
+
19
+ ### Advanced Reference
20
+
21
+ Also load [RSA_ATTACK_CATALOG.md](./RSA_ATTACK_CATALOG.md) when you need:
22
+ - Detailed SageMath/Python implementation for each attack
23
+ - Step-by-step mathematical derivation
24
+ - Edge cases and failure conditions per attack
25
+
26
+ ### Quick attack selection
27
+
28
+ | Given / Observable | Attack | Tool |
29
+ |---|---|---|
30
+ | Small n (< 512 bits) | Direct factorization | factordb, yafu, msieve |
31
+ | e = 3, small message | Cube root | gmpy2.iroot |
32
+ | Multiple (n, c) same small e | Hastad broadcast | CRT + iroot |
33
+ | Very large e or very small d | Wiener / Boneh-Durfee | SageMath, RsaCtfTool |
34
+ | Partial p knowledge | Coppersmith small roots | SageMath |
35
+ | Same n, different e | Common modulus | Extended GCD |
36
+ | Multiple n values | Batch GCD (shared factor) | Python/SageMath |
37
+ | Padding error oracle | Bleichenbacher | Custom script |
38
+ | LSB parity oracle | LSB oracle attack | Custom script |
39
+ | Fault in CRT computation | RSA-CRT fault | Single faulty signature |
40
+
41
+ ---
42
+
43
+ ## 1. FACTORIZATION ATTACKS
44
+
45
+ ### 1.1 Direct Factorization (Small n)
46
+
47
+ ```python
48
+ from sympy import factorint
49
+
50
+ n = 0x... # small modulus
51
+ factors = factorint(n)
52
+ p, q = list(factors.keys())
53
+ ```
54
+
55
+ **When**: n < ~512 bits, or known to be in factordb.
56
+
57
+ ### 1.2 Fermat's Factorization
58
+
59
+ Works when p and q are close together: |p - q| is small.
60
+
61
+ ```python
62
+ from gmpy2 import isqrt, is_square
63
+
64
+ def fermat_factor(n):
65
+ a = isqrt(n) + 1
66
+ while True:
67
+ b2 = a * a - n
68
+ if is_square(b2):
69
+ b = isqrt(b2)
70
+ return (a + b, a - b)
71
+ a += 1
72
+ ```
73
+
74
+ ### 1.3 Pollard's p-1
75
+
76
+ Works when p-1 has only small prime factors (B-smooth).
77
+
78
+ ```python
79
+ from gmpy2 import gcd
80
+
81
+ def pollard_p1(n, B=2**20):
82
+ a = 2
83
+ for j in range(2, B):
84
+ a = pow(a, j, n)
85
+ d = gcd(a - 1, n)
86
+ if 1 < d < n:
87
+ return d
88
+ return None
89
+ ```
90
+
91
+ ### 1.4 Batch GCD (Multiple n share a factor)
92
+
93
+ ```python
94
+ from math import gcd
95
+ from functools import reduce
96
+
97
+ def batch_gcd(moduli):
98
+ """Find shared factors among multiple RSA moduli."""
99
+ product = reduce(lambda a, b: a * b, moduli)
100
+ results = {}
101
+ for i, n in enumerate(moduli):
102
+ remainder = product // n
103
+ g = gcd(n, remainder)
104
+ if g != 1 and g != n:
105
+ results[i] = (g, n // g)
106
+ return results
107
+ ```
108
+
109
+ ---
110
+
111
+ ## 2. SMALL EXPONENT ATTACKS
112
+
113
+ ### 2.1 Cube Root Attack (e = 3, small m)
114
+
115
+ If m^e < n (no modular reduction occurred), simply take the e-th root.
116
+
117
+ ```python
118
+ from gmpy2 import iroot
119
+
120
+ c = 0x... # ciphertext
121
+ e = 3
122
+ m, exact = iroot(c, e)
123
+ if exact:
124
+ print(f"Plaintext: {bytes.fromhex(hex(m)[2:])}")
125
+ ```
126
+
127
+ ### 2.2 Hastad Broadcast Attack
128
+
129
+ Same message encrypted with same small e under different moduli (n₁, n₂, ..., nₑ).
130
+
131
+ ```python
132
+ from sympy.ntheory.modular import crt
133
+ from gmpy2 import iroot
134
+
135
+ # e = 3, three ciphertexts under three different n
136
+ n_list = [n1, n2, n3]
137
+ c_list = [c1, c2, c3]
138
+
139
+ # CRT: find x such that x ≡ ci (mod ni) for all i
140
+ r, M = crt(n_list, c_list)
141
+ m, exact = iroot(r, 3)
142
+ assert exact
143
+ ```
144
+
145
+ ### 2.3 Related Message Attack (Franklin-Reiter)
146
+
147
+ Two messages related by a known linear function: m₂ = a·m₁ + b. Same n and e.
148
+
149
+ ```python
150
+ # SageMath
151
+ def franklin_reiter(n, e, c1, c2, a, b):
152
+ R.<x> = PolynomialRing(Zmod(n))
153
+ f1 = x^e - c1
154
+ f2 = (a*x + b)^e - c2
155
+ return Integer(n - gcd(f1, f2).coefficients()[0])
156
+ ```
157
+
158
+ ---
159
+
160
+ ## 3. LARGE e / SMALL d ATTACKS
161
+
162
+ ### 3.1 Wiener's Attack (Continued Fractions)
163
+
164
+ When d < n^(1/4) / 3, the continued fraction expansion of e/n reveals d.
165
+
166
+ ```python
167
+ def wiener_attack(e, n):
168
+ """Recover d when d is small via continued fractions."""
169
+ cf = continued_fraction(e, n)
170
+ convergents = get_convergents(cf)
171
+
172
+ for k, d in convergents:
173
+ if k == 0:
174
+ continue
175
+ phi_candidate = (e * d - 1) // k
176
+ # phi(n) = n - p - q + 1 → p + q = n - phi + 1
177
+ s = n - phi_candidate + 1
178
+ # p, q are roots of x^2 - s*x + n = 0
179
+ discriminant = s * s - 4 * n
180
+ if discriminant >= 0:
181
+ from gmpy2 import isqrt, is_square
182
+ if is_square(discriminant):
183
+ return d
184
+ return None
185
+
186
+ def continued_fraction(a, b):
187
+ cf = []
188
+ while b:
189
+ cf.append(a // b)
190
+ a, b = b, a % b
191
+ return cf
192
+
193
+ def get_convergents(cf):
194
+ convergents = []
195
+ h_prev, h_curr = 0, 1
196
+ k_prev, k_curr = 1, 0
197
+ for a in cf:
198
+ h_prev, h_curr = h_curr, a * h_curr + h_prev
199
+ k_prev, k_curr = k_curr, a * k_curr + k_prev
200
+ convergents.append((h_curr, k_curr))
201
+ return convergents
202
+ ```
203
+
204
+ ### 3.2 Boneh-Durfee Attack (Lattice-Based)
205
+
206
+ Extends Wiener: works when d < n^0.292. Uses lattice reduction (LLL/BKZ).
207
+
208
+ **Use SageMath implementation** — see [lattice-crypto-attacks](../lattice-crypto-attacks/SKILL.md) for theory.
209
+
210
+ ---
211
+
212
+ ## 4. COPPERSMITH'S METHOD
213
+
214
+ ### 4.1 Stereotyped Message
215
+
216
+ Known portion of plaintext, unknown part is small.
217
+
218
+ ```python
219
+ # SageMath
220
+ n = ...
221
+ e = 3
222
+ c = ...
223
+ known_prefix = b"flag{" + b"\x00" * 27 # known prefix, unknown suffix
224
+ known_int = int.from_bytes(known_prefix, 'big')
225
+
226
+ R.<x> = PolynomialRing(Zmod(n))
227
+ f = (known_int + x)^e - c
228
+ roots = f.small_roots(X=2^(27*8), beta=1.0)
229
+ if roots:
230
+ m = known_int + int(roots[0])
231
+ print(bytes.fromhex(hex(m)[2:]))
232
+ ```
233
+
234
+ ### 4.2 Partial Key Exposure
235
+
236
+ Known MSB or LSB of p → recover full p via Coppersmith.
237
+
238
+ ```python
239
+ # SageMath — known MSB of p
240
+ p_msb = ... # known upper bits of p
241
+ R.<x> = PolynomialRing(Zmod(n))
242
+ f = p_msb + x
243
+ roots = f.small_roots(X=2^unknown_bits, beta=0.5)
244
+ if roots:
245
+ p = p_msb + int(roots[0])
246
+ q = n // p
247
+ ```
248
+
249
+ ---
250
+
251
+ ## 5. COMMON MODULUS ATTACK
252
+
253
+ Two ciphertexts of same message under same n but different e₁, e₂ where gcd(e₁, e₂) = 1.
254
+
255
+ ```python
256
+ from gmpy2 import gcd, invert
257
+
258
+ def common_modulus(n, e1, e2, c1, c2):
259
+ """Recover m when same message encrypted with two different e under same n."""
260
+ assert gcd(e1, e2) == 1
261
+ _, s1, s2 = extended_gcd(e1, e2) # s1*e1 + s2*e2 = 1
262
+
263
+ if s1 < 0:
264
+ c1 = invert(c1, n)
265
+ s1 = -s1
266
+ if s2 < 0:
267
+ c2 = invert(c2, n)
268
+ s2 = -s2
269
+
270
+ m = (pow(c1, s1, n) * pow(c2, s2, n)) % n
271
+ return m
272
+
273
+ def extended_gcd(a, b):
274
+ if a == 0:
275
+ return b, 0, 1
276
+ g, x, y = extended_gcd(b % a, a)
277
+ return g, y - (b // a) * x, x
278
+ ```
279
+
280
+ ---
281
+
282
+ ## 6. ORACLE ATTACKS
283
+
284
+ ### 6.1 LSB Oracle (Parity Oracle)
285
+
286
+ An oracle reveals whether decrypted message is even or odd.
287
+
288
+ ```python
289
+ from gmpy2 import mpz
290
+
291
+ def lsb_oracle_attack(n, e, c, oracle_func):
292
+ """Decrypt using LSB (parity) oracle. oracle_func(c) returns m%2."""
293
+ from fractions import Fraction
294
+ lo, hi = Fraction(0), Fraction(n)
295
+
296
+ for _ in range(n.bit_length()):
297
+ c = (c * pow(2, e, n)) % n # multiply plaintext by 2
298
+ if oracle_func(c) == 0:
299
+ hi = (lo + hi) / 2
300
+ else:
301
+ lo = (lo + hi) / 2
302
+
303
+ return int(hi)
304
+ ```
305
+
306
+ ### 6.2 Bleichenbacher (PKCS#1 v1.5 Padding Oracle)
307
+
308
+ Given a padding validity oracle (valid/invalid PKCS#1 v1.5), iteratively narrow down the plaintext range.
309
+
310
+ **Complexity**: O(2^16) oracle queries per byte on average.
311
+
312
+ **Target**: TLS implementations returning different errors for valid/invalid padding.
313
+
314
+ ### 6.3 Manger's Attack (PKCS#1 OAEP)
315
+
316
+ Similar to Bleichenbacher but for OAEP padding. Exploits oracle that distinguishes whether the first byte after unpadding is 0x00.
317
+
318
+ ---
319
+
320
+ ## 7. RSA-CRT FAULT ATTACK
321
+
322
+ If RSA-CRT signing produces a faulty signature (fault in one CRT half):
323
+
324
+ ```python
325
+ def rsa_crt_fault(n, e, correct_sig, faulty_sig, msg):
326
+ """Factor n from one correct and one faulty CRT signature."""
327
+ from math import gcd
328
+ diff = pow(correct_sig, e, n) - pow(faulty_sig, e, n)
329
+ p = gcd(diff % n, n)
330
+ if 1 < p < n:
331
+ q = n // p
332
+ return p, q
333
+ return None
334
+
335
+ # Even simpler: only faulty signature needed if message is known
336
+ def rsa_crt_fault_simple(n, e, faulty_sig, msg):
337
+ p = gcd(pow(faulty_sig, e, n) - msg, n)
338
+ if 1 < p < n:
339
+ return p, n // p
340
+ return None
341
+ ```
342
+
343
+ ---
344
+
345
+ ## 8. DECISION TREE
346
+
347
+ ```
348
+ RSA challenge — what information do you have?
349
+
350
+ ├─ Have n and it's small (< 512 bits)?
351
+ │ └─ Factor directly: factordb.com → yafu → msieve
352
+
353
+ ├─ Have multiple n values?
354
+ │ └─ Batch GCD — shared factors?
355
+ │ ├─ Yes → factor all that share factors
356
+ │ └─ No → analyze each n individually
357
+
358
+ ├─ Know e?
359
+ │ ├─ e = 3 (or small)?
360
+ │ │ ├─ Single ciphertext, small message → cube root
361
+ │ │ ├─ Multiple ciphertexts, different n → Hastad broadcast
362
+ │ │ ├─ Two related messages → Franklin-Reiter
363
+ │ │ └─ Partial plaintext known → Coppersmith
364
+ │ │
365
+ │ ├─ e is very large?
366
+ │ │ └─ d is likely small → Wiener → Boneh-Durfee
367
+ │ │
368
+ │ └─ Same n, two different e values?
369
+ │ └─ Common modulus attack (Bezout coefficients)
370
+
371
+ ├─ Know partial factorization info?
372
+ │ ├─ Know some bits of p → Coppersmith partial key
373
+ │ ├─ p-1 is B-smooth → Pollard p-1
374
+ │ └─ p ≈ q (close primes) → Fermat factorization
375
+
376
+ ├─ Have an oracle?
377
+ │ ├─ Parity oracle (LSB) → LSB oracle attack
378
+ │ ├─ Padding validity oracle (PKCS#1 v1.5) → Bleichenbacher
379
+ │ └─ OAEP oracle → Manger's attack
380
+
381
+ ├─ Have faulty signature?
382
+ │ └─ RSA-CRT fault → factor n from faulty sig
383
+
384
+ ├─ Know e·d relationship?
385
+ │ └─ e·d ≡ 1 mod φ(n) → factor n from (e,d,n)
386
+
387
+ └─ None of the above?
388
+ ├─ Check factordb for known factorization
389
+ ├─ Try Pollard rho for medium-size n
390
+ ├─ Look for implementation flaws (weak PRNG for key generation)
391
+ └─ Consider side-channel if physical access available
392
+ ```
393
+
394
+ ---
395
+
396
+ ## 9. TOOLS
397
+
398
+ | Tool | Purpose | Usage |
399
+ |---|---|---|
400
+ | **RsaCtfTool** | Automated RSA attack suite | `python3 RsaCtfTool.py --publickey pub.pem --uncipherfile flag.enc` |
401
+ | **SageMath** | Mathematical computation | Coppersmith, lattice attacks, polynomial arithmetic |
402
+ | **factordb.com** | Online factor database | Check if n is already factored |
403
+ | **yafu** | Fast factorization (SIQS/GNFS) | `yafu "factor(n)"` |
404
+ | **msieve** | GNFS factorization | Large n factorization |
405
+ | **gmpy2** | Fast Python integer library | `iroot`, `invert`, `gcd` |
406
+ | **pycryptodome** | RSA primitives | Key construction from factors |
407
+
408
+ ### RsaCtfTool Quick Commands
409
+
410
+ ```bash
411
+ # From public key
412
+ python3 RsaCtfTool.py --publickey pub.pem -n --private
413
+
414
+ # From parameters
415
+ python3 RsaCtfTool.py -n $N -e $E --uncipher $C
416
+
417
+ # Try all attacks
418
+ python3 RsaCtfTool.py --publickey pub.pem --uncipherfile flag.enc --attack all
419
+ ```
420
+
421
+ ### Decrypt After Factoring
422
+
423
+ ```python
424
+ from Crypto.PublicKey import RSA
425
+ from gmpy2 import invert
426
+
427
+ p, q = ... # factored
428
+ n = p * q
429
+ e = 65537
430
+ phi = (p - 1) * (q - 1)
431
+ d = int(invert(e, phi))
432
+
433
+ c = ... # ciphertext as integer
434
+ m = pow(c, d, n)
435
+ plaintext = m.to_bytes((m.bit_length() + 7) // 8, 'big')
436
+ print(plaintext)
437
+ ```
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: saml-sso-assertion-attacks
3
+ description: >-
4
+ SAML SSO assertion attack playbook. Use when testing signature validation, assertion wrapping, audience restrictions, ACS handling, XML trust boundaries, and enterprise SSO flaws.gated: true
5
+ ---
6
+
7
+ # SKILL: SAML SSO and Assertion Attacks — Signature Validation, Binding, and Trust Confusion
8
+
9
+ > **AI LOAD INSTRUCTION**: Use this skill when the target uses SAML-based SSO and you need to validate assertion trust: signature coverage, audience and recipient checks, ACS handling, XML parsing weaknesses, and IdP/SP confusion.
10
+
11
+ ## 1. WHEN TO LOAD THIS SKILL
12
+
13
+ Load when:
14
+
15
+ - Enterprise SSO uses SAML requests or responses
16
+ - You see `SAMLRequest`, `SAMLResponse`, XML assertions, or ACS endpoints
17
+ - Login flows involve an external IdP and browser POST/redirect binding
18
+
19
+ ## 2. HIGH-VALUE MISCONFIGURATION CHECKS
20
+
21
+ | Theme | What to Check |
22
+ |---|---|
23
+ | signature validation | unsigned assertion accepted, wrong node signed, signature wrapping |
24
+ | audience and recipient | weak `Audience`, `Recipient`, `Destination`, or ACS validation |
25
+ | issuer trust | wrong IdP accepted or multi-tenant issuer confusion |
26
+ | replay and freshness | missing `InResponseTo`, weak `NotBefore` / `NotOnOrAfter` enforcement |
27
+ | account mapping | email-only binding, case folding, unverified attributes |
28
+ | XML parser behavior | XXE-like parser issues or unsafe transforms around SAML documents |
29
+
30
+ ## 3. QUICK TRIAGE
31
+
32
+ 1. Capture one full login round trip.
33
+ 2. Inspect which XML nodes are signed and which attributes drive account binding.
34
+ 3. Compare SP-initiated and IdP-initiated flows.
35
+ 4. Test replay, altered attributes, and assertion placement confusion.
36
+
37
+ ## 4. RELATED ROUTES
38
+
39
+ - XML parser attack depth: [xxe xml external entity](../xxe-xml-external-entity/SKILL.md)
40
+ - OAuth or OIDC SSO alternatives: [oauth oidc misconfiguration](../oauth-oidc-misconfiguration/SKILL.md)
41
+ - Auth boundary issues after SSO: [authbypass authentication flaws](../authbypass-authentication-flaws/SKILL.md)