둘둘리둘둘리둘둘리둘둘리둘둘리둘

[Hacker school FTZ] Level16 -> Level17 본문

War game/해커 스쿨 FTZ

[Hacker school FTZ] Level16 -> Level17

dool2ly 2015. 8. 20. 19:42

#include <stdio.h>


void shell() {

  setreuid(3097,3097);

  system("/bin/sh");

}


void printit() {

  printf("Hello there!\n");

}


main()

{ int crap;

  void (*call)()=printit;

  char buf[20];

  fgets(buf,48,stdin);

  call();

}



shell함수와 printit함수가 정의되어 있고

아래와 같이 동작한다.

1. 변수 call에 printit함수의 주소값을 넣는다.

2. 크기 20byte인 buf에 stdin으로부터 최대 48byte까지 입력받는다.

3. call을 호출한다.

call을 호출할때 printit이 아니라 shell이 호출되게 하면 된다.


함수 printit의 주소와 shell의 주소는 아래와 같다






[그림 1]


[그림 1]을 보면 ebp-16에 printit함수의 주소를 저장하고 마지막에 call eax로 ebp-16이 가진 주소를 호출한다.

그러므로 buf에 56-16 = 40byte의 더미와 함수 shell의 주소를 입력하면 printit이 아니라 shell함수가 호출 될 것이다.


페이로드 : [ 더미(40) | 함수 shell의 주소 ]



--풀이--


Comments