[드림핵] cmd_center
A A

문제: https://dreamhack.io/wargame/challenges/117

 

cmd_center

Description IP를 확인할 필요가 없습니다! 혹시 다른 명령어는 못쓰나요? 다른 명령어를 사용했다면 플래그를 획득하세요! References https://dreamhack.io/learn/2/1#3 https://dreamhack.io/learn/2/14#3

dreamhack.io

 

 

📍 소스코드

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

void init() {
	setvbuf(stdin, 0, 2, 0);
	setvbuf(stdout, 0, 2, 0);
}

int main()
{

	char cmd_ip[256] = "ifconfig";
	int dummy;
	char center_name[24];

	init();

	printf("Center name: ");
	read(0, center_name, 100);


	if( !strncmp(cmd_ip, "ifconfig", 8)) {
		system(cmd_ip);
	}

	else {
		printf("Something is wrong!\n");
	}
	exit(0);
}

 

1. 사용자의 입력값 100바이트를 center_name에 저장

2. "ifconfig"로 초기화한 cmd_ip의 처음 8바이트와 "ifconfig" 문자열을 비교

3. 같으면 시스템 권한으로 cmd_ip를 실행

 

Command Injection 취약점을 활용하는 문제이다.

 

center_name과 cmd_ip의 메모리상 위치를 확인해 보고, 둘이 붙어 있으면 오버플로우를 시도해 볼 수 있을 것 같다.

 

명령어를 실행하기 위해서는, if문에서 cmd_ip의 처음 8바이트와 "ifconfig"가 같아야 하므로

"ifconfig;cat flag"
이런 식으로 overflow를 시도해 보자.



 

 

center_name => rbp-0x130

cmd_ip => rbp-0x110

 

그러면 0x20 = 32바이트만큼 차이가 난다.

center_name의 처음 32바이트는 더미 값으로 채우고, 그 다음 8바이트는 "ifconfig"로, 그 다음은 ";cat flag"로 채워 보자.

 

 

 

🚩

EZ

Copyright 2024. GRAVITY all rights reserved