可能很多人都看过灰鸽子中的 配置服务器端,点击后弹出一个窗口,选择几项之后,点生成,就可以生成木马的服务器端(一个exe文件),只要这个exe文件运行在谁的电脑上,那个电脑就成了肉鸡。^_^ 不过我不会这招。
我今天是想做个能够通过一个exe文件生成另一个exe文件的东东。
首先新建个winform应用程序,代码如下
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
namespace Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//源代码模板
string codeBase = @"
using System;
using System.Collections.Generic;
using System.Text;
namespace lhking
{
public class Class1
{
static void Main()
{
System.Windows.Forms.Application.Run(new Server.Form1());
}
}
}";
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Length > 0)
{
string code = codeBase;
//编译生成exe
CompileCode(code, System.IO.Path.Combine(Application.StartupPath, this.textBox1.Text + ".exe"));
}
else MessageBox.Show("文件名不能为空!");
}
private CompilerResults CompileCode(string SourceCode, string ExeuteFileName)
{
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters(new string[] { "System.dll", "Server.DLL", "System.Windows.Forms.dll" }, ExeuteFileName, false);
cp.CompilerOptions = "/target:winexe";
cp.GenerateExecutable = true;
CompilerResults cr = provider.CompileAssemblyFromSource(cp, SourceCode);
return cr;
}
}
然后新建个类库,刚才的那个程序引用这个类库,类库里新建个winform窗口。
这个类库就是弹出个对话框
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("这是动态生成的exe文件哦!");
}
这样就完成了。
说明下缺点:这样做,生成的那个exe文件,如果要想运行,同目录下必须有那个类库。??
完整程序下载