關於IPC和PTH使用者許可權問題,psexec拒絕訪問(Access Denied)的原因

青瀾Cyan發表於2022-05-05

前瞻

關於net use和psexec無法使用本地管理員組使用者建立連線的問題

測試環境:

win7系統,存在域環境
域名:de1ay
普通域使用者: de1ay\de1ay
域管理員使用者:de1ay\Administrator
本地管理員使用者: de1ay

當我嘗試使用域使用者de1ay\de1ay和本地管理員組的使用者de1ay使用psexec連線目標Windows伺服器執行命令時返回了拒絕訪問,並且在使用net use建立IPC連線的時候返回了Access Denied
image
image
唯一成功的是使用域管使用者de1ay\Administrator成功獲取到cmd

  1. net localgroup Administrators 檢視本地管理員組,存在本地使用者de1ay
  2. net user de1ay /domain 檢視域使用者de1ay
  3. net share 確定ADMIN$開啟了共享

並且確定ADMIN$目錄開啟了共享
image
瞭解到Psexec是藉助的IPC連線執行命令,那麼嘗試使用上面兩組使用者名稱進行IPC連線
image
只有域管使用者成功建立了IPC連線,de1ay/de1ay全域性組成員顯示為Domain Users 普通的域成員,並非管理員,猜測是因為de1ay\de1ay是普通使用者許可權不足,所以無法建立連線。嘗試將de1ay\de1ay加入到Domain Admins域管理員組。

  • net group "Domain Admins" de1ay /add /domain 在域控中執行,新增域管理員

再次嘗試使用de1ay\de1ay使用者連線,果然這次成功建立了對admin$目錄的IPC連線
image
可成功使用Psexec彈回cmd
image
此時回到本地使用者,在我修改了域控的密碼複雜度等組策略並且在目標機器上啟用了Administrator使用者後發現使用目標機器本地的Administrator使用者可以建立對admin$目錄的IPC連線,而同為管理員組下的de1ay又是失敗的。

既然域使用者加入到管理員組後便可以成功建立IPC連線,為什麼本地使用者卻又不行?

聯想到微軟 KB2871997 補丁使攻擊者無法將雜湊傳遞給非內建RID為500(Administrator)的管理用使用者,猜測是否與補丁有關

但是通過查詢補丁發現並沒有安裝KB2871997
image
而且網上也有一些即使未安裝補丁也無法使用本地管理員組非RID500的使用者進行雜湊傳遞安裝了補丁也可以使用RID非500的使用者完成雜湊傳遞的案例,那麼除了補丁外,還有什麼會對這些行為造成影響?

這些問題的罪魁禍首是遠端訪問上下文中的使用者帳戶控制(UAC)令牌過濾

本地使用者和域使用者的訪問控制

微軟的 WindowsVistaUACDevReqs 文件中有如下描述:

  • User Account Control and Remote Scenarios:
    When an administrator logs on to a Windows Vista computer remotely, through Remote Desktop for instance, the user is logged on to the computer as a standard user by default. Remote administration has been modified to be restrictive over a network. This restriction helps prevent malicious software from performing application “loopbacks” if a user is running with an administrator access token.

  • Local User Accounts:
    When a user with an administrator account in a Windows Vista computer’s local Security Accounts Manager (SAM) database remotely connects to a Windows Vista computer, the user has no elevation potential on the remote computer and cannot perform administrative tasks. If the user wants to administer the workstation with a SAM account, the user must interactively logon to the computer that he/she wishes to administer.

  • Domain User Accounts:
    When a user with a domain user account logs on to a Windows Vista computer remotely, and the user is a member of the Administrators group, the domain user will run with a full administrator access token on the remote computer and UAC is disabled for the user on the remote computer for that session.

