Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DWORD _DataCompare(BYTE *data, BYTE *sig, DWORD siglen)
- {
- DWORD i = 0;
- for(; i < siglen; i++)
- if ((sig[i] != '?') && (sig[i] != data[i]))
- return 0;
- return (i == siglen);
- }
- DWORD _FindPattern(DWORD addr, DWORD len, BYTE *sig, DWORD siglen)
- {
- DWORD i = 0;
- for (; i < len; i++)
- if (_DataCompare((BYTE*)(addr+i), sig, siglen))
- return addr + i;
- return 0;
- }
- LUA_FUNC(SigScan)
- {
- HANDLE h = (void*)((DWORD)lua_tointeger(l, 1));
- DWORD dwAddress = (DWORD)lua_tostring(l, 2);
- BYTE *bSig = (BYTE*)lua_tostring(l, 3);
- DWORD dwSigLen = (DWORD)lua_tointeger(l, 4);
- //Get address & size of dll
- if (dwAddress == 0) { lua_pushinteger(l, 1); return 1; }
- MEMORY_BASIC_INFORMATION mbi;
- VirtualQueryEx(h, (void*)dwAddress, &mbi, sizeof(MEMORY_BASIC_INFORMATION));
- DWORD dwLen = mbi.RegionSize;
- if (mbi.RegionSize == 0) { lua_pushinteger(l, 2); return 1; }
- BYTE *buffer = (BYTE*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 0x1000);
- if (buffer == 0) { lua_pushinteger(l, 3); return 1; }
- //Scan every page
- DWORD dwTemp = 0, dwDelta = 0;
- do
- {
- ReadProcessMemory(h, (void*)dwAddress, (void*)buffer, 0x1000, 0);
- dwDelta = _FindPattern(dwAddress, 0x1000, bSig, dwSigLen);
- if (dwDelta != 0)
- {
- HeapFree(GetProcessHeap(), 0, buffer);
- dwDelta -= (DWORD)buffer;
- dwDelta += dwAddress;
- lua_pushinteger(l, dwDelta);
- return 1;
- }
- dwAddress += 0x1000;
- } while (dwAddress < (dwTemp + dwLen));
- HeapFree(GetProcessHeap(), 0, buffer);
- lua_pushinteger(l, 4);
- return 1;
- }
- LUA_FUNC(SetDebugPrivileges)
- {
- TOKEN_PRIVILEGES Debug_Privileges;
- //STEP 1
- if (!LookupPrivilegeValue (NULL, // Privieleges for the local system
- SE_DEBUG_NAME, // define the name of the privilege
- &Debug_Privileges.Privileges[0].Luid)) // will get the LUID value into this variable
- { //if function failed, cannot proceed to the next step
- return GetLastError(); //terminate the outer function
- }
- //STEP 2
- DWORD err = 0; // define error holder, used to store the error code in case of failure
- HANDLE hToken = 0; // instantiate a token handle
- if (!OpenProcessToken (GetCurrentProcess (), // current process ID handle
- TOKEN_ADJUST_PRIVILEGES, //set the desired access
- &hToken)) // handle to the token will be held here
- { // if function failed, cannot proceed to the next step
- err = GetLastError();
- if (hToken) // if handle is still valid
- CloseHandle (hToken); // destroy it
- return err; //terminate the outer function
- }
- //STEP3
- Debug_Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // set to enable privilege
- Debug_Privileges.PrivilegeCount = 1; // working with only one privilege
- if (!AdjustTokenPrivileges (hToken, // access token handle
- FALSE, // do not disable privileges
- &Debug_Privileges, // pointer to the token structure
- 0, // no need for a buffer
- NULL, // previous state not set
- NULL)) // no need for a buffer
- {
- err = GetLastError();
- if (hToken) // if handle is still valid
- CloseHandle (hToken); // destroy it
- return err; //terminate the outer function
- }
- return err;
- }
- BOOL VistaOrHigher()
- {
- void *peb;
- _asm
- {
- push EAX
- xor EAX, EAX
- mov EAX, fs:[0x30]
- mov [peb], EAX
- POP EAX
- }
- ULONG OSMinor = *((BYTE*)peb + 0xA4);
- ULONG OSMajor = *((BYTE*)peb + 0xA8);
- ULONG OSPlatform = *((BYTE*)peb + 0xB0);
- BOOL vistaorhigher = 0;
- if (OSPlatform == 2 && OSMajor == 6)
- vistaorhigher = 1;
- return vistaorhigher;
- }
- DWORD RemoteGMH(HANDLE proc, char *module)
- {
- //Write module name to process
- void *rModule = VirtualAllocEx(proc, 0, lstrlenA(module), MEM_COMMIT, PAGE_READWRITE);
- if (rModule == 0) { printf("VirtualAllocEx failed\n"); return 0; }
- WriteProcessMemory(proc, rModule, (void*)module, lstrlenA(module), 0);
- //Get module handle in process
- HANDLE rModThread = CreateRemoteThread(proc, 0, 0, (LPTHREAD_START_ROUTINE)
- GetProcAddress(GetModuleHandle("kernel32.dll"), "GetModuleHandleA"), rModule, 0, 0);
- DWORD rModResult = WaitForSingleObject(rModThread, INFINITE);
- DWORD rModHandle = 0;
- GetExitCodeThread(rModThread, &rModHandle);
- VirtualFreeEx(proc, (void*)rModule, lstrlenA(module), MEM_RELEASE);
- if (rModHandle == 0) { printf("Remote thread exit code is 0\n"); return 0; }
- return rModHandle;
- }
Add Comment
Please, Sign In to add comment