Created
August 25, 2019 22:41
-
-
Save apple1417/608aac1e4922850b6465fad6f3869c34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "pch.h" | |
| #include <iostream> | |
| #include <windows.h> | |
| #include <psapi.h> | |
| int main() | |
| { | |
| /*HANDLE current_token = 0; | |
| bool found_token = OpenProcessToken( | |
| GetCurrentProcess(), | |
| TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, | |
| ¤t_token | |
| ); | |
| if (found_token == FALSE) { | |
| std::cout << "Couldn't find current process token, " << GetLastError() << "\n"; | |
| return 1; | |
| } | |
| LUID luid; | |
| bool found_privilege = LookupPrivilegeValueW( | |
| NULL, | |
| SE_DEBUG_NAME, | |
| &luid | |
| ); | |
| if (found_privilege == FALSE) { | |
| std::cout << "Couldn't find privilege LUID, " << GetLastError() << "\n"; | |
| std::cout << GetLastError(); | |
| return 1; | |
| } | |
| TOKEN_PRIVILEGES tp; | |
| tp.PrivilegeCount = 1; | |
| tp.Privileges[0].Luid = luid; | |
| tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | |
| bool adjusted_privileges = AdjustTokenPrivileges( | |
| current_token, | |
| FALSE, | |
| &tp, | |
| 0, | |
| NULL, | |
| NULL | |
| ); | |
| if (adjusted_privileges == FALSE) { | |
| std::cout << "Couldn't adjust privilege, " << GetLastError() << "\n"; | |
| return 1; | |
| }*/ | |
| DWORD process_list[4096]; | |
| DWORD process_count_bytes; | |
| bool did_enum = EnumProcesses( | |
| process_list, | |
| sizeof(process_list), | |
| &process_count_bytes | |
| ); | |
| if (did_enum == FALSE) { | |
| std::cout << "EnumProcesses failed, " << GetLastError() << "\n"; | |
| return 1; | |
| } | |
| int process_count = process_count_bytes / sizeof(DWORD); | |
| for (int i = 0; i < process_count; i++) { | |
| int pid = process_list[i]; | |
| HANDLE proc_handle = OpenProcess( | |
| PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, | |
| FALSE, | |
| pid | |
| ); | |
| if (proc_handle == NULL) { | |
| std::cout << "Open Process failed on process " << pid << ", " << GetLastError() << "\n"; | |
| } | |
| else { | |
| std::cout << "Succeeded on process " << pid << "\n"; | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment