slide-image

 

LOB

[the Lord Of Buffer overflow]

#19 : nightmare->xavius

 

일단 복사해주었고, cat xavius.c 한 결과는 이렇다.

/*
        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);
}

코드는 사실 별 거 없다. 리턴 어드레스로 bf(스택)와 08(코드영역)을 쓰지말고, 라이브러리 영역도 막고 있다.

근데 막는 방법이 조금 이상하다. 44부분부터 주소가 \x90\x90이 아니면서 값이 c9c3이면 종료시키고 아니라면 값을 증가시킨다. (사실 뭘 우회하려고 하는지도 잘 모르겠다.)

그리고 스택의 RET을 남겨놓은 모든 부분을 0으로 초기화하고, LD_환경변수들도 막기 위해서 3000부터 40바이트를 남겨놓고(memset function을 위해서) 모두 0으로 초기화 한다.

 

 

'Wargame > LOB(Redhat)' 카테고리의 다른 글

[LOB] xavius->death_knight  (0) 2019.07.08
[LOB] succubus->nightmare  (0) 2019.07.03
[LOB] zombie_assassin->succubus  (0) 2019.07.01
[LOB] assassin->zombie_assassin  (0) 2019.04.01
[LOB] gaint->assassin  (0) 2019.03.31