Windows命令行查看/设置指定文件的owner

admin 2023年9月26日15:24:30评论36 views字数 2148阅读7分9秒阅读模式

7.15 命令行查看/设置指定文件的owner

https://scz.617.cn/windows/202309251425.txt

Q:

Win10命令行如何查看、设置指定文件的owner?GUI界面我会操作。

A:

查看owner:

dir /q some.ext

该命令会显示some.ext的owner,但有个缺陷

dir /q C:WindowsSystem32notepad.exe | findstr notepad.exe

01/08/2021  06:37           243,200 NT SERVICETrustedInstanotepad.exe

倒数第二列的owner本应是"NT SERVICETrustedInstaller",被截断了。

wmic path Win32_LogicalFileSecuritySetting where Path="C:\Windows\System32\notepad.exe" ASSOC /RESULTROLE:Owner /ASSOCCLASS:Win32_LogicalFileOwner /RESULTCLASS:Win32_SID

… S-1-5-80-…-2271478464 … TrustedInstaller … NT SERVICE …

表示owner是"NT SERVICETrustedInstaller",其SID是

S-1-5-80-...-2271478464

已知SID,查询名称:

PowerShell中执行

[wmi]"Win32_SID.SID='S-1-5-80-...-2271478464'"
---------------------------------------
$sid = 'S-1-5-80-...-2271478464';
$obj = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList $sid;
$obj.Translate([System.Security.Principal.NTAccount]).Value;
---------------------------------------
$sid = 'S-1-5-80-...-2271478464';
$obj = New-Object System.Security.Principal.SecurityIdentifier($sid);
$obj.Translate([System.Security.Principal.NTAccount]).Value;

若SID对应普通用户,而非内置SID,下列命令亦可查询名称:

wmic useraccount where sid="S-1-5-21-...-1001" get Caption

上述命令无法查询内置SID的名称

A:

设置owner:

icacls C:tempnotepad.exe /setowner "DESKTOP-TESTscz"
icacls C:tempnotepad.exe /setowner "NT SERVICETrustedInstaller"

在管理员级cmd中执行上述命令,下列命令检验效果:

dir /q C:tempnotepad.exe
wmic path Win32_LogicalFileSecuritySetting where Path="C:\temp\notepad.exe" ASSOC /RESULTROLE:Owner /ASSOCCLASS:Win32_LogicalFileOwner /RESULTCLASS:Win32_SID

A:

获取owner:

takeown /f C:tempnotepad.exe

不同于"icacls /setowner"指定owner,takeown固定将owner改成当前用户

A:

SubInACL
https://web.archive.org/web/20190830103837/http://www.microsoft.com/en-us/download/confirmation.aspx?id=23510
https://web.archive.org/web/20190830103837/https://download.microsoft.com/download/1/7/d/17d82b72-bc6a-4dc8-bfaa-98b37b22b367/subinacl.msi

微软已经下架了该工具,上面是archive备份。

设置owner:

subinacl /file C:tempnotepad.exe /setowner="DESKTOP-TESTscz"
subinacl /file C:tempnotepad.exe /setowner="NT SERVICETrustedInstaller"

查看owner:

subinacl /file C:tempnotepad.exe /display=owner

原文始发于微信公众号(青衣十三楼飞花堂):Windows命令行查看/设置指定文件的owner

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年9月26日15:24:30
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Windows命令行查看/设置指定文件的ownerhttps://cn-sec.com/archives/2068929.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息