te
This commit is contained in:
BIN
cscg25/crypto/intro1/__pycache__/secret.cpython-313.pyc
Normal file
BIN
cscg25/crypto/intro1/__pycache__/secret.cpython-313.pyc
Normal file
Binary file not shown.
45
cscg25/crypto/intro1/exploit.py
Normal file
45
cscg25/crypto/intro1/exploit.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from pwn import *
|
||||
import binascii
|
||||
|
||||
|
||||
p = remote("a96a15c9c5222abacb014e80-1024-intro-crypto-1.challenge.cscg.live", 1337, ssl=True)# Define functions for convenience
|
||||
|
||||
def recv_until(delim):
|
||||
return p.recvuntil(delim)
|
||||
|
||||
def interact():
|
||||
p.interactive()
|
||||
|
||||
def send_payload(payload):
|
||||
p.sendline(payload)
|
||||
|
||||
def xor(bytes1, bytes2):
|
||||
return bytes([b1 ^ b2 for b1, b2 in zip(bytes1, bytes2)])
|
||||
|
||||
|
||||
# Example interaction
|
||||
recv_until(b":")
|
||||
payload = b"41" * 74
|
||||
send_payload(payload)
|
||||
|
||||
encrypted_plaintext = []
|
||||
|
||||
for _ in range(255):
|
||||
data = binascii.unhexlify(recv_until(b"\n").replace(b"\n",b"").split(b" ")[-1])
|
||||
encrypted_plaintext.append(data)
|
||||
|
||||
payload = b"\x41" * 74
|
||||
|
||||
print(payload)
|
||||
|
||||
keystreams = [xor(enc, payload) for enc in encrypted_plaintext]
|
||||
|
||||
enc_flag = binascii.unhexlify(recv_until(b"\n").replace(b"\n",b"").split(b" ")[-1])
|
||||
print(enc_flag)
|
||||
|
||||
dec_flags = [xor(keystream, enc_flag) for keystream in keystreams]
|
||||
|
||||
for flag in dec_flags:
|
||||
if b'CSCG{' in flag:
|
||||
print(flag)
|
||||
|
||||
60
cscg25/crypto/intro1/main.py
Executable file
60
cscg25/crypto/intro1/main.py
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env pypy3
|
||||
|
||||
import os
|
||||
from pydoc import plain
|
||||
from sys import byteorder
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Util import Counter
|
||||
import hashlib
|
||||
|
||||
# Create a secret.py file with a variable `FLAG` for local testing :)
|
||||
from secret import FLAG
|
||||
|
||||
secret_key = os.urandom(16)
|
||||
|
||||
def encrypt(plaintext, counter):
|
||||
m = hashlib.sha256()
|
||||
m.update(counter.to_bytes(8, byteorder="big"))
|
||||
|
||||
alg = AES.new(secret_key, AES.MODE_CTR, nonce=m.digest()[0:8])
|
||||
ciphertext = alg.encrypt(plaintext)
|
||||
|
||||
return ciphertext.hex()
|
||||
|
||||
def xor(bytes1, bytes2):
|
||||
return bytes([b1 ^ b2 for b1, b2 in zip(bytes1, bytes2)])
|
||||
|
||||
def main():
|
||||
print("DES is broken, long live the secure AES encryption!")
|
||||
print("Give me a plaintext and I'll encrypt it a few times for you. For more security of course!")
|
||||
|
||||
try:
|
||||
plaintext = bytes.fromhex("41" * 512)
|
||||
print(plaintext)
|
||||
except ValueError:
|
||||
print("Please enter a hex string next time.")
|
||||
exit(0)
|
||||
|
||||
encrypted_plaintext = []
|
||||
|
||||
for i in range(0, 255):
|
||||
crypt = encrypt(plaintext, i)
|
||||
encrypted_plaintext.append(bytes.fromhex(crypt))
|
||||
print(f"Ciphertext {i:03d}: {crypt}")
|
||||
|
||||
keystreams = [xor(enc, plaintext) for enc in encrypted_plaintext]
|
||||
|
||||
enc_flag = encrypt(FLAG.encode("ascii"), int.from_bytes(os.urandom(1), byteorder="big"))
|
||||
|
||||
print("Flag:", enc_flag)
|
||||
|
||||
dec_flags = [xor(keystream, bytes.fromhex(enc_flag)) for keystream in keystreams]
|
||||
|
||||
for flag in dec_flags:
|
||||
if b'cscg' in flag:
|
||||
print(flag)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1
cscg25/crypto/intro1/secret.py
Normal file
1
cscg25/crypto/intro1/secret.py
Normal file
@@ -0,0 +1 @@
|
||||
FLAG = "cscg{a1b2c3d4e5f67890abcdef1234567890abcdef1234567890abcdef1234}"
|
||||
Reference in New Issue
Block a user