博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
写其他进程的环境变量
阅读量:6821 次
发布时间:2019-06-26

本文共 3025 字,大约阅读时间需要 10 分钟。

  hot3.png

#include 
#include
#include
#include
#include
DWORD GetParentProcessId(DWORD pid){ DWORD ppid = (DWORD)(-1); HANDLE hProcessSnap; PROCESSENTRY32 pe32; hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); assert(hProcessSnap != INVALID_HANDLE_VALUE); pe32.dwSize = sizeof( PROCESSENTRY32 ); BOOL bResult = Process32First( hProcessSnap, &pe32 ); assert(bResult != FALSE); do { if (pid == pe32.th32ProcessID) { ppid = pe32.th32ParentProcessID; break; } } while( Process32Next( hProcessSnap, &pe32 ) ); CloseHandle( hProcessSnap ); return( ppid );}DWORD ppid(VOID){ return GetParentProcessId( GetCurrentProcessId() );}typedef struct _RemoteParam { DWORD funcptr; BYTE Param1[64]; BYTE Param2[64];} RemoteParam, *PRemoteParam;typedef int (WINAPI *PFN_MessageBox)(HWND, LPCTSTR, LPCTSTR, DWORD);typedef BOOL (WINAPI *PFN_SetEnvironmentVariable)(LPCTSTR, LPCTSTR);DWORD WINAPI threadProc(LPVOID lpParam){ RemoteParam *pRP = (RemoteParam *)lpParam; PFN_SetEnvironmentVariable pfnSetEnvironmentVariable = (PFN_SetEnvironmentVariable)pRP[0].funcptr; pfnSetEnvironmentVariable(pRP[0].Param1, pRP[0].Param2); PFN_MessageBox pfnMessageBox = (PFN_MessageBox)pRP[1].funcptr; pfnMessageBox(NULL, pRP[1].Param1, pRP[1].Param2, 0); return 0;}int main(int argc, char *argv[]){ DWORD dwProcessId = ppid(); assert(dwProcessId != (DWORD)(-1)); HANDLE hTargetProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId); assert(hTargetProcess != NULL); DWORD dwMemSize = 4096; LPVOID pRemoteThread = VirtualAllocEx(hTargetProcess, 0, dwMemSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE) ; assert(pRemoteThread != NULL); BOOL bResult = WriteProcessMemory(hTargetProcess, pRemoteThread, threadProc, dwMemSize, NULL) ; assert(bResult != FALSE); RemoteParam RemoteParams[2] = {
{0}}; HMODULE hUser32 = LoadLibrary("User32.dll"); HMODULE hKernel32 = LoadLibrary("Kernel32.dll"); RemoteParams[0].funcptr = (DWORD)GetProcAddress(hKernel32, "SetEnvironmentVariableA"); strcpy(RemoteParams[0].Param1, "__var"); strcpy(RemoteParams[0].Param2, "hello"); RemoteParams[1].funcptr = (DWORD)GetProcAddress(hUser32, "MessageBoxA"); strcpy(RemoteParams[1].Param1, "www.bathome.net"); strcpy(RemoteParams[1].Param2, "hello"); dwMemSize = sizeof(RemoteParams); LPVOID pRemoteParam = VirtualAllocEx(hTargetProcess, 0, dwMemSize, MEM_COMMIT, PAGE_READWRITE); assert(pRemoteParam != NULL); bResult = WriteProcessMemory(hTargetProcess, pRemoteParam, RemoteParams, dwMemSize, NULL) ; assert(bResult != FALSE); HANDLE hRemoteThread = CreateRemoteThread(hTargetProcess, NULL, 0, pRemoteThread, pRemoteParam, 0, NULL); assert(hRemoteThread != NULL); CloseHandle(hRemoteThread); CloseHandle(hTargetProcess); return 0;}

出处:

转载于:https://my.oschina.net/plp626/blog/312660

你可能感兴趣的文章
团队开发------第一次冲刺第4天
查看>>
原生模态框,遮罩层
查看>>
R对term进行层次聚类完整实例(tm包)
查看>>
SQL Server创建用户并分配权限
查看>>
python 反转列表的3种方式
查看>>
[NOIP2002]字串变换 T2 双向BFS
查看>>
linux上我认为最适合编程和使用的字体
查看>>
go环境import cycle not allowed问题处理
查看>>
GZFramework.DB.Core初始化
查看>>
Markdown 语法
查看>>
Hadoop下各技术应用场景
查看>>
django template
查看>>
Tomcat乱码问题
查看>>
HDU 1564 Play a game
查看>>
URL
查看>>
053_Salesforce Lightning与Classic对比
查看>>
volley3--Volley类
查看>>
topcoder srm 620 div1
查看>>
20151124001 关闭C#主窗体弹出是否关闭对话框
查看>>
java 判断元素是否在数组内
查看>>