This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
generated from BCACTF/chall-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* challenge * dockerfile * better solvepath Co-authored by: glacialcascade <[email protected]> * fix deploy * change solution (#73) --------- Co-authored-by: glacialcascade <[email protected]>
- Loading branch information
1 parent
fe2340a
commit e05e507
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM --platform=linux/amd64 ubuntu:20.04 AS build | ||
|
||
RUN apt-get update -y && apt-get install -y gcc wget unzip && rm -rf /var/lib/apt/lists/* | ||
|
||
RUN wget -Oynetd.c https://raw.githubusercontent.com/johnsonjh/ynetd/master/ynetd.c \ | ||
&& gcc -o ynetd ynetd.c \ | ||
&& rm -f /tmp/ynetd.zip | ||
|
||
FROM --platform=linux/amd64 python:3.12-slim-bookworm | ||
|
||
RUN useradd -m -d /home/ctf -u 12345 ctf | ||
WORKDIR /home/ctf | ||
|
||
COPY server.py ./ | ||
COPY requirements.txt ./ | ||
COPY flag.txt ./ | ||
|
||
COPY --from=build ynetd ynetd | ||
RUN chmod +x ynetd | ||
|
||
RUN chown -R root:root /home/ctf | ||
RUN pip install -r requirements.txt | ||
|
||
USER ctf | ||
EXPOSE 3000 | ||
CMD ["./ynetd", "-p", "3000", "python3 server.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Encryptor Shop | ||
categories: | ||
- crypto | ||
value: 50 | ||
flag: | ||
file: ./flag.txt | ||
description: |- | ||
After realizing how insecure the systems of many companies are (they're | ||
always getting hacked), I decided to start offering Encryption as a | ||
Service (EaaS). With such a strong guarantee of security, I'll even | ||
give you the source code AND my encrypted super secret flag. | ||
hints: [] | ||
files: | ||
- src: ./server.py | ||
authors: | ||
- Mudasir | ||
deploy: | ||
nc: | ||
build: . | ||
expose: 5000/tcp | ||
visible: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bcactf{w0w_@lg3br@_d3in48uth934r} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pycryptodome==3.20.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from Crypto.Util.number import * | ||
|
||
p = getPrime(1024) | ||
q = getPrime(1024) | ||
r = getPrime(1024) | ||
n = p * q | ||
phi = (p - 1) * (q - 1) | ||
e = 65537 | ||
d = pow(e, -1, phi) | ||
|
||
print("Welcome to the enc-shop!") | ||
print("What can I encrypt for you today?") | ||
|
||
|
||
for _ in range(3): | ||
message = input("Enter text to encrypt: ") | ||
m = bytes_to_long(message.encode()) | ||
c = pow(m, e, n) | ||
print(f"Here is your encrypted message: {c}") | ||
print(f"c = {c}") | ||
print("Here is the public key for your reference:") | ||
print(f"n = {n}") | ||
print(f"e = {e}") | ||
|
||
print("Thank you for encrypting with us!") | ||
print("In order to guarantee the security of your data, we will now let you view the encrypted flag.") | ||
x=input("Would you like to view it? (yes or no) ") | ||
|
||
if x.lower() == "yes": | ||
with open("flag.txt", "r") as f: | ||
flag = f.read().strip() | ||
m = bytes_to_long(flag.encode()) | ||
n = p*r | ||
c = pow(m, e, n) | ||
print(f"Here is the encrypted flag: {c}") | ||
print("Here is the public key for your reference:") | ||
print(f"n = {n}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/sage | ||
from Crypto.Util.number import long_to_bytes | ||
|
||
# sample values | ||
n = 25672717426820513710943205839364483916462804218548801569145802652630577782900538695973744861105496729905627921059008367561569523305960463813216527736798326653292438086191944762789172647312900551902461060352376019547331143616013304184614930906004171476480510470587909456774815137176855734430612064982542863659570395295482686120891117968898216622206615854128611416469340618239366172641009539517658878551692132791618016300846596344387852192596993173217855138296633962850557028630352495932230646527202752234601562497215822764663650767710458962369922520233739420580532819716680556394145993527683129009216404336549252330091 | ||
e = 65537 | ||
flag = 1083625496779970264419136305221671016117829663020044050146555349899787834011590086920869802111023991613821066623716559972755949113701501874048562224439274720251945134284083684492761219205132838372764452677281768274305372099912532025957284473071373317196230163363640098605346443685525909370527747332955548675206412274584950839734716346547094425347696118475715583261416077609393966266153722274187119120682987915292966511175589928588362998907734884276112744211599285641171140402681639667044788628645470007439249161157400845406659256582870356000464445445478989477502854810644166856995360456670068896815610415108264478323 | ||
n2 = 27368115041311256275227024917950858454235788667021073198311116355186647544767717811973935453582324380335430354834788466153181148557334562671645375401434653132878379082952166788670952485522953276925557458943115441308780807836250927064634092981175701891508525682899992903672949137706472233445943878804298329629278526495430527687968010293979124319259469576481820335370026921880073228386101660016332613679667679937345493922150203642222273091669777337735254184786282363582190082715868568569189222774625804615657773286270123197871252891782578640230520633961840128629257859130644151809317074356832564646866829943858656213303 | ||
|
||
# n and n2 share a factor p, so we can efficiently | ||
# find p using gcd (euclidean algorithm) | ||
|
||
p = gcd(n, n2) | ||
r = n2 // p | ||
|
||
d = pow(e, -1, (p-1)*(r-1)) | ||
flag = pow(flag, d, n2) | ||
print(long_to_bytes(flag)) |