From 63e5b75f0f030d9e36072f486116790bef20cd10 Mon Sep 17 00:00:00 2001 From: Maxime Vorwerk Date: Fri, 20 Sep 2024 11:16:38 +0100 Subject: [PATCH] incomplete --- clouds/clouds.py | 108 ++++++++++++++++++++++++++++++++++++++++++++++ clouds/flag | 1 + clouds/key | 1 + clouds/sol.py | 40 +++++++++++++++++ sans_alpha/sol.py | 6 +++ 5 files changed, 156 insertions(+) create mode 100755 clouds/clouds.py create mode 100644 clouds/flag create mode 100644 clouds/key create mode 100755 clouds/sol.py create mode 100755 sans_alpha/sol.py diff --git a/clouds/clouds.py b/clouds/clouds.py new file mode 100755 index 0000000..cdb5c9a --- /dev/null +++ b/clouds/clouds.py @@ -0,0 +1,108 @@ +#!python2.7 +import binascii + +ROUNDS = 5 +BLOCK_LEN = 8 +HEX_BLOCK_LEN = BLOCK_LEN * 2 +MAX_NOTES = 2048 +MAX_NOTE_LEN = 512 + + +def pad(p): + if len(p) % BLOCK_LEN != 0: + return p + "\0" * (BLOCK_LEN - (len(p) % BLOCK_LEN)) + else: + return p + +def g(i): + b = bin(i).lstrip("0b").rstrip("L").rjust(BLOCK_LEN * 8, "0") + return int(b[::-1], 2) + +def encrypt_block(b): + k = open("./key").read().rstrip() + assert (len(b) * ROUNDS) == len(k) + result = int(binascii.hexlify(b), 16) + for i in range(ROUNDS): + key = int(binascii.hexlify(k[i * BLOCK_LEN:(i + 1) * BLOCK_LEN]), 16) + key_odd = key | 1 + result ^= key + result = g(result) + result = (result * key_odd) % (1 << 64) + return hex(result).lstrip("0x").rstrip("L").rjust(HEX_BLOCK_LEN, "0") + +def encrypt(msg): + plain = pad(msg) + result = "" + for i in range(0, len(plain), BLOCK_LEN): + result += encrypt_block(plain[i:i + BLOCK_LEN]) + return result + +def menu(n): + notes = n + print(""" +1) Store +2) Retrieve +Anything else to quit +""") + ui = raw_input("Selection? ").rstrip() + if ui == "1": + if len(notes) >= MAX_NOTES: + print("Max capacity") + return notes + ui = raw_input("Give me a note to encrypt: ").rstrip() + try: + msg = binascii.unhexlify(ui) + except: + print("Invalid input.") + return notes + if len(msg) > MAX_NOTE_LEN: + print("Invalid input.") + else: + notes.append(encrypt(msg)) + elif ui == "2": + ui = raw_input("What index would you like to read? ").rstrip() + try: + index = int(ui) + except: + print("Invalid index.") + return notes + if index >= 0 and index < len(notes): + print(notes[index]) + else: + print("Invalid index.") + else: + return None + return notes + + +art = """ + . + + | + . / + \ I + / + \ ,g88R_ + d888(` ). _ + - --== 888( ).=-- .+(` )`. + ) Y8P( '`. :( . ) + .+(`( . ) .-- `. ( ) ) + (( (..__.:'-' .=( ) ` _` ) ) + `. `( ) ) ( . ) ( ) ._ + ) ` __.:' ) ( ( )) `-'.:(` ) + ) ) ( ) --' `- __.' :( )) + .-' (_.' .') `( ) )) + (_ ) ` __.:' + + --..,___.--,--'`,---..-.--+--.,,-,,..._.--..-._.-a:f--. + +""" + +print(art) +print("I love cloud watching, so I made a place to store all my notes about them.") + +flag = open("./flag").read().rstrip() +notes = [encrypt(flag)] +notes = menu(notes) +while notes: + notes = menu(notes) diff --git a/clouds/flag b/clouds/flag new file mode 100644 index 0000000..6c32239 --- /dev/null +++ b/clouds/flag @@ -0,0 +1 @@ +picoCTF{flagFLAG} diff --git a/clouds/key b/clouds/key new file mode 100644 index 0000000..044e7f6 --- /dev/null +++ b/clouds/key @@ -0,0 +1 @@ +12345678abcdefgh1a2b3c4d5e6f7g8hffffffff diff --git a/clouds/sol.py b/clouds/sol.py new file mode 100755 index 0000000..9ba66ff --- /dev/null +++ b/clouds/sol.py @@ -0,0 +1,40 @@ +#!python3 +from sage.all import * +from pwn import * + +conn = remote("mercury.picoctf.net", 24402) +conn.recvuntil(b"? ") + +def store(msg): + conn.sendline(b"1") + conn.recvuntil(b": ") + conn.sendline(msg) + conn.recvuntil(b"? ") + +def retrieve(i): + conn.sendline(b"2") + conn.recvuntil(b"? ") + conn.sendline(str(i).encode()) + msg = conn.recvline().strip() + conn.recvuntil(b"? ") + return msg + +def sbox(input): + output = Integer("".join(reversed(input.binary()))) + return output + +def sbox_inv(output): + pass + +def mixin_pre(input, key): + pass + +def mixin_pre_inv(output, result): + pass + +def mixin_post(input, key): + pass + +def mixin_post_inv(output, result): + pass + diff --git a/sans_alpha/sol.py b/sans_alpha/sol.py new file mode 100755 index 0000000..b6458c5 --- /dev/null +++ b/sans_alpha/sol.py @@ -0,0 +1,6 @@ +#!/home/maxime/.pyvenv/bin/python3 +from pwn import * + +s = ssh(host="mimas.picoctf.net", user="ctf-player" , port=50061, password="6abf4a82") +#sh = s.shell(tty=True) +