【问题标题】:What are the return values of the function GetTokenInformation() and how do I use itGetTokenInformation() 函数的返回值是什么以及如何使用它
【发布时间】:2021-10-29 07:15:01
【问题描述】:

我试过这段代码:

import win32security
import win32api
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32security.TOKEN_QUERY_SOURCE | win32security.TOKEN_QUERY)

for i in range(0x30):
    try:
        n = win32security.LookupPrivilegeName(None, i)
        privs = win32security.GetTokenInformation(token, i)

    except Exception as e:
        pass
    else:
        print(privs)
        print(i, n)

while True:
    pass

我试图获取每个特权的信息(我主要想要标志),但我无法理解 GetTokenInformation() 的返回值,它返回不同的类型,我无法从中提取任何信息它,我在MSDN上搜索过,但还是不明白。

【问题讨论】:

  • 这记录在 MSDN 上。鉴于问题中的代码,您似乎没有足够仔细地阅读该文档。

标签: python security winapi


【解决方案1】:

在 MSDN 中阅读更多内容后,我发现 GetTokenInformation 函数接收一个名为 TOKEN_INFORMATION_CLASS 的参数,该参数指定函数将返回的内容,因此为了找到有关权限及其标志的信息,我使用了以下代码:

import win32security
import win32api
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32security.TOKEN_QUERY_SOURCE | win32security.TOKEN_QUERY)
privs = win32security.GetTokenInformation(token, win32security.TokenPrivileges)
for i in range(len(privs)):
    # name of privilege
    name = win32security.LookupPrivilegeName(None, privs[i][0])
    flag = privs[i][1]

    # check the flag value
    if flag == 0:
        flag = 'Disabled'
    elif flag == 3:
        flag = 'Enabled'

    print(name, flag)

while True:
    pass

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 2022-01-10
    • 2015-03-13
    • 2013-10-25
    相关资源
    最近更新 更多