找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 613|回复: 2

昭姐每天一练- 经典注入游戏1(远程线程注入)

[复制链接]

30

主题

1

回帖

0

积分

版主

积分
0
发表于 2013-6-8 10:48:42 | 显示全部楼层 |阅读模式

// RemoteThread.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include <windows.h>
#include <string>
#include "stdio.h"
#include <iostream>
using namespace std;

#define DEF_BUF_SIZE 1024

// 用于存储注入模块DLL的路径全名
char szDllPath[DEF_BUF_SIZE] = {0} ;

// 使用远程线程向指定ID的进程注入模块
BOOL InjectModuleToProcessById ( DWORD dwProcessId )
{
    if ( dwProcessId == 0 )
        return FALSE ;

    // 打开进程
    HANDLE hProcess = OpenProcess ( PROCESS_ALL_ACCESS, FALSE, dwProcessId ) ;
    if ( hProcess == NULL )
        return FALSE ;

    //申请存放文件名的空间
    UINT    nLen = (UINT)strlen ( szDllPath ) + 1;
    LPVOID    lpRemoteDllName = VirtualAllocEx ( hProcess, NULL, nLen, MEM_COMMIT, PAGE_READWRITE ) ;
    if ( lpRemoteDllName == NULL )
    {
        printf ( "[ERROR]VirtualAllocEx(%d)\n", GetLastError() );
        return FALSE ;
    }

    //把dll文件名写入申请的空间
    if ( WriteProcessMemory ( hProcess, lpRemoteDllName, szDllPath, nLen, NULL) == FALSE )
    {
        printf ( "[ERROR]WriteProcessMemory(%d)\n", GetLastError() );
        return FALSE ;
    }

    //获取动态链接库函数地址
    HMODULE hModule = GetModuleHandle ( L"kernel32.dll" ) ;
    LPTHREAD_START_ROUTINE fnStartAddr = ( LPTHREAD_START_ROUTINE )GetProcAddress(hModule,"LoadLibraryA") ;
    if ( (DWORD)fnStartAddr == 0 )
    {
        printf ( "[ERROR]GetProcAddress(%d)\n", GetLastError() );
        return FALSE ;
    }

    //创建远程线程
    HANDLE hRemoteThread = CreateRemoteThread ( hProcess, NULL, 0,fnStartAddr, lpRemoteDllName, 0, NULL ) ;
    if ( hRemoteThread == NULL )
    {
        printf ( "[ERROR]CreateRemoteThread(%d)\n", GetLastError() );
        return FALSE ;
    }

    // 等待远程线程结束
    if ( WaitForSingleObject ( hRemoteThread, INFINITE ) != WAIT_OBJECT_0 )
    {
        printf ( "[ERROR]WaitForSingleObject(%d)\n", GetLastError() );
        return FALSE ;
    }

    CloseHandle ( hRemoteThread ) ;
    CloseHandle ( hModule ) ;
    CloseHandle ( hProcess ) ;
    return TRUE ;
}

int _tmain(int argc, _TCHAR* argv[])
{
    // 取得当前工作目录路径
    GetCurrentDirectoryA ( DEF_BUF_SIZE, szDllPath ) ;

    // 生成注入模块DLL的路径全名
    strcat ( szDllPath, "\\mydll.dll" ) ;

    DWORD dwProcessId = 0 ;
    // 接收用户输入的目标进程ID
    while ( printf ( "请输入目标进程ID:" ) && cin >> dwProcessId && dwProcessId > 0 )
    {
        BOOL bRet = InjectModuleToProcessById ( dwProcessId ) ;
        printf ( bRet ? "注入成功!\n":"注入失败!\n") ;
    }
    return 0;
}

0

主题

38

回帖

0

积分

版主

积分
0
发表于 2013-6-11 09:47:07 | 显示全部楼层
不错,给顶了

0

主题

7

回帖

0

积分

新手上路

积分
0
发表于 2013-8-31 21:45:02 | 显示全部楼层
感谢,学习下!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-1 03:24 , Processed in 0.070358 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表