Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.36 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include "MinHook.h"
  4. #include <ws2tcpip.h>
  5. #include <tlhelp32.h>
  6. #include <shellapi.h>
  7. #pragma comment(lib, "libMinHook-x64.lib")
  8. //#define DEBUG_OUTPUT
  9.  
  10. char textBuffer[1024];
  11.  
  12. void Log(char* text)
  13. {
  14. #ifdef DEBUG_OUTPUT
  15.     FILE * fp;
  16.     fp = fopen ("D:\\log_soda.txt","a");
  17.     fprintf(fp, text);
  18.     fclose(fp);
  19. #endif
  20. }
  21.  
  22. typedef int (WSAAPI * GETADDRINFO)(PCSTR, PCSTR, const ADDRINFOA*, PADDRINFOA*);
  23. typedef INT64 (*CURL_SETOPT)(INT64, INT64, ...);
  24.  
  25. GETADDRINFO org_getaddrinfo = NULL;
  26. CURL_SETOPT org_curlsetopt = NULL;
  27.  
  28. INT WSAAPI mygetaddrinfo(PCSTR pNodeName, PCSTR pServiceName, const ADDRINFOA *pHints, PADDRINFOA *ppResult)
  29. {
  30.     Log("getaddrinfo called with ");
  31.     Log((char*)pNodeName);
  32.     Log("\n");
  33.     return org_getaddrinfo("127.0.0.1", pServiceName, pHints, ppResult);
  34. }
  35.  
  36. INT64 mycurlsetopt(INT64 a1, INT64 a2, ...)
  37. {  
  38.     va_list va;
  39.     va_start(va, a2);
  40.     INT64* pTmp = (INT64*)&va;
  41.     INT64* pTmp2 = (INT64*)(*pTmp);
  42.     sprintf(textBuffer, "curl_setopt called for id %d\n\0", a2);
  43.     Log(textBuffer);
  44.     if(a2 == 64 || a2 == 81)
  45.     {
  46.         *pTmp2 = 0;
  47.         Log("SSL Patched\n");
  48.     }
  49.     return org_curlsetopt(a1, a2, *pTmp2);
  50. }
  51.  
  52. bool IsProcessRunning(const wchar_t* const processName) {
  53.     PROCESSENTRY32 entry;
  54.     entry.dwSize = sizeof(PROCESSENTRY32);
  55.  
  56.     const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  57.  
  58.     if (!Process32First(snapshot, &entry)) {
  59.         CloseHandle(snapshot);
  60.         return false;
  61.     }
  62.  
  63.     do {
  64.         if (!_wcsicmp(entry.szExeFile, processName)) {
  65.             CloseHandle(snapshot);
  66.             return true;
  67.         }
  68.     } while (Process32Next(snapshot, &entry));
  69.  
  70.     CloseHandle(snapshot);
  71.     return false;
  72. }
  73.  
  74. void Hack1();
  75. void Hack2();
  76.  
  77. void HackMain()
  78. {
  79.     char moduleName[MAX_PATH];
  80.     GetModuleFileNameA(NULL, moduleName, MAX_PATH);
  81.     if (strstr(moduleName, "\\ws.exe") == NULL)
  82.         return;
  83.     Log("Start\n");
  84.     if (MH_Initialize() != MH_OK)
  85.     {
  86.         Log("Minhook init failed\n");
  87.         return;
  88.     }
  89.     Log("Minhook init done\n");
  90.     Hack1();
  91.     Hack2();
  92. }
  93.  
  94. void Hack1()
  95. {  
  96.     HMODULE h = GetModuleHandleA("ws2_32.dll");
  97.     if(h == NULL)
  98.     {
  99.         Log("ws2_32.dll not found\n");
  100.         return;
  101.     }
  102.     Log("ws2_32.dll found...\n");
  103.     FARPROC address = GetProcAddress(h, "getaddrinfo");
  104.     if(address == NULL)
  105.     {
  106.         Log("getaddrinfo not found\n");
  107.         return;
  108.     }
  109.     Log("getaddrinfo found...\n");
  110.     if (MH_CreateHook(address, &mygetaddrinfo, reinterpret_cast<LPVOID*>(&org_getaddrinfo)) != MH_OK)
  111.     {
  112.         Log("Installing hook failed\n");
  113.         return;
  114.     }
  115.     Log("Hook installed\n");
  116.     if (MH_EnableHook(address) != MH_OK)
  117.     {
  118.         Log("Enabling hook failed\n");
  119.         return;
  120.     }
  121.     Log("Hook enabled\n");
  122. }
  123.  
  124.  
  125. void Hack2()
  126. {  
  127.     HMODULE h = GetModuleHandleA("libcurl.dll");
  128.     if(h == NULL)
  129.     {
  130.         Log("libcurl.dll not found\n");
  131.         return;
  132.     }
  133.     Log("libcurl.dll found...\n");
  134.     FARPROC address = GetProcAddress(h, "curl_easy_setopt");
  135.     if(address == NULL)
  136.     {
  137.         Log("curl_easy_setopt not found\n");
  138.         return;
  139.     }
  140.     Log("curl_easy_setopt found...\n");
  141.     if (MH_CreateHook(address, &mycurlsetopt, reinterpret_cast<LPVOID*>(&org_curlsetopt)) != MH_OK)
  142.     {
  143.         Log("Installing hook failed\n");
  144.         return;
  145.     }
  146.     Log("Hook installed\n");
  147.     if (MH_EnableHook(address) != MH_OK)
  148.     {
  149.         Log("Enabling hook failed\n");
  150.         return;
  151.     }
  152.     Log("Hook enabled\n");
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement