> For the complete documentation index, see [llms.txt](https://twentysick.gitbook.io/twentysick/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://twentysick.gitbook.io/twentysick/sharing/series-phat-minh-lai-cai-banh-xe/iis-native-module-nhung-la-backdoor/lam-sao-de-phan-tich-ma-doc-la-iis-native-module.md).

# Làm sao để phân tích mã độc là IIS Native Module

Viết được mã độc, vậy giờ làm sao để phân tích được mã độc ở dạng IIS Native Module nhỉ?

{% hint style="info" %}
Ném cho **Claude** hoặc **mấy con AI** cho nhanh. Thời đại nào rồi còn ngồi phân tích tay bo
{% endhint %}

## Phân tích tĩnh

#### Công cụ

* IDA Free (Decompiler)
* CFF Explorer (PE Analyst)

#### Nội dung

Mình sẽ thực hiện phân tích bằng các công cụ decompiler như IDA và Ghidra, rồi ngồi đọc chay thôi.

Tuy nhiên, sẽ có 1 số key word mà mình thường ưu tiên:

* Địa chỉ IP, domain C\&C
* Các API nhạy cảm như CreateProcess, RegCreateKeyEx,...

Bên cạnh đó, mình ngồi trace để tìm ra hàm có mùi không thơm (có thể tham khảo [*https://github.com/PwCUK-CTO/iis-helper-plugin*](https://github.com/PwCUK-CTO/iis-helper-plugin))

<figure><img src="https://3579869334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqj23826F0xExp2MNexN5%2Fuploads%2FR3nlMdkaRpT8X0VGnuua%2Fimage.png?alt=media&amp;token=452cc170-9d5f-4353-b09e-4711c5125da5" alt=""><figcaption></figcaption></figure>

## Phân tích động

#### Công cụ

* x64dbg (Debugger)
* Wireshark
* Process Monitor (ProcMon)
* Process Explorer (ProcExp)

#### Nội dung

Patch lại file thư viện đó với MAGICALBYTEEEEEEE để nó nhảy tại chỗ UwU

{% code expandable="true" %}

```
EB FE
```

{% endcode %}

<figure><img src="https://3579869334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqj23826F0xExp2MNexN5%2Fuploads%2FT5e6qX8jFUA3Ao6gPZjL%2Fimage.png?alt=media&amp;token=5691fe43-5512-45fd-9472-a0d43f9ff340" alt=""><figcaption><p><em>Trước khi patched</em></p></figcaption></figure>

<figure><img src="https://3579869334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqj23826F0xExp2MNexN5%2Fuploads%2FuyVPgyc6iGp516JEeRBu%2Fimage.png?alt=media&amp;token=ab577bd8-15ed-407d-ac6a-965a445e1fbb" alt=""><figcaption><p><em>Sau khi patched</em></p></figcaption></figure>

Tiếp theo, thực thi tiến trình *w3wp.exe* để thực hiện load ***Native Module** (Lưu ý: Cần nhanh tay tại cẩn thận bị tràn bộ nhớ nhóe)* và attach process vào x64dbg (đã cài plugin ScyllaHide)

<figure><img src="https://3579869334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqj23826F0xExp2MNexN5%2Fuploads%2FS734fIHUVeTTfUUGIOc3%2Fimage.png?alt=media&amp;token=f9d92225-4a6f-40cc-9628-44449176a861" alt=""><figcaption></figcaption></figure>

Đặt breakpoint tại đúng vị trí mình đã sửa 2 bytes

<figure><img src="https://3579869334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqj23826F0xExp2MNexN5%2Fuploads%2FyeZL1fan9ZuLmTC9eN7A%2Fimage.png?alt=media&amp;token=e3c48fe9-9c4c-4a52-8a68-679aa73c419a" alt=""><figcaption><p><em>Đặt breakpoint tại chỗ sửa 2 bytes</em></p></figcaption></figure>

Sửa lại 2 bytes và ***thực hiện debug bình thường thôi UwU***

<figure><img src="https://3579869334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqj23826F0xExp2MNexN5%2Fuploads%2FcWvuj5Cbz7HlqiDeZbFU%2Fimage.png?alt=media&amp;token=a0eb8c5d-40e8-4f37-a614-3082883ce587" alt=""><figcaption><p><em>Thực hiện sửa lại 2 bytes</em></p></figcaption></figure>

<figure><img src="https://3579869334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqj23826F0xExp2MNexN5%2Fuploads%2FCV3gPEt6iVWH7Y8oOjBa%2Fimage.png?alt=media&amp;token=5e4dcf48-3675-4250-ad71-e7af9c63c49a" alt=""><figcaption><p><em>Hiện trạng sau khi sửa</em></p></figcaption></figure>

<figure><img src="https://3579869334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqj23826F0xExp2MNexN5%2Fuploads%2FQvYPR4D7HqjLQExAn7s4%2Fimage.png?alt=media&amp;token=aa071cce-c18e-4ca4-9ecf-d8f98c26f111" alt=""><figcaption><p><em>Disassemble chuẩn, ban đầu chưa chỉnh sửa</em></p></figcaption></figure>
