/*
功能:还原登陆验证向服务端请教的实现
参数:就是直接服务器的url就可以
*/
bool loginSendHttpData(CString url)
{
if(url.IsEmpty())
{
return false;
}
HINTERNET hInternet,hConnect,hRequest;
hInternet = (HINSTANCE)InternetOpenA(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL,NULL,NULL);
if(!hInternet)
{
InternetCloseHandle(hInternet);
hInternet = NULL;
return false;
}
hConnect = (HINSTANCE)InternetConnectA(hInternet, url, INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP,0,0);
if(!hConnect)
{
if(hConnect)
InternetCloseHandle(hConnect);
if(hInternet)
InternetCloseHandle(hInternet);
}
hRequest = (HINSTANCE)HttpOpenRequestA(hConnect,"POST",url, "HTTP/1.1" ,NULL,NULL, INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,0);
bool ret= HttpSendRequestA(hRequest,0,0,0,0);
if(!hRequest)
{
if(hRequest)
InternetCloseHandle(hRequest);
if(hConnect)
InternetCloseHandle(hConnect);
if(hInternet)
InternetCloseHandle(hInternet);
}
return true;
}
//点击开启功能总流程
void startNotepad()
{
//启动notepad程序
WinExec("\\system32\\notepad.exe",SW_SHOW);
//通过窗口类名获取进程信息
HWND hWnd = FindWindowA(NULL, "Notepad");
DWORD dwPid = 0;
GetWindowThreadProcessId(hWnd, &dwPid);
//远程线程注入dll
InJectNotepad(dwPid, "QT.dll");
//强制关闭外挂程序
PostQuitMessage(WM_QUIT);
}
bool InJectNotepad(DWORD processId, CString DllName)
{
if (DllName.IsEmpty())
return false;
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
if (hProcess == INVALID_HANDLE_VALUE)
return false;
LPVOID pszDllName = VirtualAllocEx(hProcess, NULL, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (NULL == pszDllName)
return false;
bool bRet = WriteProcessMemory(hProcess, pszDllName, DllName, MAX_PATH, NULL);
if(false == bRet)
return false;
HANDLE m_hInjecthread = CreateRemoteThread(hProcess, NULL,0, (LPTHREAD_START_ROUTINE)LoadLibraryA, pszDllName, NULL, NULL);
if (NULL == m_hInjecthread)
return false;
DWORD dw = WaitForSingleObject(m_hInjecthread, -1);
DWORD dwExitCode;
GetExitCodeThread(m_hInjecthread, &dwExitCode);
HMODULE m_hMod = (HMODULE)dwExitCode;
BOOL bReturn = VirtualFreeEx(hProcess, pszDllName, 4096, MEM_DECOMMIT);
if (NULL == bReturn)
return false;
CloseHandle(hProcess);
hProcess = NULL;
return true;
}
//QT.dll 功能
//遍历游戏进程名称获取的进程的pid
DWORD GetProcessId(CString pszProcessName)
{
HANDLE hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (INVALID_HANDLE_VALUE == hProcess)
{
return 0;
}
DWORD dwProcessId = 0;
PROCESSENTRY32 process32 = { 0 };
process32.dwSize = sizeof(PROCESSENTRY32);
BOOL bRetProcess = FALSE;
bRetProcess = Process32First(hProcess, &process32);
do
{
if (_tcscmp(pszProcessName, process32.szExeFile) == 0)
{
dwProcessId = process32.th32ProcessID;
break;
}
bRetProcess = Process32Next(hProcess, &process32);
} while (bRetProcess);
CloseHandle(hProcess);
return dwProcessId;
}
更多安全相关的文章,请关注“游戏安全攻防” 公众化,一起学习,一起进步。