Implement tấn công

DLL injection

Tạo DLL độc hại hiển thị thông báo Meow from evil.dll! biên dịch từ đoạn code sau:

#include <windows.h>
#pragma comment (lib, "user32.lib")
BOOL APIENTRY DllMain(HMODULE hModule, DWORD nReason, LPVOID lpReserved) {
switch (nReason) {
case DLL_PROCESS_ATTACH:
MessageBox(
NULL,
"Meow from evil.dll!",
"=^..^=",
MB_OK
);
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}

Phần Code c++ tạo inj.exe để injection

Khởi chạy win32calc.exe và chạy chương trình inject vào process đó

Xác minh DLL độc hại đã được đưa vào sử dụng Process Hacker

Detection: kiểm tra danh sách các module import và tìm các vùng nhớ có quyền đọc ghi của process

PE injection

Code triển khai: https://github.com/ollahneew/DLL-Attacks/blob/main/pe_inj.cpparrow-up-right

Detection:

Xem xét Event số 8 trong Sysmon

DLL Side-loading

  • Thủ thuật chiếm đoạt thứ tự tìm kiếm DLL của một ứng dụng hợp lệ.

  • Lợi dụng các tệp manifest được cấu hình kém bằng cách đặt một DLL độc hại trùng tên với một DLL hợp pháp ở vị trí ưu tiên mà ứng dụng sẽ load nó lên trước DLL hợp lệ

GUP.exe được sử dụng để xác minh các bản cập nhật cho Notepad++

Áp dụng Filter trong Procmon, sẽ tìm thấy dll này. libcurlarrow-up-right là một thư viện được sử dụng để kết hợp curl vào mã.

Khi rename file này, sẽ gặp lỗi khi mở ứng dụng

Như vậy, nếu không có DLL đó, nó sẽ gây ra lỗi trong ứng dụng

Kiểm tra Import Address Table (IAT) trong GUP.exe sử dụng dumpbin /IMPORTS.

Chỉ có 4 hàm có trong IAT trong GUP.exe, vì vậy chúng ta có thể triển khai chúng.

Thay đổi cấu hình trong file config.xml để Notepad++ luôn mở GUP.exe mỗi khi chạy: (Path: C:\Users\Administrator\AppData\Roaming\Notepad++)

Sửa thành

Tạo DLL độc hại từ các file dllmainarrow-up-rightSource.defarrow-up-right sử dụng Visual Studio

Đổi tên DLL gốc và thay thế nó. Khi mở Notepad++, nó sẽ hiển thị như vậy.

Detection

  • Kiểm tra các import DLL, Kiểm tra các process có kết nối mạng bất thường, tạo dLL whitelist để theo dõi các giá trị hash của DLL được sử dụng trên hệ thống

Tham khảo:

https://cocomelonc.github.io/tutorial/2021/09/20/malware-injection-2.htmlarrow-up-right

https://www.letsdefend.io/blog/process-injection-detection-with-sysmonarrow-up-right

https://www.ired.team/offensive-security/code-injection-process-injection/pe-injection-executing-pes-inside-remote-processesarrow-up-right

https://medium.com/@mateus.tesser/dll-proxying-and-dll-side-loading-in-notepad-and-why-this-bypass-some-defenses-87bd9f7211f1arrow-up-right

Last updated