
특정 Windows API를 다른 API로 난독화합니다.
정적/동적 분석 도구로부터 PE 임포트를 난독화(숨김)합니다.
이는 매우 간단합니다. VirtualProtect를 사용했고 이를 Sleep으로 난독화하고 싶다고 가정해 보겠습니다. 이 도구는 IAT를 조작하여 VirtualProtect를 가리키는 썽크 대신 Sleep을 가리키도록 합니다. 이제 파일을 실행할 때 Windows 로더는 VirtualProtect 대신 Sleep을 로드하고, 엔트리 포인트로 실행을 이동시킵니다. 거기서부터 실행은 쉘코드로 리디렉션되며, 도구가 미리 배치한 쉘코드가 VirtualProtect의 주소를 찾아 로더가 이전에 할당한 Sleep의 주소를 대체하는 데 사용됩니다.
#include <cobf.hpp>
int main() {
cobf obf_file = cobf("sample.exe");
obf_file.load_pe();
obf_file.obf_sym("kernel32.dll", "SetLastError", "Beep");
obf_file.obf_sym("kernel32.dll", "GetLastError", "GetACP");
obf_file.generate("sample_obfuscated.exe");
obf_file.unload_pe();
return 0;
};
config.ini)를 제공하면 됩니다.cobf.exe <input file> <out file> [config file]; Template for the config file:
; * Sections can be written as:
; [dll_name]
; old_sym=new_sym
; * The dll name is case insensitive, but
; the old and the new symbols are not.
; * You can use the wildcard on both the
; dll name and the old symbol.
; * You can use '#' at the start of
; the old or the new symbol to flag
; an ordinal.
; * The new symbol should be exported
; by the dll so the windows loader can resolve it.
; For example:
; * Obfuscating all of the symbols
; imported from user32.dll with ordinal 1600.
[user32.dll]
*=#1600
; * Obfuscating symbols imported from both
; kernel32.dll and kernelbase.dll with Sleep.
[kernel*.dll]
*=Sleep
; * Obfuscating fprintf with exit.
[*]
fprintf=exit
이 코드 샘플을 빌드하세요
#include <windows.h>
#include <stdio.h>
int main() {
SetLastError(5);
printf("Last error is %d\n", GetLastError());
return 0;
};
빌드한 후 kernel32 임포트가 다음과 같이 표시됩니다

이제 SetLastError와 GetLastError를 Beep 및 GetACP로 난독화해 보겠습니다(실제로 kernel32의 모든 api는 전혀 임포트되지 않아도 괜찮습니다).
사용된 구성은 다음과 같습니다
[kernel32.dll]
SetLastError=Beep
GetLastError=GetACP
출력 결과입니다(위에 표시된 대로 라이브러리를 직접 사용할 수도 있습니다).

다시 kernel32 임포트를 살펴보겠습니다

SetLastError 또는 GetLastError가 존재하지 않습니다
두 파일이 제대로 작동할 것이라는 확인

IDA HexRays 디컴파일러

IDA 디버거

Ghidra

ApiMonitor

이는 모든 정적 분석 도구가 조작될 수 있는 IAT에 기록된 API 이름에 의존하기 때문입니다.
ApiMonitor의 경우 IAT 후킹을 사용하기 때문에 동일한 문제가 존재합니다.
반면에 x64dbg와 같은 도구의 경우 표시되는 API 이름은 실제로 호출된 내용에만 의존합니다(IAT에 기록된 내용이 아님).

.cobf라는 새로운 rwx 섹션을 생성합니다.git clone https://github.com/d35ha/CallObfuscator로 소스를 가져옵니다.