Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add greatest common multiple #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CODEGATE2024_Greatest_Common_Multiple/description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Greatest Common Multiple
authors:
- soon_haari
original_ctf: "CODEGATE CTF"
year: 2024
description: >-
"My boss 1nteger_c said we will come back with a better GCM challenge. I hereby present, the **Greatest Common Multiple**."
base64_flag: 'Y29kZWdhdGUyMDI0e0lzX2l0X25vcm1hbF9pZl9zb21lX2RhdGFfaXNfb2J0YWluYWJsZV9qdXN0X3dpdGhfdGFnPy4uLkZfMl4xMjgnc19zdXBlcl9wcm9wZXJ0eX0='
flag_format: 'codegate2024{.*}'
31 changes: 31 additions & 0 deletions CODEGATE2024_Greatest_Common_Multiple/release_files/chall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from Crypto.Cipher import AES
from os import urandom
from signal import alarm
from secret import PoW, flag

PoW(26)
alarm(20)

gen = lambda: urandom(12)
randbit = lambda: gen()[0] & 1

key, nonce = urandom(16), gen()

new = lambda: AES.new(key, AES.MODE_GCM, nonce)
s = [gen(), gen()]

while cmd := input("> "):
if cmd == "tag":
cipher = new()
cipher.update(s[0])
cipher.encrypt(s[1])
print(f"tag: {cipher.digest().hex()}")

elif cmd == "u1":
s[randbit()] = gen()

elif cmd == "u2":
s[randbit()] += gen()

if input(f"tag: ") == new().digest().hex():
print(flag)
17 changes: 17 additions & 0 deletions CODEGATE2024_Greatest_Common_Multiple/server_files/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:22.04@sha256:965fbcae990b0467ed5657caceaec165018ef44a4d2d46c7cdea80a9dff0d1ea

RUN apt update
RUN apt-get install -y socat python3 python3-pip

ENV TERM=linux

RUN pip install pycryptodome

COPY ./src/chall.py /
COPY ./src/flag.txt /
COPY ./src/banner.txt /
COPY ./src/secret.py /

CMD socat TCP-LISTEN:9999,reuseaddr,fork EXEC:"python3 /chall.py"

EXPOSE 9999
11 changes: 11 additions & 0 deletions CODEGATE2024_Greatest_Common_Multiple/server_files/src/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

▄████ ▄████▄ ███▄ ▄███▓
██▒ ▀█▒▒██▀ ▀█ ▓██▒▀█▀ ██▒
▒██░▄▄▄░▒▓█ ▄ ▓██ ▓██░
░▓█ ██▓▒▓▓▄ ▄██▒▒██ ▒██
░▒▓███▀▒▒ ▓███▀ ░▒██▒ ░██▒
░▒ ▒ ░ ░▒ ▒ ░░ ▒░ ░ ░
░ ░ ░ ▒ ░ ░ ░
░ ░ ░ ░ ░ ░
░ ░ ░ ░
31 changes: 31 additions & 0 deletions CODEGATE2024_Greatest_Common_Multiple/server_files/src/chall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from Crypto.Cipher import AES
from os import urandom
from signal import alarm
from secret import PoW, flag

PoW(26)
alarm(20)

gen = lambda: urandom(12)
randbit = lambda: gen()[0] & 1

key, nonce = urandom(16), gen()

new = lambda: AES.new(key, AES.MODE_GCM, nonce)
s = [gen(), gen()]

while cmd := input("> "):
if cmd == "tag":
cipher = new()
cipher.update(s[0])
cipher.encrypt(s[1])
print(f"tag: {cipher.digest().hex()}")

elif cmd == "u1":
s[randbit()] = gen()

elif cmd == "u2":
s[randbit()] += gen()

if input(f"tag: ") == new().digest().hex():
print(flag)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
codegate2024{Is_it_normal_if_some_data_is_obtainable_just_with_tag?...F_2^128's_super_property}
28 changes: 28 additions & 0 deletions CODEGATE2024_Greatest_Common_Multiple/server_files/src/secret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import hashlib
import os
import random
import string

colors = ['\033[94m', '\033[96m', '\033[95m']
reset = '\033[0m'

banner = ''.join(random.choice(colors) + char + reset if char != ' ' else char for char in open("banner.txt", "r").read())


colors = ["\033[0;32m", "\033[0;33m", "\033[0;34m", "\033[0;35m", "\033[0;36m", "\033[0;37m", "\033[0;31m", "\033[38;5;248m", "\033[0m"]
green, yellow, blue, purple, cyan, white, red, grey, reset = colors

flag = ""

for c in open("flag.txt", "r").read(): flag += colors[random.randrange(0, 6)] + c
flag += reset

def PoW(bits):
print(banner)
n = random.randrange(0, 2**bits)
a = "".join(random.choices(string.ascii_letters, k=20)).encode()
hsh = hashlib.md5(str(n).encode() + a).digest()

print(f"md5(str(n).encode() + {a}).hexdigest() = {bytes.hex(hsh)}")
if int(input(f"Input the decimal result of n within range(2**{bits}): ")) != n:
exit()