ほとんどのアンチウイルスとサンドボックスを回避できるトロイの木馬サンプル
以下、このトロイの木馬に関わる技術について説明します。shellcodeとローダーの2つの側面から解説します。
ローダー部分
1.アンチサンドボックス
周知のとおり、アンチサンドボックスの検出は通常、ホストのCPU、メモリ、ディスクなどの操作を対象としています。しかし、私は個人的にこの方法は適切ではないと考えます。なぜなら、一部のアンチウイルスやクラウドサンドボックスはアンチサンドボックス機能を検出し、敏感なAPIを監視して検知される恐れがあるからです。そこで私の考え方は、デスクトップのショートカットを検出することです。例えば、QQ、WeChat、DingTalkなど日常的に使用されるソフトウェアを検出して、クラウドサンドボックスを回避します。
2.ntdllのリロードとAPIの動的呼び出し
一般的なアンチウイルスの検出メカニズムは、いくつかの敏感なAPIにフックを仕掛けることです。そこで、ntdllのリロードとAPIの動的呼び出し技術を使用することで、フックを回避して機能を実現できます。ntdllのリロード部分では、システムディレクトリから元のntdll.dllを読み込み、現在のプロセス内でフックされたntdllのコードセグメント(.textセグメント)を元のコードに置き換えます。APIの動的呼び出しでは、対象DLLのエクスポートテーブルを走査し、ハッシュを使用して関数名を照合し、対象関数のアドレスを取得してポインタを使って実行します。
3.shellcodeとローダーの分離
shellcodeは、エンコードによるアンチウイルスの回避に加えて、ローダーと分離することもできます。shellcodeがexe内に存在しなければ、アンチウイルスが問題を検出するのはかなり難しくなります。
shellcode部分
shellcode部分では主に多層難読化処理を行います。使用するのはXOR+RC4+base64+macの多層処理で、最終的にはmacアドレス形式で存在します。これは、Windowsがmac形式の文字列に対して一定の寛容性を持っているためです。
使用方法
まずencode.cppを使用してshellcodeを暗号化します。shellcodeをexeに書き込む場合は、Unseparation_shellcode.cppのmac_shellcode配列に入れてください。パラメータ分離を実現したい場合は、私がコンパイルしたexe+shellcodeをそのまま実行すればOKです。
お読みいただきありがとうございます
English version
This is a Trojan sample that can bypass the vast majority of antivirus software and sandboxes. Below, I will explain the technologies involved in the Trojan, focusing on both the shellcode and the loader.
Loader Section
1. Anti-sandbox
It is well-known that the conventional detection of anti-sandbox functions is based on operations on the host's CPU, memory, hard disk, etc. However, I personally think this approach is not ideal because some antivirus software or cloud sandboxes will monitor anti-sandbox functions and keep an eye on sensitive APIs, which may lead to detection. Therefore, my idea is to detect desktop shortcuts, such as those for commonly used software like QQ, WeChat, and DingTalk, to evade cloud sandboxes. 
2. Overloading of ntdll and Dynamic Invocation of APIs
The detection mechanism of general anti-virus software is to hook some sensitive APIs. Therefore, we can bypass the hooks and achieve the function by using the ntdll overloading and dynamic API calling techniques. The ntdll overloading part involves loading the original ntdll.dll from the system directory and replacing the hooked ntdll code segment (.text segment) in the current process with the original code. The dynamic API calling is to traverse the export table of the target dll, match the function name using hash, obtain the address of the target function, and execute it using a pointer.
3. Separation of Shellcode and Loader
Besides encoding to bypass antivirus software, shellcode can also be separated from the loader. If the shellcode is not included in the exe file, it becomes quite difficult for antivirus software to detect any issues.
The shellcode section mainly undergoes multi-layer obfuscation processing, which involves XOR, RC4, base64, and MAC. The final output is in MAC address format, taking advantage of Windows' tolerance for MAC format strings.
Usage Method
First, use encode.cpp to encrypt the shellcode. If you write the shellcode into an exe file, please place it in the mac_shellcode array in Unseparation_shellcode.cpp. If you want to achieve parameter separation, you can run the compiled exe + shellcode directly.
Thank you for reading.