Pwnstar

Pwnable.kr fix 본문

Pwnable.kr/Rookiss

Pwnable.kr fix

포너블처돌이 2020. 7. 28. 16:40

 

fix라는 문제이다. 

 

mitigation은 하나도 걸려있지 않다.

 

소스코드

#include <stdio.h>

// 23byte shellcode from http://shell-storm.org/shellcode/files/shellcode-827.php
char sc[] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69"
		"\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80";

void shellcode(){
	// a buffer we are about to exploit!
	char buf[20];

	// prepare shellcode on executable stack!
	strcpy(buf, sc);

	// overwrite return address!
	*(int*)(buf+32) = buf;

	printf("get shell\n");
}

int main(){
        printf("What the hell is wrong with my shellcode??????\n");
        printf("I just copied and pasted it from shell-storm.org :(\n");
        printf("Can you fix it for me?\n");

	unsigned int index=0;
	printf("Tell me the byte index to be fixed : ");
	scanf("%d", &index);
	fflush(stdin);

	if(index > 22)	return 0;

	int fix=0;
	printf("Tell me the value to be patched : ");
	scanf("%d", &fix);

	// patching my shellcode
	sc[index] = fix;	

	// this should work..
	shellcode();
	return 0;
}

 

이렇게 되어 있는데, 쉘코드에서 틀린 부분을 고치라는 것 같다. 그래서 

https://defuse.ca/online-x86-assembler.htm

 

Online x86 and x64 Intel Instruction Assembler

Online x86 / x64 Assembler and Disassembler This tool takes x86 or x64 assembly instructions and converts them to their binary representation (machine code). It can also go the other way, taking a hexadecimal string of machine code and transforming it into

defuse.ca

 

이 사이트에 코드를 넣어보고 분석해봤는데, 

 

 

이렇게 보면 뭐가 이상한지 잘 모르겠다...

 

디버깅을 해보니 push eax를 하기 전

 

push eax를 한 이후

 

 

이렇게 보니 문제점이 보였다. 쉘코드 부분을 다시 스택으로 쓰면서 쉘코드가 다른 값으로 덮였다.

 

이 부분을 해결해주려고, 스택의 주소를 제한이 없게 만들어줬다. ulimit -s unlimited 그래도 이 부분에서 똑같은 에러가 발생했는데, 처음 문제를 풀 때 브루트 포싱으로 해결했다...ㅋㅋ;;

 

우선 push eax부터 문제가 생기는 것은 확인했으니, 15번째 바이트를 다른 값으로 바꿔주면 될 것이라고 생각하고 0~255까지 반복문을 돌려 보았다.

 

이렇게 문제를 풀긴 했는데 왜 이렇게 되는지 정확한 동작이 궁금했다. 15번째 바이트를 92(pop esp)로 바꾸어줬는데, 이때의 스택 주소는 이렇게 변해 있었다.

 

 

스택의 주소에 제한이 없어져 0x6e69622b같은 괴랄한 주소도 스택으로 활용이 되는 것이었다.

 

다른 방법도 있지 않을까 생각해 봤는데, 한 바이트만 값을 바꿔야 하는 상황에서 별다른 선택지가 없는 것 같다ㅋㅋ;

 

 

아무튼 끗

'Pwnable.kr > Rookiss' 카테고리의 다른 글

Pwnable.kr echo2  (0) 2020.07.28
Pwnable.kr echo1  (0) 2020.07.28
Pwnable.kr otp  (0) 2020.07.28
Pwnable.kr syscall  (0) 2020.07.22
Pwnable.kr fsb  (0) 2020.06.25
Comments