通用 C# DLL 注入器injector(注入dll不限)
为了方便那些不懂或者不想用C++的同志,我把C++的dll注入器源码转换成了C#的,这是一个很简单实用的注入器,用到了CreateRemoteThread,WriteProcessMemory ,VirtualAllocEx这几个Api
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text; namespace GijSoft.DllInjection
{
public enum DllInjectionResult
{
DllNotFound,
GameProcessNotFound,
InjectionFailed,
Success
} public sealed class DllInjector
{
static readonly IntPtr INTPTR_ZERO = (IntPtr); [DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr OpenProcess(uint dwDesiredAccess, int bInheritHandle, uint dwProcessId); [DllImport("kernel32.dll", SetLastError = true)]
static extern int CloseHandle(IntPtr hObject); [DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); [DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetModuleHandle(string lpModuleName); [DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, uint flAllocationType, uint flProtect); [DllImport("kernel32.dll", SetLastError = true)]
static extern int WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, uint size, int lpNumberOfBytesWritten); [DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttribute, IntPtr dwStackSize, IntPtr lpStartAddress,
IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId); static DllInjector _instance; public static DllInjector GetInstance
{
get
{
if (_instance == null)
{
_instance = new DllInjector();
}
return _instance;
}
} DllInjector() { } public DllInjectionResult Inject(string sProcName, string sDllPath)
{
if (!File.Exists(sDllPath))
{
return DllInjectionResult.DllNotFound;
} uint _procId = ; Process[] _procs = Process.GetProcesses();
for (int i = ; i < _procs.Length; i++)
{
if (_procs[i].ProcessName == sProcName)
{
_procId = (uint)_procs[i].Id;
break;
}
} if (_procId == )
{
return DllInjectionResult.GameProcessNotFound;
} if (!bInject(_procId, sDllPath))
{
return DllInjectionResult.InjectionFailed;
} return DllInjectionResult.Success;
} bool bInject(uint pToBeInjected, string sDllPath)
{
IntPtr hndProc = OpenProcess((0x2 | 0x8 | 0x10 | 0x20 | 0x400), , pToBeInjected); if (hndProc == INTPTR_ZERO)
{
return false;
} IntPtr lpLLAddress = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA"); if (lpLLAddress == INTPTR_ZERO)
{
return false;
} IntPtr lpAddress = VirtualAllocEx(hndProc, (IntPtr)null, (IntPtr)sDllPath.Length, (0x1000 | 0x2000), 0X40); if (lpAddress == INTPTR_ZERO)
{
return false;
} byte[] bytes = Encoding.ASCII.GetBytes(sDllPath); if (WriteProcessMemory(hndProc, lpAddress, bytes, (uint)bytes.Length, ) == )
{
return false;
} if (CreateRemoteThread(hndProc, (IntPtr)null, INTPTR_ZERO, lpLLAddress, lpAddress, , (IntPtr)null) == INTPTR_ZERO)
{
return false;
} CloseHandle(hndProc); return true;
}
}
}
注意:使用时必须安装.netFramework
通用 C# DLL 注入器injector(注入dll不限)的更多相关文章
- 如何创建DLL,以及注入DLL
为了防止忘记,特记下 DLL的创建,在VS2017中选择dll的创建 // dllmain.cpp : Defines the entry point for the DLL application. ...
- 【资源分享】Dll Injector(DLL注入器)
*----------------------------------------------[下载区]----------------------------------------------* ...
- N种内核注入DLL的思路及实现
内核注入,技术古老但很实用.现在部分RK趋向无进程,玩的是SYS+DLL,有的无文件,全部存在于内存中.可能有部分人会说:"都进内核了.什么不能干?".是啊,要是内核中可以做包括R ...
- [转]N种内核注入DLL的思路及实现
内核注入,技术古老但很实用.现在部分RK趋向无进程,玩的是SYS+DLL,有的无文件,全部存在于内存中.可能有部分人会说:“都进内核了.什么不能干?”.是啊,要是内核中可以做包括R3上所有能做的事,软 ...
- Windows x86/ x64 Ring3层注入Dll总结
欢迎转载,转载请注明出处:http://www.cnblogs.com/uAreKongqi/p/6012353.html 0x00.前言 提到Dll的注入,立马能够想到的方法就有很多,比如利用远程线 ...
- 【windows核心编程】使用远程线程注入DLL
前言 该技术是指通过在[目标进程]中创建一个[远程线程]来达到注入的目的. 创建的[远程线程]函数为LoadLibrary, 线程函数的参数为DLL名字, 想要做的工作在DLL中编写. 示意图如下: ...
- 分析恶意驱动(进程启动apc注入dll)
一.前言 用IDA也有好些时间了,以前就只会用F5功能玩无壳无保护的裸驱动,感觉太坑了,这两天就开始看网上大牛的逆向. 今天记录一下sudami曾经逆向过的fuck.sys.第一遍自己走的时候漏掉了 ...
- [C#] - 注入DLL
原文:http://xyzlht.blog.163.com/blog/static/69301417200882834211787/ ) { MessageBox.Show("创建远程线程失 ...
- Hook任务栏时钟窗口(原理其实很简单,就是注入DLL到时钟窗口进程(explorer.exe))
用过一些日历软件的小伙伴应该都知道它们都实现了在时钟窗口上的Hook,也就是屏蔽了系统原有的功能,实现自己的功能 某日历软件Hook时钟窗口后的效果 经过一番研究,发现原理其实很简单,就是注入DLL到 ...
随机推荐
- 小明种苹果(续)第十七次CCF认证
小明种苹果(续)第十七次CCF认证 题目 原题链接 ](http://118.190.20.162/view.page?gpid=T93) 很高心,在现在CCF CSP可以下载自己当时的答卷了,也就是 ...
- dfs(最佳路径)
http://acm.hdu.edu.cn/showproblem.php?pid=1242 Rescue Time Limit: 2000/1000 MS (Java/Others) Memo ...
- WNMP环境搭建步骤 nginx1.4.3+php-5.3.27+mysql-5.5+RunHiddenConsole
安装目录:D:/webServer/所需软件: mysql-installer-community-5.5.34.0.msi 下载:http://cdn.mysql.com/D ...
- 基于spring boot2.0+spring security +oauth2.0+ jwt微服务架构
github地址:https://github.com/hankuikuide/microservice-spring-security-oauth2 项目介绍 该项目是一个演示项目,主要演示了,基于 ...
- django中配置MySql
1.配置字段 在setting文件中配置数据库字段:数据库需要提前手动创建好:语句(create database testdb charset "utf8";) DATABASE ...
- npm学习(一)之安装、更新以及管理npm版本
安装npm 安装前须知: npm是在Node中编写的,因此需要安装Node.js才能使用npm.可以通过Node.js网站安装npm,或者安装节点版本管理器NVM. 如果只是想开始探索npm,使用No ...
- luogu P1397 [NOI2013]矩阵游戏
传送门 题目中那两个递推式显然可以写成矩乘的形式,然后十进制快速幂即可.这里不再赘述 只有两个递推式,我们可以考虑一波推式子,首先第一行的元素应该分别是\(1,a+b,a^2+ab+b,a^3+a^2 ...
- Linux系统性能测试工具(八)——网络性能测试工具之netperf
本文介绍关于Linux系统(适用于centos/ubuntu等)的网络性能测试工具-iperf.磁盘io性能测试工具包括: iperf: netperf 参考链接:https://www.jiansh ...
- Codeforces 948 数论推导 融雪前缀和二分check 01字典树带删除
A. 全部空的放狗 B. 先O(NLOGNLOGN)处理出一个合数质因数中最大的质数是多少 因为p1 x1 x2的关系是 x2是p在x1之上的最小倍数 所以x1的范围是[x2-p+1,x2-1]要使最 ...
- hdu2955_Robberies 01背包
有一个强盗要去几个银行偷盗,他既想多投点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率,以及强盗能容忍的最大被抓概率.求他最多能偷到多少钱? 解:以概率为价值 问价值在合理范围背包的最大容量 ...