`

远程dll注入 C#

    博客分类:
  • C#
阅读更多

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace hooktest01
{
    public partial class Form1 : Form
    {
        [DllImport("kernel32.dll")]
        public static extern int VirtualAllocEx(IntPtr hwnd, Int32 lpaddress, int size, int type, Int32 tect);
        [DllImport("kernel32.dll")]
        public static extern Boolean WriteProcessMemory(IntPtr hwnd, int baseaddress, string buffer, int nsize, int filewriten);
        [DllImport("kernel32.dll")]
        public static extern int GetProcAddress(int hwnd, string lpname);
        [DllImport("kernel32.dll")]
        public static extern int GetModuleHandleA(string name);
        [DllImport("kernel32.dll")]
        public static extern IntPtr CreateRemoteThread(IntPtr hwnd, int attrib, int size, int address, int par, int flags, int threadid);
        [DllImport("kernel32.dll")]
        public static extern Int32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);
        [DllImport("kernel32.dll")]
        public static extern Boolean VirtualFree(IntPtr lpAddress, Int32 dwSize, Int32 dwFreeType);
        Process pname;
        UInt32 INFINITE = 0xFFFFFFFF;
        Int32 PAGE_EXECUTE_READWRITE = 0x40;
        Int32 MEM_COMMIT = 0x1000;
        Int32 MEM_RESERVE = 0x2000;
        Int32 MEM_RELEASE = 0x8000;
        Int32 AllocBaseAddress;
        IntPtr hwnd;
        string dllname;
        Int32 Pid;
        Boolean ok;
        Int32 loadaddr;
        IntPtr ThreadHwnd;


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text == "" || textBox1.Text == null)
                {
                    MessageBox.Show("Pid is null"); return;
                }
                if (textBox2.Text == "" || textBox2.Text == null)
                {
                    MessageBox.Show("dll name is null"); return;
                }
                Pid = Int32.Parse(textBox1.Text);
                dllname = textBox2.Text;
            }
            catch(Exception error)
            {
                MessageBox.Show(error.Message); return;
            }
            try
            {
                pname = Process.GetProcessById(Pid);
                hwnd = pname.Handle;
            }
            catch(Exception error)
            {   //当标示pid的进程不存在时发生异常;
                MessageBox.Show (error.Message); return;
            }
            AllocBaseAddress= VirtualAllocEx(hwnd, 0, dllname.Length + 1, MEM_COMMIT+ MEM_RESERVE, PAGE_EXECUTE_READWRITE);
            if (AllocBaseAddress == 0)
            {
                MessageBox.Show("virtualallocex  fail"); return;
            }
            ok=WriteProcessMemory(hwnd, AllocBaseAddress, dllname, dllname.Length + 1,0);
            if (!ok)
            {
                MessageBox.Show("writeprocessmemory fail"); return;
            }
            loadaddr = GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
            if (loadaddr == 0)
            {   //取得LoadLibraryA的地址失败时返回
                MessageBox.Show("get loadlibraryA fail"); return;
            }
            ThreadHwnd=CreateRemoteThread(hwnd, 0, 0, loadaddr, AllocBaseAddress,0, 0);
            if (ThreadHwnd ==IntPtr.Zero)
            {
                MessageBox.Show("createremotethread fail"); return;
            }
           
            
            WaitForSingleObject(ThreadHwnd, INFINITE);
            MessageBox.Show("ok ,you can check now!!!");
            VirtualFree(hwnd, 0, MEM_RELEASE);
            //下面开始枚举模块列表;
            ProcessModuleCollection pmodule = pname.Modules;
            foreach (ProcessModule processm in pmodule)
            {
                listBox1.Items.Add(processm.FileName);
            }
            pname.Dispose();
        }
        //进程 句柄

    }
}
 转自:http://blog.csdn.net/pandyer/archive/2009/01/06/3719836.aspx
分享到:
评论

相关推荐

    C#版DLL远程线程注入源代码

    C#没有自动调用WIN32的一些API函数,我们可以手动添加内核库到我们自己的代码中,从而实现调用...此方法不仅仅用于远程线程注入,还可以用于从MFC转C#过程中不知道如何用C#实现功能,但有知道如何用MFC实现功能的方法。

    csrss.exe通过远程DLL注入

    C++源代码,DLL工程的主文件。注入的代码和注入后执行的代码在一起。

    C#使用EasyHook注入简单案例

    C#使用EasyHook注入简单案例。C#使用EasyHook注入简单案例。C#使用EasyHook注入简单案例。

    dll远程线程注入(支持64bit win7)

    把dll注入到远程线程。使用的时候创建一个空的工程,然后把代码当做主文件放到工程中,自己写个mian函数调用injectDLL函数就能注入了。菜鸟级友情提醒:64位别忘了编译成x64的可执行文件

    DLL注入

    c# 整合c++远程注入 api重写等 记事本应用实例等 是值得一看的小工具

    C++实现dll注入其它进程

    DLL注入其他进程技术  阅读本篇文章,需要有《线程注入其他进程技术》基础。  DLL注入技术才具有强大的功能和使用性,同时简单易用,因为DLL中可以实现复杂的功能和很多的技术。  技术要点:  1、宿主进程...

    远程线程注入工具,可生成代码 可自定义shellcode注入进程-易语言

    双击第三个输入框即可生成shellcode,这里默认的shellcode是远程线程注入 注入的是当前程序选择注入的进程 这里选择最左下角的选项,然后再双击输入框 即可生成在自身程序执行的shellcode 这里说明一下哈,这里是...

    asp.net 引用 dll 库

    C#,asp.net 引用DLL 说明,昨天引用了半天引用不了,原来是没有注册 RECER32 注册 引用文件,(路径填好) 在项目里添加引用 即可

    CreateRemoteThread DLL源码

    C++编写的DLL C#程序调用 远程线程执行DLL注入

    DcRat:一个用C#编写的简单远程工具

    DcRat是用C#编写的简单远程工具 屏幕截图 介绍 特征 TCP连接,带有证书验证,稳定且安全 服务器IP端口可以通过链接进行归档 多服务器,多端口支持 通过Dll的插件系统,具有很强的扩展性 极小的客户端大小(约40〜...

    【没积分看简介】DLoad_c#全网唯一能成功加载驱动的C#代码,有成品exe可直接测试!

    全网就这个C#能成功加载驱动,有实例,原理利用C++dll进行注入【远程加载驱动】,如果是自身程序,则直接加载即可!有exe,可运行加载,已经成功(驱动行64位,无签名),没C币请到:...

    C#全能速查宝典

    《C#全能速查宝典》共分为8章,分别介绍了C#语言基础、Windows窗体及常用控件、Windows高级控件、控件公共属性、方法及事件、数据库开发、文件、数据流与注册表、GDI+绘图技术和C#高级编程,共包含562个C#编程中常用...

    DNCI:DNCI-点净代码注入器

    DNCI-点净代码注入器DNCI允许在Windows的非托管进程中远程注入.Net代码(.exe或.dll)。1.项目结构该项目的结构为: DNCI.Injector.Library-注入库包含所有注入组件和逻辑; DNCI.Injector.Runner-用于注入的命令行...

    Spring.net框架

    除此之外,对于单继承的C#语言而言,使用接口可以拥有更大 的弹性。 二、接口依赖 既然类之间的依赖导致耦合过于紧密,按照《设计模式》的理论,我们要依赖于接口。但是人们往往发现,仅仅依赖于接口似乎并不能完全...

    asp.net知识库

    多样式星期名字转换 [Design, C#] .NET关于string转换的一个小Bug Regular Expressions 完整的在.net后台执行javascript脚本集合 ASP.NET 中的正则表达式 常用的匹配正则表达式和实例 经典正则表达式 delegate vs. ...

    Virbox 开发者工具盒-软件加密工具

    dll、exe的加密保护 防止软件被反向工程、反向汇编、反向编译 软件的授权控制:限时、限次、限功能,限制设备绑定等 资源文件的加密:PDF、PPT、视频等,防止复制拷贝 优势 Virbox 加密方案配合使用深思新一代...

Global site tag (gtag.js) - Google Analytics