還有另一份 Description of User Account Control and remote restrictions in Windows Vista 中的描述

  • Local user accounts (Security Account Manager user account):
    When a user who is a member of the local administrators group on the target remote computer establishes a remote administrative connection by using the net use * \remotecomputer\Share$ command, for example, they will not connect as a full administrator. The user has no elevation potential on the remote computer, and the user cannot perform administrative tasks. If the user wants to administer the workstation with a Security Account Manager (SAM) account, the user must interactively log on to the computer that is to be administered with Remote Assistance or Remote Desktop, if these services are available.

  • Domain user accounts (Active Directory user account):
    A user who has a domain user account logs on remotely to a Windows Vista computer. And, the domain user is a member of the Administrators group. In this case, the domain user will run with a full administrator access token on the remote computer, and UAC will not be in effect.
    Note This behavior is not different from the behavior in Windows XP.

對於本地使用者:

  • 當使用遠端計算機上本地管理員組成員的使用者通過net use \\remotecomputer\ 命令建立IPC連線的時候不會以完全管理許可權的管理員身份連線,使用者無法在遠端計算機上提升自己的許可權,並且無法執行管理任務,如果使用者希望使用安全賬戶管理器(SAM)中的使用者管理伺服器,則必須通過遠端桌面連線來登入

即使已啟用遠端管理,內建管理員帳戶之外的本地管理員帳戶也可能不具有遠端管理伺服器的許可權。 必須將遠端使用者帳戶控制(UAC) LocalAccountTokenFilterPolicy登錄檔設定配置為允許除內建管理員帳戶之外的管理員組的本地帳戶遠端管理伺服器。

如果目標伺服器未加入域,請啟用以下注冊表設定:

HKLM\SOFTWARE\Microsoft\Windows\Currentversion\system\LocalAccountTokenFilterPolicy\策略。

在不對系統設定進行更改的情況下,除預設的本地管理員賬戶(Administrators)外無法使用其他本地管理員賬戶完成遠端管理。

對於域使用者(ACTIVE DIRECTORY 賬戶):

  • 大致是說:如果你的計算機是域中的一部分,使用管理員組中的使用者連線遠端計算機,此時UAC 訪問令牌過濾器不會生效,不要使用本地的、非域內使用者的賬戶連線遠端計算機,即使該使用者屬於管理員組
  • 當使用域使用者(並且該域使用者屬於管理員組)遠端登入到計算機時,該使用者會擁有完整的管理員許可權,並且UAC會在該會話期間被禁用

以上便解釋了為什麼本地管理賬戶在利用IPC遠端訪問時會失敗,但是域管理員賬戶可以成功。

Windows已經普遍預設禁用了Administrator使用者,並且在域環境下,由於域控端設定的密碼安全策略,會因為預設的空密碼不滿足域內密碼安全策略中的密碼最小長度導致無法在域機器中啟用該賬戶,除非在域控機器上主動修改域內的密碼安全策略,在官方文件中已經有了解決方法,通過修改登錄檔來解除對非預設管理員賬戶的限制.

在登錄檔中新建如下項:

Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
Value: LocalAccountTokenFilterPolicy
Data: 1 (to disable, 0 enables filtering)
Type: REG_DWORD (32-bit)

image
建立完成後再次測試,本地管理員使用者de1ay成功建立IPC連線,並且Psexec執行成功。
image
至此問題已經解決,總結如下:

  • 預設情況下,只有使用域管理員(歸屬於Domain Admins組)使用者,可以直接進行連線,但本地管理員組中除Administrator使用者外無法進行連線;
  • 新增HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LocalAccountTokenFilterPolicy之後,rid非500的本地管理員賬戶可以進行連線(不影響本地和域的普通使用者),並且可以進行雜湊傳遞攻擊,在此情況下KB2871997補丁將不會有實際作用
使用者(組) 新增登錄檔前 新增登錄檔後
本地管理員(非Administrator) 無許可權 有許可權
Administrator 有許可權 有許可權
域管理員 有許可權 有許可權
普通域使用者 無許可權 無許可權
普通使用者 無許可權 無許可權

參考文章:https://ares-x.com/2020/03/10/關於IPC和PTH使用者許可權問題/

相關文章