2018年6月13日 星期三

Windows 7 ~ 10 系統 cacls / icacls / takeown 權限

微軟官方 說明 Cacls
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cacls_1

微軟官方 說明 iCacls
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/icacls


檢查方式?

cacls c: /t

將列出 C磁碟 的檔案權限檢查

icacls c: /t

將列出 C磁碟 的檔案權限檢查




以下網路上擷取參照


CACLS : 顯示或修改檔案的存取控制清單 (ACLs)。

指令詳解:

CACLS filename [/T] [/E] [/C] [/G user:perm] [/R user [...]]
[/P user:perm [...]] [/D user [...]]
filename 顯示 ACL。
/T 變更指定檔案的 ACL 於現有的目錄或所有子目錄中。
/E 編輯 ACL 而非將它取代。
/C 拒絕存取的錯誤繼續發生。
/G user:perm 授與指定的使用者存取權限。
Perm 的值可以是: R 讀取
C 變更 (寫入)
F 完全控制
/R user 撤銷已指定的使用者存取權限 (只有當 /E 存在時才有效)。
/P user:perm 取代已指定的使用者存取權限。
Perm 的值可以是: N 沒有權限
R 讀取
C 變更 (寫入)
F 完全控制
/D user 拒絕已指定的使用者存取。
您可以在命令中使用萬用字元一次指定數個檔案。
您可以在命令中指定數個使用者。
縮寫:
CI - 容器繼承。
ACE 將被目錄繼承。
OI - 物件繼承。
ACE 將被檔案繼承。
IO - 僅供繼承。
ACE 不可套用到目前的檔案/目錄。




命令提示字元 指令 icaals



Parameter Description
Specifies the file for which to display DACLs.
Specifies the directory for which to display DACLs.
/t Performs the operation on all specified files in the current directory and its subdirectories.
/c Continues the operation despite any file errors. Error messages will still be displayed.
/l Performs the operation on a symbolic link versus its destination.
/q Suppresses success messages.
[/save [/t] [/c] [/l] [/q]] Stores DACLs for all matching files into ACLfile for later use with /restore.
[/setowner [/t] [/c] [/l] [/q]] Changes the owner of all matching files to the specified user.
[/findSID [/t] [/c] [/l] [/q]] Finds all matching files that contain a DACL explicitly mentioning the specified security identifier (SID).
[/verify [/t] [/c] [/l] [/q]] Finds all files with ACLs that are not canonical or have lengths inconsistent with ACE (access control entry) counts.
[/reset [/t] [/c] [/l] [/q]] Replaces ACLs with default inherited ACLs for all matching files.
[/grant[:r] :[...]] Grants specified user access rights. Permissions replace previously granted explicit permissions.
Without :r, permissions are added to any previously granted explicit permissions.
[/deny :[...]] Explicitly denies specified user access rights. An explicit deny ACE is added for the stated permissions and the same permissions in any explicit grant are removed.
[/remove[:g :d]] [...]] [/t] [/c] [/l] [/q]
[/setintegritylevel [(CI)(OI)]:[...]] Explicitly adds an integrity ACE to all matching files. Level is specified as:
- L[ow]
- M[edium]
- H[igh]
Inheritance options for the integrity ACE may precede the level and are applied only to directories.
[/substitute [...]] Replaces an existing SID (SidOld) with a new SID (SidNew). Requires the Directory parameter.
/restore [/c] [/l] [/q] Applies stored DACLs from ACLfile to files in the specified directory. Requires the Directory parameter.
Remarks
SIDs may be in either numerical or friendly name form. If you use a numerical form, affix the wildcard character * to the beginning of the SID.
icacls preserves the canonical order of ACE entries as:
Explicit denials
Explicit grants
Inherited denials
Inherited grants
Perm is a permission mask that can be specified in one of the following forms:

A sequence of simple rights:

F (full access)

M (modify access)

RX (read and execute access)

R (read-only access)

W (write-only access)

A comma-separated list in parenthesis of specific rights:

D (delete)

RC (read control)

WDAC (write DAC)

WO (write owner)

S (synchronize)

AS (access system security)

MA (maximum allowed)

GR (generic read)

GW (generic write)

GE (generic execute)

GA (generic all)

RD (read data/list directory)

WD (write data/add file)

AD (append data/add subdirectory)

