远程注入法,简单写了一个:- #include <windows.h>
- #include <stdio.h>
- #include <tchar.h>
- #include <assert.h>
- #include <tlhelp32.h>
-
- 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;
- }
复制代码
E:\Projects\Inject>set
ALLUSERSPROFILE=D:\Documents and Settings\All Users
APPDATA=D:\Documents and Settings\root\Application Data
CLIENTNAME=Console
CommonProgramFiles=D:\Program Files\Common Files
COMPUTERNAME=POWERPC
ComSpec=D:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=D:
HOMEPATH=\Documents and Settings\root
LOGONSERVER=\\POWERPC
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
Path=D:\WINDOWS\system32;D:\WINDOWS;D:\WINDOWS\System32\Wbem;E:\MinGW\bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 37 Stepping 5, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=2505
ProgramFiles=D:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=D:
SystemRoot=D:\WINDOWS
TEMP=D:\DOCUME~1\root\LOCALS~1\Temp
TMP=D:\DOCUME~1\root\LOCALS~1\Temp
USERDOMAIN=POWERPC
USERNAME=root
USERPROFILE=D:\Documents and Settings\root
windir=D:\WINDOWS
E:\Projects\Inject>gcc -o conset.exe conset.c
E:\Projects\Inject>conset
E:\Projects\Inject>set
ALLUSERSPROFILE=D:\Documents and Settings\All Users
APPDATA=D:\Documents and Settings\root\Application Data
CLIENTNAME=Console
CommonProgramFiles=D:\Program Files\Common Files
COMPUTERNAME=POWERPC
ComSpec=D:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=D:
HOMEPATH=\Documents and Settings\root
LOGONSERVER=\\POWERPC
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
Path=D:\WINDOWS\system32;D:\WINDOWS;D:\WINDOWS\System32\Wbem;E:\MinGW\bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 37 Stepping 5, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=2505
ProgramFiles=D:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=D:
SystemRoot=D:\WINDOWS
TEMP=D:\DOCUME~1\root\LOCALS~1\Temp
TMP=D:\DOCUME~1\root\LOCALS~1\Temp
USERDOMAIN=POWERPC
USERNAME=root
USERPROFILE=D:\Documents and Settings\root
windir=D:\WINDOWS
__var=hello
E:\Projects\Inject> |