I made few projects that create a sample target window program, debug process which attempts to gain "debug" rights to the window process in order to write process memory and also a DLL which will help to tell us what the error is.
note that there is still a lot of work to do, this is only to show how this sort of stuff is done.
I don't have much time to write code for you, the rest of the work belong to you!
In short here is the most important part on how to set process priviledge, see comments and links for further information:
also note that these function can't add priviledge, only modify existing ones. you should read MSDN for more information.
If you really want to hack someones process from non administrative account it's the best to create your own process which is automatically PROCESS_ALL_ACCESS, you can then write byte code into that process memory from some executable. something similar to how crypters works.
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
|
bool SetProcessPrivilege(
HANDLE hToken,
const std::wstring privilege,
bool enable_priviledge
)
{
TOKEN_PRIVILEGES tp;
LUID luid;
if (!LookupPrivilegeValueW(
nullptr, // lookup privilege on local system
privilege.c_str(), // privilege to lookup
&luid)) // receives LUID of privilege
{
ShowError(ERR_BOILER);
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (enable_priviledge)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if (!AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES)NULL,
(PDWORD)NULL))
{
ShowError(ERR_BOILER);
return false;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
{
SetLastError(ERROR_NOT_ALL_ASSIGNED);
ShowError(ERR_BOILER);
return false;
}
return true;
}
|
This function on it own is does not do much work it is called by following function:
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
|
void AttachProcess()
{
int buff[10] = {};
HWND hWnd = FindWindowW(L"DebuggableWindow", L"TestWindow");
if (!IsWindow(hWnd))
{
SetLastError(ERROR_INVALID_HANDLE);
ShowError(ERR_BOILER);
return;
}
DWORD pId;
GetWindowThreadProcessId(hWnd, &pId);
// for a list of access rights see:
// https://docs.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights
HANDLE hProc = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_READ | PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION, TRUE, pId);
if (!hProc)
{
ShowError(ERR_BOILER);
return;
}
// The OpenProcessToken function opens the access token associated with a process.
// for a list of access tokens see:
// https://docs.microsoft.com/en-us/windows/win32/secauthz/access-rights-for-access-token-objects
HANDLE hTokenHandle = nullptr;
if (!OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hTokenHandle)
|| !hTokenHandle)
{
ShowError(ERR_BOILER);
return;
}
// set debug priviledge, for a list of priviledges see
// https://docs.microsoft.com/en-us/windows/win32/secauthz/privilege-constants
if (!SetProcessPrivilege(&hTokenHandle, SE_DEBUG_NAME, true))
return;
SIZE_T bytes_written = 0;
const int isSuccessful = WriteProcessMemory(hProc, (LPVOID)0x0177520E, buff, static_cast<SIZE_T>(10 * sizeof(int)), &bytes_written);
if (isSuccessful)
{
MessageBoxW(hWnd, (std::to_wstring(bytes_written) + L" bytes were written to process memory").c_str(), L"Info", MB_OK | MB_ICONINFORMATION);
}
else
{
ShowError(ERR_BOILER);
}
CloseHandle(hProc);
CloseHandle(hTokenHandle);
}
|
You can download complete sample code on below link, with error checking DLL and 2 more projects just make sure you launch both programs in same time, you can set this option in solution.
if you do not use VS, then you're on you own, please don't ask me to help you configure some crappy IDE.
hopefully you learn something out from this!
http://s000.tinyupload.com/index.php?file_id=06235139145522649778