本文为看雪论坛优秀文章
看雪论坛作者ID:寒江独钓_
一、编译源码
程序源代码如下:
//子进程要执行的代码
void ChildProc()
{
MessageBox(NULL, L"This is a child process!", L"DebugMe2", MB_OK);
ExitProcess(0);
}
//主函数
void _tmain(int argc, TCHAR *argv[])
{
TCHAR szPath[MAX_PATH] = { 0, };
STARTUPINFO si = { sizeof(STARTUPINFO), };
PROCESS_INFORMATION pi = { 0, };
CONTEXT ctx = { 0, };
_tprintf(L"This is a parent process!n");
if (!GetModuleFileName(NULL, szPath, sizeof(TCHAR) * MAX_PATH))
{
printf("GetModuleFileName() failed! [%d]n", GetLastError());
return;
}
// 创建子进程
if (!CreateProcess(
szPath,
NULL,
NULL,
NULL,
FALSE,
CREATE_SUSPENDED,
NULL,
NULL,
&si,
&pi))
{
printf("CreateProcess() failed! [%d]n", GetLastError());
return;
}
// 修改EIP
ctx.ContextFlags = CONTEXT_FULL;
if (!GetThreadContext(pi.hThread, &ctx))
{
printf("GetThreadContext() failed! [%d]n", GetLastError());
return;
}
ctx.Eip = (DWORD)ChildProc;
if (!SetThreadContext(pi.hThread, &ctx))
{
printf("SetThreadContext() failed! [%d]n", GetLastError());
return;
}
// 恢复线程
if (-1 == ResumeThread(pi.hThread))
{
printf("ResumeThread() failed! [%d]n", GetLastError());
return;
}
//等待返回
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
二、程序编译好以后,我们使用OD进行调试分析

调用CreateProcessW以挂起方式创建子进程。



修改子进程的主线程的CONTEXT结构体中的EIP的值为ChildProc,然后调用SetThreadContext进行设置。



点击确定后子程序结束运行并返回。

三、实时调试模式



得到的结果为400。


修改并保存




四、总结
看雪ID:寒江独钓_
https://bbs.pediy.com/user-home-941725.htm

# 往期推荐


球分享

球点赞

球在看

点击“阅读原文”,了解更多!
原文始发于微信公众号(看雪学苑):病毒木马常用手段之自我创建