本文整理匯總了Python中win32security.AdjustTokenPrivileges方法的典型用法代碼示例。如果您正苦於以下問題:Python win32security.AdjustTokenPrivileges方法的具體用法?Python win32security.AdjustTokenPrivileges怎麽用?Python win32security.AdjustTokenPrivileges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類win32security
的用法示例。
在下文中一共展示了win32security.AdjustTokenPrivileges方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_extra_privs
# 需要導入模塊: import win32security [as 別名]
# 或者: from win32security import AdjustTokenPrivileges [as 別名]
def get_extra_privs():
# Try to give ourselves some extra privs (only works if we're admin):
# SeBackupPrivilege - so we can read anything
# SeDebugPrivilege - so we can find out about other processes (otherwise OpenProcess will fail for some)
# SeSecurityPrivilege - ??? what does this do?
# Problem: Vista+ support "Protected" processes, e.g. audiodg.exe. We can't see info about these.
# Interesting post on why Protected Process aren't really secure anyway: http://www.alex-ionescu.com/?p=34
th = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32con.TOKEN_ADJUST_PRIVILEGES | win32con.TOKEN_QUERY)
privs = win32security.GetTokenInformation(th, TokenPrivileges)
newprivs = []
for privtuple in privs:
if privtuple[0] == win32security.LookupPrivilegeValue(remote_server, "SeBackupPrivilege") or privtuple[0] == win32security.LookupPrivilegeValue(remote_server, "SeDebugPrivilege") or privtuple[0] == win32security.LookupPrivilegeValue(remote_server, "SeSecurityPrivilege"):
print "Added privilege " + str(privtuple[0])
# privtuple[1] = 2 # tuples are immutable. WHY?!
newprivs.append((privtuple[0], 2)) # SE_PRIVILEGE_ENABLED
else:
newprivs.append((privtuple[0], privtuple[1]))
# Adjust privs
privs = tuple(newprivs)
str(win32security.AdjustTokenPrivileges(th, False , privs))
示例2: enable_privilege
# 需要導入模塊: import win32security [as 別名]
# 或者: from win32security import AdjustTokenPrivileges [as 別名]
def enable_privilege(privilege_name):
success = False
privilege_id = win32security.LookupPrivilegeValue(
None,
privilege_name
)
new_privilege = [(privilege_id, win32con.SE_PRIVILEGE_ENABLED)]
h_token = win32security.OpenProcessToken(
win32process.GetCurrentProcess(),
win32security.TOKEN_ALL_ACCESS
)
if h_token:
success = win32security.AdjustTokenPrivileges(
h_token, 0, new_privilege
)
close_handle(h_token)
return success
示例3: acquire_privilege
# 需要導入模塊: import win32security [as 別名]
# 或者: from win32security import AdjustTokenPrivileges [as 別名]
def acquire_privilege(privilege):
process = win32process.GetCurrentProcess()
token = win32security.OpenProcessToken(
process,
win32security.TOKEN_ADJUST_PRIVILEGES |
win32security.TOKEN_QUERY)
priv_luid = win32security.LookupPrivilegeValue(None, privilege)
privilege_enable = [(priv_luid, win32security.SE_PRIVILEGE_ENABLED)]
privilege_disable = [(priv_luid, win32security.SE_PRIVILEGE_REMOVED)]
win32security.AdjustTokenPrivileges(token, False, privilege_enable)
try:
yield
finally:
win32security.AdjustTokenPrivileges(token, False, privilege_disable)
示例4: seDebug
# 需要導入模塊: import win32security [as 別名]
# 或者: from win32security import AdjustTokenPrivileges [as 別名]
def seDebug():
try:
"""SEDebug"""
flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY
htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(), flags)
id = win32security.LookupPrivilegeValue(None, "seDebugPrivilege")
newPrivileges = [(id, win32security.SE_PRIVILEGE_ENABLED)]
win32security.AdjustTokenPrivileges(htoken, 0, newPrivileges)
except Exception as e:
print 'je me vautre'
pass