首页
社区
课程
招聘
[求助]注入疑惑
发表于: 2018-3-18 13:38 3892

[求助]注入疑惑

2018-3-18 13:38
3892
//首先挂起方式启动游戏
//当时主线程的入口就是游戏的线程入口
//挂起时,EAX寄存器就是程序的入口(OEP)
//修改EAX寄存器到我们的邪恶内存中(push XXXXXX,Call LoadLibraryA 把邪恶内存清理干净 jmp 原始的OEP)

//这种注入对于游戏只有单进程的游戏能注入

//不过现在大多数游戏都是一个登录器一个游戏端双进程的游戏,这种注入就显得无力了,请问有啥方法能直接注入到游戏端里面吗,想得头都大了

BOOL CreatProcessInsertDLL(const TCHAR *lpApplicationName,

const TCHAR *lpDLLName,
const TCHAR *lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
LPVOID lpEnvironment,
const TCHAR *lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation)

{
try
{
//(1)创建进程并暂停
BOOL IsRet = ::CreateProcess(lpApplicationName,
(LPSTR)lpCommandLine,
lpProcessAttributes, lpThreadAttributes,
bInheritHandles,
CREATE_SUSPENDED,
lpEnvironment,
lpCurrentDirectory,
lpStartupInfo,
lpProcessInformation);
if (IsRet == FALSE)
{
TRACE(TEXT("CreateProcess GetLastError :%d"), GetLastError());
}
CONTEXT conxt = { 0 };
conxt.ContextFlags = CONTEXT_FULL; //**
//获取到EXE的入口地址
GetThreadContext(lpProcessInformation->hThread, &conxt);

    TRACE(TEXT("EXE入口地址: %08X"), conxt.Eax);
    DWORD dwEXEPoint = conxt.Eax;  //保存入口点地址

    LPVOID lpMemoryAddress = VirtualAllocEx(lpProcessInformation->hProcess,
        0,
        0x1000,
        MEM_COMMIT,
        PAGE_EXECUTE_READWRITE);

    TRACE(TEXT("DLL入口地址: %08X"), lpMemoryAddress);

    DWORD dwWritePos = 0; //写入的字节数
    DWORD dwPos = 0;
    //写入DLL的路径
    WriteProcessMemory(lpProcessInformation->hProcess,
        lpMemoryAddress,
        lpDLLName,
        lstrlen(lpDLLName),
        &dwPos);

    dwWritePos += dwPos;
    char StrZero = 0;

    WriteProcessMemory(lpProcessInformation->hProcess,
        LPBYTE((DWORD)lpMemoryAddress + dwWritePos),
        &StrZero,
        sizeof(char),
        &dwPos);     //字符串构建完毕

    dwWritePos += dwPos;
    //修改入口
    conxt.Eax = (DWORD)lpMemoryAddress + dwWritePos;
    SetThreadContext(lpProcessInformation->hThread, &conxt);
    //push LoadLibraryA参数
    BYTE PUSHCode[5];
    PUSHCode[0] = 0x68;   //push
    *(DWORD*)&PUSHCode[1] = (DWORD)lpMemoryAddress; //DLL名称起始位置
    WriteProcessMemory(lpProcessInformation->hProcess,
        LPBYTE((DWORD)lpMemoryAddress + dwWritePos),
        PUSHCode,
        sizeof(PUSHCode),
        &dwPos);
    dwWritePos += dwPos;  //Push xxxx
    HMODULE hModule = LoadLibrary(TEXT("Kernel32.dll"));
    //call LoadLibraryW
    BYTE CALLCode[5];
    DWORD dwLoadLibraryWAddress = (DWORD)GetProcAddress(hModule, "LoadLibraryA");
    CALLCode[0] = 0xE8;
    //TRACE(TEXT("dwLoadLibraryWAddress = %08X,CodeAddress = %08X"),dwLoadLibraryWAddress,(DWORD)lpMemoryAddress + dwWritePos);
    dwLoadLibraryWAddress = dwLoadLibraryWAddress - ((DWORD)lpMemoryAddress + dwWritePos) - 0x5; //XXXX跳转地址
    *(DWORD*)&CALLCode[1] = (DWORD)dwLoadLibraryWAddress;
    WriteProcessMemory(lpProcessInformation->hProcess,
        LPBYTE((DWORD)lpMemoryAddress + dwWritePos),
        CALLCode,
        sizeof(CALLCode),
        &dwPos);

    dwWritePos += dwPos;

    //jmp 程序入口点
    BYTE JMPCode[5];
    DWORD dwPoint = dwEXEPoint - ((DWORD)lpMemoryAddress + dwWritePos) - 0x5;
    JMPCode[0] = 0xE9;
    *(DWORD*)&JMPCode[1] = dwPoint;
    WriteProcessMemory(lpProcessInformation->hProcess,
        LPBYTE((DWORD)lpMemoryAddress + dwWritePos),
        JMPCode,
        sizeof(JMPCode),
        &dwPos);

    ::ResumeThread(lpProcessInformation->hThread);
    Sleep(6000);
    //覆盖缓冲区
    BYTE DeleteBuffer[0x1000] = { 0 };
    WriteProcessMemory(lpProcessInformation->hProcess,
        LPBYTE(lpMemoryAddress),
        DeleteBuffer,
        sizeof(DeleteBuffer),
        &dwPos);

    //释放缓冲区
    VirtualFreeEx(lpProcessInformation->hProcess,
        lpMemoryAddress,
        0x1000,
        PAGE_EXECUTE_READWRITE);

    return IsRet;
}
catch (...)
{
    TRACE(TEXT("CreatProcessInsertDLL() 发生异常"));
}
return FALSE;

}


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 429
活跃值: (393)
能力值: ( LV6,RANK:81 )
在线值:
发帖
回帖
粉丝
2
hook  createprocessinternalw  然后再用相同方法  来进行可继承注入?
2018-3-18 14:29
0
雪    币: 12848
活跃值: (9142)
能力值: ( LV9,RANK:280 )
在线值:
发帖
回帖
粉丝
3
双进程一般用劫持或LSP注入
2018-3-18 15:04
0
雪    币: 576
活跃值: (2035)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
全局钩子
2018-3-18 20:20
0
雪    币: 123
活跃值: (316)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
全局注入WH_CBT,有惊喜哟
2018-3-22 01:01
0
游客
登录 | 注册 方可回帖
返回
//