Skip to content

Commit

Permalink
✨ encrypt tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
cairoeth committed Mar 16, 2024
1 parent cc03a25 commit 9282ad2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions paradigmctf.py/ctf_launchers/team_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
from typing import Optional

import requests
from cryptography.fernet import Fernet

def encrypt(message: bytes, key: bytes) -> bytes:
return Fernet(key).encrypt(message)

def decrypt(token: bytes, key: bytes) -> bytes:
return Fernet(key).decrypt(token)


class TeamProvider(abc.ABC):
Expand All @@ -25,11 +32,9 @@ def __init__(self, challenge_id):
def get_team(self):
ticket = self.__check_ticket(input("ticket? "))
if not ticket:
print("invalid ticket!")
return None

if ticket.challenge_id != self.__challenge_id:
print("invalid ticket!")
return None

return ticket.team_id
Expand All @@ -38,7 +43,10 @@ def __check_ticket(self, ticket: str) -> Ticket:
std_base64chars = "0123456789"
custom = "0629851743"

x = str(ticket).translate(str(ticket).maketrans(custom, std_base64chars))
key = b'G69S2TR9MBg3NI9FTGzAfJh3xn549mswWtL6fB66m2Q='
decrypted = decrypt(ticket, key).decode()

x = decrypted.translate(str(ticket).maketrans(custom, std_base64chars))
decoded = base64.b64decode(x).decode().split(',')
chall = decoded[0]
id = decoded[1]
Expand Down

0 comments on commit 9282ad2

Please sign in to comment.