流沙团
进程继承操作的传递控制
2018-1-6 流沙团


主要是两个子进程之间的控制:



0x1 代码一



 


// 20180106_01.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>

int main(int argc, char* argv[])
{
//printf("Hello World!\n");

//开启IE

/*
BOOL CreateProcess(
LPCTSTR lpApplicationName, // name of executable module
LPTSTR lpCommandLine, // command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
BOOL bInheritHandles, // handle inheritance option
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCTSTR lpCurrentDirectory, // current directory name
LPSTARTUPINFO lpStartupInfo, // startup information
LPPROCESS_INFORMATION lpProcessInformation // process information
);
*/
//准备参数
TCHAR lpCommandLine[] = "C://Program Files//Internet Explorer//IEXPLORE.EXE";

SECURITY_ATTRIBUTES pa;
pa.nLength = sizeof(SECURITY_ATTRIBUTES);
pa.lpSecurityDescriptor = NULL;
pa.bInheritHandle = TRUE;

SECURITY_ATTRIBUTES ta;
ta.nLength =sizeof(SECURITY_ATTRIBUTES);
ta.lpSecurityDescriptor = NULL;
ta.bInheritHandle = TRUE;

STARTUPINFO si={0};
si.cb = sizeof(STARTUPINFO);

PROCESS_INFORMATION pi;

CreateProcess(NULL,
lpCommandLine,
&pa,
&ta,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&si,
&pi);

printf("输出IE进程的句柄参数: %x,%x\n",pi.hProcess,pi.hThread);


Sleep(3000);

//开启zzz 控制IE进程
TCHAR szBuffer[100] = {0};
sprintf(szBuffer,"c://zzz.exe %x %x",pi.hProcess,pi.hThread);

printf("检测运行的命令: %s \n",szBuffer);

STARTUPINFO si_z={0};
si_z.cb = sizeof(STARTUPINFO);

PROCESS_INFORMATION pi_z;

CreateProcess(NULL,
szBuffer,
NULL,
NULL,
TRUE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&si_z,
&pi_z);

printf("子线程信息: %x %x\n",pi_z.hProcess, pi_z.hThread);


return 0;
}



 



 



0x2 代码二


// 20180106_02.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>

int main(int argc, char* argv[])
{
//printf("Hello World!\n");
//接受信息,控制IE


DWORD dwThreadHandle = 0;
DWORD dwProcessHandle = 0;

sscanf(argv[1],"%x",&dwProcessHandle);
sscanf(argv[2],"%x",&dwThreadHandle);

printf("process: %x \n",dwProcessHandle);
printf("thread: %x \n",dwThreadHandle);

//开始操作IE
Sleep(2000);
printf("挂起主线程\n");
::SuspendThread((HANDLE)dwThreadHandle);

Sleep(5000);
::ResumeThread((HANDLE)dwThreadHandle);
printf("恢复主线程\n");

Sleep(5000);

//关闭
TerminateProcess((HANDLE)dwProcessHandle,1);
WaitForSingleObject((HANDLE)dwProcessHandle,INFINITE);
printf("关闭进程ID : %x \n",dwProcessHandle);

getchar();

return 0;
}



 



 

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容