______ Y ______
My own personal time capsule.
Tag Archives: process
Universal Process Privilage Escalation
January 29, 2012
Posted by on By adjusting process token its possible to elevate your current process privileges to enable certain functionality not available otherwise.
Basically steps we follow are :
1) Get current process handle
2) Get current process token
3) Resolve SeDebugPrivilege value
4) Created new Token with the resolved value from step 3
5) Adjust the token of the current process with new privilege
6) Close process handle
Following code demonstrates the principle.
print "[+] Universal Process Escalation by Y" print "[+] contact : If you know me then give me a shout" from ctypes import windll import ctypes from ctypes import * class TOKEN_PRIVS(ctypes.Structure): _fields_ = ( ("PrivilegeCount", ULONG), ("Privileges", ULONG * 3 ) ) def get_debug_privs(): # Adjust Current TOKEN token = HANDLE() print "\t[+] Getting Current Token" flags = 40 # TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY windll.advapi32.OpenProcessToken(windll.kernel32.GetCurrentProcess(), 0x00000020, ctypes.byref(token)) print "\t[+] Calculating Local SeDebugPrivilege" admin_priv_name = "SeDebugPrivilege" # we want this priv on the process pBytesReturned = ctypes.c_ulong() windll.advapi32.LookupPrivilegeValueA(None,admin_priv_name,ctypes.byref(pBytesReturned)) print "\t[+] Resolved SeDebugPrivilege as %d" % pBytesReturned.value print "\t[+] Modifying TOKEN Structure to enable Debug" privs = TOKEN_PRIVS() privs.PrivilegeCount = 1 privs.Privileges = (pBytesReturned.value,0, 2) print "\t[+] Adjusting Privileges of the current process" windll.advapi32.AdjustTokenPrivileges(token, 0, ctypes.byref(privs),0,0,0) print "\t[+] Closing current handle, almost done" windll.kernel32.CloseHandle(token) print "[+] Done, your process " , windll.kernel32.GetCurrentProcessId(), "has now admin privileges" ############ CURRENT TOKEN ADJUSTED ################## get_debug_privs()
PID Enumeration on Windows with pure python ctypes
January 27, 2012
Posted by on Following code will enumerate process ID’s on the current system by calling EnumProcesses from psapi on Windows. Should for for majority of windows distributions that have psapi.dll in %systemroot%.
from ctypes import * psapi = windll.psapi print "[+] PID dumper by Y" print "[+] contact : If you know me then give me a shout" def getListOfProcesses(): max_array = c_ulong * 4096 # define long array to capture all the processes pProcessIds = max_array() # array to store the list of processes pBytesReturned = c_ulong() # the number of bytes returned in the array #EnumProcess psapi.EnumProcesses(byref(pProcessIds), sizeof(pProcessIds), byref(pBytesReturned)) # get the number of returned processes nReturned = pBytesReturned.value/sizeof(c_ulong()) pidProcessArray = [i for i in pProcessIds][:nReturned] for processes in pidProcessArray: print "[+] Running Process PID %d" % processes getListOfProcesses()