slide-image

LOB

[the Lord Of Buffer overflow]

#17 : zombie_assassin->succubus

 

오랜만에 글을 쓰는 것 같다.

...더보기

일단 succubus를 temp로 복사해줬다.

 

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

 

일단 addr가 바뀌면 안되고, count 때문에 함수 도에서 개 걸 윷 모로 이동해야 한다.

 

함수를 호출할 때에 (CALL) push EIP, jmp ~~로 이루어지는데, push EIP가 리턴 어드레스가 된다. 따라서 DO의 리턴 어드레스가 48에 들어가게 된다.

우리는 DO에서 main으로 돌아가지 않고, GYE로 돌아가고 싶으니까, 이 부분에 GYE의 어드레스를 넣고, 마찬가지로 GYE의 RET를 변조하기 위해서 GUL의 어드레스를 52(인덱스)에 넣고, YUT은 56인덱스에 넣고, MO는 60인덱스에 넣는다. 

 

그 후 MO의 cmd 인자도 변조해야 한다. /bin/sh를 넣어주면 system함수에 의해서 쉘이 실행될 것이다.

system함수 직전에 참고하는 값은 ebp+8의 [값]이므로, MO의 어드레스를 넣고 난 후의 8바이트 자리에 /bin/sh의 주소값을 넣어준다. 

 

일단 gdb 하였다. gdb로 인자를 아까 말한 것처럼 도 개 걸 윷 모의 함수 어드레스를 넣은 후에, 8바이트 자리에 /bin/sh의 주소값이 있어야 하므로, 4바이트의 더미값과 주소값, /bin/sh의 문자열을 주었다. 

사실 주소값은 임의로 준 것이고, 디버깅할 것이다. 

 

주소값이 78임을 알 수 있다. (내가 준 값이 74에 있으므로)

 

근데 안되길래.. 코어덤프 해보았다. 

덤프 해보니 68로 바뀐 것을 알 수 있었다.

다시 해보았는데, 되길래 원본 파일에 하려고 한다.

 

성공



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

[LOB] nightmare->xavius  (0) 2019.07.05
[LOB] succubus->nightmare  (0) 2019.07.03
[LOB] assassin->zombie_assassin  (0) 2019.04.01
[LOB] gaint->assassin  (0) 2019.03.31
[LOB] bugbear->giant  (0) 2019.03.29