REA (read extended attributes)

WEA (write extended attributes)

X (execute/traverse)

DC (delete child)

RA (read attributes)

WA (write attributes)

Inheritance rights may precede either Perm form, and they are applied only to directories:

(OI): object inherit

(CI): container inherit

(IO): inherit only

(NP): do not propagate inherit

Examples
To save the DACLs for all files in the C:\Windows directory and its subdirectories to the ACLFile file, type:

icacls c:\windows\* /save aclfile /t
To restore the DACLs for every file within ACLFile that exists in the C:\Windows directory and its subdirectories, type:

icacls c:\windows\ /restore aclfile
To grant the user User1 Delete and Write DAC permissions to a file named "Test1", type:

icacls test1 /grant User1:(d,wdac)
To grant the user defined by SID S-1-1-0 Delete and Write DAC permissions to a file, named "Test2", type:

icacls test2 /grant *S-1-1-0:(d,wdac)





以下為完整描述及範例:

1. ICACLS name /save aclfile [/T] [/C] [/L] [/Q]:將符合名稱之檔案與資料夾的DACL 儲存至aclfile,以供稍後與
/restore 搭配使用。請注意,這不會儲存SACL、擁有者或完整性標籤。

2. ICACLS directory [/substitute SidOld SidNew [...]] /restore aclfile [/C] [/L] [/Q]:將儲存的DACL 套用到目錄中的檔案。

3. ICACLS name /setowner user [/T] [/C] [/L] [/Q]:變更所有相符名稱的擁有者。此選項不會強制變更擁有權;如果要強制變更擁有權,請使用takeown.exe 公用程式。

4. ICACLS name /findsid Sid [/T] [/C] [/L] [/Q]:尋找內含明確提及Sid 之ACL 的所有相符名稱。

5. ICACLS name /verify [/T] [/C] [/L] [/Q]:尋找含有未使用標準格式的ACL 或長度與ACE 計數不一致的所有檔案。

6. ICACLS name /reset [/T] [/C] [/L] [/Q]:針對所有符合的檔案,使用預設繼承的ACL 取代ACL。

7. ICACLS name [/grant[:r] Sid:perm[...]]

[/deny Sid:perm [...]]

[/remove[:g|:d]] Sid[...]] [/T] [/C] [/L] [/Q]

[/setintegritylevel Level:policy[...]]

a. /grant[:r] Sid:perm:授與指定的使用者存取權限。若加上:r,該權限便會取代先前授與的明確權限。若不加上

:r,則會將權限加入先前授與的任何明確權限。

b. /deny Sid:perm:明確拒絕指定的使用者存取權限。對指定的權限新增明確拒絕的ACE,並將任何明確授與中

的相同權限移除。

c. /remove[:[g|d]] Sid:會移除ACL 中Sid 的所有符合項目。若加上:g,會將授與該Sid 之權限的所有符合項目移

除。若加上:d,則會將拒絕該Sid 之權限的所有符合項目移除。

d. /setintegritylevel [(CI)(OI)]Level:明確地新增完整性ACE 至所有符合的檔案。

可指定下列層級的其中一個:L[ow]、M[edium]、H[igh]

完整性ACE 的繼承選項具有高於層級的優先性,且只會套用到目錄。

e. /inheritance:e(啟用繼承)|d(停用繼承並複製ACE)|r(移除所有繼承的ACE)



注意:

1. Sid 的格式可以是數字或好記的名稱。如果指定使用數字格式,請在SID 的開頭加上*。
2. /T:指示要在name 指定之目錄下的所有相符檔案/目錄上執行此操作。
3. /C:指示不論發生任何檔案錯誤,都繼續執行此操作。仍會顯示錯誤訊息。
4. /L:指示此操作會在符號連結(而非其目標) 上執行。
5. /Q:指示icacls 應隱藏成功訊息。
6. ICACLS 保留ACE 項目的標準順序:明確拒絕、明確授與、繼承拒絕、繼承授與
7. perm 是權限遮罩,可使用下列其中一種格式來指定:

a. 一連串簡單權限:

N - 不允許存取
F - 完整存取權
M - 修改存取權
RX - 讀取和執行存取權
R - 唯讀存取權
W - 唯寫存取權
D - 刪除存取權

b. 在括號中以逗號分隔特定權限的清單:

