Windows NTFS File Ownership & Permissions (icacls)


  1. 說明
    1. 關於權限的那些事兒
    2. Subject & Object
    3. CLI
      1. 清除權限
      2. 停止權限繼承
    4. Ownership
  2. Scripts
    1. IIS with AD Authentication
    2. IIS with Annoymous Authentication
    3. IIS Permissions Lab
  3. 參考資料

說明如何查閱、設定 Windows NTFS 檔案與資料夾的擁有者 (Ownership) 以及權限擁有者 (Permissions),同時示範 icacls 以及 takeown 以及 PowerShell 關於權限的使用方式。

logo

說明

Owner
Grant permissions on object without limits
Object Security Descriptors
Container & Objects' set of access control information
ACE
存取控制項,例如授予 Principal 閱讀權限在文字檔上的一個授權行為
DACL
一個物件所有的存取控制項的集合。不具有 DACL 的物件表示所有人都可以存取;擁有 DACL 的物件限符合 ACE 的主體使用。
SACL
定義物件存取行為該如何被稽核 (audit)

關於權限的那些事兒

  • Deny 的權限優先於 Grant
  • 所有的 Deny 都無法阻止 Owner 進行授權
  • Owner 只有一個
  • Share Folder 與 NTFS 的權限是獨立的
  • Share Folder 的權限僅作用在 UNC 存取上
  • UNC 存取上使用的是 Share Folder 與 NTFS 的權限交集
  • NTFS 權限是累加上去的

Subject & Object

Subject

  • User SID
  • Group SID
  • List of privileges
  • Other Access info

Object

  • Object Owner SID
  • Group SID
  • SACL (with ACEs)
  • DACL, Discretionary Access Control (wit ACES)

CLI

icacls C:\temp
C:\temp BUILTIN\Administrators:(I)(OI)(CI)(F)
        NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
        BUILTIN\Users:(I)(OI)(CI)(RX)
        NT AUTHORITY\Authenticated Users:(I)(M)
        NT AUTHORITY\Authenticated Users:(I)(OI)(CI)(IO)(M)
代號 意義
N 不允許存取 No
F 完整存取權 Full
M 修改存取權 Modyify
RX 讀取和執行存取權 Read & Execute
R 唯讀存取權 Read
W 唯寫存取權 Write
D 刪除存取權 Delete
繼承權限 意義
(OI) 物件繼承 Object Inheritance
(CI) 容器繼承 Container Inharitance
(IO) 僅繼承 Inheritance only
(NP) 不傳播繼承 No Propaganda
(I) 從父容器繼承的權限 Inheritance

清除權限

icacls C:\temp /remove domain\userName

停止權限繼承

icacls C:\temp /inheritance:r
參數 用途
e 啟用繼承
d 停用繼承並複製 ACE
r 移除所有繼承的 ACE

Ownership

確認 Ownership 的方式

  • 使用安全性, 進階安全性
  • 使用 Powershell
GET-ACL | Format-List
Path   : Microsoft.PowerShell.Core\FileSystem::C:\Users\domainUser\desktop
Owner  : domain\UserName

Scripts

IIS with AD Authentication

mkdir Websites
icacls Websites /inheritance:r
icacls Websites /grant "iis apppool"\appPoolIdentity:R
icacls Websites /grant domain\authenticated users:R
cd Websites
mkdir UploadFiles
icacls UploadFiles /grant "iis apppool"\appPoolIdentity:W

IIS with Annoymous Authentication

匿名驗證的身分要從 IUSR 調整為 Application Pool Identity

mkdir Websites
icacls Websites /inheritance:r
icacls Websites /grant "iis apppool"\appPoolIdentity:R
cd Websites
mkdir UploadFiles
icacls UploadFile /grant "iis apppool"\appPoolIdentity:W

IIS Permissions Lab

mkdir Websites
icacls Websites /inheritance:r
icacls Websites /grant "iis apppool"\appPoolIdentity:R
cd Websites
mkdir StaticFiles
echo > everyone.txt
icacls everyone.txt /inheritance:r
icacls everyone.txt /grant everyone:R
echo > iis_iusrs.txt
icacls iis_iusrs.txt /inheritance:r
icacls iis_iusrs.txt /grant iis_iusrs:R

參考資料

How Permissions Work

Access Control Overview

How Effective Permissions Are Determined

存取控制清單

ACLs - DACLs/SACLs/ACEs