ãããããããWindows XPããŸã ååšããŠããªãã£ããšããããã«ãŒã«é¢ããæ å ±ãæ±ããŠãåœæã®è¥ãUPXãœãŒã¹ã®ãžã£ã³ã°ã«ã«ç»ããŸããã ããããè³å ã®ã¢ã»ãã«ã³ãªã³ã¯å¿ èŠä»¥äžã«åæãããªãã£ãããUPXã¯ãã§ã«éåžžã«éå±ã§ãã-äžè¬çã«ããããã®ã¿ã€ãããã¯ã»ãšãã©äœãæœåºããŸããã§ããã ãããã»ããã¬ãã¯ããããŠåœŒã¯ãã£ãšå©ããã æ å ±ãè¿œå ãããããšã§ãã¯ããã«ç°¡åã«ãªããŸããã ã»ãšãã©ãã¹ãŠããããŸãã ããªãæ®éã®éè¡ã®ããã€ã§ãããŠã³ããŒãã§ããŸãïŒ Zeus 2.0.8.9 ïŒã ã¯ããæ¬åœã«ããã«ããã®ã¯ãWindowsã®äžŠã¹æ¿ããé·ãéå ¬éãããŠããããšã§ãïŒ Windows 2000 ïŒã
ããã«ãŒã«é¢ããæ å ±ããããŸãããäž»ã«ç 究ã§ãããç§ãã¡ãæãã§ããåŽé¢ã§ã¯ãªãéçºã«çŽæ¥é¢é£ããŠããŸãã ããã®åªããäŸã¯ãæªåé«ãæç¥VolodyaãšNEOxã«ãã£ãŠæžããã2ã€ã®ããŒãã®èšäºãååã®ããã«ãŒã«ã€ããŠãã§ãã
次ã«ãããŒãºã«åãããŠãæãã·ã³ãã«ã§ãããªããç°¡åã«å€æŽå¯èœãªPEããã«ãŒã®éçºã«é¢ããæãå ·äœçã§äžè²«ããæ å ±ãæäŸããããšããŸãã
ã¢ã«ãŽãªãºã
ããšãã°ãnotepad.exeããããŸãã éåžžã®32ããã圢åŒã§ã¯ãééã¯çŽ60 Kbã§ãã ãã¹ãŠã®æ©èœãç¶æããªãããå€§å¹ ã«åæžããããšèããŠããŸãã ç§ãã¡ã®è¡åã¯ã©ãããã¹ãã§ããïŒ ãŸããæåã®ãã¡ã€ã«ããæåŸã®ãã€ããŸã§é åã«ãã¡ã€ã«ãèªã¿èŸŒã¿ãŸãã ä»ãç§ãã¡ã¯åœŒãšäœã§ãã§ããŸãã ãããŠãç§ãã¡ã¯ãããçµãããã§ãã ãããååŸããŠç°¡åãªã³ã³ãã¬ããµãŒã«æž¡ããŸãããã®çµæãé åã¯60 Kbã§ã¯ãªããããšãã°20 Kbã«ãªããŸãã ããã¯ã¯ãŒã«ã§ãããå§çž®åœ¢åŒã§ã¯ãã¡ã¢åž³ã®ã€ã¡ãŒãžã¯é«ããšã³ããããŒãæã€åãªããã€ãã®ã»ããã§ãããå®è¡å¯èœãã¡ã€ã«ã§ã¯ãªãããã¡ã€ã«ã«æžã蟌ãã§ã¯ãªãã¯ããŠãèµ·åã§ããŸããã å§çž®ãããã€ã¡ãŒãžãæã€ã¢ã¬ã€ã®å Žåãã¡ãã£ã¢ïŒããŒãããŒããŒïŒãéåžžã«å°ããªå®è¡å¯èœãã¡ã€ã«ãå¿ èŠã§ããããã«ã¢ã¬ã€ãæ¥ç¶ããã¢ã¬ã€ãéããŠå®è¡ããŸãã ã¡ãã£ã¢ãäœæããŠã³ã³ãã€ã«ããå§çž®ãããã¡ã¢åž³ã®æåŸã«è¿œå ããŸãã ãããã£ãŠããã¹ãŠã®ã¢ã¯ã·ã§ã³ã®çµæãšããŠååŸããããã¡ã€ã«ïŒãµã€ãºãåçŽã«å§çž®ãããã¡ã¢åž³ã®ãµã€ãºããããããã«å€§ããïŒãèµ·åããããšãããã±ãŒãžåãããã€ã¡ãŒãžèªäœãæ€åºãããã¢ã³ããã¯ããããã®æ§é ã解æãããŠå®è¡ãããŸãã
ã芧ã®ãšãããããŸãè€éã§ã¯ãªãããã»ã¹ãèªååããå¿ èŠããããŸãã ããŒããŒãšãå®éã«ã¯ããã«ãŒãšãã2ã€ã®ããã°ã©ã ãäœæããã ãã§ãã
ããã«ãŒäœæ¥ã¢ã«ãŽãªãºã ïŒ
- PEãã¡ã€ã«ãé åã«èªã¿èŸŒã¿ãŸãã
- ãã¹ã¬ã¹å§çž®ã¢ã«ãŽãªãºã ã䜿çšããŠé åãå§çž®ããŸãã
- PE圢åŒã«åŸã£ãŠãå§çž®ãããé åãããŒããŒãã³ãã¬ãŒãã«è¿œå ããŸãã
- å§çž®ãããPEãã¡ã€ã«ãæåŸã«ããé åãèŠã€ããŸãã
- ãããåºãã;
- PEãã¡ã€ã«ã®ããããŒã解æãããã¹ãŠã®æš©éãèšå®ããã¡ã¢ãªãå²ãåœãŠãŠãæçµçã«å®è¡ããŸãã
ããŒãããŒããŒ
ãããã£ãŠãããŒããŒãæåã«è¡ãã¹ãããšã¯ãPEãã¡ã€ã«ã®å§çž®ã€ã¡ãŒãžãå«ãé åã®ã¢ãã¬ã¹ãæ¬äœã§èŠã€ããããšã§ãã æ€çŽ¢æ¹æ³ã¯ãããã«ãŒããã®é åãããŒããŒã«ã©ã®ããã«ç§»æ€ãããã«ãã£ãŠç°ãªããŸãã
ããšãã°ãããŒã¿ãå«ãæ°ããã»ã¯ã·ã§ã³ãåã«è¿œå ããå Žåãæ€çŽ¢ã¯æ¬¡ã®ããã«ãªããŸãã
æåŸã®ã»ã¯ã·ã§ã³ã§å§çž®ç»åãæ€çŽ¢ãã
// PE- HMODULE hModule = GetModuleHandle(NULL); PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; PIMAGE_NT_HEADERS pNTHeaders = MakePtr(PIMAGE_NT_HEADERS,hModule,pDosHeader->e_lfanew); PIMAGE_SECTION_HEADER pSections = IMAGE_FIRST_SECTION(pNTHeaders); // , PIMAGE_SECTION_HEADER pLastSection = &pSections[pNTHeaders->FileHeader.NumberOfSections - 1]; // , LPBYTE pbPackedImage = MakePtr(LPBYTE, hModule, pLastSection->VirtualAddress); // DWORD dwPackedImageSize = pLastSection->SizeOfRawData;
ããããç§ãã¡ã®æèŠã§ã¯ãããŒãããŒããŒã®ãã®ã³ãŒãã¯ç ç²ã«ãªãå¯èœæ§ããããŸãã äžè¬çã«ãããã«ãŒãã§ããããšã¯ãã¹ãŠã圌ãšåœŒã ããã§ããããã«ããŸãã ããŒãããŒããŒã®ã¢ãã¬ã¹ç©ºéå ã®ã€ã¡ãŒãžã¢ãã¬ã¹ã¯ãããã±ãŒãžã³ã°äžã«äºåã«èšç®ããé©åãªå Žæã«å ¥åããã ãã§ãã ãããè¡ãã«ã¯ãããã°ã©ã ã«2ã€ã®ããŒã¯ãæ®ããŸãã
LPBYTE pbPackedImage = (LPBYTE) 0xDEADBEEF; DWORD dwPackedImageSize = 0xBEEFCACE;
ããã«ãŒã¯ãå§çž®ãããã€ã¡ãŒãžãå«ãé åãããŒããŒã«åã蟌ããšãããŒããŒã®æ¬äœã§çœ²åæ€çŽ¢ãå®è¡ãã0xDEADBEEFãé åã®ã¢ãã¬ã¹ã«ã0xBEEFCACEããã®ãµã€ãºã«çœ®ãæããŸãã
ã¢ãã¬ã¹ã®æ€çŽ¢æ¹æ³ã決å®ããã®ã§ãå§çž®ããŒã«ã®æ¢è£œã®å®è£ ãéžæããŠãããã«ãŒã§äœ¿çšã§ããŸãã
é©åãªãªãã·ã§ã³ã¯aplibã䜿çšããããšã§ã ãããã¯ãLempel-Zivã¢ã«ãŽãªãºã ïŒLZïŒã«åºã¥ãå§çž®ãå®è£ ããããããã§éåžžã«ã³ã³ãã¯ããªã³ãŒããåããå°ããªã©ã€ãã©ãªã§ãã ãããŠãç§ãã¡ã¯ééããªãä»ã®æ¥ã«ãããéžæããŸãããä»æ¥ã¯ããã«ã·ã³ãã«ã§ã³ã³ãã¯ããªãœãªã¥ãŒã·ã§ã³ãã€ãŸãWindowsã«çµã¿èŸŒãŸããæ©èœãæ±ããŠããŸãïŒ
XPããããæ°ã«å ¥ãã®ntdll.dllã2ã€ã®åªããæ©èœã®ãšã¯ã¹ããŒããéå§ããŸããã
NTSTATUS RtlCompressBuffer( __in USHORT CompressionFormatAndEngine, __in PUCHAR UncompressedBuffer, __in ULONG UncompressedBufferSize, __out PUCHAR CompressedBuffer, __in ULONG CompressedBufferSize, __in ULONG UncompressedChunkSize, __out PULONG FinalCompressedSize, __in PVOID WorkSpace ); NTSTATUS RtlDecompressBuffer( __in USHORT CompressionFormat, __out PUCHAR UncompressedBuffer, __in ULONG UncompressedBufferSize, __in PUCHAR CompressedBuffer, __in ULONG CompressedBufferSize, __out PULONG FinalUncompressedSize );
ãããã®ååã¯ãå§çž®ã®ããã®æ©èœãšè§£åã®ããã®æ©èœã®1ã€ã§ãã ãã¡ãããéåžžã«çå£ãªè£œåãéçºããŠããå ŽåãWindows 2000ããã³NT 4.0ãæèŒããã³ã³ãã¥ãŒã¿ãŒããŸã ååšããããããããã®æ©èœã«ã¯è§ŠããŸããã§ãã;ïŒ
Platform SDKããããŒã«ã¯ãããã®é¢æ°ããªããããéçã«ãªã³ã¯ã§ããªããããGetProcAddressã䜿çšããå¿ èŠããããŸãã
解åããé¢æ°ã®ã¢ãã¬ã¹ã決å®ãã
// RtlDecompressBuffer DWORD (__stdcall *RtlDecompressBuffer)(ULONG,PVOID,ULONG,PVOID,ULONG,PULONG); // RtlDecompressBuffer ntdll.dll (FARPROC&)RtlDecompressBuffer = GetProcAddress(LoadLibrary("ntdll.dll"), "RtlDecompressBuffer" );
é梱ãããã®ããããé梱ãããã®ãããå Žåãæçµçã«ãã§ã«ãããè¡ãããšãã§ããŸãã ãããè¡ãã«ã¯ãã¡ã¢ãªãäœè£ãæã£ãŠå²ãåœãŠïŒè§£åãããã¡ã€ã«ã®ããªã¥ãŒã ãããããªãããïŒãäžèšã§å®çŸ©ããé¢æ°ãå®è¡ããŸãã
DWORD dwImageSize = 0; DWORD dwImageTempSize = dwPackedImageSize * 15; // LPVOID pbImage = VirtualAlloc( NULL, dwImageTempSize, MEM_COMMIT, PAGE_READWRITE ); // RtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1, pbImage, dwImageTempSize, pbPackedImage, dwPackedImageSize, &dwImageSize);
COMPRESSION_FORMAT_LZNT1ãã©ã¡ãŒã¿ãŒã¯ãåŸæ¥ã®LZå§çž®ã䜿çšããããšãæå³ããŸãã ãã®é¢æ°ã¯ä»ã®ã¢ã«ãŽãªãºã ã§å§çž®ã§ããŸãããããã§ååã§ãã
ããã§ãã¡ã¢ãªïŒpbImageïŒã«PEãã¡ã€ã«ã®çã®ã€ã¡ãŒãžãã§ããŸããã éå§ããã«ã¯ããã€ãã£ãã®Windows PEããŒããŒãéåžžè¡ãäžé£ã®æäœãå®è¡ããå¿ èŠããããŸãã ãªã¹ããæãå¿ èŠãªãã®ã«æžãããŸãã
- ãªãã·ã§ã³ã®ããããŒïŒOPTIONAL_HEADERïŒã®Image Baseãã£ãŒã«ãã§æå®ãããã¢ãã¬ã¹ã«ãç»åã®å é ïŒããããŒïŒãé 眮ããŸãã
- PEãã¡ã€ã«ã®ã»ã¯ã·ã§ã³ãã»ã¯ã·ã§ã³ããŒãã«ã«ç€ºãããŠããã¢ãã¬ã¹ã«é 眮ããŸãã
- ã€ã³ããŒãããŒãã«ã解æããé¢æ°ã®ãã¹ãŠã®ã¢ãã¬ã¹ãèŠã€ããŠã察å¿ããã»ã«ã«å ¥åããŸãã
çªç¶ãæ·±å»ãªäºææ§ãå¿ èŠãªå Žåã¯ãã¯ãŒã«ãªPEããŒããŒãèªåã§äœæããããWebã§æãå®å šãªå®è£ ãèŠã€ããŠãã ããã ;ïŒåãæšãŠããã圢åŒã§ããPEããŒããŒã®æ©èœã¯100è¡ä»¥äžã§ãããããããã§ã¯ãããã¿ã€ãã®ã¿ã瀺ããŸãïŒå®å šãªã³ãŒãã¯ãã£ã¹ã¯äžã«ãããŸãïŒã
HMODULE LoadExecutable (LPBYTE image, DWORD* AddressOfEntryPoint)
å±éãããã€ã¡ãŒãžãžã®ãã€ã³ã¿ãååŸããããŒããããã¢ãžã¥ãŒã«ã®ãã³ãã«ïŒPEãã¡ã€ã«ãããŒããããã¢ãã¬ã¹ã«çžåœïŒãšãšã³ããªãã€ã³ãã®ã¢ãã¬ã¹ïŒAddressOfEntryPointãã€ã³ã¿ã«ããïŒãè¿ããŸãã ãã®é¢æ°ã¯ãç»åãã¡ã¢ãªã«æ£ããé 眮ããããã«ãã¹ãŠãè¡ããŸããããã¹ãŠã§ã¯ãªããæçµçã«å¶åŸ¡ãããã«ç§»ãããšãã§ããŸãã
äºå®ã¯ãã·ã¹ãã ã¯ãŸã ç§ãã¡ã«ãã£ãŠããŒããããã¢ãžã¥ãŒã«ã«ã€ããŠäœãç¥ããªããšããããšã§ãã å§çž®ããã°ã©ã ã®å®è¡ãéå§ãããšã³ããªãã€ã³ããä»ããåŒã³åºããšãå€ãã®åé¡ãçºçããå¯èœæ§ããããŸãã ããã°ã©ã ã¯åäœããŸãããæ²ãã£ãŠããŸãã
ããšãã°ãGetModuleHandleïŒNULLïŒã¯ãå±éãããããã°ã©ã ã§ã¯ãªããããŒããŒã¢ãžã¥ãŒã«ã®ã€ã¡ãŒãžããŒã¹ãè¿ããŸãã FindResourceé¢æ°ãšLoadResourceé¢æ°ã¯ããªãœãŒã¹ããŸã£ãããªãããŒãããŒããŒã調ã¹ãŸãã ããå ·äœçãªã°ãªãããååšããå ŽåããããŸãã ããããã¹ãŠé²æ¢ããã«ã¯ãããã»ã¹ã®ã·ã¹ãã æ§é ã®ããããå Žæã§æ å ±ãæŽæ°ããããŒããŒã¢ãžã¥ãŒã«ã®ã¢ãã¬ã¹ãããŒããããã¢ãžã¥ãŒã«ã®ã¢ãã¬ã¹ã«çœ®ãæããå¿ èŠããããŸãã
ãŸããå€ãã€ã¡ãŒãžããŒã¹ã瀺ãPEBïŒProcess Enviroment BlockïŒãä¿®æ£ããå¿ èŠããããŸãã PEBã¢ãã¬ã¹ã¯éåžžã«ç°¡åã«ååŸã§ãããŠãŒã¶ãŒã¢ãŒãã§ã¯åžžã«FSã»ã°ã¡ã³ãã®ãªãã»ãã0x30ã«ãããŸãã
PPEB Peb; __asm { push eax mov eax, FS:[0x30]; mov Peb, eax pop eax } // hModule â PE- Peb->ImageBaseAddress = hModule;
ãŸããPEBã«ãã£ãŠåç §ãããLDR_DATAæ§é å ã®ã¢ãžã¥ãŒã«ã®ãªã¹ããä¿®æ£ããŠã害ã¯ãããŸããã åèš3ã€ã®ãªã¹ãããããŸãã
- InLoadOrderModuleList-ããŒãé ã®ã¢ãžã¥ãŒã«ã®ãªã¹ãã
- InMemoryOrderModuleList-ã¡ã¢ãªã®å Žæã®é çªã®ã¢ãžã¥ãŒã«ã®ãªã¹ãã
- InInitializationOrderModuleList-åæåé ã®ã¢ãžã¥ãŒã«ã®ãªã¹ãã
// , // PLDR_DATA_TABLE_ENTRY pLdrEntry = (PLDR_DATA_TABLE_ENTRY)(Peb->Ldr->ModuleListLoadOrder.Flink); pLdrEntry->DllBase = hModule; ...
ããã§ãããŒããããã¢ãžã¥ãŒã«ã®ãšã³ããªãã€ã³ããå®å šã«åŒã³åºãããšãã§ããŸãã æãæ®éã®æ¹æ³ã§åŒã³åºããããã®ããã«æ©èœããŸãã
LPVOID entry = (LPVOID)( (DWORD)hModule + AddressOfEntryPoint ); __asm call entry;
AddressOfEntryPointã¯ããšã³ããªãã€ã³ãã®çžå¯Ÿä»®æ³ã¢ãã¬ã¹ïŒRVAãçžå¯Ÿä»®æ³ã¢ãã¬ã¹ïŒã§ãããLoadExecutableé¢æ°ã®ãªãã·ã§ã³ããããŒããååŸãããŸãã 絶察ã¢ãã¬ã¹ãååŸããã«ã¯ãããŒã¹ã¢ãã¬ã¹ïŒã€ãŸããæ°ããããŒããããã¢ãžã¥ãŒã«ïŒãRVAã«è¿œå ããã ãã§ãã
ããŠã³ããŒããŒã®ãµã€ãº
VS 2010ã§ããã©ã«ããã©ã°ã䜿çšããŠããŒãããŒããŒãã³ã³ãã€ã«ããã³ãã«ããããšã2ãããã€ãã®ããã°ã©ã ãã£ãªã¢ã§ã¯ãªãã10 Kbãè¶ ããã¢ã³ã¹ã¿ãŒãååŸãããŸãã ã¹ã¿ãžãªã¯äžèŠãªãã®ã倧éã«æ§ç¯ããããããããããã¹ãŠãåŒãåºãå¿ èŠããããŸãã
ãããã£ãŠãããŒããŒãããžã§ã¯ãã®ã³ã³ãã€ã©ããããã£ïŒC / C ++ã¿ãïŒã§ã¯ã次ã®ããšãè¡ããŸãã
- ãæé©åãã»ã¯ã·ã§ã³ã§ããæå°ãµã€ãºïŒ/ O1ïŒããéžæããŠãã³ã³ãã€ã©ãŒããã¹ãŠã®æ©èœãããã³ã³ãã¯ãã«ããããã«ããŸãã
- ãŸããé床ããããµã€ãºã®åªå é äœã瀺ããŸãïŒãã©ã°/ OsïŒã
- ãã³ãŒãã®äœæãã»ã¯ã·ã§ã³ã§ã¯ãC ++äŸå€ããªãã«ãããããã䜿çšããŸããã
- ãŸãããããã¡ãªãŒããŒãããŒïŒ/ GS-ïŒããã§ãã¯ããå¿ èŠããããŸããã ããã¯è¯ãããšã§ãããç§ãã¡ã®å Žåã¯ããã§ã¯ãããŸããã
- ãããã§ã¹ãããå°çãå€ããã ããã¯å€§ããããã®ãããããŒãããŒãã«.rsrcã»ã¯ã·ã§ã³ãäœæãããŸãããããã¯çµ¶å¯Ÿã«å¿ èŠãããŸããã äžè¬ã«ãPEãã¡ã€ã«ã®ãã¹ãŠã®è¿œå ã»ã¯ã·ã§ã³ã¯ãã¢ã©ã€ã¡ã³ãã®ãããã§ãå°ãªããšã512ã®å®å šã«äžèŠãªãã€ãã§ãã
- ãããã°æ å ±ã®äœæããªãã«ããŸãã
- [詳现èšå®]ã¿ãã«ç§»åããŸãã ãããŒã¹ã¢ãã¬ã¹ãžã®ã©ã³ãã æ§ã®å°å ¥ãïŒ/ DYNAMICBASEïŒNOïŒããªãã«ããŸããããããªããšããªã³ã«ãŒã¯åé 眮ã»ã¯ã·ã§ã³ïŒ.relocïŒãäœæããŸãã
- ããŒã¹ã¢ãã¬ã¹ãæå®ããŸãã 0x02000000ãªã©ãéæšæºã®äžäœãéžæããŠã¿ãŸãããã GetModuleHandleïŒNULLïŒãããŒãããŒããŒã«è¿ãã®ã¯ãã®å€ã§ãã ããŒãã³ãŒãã£ã³ã°ããããšãã§ããŸãã
- CRT-shnuyuïŒ/ ENTRYïŒWinMainã§ã¯ãªãããšã³ããªãã€ã³ããæå®ããŸãã äžè¬ã«ãã³ãŒãããçŽæ¥ãã©ã°ããã£ã¬ã¯ãã£ãã䜿çšããŠãããè¡ãããšã«æ £ããŠããŸãããããããã£ã«å°éããã®ã§ãããã§ã§ããŸãã
#pragma comment(linker,"/MERGE:.rdata=.text")
ããã§ã¯ãèªã¿åãå°çšããŒã¿ïŒè¡ãã€ã³ããŒãããŒãã«ãªã©ïŒãå«ã.rdataã»ã¯ã·ã§ã³ãš.textã³ãŒãã»ã¯ã·ã§ã³ãçµã¿åãããŸããã ã°ããŒãã«å€æ°ã䜿çšããå Žåã.dataã»ã¯ã·ã§ã³ãã³ãŒããšçµã¿åãããå¿ èŠããããŸãã
#pragma comment(linker,"/MERGE:.data=.text") // .data , // #pragma comment(linker,"/SECTION:.text,EWR")
äžèšã¯ãã¹ãŠã1.5 KbããŒããŒãååŸããã®ã«ååã§ãã
ããã«ãŒ
äžãããããã¡ã€ã«ãå§çž®ããããŒããŒã«ã¢ã¿ããããã³ã³ãœãŒã«ãŠãŒãã£ãªãã£ãéçºããããšã¯æ®ããŸãã èšäºã®åé ã§èª¬æããã¢ã«ãŽãªãºã ã«åŸã£ãŠæåã«è¡ãã¹ãããšã¯ããã¡ã€ã«ãé åã«èªã¿èŸŒãããšã§ãã åŠçã察åŠããã¿ã¹ã¯ïŒ
HANDLE hFile = CreateFile(argv[1], GENERIC_READ,FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DWORD dwImageSize = GetFileSize(hFile, 0); LPBYTE lpImage = new BYTE[dwImageSize], lpCompressedImage = new BYTE[dwImageSize]; DWORD dwReaded; ReadFile(hFile, lpImage, dwImageSize, &dwReaded, 0); CloseHandle(hFile);
次ã«ãããã«ãŒã¯çµæã®ãã¡ã€ã«ãå§çž®ããå¿ èŠããããŸãã ãããPEãã¡ã€ã«ãã©ãããããããŒãæ£ãããã©ãããªã©ã¯ãã§ãã¯ããŸããããã¹ãŠããŠãŒã¶ãŒã®è¯å¿ã«ä»»ããããã«å§çž®ããŸãã ãããè¡ãã«ã¯ãRtlCompressBufferé¢æ°ãšRtlGetCompressionWorkSpaceSizeé¢æ°ã䜿çšããŸãã æåã«èª¬æããæåã®ãã®-ãããã¡ãå§çž®ãã2çªç®ã¯å§çž®ãšã³ãžã³ã®åäœã«å¿ èŠãªã¡ã¢ãªéãèšç®ããããã«å¿ èŠã§ãã ïŒããŒãããŒããŒã®ããã«ïŒäž¡æ¹ã®æ©èœãæ¢ã«åçã«æ¥ç¶ããŠãããšä»®å®ããããããå®è¡ããã ãã§ãïŒ
DWORD format = COMPRESSION_FORMAT_LZNT1|COMPRESSION_ENGINE_STANDARD; DWORD dwCompressedSize, dwBufferWsSize, dwFragmentWsSize; RtlGetCompressionWorkSpaceSize(format, &dwBufferWsSize, &dwFragmentWsSize); LPBYTE workspace = new BYTE [dwBufferWsSize]; RtlCompressBuffer(format , // lpImage, // dwImageSize, // lpCompressedImage, // dwImageSize, // 4096, // , &dwCompressedSize, // workspace); //
ãã®çµæãå§çž®ããããããã¡ãŒãšãã®ãµã€ãºããããããŒãããŒããŒã«åºå®ã§ããŸãã ãããè¡ãã«ã¯ããŸããããŒããŒã®ã³ã³ãã€ã«æžã¿ã³ãŒããããã«ãŒã«ãã«ãããå¿ èŠããããŸãã ãããããã°ã©ã ã«å ¥ããæã䟿å©ãªæ¹æ³ã¯ã bin2hãŠãŒãã£ãªãã£ã䜿çšããããšã§ãã ä»»æã®ãã€ããªã䟿å©ãªããããŒã«å€æãããã®äžã®ãã¹ãŠã®ããŒã¿ã¯æ¬¡ã®ããã«ãªããŸãã
unsigned int loader_size=1536; unsigned char loader[] = { 0x4d,0x5a,0x00,0x00,0x01,0x00,0x00, ...
bin2hã«ããããããŒäœæãèªååã§ããŸã
ç§ãã¡ã¯åœŒå¥³ã«ããŒããŒã§ãã¡ã€ã«ãéãããããªãåé¯ã«å¿ èŠãªãã®ãã¹ãŠãæã«å ¥ããŸãã ããã§ãèšäºã®åé ã§èª¬æããã¢ã«ãŽãªãºã ã«åŸãå Žåã¯ãããŒãããŒããŒã«å§çž®ã€ã¡ãŒãžãæ·»ä»ããå¿ èŠããããŸãã ããã§ã¯ã90幎代ãšç§ãã¡ã®virmakerã®éå»ãæãåºããªããã°ãªããŸãã;ïŒã äºå®ããµãŒãããŒãã£ã®PEãã¡ã€ã«ã«ããŒã¿ãŸãã¯ã³ãŒããåã蟌ãããšã¯ãçŽç²ã«ãã€ã©ã«ãªãããã¯ã§ãã å®è£ ã¯ããŸããŸãªæ¹æ³ã§æ§æãããŠããŸãããæãåçŽã§äžè¬çãªæ¹æ³ã¯ãæåŸã®ã»ã¯ã·ã§ã³ãæ¡åŒµããããç¬èªã®ã»ã¯ã·ã§ã³ãè¿œå ããããšã§ãã ç§ãã¡ã®æèŠã§ã¯ãè¿œå ã¯ã¢ã©ã€ã¡ã³ãäžã«æ倱ã䌎ããããããŒããŒã«å§çž®ã€ã¡ãŒãžãåã蟌ãããã«ãæåŸã®ã»ã¯ã·ã§ã³ïŒããŒããŒïŒãæ¡åŒµããŸãã ããããå¯äžã®ã»ã¯ã·ã§ã³-äœåãªãã®ã¯ãã¹ãŠåãé€ããŸããã ;ïŒ
ã¢ã¯ã·ã§ã³ã®ã¢ã«ãŽãªãºã ã¯æ¬¡ã®ãšããã§ãã
- ããŒãããŒããŒã«å¯äžã®ã»ã¯ã·ã§ã³ïŒ.textïŒããããŸãã
- ãã®ç©çãµã€ãºãã€ãŸããã£ã¹ã¯äžã®ãµã€ãºïŒSizeOfRawDataïŒãå€æŽããŸãã ããã¯ãå€ããµã€ãºãšå§çž®ã€ã¡ãŒãžã®ãµã€ãºã®åèšã«çãããåæã«ãã¡ã€ã«ã®é 眮ïŒFileAlignmentïŒã«åŸã£ãŠé 眮ããå¿ èŠããããŸãã
- ä»®æ³ã¡ã¢ãªãµã€ãºïŒMisc.VirtualSizeïŒãå€æŽããããã«å§çž®ã€ã¡ãŒãžã®ãµã€ãºãè¿œå ããŸãã
- å€ä»£ã®åŒ[æåŸã®ã»ã¯ã·ã§ã³ã®ä»®æ³ãµã€ãº] + [æåŸã®ã»ã¯ã·ã§ã³ã®ä»®æ³ã¢ãã¬ã¹]ã«åŸã£ãŠãå€ãFileAlignmentã«æããããšãå¿ããã«ãããŒãããŒããŒã€ã¡ãŒãžå šäœïŒOptionalHeader.SizeOfImageïŒã®ãµã€ãºãå€æŽããŸãã
- å§çž®ãããç»åãã»ã¯ã·ã§ã³ã®æåŸã«ã³ããŒããŸãã
ã€ãŸããæŽåãŒãã®æã®åŸã«ããŒã¿ãæžã蟌ã¿ãããããç¥ã£ãŠããã°ããããã®ãŒããäžæžãã§ããŸãã
ããããã³ãŒãã§ã®ãã¹ãŠã®æèã®èŠãæ¹ã§ãã
ã³ãŒãã»ã¯ã·ã§ã³æ¡åŒµ
// PBYTE pbLoaderCopy = new BYTE[simple_packer_size + dwCompressedSize + 0x1000]; memcpy(pbLoaderCopy, (LPBYTE)&simple_packer, simple_packer_size); // PIMAGE_DOS_HEADER dos = (PIMAGE_DOS_HEADER)pbLoaderCopy; PIMAGE_NT_HEADERS nt = MakePtr(PIMAGE_NT_HEADERS, pbLoaderCopy, dos->e_lfanew); // PIMAGE_SECTION_HEADER text = IMAGE_FIRST_SECTION(nt); // memcpy(&pbLoaderCopy[text->PointerToRawData + text->Misc.VirtualSize], lpCompressedImage, dwCompressedSize); // , Misc.VirtualSize text->SizeOfRawData = ALIGN(text->Misc.VirtualSize + dwCompressedSize, nt->OptionalHeader.FileAlignment); // ( ) text->Misc.VirtualSize += dwCompressedSize; // nt->OptionalHeader.SizeOfImage = ALIGN(test->Misc.VirtualSize + test->VirtualAddress, nt->OptionalHeader.FileAlignment); // DWORD dwNewFileSize = pSections->SizeOfRawData + test->PointerToRawData;
ãããããŒãããŒããŒã«æ®ã£ãŠãã0xDEADBEEFããã³0xBEEFCACEã©ãã«ãå®éã®å€ã«çœ®ãæããã®ãå¿ããŠããŸããïŒ 0xBEEFCACEã¯å§çž®ã€ã¡ãŒãžã®ãµã€ãºã«å€æŽããã0xDEADBEEFã¯çµ¶å¯Ÿã¢ãã¬ã¹ã«å€æŽãããŸãã ã€ã¡ãŒãžã¢ãã¬ã¹ã¯ã[ã€ã¡ãŒãžã¢ãã¬ã¹] + [ã»ã¯ã·ã§ã³ã®ä»®æ³ã¢ãã¬ã¹] + [ã»ã¯ã·ã§ã³ã®å é ããã®ã€ã¡ãŒãžãªãã»ãã]ã®åŒã§èšç®ãããŸãã Misc.VirtualSizeã®å€ãæŽæ°ããåã«çœ®æãè¡ãå¿ èŠãããããšã«æ³šæããŠãã ãããããããªããšãçµæã®ãã¡ã€ã«ãæ©èœããŸããã
éåžžã«åçŽãªã«ãŒãã䜿çšããŠã¿ã°ãæ€çŽ¢ããã³çœ®æããŸãã
for (int i = 0; i < simple_packer_size; i++) if (*(DWORD*)(&pbLoaderCopy[i]) == 0xBEEFCACE) *(DWORD*)(&pbLoaderCopy[i]) = dwCompressedSize; else if (*(DWORD*)(&pbLoaderCopy[i]) == 0xDEADBEEF) *(DWORD*)(&pbLoaderCopy[i]) = nt->OptionalHeader.ImageBase + text->VirtualAddress + text->Misc.VirtualSize;
å®éãããããã¹ãŠã§ãã ããã§ãã¡ã¢ãªã«ããã±ãŒãžåãããäœæ¥æºåãã¡ã€ã«ãã§ããŸãããCreateFile/ WriteFileé¢æ°ã䜿çšããŠãã£ã¹ã¯ã«ä¿åããã ãã§ãã
OllyDbgã®å€ªåãã¡ã€ã«ããããã°ããããã»ã¹
çµè«
notepad.exeã®äŸã§ãUPXãšããã«ãŒã®å§çž®å¹çãæ¯èŒãããšãUPXã®48 128ã«å¯ŸããŠ46 592ãã€ãã§çŽ1 Kbãç²åŸããŸãã ããããç§ãã¡ã®ããã«ãŒã¯å®ç§ã«ã¯ã»ã©é ãã§ãã ãããŠãããã¯éåžžã«é¡èã§ãã
å®éã®ãšããããªãœãŒã¹ã®è»¢éãªã©ã®éèŠãªããšãæå³çã«ç¡èŠããŸããã çµæã®å§çž®ãã¡ã€ã«ã¯ã¢ã€ã³ã³ã倱ããŸãïŒ äžè¶³ããŠããæ©èœãèªåã§å®è£ ããå¿ èŠããããŸãã ãã®è³æããåŸãããç¥èã®ãããã§ãããªãã¯ãã®åé¡ã«é¢ããŠäœã®å°é£ããããŸããã
èšäºã®ãœãŒã¹ ã
packerã¯UPXããnotepad.exeãå§çž®ããŸããïŒ
æå·ã«å€æ
å®éãç§ãã¡ã®ããã±ãŒãžã¯æå·ãšã¯ããªãç°ãªããŸãïŒæå·åãšã¢ã³ããšãã¥ã¬ãŒã·ã§ã³æè¡ã®æ¬ åŠã ããã«ã§ããæãç°¡åãªããšã¯ãããŒãããŒããŒã§è§£åããçŽåŸã«ã€ã¡ãŒãžå šäœãè¿œå ããããšã§ãã ããããã¢ã³ããŠã€ã«ã¹ãšãã¥ã¬ãŒã¿ãŒãçªæ¯ããã«ã¯ãããã ãã§ã¯äžååã§ãã ã¿ã¹ã¯ãäœããã®åœ¢ã§è€éã«ããå¿ èŠããããŸãã ããšãã°ãããŒãããŒããŒæ¬äœã«xorããŒãç»é²ããªãã§ãã ããã ã€ãŸããããŒãããŒããŒã¯ã³ãŒãã解èªããããã«å¿ èŠãªããŒãèªèãããç§ãã¡ãå®çŸ©ãããã¬ãŒã ã¯ãŒã¯ã§ãããå埩åŠçããŸãã ã¢ã³ããŠã€ã«ã¹ãšã¯ç°ãªããããã«ã¯æéããããå ŽåããããŸãã
ãŸããããŒããšãã¥ã¬ãŒããããŠããªãæ©èœãŸãã¯æ§é ã«äŸåãããããšãã§ããŸãã 圌ãã ããèŠã€ããå¿ èŠããããŸãã
ããŒãããŒããŒã³ãŒãã眲åã«ãã£ãŠçŒãä»ããããªãããã«ãé«åºŠãªãŠã€ã«ã¹ãšã³ãžã³ãããã«ãŒã«åºå®ããŠãWebã«å€§éã«ãããããã¬ããŒãžãããããçš®é¡ã®ã³ãŒãå€æŽãçæã§ããŸãã
ããŒãããŒããŒã§LoadExecutableé¢æ°ãå®è¡ããåŸãã¢ã³ããã¯çšã«å²ãåœãŠãããã¡ã¢ãªã解æŸãããšããã§ããããããã¯ãã¯ã圹ã«ç«ã¡ãŸããã
ããã«ãŒãã¬ãžã³ã 2æïŒ02ïŒ157
ããŒã¿ãŒãšãªãªã«ã ã
ããã«ãŒã賌èªãã
- 1 999 pã 12æã®çšçŽãªãã·ã§ã³çš
- 1249 RUR iOS / iPadã®å¹Žéãµãã¹ã¯ãªãã·ã§ã³ïŒAndroidãªãªãŒã¹ã¯è¿æ¥å ¬éäºå®ïŒïŒ
- Androidã®ããã«ãŒ