C# DLL注入后无法执行,求大神帮助。

AngleBlueWing 2020-12-30 02:49:28
近日做期末计算机程序结课设计,题目是C#开发一个DLL并注入到explorer.exe并执行,好不容易贪黑写完了终于能注入了,但是注入后无法自动执行,各种百度也不行,眼看日期临近实在没有办法了,望各路大神出手相助,谢谢!
附C# dll注入源代码(XP下可运行(32位)):

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace DllInjectA
{
class Program
{
[DllImport("kernel32.dll")] //声明API函数
public static extern int VirtualAllocEx(IntPtr hwnd, int lpaddress, int size, int type, int tect);

[DllImport("kernel32.dll")]
public static extern int 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 int CreateRemoteThread(IntPtr hwnd, int attrib, int size, int address, int par, int flags, int threadid);

static void Main(string[] args)
{
int ok1;
int baseaddress;
int temp = 0;
int hack;
int yan;
string dllname;

dllname = "c:\\test.dll";
int dlllength;
dlllength = dllname.Length + 1;
Process[] pname = Process.GetProcesses(); //取得所有进程

foreach (Process name in pname) //遍历进程
{
//MessageBox.Show(name.ProcessName.ToLower());
if (name.ProcessName.ToLower().IndexOf("svchost") != -1) //所示记事本,那么下面开始注入
{
baseaddress = VirtualAllocEx(name.Handle, 0, dlllength, 4096, 4); //申请内存空间
if (baseaddress == 0) //返回0则操作失败
{
Console.WriteLine("申请内存空间失败!!");
return;
}

ok1 = WriteProcessMemory(name.Handle, baseaddress, dllname, dlllength, temp); //写内存
if (ok1 == 0)
{
Console.WriteLine("写内存失败!!");
return;
}

hack = GetProcAddress(GetModuleHandleA("Kernel32"), "LoadLibraryA"); //取得loadlibarary在kernek32.dll地址

if (hack == 0)
{
Console.WriteLine("无法取得函数的入口点!!");
return;
}

yan = CreateRemoteThread(name.Handle, 0, 0, hack, baseaddress, 0, temp); //创建远程线程

if (yan == 0)
{
Console.WriteLine("创建远程线程失败!!");
return;
}
else
{
Console.WriteLine("已成功注入dll!");
Console.ReadKey();
return;
}
}
}
}
}
}
...全文
5716 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_44849620 2022-10-26
  • 打赏
  • 举报
回复

我也遇到了这个问题,请问解决了吗?

glb21 2021-01-04
  • 打赏
  • 举报
回复
右键管理员权限运行
AngleBlueWing 2021-01-01
  • 打赏
  • 举报
回复
又向老师确认了一下,是用C++写且只能用于课程设计,多谢指教
泡泡龙 2020-12-30
  • 打赏
  • 举报
回复
是你的老师让你这么写代码注入托管dll到非托管进程的吗?你确认老师自己亲自测试过吗? 托管dll的main不会被执行,除非你用c++/clr写
wanghui0380 2020-12-30
  • 打赏
  • 举报
回复
这问题我们不敢回答,怕进“小黑屋” 你要弄别的,技术上俺们聊聊 要弄explorer.exe,俺们就不能说啥了

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