보안_기타/ftz
ftz level13
정지홍
2024. 8. 8. 18:09
Level13 Password is "have no clue".
[level13@ftz level13]$ cat hint
#include <stdlib.h>
main(int argc, char *argv[])
{
long i=0x1234567;
char buf[1024];
setreuid( 3094, 3094 );
if(argc > 1)
strcpy(buf,argv[1]);
if(i != 0x1234567) {
printf(" Warnning: Buffer Overflow !!! \n");
kill(0,11);
}
}

(gdb) disas main
Dump of assembler code for function main:
0x080484a0 <main+0>: push ebp # 원래의 base pointer값을 stack에 push. main함수 실행시 처음부분을 지정한다.
0x080484a1 <main+1>: mov ebp,esp # ebp의 주소값을 esp에 넣는다. 새로운 스택 프레임이 시작됨.
0x080484a3 <main+3>: sub esp,0x418 # esp를 0x418(1048byte)만큼 감소시킴.
0x080484a9 <main+9>: mov DWORD PTR [ebp-12],0x1234567 # ebp-12의 memory에 0x12345657값을 저장
0x080484b0 <main+16>: sub esp,0x8 # 그리고 0x8(8byte)만큼 감소 시킴
0x080484b3 <main+19>: push 0xc16 # 0xc16(3094)를 push
0x080484b8 <main+24>: push 0xc16 # 한번 더 push
0x080484bd <main+29>: call 0x8048370 <setreuid> #setreuid(3094,3094)를 호출해서 user ID설정
0x080484c2 <main+34>: add esp,0x10 # 0x10(16byte)만큼 증가시킴. 매개변수 정리
0x080484c5 <main+37>: cmp DWORD PTR [ebp+8],0x1 # epb+8에 있는 값과 0x1를 compare한다.
0x080484c9 <main+41>: jle 0x80484e5 <main+69> # argc>1을 만족 못할시 if문에 안들어감. 그리고 main+69로 점프
0x080484cb <main+43>: sub esp,0x8 # esp의 값을 0x8만큼 감소
0x080484ce <main+46>: mov eax,DWORD PTR [ebp+12] # eax에 ebp+12값을 넣는다
0x080484d1 <main+49>: add eax,0x4 # eax값을 4byte증가 시켜 argv[1]을 가르키게 함
0x080484d4 <main+52>: push DWORD PTR [eax] # eax가 가르키는 값을 stack에 push
0x080484d6 <main+54>: lea eax,[ebp-1048] # eax에 ebp-1048주소를 로드한다. 이는 buf값
0x080484dc <main+60>: push eax # eax값 push
0x080484dd <main+61>: call 0x8048390 <strcpy> # 함수호출
0x080484e2 <main+66>: add esp,0x10 # 16byte 매개변수 정리
0x080484e5 <main+69>: cmp DWORD PTR [ebp-12],0x1234567 # ebp-12의 값과 0x1234567을 비교
0x080484ec <main+76>: je 0x804850d <main+109> # 결과값이 같다면 main+109로 점프
0x080484ee <main+78>: sub esp,0xc # 12byte감소
0x080484f1 <main+81>: push 0x80485a0 # 해당주소를 push하며 이는 문자열 주소일것임
0x080484f6 <main+86>: call 0x8048360 <printf> # 함수호출
0x080484fb <main+91>: add esp,0x10 # 매개변수 정리
0x080484fe <main+94>: sub esp,0x8 # stack point를 8byte감소
0x08048501 <main+97>: push 0xb # 11 push
0x08048503 <main+99>: push 0x0 # 0 push
0x08048505 <main+101>: call 0x8048380 <kill> # kill(0,11)호출. 0은 현재 ps와 같은 ps group에 속하는 대상으로 하는것
0x0804850a <main+106>: add esp,0x10 # 정리 # 11은 SIGSEGV이며 segmentation fault 시그널을 의미
0x0804850d <main+109>: leave # leave명령어로 이전의 ebp값 복귀하고 esp를 ebp로 설정
0x0804850e <main+110>: ret # 함수 호출에서 복귀
0x0804850f <main+111>: nop
End of assembler dump.


[level13@ftz tmp]$ cat test.c
#include <stdio.h>
int main(){
printf("%p\n",getenv("env"));
return 0;
}
