반응형
설명
This level introduces the concept that memory can be accessed outside of its allocated region, how the stack variables are laid out, and that modifying outside of the allocated memory can modify program execution. |
할당된 부분 밖에서에 대한 이야기를 하는 듯 하다.
stack0.c
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char **argv)
{
volatile int modified;
char buffer[64];
modified = 0;
gets(buffer);
if(modified != 0) {
printf("you have changed the 'modified' variable\n");
} else {
printf("Try again?\n");
}
}
코드를 살펴본다.
modified가 0이 아니면 '변수를 바꿨다'
그 외의 경우는 '다시 해라'란 메시지가 나온다.
일단 이 위치에 있다고 하니 이 위치로 이동한다.
gdb로 들어가 main을 본다.
if(modified != 0)에서 modified가 0이면 "Try again?"이라는 문자가 출력된다.
그래서 buffer변수 64byte를 넘어야 함을 확인할 수 있다.
"A" 65개를 주면 버퍼가 넘쳐 modified는 "A" 기계어 0x41로 인식될 것이다.
그래서 "changed the modified variable" 문자가 잘 출력됨을 확인할 수 있다.
반응형
'system' 카테고리의 다른 글
[protostar]stack6.c (0) | 2020.11.02 |
---|---|
[protostar]stack4.c (0) | 2020.09.24 |
[protostar]stack3.c (0) | 2020.09.22 |
[protostar]stack1.c (0) | 2020.09.22 |
[protostar]stack2 (0) | 2020.09.17 |