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.
- package/package.json +2 -1
- package/skills/401-403-bypass-techniques/SKILL.md +348 -0
- package/skills/active-directory-acl-abuse/BLOODHOUND_PATHS.md +281 -0
- package/skills/active-directory-acl-abuse/SKILL.md +295 -0
- package/skills/active-directory-certificate-services/ADCS_ESC_MATRIX.md +197 -0
- package/skills/active-directory-certificate-services/SKILL.md +303 -0
- package/skills/active-directory-kerberos-attacks/KERBEROS_ATTACK_CHAINS.md +226 -0
- package/skills/active-directory-kerberos-attacks/SKILL.md +311 -0
- package/skills/ai-ml-security/SKILL.md +425 -0
- package/skills/android-pentesting-tricks/FRIDA_SCRIPTS.md +394 -0
- package/skills/android-pentesting-tricks/SKILL.md +369 -0
- package/skills/anti-debugging-techniques/ANTI_DEBUG_MATRIX.md +117 -0
- package/skills/anti-debugging-techniques/SKILL.md +407 -0
- package/skills/api-auth-and-jwt-abuse/SKILL.md +76 -0
- package/skills/api-authorization-and-bola/SKILL.md +48 -0
- package/skills/api-recon-and-docs/SKILL.md +61 -0
- package/skills/api-sec/SKILL.md +49 -0
- package/skills/arbitrary-write-to-rce/SKILL.md +361 -0
- package/skills/auth-sec/SKILL.md +41 -0
- package/skills/authbypass-authentication-flaws/SKILL.md +441 -0
- package/skills/bba-ad-attacker/SKILL.md +420 -0
- package/skills/bba-api-security/SKILL.md +95 -0
- package/skills/bba-attack-planner/SKILL.md +186 -0
- package/skills/bba-binary-exploit/SKILL.md +65 -0
- package/skills/bba-bizlogic-hunter/SKILL.md +304 -0
- package/skills/bba-bug-bounty/SKILL.md +245 -0
- package/skills/bba-cicd-redteam/SKILL.md +515 -0
- package/skills/bba-cloud-security/SKILL.md +97 -0
- package/skills/bba-container-escape/SKILL.md +161 -0
- package/skills/bba-credential-tester/SKILL.md +346 -0
- package/skills/bba-crypto-analyst/SKILL.md +54 -0
- package/skills/bba-ctf-solver/SKILL.md +166 -0
- package/skills/bba-detection-engineer/SKILL.md +93 -0
- package/skills/bba-engagement-planner/SKILL.md +68 -0
- package/skills/bba-exploit-chainer/SKILL.md +280 -0
- package/skills/bba-exploit-guide/SKILL.md +96 -0
- package/skills/bba-forensics-analyst/SKILL.md +512 -0
- package/skills/bba-graphql-hunter/SKILL.md +145 -0
- package/skills/bba-hardware-hacker/SKILL.md +57 -0
- package/skills/bba-jwt-cracker/SKILL.md +133 -0
- package/skills/bba-llm-redteam/SKILL.md +149 -0
- package/skills/bba-malware-analyst/SKILL.md +305 -0
- package/skills/bba-mobile-pentester/SKILL.md +350 -0
- package/skills/bba-osint-collector/SKILL.md +645 -0
- package/skills/bba-payload-crafter/SKILL.md +347 -0
- package/skills/bba-phishing-operator/SKILL.md +516 -0
- package/skills/bba-poc-validator/SKILL.md +249 -0
- package/skills/bba-privesc-advisor/SKILL.md +98 -0
- package/skills/bba-purple-team/SKILL.md +56 -0
- package/skills/bba-recon-advisor/SKILL.md +215 -0
- package/skills/bba-red-team-operator/SKILL.md +61 -0
- package/skills/bba-report-generator/SKILL.md +145 -0
- package/skills/bba-reverse-engineer/SKILL.md +298 -0
- package/skills/bba-social-engineer/SKILL.md +341 -0
- package/skills/bba-ssrf-hunter/SKILL.md +120 -0
- package/skills/bba-stig-analyst/SKILL.md +108 -0
- package/skills/bba-subdomain-takeover/SKILL.md +141 -0
- package/skills/bba-swarm-orchestrator/SKILL.md +351 -0
- package/skills/bba-threat-modeler/SKILL.md +574 -0
- package/skills/bba-vuln-scanner/SKILL.md +305 -0
- package/skills/bba-web-hunter/SKILL.md +285 -0
- package/skills/bba-wireless-pentester/SKILL.md +539 -0
- package/skills/binary-protection-bypass/PROTECTION_BYPASS_MATRIX.md +168 -0
- package/skills/binary-protection-bypass/SKILL.md +295 -0
- package/skills/browser-exploitation-v8/SKILL.md +334 -0
- package/skills/browser-exploitation-v8/V8_EXPLOITATION_PATTERNS.md +288 -0
- package/skills/business-logic-vuln/SKILL.md +33 -0
- package/skills/business-logic-vulnerabilities/CHECKLIST.md +375 -0
- package/skills/business-logic-vulnerabilities/METHODOLOGY.md +337 -0
- package/skills/business-logic-vulnerabilities/SCENARIOS.md +1095 -0
- package/skills/business-logic-vulnerabilities/SKILL.md +711 -0
- package/skills/classical-cipher-analysis/SKILL.md +663 -0
- package/skills/clickjacking/SKILL.md +163 -0
- package/skills/cmdi-command-injection/SKILL.md +687 -0
- package/skills/code-obfuscation-deobfuscation/SKILL.md +391 -0
- package/skills/container-escape-techniques/DOCKER_ESCAPE_CHAINS.md +296 -0
- package/skills/container-escape-techniques/SKILL.md +339 -0
- package/skills/cors-cross-origin-misconfiguration/SCENARIOS.md +152 -0
- package/skills/cors-cross-origin-misconfiguration/SKILL.md +270 -0
- package/skills/crlf-injection/SKILL.md +179 -0
- package/skills/csp-bypass-advanced/SKILL.md +259 -0
- package/skills/csrf-cross-site-request-forgery/SKILL.md +526 -0
- package/skills/csv-formula-injection/SKILL.md +144 -0
- package/skills/dangling-markup-injection/SKILL.md +321 -0
- package/skills/defi-attack-patterns/SKILL.md +355 -0
- package/skills/dependency-confusion/SKILL.md +178 -0
- package/skills/deserialization-insecure/JAVA_GADGET_CHAINS.md +511 -0
- package/skills/deserialization-insecure/SKILL.md +725 -0
- package/skills/dns-rebinding-attacks/SKILL.md +337 -0
- package/skills/email-header-injection/SKILL.md +349 -0
- package/skills/expression-language-injection/SKILL.md +243 -0
- package/skills/file-access-vuln/SKILL.md +33 -0
- package/skills/format-string-exploitation/SKILL.md +312 -0
- package/skills/ghost-bits-cast-attack/PAYLOAD_COOKBOOK.md +448 -0
- package/skills/ghost-bits-cast-attack/SKILL.md +799 -0
- package/skills/graphql-and-hidden-parameters/SKILL.md +50 -0
- package/skills/hack/SKILL.md +162 -0
- package/skills/hash-attack-techniques/SKILL.md +491 -0
- package/skills/heap-exploitation/HOUSE_OF_TECHNIQUES.md +244 -0
- package/skills/heap-exploitation/IO_FILE_EXPLOITATION.md +256 -0
- package/skills/heap-exploitation/SKILL.md +217 -0
- package/skills/http-host-header-attacks/SKILL.md +323 -0
- package/skills/http-parameter-pollution/SKILL.md +208 -0
- package/skills/http2-specific-attacks/SKILL.md +350 -0
- package/skills/idor-broken-object-authorization/SKILL.md +336 -0
- package/skills/injection-checking/EXTRA_INJECTION_TYPES.md +450 -0
- package/skills/injection-checking/SKILL.md +50 -0
- package/skills/insecure-source-code-management/SKILL.md +161 -0
- package/skills/ios-pentesting-tricks/IOS_RUNTIME_TRICKS.md +411 -0
- package/skills/ios-pentesting-tricks/SKILL.md +418 -0
- package/skills/jndi-injection/SKILL.md +265 -0
- package/skills/jwt-oauth-token-attacks/SKILL.md +301 -0
- package/skills/kernel-exploitation/KERNEL_HEAP_TECHNIQUES.md +293 -0
- package/skills/kernel-exploitation/KERNEL_MITIGATION_BYPASS.md +224 -0
- package/skills/kernel-exploitation/SKILL.md +307 -0
- package/skills/kubernetes-pentesting/SKILL.md +348 -0
- package/skills/lattice-crypto-attacks/SKILL.md +497 -0
- package/skills/linux-lateral-movement/SKILL.md +348 -0
- package/skills/linux-privilege-escalation/KERNEL_EXPLOITS_CHECKLIST.md +260 -0
- package/skills/linux-privilege-escalation/SKILL.md +346 -0
- package/skills/linux-privilege-escalation/SUID_CAPABILITIES_TRICKS.md +305 -0
- package/skills/linux-security-bypass/SKILL.md +345 -0
- package/skills/llm-prompt-injection/JAILBREAK_PATTERNS.md +306 -0
- package/skills/llm-prompt-injection/SKILL.md +357 -0
- package/skills/macos-process-injection/DYLIB_XPC_TECHNIQUES.md +373 -0
- package/skills/macos-process-injection/SKILL.md +384 -0
- package/skills/macos-security-bypass/SKILL.md +337 -0
- package/skills/macos-security-bypass/TCC_BYPASS_MATRIX.md +200 -0
- package/skills/memory-forensics-volatility/SKILL.md +323 -0
- package/skills/memory-forensics-volatility/VOLATILITY_CHEATSHEET.md +225 -0
- package/skills/mobile-ssl-pinning-bypass/SKILL.md +531 -0
- package/skills/network-protocol-attacks/NAME_RESOLUTION_POISONING.md +226 -0
- package/skills/network-protocol-attacks/SKILL.md +330 -0
- package/skills/nosql-injection/SKILL.md +341 -0
- package/skills/ntlm-relay-coercion/COERCION_METHODS.md +253 -0
- package/skills/ntlm-relay-coercion/SKILL.md +267 -0
- package/skills/oauth-oidc-misconfiguration/SKILL.md +46 -0
- package/skills/open-redirect/SKILL.md +380 -0
- package/skills/path-traversal-lfi/SKILL.md +802 -0
- package/skills/prototype-pollution/SKILL.md +190 -0
- package/skills/prototype-pollution-advanced/KNOWN_GADGETS.md +253 -0
- package/skills/prototype-pollution-advanced/SKILL.md +338 -0
- package/skills/race-condition/SKILL.md +526 -0
- package/skills/recon-and-methodology/SKILL.md +389 -0
- package/skills/recon-for-sec/SKILL.md +29 -0
- package/skills/request-smuggling/H2_SMUGGLING_VARIANTS.md +498 -0
- package/skills/request-smuggling/SKILL.md +314 -0
- package/skills/reverse-shell-techniques/SHELL_CHEATSHEET.md +196 -0
- package/skills/reverse-shell-techniques/SKILL.md +290 -0
- package/skills/rsa-attack-techniques/RSA_ATTACK_CATALOG.md +432 -0
- package/skills/rsa-attack-techniques/SKILL.md +437 -0
- package/skills/saml-sso-assertion-attacks/SKILL.md +41 -0
- package/skills/sandbox-escape-techniques/PYTHON_SANDBOX_ESCAPE.md +349 -0
- package/skills/sandbox-escape-techniques/SECCOMP_BYPASS.md +332 -0
- package/skills/sandbox-escape-techniques/SKILL.md +250 -0
- package/skills/smart-contract-vulnerabilities/SKILL.md +314 -0
- package/skills/smart-contract-vulnerabilities/SOLIDITY_VULN_PATTERNS.md +460 -0
- package/skills/sqli-sql-injection/SCENARIOS.md +575 -0
- package/skills/sqli-sql-injection/SKILL.md +489 -0
- package/skills/sqli-sql-injection/SQLMAP_ADVANCED.md +642 -0
- package/skills/ssrf-server-side-request-forgery/SCENARIOS.md +226 -0
- package/skills/ssrf-server-side-request-forgery/SKILL.md +323 -0
- package/skills/ssrf-server-side-request-forgery/URL_PARSER_TRICKS.md +650 -0
- package/skills/ssti-server-side-template-injection/ENGINE_PAYLOADS.md +456 -0
- package/skills/ssti-server-side-template-injection/SCENARIOS.md +319 -0
- package/skills/ssti-server-side-template-injection/SKILL.md +344 -0
- package/skills/stack-overflow-and-rop/ROP_ADVANCED_TECHNIQUES.md +249 -0
- package/skills/stack-overflow-and-rop/SKILL.md +304 -0
- package/skills/steganography-techniques/SKILL.md +348 -0
- package/skills/steganography-techniques/STEGO_TOOLS_GUIDE.md +335 -0
- package/skills/subdomain-takeover/SKILL.md +247 -0
- package/skills/symbolic-execution-tools/ANGR_COOKBOOK.md +437 -0
- package/skills/symbolic-execution-tools/SKILL.md +419 -0
- package/skills/symmetric-cipher-attacks/BLOCK_CIPHER_ATTACKS.md +364 -0
- package/skills/symmetric-cipher-attacks/SKILL.md +462 -0
- package/skills/traffic-analysis-pcap/SKILL.md +341 -0
- package/skills/tunneling-and-pivoting/SKILL.md +343 -0
- package/skills/type-juggling/SKILL.md +291 -0
- package/skills/unauthorized-access-common-services/PORT_SERVICE_MATRIX.md +340 -0
- package/skills/unauthorized-access-common-services/SKILL.md +388 -0
- package/skills/upload-insecure-files/SCENARIOS.md +158 -0
- package/skills/upload-insecure-files/SKILL.md +543 -0
- package/skills/vm-and-bytecode-reverse/SKILL.md +450 -0
- package/skills/vr-cheatsheet-authentication_bypass/SKILL.md +184 -0
- package/skills/vr-cheatsheet-dangerous_functions/SKILL.md +200 -0
- package/skills/vr-cheatsheet-linux_commands/SKILL.md +40 -0
- package/skills/vr-cheatsheet-rce/SKILL.md +177 -0
- package/skills/vr-cheatsheet-reverse_engineering/SKILL.md +144 -0
- package/skills/vr-cheatsheet-sqli/SKILL.md +270 -0
- package/skills/vr-cheatsheet-ssrf/SKILL.md +173 -0
- package/skills/vr-cheatsheet-xss/SKILL.md +177 -0
- package/skills/vr-methodology-mindset_and_tips/SKILL.md +51 -0
- package/skills/vr-template-vulnerability_report_template/SKILL.md +59 -0
- package/skills/vr-writeup-CVE-2026-9136/SKILL.md +171 -0
- package/skills/vr-writeup-ZVE-2026-3795/SKILL.md +350 -0
- package/skills/vr-writeup-api_key_leak/SKILL.md +103 -0
- package/skills/waf-bypass-techniques/SKILL.md +290 -0
- package/skills/waf-bypass-techniques/WAF_PRODUCT_MATRIX.md +202 -0
- package/skills/web-cache-deception/CACHE_POISONING_TECHNIQUES.md +637 -0
- package/skills/web-cache-deception/SKILL.md +222 -0
- package/skills/websocket-security/SKILL.md +454 -0
- package/skills/windows-av-evasion/AMSI_BYPASS_TECHNIQUES.md +289 -0
- package/skills/windows-av-evasion/SKILL.md +342 -0
- package/skills/windows-lateral-movement/CREDENTIAL_DUMPING.md +308 -0
- package/skills/windows-lateral-movement/SKILL.md +335 -0
- package/skills/windows-privilege-escalation/SKILL.md +328 -0
- package/skills/windows-privilege-escalation/TOKEN_POTATO_TRICKS.md +216 -0
- package/skills/windows-privilege-escalation/UAC_BYPASS_METHODS.md +225 -0
- package/skills/xslt-injection/SKILL.md +281 -0
- package/skills/xss-cross-site-scripting/ADVANCED_XSS_TRICKS.md +276 -0
- package/skills/xss-cross-site-scripting/SCENARIOS.md +278 -0
- package/skills/xss-cross-site-scripting/SKILL.md +379 -0
- package/skills/xxe-xml-external-entity/SCENARIOS.md +112 -0
- package/skills/xxe-xml-external-entity/SKILL.md +554 -0
- package/src/agent.js +1 -1
- package/src/session.js +47 -11
- package/src/skills.js +30 -6
- package/src/ui.js +1 -1
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
# Block Cipher Attacks — Detailed Scripts & Walkthrough
|
|
2
|
+
|
|
3
|
+
> **AI LOAD INSTRUCTION**: Load this when you need full attack implementations, step-by-step walkthroughs, and edge-case handling for block cipher exploitation. Assumes the main [SKILL.md](./SKILL.md) is already loaded for attack selection and decision trees.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. PADDING ORACLE — FULL WALKTHROUGH
|
|
8
|
+
|
|
9
|
+
### 1.1 PKCS#7 Padding Review
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
Block size: 16 bytes
|
|
13
|
+
Data "HELLO" (5 bytes) → padded to 16 bytes:
|
|
14
|
+
48 45 4C 4C 4F 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B
|
|
15
|
+
|
|
16
|
+
Valid padding examples (last byte determines):
|
|
17
|
+
...01 → 1 byte of padding
|
|
18
|
+
...02 02 → 2 bytes of padding
|
|
19
|
+
...03 03 03 → 3 bytes of padding
|
|
20
|
+
...10 10 10 ... → 16 bytes (full block of padding)
|
|
21
|
+
|
|
22
|
+
Invalid:
|
|
23
|
+
...03 03 04 → last byte says 4, but 3rd-from-end ≠ 04
|
|
24
|
+
...00 → 0x00 is never valid PKCS#7
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 1.2 Attack Internals — Byte-by-Byte Decryption
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Target: decrypt P[15] (last byte of target block)
|
|
31
|
+
|
|
32
|
+
CBC decryption internals:
|
|
33
|
+
I[15] = AES_DEC(C_target)[15] (intermediate value, unknown)
|
|
34
|
+
P[15] = I[15] ⊕ C_prev[15] (plaintext = intermediate ⊕ prev ciphertext)
|
|
35
|
+
|
|
36
|
+
Attack for padding 0x01 (valid when last plaintext byte = 0x01):
|
|
37
|
+
We send: C'_prev || C_target
|
|
38
|
+
Where C'_prev[15] = guess
|
|
39
|
+
|
|
40
|
+
Server computes: P'[15] = I[15] ⊕ guess
|
|
41
|
+
If P'[15] == 0x01, padding is valid!
|
|
42
|
+
|
|
43
|
+
Therefore: I[15] = guess ⊕ 0x01
|
|
44
|
+
And: P[15] = I[15] ⊕ original_C_prev[15]
|
|
45
|
+
|
|
46
|
+
Next: decrypt P[14] (need padding = 0x02 0x02):
|
|
47
|
+
Set C'_prev[15] = I[15] ⊕ 0x02 (forces P'[15] = 0x02)
|
|
48
|
+
Brute force C'_prev[14] until P'[14] = 0x02
|
|
49
|
+
|
|
50
|
+
Continue until all 16 bytes recovered.
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 1.3 Handling False Positives
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
def is_real_padding(oracle, modified_block, target_block, byte_pos, block_size):
|
|
57
|
+
"""
|
|
58
|
+
When cracking the last byte, padding 0x02 0x02 can give false positive.
|
|
59
|
+
Verify by flipping the penultimate byte — if still valid, it was 0x01.
|
|
60
|
+
"""
|
|
61
|
+
if byte_pos != block_size - 1:
|
|
62
|
+
return True
|
|
63
|
+
|
|
64
|
+
check = bytearray(modified_block)
|
|
65
|
+
check[byte_pos - 1] ^= 1 # flip adjacent byte
|
|
66
|
+
return oracle(bytes(check) + target_block)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 1.4 Encryption via Padding Oracle (CBC-R)
|
|
70
|
+
|
|
71
|
+
A padding oracle can also encrypt arbitrary plaintext without the key:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
def padding_oracle_encrypt(plaintext, block_size, oracle):
|
|
75
|
+
"""Encrypt arbitrary plaintext using padding oracle (CBC-R technique)."""
|
|
76
|
+
# Pad plaintext
|
|
77
|
+
pad_len = block_size - (len(plaintext) % block_size)
|
|
78
|
+
padded = plaintext + bytes([pad_len] * pad_len)
|
|
79
|
+
pt_blocks = [padded[i:i+block_size] for i in range(0, len(padded), block_size)]
|
|
80
|
+
|
|
81
|
+
# Start with random last ciphertext block
|
|
82
|
+
import os
|
|
83
|
+
ct_blocks = [os.urandom(block_size)]
|
|
84
|
+
|
|
85
|
+
# Work backwards
|
|
86
|
+
for pt_block in reversed(pt_blocks):
|
|
87
|
+
# Use padding oracle to find intermediate values for ct_blocks[0]
|
|
88
|
+
intermediate = decrypt_block_intermediate(ct_blocks[0], block_size, oracle)
|
|
89
|
+
# Previous CT block = intermediate ⊕ desired plaintext
|
|
90
|
+
prev_ct = bytes(i ^ p for i, p in zip(intermediate, pt_block))
|
|
91
|
+
ct_blocks.insert(0, prev_ct)
|
|
92
|
+
|
|
93
|
+
return b"".join(ct_blocks) # first block is IV
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 2. CBC BIT FLIPPING — ADVANCED SCENARIOS
|
|
99
|
+
|
|
100
|
+
### 2.1 Multi-Byte Flip
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
def cbc_multibyte_flip(ciphertext, block_size, changes):
|
|
104
|
+
"""
|
|
105
|
+
changes: list of (absolute_position, old_byte, new_byte)
|
|
106
|
+
All changes must be in the SAME target block.
|
|
107
|
+
"""
|
|
108
|
+
ct = bytearray(ciphertext)
|
|
109
|
+
|
|
110
|
+
for pos, old, new in changes:
|
|
111
|
+
target_block = pos // block_size
|
|
112
|
+
byte_in_block = pos % block_size
|
|
113
|
+
prev_block_pos = (target_block - 1) * block_size + byte_in_block
|
|
114
|
+
ct[prev_block_pos] ^= old ^ new
|
|
115
|
+
|
|
116
|
+
return bytes(ct)
|
|
117
|
+
|
|
118
|
+
# Example: change ";admin=false;" to ";admin=true;x"
|
|
119
|
+
changes = [
|
|
120
|
+
(32 + 7, ord('f'), ord('t')), # f → t
|
|
121
|
+
(32 + 8, ord('a'), ord('r')), # a → r
|
|
122
|
+
(32 + 9, ord('l'), ord('u')), # l → u
|
|
123
|
+
(32 + 10, ord('s'), ord('e')), # s → e
|
|
124
|
+
(32 + 11, ord('e'), ord(';')), # e → ;
|
|
125
|
+
(32 + 12, ord(';'), ord('x')), # ; → x (pad)
|
|
126
|
+
]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 2.2 Dealing with Corrupted Block
|
|
130
|
+
|
|
131
|
+
The previous block gets corrupted. Strategies:
|
|
132
|
+
- If corrupted block is IV: server may not validate IV content
|
|
133
|
+
- If corrupted block is a "don't care" field: acceptable corruption
|
|
134
|
+
- Two-block technique: use padding oracle to fix the corrupted block
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 3. ECB BYTE-AT-A-TIME — COMPLETE WALKTHROUGH
|
|
139
|
+
|
|
140
|
+
### Step-by-Step Example
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
Server: encrypt(user_input || secret)
|
|
144
|
+
Block size: 16
|
|
145
|
+
Secret: "FLAG{example}"
|
|
146
|
+
|
|
147
|
+
Round 1: Find block size
|
|
148
|
+
Send "A", "AA", "AAA", ...
|
|
149
|
+
Watch ciphertext length — when it jumps by 16, block size = 16
|
|
150
|
+
|
|
151
|
+
Round 2: Confirm ECB
|
|
152
|
+
Send "A" * 32 → check for repeated blocks
|
|
153
|
+
|
|
154
|
+
Round 3: Decrypt byte 0
|
|
155
|
+
Send "A" * 15 (pad to align secret[0] at end of block 0)
|
|
156
|
+
|
|
157
|
+
Ciphertext block 0 = E("AAAAAAAAAAAAAAA" + secret[0])
|
|
158
|
+
|
|
159
|
+
Build table:
|
|
160
|
+
E("AAAAAAAAAAAAAAA" + chr(0)) → block_0_0
|
|
161
|
+
E("AAAAAAAAAAAAAAA" + chr(1)) → block_0_1
|
|
162
|
+
...
|
|
163
|
+
E("AAAAAAAAAAAAAAA" + "F") → block_0_70 ← matches!
|
|
164
|
+
|
|
165
|
+
secret[0] = "F"
|
|
166
|
+
|
|
167
|
+
Round 4: Decrypt byte 1
|
|
168
|
+
Send "A" * 14
|
|
169
|
+
|
|
170
|
+
Ciphertext block 0 = E("AAAAAAAAAAAAAA" + "F" + secret[1])
|
|
171
|
+
|
|
172
|
+
Build table with known prefix "AAAAAAAAAAAAAAAF":
|
|
173
|
+
E("AAAAAAAAAAAAAA" + "F" + chr(0)) → ...
|
|
174
|
+
E("AAAAAAAAAAAAAA" + "F" + "L") → matches!
|
|
175
|
+
|
|
176
|
+
secret[1] = "L"
|
|
177
|
+
|
|
178
|
+
Continue until all bytes recovered.
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### 3.1 Handling Prefix
|
|
182
|
+
|
|
183
|
+
If server adds unknown prefix: `encrypt(prefix || user_input || secret)`
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
def find_prefix_length(encrypt_oracle, block_size):
|
|
187
|
+
"""Determine length of unknown prefix."""
|
|
188
|
+
# Find which block the prefix ends in
|
|
189
|
+
base = encrypt_oracle(b"")
|
|
190
|
+
for i in range(1, block_size + 1):
|
|
191
|
+
test = encrypt_oracle(b"A" * i)
|
|
192
|
+
# Find first block that differs from base
|
|
193
|
+
for b in range(len(base) // block_size):
|
|
194
|
+
base_block = base[b*block_size:(b+1)*block_size]
|
|
195
|
+
test_block = test[b*block_size:(b+1)*block_size]
|
|
196
|
+
if base_block != test_block:
|
|
197
|
+
# Prefix ends in block b
|
|
198
|
+
# Now find exact byte offset within block
|
|
199
|
+
for j in range(1, block_size + 1):
|
|
200
|
+
t1 = encrypt_oracle(b"A" * j)
|
|
201
|
+
t2 = encrypt_oracle(b"B" * j)
|
|
202
|
+
if (t1[b*block_size:(b+1)*block_size] !=
|
|
203
|
+
t2[b*block_size:(b+1)*block_size]):
|
|
204
|
+
continue
|
|
205
|
+
return b * block_size + (block_size - j)
|
|
206
|
+
return 0
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 4. LCG STATE RECOVERY
|
|
212
|
+
|
|
213
|
+
### 4.1 Known Outputs (Full)
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
def recover_lcg_full(outputs, modulus):
|
|
217
|
+
"""Recover LCG parameters a, b from full consecutive outputs.
|
|
218
|
+
LCG: x_{n+1} = a * x_n + b (mod m)
|
|
219
|
+
"""
|
|
220
|
+
# From three consecutive outputs x0, x1, x2:
|
|
221
|
+
x0, x1, x2 = outputs[0], outputs[1], outputs[2]
|
|
222
|
+
|
|
223
|
+
# x1 = a*x0 + b (mod m)
|
|
224
|
+
# x2 = a*x1 + b (mod m)
|
|
225
|
+
# x2 - x1 = a*(x1 - x0) (mod m)
|
|
226
|
+
|
|
227
|
+
a = ((x2 - x1) * pow(x1 - x0, -1, modulus)) % modulus
|
|
228
|
+
b = (x1 - a * x0) % modulus
|
|
229
|
+
return a, b
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### 4.2 Truncated Outputs (Lattice-Based)
|
|
233
|
+
|
|
234
|
+
When only upper bits of each output are known:
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
# SageMath
|
|
238
|
+
def recover_lcg_truncated(known_upper_bits, modulus, a, b, unknown_bits):
|
|
239
|
+
"""
|
|
240
|
+
Recover full LCG state from truncated outputs.
|
|
241
|
+
Uses CVP on a lattice.
|
|
242
|
+
"""
|
|
243
|
+
n = len(known_upper_bits)
|
|
244
|
+
B = 2^unknown_bits # bound on unknown part
|
|
245
|
+
|
|
246
|
+
# Build lattice
|
|
247
|
+
M = matrix(ZZ, n+1, n+1)
|
|
248
|
+
for i in range(n):
|
|
249
|
+
M[i, i] = modulus
|
|
250
|
+
# Last row encodes the recurrence
|
|
251
|
+
for i in range(n):
|
|
252
|
+
M[n, i] = (a^i) % modulus
|
|
253
|
+
M[n, n] = B
|
|
254
|
+
|
|
255
|
+
# LLL reduction
|
|
256
|
+
L = M.LLL()
|
|
257
|
+
# Extract short vector → recover unknown bits
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## 5. MERSENNE TWISTER STATE RECOVERY
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
def untemper(y):
|
|
266
|
+
"""Reverse MT19937 tempering to recover internal state."""
|
|
267
|
+
# Undo: y ^= y >> 18
|
|
268
|
+
y ^= y >> 18
|
|
269
|
+
|
|
270
|
+
# Undo: y ^= (y << 15) & 0xEFC60000
|
|
271
|
+
y ^= (y << 15) & 0xEFC60000
|
|
272
|
+
|
|
273
|
+
# Undo: y ^= (y << 7) & 0x9D2C5680 (need multiple steps)
|
|
274
|
+
y ^= (y << 7) & 0x9D2C5680
|
|
275
|
+
y ^= (y << 14) & 0x9D2C5680
|
|
276
|
+
y ^= (y << 21) & 0x9D2C5680
|
|
277
|
+
y ^= (y << 28) & 0x9D2C5680
|
|
278
|
+
|
|
279
|
+
# Undo: y ^= y >> 11 (need two steps)
|
|
280
|
+
y ^= (y >> 11)
|
|
281
|
+
y ^= (y >> 22)
|
|
282
|
+
|
|
283
|
+
return y & 0xFFFFFFFF
|
|
284
|
+
|
|
285
|
+
def clone_mt(outputs_624):
|
|
286
|
+
"""Clone MT19937 state from 624 consecutive outputs."""
|
|
287
|
+
assert len(outputs_624) == 624
|
|
288
|
+
state = [untemper(o) for o in outputs_624]
|
|
289
|
+
# Now state[] is the internal state array
|
|
290
|
+
# Can predict all future outputs
|
|
291
|
+
return state
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## 6. AES KEY SCHEDULE WEAKNESS EXPLOITATION
|
|
297
|
+
|
|
298
|
+
### 6.1 Related-Key Attack Setup
|
|
299
|
+
|
|
300
|
+
```python
|
|
301
|
+
from Crypto.Cipher import AES
|
|
302
|
+
|
|
303
|
+
def related_key_test(key1, key2, plaintext):
|
|
304
|
+
"""Demonstrate related-key distinguisher."""
|
|
305
|
+
c1 = AES.new(key1, AES.MODE_ECB).encrypt(plaintext)
|
|
306
|
+
c2 = AES.new(key2, AES.MODE_ECB).encrypt(plaintext)
|
|
307
|
+
|
|
308
|
+
# In AES-256, related keys with specific XOR differences
|
|
309
|
+
# can produce predictable ciphertext relationships
|
|
310
|
+
return c1, c2
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## 7. GCM NONCE REUSE
|
|
316
|
+
|
|
317
|
+
### 7.1 Authentication Key Recovery
|
|
318
|
+
|
|
319
|
+
When AES-GCM nonce is reused with two different messages:
|
|
320
|
+
|
|
321
|
+
```
|
|
322
|
+
Given: (C1, T1, AAD1) and (C2, T2, AAD2) under same (K, nonce)
|
|
323
|
+
|
|
324
|
+
The authentication tags are:
|
|
325
|
+
T1 = GHASH_H(AAD1, C1) ⊕ E_K(nonce||1)
|
|
326
|
+
T2 = GHASH_H(AAD2, C2) ⊕ E_K(nonce||1)
|
|
327
|
+
|
|
328
|
+
Therefore:
|
|
329
|
+
T1 ⊕ T2 = GHASH_H(AAD1, C1) ⊕ GHASH_H(AAD2, C2)
|
|
330
|
+
|
|
331
|
+
GHASH is polynomial evaluation over GF(2^128):
|
|
332
|
+
GHASH_H(A, C) = A_n * H^(n+1) + ... + C_m * H^2 + len_block * H
|
|
333
|
+
|
|
334
|
+
T1 ⊕ T2 gives a polynomial equation in H (the auth key).
|
|
335
|
+
Factor the polynomial over GF(2^128) to find H.
|
|
336
|
+
With H known: forge tags for arbitrary messages.
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
```python
|
|
340
|
+
# SageMath
|
|
341
|
+
def gcm_nonce_reuse_recover_H(aad1, c1, t1, aad2, c2, t2):
|
|
342
|
+
"""Recover GHASH authentication key H from nonce reuse."""
|
|
343
|
+
F.<a> = GF(2^128, modulus=x^128 + x^7 + x^2 + x + 1)
|
|
344
|
+
|
|
345
|
+
def bytes_to_gf(b):
|
|
346
|
+
return F(Integer(int.from_bytes(b, 'big')).bits())
|
|
347
|
+
|
|
348
|
+
# Build GHASH polynomials and find roots of their difference
|
|
349
|
+
# ... (polynomial construction in GF(2^128))
|
|
350
|
+
# Factor to find H
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## 8. PRACTICAL TIPS
|
|
356
|
+
|
|
357
|
+
| Scenario | Common Mistake | Correct Approach |
|
|
358
|
+
|---|---|---|
|
|
359
|
+
| Padding oracle timing | Not accounting for network jitter | Use statistical threshold (multiple requests per guess) |
|
|
360
|
+
| ECB byte-at-a-time | Wrong block alignment with prefix | Measure prefix length first, add compensating padding |
|
|
361
|
+
| CBC bit flip | Forgetting IV is block -1 | If flipping block 0 content, modify IV bytes |
|
|
362
|
+
| XOR key reuse | Trying all cribs simultaneously | Start with high-frequency English words, drag incrementally |
|
|
363
|
+
| LFSR recovery | Too few output bits | Need at least 2×LFSR_length bits for Berlekamp-Massey |
|
|
364
|
+
| MT clone | Non-consecutive outputs | Must be exactly 624 consecutive outputs, no gaps |
|