---
title: "18. Miscellaneous misconfigurations"
date: 2024-09-10
draft: false
---

Portions that require linux: 
`htb-student:HTB_@cademy_stdnt!` 
Open PS and SSH to 172.16.5.225

**Exchange Related Group Membership**
- default (no split admin model): opens atk vectors
- often given high priv via users groups and acls 
- Group: `Exchange Windows Permissions` 
	- members granted ability to write dacl to domain obj
		- can be leveraged to give a user dcsync privs 
	- potentially able to add accts to this group leveraging dacl misconfig
	- pwr users/support staff often added to allow them to change pws
- https://github.com/gdedrouas/Exchange-AD-Privesc
- group: `Organization Management`
	- v powerful `domain admins` of exchange - access mailboxes of all users
	- not uncommon for sysadmins to be apart of this grp 
	- grp has full control of OU called `microsoft exchange security groups` which contains group `exch windows permissions` 

if we compromise exchange server this often leads to domain admin privileges ult 
- dumping creds in memory from an exchange server will produce 10s if not 100s of cleartext creds or ntlm hashes 
	- often due to users logging into outlook web access (OWA) and exchange caching their credentials in memory 

## PrivExchange
results from a flaw in exch. server `pushsubscription` 
- allows domain users w/ mailbox to force server to auth any host provided by client over http 
- exch. svc runs as sys and is overpriv'd by default (has writedacl privs) 
- used to relay to ldap and dump domain ntds db 
- if unable to relay ldap, we can relay+auth to other hosts within domain 
- leads to DA with any authenticated user

## Print bug
Printer bug is flaw in `MS-RPRN` print system remote protocol 
- defines communication of a print job processing + print system mgmt between client + print server 
- to leverage, any domain user can connect to spool's named pipe with `RpcOpenPrinter` method and use `RpcRemoteFindFirstPrinterChangeNotificationEx` 
	- **forces server to auth any host provided by client over smb**

spooler runs as sys and is installed by default in winserv running desktop experience 
- can be leveraged to relay to ldap + grant attacker account dcsync privs to retrieve all pw hashes from AD 
- can be leveraged to relay ldap auth and grant resource-based constrained delegation (RBCD) privs for victim to comp acct under control (thus giving attker priv to auth as any user on victim computer) 
	- this can be levg'd to comp a dom controller in a partner domain/forest provided you have admin access to a DC in the first forest/domain already and the trust allows TGT delegation (not default anymore) 

we can use `Get-SpoolStatus` module 
http://web.archive.org/web/20200919080216/https://github.com/cube0x0/Security-Assessment
https://github.com/NotMedic/NetNTLMtoSilverTicket
to assess vulnerability 

flaw can be used to compromise a host in another forest that has unconstrained delegation enabled; such as a DC. it can help us to attack across forest trusts once we have compromised one forest. 

```bash
PS C:\htb> Import-Module .\SecurityAssessment.ps1
PS C:\htb> Get-SpoolStatus -ComputerName ACADEMY-EA-DC01.INLANEFREIGHT.LOCAL
```

---
## MS14-068 
- Flaw in Kerberos protocol 
- Standard dom user creds elevate to DA 
- Kerb ticket contains user info including acct name id and grp memb. in the `Privilege Attribute Certificate` (PAC) 
	- Signed by KDC using secret keys to validate pac has not been tampered with

