This page looks best with JavaScript enabled

Red Team Village CTF solutions

Solutions to some programming challenges in Defcon29

 ·  ☕ 4 min read

3 different Pawning boxes where you have to read the questions and act upon them.

crypto_morse.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from pwn import *  # pip install pwntools

CODE = {'A': '.-', 'B': '-...', 'C': '-.-.',
        'D': '-..', 'E': '.', 'F': '..-.',
        'G': '--.', 'H': '....', 'I': '..',
        'J': '.---', 'K': '-.-', 'L': '.-..',
        'M': '--', 'N': '-.', 'O': '---',
        'P': '.--.', 'Q': '--.-', 'R': '.-.',
        'S': '...', 'T': '-', 'U': '..-',
        'V': '...-', 'W': '.--', 'X': '-..-',
        'Y': '-.--', 'Z': '--..',

        '0': '-----', '1': '.----', '2': '..---',
        '3': '...--', '4': '....-', '5': '.....',
        '6': '-....', '7': '--...', '8': '---..',
        '9': '----.',

        ' ': ' ',

        ', ': '--..--', '.': '.-.-.-',
        '?': '..--..', '/': '-..-.', '-': '-....-',
        '(': '-.--.', ')': '-.--.-'
        }

CODE_REVERSED = {value: key for key, value in CODE.items()}


def to_morse(s):
    return ' '.join(CODE.get(i.upper()) for i in s)


def from_morse(s):
    return ''.join(CODE_REVERSED.get(i) for i in s.split())


r = remote('159.203.98.188', 2345)


def recv():
    while True:
        _s = r.recv().decode()
        if _s == '\n':
            return None
        print(from_morse(_s), end=" ")


def send(hsh):
    req = to_morse(hsh)
    print(req)
    r.sendline(req.encode())


if __name__ == '__main__':
    print(to_morse('y'))
    recv()
    send('Y')
    recv()
    send('1838')
    recv()
    send('CQD')
    recv()

# TELEGRAPH PUT IT IN BRACES THEN  PUT THE  LETTERS TS AT  THE  BE G I N I NG  O F I T  BE F O R E T H E B R A E S [*] Closed connection to 159.203.98.188 port 2345

auto_calc.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from pwn import *  # pip install pwntools

r = remote('auto.threatsims.com', 4224)

PI = 3.14

questions = 0


def Get():
    return r.recvline(timeout=5).decode()


def json_recv():
    global questions
    if questions == 1000 + 1:
        print(r.recvuntil("}"))

    red = Get()
    while red != "":
        print(red)
        if red[0] == "Q":
            questions = questions + 1
        red = Get()
        if "Find" in red:
            return red


def json_send(hsh):
    r.sendline(str(hsh).encode())


def Find(x: str):
    print(x)
    val = int(x.split(" ")[-1].strip())
    res = -1
    if "Find the Volume of A Semi-Sphere with a Radius" in x:
        res = 2 * PI * val * val * val / 3
    if "Find the Area of A Square with a Side Length of" in x:
        res = val * val
    if "Find the Volume of A Sphere with a Radius of" in x:
        res = 4 * PI * val * val * val / 3
    if "Find the Area of A Circle with a Radius" in x:
        res = PI * val * val
    if "Find the Area of A Semi-Circle with a Radius" in x:
        res = PI * val * val / 2
    if "Find the Volume of A Cube with a Side Length" in x:
        res = val * val * val
    return round(res)


if __name__ == '__main__':

    received = json_recv()

    while True:
        _res = Find(received)
        print(_res)
        json_send(_res)
        received = json_recv()

auto_office.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from pwn import *  # pip install pwntools

r = remote('auto.threatsims.com', 5225)


def json_send(hsh):
    print(hsh)
    r.sendline(str(hsh).encode())


def Get():
    return r.recvline(timeout=10).decode()


def askMemo():
    memo = ""
    for _ in range(6):
        red = Get()
        print(red)
        if red[0:4] != "Spam":
            memo = red.split(":")[1].strip()
    json_send(memo)


def askSum():
    red = Get()
    nums = map(int, red.split("+")[:-1])
    res = int(red.split("=")[1])
    res = res - sum(nums)
    json_send(str(res))


def askTax():
    tax = float(Get().split(":")[1].strip())
    earnings = float(Get().split(":")[1].strip())
    json_send(str(round(earnings * tax)))


def askWork():
    hoursWorked = float(Get().split(":")[1].strip())
    rate = float(Get().split(":")[1].strip())
    overtime = float(Get().split(":")[1].strip())
    json_send(str(round(hoursWorked * rate + overtime * rate / 2)))


def json_recv():
    red = Get()
    cnt = 0
    while red != "":
        print(red)
        red = Get()
        if "Can you tell me what the memo is through all this spam?" in red:
            cnt = cnt + 1
            askMemo()
        elif "Can you tell me how much we are missing in this book?" in red:
            cnt = cnt + 1
            askSum()
        elif "Can you tell me how much we owe in taxes this year?" in red:
            cnt = cnt + 1
            askTax()
        elif "Can you write a check for this employee?" in red:
            cnt = cnt + 1
            askWork()
        print(cnt)
        if cnt == 1001:
            print(r.recvuntil("}"))


if __name__ == '__main__':
    for _ in range(10):
        Get()
    json_recv()

Share on
Support the author with

Rishabhdeep Singh
WRITTEN BY
Rishabhdeep Singh
CTF Player | Algorithmist | Learner