Skip to content

Commit

Permalink
以取父进程PID枚举模块判断是否为QQ的子进程
Browse files Browse the repository at this point in the history
  • Loading branch information
sysrom committed Mar 30, 2024
1 parent 76e628f commit 483b150
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 9 deletions.
48 changes: 44 additions & 4 deletions HijackMethod/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <MinHook.h>
#include <tlhelp32.h>
#include <psapi.h>
#include <tchar.h>
#include "nt.h"
#include "scanner.h"
#define Sig_text "57 41 56 41 55 41 54 56 57 55 53 48 81 ec ?? ?? ?? ?? 0f 29 bc 24 ?? ?? ?? ?? 0f 29 b4 24 ?? ?? ?? ?? 48 8b 05 ?? ?? ?? ?? 48 31 e0 48 89 84 24 ?? ?? ?? ?? b9"
Expand Down Expand Up @@ -30,6 +32,47 @@ void Exploit() {
}
}

DWORD GetParentProcessID() {
HANDLE hSnapshot;
PROCESSENTRY32 pe32;
DWORD ppid = 0, pid = GetCurrentProcessId();

hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return 0;

pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapshot, &pe32)) {
do {
if (pe32.th32ProcessID == pid) {
ppid = pe32.th32ParentProcessID;
break;
}
} while (Process32Next(hSnapshot, &pe32));
}

CloseHandle(hSnapshot);
return ppid;
}

bool IsParentQQ() {
DWORD parentPID = GetParentProcessID();
TCHAR szProcessName[MAX_PATH] = TEXT("U N K N O W N");
bool isExplorer = false;

HANDLE hParentProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, parentPID);
if (hParentProcess) {
HMODULE hMod;
DWORD cbNeeded;
if (EnumProcessModules(hParentProcess, &hMod, sizeof(hMod), &cbNeeded)) {
GetModuleBaseName(hParentProcess, hMod, szProcessName, sizeof(szProcessName) / sizeof(TCHAR));
isExplorer = (_tcsicmp(szProcessName, TEXT("QQ.exe")) == 0);
}
CloseHandle(hParentProcess);
}

return isExplorer;
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
Expand All @@ -40,10 +83,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
std::wstring processName(MAX_PATH, L'\0');
GetModuleFileNameEx(hProc, nullptr, &processName[0], MAX_PATH);
DisableThreadLibraryCalls(hinstDLL);
if (processName.find(L"QQ.exe") != std::wstring::npos) {
if (wcsstr(GetCommandLine(), L"--") != NULL) {
return true;
}
if (IsParentQQ()!=true) {
Exploit();
return true;
}
Expand Down
50 changes: 45 additions & 5 deletions HijackMethod_x86/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "scanner.h"
#include <Psapi.h>
#include <tlhelp32.h>
#include <psapi.h>
#include <tchar.h>
#define Sig_text "75 ?? e8 ?? ?? ?? ?? 84 c0 0f 85 ?? ?? ?? ?? 68 ?? ?? ?? ?? e8"


Expand All @@ -22,6 +24,47 @@ void Exploit() {
}
}

DWORD GetParentProcessID() {
HANDLE hSnapshot;
PROCESSENTRY32 pe32;
DWORD ppid = 0, pid = GetCurrentProcessId();

hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return 0;

pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapshot, &pe32)) {
do {
if (pe32.th32ProcessID == pid) {
ppid = pe32.th32ParentProcessID;
break;
}
} while (Process32Next(hSnapshot, &pe32));
}

CloseHandle(hSnapshot);
return ppid;
}

bool IsParentQQ() {
DWORD parentPID = GetParentProcessID();
TCHAR szProcessName[MAX_PATH] = TEXT("U N K N O W N");
bool isExplorer = false;

HANDLE hParentProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, parentPID);
if (hParentProcess) {
HMODULE hMod;
DWORD cbNeeded;
if (EnumProcessModules(hParentProcess, &hMod, sizeof(hMod), &cbNeeded)) {
GetModuleBaseName(hParentProcess, hMod, szProcessName, sizeof(szProcessName) / sizeof(TCHAR));
isExplorer = (_tcsicmp(szProcessName, TEXT("QQ.exe")) == 0);
}
CloseHandle(hParentProcess);
}

return isExplorer;
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
Expand All @@ -32,10 +75,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
std::wstring processName(MAX_PATH, L'\0');
GetModuleFileNameEx(hProc, nullptr, &processName[0], MAX_PATH);
DisableThreadLibraryCalls(hinstDLL);
if (processName.find(L"QQ.exe") != std::wstring::npos) {
if (wcsstr(GetCommandLine(), L"--") != NULL) {
return true;
}
if (IsParentQQ()!=true) {
Exploit();
return true;
}
Expand Down

0 comments on commit 483b150

Please sign in to comment.