DE - 刪除
RC - 讀取控制
WDAC - 寫入DAC
WO - 寫入擁有者
S - 同步
AS - 存取系統安全性
MA - 允許的最大值
GR - 一般讀取
GW - 一般寫入
GE - 一般執行
GA - 一般所有權限
RD - 讀取資料/列出目錄
WD - 寫入資料/新增檔案
AD - 附加資料/新增子目錄
REA - 讀取擴充屬性
WEA - 寫入擴充屬性
X - 執行/周遊
DC - 刪除子系
RA - 讀取屬性
WA - 寫入屬性

c. 繼承權限的優先順序高於上述任一種格式,且僅套用到目錄:
(OI) - 物件繼承
(CI) - 容器繼承
(IO) - 僅繼承
(NP) - 不傳播繼承
(I) - 從父容器繼承的權限

範例:

1. icacls c:\windows\* /save AclFile /T:會將c:\windows 及其子目錄下所有檔案的ACL 儲存到AclFile。
2. icacls c:\windows\ /restore AclFile:會還原AclFile 之中每個檔案的Acl,而AclFile 位於c:\windows及其子目錄下。
3. icacls file /grant Administrator:(D,WDAC):會將檔案的刪除和寫入DAC 權限授與使用者Administrator。
4. icacls file /grant *S-1-1-0:(D,WDAC):會將檔案的刪除和寫入DAC 權限授與sid S-1-1-0 所定義的使用者。


------------------------------------------------------------------------------

icacls: Takeown: 改變檔案擁有權


代碼:

C:\WINDOWS\system32>icacls

ICACLS name /save aclfile [/T] [/C] [/L] [/Q]
將符合名稱之檔案與資料夾的 DACL 儲存至 aclfile,以供稍後與
/restore 搭配使用。請注意,這不會儲存 SACL、擁有者或完整
性標籤。

ICACLS directory [/substitute SidOld SidNew [...]] /restore aclfile
[/C] [/L] [/Q]
將儲存的 DACL 套用到目錄中的檔案。

ICACLS name /setowner user [/T] [/C] [/L] [/Q]
變更所有相符名稱的擁有者。此選項不會強制變更擁有權; 如果要強制變更擁有
權,請使用 takeown.exe 公用程式。

ICACLS name /findsid Sid [/T] [/C] [/L] [/Q]
尋找內含明確提及 Sid 之 ACL 的所有相符名稱。

ICACLS name /verify [/T] [/C] [/L] [/Q]
尋找含有未使用標準格式的 ACL 或長度與 ACE 計數不一致的所有檔案。

ICACLS name /reset [/T] [/C] [/L] [/Q]
針對所有符合的檔案,使用預設繼承的 ACL 取代 ACL。

ICACLS name [/grant[:r] Sid:perm[...]]
[/deny Sid:perm [...]]
[/remove[:g|:d]] Sid[...]] [/T] [/C] [/L] [/Q]
[/setintegritylevel Level:policy[...]]

/grant[:r] Sid:perm 授與指定的使用者存取權限。若加上 :r,該權限便會取
代先前授與的明確權限。若不加上 :r,則會將權限加入先前授與的任何明
確權限。

/deny Sid:perm 明確拒絕指定的使用者存取權限。對指定的權限新增明確拒絕的
ACE,並將任何明確授與中的相同權限移除。

/remove[:[g|d]] Sid 會移除 ACL 中 Sid 的所有符合項目。若加上 :g,會將授
與該 Sid 之權限的所有符合項目移除。若加上 :d,則會將拒絕該 Sid 之權
限的所有符合項目移除。

/setintegritylevel [(CI)(OI)]Level 明確地新增完整性 ACE 至所有符合的檔
案。可指定下列層級的其中一個:
L[ow]
M[edium]
H[igh]
完整性 ACE 的繼承選項具有高於層級的優先性,且只會套用到目錄。

/inheritance:e|d|r
e - 啟用繼承
d - 停用繼承並複製 ACE
r - 移除所有繼承的 ACE


注意:
Sid 的格式可以是數字或好記的名稱。如果指定使用數字格式,請在 SID 的開頭
加上 *。

/T 指示要在 name 指定之目錄下的所有相符檔案/目錄上執行此操作。

/C 指示不論發生任何檔案錯誤,都繼續執行此操作。仍會顯示錯誤訊息。

