Dreamhack/Dreamhack Wargame (Challenge)

[26] IT 비전공자 [dreamhack] baby-bof문제 풀기

imaginefuture-1 2024. 10. 6. 08:05

 https://mnzy.tistory.com/m/203

 

[Dreamhack] beginner: baby-bof

1. 문제 https://dreamhack.io/wargame/challenges/974 baby-bofDescription Simple pwnable 101 challenge Q. What is Return Address? Q. Explain that why BOF is dangerous.dreamhack.io Q. What is Return Address?Q. Explain that why BOF is dangerous.2. 풀이

mnzy.tistory.com

어제 dayoff하고 오늘 25번째 문제 풀이 시작!

 

 

BoF란? BoF(버퍼 오버플로) 공격은 프로그램이 고정 크기 메모리 버퍼에 원래 보관하도록 설계된 것보다 더 많은 데이터를 쓸 때 발생하는 보안 취약점입니다.

 

 

메모리량을 확인해야할 것 같은데...

는 해설 봐도 이해가 안감...너는 나중에 c언어 더 공부하고 풀러온다 ㅠㅜ


2024-10-22 

Buffer Over Flow

  • 프로그램이 특정 크기의 메모리 버퍼를 넘어서 데이터를 쓸 때 발생
  • 취약점은 공격자가 악의적인 코드를 실행하거나 시스템의 동작을 변조하는 데 이용가능

풀러왔다

 

❘ 7ffc5ac98f10 ❘ 7ffc5ac98f18 ❘ 에 입력한 데이터가 stack 안에 저장 a=아스키코드로 61
stack 값을 win 함수 주소 값으로 대체

 

 

소스코드

 

// gcc -o baby-bof baby-bof.c -fno-stack-protector -no-pie
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>

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

void win () 
{
  char flag[100] = {0,};
  int fd;
  puts ("You mustn't be here! It's a vulnerability!");

  fd = open ("./flag", O_RDONLY);
  read(fd, flag, 0x60);
  puts(flag);
  exit(0);
}

long count;
long value;
long idx = 0;
int main ()
{
  char name[16];

  // don't care this init function
  proc_init (); 

  printf ("the main function doesn't call win function (0x%lx)!\n", win);

  printf ("name: ");
  scanf ("%15s", name);

  printf ("GM GA GE GV %s!!\n: ", name);

  printf ("|  addr\t\t|  value\t\t|\n");
  for (idx = 0; idx < 0x10; idx++) {
    printf ("|  %lx\t|  %16lx\t|\n", name + idx *8, *(long*)(name + idx*8));
  }

  printf ("hex value: ");
  scanf ("%lx%c", &value);

  printf ("integer count: ");
  scanf ("%d%c", &count);


  for (idx = 0; idx < count; idx++) {
    *(long*)(name+idx*8) = value;
  }

  
  printf ("|  addr\t\t|  value\t\t|\n");
  for (idx = 0; idx < 0x10; idx++) {
    printf ("|  %lx\t|  %16lx\t|\n", name + idx *8, *(long*)(name + idx*8));
  }

  return 0;
}

https://hackinguko.tistory.com/m/135

 

[PWN] dreamhack - baby-bof

dreamhack begginer baby-bof 챌린지 writeup// gcc -o baby-bof baby-bof.c -fno-stack-protector -no-pie#include #include #include #include #include #include #include void proc_init (){ setvbuf (stdin, 0, 2, 0); setvbuf (stdout, 0, 2, 0); setvbuf (stderr, 0

hackinguko.tistory.com

https://velog.io/@chlqls/CTF07

 

💫[Dreamhack] baby-bof

baby-bof

velog.io

https://ah-rok.tistory.com/48

 

[Dream Hack - Pwnable] baby-bof

Buffer Over Flow 프로그램이 특정 크기의 메모리 버퍼를 넘어서 데이터를 쓸 때 발생 취약점은 공격자가 악의적인 코드를 실행하거나 시스템의 동작을 변조하는 데 이용가능 풀이방법 1. name을 입력

ah-rok.tistory.com

flag가 반환되는 win함수가 제공되어서 해당 함수로 flag를 출력시키면 풀리는 간단한 bof 문제다.
win함수의 주소는 문제를 실행시키면 출력되어있다.
따라서 실행 시 얻은 win 함수의 주소를 ret할 주소로 지정해주면 된다.

출처 ㅣ https://hackinguko.tistory.com/m/135
Q. What is Return Address?
즉 main 함수의 리턴 주소를 변조하여 원하는 임의의 주소로 이동하도록 변조한 것이다. 
Q. Explain that why BOF is dangerous. 
이렇게 bof 취약점은 임의의 함수를 마음대로 실행할 수 있도록 하기 때문에 매우 위험한 취약점이다. 
출처 ㅣ https://mnzy.tistory.com/m/203