commit 93974b52a3e0c66a5561ef847f05d89b6b806ec7 Author: Toerd@archlinux Date: Wed Jan 6 02:48:33 2021 +0100 First 2 challenges from 247ctf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..424df08 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.zip +*.tar.gz +*.tar +*.bin +*.exe +*.jpg +*.enc +*.png +*.gif \ No newline at end of file diff --git a/247ctf/beginner_tutorial/tips_and_tricks/addition.py b/247ctf/beginner_tutorial/tips_and_tricks/addition.py new file mode 100755 index 0000000..0fa9ce5 --- /dev/null +++ b/247ctf/beginner_tutorial/tips_and_tricks/addition.py @@ -0,0 +1,21 @@ +#!/usr/bin/python +import pwn +import re +import time + +r = pwn.remote('0c2450d17014ac4e.247ctf.com', 50319) + +while not r.can_recv(0): + time.sleep(0.5) + +# can be substituted by True to speed up the process (: +while r.can_recv(0): + answ = r.recvline().decode('utf-8') + ns = re.findall("\d{1,4}", answ) + if len(ns) == 2: + sum = int(ns[0]) + int(ns[1]) + ans = bytes(str(sum) + '\r\n', 'utf-8') + r.send(ans) + time.sleep(0.05) + else: + print(answ) diff --git a/247ctf/cryptography/my_magic_bytes/xor.py b/247ctf/cryptography/my_magic_bytes/xor.py new file mode 100755 index 0000000..05587c5 --- /dev/null +++ b/247ctf/cryptography/my_magic_bytes/xor.py @@ -0,0 +1,22 @@ +#!/bin/python +# JPEG (JFIF) has the following header: FF D8 FF E0 00 10 4A 46 49 46 00 01 +correct_header = [0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01] +# The file we got has this header: (Inspected using xxd / emacs hexl-mode) +# false_header = [0xb9, 0x14, 0x06, 0x45, 0x71, 0xe0, 0xb5, 0xf7, 0x37, 0x07, 0xcb, 0x85] + +# A: Correct header, B: Wrong header, X: de/encryption key +# Get the XOR key to decrypt the file (A ^ X = B => X = A ^ B) +xor = [] +with open("my_magic_bytes.jpg.enc", "rb") as f: + for i in range(len(correct_header)): + xor.append(correct_header[i] ^ int(f.read(1).hex(), 16)) + +# read binary data from file, write xored binary data to file +i = 0 +with open("my_magic_bytes.jpg.enc", "rb") as f, open("mep.jpg", "wb") as o: + while (cb := f.read(1)): + xored = int(cb.hex(), 16) ^ xor[i] + o.write(bytes([xored])) + i = (i + 1) % len(xor) + +# FLAG: 247CTF{ca4e3b7f913ca7ca8f33fb0504f2947f} \ No newline at end of file