
generate EXE
#include <windows.h>#include <stdio.h>#include <stdlib.h>#include <string.h>int main(void) {printf("RT Operator, here I come!\n");getchar();return 0;}
@ECHO OFF//编译cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /Tcimplant.cpp /link /OUT:implant.exe /SUBSYSTEM:CONSOLE /MACHINE:x64
generate dll
当系统启动或终止进程或线程时,它会使用进程的第一个线程为每个加载的 DLL 调用入口点函数。 当 DLL 使用 LoadLibrary 和 FreeLibrary 函数加载或卸载 DLL 时,系统还会调用该函数的入口点函数。
https://learn.microsoft.com/zh-cn/windows/win32/dlls/dllmain
#include <Windows.h>#pragma comment (lib, "user32.lib")BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL moduleDWORD fdwReason, // reason for calling functionLPVOID lpvReserved ) // reserved{// Perform actions based on the reason for calling.switch( fdwReason ){case DLL_PROCESS_ATTACH://由于启动进程或调用 LoadLibrary,DLL 正在加载到当前进程的虚拟地址空间中。// Initialize once for each new process.// Return FALSE to fail DLL load.break;case DLL_THREAD_ATTACH://当前进程正在创建新线程。// Do thread-specific initialization.break;case DLL_THREAD_DETACH://线程正在完全退出。// Do thread-specific cleanup.break;case DLL_PROCESS_DETACH://DLL 正从调用进程的虚拟地址空间中卸载,因为它加载失败,或者引用计数已达到零,// (进程每次调用 LoadLibrary) 时,都会终止或调用 FreeLibrary 。if (lpvReserved != nullptr){break; // do not do cleanup if process termination scenario}// Perform any necessary cleanup.break;}return TRUE; // Successful DLL_PROCESS_ATTACH.}extern "C" {//导出函数__declspec(dllexport) BOOL WINAPI RunME(void) {MessageBox(NULL,"RT Operator, here I come!","RTO",MB_OK);return TRUE;}}
@ECHO OFFcl.exe /D_USRDLL /D_WINDLL implantDLL.cpp /MT /link /DLL /OUT:implant.dll