/L 指示此操作會在符號連結 (而非其目標) 上執行。

/Q 指示 icacls 應隱藏成功訊息。

ICACLS 保留 ACE 項目的標準順序:
明確拒絕
明確授與
繼承拒絕
繼承授與

perm 是權限遮罩,可使用下列其中一種格式來指定:
一連串簡單權限:
N - 不允許存取
F - 完整存取權
M - 修改存取權
RX - 讀取和執行存取權
R - 唯讀存取權
W - 唯寫存取權
D - 刪除存取權
在括號中以逗號分隔特定權限的清單:
DE - 刪除
RC - 讀取控制
WDAC - 寫入 DAC
WO - 寫入擁有者
S - 同步
AS - 存取系統安全性
MA - 允許的最大值
GR - 一般讀取
GW - 一般寫入
GE - 一般執行
GA - 一般所有權限
RD - 讀取資料/列出目錄
WD - 寫入資料/新增檔案
AD - 附加資料/新增子目錄
REA - 讀取擴充屬性
WEA - 寫入擴充屬性
X - 執行/周遊
DC - 刪除子系
RA - 讀取屬性
WA - 寫入屬性
繼承權限的優先順序高於上述任一種格式,且僅套用到目錄:
(OI) - 物件繼承
(CI) - 容器繼承
(IO) - 僅繼承
(NP) - 不傳播繼承
(I) - 從父容器繼承的權限

範例:

icacls c:\windows\* /save AclFile /T
- 會將 c:\windows 及其子目錄下所有檔案的 ACL 儲存到 AclFile。

icacls c:\windows\ /restore AclFile
- 會還原 AclFile 之中每個檔案的 Acl,而 AclFile 位於 c:\windows
及其子目錄下。

icacls file /grant Administrator:(D,WDAC)
- 會將檔案的刪除和寫入 DAC 權限授與使用者 Administrator。

icacls file /grant *S-1-1-0:(D,WDAC)
- 會將檔案的刪除和寫入 DAC 權限授與 sid S-1-1-0 所定義的使用者。






------------------------------------------------------------------------------------------------------



C:\WINDOWS\system32>takeown /?

TAKEOWN [/S system [/U username [/P [password]]]]
/F filename [/A] [/R [/D prompt]]

描述:
這個工具可以讓系統管理員恢復之前被拒絕重新指派檔案擁有權。

參數清單:
/S system 指定要連線的遠端系統。
/U [domain\]user 指定執行命令的使用者內容。
/P [password] 指定使用者密碼。
如果省略,會出現密碼輸入要求。

/F filename 指定檔案名稱或目錄 名稱模式。萬用字元 "*" 可以用來指定 模式。允許 sharename\filename。

/A 將擁有權給予系統管理員,而非目前的使用者。

/R 遞迴搜尋: 指示工具在指定的目錄和所有子目錄中的檔案操作。

/D prompt 當目前的使用者沒有目錄 "list folder" 使用權時,所使用的預設回答。在子目錄遞迴操作時將發生
此情況。要取得擁有權,有效值為 "Y",要略過則是 "N"。

/SKIPSL 請勿接著符號連結。 僅可與 /R 搭配使用。

/? 顯示這個說明訊息。

注意: 1) 如果沒有指定 /A,檔案擁有權將給予
目前登入的使用者。

2) 不支援混合使用 "?" 和 "*"。

3) 要壓抑確認提示,請用 /D。

範例:
TAKEOWN /?
TAKEOWN /F lostfile
TAKEOWN /F \\system\share\lostfile /A
TAKEOWN /F directory /R /D N
TAKEOWN /F directory /R /A
TAKEOWN /F *
TAKEOWN /F C:\Windows\System32\acme.exe
TAKEOWN /F %windir%\*.txt
TAKEOWN /S system /F MyShare\Acme*.doc
TAKEOWN /S system /U user /F MyShare\MyBinary.dll
TAKEOWN /S system /U domain\user /P password /F share\filename
TAKEOWN /S system /U user /P password /F Doc\Report.doc /A
TAKEOWN /S system /U user /P password /F Myshare\*
TAKEOWN /S system /U user /P password /F Home\Logon /R
TAKEOWN /S system /U user /P password /F Myshare\directory /R /A

C:\WINDOWS\system32>