본문 바로가기
알고리즘/이론

reverse 1

by 유이얼 2022. 9. 6.
#include <stdio.h>
#include <Windows.h>


char code1[] = { "\x55\x8b\xec\x83\xec\x48\xc7\x45\xf4\x63\x61\x6c\x63\xc7\x45\xf8"
	"\x00\x00\x00\x00\x6a\x01\x8d\x45\xf4\x50\xa1"
	"\x00\x80\x41\x00"
	"\xff\xd0\x6a\x00\xa1"
	"\xfc\x80\x41\x00"
	"\xff\xd0" };

char code2[] = { "\x55\x8b\xec\x83\xec\x48\xc7\x45\xf4\x63\x61\x6c\x63\xc7\x45\xf8"
	"\x00\x00\x00\x00\x6a\x01\x8d\x45\xf4\x50\xa1"
	"\x00\x80\x41\x00"
	"\xff\xd0\x6a\x00\xa1"
	"\xfc\x80\x41\x00"
	"\xff\xd0" };

void main()
{
	//char code[] = { "\x55\x8b\xec\x83\xec\x48\xc7\x45\xf4\x63\x61\x6c\x63\xc7\x45\xf8"
	//	"\x00\x00\x00\x00\x6a\x01\x8d\x45\xf4\x50\xa1"
	//	"\x00\x80\x41\x00"
	//	"\xff\xd0\x6a\x00\xa1"
	//	"\xfc\x80\x41\x00"
	//	"\xff\xd0" };

	///*int* shell = (int*)code;
	//__asm
	//{
	//	jmp shell
	//}*/

	//char name[12] = { 0 };
	//scanf("%s", name);

	//printf("%s\n", name);

	//WinExec("notepad", 1);
	//exit(0);


	// WinExec("calc", 1) && exit(0)
	__asm
	{
		push		ebp
		mov			ebp, esp
		sub			esp, 48h

		mov         dword ptr[ebp - 0ch], 636c6163h
		//mov         dword ptr[ebp - 0bh], 61h
		//mov         dword ptr[ebp - 0ah], 6ch
		//mov         dword ptr[ebp - 9], 63h
		mov         dword ptr[ebp - 8], 0

		push        1
		lea         eax, [ebp -0ch]
		push        eax

		mov         eax, WinExec
		call        eax
	
		push        0
		mov         eax, exit
		call        eax
	}
}

asm 동작 코드 마련

-> machine code instruction 문자열로 변환

-> api 및 dll memory 참조 위치 확인

-> 쉘 코드 호출

 

보안 관련 속성 변경 후 테스트 가능하다. 특히 stack 영역의 데이터를 instruction으로 실행할 수 없다.

- ASLR 해제

- DEP 해제

- 런타임 검사 해제

- 보안 검사 해제

 

출처 https://www.youtube.com/playlist?list=PLXvgR_grOs1DcOi82-ljnG8BnHyA7VIVq 

'알고리즘 > 이론' 카테고리의 다른 글

트리 순회 순서와 완전 탐색  (0) 2022.10.02
누적합과 전처리  (0) 2022.10.02
code note  (0) 2022.07.22
good taste  (0) 2022.07.22
tree - dfs  (0) 2021.04.21