From 002f99764111f537e3ddb38ea14f6abf113394ef Mon Sep 17 00:00:00 2001 From: itoid Date: Sat, 11 Oct 2025 22:45:10 +0700 Subject: [PATCH] Delete services/phew directory --- services/phew/Dockerfile | 32 -------- services/phew/chall.py | 126 ------------------------------- services/phew/dist/chall.py | 126 ------------------------------- services/phew/docker-compose.yml | 16 ---- services/phew/requirements.txt | 1 - services/phew/run.sh | 3 - services/phew/start.sh | 25 ------ 7 files changed, 329 deletions(-) delete mode 100644 services/phew/Dockerfile delete mode 100644 services/phew/chall.py delete mode 100644 services/phew/dist/chall.py delete mode 100644 services/phew/docker-compose.yml delete mode 100644 services/phew/requirements.txt delete mode 100644 services/phew/run.sh delete mode 100644 services/phew/start.sh diff --git a/services/phew/Dockerfile b/services/phew/Dockerfile deleted file mode 100644 index 0d0920d..0000000 --- a/services/phew/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -FROM python:3.12-slim - -ARG PASSWORD=root -ENV DEBIAN_FRONTEND=noninteractive -ENV HOME=/home/ctf -WORKDIR /home/ctf/chall - -RUN apt-get update && apt-get install -y --no-install-recommends \ - openssh-server \ - build-essential \ - libffi-dev \ - libssl-dev \ - python3-dev \ - bash \ - && rm -rf /var/lib/apt/lists/* - -RUN useradd -m -d /home/ctf -s /bin/bash ctf && \ - echo "ctf:${PASSWORD}" | chpasswd - -RUN mkdir -p /var/run/sshd - -COPY requirements.txt /tmp/requirements.txt -RUN pip install --no-cache-dir -r /tmp/requirements.txt - -COPY ./src /home/ctf/chall/src -COPY ./start.sh /start.sh -RUN chmod +x /start.sh /home/ctf/chall/src/run.sh - -RUN chown -R root:root /home/ctf/chall && chmod -R 555 /home/ctf/chall - -EXPOSE 8000 22 -CMD ["/start.sh"] diff --git a/services/phew/chall.py b/services/phew/chall.py deleted file mode 100644 index a7bea1b..0000000 --- a/services/phew/chall.py +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env python3 - -import os, sys, json, random, hashlib, hmac -from Crypto.Cipher import AES -from Crypto.Util.Padding import pad -with open("/flag.txt", "rb") as f: - flag = f.read() - -menu = ( - "1) encrypt\n" - "2) profit\n" - "3) nyerah\n" - ">> " -) - - -k = 1024 -n = 169 - -rng = random.SystemRandom() - -def rand(k_bits: int) -> int: - return rng.randrange(1, 1 << k_bits) - -def gen(n: int, k_bits: int): - a = [rand(k_bits) for _ in range(n)] - return a - -def b2b(b: bytes) -> list[int]: - out = [] - for byte in b: - for i in range(8): - out.append((byte >> i) & 1) - return out - -def pack(bits) -> bytes: - out = bytearray() - for i in range(0, len(bits), 8): - chunk = bits[i:i+8] - val = 0 - for j, bit in enumerate(chunk): - val |= (bit & 1) << j - out.append(val) - return bytes(out) - -def gen_key(x_bits: list[int], saltx: bytes, salty: bytes, length: int = 16) -> bytes: - material = pack(x_bits) - prk = hashlib.pbkdf2_hmac("sha256", material, saltx, 131072, dklen=32) - return hmac.new(prk, b"afk-players-wanted-now" + salty + b"\x01", hashlib.sha256).digest()[:length] - -def enc(k: bytes, data: bytes): - iv = os.urandom(16) - ct = AES.new(k, AES.MODE_CBC, iv).encrypt(pad(data, 16)) - return iv, ct - -def add(a, x_bits) -> int: - return sum(ai for ai, xi in zip(a, x_bits) if xi) - -def main(): - a = gen(n, k) - x_bits = b2b(flag) - if len(x_bits) < n: - x_bits += [rng.randrange(0, 2) for _ in range(n - len(x_bits))] - else: - x_bits = x_bits[:n] - - s = add(a, x_bits) - - saltx = os.urandom(16) - salty = os.urandom(16) - key = gen_key(x_bits, saltx, salty) - - iv, ct = enc(key, flag) - - header = { - "n": n, - "k_bits": k, - } - print(json.dumps(header, separators=(",", ":")), flush=True) - - while True: - try: - print(menu, end="", flush=True) - line = sys.stdin.readline() - if not line: - break - try: - choice = int(line.strip()) - except ValueError: - print("sheesh") - continue - - if choice == 1: - print("data: ", end="", flush=True) - dline = sys.stdin.readline() - if not dline: - break - try: - data = bytes.fromhex(dline.strip()) - except Exception: - print("hmmm") - continue - iv, ct = enc(key, data) - print(iv.hex()) - print(ct.hex()) - - elif choice == 2: - print(json.dumps({"a": a}, separators=(",", ":"))) - print(str(s)) - print(saltx.hex()) - print(salty.hex()) - print(iv.hex()) - print(ct.hex()) - - elif choice == 3: - print("bubay") - return - - else: - print("tidak ada yang mustahil, hehehe") - - except Exception: - print("zzz") - -if __name__ == "__main__": - main() diff --git a/services/phew/dist/chall.py b/services/phew/dist/chall.py deleted file mode 100644 index a7bea1b..0000000 --- a/services/phew/dist/chall.py +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env python3 - -import os, sys, json, random, hashlib, hmac -from Crypto.Cipher import AES -from Crypto.Util.Padding import pad -with open("/flag.txt", "rb") as f: - flag = f.read() - -menu = ( - "1) encrypt\n" - "2) profit\n" - "3) nyerah\n" - ">> " -) - - -k = 1024 -n = 169 - -rng = random.SystemRandom() - -def rand(k_bits: int) -> int: - return rng.randrange(1, 1 << k_bits) - -def gen(n: int, k_bits: int): - a = [rand(k_bits) for _ in range(n)] - return a - -def b2b(b: bytes) -> list[int]: - out = [] - for byte in b: - for i in range(8): - out.append((byte >> i) & 1) - return out - -def pack(bits) -> bytes: - out = bytearray() - for i in range(0, len(bits), 8): - chunk = bits[i:i+8] - val = 0 - for j, bit in enumerate(chunk): - val |= (bit & 1) << j - out.append(val) - return bytes(out) - -def gen_key(x_bits: list[int], saltx: bytes, salty: bytes, length: int = 16) -> bytes: - material = pack(x_bits) - prk = hashlib.pbkdf2_hmac("sha256", material, saltx, 131072, dklen=32) - return hmac.new(prk, b"afk-players-wanted-now" + salty + b"\x01", hashlib.sha256).digest()[:length] - -def enc(k: bytes, data: bytes): - iv = os.urandom(16) - ct = AES.new(k, AES.MODE_CBC, iv).encrypt(pad(data, 16)) - return iv, ct - -def add(a, x_bits) -> int: - return sum(ai for ai, xi in zip(a, x_bits) if xi) - -def main(): - a = gen(n, k) - x_bits = b2b(flag) - if len(x_bits) < n: - x_bits += [rng.randrange(0, 2) for _ in range(n - len(x_bits))] - else: - x_bits = x_bits[:n] - - s = add(a, x_bits) - - saltx = os.urandom(16) - salty = os.urandom(16) - key = gen_key(x_bits, saltx, salty) - - iv, ct = enc(key, flag) - - header = { - "n": n, - "k_bits": k, - } - print(json.dumps(header, separators=(",", ":")), flush=True) - - while True: - try: - print(menu, end="", flush=True) - line = sys.stdin.readline() - if not line: - break - try: - choice = int(line.strip()) - except ValueError: - print("sheesh") - continue - - if choice == 1: - print("data: ", end="", flush=True) - dline = sys.stdin.readline() - if not dline: - break - try: - data = bytes.fromhex(dline.strip()) - except Exception: - print("hmmm") - continue - iv, ct = enc(key, data) - print(iv.hex()) - print(ct.hex()) - - elif choice == 2: - print(json.dumps({"a": a}, separators=(",", ":"))) - print(str(s)) - print(saltx.hex()) - print(salty.hex()) - print(iv.hex()) - print(ct.hex()) - - elif choice == 3: - print("bubay") - return - - else: - print("tidak ada yang mustahil, hehehe") - - except Exception: - print("zzz") - -if __name__ == "__main__": - main() diff --git a/services/phew/docker-compose.yml b/services/phew/docker-compose.yml deleted file mode 100644 index 48b947b..0000000 --- a/services/phew/docker-compose.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: "3.8" - -services: - phew: - container_name: phew_container - hostname: phew - restart: always - build: - context: . - args: - - PASSWORD=root - ports: - - "13000:8000" - - "13022:22" - environment: - - FLAG=GEMASTIK{local_flag} diff --git a/services/phew/requirements.txt b/services/phew/requirements.txt deleted file mode 100644 index c21b6ec..0000000 --- a/services/phew/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pycryptodome \ No newline at end of file diff --git a/services/phew/run.sh b/services/phew/run.sh deleted file mode 100644 index 6ae49cb..0000000 --- a/services/phew/run.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exec socat tcp-l:8000,reuseaddr,fork exec:"python3 ./chall.py" diff --git a/services/phew/start.sh b/services/phew/start.sh deleted file mode 100644 index 7b40126..0000000 --- a/services/phew/start.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -e - -ssh-keygen -A - -# Configure SSH -grep -q "^PermitRootLogin" /etc/ssh/sshd_config && \ - sed -i "s/^PermitRootLogin.*/PermitRootLogin no/" /etc/ssh/sshd_config || \ - echo "PermitRootLogin no" >> /etc/ssh/sshd_config - -grep -q "^PasswordAuthentication" /etc/ssh/sshd_config && \ - sed -i "s/^PasswordAuthentication.*/PasswordAuthentication yes/" /etc/ssh/sshd_config || \ - echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config - -echo "AllowUsers ctf" >> /etc/ssh/sshd_config - -/usr/sbin/sshd - -if [ -n "$FLAG" ]; then - echo "$FLAG" > /flag.txt - chmod 644 /flag.txt - chown root:root /flag.txt -fi - -exec su -c "cd /home/ctf/chall/src && ./run.sh" -s /bin/bash ctf