Skip to content
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 CrewCTF2024-noisy-encryption/description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Noisy encryption
authors:
- KLPP
original_ctf: 'CrewCTF 2024'
year: 2024
description: >-
I can encrypt your messages, however, I will reveal just a little bit of information ...
base64_flag: 'Y3Jld3tEMWN0MW9uNHJ5XzR0dGFja3M/XzR0X3RoMXNfVDFtM18wZl95MzRyX0E3XzdoMTVfdGltM18wZl9kNHlfMW5fN2gxc19QNHJ0XzBmX0MwdW50cnk/fQ=='
flag_format: 'crew{FLAG}'
47 changes: 47 additions & 0 deletions CrewCTF2024-noisy-encryption/release_files/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

import secrets
import sympy

FLAG="crew{**REDACTED**}"
BITS=512
LIM=pow(2,BITS)

while True:
while (not sympy.isprime(p:=secrets.randbelow(LIM//2)+LIM//2)) or (p-1)%3==0:
pass

while (not sympy.isprime(q:=secrets.randbelow(LIM//2)+LIM//2)) or (q-1)%3==0:
pass

n=p*q
if n>pow(2,1023):
break

phi=(p-1)*(q-1)
e=3
Secret=secrets.randbelow(LIM)
d=pow(e,-1,phi)
sig=pow(Secret,d,n)

print("The signature is: "+str(sig))

def hamming_weight(x):
return sum([int(y) for y in bin(x)[2:]])


while True:
print("I can encrypt anything for you! But the bits may get messy")
msg=input()
if msg=="guess":
print("Do you know the secret?")
msg=int(input())
if msg==Secret:
print("You sure do! Here is your prize:")
print(FLAG)
exit(0)
else:
print("Wrong answer!")
exit(0)
msg=int(msg)
enc=pow(msg,3,n)
print(hamming_weight(enc)%2)
12 changes: 12 additions & 0 deletions CrewCTF2024-noisy-encryption/server_files/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.10-slim-buster
RUN apt update -y && apt install -y xinetd && apt clean && rm -rf /var/lib/apt/lists/*

RUN useradd -d /home/ctf -m ctf
USER ctf

RUN pip3 install --no-cache-dir sympy==1.13.3

COPY xinetd /etc/xinetd.d/xinetd
COPY server.py /home/ctf/server.py

CMD ["/usr/sbin/xinetd", "-dontfork"]
47 changes: 47 additions & 0 deletions CrewCTF2024-noisy-encryption/server_files/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

import secrets
import sympy

FLAG="crew{D1ct1on4ry_4ttacks?_4t_th1s_T1m3_0f_y34r_A7_7h15_tim3_0f_d4y_1n_7h1s_P4rt_0f_C0untry?}"
BITS=512
LIM=pow(2,BITS)

while True:
while (not sympy.isprime(p:=secrets.randbelow(LIM//2)+LIM//2)) or (p-1)%3==0:
pass

while (not sympy.isprime(q:=secrets.randbelow(LIM//2)+LIM//2)) or (q-1)%3==0:
pass

n=p*q
if n>pow(2,1023):
break

phi=(p-1)*(q-1)
e=3
Secret=secrets.randbelow(LIM)
d=pow(e,-1,phi)
sig=pow(Secret,d,n)

print("The signature is: "+str(sig))

def hamming_weight(x):
return sum([int(y) for y in bin(x)[2:]])


while True:
print("I can encrypt anything for you! But the bits may get messy")
msg=input()
if msg=="guess":
print("Do you know the secret?")
msg=int(input())
if msg==Secret:
print("You sure do! Here is your prize:")
print(FLAG)
exit(0)
else:
print("Wrong answer!")
exit(0)
msg=int(msg)
enc=pow(msg,3,n)
print(hamming_weight(enc)%2)
19 changes: 19 additions & 0 deletions CrewCTF2024-noisy-encryption/server_files/xinetd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
service ctf
{
disable = no
type = UNLISTED
wait = no
server = /usr/local/bin/python3
server_args = /home/ctf/server.py
socket_type = stream
protocol = tcp
user = ctf
bind = 0.0.0.0
port = 1337
flags = REUSE
per_source = 2
rlimit_cpu = 30
log_type = FILE /home/ctf/log
log_on_success = HOST PID EXIT DURATION
log_on_failer = HOST
}