| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 04, 2008 1:33 pm Post subject: token privileges |
|
|
I'm trying to make a function to change the token privileges of a process so that you can use PROCESS_ALL_ACCESS, but I have a problem. In the OpenProcessToken API it asks for a handle to the process, but the only way I can think of being able to get that is to call OpenProcess with any access (but PROCESS_ALL_ACCESS) and then pass the handle, then after the function close the handle and open it up again, but this time with PROCESS_ALL_ACCESS. But that doesn't seem, right, is there any other way to do it? Here's my code:
| Code: |
BOOL SetPrivilege(LPCSTR lpPrivilege) {
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
if(OpenProcessToken(, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { //I left the first param blank because that's the one I'm having trouble with
if(LookupPrivilegeValue(NULL, lpPrivilege, &luid)) {
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if(AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
return TRUE;
}
return FALSE;
}
return FALSE;
}
return FALSE;
}
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri Jul 04, 2008 2:20 pm Post subject: |
|
|
| The first parameter is the process to set the privileges, call it with the first parameter being -1. (current process)
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 04, 2008 2:24 pm Post subject: |
|
|
That requires me to inject a DLL into a process and call this function and pass GetCurrentProcess(). I want to be able to do this just from a normal application.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri Jul 04, 2008 2:49 pm Post subject: |
|
|
You want to change the current process privileges, so you can call OpenProcess with PROCESS_ALL_ACCESS from the current process, if you want to change another process's privileges, get the handle by calling OpenProcess, but if you get access denied then you still have to set the current process's privileges...
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 04, 2008 3:51 pm Post subject: |
|
|
Oh, right. I just realized that you have to change the current process's privileges so that it can do whatever.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|