Skip to content

Latest commit

 

History

History
70 lines (47 loc) · 1.93 KB

README.md

File metadata and controls

70 lines (47 loc) · 1.93 KB

Greetings

  • Category: crypto
  • Challenge author: Björn Österman

Description

Do you want it wrapped?

Connection info

nc 2021.santahack.xyz 42003

Writeup

This challenge can be solved with the insight that the IV and Key is reused for every message. By starting out by almost filling up a 16-byte segment (ie with 15 chars) and letting the oracle (ie the script running on the server) adding the 16:th character you can then try the same thing for every printable character until you find the same crypto-bytes. Then iterating one character at the time until you get the whole flag.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from pwn import *

io = remote("2021.santahack.xyz", 42003)

buflen = 48
flag = b''


def split_print(msg, end='\n'):
    print(msg[:16] + ' ' + msg[16:32] + ' ' + msg[32:], end=end)


def encrypt(x):
    io.sendlineafter(b"?", x)
    io.recvuntil(b"flag:\n")
    return io.recvline()[:buflen*2]


while not flag[-1:] == b'}':
    text = b'.' * (buflen - len(flag) - 1)
    correct = encrypt(text)
    msg = (text + flag + b'?').decode()
    split_print(msg + ' -> ' + correct[64:72].hex() + '... - Searching...')
    split_print(msg[:47] + ' '*24, '')

    for c in [bytes([ord(x)]) for x in string.printable]:
        check = encrypt(text + flag + c)

        print('\b'*24, end='')
        print(c.decode() + ' -> ' + check[64:72].hex() + '...', end='')

        if check == correct:
            flag += c
            print(" - Found!\n")
            break

print('\n')

Existing writeups