Homework (Smart Home, 300p)

Help your brother Billy with his homework.
He has been complaining that it is too difficult.
Solve the homework to reveal the answer in flag.txt
Homework

solution

Archive contains two files, encrypted flag.txt and binary math.exe.

root@env259.kali05:~# 7z l -ba homework.zip
2022-09-08 10:55:51 .....           96          101  flag.txt
2022-09-08 10:55:51 .....        14472         2591  math.exe

Binary is a ELF (Linux) binary.

# file math.exe
math.exe: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=b6d0a4d839f0c04ae3bcbda532a2ed6699e66c5e, for GNU/Linux 3.2.0, stripped

Running the binary doesn't lead to anything useful, therefore reverse engineering must be done.

Reversing the binary reveals that there is an AES key and IV, which is xored (fnc.00001209) with value AES.

# r2 -A math.exe
(..)
[0x00001120]> pdf @ main
            ; DATA XREF from entry0 @ 0x1141
┌ 576: int main (int argc, char **argv, char **envp);
(..)
│           0x0000129a      c745ac414553.  mov dword [var_54h], 0x534541 ; 'AES'
│           0x000012a1      48b870701275.  movabs rax, 0x3726a7c75127070
│           0x000012ab      48ba17797210.  movabs rdx, 0x4657c7710727917
│           0x000012b5      488945b0       mov qword [var_50h], rax
│           0x000012b9      488955b8       mov qword [var_48h], rdx
│           0x000012bd      48b873107177.  movabs rax, 0x6672051577711073
│           0x000012c7      48ba71016779.  movabs rdx, 0x102177d79670171
│           0x000012d1      488945c0       mov qword [var_40h], rax
│           0x000012d5      488955c8       mov qword [var_38h], rdx
│           0x000012d9      48b869727460.  movabs rax, 0x7260767360747269 ; 'irt`sv`r'
│           0x000012e3      48ba71607476.  movabs rdx, 0x6072726576746071 ; 'q`tverr`'
│           0x000012ed      488945d0       mov qword [var_30h], rax
│           0x000012f1      488955d8       mov qword [var_28h], rdx
│           0x000012f5      48b879766a72.  movabs rax, 0x76706075726a7679 ; 'yvjru`pv'
│           0x000012ff      48ba61727660.  movabs rdx, 0x7266767560767261 ; 'arv`uvfr'
│           0x00001309      488945e0       mov qword [var_20h], rax
│           0x0000130d      488955e8       mov qword [var_18h], rdx
│           0x00001311      66c745f07300   mov word [var_10h], 0x73    ; 's'
(..)
│      │╎   0x0000146b      e899fdffff     call fcn.00001209

Xor-ing values gives AES key as 15A4993FD87C696E6C02FD750D488DCD and IV as 3132333435363738393031323334353.

#!/usr/bin/env python3
from itertools import cycle
from operator import xor
key = bytes.fromhex('534541')[::-1]
msg = b''
for x in ['03726a7c75127070', '04657c7710727917', '6672051577711073','0102177d79670171','7260767360747269','6072726576746071','76706075726a7679','7266767560767261', '73']:
        msg += bytes.fromhex(x)[::-1]
xored = bytes(map(xor, msg, cycle(key)))
print(xored.decode())
# python3 xor.py
15A4993FD87C696E6C02FD750D488DCD:31323334353637383930313233343536

Decrypt the flag.

#!/usr/bin/env python3
import io
from Crypto.Cipher import AES

key = bytes.fromhex('15A4993FD87C696E6C02FD750D488DCD')
iv = bytes.fromhex('31323334353637383930313233343536')

with io.open('flag.txt', 'rb') as fp:
        ct = fp.read()
cipher = AES.new(key, AES.MODE_CBC, iv)
pt = cipher.decrypt(ct).strip()
print(pt.decode())
# python3 dec.py
The flag is ctftech{ec54a12e40b69f4e90a9e91217851c3534ee17e14415995d7202e6518cb1529b}

Flag is ctftech{ec54a12e40b69f4e90a9e91217851c3534ee17e14415995d7202e6518cb1529b}.


Buy Me A Coffee