리소스 등록하는 방법 AKA 드롭퍼

2018. 1. 13. 05:220x03 Reversing Theory

728x90

리소스에서 새로운 섹션 exe 추가 한 후 bin 파일 복사하고 


resource.h 인클루드 


// 숨어 있는 파일을 찾아랏 !! 

#define _CRT_SECURE_NO_WARNINGS

#define IDD_HAND_ABOUTBOX (103)

#define IDD_FOOT_ABOUTBOX (110)

#define  WIN32_LEAN_AND_MEAN



#include <stdio.h>

#include <stdlib.h>

#include <windows.h>

#include <io.h>

#include <shellapi.h>

#include <string.h>

#include <direct.h>

#include "E:\MAKE_CTF\2018HACKINGCAMP\HIDEFILE\HIDEFILE\resource.h"


unsigned int num, num2;

char fileName[] = "click.exe";



static HINSTANCE HInstRes;

int check = 0x1234; // 이렇게 const 박아두었는데 레지스터나 메모리에서 수정할 순 있거든요 


void add()

{

printf("즐거운 덧셈시간~\n");

scanf("%d %d", &num, &num2);

printf(" 합 : %d\n", num + num2);

}


void sub()

{

printf("즐거운 뺄셈시간~\n");

scanf("%d %d", &num, &num2);

printf(" 차 : %d\n", num - num2);

}


void mul()

{

printf("즐거운 곱셈시간~\n");

scanf("%d %d", &num, &num2);

printf(" 곱 : %d\n", num * num2);

}


void div()

{

printf("즐거운 나눗셈시간~\n");

scanf("%d %d", &num, &num2);

printf(" 나눗셈 : %d\n", num / num2);

}




int Stage1()

{

//printf("Round 1 . can you analysis about autoit?\n");

Sleep(3000);




int result = -1;


return result; // -1이면 탈락

}





int isFileHidden(char* filename) {

_finddatai64_t c_file;

intptr_t hFile;

int result = 0;


if ((hFile = _findfirsti64(filename, &c_file)) == -1L)

result = -1;

else

if (c_file.attrib & _A_HIDDEN) result = 1;



_findclose(hFile);


return result;

}


HGLOBAL WINAPI MyLoadResource(LPCSTR ResName, LPCSTR ResType, int *lpResSize)

{

HRSRC   hRsrc;

HGLOBAL hRes = NULL;



if ((hRsrc = FindResource(HInstRes, ResName, ResType)) != NULL)

{

hRes = LoadResource(HInstRes, hRsrc);

if (lpResSize != NULL) *lpResSize = SizeofResource(HInstRes, hRsrc);

}

return hRes;

}



void HideBinary()

{

if (isFileHidden(fileName) == 1) {

puts("지금 무엇인가가 숨겨져 있습니다.");

}

else if (isFileHidden(fileName) == 0) {

puts("숨김 파일이 아닙니다.");

}

else if (isFileHidden(fileName) == -1) {

puts("에러가 났습니다. 파일이 없다네요...");

}

system("pause");


}


void ErrorHandler(const char *text)

{

printf("%s\n", text);

}


VOID  LoadExeFile()

{

//HGLOBAL hResLoad; // handle to loaded resource

HMODULE hExe; // handle to existing .EXE File

  //HRSRC hRes; // handle or ptr  . to res. info. in hExe

  //HANDLE hUpdateRes; // update resource handle

  //LPVOID lpResLock; // pointer to resource data

  //BOOL result; // reset


hExe = LoadLibrary(TEXT("click.exe"));


if (hExe == NULL)

{

ErrorHandler("Counldn't load EXE");

return;

}

}


void StartBinary()