This vulnerability allows forged PAC to be accepted by KDC. 
- Levg'd to make fake pac
- Present user as DA group member (or other priv'd group)

https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS14-068/pykek
- Python Kerberos Exploitation Kit (PyKEK) 
- HTB Box - `Mantis` showcases this vulnerability
- Only defense is patching 

---
### Sniffing LDAP credentials

Many apps/printers store LDAP creds in web admin console. 
Consoles often left with weak/default pws. 
Sometimes viewable in cleartext. 
Occasionally `test connection` functionality we can use to gather creds by changing the LDAP IP to that of our atk host and using a netcat listener on ldap port 389 
When device attempts to test LDAP connecction it will send creds to our machine 
Those accounts are often privileged or could be used for foothold. 
Other times, full LDAP server required - see post: 
https://grimhacker.com/2018/03/09/just-a-printer/

---
### Enumerating DNS records
https://github.com/dirkjanm/adidnsdump
- enumerate all DNS records in a domain 
- requires valid domain user 

Post: https://dirkjanm.io/getting-in-the-zone-dumping-active-directory-dns-with-adidnsdump/

Helpful if naming convention for hosts in enumeration using bloodhoudn is similar to something like `SRV01934.INLANEFREIGHT.LOCAL` 

If servers/workstations have non-descriptive names it can make it difficult to know what exactly to attack. If we can access DNS entries in AD, we can find interesting dns records that point to the same server, such as `JENKINS.INLANEFREIGHT.LOCAL` which can be used to determine what to target. 

Tool works because by default, all users can list the child objects of a DNS zone in an AD environment. 
- Querying DNS records with ldap does not return all results
- Using `adidnsdump` we resolve all records in the zone 

```bash
stejwes@htb[/htb]$ adidnsdump -u inlanefreight\\forend ldap://172.16.5.5 

Password: 

[-] Connecting to host...
[-] Binding to host
[+] Bind OK
[-] Querying zone for records
[+] Found 27 records

stejwes@htb[/htb]$ head records.csv 

type,name,value
A,LOGISTICS,172.16.5.240
AAAA,ForestDnsZones,dead:beef::7442:c49d:e1d7:2691
AAAA,ForestDnsZones,dead:beef::231
A,ForestDnsZones,10.129.202.29
A,ForestDnsZones,172.16.5.240
A,ForestDnsZones,172.16.5.5
AAAA,DomainDnsZones,dead:beef::7442:c49d:e1d7:2691
AAAA,DomainDnsZones,dead:beef::231
A,DomainDnsZones,10.129.202.29
```

---
### Other, more specific misconfigurations

#### Passwords in description field
- Sensitive info often found in `Description` or `Notes` fields and enumerateable with Powerview 
- For large domains it's helpful to export this to a CSV for review offline. 

```bash
PS C:\htb> Get-DomainUser * | Select-Object samaccountname,description |Where-Object {$_.Description -ne $null}

samaccountname description
-------------- -----------
administrator  Built-in account for administering the computer/domain
guest          Built-in account for guest access to the computer/domain
krbtgt         Key Distribution Center Service Account
ldap.agent     *** DO NOT CHANGE ***  3/12/2012: Sunsh1ne4All!
```

#### PASSWD_NOTREQD field
Some dom accounts may have this field set in the UAC attribute. If this is set, the user is not subject to the current password policy length, meaning they could have a shorter password or no password at all (if empty pws are allowed) 

Sometimes PWs are set blank intentionally. Or accidentally hitting enter before entering a password when changing it via cmdline. 

```bash
Get-DomainUser -UACFilter PASSWD_NOTREQD | Select-Object samaccountname,useraccountcontrol
```

#### Credentials in SMB shares / SYSVOL scripts
SYSVOL share can be a treasure trove of data especially in large orgs. 
Pillaging: 
- VBScript
- Powershell
- Batch 
scripts within scripts directory readable by all authenticated users in the domain. It's worth digging here for passwords stored in scripts. Sometimes we find very old scripts containing disabled accounts / old pws, but sometimes we will find very relevant creds. 

Module shows an example of finding a script named `reset_local_admin_pass.vbs` that contains password for builtin local administrator on windows host. We can password spray this pw across the domain with nxc and see if we get any hits. 

#### Group Policy Peferences (GPP) Passwords
When GPPS created, xml file created in SYSVOL and also cached locally on endpoints the GP applies to. 

These files are used to: 
- Map drives (drives.xml)
- create local users
- create printer conf files (printers.xml)
- creating/updating services (services.xml) 
- creating scheduled tasks (scheduledtasks.xml) 
- changing local admin pws

These files contain an array of conf data and defined passwords. The `cpassword` attribute value is AES256 encrypted but Microsoft published the AES private key on MSDN which can be used to decrypt. 

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-gppref/2c15cbf0-f086-4c74-8b70-1f2fa45dd4be?redirectedfrom=MSDN

Patched in 2014 
https://support.microsoft.com/en-us/topic/ms14-025-vulnerability-in-group-policy-preferences-could-allow-elevation-of-privilege-may-13-2014-60734e15-af79-26ca-ea53-8cd617073c30

Patch does not remove existing `groups.xml` files with passwords from SYSVOL - if you delete GPP policy instead of unlinking it from the OU the cached copy on local computer remains. 


`gpp-decrypt` can also be used to decrypt the password 
```bash
stejwes@htb[/htb]$ gpp-decrypt VPe/o9YRyz2cksnYRbNeQj35w9KxQ5ttbvtRaAVqxaE
```

GPP pws located by browsing SYSVOL or using `Get-GPPPassword.ps1` (from metasploit post module) or other python/ruby scripts that will locate gpp and returned decrypted cpass 
https://github.com/PowerShellMafia/PowerSploit/blob/master/Exfiltration/Get-GPPPassword.ps1
CME has two modules for locating/retrieving GPP passwords
quick tip regarding GPPs
- often gpp pws defined for legacy accounts
- therefore: retrieve/decrypt pw for a locked/deleted account
- however, worth password spraying internally with this password esp. if it is a unique one. 

PW reuse is widespread. 
```bash
stejwes@htb[/htb]$ crackmapexec smb -L | grep gpp

[*] gpp_autologin             Searches the domain controller for registry.xml to find autologon information and returns the username and password.
[*] gpp_password              Retrieves the plaintext password and other information for accounts pushed through Group Policy Preferences.

```

can also find passwords in files like `Registry.xml` when autologin is configured via group policy. 
- setup for # of reasons for a machine to login on boot 
- If set via GP and not locally on host, anyone on domain can retrieve creds stored in Registry.xml created for this purpose
- Separate issue from GPP Passwords as microsoft has not taken any action to block storing these creds in SYSVOL in cleartext
	- hence - readable by any auth user in domain 
- we can hunt for this with cme `gpp_autologin` module , or `Get-GPPAutologon.ps1` in Powersploit 
```bash
stejwes@htb[/htb]$ crackmapexec smb 172.16.5.5 -u forend -p Klmcargo2 -M gpp_autologin
```
---
#### ASREPRoasting

**ASREPROASTING VS KERBEROASTING**
```bash
AS_REP Roasting is taking place during the initial authentication procedure within Kerberos. It´s abusing the fact, that for accounts with the option Do not require Kerberos preauthentication set, there is no need to send the (normally required) encrypted timestamp (with the users password hash) at the very beginning. Thus everyone on the network who knows the name of an affected account may ask the KDC to authenticate as that user and in return fetch a AS_REP response which partly is encrypted with the AS_REP roastable account´s password hash. Once obtained, an attacker can try to offline crack the hash and fetch the cleartext credentials.

Kerberoasting aims at asking for service tickets related to services on the network where the SPNs are tied to user accounts, rather than computer accounts. The background here is that if a person creates a user he will choose the password most likely according to human standards i.e. a phrase, a word mixed with numbers, etc. If that password is weakly chosen, then it is possible to crack the hash and get the cleartext credentials.
During the process of asking to access a service on the network, the TGS will send a data package that contains a service ticket which is encrypted with the service-account´s password hash, that again like in the AS_REP roasting attack can be cracked offline.
```
It's possible to get TGT for any account that has `do not require kerberos pre-authentication` setting enabled. 
Many vendor installation guides specify svc account must be configured this way. 
Authentication service reply (AS_REP) is encrypted with the account's password and any domain user can request it

With pre-auth
- user enters password, and encrypts a timestamp
- domain controller decrypt this value to validate correct password used
- if success = tgt issued to user for further auth requests 
- if preauth disabled, attacker can request auth data for affected account and retrieve encrypted tgt from Dc and crack offline 

asreproasting is similar to kerberoasting but it involves attacking the AS-REP instead of the TGS-REP - an SPN is not required. 
- enumerated with powerview or powershell AD module 
- can be performed with Rubeus and other tools to obtain ticket for target account 
- if attacker has genericwrite or genericall perms over an account, they can enable this attribute and obtain AS-REP ticket for offline cracking 
- success is dependent on account having a relatively weak password

Enumerating DONT_REQ_PREAUTH
```bash
PS C:\htb> Get-DomainUser -PreauthNotRequired | select samaccountname,userprincipalname,useraccountcontrol | fl
```
once we have this info we can use rubeus to retrieve the ASREP 
does not require any domain user context and can be done just by knowing sam name for the user without kerberos pre-auth 
```bash
.\Rubeus.exe asreproast /user:mmorgan /nowrap /format:hashcat
```
use hashcat mode 18200

if we enumerate using Kerbrute the tool will automatically retrieve AS-REP for any users without kerberos pre-auth 
```bash
stejwes@htb[/htb]$ kerbrute userenum -d inlanefreight.local --dc 172.16.5.5 /opt/jsmith.txt 
```

With a list of valid users we can use `Get-NPUsers.py` from impacket to hunt down all users with kerberos pre-auth not required. 
The tool will retrieve the ASREP in hashcat format. 
We can also feed it the `jsmith.txt` wordlist and it will throw errors for users that do not exist. 
If unable to crack the ASREP it is still good to report this as a finding, just lower risk because we cannot crack it. 
```bash
stejwes@htb[/htb]$ GetNPUsers.py INLANEFREIGHT.LOCAL/ -dc-ip 172.16.5.5 -no-pass -usersfile valid_ad_users 
```

---
#### Group Policy Object (GPO) abuse
- GPOS provide admins many adv. settings that apply to both user/comp objs 
- GPs when set right are great for hardening AD envs
	- when set wrong, abusable 
- if we gain rights of a GPO via an ACL misconfig we can leverage this for laterla movement, privesc and even dom compromise 
- understanding how to enumerate and attack GPOs can give us a legup and sometimes be the ticket for achieving our goal in a locked-down environment. 

GPO misconfigurations can be abused to perform the following attacks:

- Adding additional rights to a user (such as SeDebugPrivilege, SeTakeOwnershipPrivilege, or SeImpersonatePrivilege)
- Adding a local admin user to one or more hosts
- Creating an immediate scheduled task to perform any number of actions

Enumeration is possible using many of the prior tools (Powerview, bloodhound)
Others: 
- `group3r` https://github.com/Group3r/Group3r
- `ADRecon` https://github.com/sense-of-security/ADRecon
- `PingCastle` https://www.pingcastle.com/ 

Using `Get-DomainGPO` function from powerview we can get a listing of GPOs by name 
- helpful to see what sec measures are in place 
	- i.e. denying cmd.exe; sep pw policy for svc accts 
- autologon in use (may mean readable pw in gpo)
- ADCS presence or lack of presence 

If Group Policy Management Tools are installed on the host we are working from we can use various built-in `GroupPolicy cmdlets` such as `Get-GPO` to do the same enum
https://docs.microsoft.com/en-us/powershell/module/grouppolicy/?view=windowsserver2022-ps

`Get-GPO -All | Select DisplayName` 

Next check if a user we can control has any rights over GPOs - Specific user/grps may have that access. See if entire domain user group has rights over one/more GPOs
```bash
PS C:\htb> $sid=Convert-NameToSid "Domain Users"
PS C:\htb> Get-DomainGPO | Get-ObjectAcl | ?{$_.SecurityIdentifier -eq $sid}
```

Use GPO GUID with `Get-Gpo` to see display name 
```bash
PS C:\htb Get-GPO -Guid 7CA9C789-14CE-46E3-A722-83F4097AF532
```
![](/img/Pasted image 20240910180538.png)
https://github.com/FSecureLABS/SharpGPOAbuse
We can use a tool like `SharpGPOAbuse` to take advantage of this GPO misconfig by performing actions like adding users we control to local admin group on one of the affected hosts, creating an immediate scheduled task on one of them to give us a reverse shell, or configure malicious computer startup script to provide us a revshell etc. 
- When using tools like this, be careful because commands can be run in a way that effect every computer within the OU that the GPO is linked to. 
- If we find editable GPO that applies to an OU with 1000 computers we would not want to make the mistake of adding ourselves as a local admin to that many hosts. 
- Some attack options allow us to specify a target user/host 
- Hosts shown in above image are not exploitable and gpo atks are covered indepth later on. 

---
We have seen various misconfigurations that we may run into during an assessment, and there are many more that will be covered in more advanced Active Directory modules. It is worth familiarizing ourselves with as many attacks as possible, so we recommend doing some research on topics such as:

- Active Directory Certificate Services (AD CS) attacks
- Kerberos Constrained Delegation
- Kerberos Unconstrained Delegation
- Kerberos Resource-Based Constrained Delegation (RBCD)

