如何获得有效的文件权限?

2024-10-02 14:21:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试获取文件的有效权限。最好的办法是什么?在

我试图使用win32security,但是GetEffectiveRightsFromAcl(trustee)函数需要PyTRUSTEE参数。我不知道如何正确设置。在

因此,我需要获得与PowerShell中geteffectiveaccess调用相同的权限。在

我们试图使用Authz.h,但在这种情况下,我们在Windows事件查看器中遇到了审核失败。在

我们还试图使用Aclapi.h中的GetEffectiveRightsFromAcl,但这可能成为服务器挂起的原因,以防我们有很多文件。在

python:

dacl = win32security.GetNamedSecurityInfo( FILENAME,
 win32security.SE_FILE_OBJECT,
 win32security.DACL_SECURITY_INFORMATION).GetSecurityDescriptorDacl()
mask = dacl.GetEffectiveRightsFromAcl( ??? )

认证号

^{pr2}$

Aclapi.h

ACCESS_MASK accessRights;
TRUSTEE trustee;

BuildTrusteeWithName(&trustee, trav->user);
retcode = GetEffectiveRightsFromAcl( acl,&trustee,&accessRights);

我需要得到这样的东西:

文件读取数据
文件写入数据
文件附加数据
文件\u READ_EA
文件\u WRITE\u EA
文件执行
文件\u DELETE_CHILD
文件读取属性
文件写入属性
删除
读控制
写入\u DAC
写入所有者
同步


Tags: 文件数据函数权限参数属性ea办法
1条回答
网友
1楼 · 发布于 2024-10-02 14:21:36

我用@eryksun帮助得到了一些结果。谢谢。 我还发现了this useful example。在

def print_permissions(mask):
print("PERMISSION:",
      1 if bool(mask & 0x00000001) else 0,
      1 if bool(mask & 0x00000002) else 0,
      1 if bool(mask & 0x00000004) else 0,
      1 if bool(mask & 0x00000008) else 0,
      1 if bool(mask & 0x00000010) else 0,
      1 if bool(mask & 0x00000020) else 0,
      1 if bool(mask & 0x00000040) else 0,
      1 if bool(mask & 0x00000080) else 0,
      1 if bool(mask & 0x00000100) else 0,
      1 if bool(mask & 0x00010000) else 0,
      1 if bool(mask & 0x00020000) else 0,
      1 if bool(mask & 0x00040000) else 0,
      1 if bool(mask & 0x00080000) else 0,
      1 if bool(mask & 0x00100000) else 0)

def get_permissions(dacl):
for n_ace in range(dacl.GetAceCount()):
    ace = dacl.GetAce(n_ace)
    (ace_type, ace_flags) = ace[0]
    if ace_type in CONVENTIONAL_ACES:
        mask, sid = ace[1:]
    else:
        mask, object_type, inherited_object_type, sid = ace[1:]
    name, domain, type = win32security.LookupAccountSid(None, sid)
    print("\nUSER:", name)
    print_permissions(mask)

for f in files:
    try:
        dacl = win32security.GetNamedSecurityInfo(
            f,
            win32security.SE_FILE_OBJECT,
            win32security.DACL_SECURITY_INFORMATION).GetSecurityDescriptorDacl()
    except BaseException as ex:
        winerror, funcname, strerror = ex.args
        print("Error: ", winerror,"\n")
    else:
        get_permissions(dacl)

不要使用cd1中包含的。在

当我试图用特权常量创建一个令牌时,我也得到了相同的Audit Failure(在系统帐户的情况下)。所以我没有找到任何结果,如果没有Audit Faulire在这两种情况下(系统帐户和管理员)(PowerShell除外)。在

相关问题 更多 >