{

char strFolderPath[] = { "C:\\Temp\\HACKINGCAMP" };

int result = _mkdir(strFolderPath);

if (check == 0x12345678) // --> 이게 키 값

{

int Size;

HGLOBAL hRes;

HFILE hFile;

CHAR OutFileName[MAX_PATH];

if ((hRes = MyLoadResource(MAKEINTRESOURCE(IDR_EXE1), "EXE", &Size)) != NULL)

{


GetModuleFileName(NULL, OutFileName, MAX_PATH);

lstrcpy(strrchr(OutFileName, '\\') + 1, "click"); // 마지막 \\다음으로 파일 명 복사 

  //printf("FileName='%s'\n", OutFileName);


if ((hFile = _lcreat(OutFileName, 0)) != HFILE_ERROR)

{

printf("Create File\n");

_lwrite(hFile, (LPCSTR)LockResource(hRes), Size);


_lclose(hFile);

}

else printf("Cannot create '%s'\n", OutFileName);

FreeResource(hRes);

}

else printf("Not Found Resouce\n");


printf("파일이 어디있을까요..\n");

CopyFile(OutFileName, "C:\\Temp\\HACKINGCAMP\\dropper", TRUE);

DeleteFile(OutFileName);

SetFileAttributesA(fileName, FILE_ATTRIBUTE_NORMAL);

// ShellExecuteA(NULL, "open", OutFileName, NULL, NULL, SW_SHOW);

}

else

{

exit(-1);

}

}

void EndBinary()

{

char info[] = "Bye";

printf("%s\n", info);

SetFileAttributesA(fileName, FILE_ATTRIBUTE_HIDDEN);

remove(fileName);

system("pause");


}



void* hidden(int n)

{

char welcome[] = "hidden";

int tmp = 0;

int length = strlen(welcome);

int new_length = length;

//printf("%d\n", length);

HideBinary();

__asm

{

//jmp HideBinary // hide binary로 점프 


jmp start // loop 안 거치게 하기 위함 


looped :

add ecx, 0x01

add eax, 0x01

// jmp start


start :

movzx eax, welcome // 1byte 씩 eax에 넣고 

movzx edx, eax // eax값을 edx에 넣고 

mov tmp, eax

xor edx, edx  // edx 0으로 초기화 하고

mov eax, tmp

cmp eax, 0x00

jl looped

mov eax, new_length

cmp ecx, eax


}

StartBinary();

EndBinary();

return 0;

}


int *num_input()

{

int num = 0;

int *p = 0;


scanf("%d", &num);



p = &num;


return p;

}


void what()

{

printf("축하합니다!!!!");

printf("히든 ~ 맵입니다 ! 여기서 무엇을 할 수 있을까요? \n");

int *p = num_input();

int num = *p;

printf("%d\n", num);

__asm

{

mov edx, num

mov eax, edx

push eax

call hidden

}

}



int main(int argc, char *argv[])

{


HInstRes = GetModuleHandle(NULL);


SetFileAttributesA(fileName, FILE_ATTRIBUTE_HIDDEN); // 처음엔 숨겨놓았다가 나중에 쫜 하고 나타나자 

unsigned int input = 0;


char welcome[] = "hidden";

int tmp = 0;

int length = strlen(welcome);

//SetFileAttributes(fileName,FILE_ATTRIBUTE_NORMAL);


char format[] = "%s \n";

char info[] = "Bye";



printf("==============계산기===============\n");

printf("\t|1. 덧셈  |\n");

printf("\t|2. 뺄셈  |\n");

printf("\t|3. 곱셈  |\n");

printf("\t|4. 나눗셈|\n");

printf("===================================\n");

scanf("%d", &input);


switch (input)

{

case 1:

add();

break;


case 2:

sub();

break;


case 3:

mul();

break;


case 4:

div();

break;

case 9:

what();

break;

default:

MessageBoxA(NULL, "nononononono", "WTF", MB_OK);

break;

}


if (!Stage1())

{

char *whatthe;

scanf("%s", whatthe);


for (int i = 0; i < (int)strlen(whatthe); i++)

{

*(whatthe + i) ^= 0x5;

}

printf("%s\n", whatthe);

}


}



'0x03 Reversing Theory' 카테고리의 다른 글

2018 해킹캠프 문제 3  (0) 2018.01.21
SDK 프로그램 복습 및 mfc 원리 이해 하는 날  (0) 2018.01.14
온고지신 HWP 97 개념  (0) 2018.01.08
코드가상화  (0) 2018.01.03
코드 가상화 개인 공부 [0x06]  (0) 2017.12.26