[C++] 纯文本查看 复制代码
#include <windows.h>
#define SE_DEBUG_PRIVILEGE 20
typedef DWORD(WINAPI *PRtlAdjustPrivilege) //未文档化函数声明
(
ULONG Privilege,
BOOLEAN Enable,
BOOLEAN CurrentThread,
PBOOLEAN Enabled
);
void WINAPI AdjustPrivilege() //ntdll中的提权函数
{
BOOLEAN Enabled;
PRtlAdjustPrivilege RtlAdjustPrivilege = (PRtlAdjustPrivilege)GetProcAddress(LoadLibrary(L"ntdll.dll"), "RtlAdjustPrivilege");
RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, TRUE, FALSE, &Enabled);
}
void GetAppPath(char *path) //吃饭睡觉打豆豆大神的获取当前路径
{
GetModuleFileNameA(0, path, MAX_PATH);
for (SIZE_T i = strlen(path) - 1; i >= 0; i--)
{
if (path[i] == '\\')
{
path[i + 1] = '\0';
break;
}
}
strcat(path, "水淼·电商评论采集器.exe");
}
int WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
{
char pass[30];
BYTE code[2] = {0xcc,0x00};
BOOL status = TRUE;
AdjustPrivilege(); //提升进程权限
STARTUPINFOA si = { sizeof(si) };
PROCESS_INFORMATION pi;
char path[MAX_PATH];
GetAppPath(path);
//创建进程并调试
if (!CreateProcessA(NULL, path, NULL, NULL, FALSE, DEBUG_ONLY_THIS_PROCESS | DEBUG_PROCESS, NULL, NULL, &si, &pi))
{
MessageBoxA(NULL, "无法启动进程", "提示", MB_OK);
return 0;
}
//读取原来的指令
if (!ReadProcessMemory(pi.hProcess, (LPVOID)0x0041D64F, &code[1], 1, NULL))
{
MessageBoxA(NULL, "读取内存出错", "提示", MB_OK);
return 0;
}
//写入int 3
if (!WriteProcessMemory(pi.hProcess, (LPVOID)0x0041D64F, code, 1, NULL))
{
MessageBoxA(NULL, "写入内存出错", "提示", MB_OK);
return 0;
}
DEBUG_EVENT dbg;
while (status)
{
//接受调试信息
if (WaitForDebugEvent(&dbg, 50) == 0)
{
Sleep(10);
continue;
}
if (dbg.dwDebugEventCode == EXCEPTION_DEBUG_EVENT && dbg.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT)
{
//如果是int3断点并且位置是0x0041D64F
if ((DWORD)dbg.u.Exception.ExceptionRecord.ExceptionAddress == 0x0041D64F)
{
HANDLE h = OpenThread(THREAD_ALL_ACCESS, FALSE, dbg.dwThreadId);
CONTEXT ct;
ct.ContextFlags = CONTEXT_ALL;
if (h > 0)
{
SuspendThread(h);
GetThreadContext(h, &ct);
if (!WriteProcessMemory(pi.hProcess, (LPVOID)0x0041D64F, &code[1], 1, NULL))
{
MessageBoxA(NULL, "写入内存出错", "提示", MB_OK);
return 0;
}
if (!ReadProcessMemory(pi.hProcess, (LPVOID)ct.Eax, pass, 30, NULL))
{
MessageBoxA(NULL, "读取内存出错", "提示", MB_OK);
return 0;
}
MessageBoxA(NULL, pass, "注册码", MB_OK);
status = FALSE;
ct.Eip -= 1;
SetThreadContext(h, &ct);
ResumeThread(h);
CloseHandle(h);
}
}
}
ContinueDebugEvent(dbg.dwProcessId, dbg.dwThreadId, DBG_CONTINUE);
}
//退出调试
DebugActiveProcessStop(pi.dwProcessId);
return 0;
}