Skip to content

Commit

Permalink
add cpa-suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Sep 28, 2024
1 parent 315ae72 commit 977212e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cryptography/cpa-suffix/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Okay, now let's complicate things slightly to increase the realism.
It's rare that you can just craft queries for the plaintext that you want.
However, it's less rare that you can isolate the _tail end_ of some data into its own block, and in ECB, this is bad news.
We'll explore this concept in this challenge, replacing your ability to query substrings of the flag with just an ability to encrypt some bytes off the end.

Show us that you can still solve this!

----
**HINT:**
Keep in mind that, once you recover some part of the end of the flag, you can build a new codebook with additional prefixes of the known parts, and repeat the attack on the previous byte!
26 changes: 26 additions & 0 deletions cryptography/cpa-suffix/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/opt/pwn.college/python

from base64 import b64encode, b64decode
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from Crypto.Random import get_random_bytes

flag = open("/flag", "rb").read().strip()

key = get_random_bytes(16)
cipher = AES.new(key=key, mode=AES.MODE_ECB)

while True:
print("Choose an action?")
print("1. Encrypt chosen plaintext.")
print("2. Encrypt the tail end of the flag.")
if (choice := int(input("Choice? "))) == 1:
pt = input("Data? ").strip().encode()
elif choice == 2:
length = int(input("Length? "))
pt = flag[-length:]
else:
break

ct = cipher.encrypt(pad(pt, cipher.block_size))
print(f"Result: {b64encode(ct).decode()}")
6 changes: 4 additions & 2 deletions cryptography/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ challenges:
- id: level-4
name: AES
- id: cpa
name: Chosen-plaintext Attack
name: AES-ECB-CPA
- id: cpa-http
name: CPA-over-HTTP
name: AES-ECB-CPA-HTTP
- id: cpa-suffix
name: AES-ECB-CPA-Suffix
- id: level-5
name: level5
- id: level-6
Expand Down

0 comments on commit 977212e

Please sign in to comment.