docker compose bugfix
This commit is contained in:
@@ -4,7 +4,7 @@ FROM ubuntu:24.04
|
||||
# Build-time args
|
||||
ARG PASSWORD=root
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
WORKDIR /home/ctf/chall
|
||||
WORKDIR /home/ctfuser/chall
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
@@ -18,15 +18,15 @@ RUN apt-get update && \
|
||||
vim \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN useradd -m -d /home/ctf -s /bin/bash ctf && echo "ctf:${PASSWORD}" | chpasswd
|
||||
RUN useradd -m -d /home/ctfuser -s /bin/bash ctfuser && echo "ctfuser:${PASSWORD}" | chpasswd
|
||||
|
||||
RUN mkdir -p /var/run/sshd
|
||||
|
||||
COPY chall/ /home/ctf/chall
|
||||
COPY chall/ /home/ctfuser/chall
|
||||
COPY ./entrypoint.sh /entrypoint.sh
|
||||
|
||||
RUN chmod +x /entrypoint.sh /home/ctf/chall/run.sh && \
|
||||
chown -R root:root /home/ctf/chall && chmod -R 555 /home/ctf/chall
|
||||
RUN chmod +x /entrypoint.sh /home/ctfuser/chall/run.sh && \
|
||||
chown -R root:root /home/ctfuser/chall && chmod -R 555 /home/ctfuser/chall
|
||||
|
||||
EXPOSE 9000 22
|
||||
CMD ["/entrypoint.sh"]
|
||||
@@ -11,7 +11,7 @@ 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
|
||||
echo "AllowUsers ctfuser" >> /etc/ssh/sshd_config
|
||||
|
||||
/usr/sbin/sshd
|
||||
|
||||
@@ -21,4 +21,4 @@ if [ -n "$FLAG" ]; then
|
||||
chown root:root /flag.txt
|
||||
fi
|
||||
|
||||
exec su -c "cd /home/ctf/chall && ./run.sh" -s /bin/bash ctf
|
||||
exec su -c "cd /home/ctfuser/chall && ./run.sh" -s /bin/bash ctfuser
|
||||
@@ -2,8 +2,8 @@ FROM python:3.12-slim
|
||||
|
||||
ARG PASSWORD=root
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV HOME=/home/ctf
|
||||
WORKDIR /home/ctf/chall
|
||||
ENV HOME=/home/ctfuser
|
||||
WORKDIR /home/ctfuser/chall
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
openssh-server \
|
||||
@@ -11,22 +11,23 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libffi-dev \
|
||||
libssl-dev \
|
||||
python3-dev \
|
||||
socat \
|
||||
bash \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN useradd -m -d /home/ctf -s /bin/bash ctf && \
|
||||
echo "ctf:${PASSWORD}" | chpasswd
|
||||
RUN useradd -m -d /home/ctfuser -s /bin/bash ctfuser && \
|
||||
echo "ctfuser:${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 ./src /home/ctfuser/chall/src
|
||||
COPY ./start.sh /start.sh
|
||||
RUN chmod +x /start.sh /home/ctf/chall/src/run.sh
|
||||
RUN chmod +x /start.sh /home/ctfuser/chall/src/run.sh
|
||||
|
||||
RUN chown -R root:root /home/ctf/chall && chmod -R 555 /home/ctf/chall
|
||||
RUN chown -R root:root /home/ctfuser/chall && chmod -R 555 /home/ctfuser/chall
|
||||
|
||||
EXPOSE 8000 22
|
||||
CMD ["/start.sh"]
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
from Crypto.Util.number import *
|
||||
from math import lcm
|
||||
import random
|
||||
|
||||
class pailier:
|
||||
def __init__(self):
|
||||
self.primes = [getPrime(512) for _ in range(2)]
|
||||
self.n = 1
|
||||
self.phi = 1
|
||||
self.mul = 1
|
||||
for i in range(2):
|
||||
self.n *= self.primes[i]
|
||||
self.phi *= (self.primes[i] - 1)
|
||||
self.n2 = self.n * self.n
|
||||
self.g = [pow(random.randrange(1, self.n2), self.primes[i], self.n2) for i in range(2)]
|
||||
for x in self.g:
|
||||
self.mul = (self.mul * x) % self.n2
|
||||
self.miu = inverse(self.L(pow(self.mul, self.phi, self.n2)), self.n)
|
||||
self.alpha = [None, None]
|
||||
for idx in range(2):
|
||||
while True:
|
||||
a = random.randrange(2, self.n - 1)
|
||||
if GCD(a, self.n) == 1:
|
||||
self.alpha[idx] = a
|
||||
break
|
||||
self.beta = [random.randrange(0, self.n), random.randrange(0, self.n)]
|
||||
|
||||
def L(self, val):
|
||||
return (val - 1) // self.n
|
||||
|
||||
def pubkey(self):
|
||||
return (self.n, self.g)
|
||||
|
||||
def encrypt(self, msg: int) -> int:
|
||||
r = random.randrange(0, self.n - 1)
|
||||
gb = self.g[random.randrange(0, 2)]
|
||||
gm = pow(gb, msg, self.n2)
|
||||
rn = pow(r, self.n, self.n2)
|
||||
return (gm * rn) % self.n2
|
||||
|
||||
def decrypt(self, ct: int) -> int:
|
||||
raw = self.L(pow(ct, self.phi, self.n2)) % self.n
|
||||
raw = (raw * self.miu) % self.n
|
||||
t = pow(ct % self.n, (self.n - 1) // 2, self.n) if (self.n % 2 == 1) else 0
|
||||
idx = 0 if t == 1 else 1
|
||||
return (self.alpha[idx] * raw + self.beta[idx]) % self.n
|
||||
|
||||
from Crypto.Util.number import *
|
||||
from math import lcm
|
||||
import random
|
||||
|
||||
class pailier:
|
||||
def __init__(self):
|
||||
self.primes = [getPrime(512) for _ in range(2)]
|
||||
self.n = 1
|
||||
self.phi = 1
|
||||
self.mul = 1
|
||||
for i in range(2):
|
||||
self.n *= self.primes[i]
|
||||
self.phi *= (self.primes[i] - 1)
|
||||
self.n2 = self.n * self.n
|
||||
self.g = [pow(random.randrange(1, self.n2), self.primes[i], self.n2) for i in range(2)]
|
||||
for x in self.g:
|
||||
self.mul = (self.mul * x) % self.n2
|
||||
self.miu = inverse(self.L(pow(self.mul, self.phi, self.n2)), self.n)
|
||||
self.alpha = [None, None]
|
||||
for idx in range(2):
|
||||
while True:
|
||||
a = random.randrange(2, self.n - 1)
|
||||
if GCD(a, self.n) == 1:
|
||||
self.alpha[idx] = a
|
||||
break
|
||||
self.beta = [random.randrange(0, self.n), random.randrange(0, self.n)]
|
||||
|
||||
def L(self, val):
|
||||
return (val - 1) // self.n
|
||||
|
||||
def pubkey(self):
|
||||
return (self.n, self.g)
|
||||
|
||||
def encrypt(self, msg: int) -> int:
|
||||
r = random.randrange(0, self.n - 1)
|
||||
gb = self.g[random.randrange(0, 2)]
|
||||
gm = pow(gb, msg, self.n2)
|
||||
rn = pow(r, self.n, self.n2)
|
||||
return (gm * rn) % self.n2
|
||||
|
||||
def decrypt(self, ct: int) -> int:
|
||||
raw = self.L(pow(ct, self.phi, self.n2)) % self.n
|
||||
raw = (raw * self.miu) % self.n
|
||||
t = pow(ct % self.n, (self.n - 1) // 2, self.n) if (self.n % 2 == 1) else 0
|
||||
idx = 0 if t == 1 else 1
|
||||
return (self.alpha[idx] * raw + self.beta[idx]) % self.n
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from Pailier import *
|
||||
from Crypto.Util.number import *
|
||||
with open("/flag.txt", "rb") as f:
|
||||
flag = f.read()
|
||||
flag = bytes_to_long(flag)
|
||||
cipher = pailier()
|
||||
while True:
|
||||
print("1. encrypt")
|
||||
print("2. bingo")
|
||||
print("3. decrypt")
|
||||
print("4. exit")
|
||||
inp = int(input("> "))
|
||||
if inp==1:
|
||||
print("pt (hex)")
|
||||
inp = input("> ")
|
||||
ct = cipher.encrypt(int(inp,16))
|
||||
print('ct : ','{0:x}'.format(ct))
|
||||
elif inp==2:
|
||||
ct = cipher.encrypt(flag)
|
||||
print('ct : ','{0:x}'.format(ct))
|
||||
elif inp==3:
|
||||
print("ct (hex)")
|
||||
inp = input("> ")
|
||||
pt = cipher.decrypt(int(inp,16))
|
||||
print('pt : ','{0:x}'.format(pt))
|
||||
else:
|
||||
exit()
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from Pailier import *
|
||||
from Crypto.Util.number import *
|
||||
with open("/flag.txt", "rb") as f:
|
||||
flag = f.read()
|
||||
flag = bytes_to_long(flag)
|
||||
cipher = pailier()
|
||||
while True:
|
||||
print("1. encrypt")
|
||||
print("2. bingo")
|
||||
print("3. decrypt")
|
||||
print("4. exit")
|
||||
inp = int(input("> "))
|
||||
if inp==1:
|
||||
print("pt (hex)")
|
||||
inp = input("> ")
|
||||
ct = cipher.encrypt(int(inp,16))
|
||||
print('ct : ','{0:x}'.format(ct))
|
||||
elif inp==2:
|
||||
ct = cipher.encrypt(flag)
|
||||
print('ct : ','{0:x}'.format(ct))
|
||||
elif inp==3:
|
||||
print("ct (hex)")
|
||||
inp = input("> ")
|
||||
pt = cipher.decrypt(int(inp,16))
|
||||
print('pt : ','{0:x}'.format(pt))
|
||||
else:
|
||||
exit()
|
||||
@@ -12,7 +12,7 @@ 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
|
||||
echo "AllowUsers ctfuser" >> /etc/ssh/sshd_config
|
||||
|
||||
/usr/sbin/sshd
|
||||
|
||||
@@ -22,4 +22,4 @@ if [ -n "$FLAG" ]; then
|
||||
chown root:root /flag.txt
|
||||
fi
|
||||
|
||||
exec su -c "cd /home/ctf/chall/src && ./run.sh" -s /bin/bash ctf
|
||||
exec su -c "cd /home/ctfuser/chall/src && ./run.sh" -s /bin/bash ctfuser
|
||||
|
||||
@@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libffi-dev \
|
||||
libssl-dev \
|
||||
python3-dev \
|
||||
socat \
|
||||
bash \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
||||
@@ -1,116 +1,116 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import binascii
|
||||
import hashlib
|
||||
import threading
|
||||
import time
|
||||
import sys
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Util.Padding import pad, unpad
|
||||
|
||||
seed_bits = 23
|
||||
seed_max = 1 << seed_bits
|
||||
seed_len = (seed_bits + 7) // 8
|
||||
key = os.urandom(16)
|
||||
|
||||
def hash_seed(seed_int: int) -> bytes:
|
||||
sb = seed_int.to_bytes(seed_len, "big")
|
||||
return hashlib.sha256(sb).digest()[:16]
|
||||
|
||||
seed = int.from_bytes(os.urandom(4), "big") % seed_max
|
||||
seed2 = int.from_bytes(os.urandom(4), "big") % seed_max
|
||||
K1 = hash_seed(seed)
|
||||
K2 = hash_seed(seed2)
|
||||
|
||||
with open("./flag.txt", "rb") as f:
|
||||
flag = f.read()
|
||||
|
||||
def read_hex(prompt: str):
|
||||
s = input(prompt).strip()
|
||||
try:
|
||||
return binascii.unhexlify(s)
|
||||
except Exception:
|
||||
print("hmm")
|
||||
return None
|
||||
|
||||
def enc_cfb(pt: bytes) -> bytes:
|
||||
iv = os.urandom(16)
|
||||
aes = AES.new(key, AES.MODE_CFB, iv=iv, segment_size=128)
|
||||
ct = aes.encrypt(pt)
|
||||
return iv + ct
|
||||
|
||||
def enc_cbc(data: bytes, iv1: bytes, iv2: bytes, padd: bool) -> bytes:
|
||||
x = pad(data, 16) if padd else data
|
||||
c1 = AES.new(K1, AES.MODE_CBC, iv=iv1).encrypt(x)
|
||||
c2 = AES.new(K2, AES.MODE_CBC, iv=iv2).encrypt(c1)
|
||||
return c2
|
||||
|
||||
def menu():
|
||||
print("""
|
||||
1. encrypt
|
||||
2. profit
|
||||
3. get third
|
||||
4. exit
|
||||
""")
|
||||
|
||||
third = 0
|
||||
iv11 = None
|
||||
iv22 = None
|
||||
|
||||
def alarm():
|
||||
time.sleep(180)
|
||||
print("zzz")
|
||||
sys.exit(0)
|
||||
|
||||
threading.Thread(target=alarm, daemon=True).start()
|
||||
|
||||
while True:
|
||||
menu()
|
||||
op = input("> ").strip()
|
||||
|
||||
if op == "1":
|
||||
data = read_hex("pt: ")
|
||||
if data is None:
|
||||
print()
|
||||
continue
|
||||
out = enc_cfb(data)
|
||||
print("ct: ", out.hex())
|
||||
print()
|
||||
|
||||
elif op == "2":
|
||||
if iv11 is not None and iv22 is not None:
|
||||
iv1, iv2 = iv11, iv22
|
||||
iv11 = iv22 = None
|
||||
else:
|
||||
iv1 = os.urandom(16)
|
||||
iv2 = os.urandom(16)
|
||||
ct = enc_cbc(flag, iv1, iv2, padd=True)
|
||||
print("iv1: ", iv1.hex())
|
||||
print("iv2: ", iv2.hex())
|
||||
print("ct: ", ct.hex())
|
||||
print()
|
||||
|
||||
elif op == "3":
|
||||
if third:
|
||||
print("sheesh")
|
||||
continue
|
||||
block = read_hex("pt: ")
|
||||
if block is None:
|
||||
print()
|
||||
continue
|
||||
if len(block) != 16:
|
||||
print("hmmm\n")
|
||||
continue
|
||||
iv1 = os.urandom(16)
|
||||
iv2 = os.urandom(16)
|
||||
ct = enc_cbc(block, iv1, iv2, padd=False)
|
||||
iv11, iv22 = iv1, iv2
|
||||
print("ct: ", ct.hex())
|
||||
third = 1
|
||||
print()
|
||||
|
||||
elif op == "4":
|
||||
break
|
||||
else:
|
||||
print("mabokkkk?")
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import binascii
|
||||
import hashlib
|
||||
import threading
|
||||
import time
|
||||
import sys
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Util.Padding import pad, unpad
|
||||
|
||||
seed_bits = 23
|
||||
seed_max = 1 << seed_bits
|
||||
seed_len = (seed_bits + 7) // 8
|
||||
key = os.urandom(16)
|
||||
|
||||
def hash_seed(seed_int: int) -> bytes:
|
||||
sb = seed_int.to_bytes(seed_len, "big")
|
||||
return hashlib.sha256(sb).digest()[:16]
|
||||
|
||||
seed = int.from_bytes(os.urandom(4), "big") % seed_max
|
||||
seed2 = int.from_bytes(os.urandom(4), "big") % seed_max
|
||||
K1 = hash_seed(seed)
|
||||
K2 = hash_seed(seed2)
|
||||
|
||||
with open("./flag.txt", "rb") as f:
|
||||
flag = f.read()
|
||||
|
||||
def read_hex(prompt: str):
|
||||
s = input(prompt).strip()
|
||||
try:
|
||||
return binascii.unhexlify(s)
|
||||
except Exception:
|
||||
print("hmm")
|
||||
return None
|
||||
|
||||
def enc_cfb(pt: bytes) -> bytes:
|
||||
iv = os.urandom(16)
|
||||
aes = AES.new(key, AES.MODE_CFB, iv=iv, segment_size=128)
|
||||
ct = aes.encrypt(pt)
|
||||
return iv + ct
|
||||
|
||||
def enc_cbc(data: bytes, iv1: bytes, iv2: bytes, padd: bool) -> bytes:
|
||||
x = pad(data, 16) if padd else data
|
||||
c1 = AES.new(K1, AES.MODE_CBC, iv=iv1).encrypt(x)
|
||||
c2 = AES.new(K2, AES.MODE_CBC, iv=iv2).encrypt(c1)
|
||||
return c2
|
||||
|
||||
def menu():
|
||||
print("""
|
||||
1. encrypt
|
||||
2. profit
|
||||
3. get third
|
||||
4. exit
|
||||
""")
|
||||
|
||||
third = 0
|
||||
iv11 = None
|
||||
iv22 = None
|
||||
|
||||
def alarm():
|
||||
time.sleep(180)
|
||||
print("zzz")
|
||||
sys.exit(0)
|
||||
|
||||
threading.Thread(target=alarm, daemon=True).start()
|
||||
|
||||
while True:
|
||||
menu()
|
||||
op = input("> ").strip()
|
||||
|
||||
if op == "1":
|
||||
data = read_hex("pt: ")
|
||||
if data is None:
|
||||
print()
|
||||
continue
|
||||
out = enc_cfb(data)
|
||||
print("ct: ", out.hex())
|
||||
print()
|
||||
|
||||
elif op == "2":
|
||||
if iv11 is not None and iv22 is not None:
|
||||
iv1, iv2 = iv11, iv22
|
||||
iv11 = iv22 = None
|
||||
else:
|
||||
iv1 = os.urandom(16)
|
||||
iv2 = os.urandom(16)
|
||||
ct = enc_cbc(flag, iv1, iv2, padd=True)
|
||||
print("iv1: ", iv1.hex())
|
||||
print("iv2: ", iv2.hex())
|
||||
print("ct: ", ct.hex())
|
||||
print()
|
||||
|
||||
elif op == "3":
|
||||
if third:
|
||||
print("sheesh")
|
||||
continue
|
||||
block = read_hex("pt: ")
|
||||
if block is None:
|
||||
print()
|
||||
continue
|
||||
if len(block) != 16:
|
||||
print("hmmm\n")
|
||||
continue
|
||||
iv1 = os.urandom(16)
|
||||
iv2 = os.urandom(16)
|
||||
ct = enc_cbc(block, iv1, iv2, padd=False)
|
||||
iv11, iv22 = iv1, iv2
|
||||
print("ct: ", ct.hex())
|
||||
third = 1
|
||||
print()
|
||||
|
||||
elif op == "4":
|
||||
break
|
||||
else:
|
||||
print("mabokkkk?")
|
||||
Reference in New Issue
Block a user