์
์ฑ์ฝ๋๋ ํจ์ปค๊ฐ ์ ์ฉ๋ ์คํ ํ์ผ์ ๋ถ์ํ๋ค ๋ณด๋ฉด,
๊ฐ์ฅ ๋จผ์ ๋ฌด๋์ ธ ์๋ ๋ถ๋ถ์ด Import Table์
๋๋ค.
์ค๋์ Import Table์ด ํผ์๋ PE ํ์ผ์ ์ด๋ป๊ฒ ์ฌ๊ตฌ์ฑํ๋์ง,
๊ทธ๋ฆฌ๊ณ ์
์ฑ์ฝ๋๊ฐ ์ด๋ค ๋ฐฉ์์ผ๋ก Import๋ฅผ ์จ๊ธฐ๋์ง ๊ธฐ๋ก ์ค์ฌ์ผ๋ก ์ ๋ฆฌํด๋ดค์ต๋๋ค.
๋ฆฌ๋ฒ์ฑ ๊ธฐ๋ก
## 1) ๐ ๋์ ๋ก๋ฉ ๊ธฐ๋ฐ Import ์๋ ๊ธฐ๋ฒ
๋ํ์ ์ผ๋ก ์ฌ์ฉํ๋ API๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
LoadLibraryA / LoadLibraryWGetProcAddressLdrLoadDllLdrGetProcedureAddress
์ ์ฑ์ฝ๋์์ ๋ง์ด ๋ณด์ด๋ ์ ํ์ ์ธ C ๊ตฌ์กฐ๋ ์๋์ ๊ฐ์ต๋๋ค.
## 2) ๐ง C ์ฝ๋ ์์ โ API ํด์ ๊ธฐ๋ฐ ๋์ ๋ก๋ฉ
DWORD hash(char* s) {
DWORD h = 0;
while (*s) {
h = ((h << 5) + h) + *s;
s++;
}
return h;
}
FARPROC resolve(const char* dll, DWORD func_hash) {
HMODULE mod = LoadLibraryA(dll);
if (!mod) return NULL;
PIMAGE_DOS_HEADER dos = (PIMAGE_DOS_HEADER)mod;
PIMAGE_NT_HEADERS nt = (PIMAGE_NT_HEADERS)((BYTE*)mod + dos->e_lfanew);
DWORD rva = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
PIMAGE_EXPORT_DIRECTORY exp = (PIMAGE_EXPORT_DIRECTORY)((BYTE*)mod + rva);
DWORD* names = (DWORD*)((BYTE*)mod + exp->AddressOfNames);
WORD* ord = (WORD*)((BYTE*)mod + exp->AddressOfNameOrdinals);
DWORD* funcs = (DWORD*)((BYTE*)mod + exp->AddressOfFunctions);
for (DWORD i = 0; i < exp->NumberOfNames; i++) {
char* name = (char*)mod + names[i];
if (hash(name) == func_hash) {
return (FARPROC)((BYTE*)mod + funcs[ord[i]]);
}
}
return NULL;
}
๐ ์์ธ ๋ถ์
hash()๋ ์ด๋ฆ ๊ธฐ๋ฐ ํด์ ์์ฑ- Export Directory๋ฅผ ์ง์ ์ํ
- ๋ฌธ์ ๋น๊ต ๋์ ํด์ ๋น๊ต๋ก ํ์ง ํํผ
- ์ค์ ์ ์ฑ์ฝ๋์์ ๊ฐ์ฅ ํํ๊ฒ ์ฐ์
- ์ ์ ๋ถ์ ๋๊ตฌ๊ฐ Import๋ฅผ ์ฌ๊ตฌ์ฑํ๊ธฐ ์ด๋ ต๊ฒ ๋ง๋๋ ๊ตฌ์กฐ
## 3) ๐ง Assembly ์์ โ Export ๊ตฌ์กฐ ์ง์ ์ฐธ์กฐ
mov ebx, [LoadLibraryA]
push offset dll_name
call ebx
mov esi, eax ; module base
mov edi, [esi+3Ch] ; e_lfanew
add edi, esi ; PE header
mov eax, [edi+78h] ; RVA of export directory
add eax, esi ; export directory VA
mov ecx, [eax+18h] ; NumberOfNames
mov edx, [eax+20h] ; AddressOfNames
add edx, esi
next_name:
mov ebx, [edx]
add ebx, esi ; name address
push ebx
call hash_function
cmp eax, target_hash
je found
add edx, 4
loop next_name
๐ ๋ ์ง์คํฐ ๊ธฐ๋ฐ ์์ธ ์ค๋ช
esi= ๋ชจ๋ ๋ฒ ์ด์คedi= NT Header ์์eax= Export Directory ์ฃผ์ecx= ์ด๋ฆ ๊ฐ์- API ์ด๋ฆ ํ๋์ฉ ์ํํ๋ฉฐ ํด์ ๋น๊ต
- ์ค์ ํจ์ปค๋ค์ด ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉํ๋ ๋ฐฉ์
## 4) ๐ Import Table ์ฌ๊ตฌ์ฑ ํ๋ฆ (Forensics ๊ด์ )
์
์ฑ์ฝ๋ ๋ถ์ ์ Import Table์ด ํ๊ดด๋ ๊ฒฝ์ฐ,
๋ณดํต ์๋ ๋จ๊ณ๋ก ๋ณต์ํฉ๋๋ค.
- ์คํ ํ์ผ ์ ์ฒด์ BP on GetProcAddress
- ์คํ ์ค ํธ์ถ๋๋ ์ค์ API ๋ชฉ๋ก ์์ง
- ํธ์ถ ์์ยทDLL ๋งคํ ๊ธฐ๋ก
- Scylla, ImportREC ๋ฑ์ผ๋ก Import Table ์ฌ์์ฑ
- ํจ์ปค ์ ๊ฑฐ ํ ์ ์ ๋ถ์ ์งํ
๐ Written by Code & Compass