-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters