DLL 파일 분석에 유용한 DllLoader

DLL 멀웨어를 동적 분석할 때 사용할만한 간단한 DLL Loader 가 있어 소개한다. git repository 를 다운로드하여 빌드하거나 첨부 파일의 빌드된 파일을 다운로드하자.
프로그램의 핵심이 되는 LoadDLL.cpp
파일 코드는 매우 간단한다.
// LoadDLL.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#pragma warning( disable : 4127 )
#include "pch.h"
#include <iostream>
#include <stdio.h>
#include <Windows.h>
#include <conio.h>
int main(int argc, char **argv)
{
(void)argc;
(void)argv;
if (argc < 2)
{
printf("Usage: %s <DLL> [<ProcName>,...]", argv[0]);
return -1;
}
char *filename = argv[1];
printf("Loading %s\n", filename);
printf("Press any key to continue...\n");
_getch();
HMODULE hLib = LoadLibraryA(filename);
for (int i = 2; i < argc; i++)
{
FARPROC proc = GetProcAddress(hLib, argv[i]);
if (proc != NULL)
{
printf("Calling function: %s (%x)\n", argv[i], proc);
printf("Press any key to continue...\n");
_getch();
(*proc)();
}
else
{
printf("Can't resolve function: %s\n", argv[i] );
}
}
printf("Finishing program\n");
printf("Press any key to continue...\n");
_getch();
return 0;
}
사용법
실행 커맨드는 다음과 같다.
> LoadDLL.exe <DLL> [<ProcName>,...]
<DLL>
은 로딩할 DLL 의 경로, <ProcName>
은 DLL 에 포함된 Export 함수의 이름이다. 커맨드 실행 후 Press any key to continue
문구가 출력될 때 아무 버튼이나 입력해야 LoadLibrary()
가 호출되며 DLL 로딩이 시작된다. 이후 파라미터로 전달된 Export 함수를 순차적으로 실행한다.
