-
Notifications
You must be signed in to change notification settings - Fork 11
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
5 changed files
with
67 additions
and
0 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
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,16 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
|
||
from Crypto.PublicKey import RSA | ||
|
||
key = RSA.generate(2048) | ||
|
||
with open("/challenge/key-n", "w") as o: | ||
o.write(hex(key.n)) | ||
with open("/challenge/key-e", "w") as o: | ||
o.write(hex(key.e)) | ||
with open("/challenge/key-d", "w") as o: | ||
o.write(hex(key.d)) | ||
os.chmod("/challenge/key-d", 0o600) | ||
|
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 @@ | ||
So by using `d`, Alice can encrypt data that (because `n` and `e` are in the public key) anyone can decrypt... | ||
This might seem silly, but it actually enables a capability that we haven't yet seen in the module: the ability to attest to multiple people that a message came from Alice. | ||
This can serve as a sort of cryptographic version of a pen-and-ink signature and, in fact, it is called a _signature_! | ||
|
||
This level will explore one application (and pitfall) of RSA signatures. | ||
Recall that `c == m**e mod n`, and recall from middle school that `(x**e)*(y**e) == (x+y)**e`. | ||
This holds just as well in `mod n`, and you can probably see the issue here... | ||
|
||
This level gives you a signing oracle. | ||
Go use it to craft a flag command! |
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,20 @@ | ||
#!/opt/pwn.college/python | ||
|
||
import sys | ||
|
||
from base64 import b64encode | ||
|
||
n = int(open("/challenge/key-n").read(), 16) | ||
d = int(open("/challenge/key-d").read(), 16) | ||
|
||
command = sys.argv[1].strip("\0") if len(sys.argv) > 1 else "chill" | ||
if command == "flag": | ||
print("No.") | ||
sys.exit(1) | ||
|
||
signature = pow( | ||
int.from_bytes(command.encode('latin1'), "little"), | ||
d, | ||
n | ||
).to_bytes(256, "little") | ||
print(f"Signed command (b64): {b64encode(signature).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/opt/pwn.college/python | ||
|
||
import sys | ||
|
||
from base64 import b64decode | ||
|
||
n = int(open("/challenge/key-n").read(), 16) | ||
e = int(open("/challenge/key-e").read(), 16) | ||
|
||
ciphertext = b64decode(sys.argv[1]) | ||
plaintext = pow( | ||
int.from_bytes(ciphertext, "little"), | ||
e, n | ||
).to_bytes(256, "little").rstrip(b"\x00") | ||
|
||
print(f"Received signed command: {plaintext}") | ||
if plaintext == b"flag": | ||
print("You got it!") | ||
print(open("/flag").read()) |