Crto
Crto
Crto
Host Reconnaissance
is a .NET application written in C# that has various
- Seatbelt
"host safety-checks". The information it gathers includes
general OS info, installed antivirus, AppLocker, audit policies,
local users and groups, logon sessions, UAC, Windows
Firewall and more.
Host Persistence
Common userland persistence methods include:
Task Scheaduler
The Windows Task Scheduler allows us to create "tasks" that
execute on a pre-determined trigger. That trigger could be a
time of day, on user-logon, when the computer goes idle,
1/279
when the computer is locked, or a combination thereof.
Let's create a scheduled task that will execute a PowerShell
payload once every hour. To save ourselves from having to
deal with lots of quotations in the IEX cradle, we can encode
it to base64 and execute it using the -EncodedCommand
parameter in PowerShell (often appreciated to -enc).
This is a little complicated to do, because it must use
Unicode encoding (rather than UTF8 or ASCII).
In PowerShell:
2/279
Startup Folder
Applications, files and shortcuts within a user's startup folder
are launched automatically when they first log in. It's
commonly used to bootstrap the user's home environment
(set wallpapers, shortcut's etc).
Registry AutoRun
AutoRun values in HKCU and HKLM allow applications to start
on boot. You commonly see these to start native and 3rd
party applications such as software updaters, download
assistants, driver utilities and so on.
Generate a Windows EXE payload and upload it to the target.
3/279
• -k is the registry key to modify.
• -v is the name of the registry key to create.
COM Hijacks
Instead of hijacking COM objects that are in-use and breaking
applications that rely on them, a safer strategy is to find instances of
applications trying to load objects that don't actually exist (so-called
"abandoned" keys).
4/279
To speed the collection up, click random things, go into the
Windows menu, launch applications etc. After just a few
minutes, I have over 5,000 events - most of them from
Explorer, some from 3rd party software and others from OS
components.
5/279
One aspect to look out for is the number of times a particular
CLSID is loaded. If you hijack one that is loaded every couple
of seconds you're going to have a rough time - so it's well
worth the additional effort to find one that's loaded semi-
frequently but not so much so, or loaded when a commonly-
used application (Word, Excel, Outlook etc) is opened.
6/279
To generate the DLL, go to Attacks > Packages > Windows
Executable (S) and select Windows DLL as the output type.
Then upload the DLL to the location we specified in the
registry entry above.
$Tasks = Get-ScheduledTask
7/279
Host Privilege Escalation
Common methods for privilege escalation include Operating
System or 3rd party software misconfigurations and missing
patches. SharpUp can enumerate the host for any
misconfiguration-based opportunities.
Web Proxies
Many proxies can integrate with Active Directory for user authentication
and to create flexible web access policies.
It's not uncommon to find that sensitive accounts (such as DAs and/or
machine accounts) are prevented from talking out at all - meaning we
can't use HTTP Beacons with them.
Proxy settings are typically deployed via GPO and are written
8/279
into the registry. You can read these manually
(Software\Microsoft\Windows\CurrentVersion\Internet Settings) or with
a tool such as Seatbelt.
In this case, the proxy has added Via and X-Forwarded-For to the HTTP
request. Where squid.dev.cyberbotic.io is the internal FQDN of the
proxy (it also provides the proxy vendor name and a version number!),
and 10.10.17.231 is the internal IP of the originating client (in this
case WKSTN-1).
Peer-to-Peer Listeners
Peer-to-Peer (P2P) listeners allow Beacons to link their communications
9/279
together to form a chain. The P2P types in Cobalt Strike
are TCP and SMB.
These listeners integrate into all the relevant Cobalt Strike workflows
such as spawn, spawnas, inject and jump; and payloads for these
listeners can also be generated in the same way from the Attacks menu.
VIDEO:
BEACON TCP
10/279
11/279
BEACON SMB
12/279
ls \\.\pipe\
13/279
Windows Services
A Windows "service" is a special type of application that is
usually started automatically when the computer boots.
Services are used to start and manage core Windows
functionality such as Windows Defender, Windows Firewall,
Windows Update and more.
14/279
And the Get-Service PowerShell cmdlet.
15/279
A service has several properties that we may want to pay
attention to:
Binary Path
This is the path where the actual executable (.exe) for the service is
located. Windows services are often in C:\Windows\system32 and
third party in C:\Program Files / C:\Program Files (x86)
16/279
Startup Type
Service Status
Log On As
The user account that the service is configured to run as.
We can see that the paths for ALG and AppVClient are not
quoted, but the path for AmazonSSMAgent is.
1. C:\Program.exe
2. C:\Program Files\Vuln.exe
3. C:\Program Files\Vuln Services\Service.exe
19/279
You will not see a Beacon appear automatically. When the
service has been started and the Beacon executed, you
should see that port you used in your TCP listener
configuration (in my case 4444) is listening on 127.0.0.1.
20/279
The Beacon is waiting for us to connect to it, which we do
with the connect command.
22/279
Weak Service Binary Permissions
23/279
This output shows that Users have Modify privileges over
Service 3.exe. This allows us to simply overwrite the binary
with something else (make sure you take a backup first)
24/279
Always Install Elevated
This policy allows standard users to install applications that
require access to directories and registry keys that they may
not usually have permission to change.
26/279
27/279
28/279
29/279
30/279
31/279
32/279
UAC Bypasses
Veterans of Windows Vista will remember the User Account
Control window that popped up every time anything wanted
to perform a privileged operation.
33/279
To run the Command Prompt in high integrity, right-click it,
select "Run as Administrator" and consent to the UAC
dialogue.
34/279
UAC was first introduced in Windows Vista and attracted
complaints from users due to the frequency and annoyance
of the popups, which led Microsoft to introduce some
relaxations.
The default configuration for UAC is Prompt for consent for non-
Windows binaries, but can also have different settings such as
Prompt for credentials, Prompt for consent and Elevate without
prompting.
36/279
Not all UAC bypasses are created equal - some have "quirks"
that you need to be aware of.
37/279
and this will cause actions that require privileged access to
still fail.
38/279
This Beacon will have the necessary token privileges to run
post-ex command such as logonpasswords. The moral of this
story is to research into the specific bypass techniques
before you use them.
39/279
Ahora si funciona
40/279
Domain Reconnaissance
This section will review (at a relatively high level) some of
the information you can enumerate from the current domain
as a standard domain user. We'll cover many of these areas
(domain trusts, Kerberos abuses, GPO abuses, etc) in much
more detail when we get to those specific sections.
For now, we'll see some of the different tooling that can be
used to query the domain, and how we can obtain targeted
information.
It's worth noting that performing domain recon in a high
integrity process is not required, and in some cases (token
duplication) can be detrimental.
PowerView
powershell-import C:\Tools\PowerSploit\Recon\PowerView.ps1
Get-Domain
41/279
Returns a domain object for the current domain or the
domain specified with -Domain. Useful information includes
the domain name, the forest name and the domain
controllers.
Get-DomainController
Returns the domain controllers for the current or specified
domain.
Get-ForestDomain
42/279
Returns all domains for the current forest or the forest
specified by -Forest.
Get-DomainPolicyData
Returns the default domain policy or the domain controller
policy for the current domain or a specified domain/domain
controller. Useful for finding information such as the domain
43/279
password policy.
Get-DomainUser
Return all (or specific) user(s). To only return specific
properties, use -Properties. By default, all user objects for the
current domain are returned, use -Identity to return a
specific user.
Get-DomainComputer
Return all computers or specific computer objects.
44/279
Get-DomainOU
Get-DomainGroup
Return the members of a specific domain group.
45/279
Get-DomainGroupMember
Get-DomainGPO
Return all Group Policy Objects (GPOs) or specific GPO
objects. To enumerate all GPOs that are applied to a
particular machine, use -ComputerIdentity.
46/279
Get-DomainGPOLocalGroup
Returns all GPOs that modify local group memberships
through Restricted Groups or Group Policy Preferences.
Get-
DomainGPOUserLocalGroupMapping
Enumerates the machines where a specific domain user/
47/279
group is a member of a specific local group.
Find-DomainUserLocation
Enumerates all machines and queries the domain for users of
a specified group (default Domain Admins). Then finds
domain machines where those users are logged into.
Get-NetSession
Returns session information for the local (or a remote)
machine (where CName is the source IP).
48/279
Get-DomainTrust
Return all domain trusts for the current or specified domain.
BloodHound
50/279
This will download the files to the Team Server. To save them
onto your desktop go to View > Downloads, select the
files, click Sync Files and choose somewhere to save them.
It works this way so that every operator connected to the
Team Server has access to the same files.
In BloodHound, click the Upload Data button in the menu
on the right and select your ZIP files. Once the files have
been extracted, click the More Info button in the top-left -
the DB Stats and On-Prem Objects should now be populated.
There are multiple ways to search for data in BloodHound.
Since we have a Beacon running as bfarmer, a good first
step could be to find if he has any local admin rights on
machines in the domain. Use the search box in the top-left to
find bfarmer. Scroll down the Node Info tab until you find
the Local Admin Rights section. Click on Group
Delegated Local Admin Rights and BloodHound should
show a simple graph displaying the relationship between
bfarmer and SRV-1.
It shows us that bfarmer is MemberOf the Developers
domain group, which is AdminTo SRV-1.
51/279
Lateral Movement
Moving laterally between computers in a domain is
important for accessing sensitive information/materials, and
obtaining new credentials.
Each method has it's own set of OPSEC concerns - we'll review
some of the main indicators of each technique as we go
through them.
52/279
The remote-exec commands simply provide a means to
execute commands on a remote target.
PowerShell Remoting
54/279
The winrm and winrm64 methods can be used as appropriate
for 32 and 64-bit targets. There are lots of different ways to
determine the architecture of a remote system - one exaple
is to use the Get-WmiObject PowerShell cmdlet.
(Get-WmiObject Win32_OperatingSystem).OSArchitecture
55/279
There are multiple steps to this technique that we leverage
to build a detection mechanism. We can look for egress
network connections with a destination port of 5985.
EXERCISE
PsExec
The psexec / psexec64 commands work by first uploading a
service binary to the target system, then creating and
starting a Windows service to execute that binary. psexec_psh
doesn't copy a binary to the target, but instead executes a
PowerShell one-liner (always 32-bit).
56/279
Beacons executed this way run as SYSTEM.
EXERCISE
Windows Management
Instrumentation (WMI)
As you may have noticed, WMI is not part of the jump
command but it is part of remote-exec.
57/279
The process is now running on SRV-1 so now we need to
connect to it.
EXERCISE
Move laterally to SRV-1 via WMI and investigate the logs in
Kibana.
DCOM
59/279
Beacon has no built-in capabilities to interact over
Distributed Component Object Model (DCOM), so must use
an external tool such as Invoke-DCOM. We'll see in a later
module how this can be integrated into the jump command.
EXERCISE
60/279
Red teams rely on obtaining legitimate user access in order
to reach their objective rather than exploiting systems using
CVEs etc.
61/279
We can see that both jking and svc_mssql are currently
logged into SRV-1 and because we have local admin access,
we can steal and/or impersonate their credential material.
LogonPasswords
The sekurlsa::logonpasswords command in Mimikatz is
infamous for being able to "dump plaintext passwords from
memory". Having a users password has clear advantages
(see Make Token) and was a lucrative tactic for a long time.
62/279
Cobalt Strike also has a short-hand command for this called
logonpasswords.
eKeys
This Mimikatz module will dump Kerberos encryption keys.
65/279
Unfortunately, the hash format is not NTLM.
Make Token
The make_token command in Cobalt Strike uses the LogonUserA
API which takes the username, domain and plaintext
password for a user, as well as a logon type. make_token
passes the LOGON32_LOGON_NEW_CREDENTIALS type, which
the MS docs describe as:
This logon type allows the caller to clone its current token
and specify new credentials for outbound connections. The
66/279
new logon session has the same local identifier but uses
different credentials for other network connections.
68/279
same event. The event itself records the user who ran the
command, the user they're impersonating, and the process it
was run from.
EXERCISE
Process Injection
The inject command will inject a Beacon payload in the form
of shellcode into a target process.
69/279
Token Impersonation
The steal_token command will impersonate the access token
of the target process. Like make_token, it's good for access
resources across a network but not local actions.
EXERCISE
SpawnAs
The spawnas command will spawn a new process using the
plaintext credentials of another user and inject a Beacon
payload into it.
EXERCISE
https://itm4n.github.io/lsass-runasppl/
74/279
Sysmon will record the process creation event for cmd.exe
including the command line arguments echo 1cbe909fe8a > \
\.\pipe\16ca6d. This unusual pattern can be searched for in
Kibana:
76/279
EXERCISE
You can use the NTLM hash or AES keys for a user to request
a Kerberos TGT (explained in more detail in the Kerberos
section).
77/279
When a TGT is requested, event 4768: A Kerberos
authentication ticket (TGT) was requested is
generated. You can see from the output above that the
KeyType is RC4-HMAC (0x17), but the default type for
Windows is now AES256 (0x12).
78/279
This time we can see the KeyType is AES256, and the
generated 4768 joins the sea of 0x12.
A logon session can only hold one TGT at time and we don't
want to clobber the TGT of the user we've compromised.
79/279
The current logon session ID (LUID) is 0x1f253 and there are
four cached tickets.
To pass the TGT into this logon session, we can use Beacon's
kerberos_ticket_use command.
[System.IO.File]::WriteAllBytes("C:
\Users\Administrator\Desktop\jkingTGT.kirbi",
[System.Convert]::FromBase64String("[...ticket...]"))
or bash:
81/279
82/279
EXERCISE
Rubeus triage will list the Kerberos tickets in all the logon
sessions currently on a system (if not elevated, it can only
show tickets in your own logon session).
83/279
jking has a logon session with LUID 0x462eb and the krbtgt
service means that this is a TGT. To extract it from memory,
use Rubeus dump. The /service and /luid flags can be used
to limit the tickets to extract.
84/279
Now use ptt to pass the extracted TGT into the sacrificial
logon session using the /luid flag.
Steal the access token of that process and access the target
resource.
85/279
You can also extract and reuse service tickets (TGS's) using
this technique.
Wordlists
A "wordlist" or "dictionary" attack is the easiest mode of
password cracking, in which we simply read in a list of
password candidates and try each one line-by-line.
86/279
There are many popular lists out there, including the
venerable rockyou list. The SecLists repo also have an
expansive collection for different applications.
Wordlist + Rules
Rules are a means of extending or manipulating the "base"
words in a wordlist in ways that are common habits for users.
87/279
The rockyou list does not contain Summer2020, but it does
contain the base word Summer.
Masks
A brute-force is where we try all combinations from a given
keyspace - for lowercase alphanumeric (of 3 characters), that
would mean trying aaa, aab, aac… all the way to zzz.
89/279
You can combine these charsets within your mask for even
more flexibility. It's also common for password to end with a
special (such as !) rather than a number, but we can specify
both in a mask.
Where:
• -1 ?d?s defines a custom charset (digits and specials).
• ?u?l?l?l?l?l?l?l?1 is the mask, where ?1 is the custom charset.
Hashcat mask files make this process a lot easier for custom
masks that you use often.
91/279
Combinator
The combinator attack combines the entries from two
dictionaries into single-word candidates. Take the following
lists as an example:
You can also apply a rule to each word on the left or right
hand side using the options -j and -k. For instance, -j $- and
-k $! would produce purple-monkey!.
92/279
Hybrid
Hashcat modes 6 and 7 are hybrid's based on wordlists,
masks and the combinator.
Where:
• -a 6 specifies the hybrid wordlist + mask mode.
• ?d?d?d?d is the mask.
kwprocessor
There are a number of external utilities that are separate
from the main hashcat application.
93/279
Here we'll review one called kwprocessor.
Session Passing
Session passing is a means of spawning payloads that can
talk to other Cobalt Strike listeners, or even listeners of
entirely different C2 frameworks.
There are many good reasons for doing this, a few examples
include:
95/279
Now to spawn a Meterpreter session from Beacon, simply
type spawn <listener name>
OPSEC Alert
97/279
This same process can work in reverse, to inject Beacon
shellcode from a Meterpreter session.
98/279
A la inversa de metasploit a cobalt strike
99/279
Pivoting
A SOCKS (Secure Socket) Proxy exchanges network packets
between a client and a server via a "proxy". A common
implementation of a proxy server is found in web proxies -
where a browser will connect to the proxy, which relays
requests to the destination website and back to the browser
(performing filtering etc on the way).
102/279
Windows Apps
We can tunnel GUI apps that run on Windows using a proxy
client such as Proxifier.
103/279
automatically proxied through the Cobalt Strike proxy server
defined above.
104/279
You will then see the traffic being proxied in Proxifier, and
ADExplorer connects successfully.
105/279
Some applications (such as the RSAT tools) don't provide a
means of providing a username or password, because they're
designed to use a user's domain context.
106/279
You will also need to add a static host entry in your C:
\Windows\System32\drivers\etc\hosts file: 10.10.17.71
dev.cyberbotic.io. You can enable DNS lookups through
Proxifier, but that will cause DNS leaks from your computer
into the target environment.
107/279
Metasploit
You can also tunnel Metasploit modules through Beacon's
SOCKS proxy, which is really useful with remote exploits.
108/279
There are two main ways to create a reverse port forward:
1. Windows netsh.
2. Reverse port forward capability built into the C2 framework.
Windows Firewall
Let's start with the Windows Firewall.
Not all of these domains can talk to each other directly - the
traffic flow looks a little like this:
109/279
For instance - cyberbotic.io can talk with dev.cyberbotic.io,
but not to subsidiary.external. So let's use this as an
opportunity to create a reverse port forward that will allow
dc-1.cyberbotic.io to talk to ad.subsidiary.external via
dc-2.dev.cyberbotic.io .
This will bind port 4444, listen for incoming connections and
print a message when something does. This is how we're
going to prove the reverse port forward works.
110/279
The native netsh (short for Network Shell) utility allows you
to view and configure various networking components on a
machine, including the firewall.
Where:
rportfwd Command
112/279
Next, let's look at Beacon's rportfwd command.
113/279
Now any traffic hitting this port will be redirected to
10.10.5.120 on port 80. On DC-2, instead of trying to hit
10.10.5.120:80, we use 10.10.17.231:8080 (where 10.10.17.231
is the IP address of WKSTN-1).
The Web Log in Cobalt Strike also lets us know the request
has reached us.
Aspects to note:
• Beacon's reverse port forward always tunnels the traffic to the Team
Server and the Team Server sends the traffic to its intended destination,
so shouldn't be used to relay traffic between individual machines.
• The traffic is tunnelled inside Beacon's C2 traffic, not over separate
sockets, and also works over P2P links.
114/279
• You don't need to be a local admin to create reverse port forwards on
high ports.
rportfwd_local
This will bind port 8080 on the machine running the Beacon
and will tunnel the traffic to port 8080 of the localhost
running the Cobalt Strike client.
NTLM Relaying
NTLM authentication uses a 3-way handshake between a
client and server. The high-level steps are as follows:
It's still possible to do with Cobalt Strike, but requires the use
of multiple capabilities simultaneously.
1. Use a driver to redirect traffic destined for port 445 to another port
(e.g. 8445) that we can bind to.
2. Use a reverse port forward on the port the SMB traffic is being
redirected to. This will tunnel the SMB traffic over the C2 channel to our
Team Server.
3. The tool of choice (ntlmrelayx) will be listening for SMB traffic on the
Team Server.
4. A SOCKS proxy is required to allow ntlmrelayx to send traffic back
into the target network.
117/279
PortBender is a reflective DLL and Aggressor script specifically
designed to help facilitate this through Cobalt Strike.
It requires local admin access in order for the driver to be
loaded, and that the driver be located in the current working
directory of the Beacon. It makes sense to use C:
\Windows\System32\drivers since this is where most Windows
drivers go.
118/279
Next, load PortBender.cna from C:\Tools\PortBender - this adds
a new PortBender command to the console.
Next, create a reverse port forward that will then relay the
traffic from port 8445 to port 445 on the Team Server (where
ntlmrelayx will be waiting).
119/279
On WKSTN-2, attempt to access WKSTN-1 over SMB.
120/279
Local NTLM hashes could then be cracked or used with pass-
the-hash.
After seeing the hit on the web log, connect to the waiting
Beacon.
121/279
To stop PortBender, stop the job and kill the spawned process.
EXERCISE
Perform the attack above and find the driver load in Kibana.
When the recipients view the email in their mail client, such
as Outlook, it will attempt to download the image over the
UNC path and trigger an NTLM authentication attempt.
EXERCISE
Windows Shortcuts
A Windows shortcut can have multiple properties including a
target, working directory and an icon.
Creating a shortcut with the icon property pointing to a UNC
path will trigger an NTLM authentication attempt when it's
viewed in Explorer (it doesn't even have to be clicked).
EXERCISE
124/279
Create a shortcut in the software share and then view it as
nlamb on WKSTN-2.
Credential Manager
The credential manager blobs are stored in the user's AppData
directory.
125/279
Or mimikatz vault::list.
126/279
To decrypt the credential, we need to find the master
encryption key.
There are a few ways to get the actual Master Key content. If
you have access to a high integrity session, you may be able
to dump it from memory using sekurlsa::dpapi.
Google Chrome
Chrome stores DPAPI-protected credentials in a local SQLite
database, which can be found within the user's local AppData
directory.
129/279
Kerberos
Kerberos is a fun topic and contains some of the more well-
known abuse primitives within Active Directory environments.
130/279
When a user logs onto their workstation, their machine will
send an AS-REQ message to the Key Distribution Center
(KDC), aka Domain Controller, requesting a TGT using a
secret key derived from the user’s password.
131/279
The KDC verifies the secret key with the password it has
stored in Active Directory for that user. Once validated, it
returns the TGT in an AS-REP message. The TGT contains
the user’s identity and is encrypted with the KDC secret key
(the krbtgt account).
Kerberoasting
Services run on a machine under the context of a user
account. These accounts are either local to the machine
(LocalSystem, LocalService, NetworkService) or are domain
accounts (e.g. DOMAIN\mssql).
132/279
Part of the TGS returned by the KDC is encrypted with a
secret derived from the password of the user account running
that service. Kerberoasting is a technique for requesting
TGS’s for services running under the context of domain
accounts and cracking them offline to reveal their plaintext
passwords.
This is pretty bad OPSEC. Judging from the fake SPN set on
the svc_honey account, we may have just wandered into a
trap.
133/279
You can find them in Kibana with:
Depending on how long your lab has been in use, there will
be a lot of events. However, we can filter down to the
specific account name:
134/279
Find all users (in the current domain) where the
ServicePrincipalName field is not blank.
AS-REP Roasting
If a user does not have Kerberos pre-authentication enabled, an AS-REP
can be requested for that user, and part of the reply can be cracked
offline to recover their plaintext password.
135/279
This configuration is also enabled on the User Object and is often seen
on accounts that are used on Linux systems.
In bloodhound:
136/279
MATCH (u:User {dontreqpreauth:true}) RETURN u
EXERCISE
Unconstrained Delegation
Delegation allows a user or a service to act on behalf of another user to
another service.
137/279
We understand how a user performs Kerberos authentication
to the Web Server.
138/279
use them to impersonate the users against other services in
the domain.
In BloodHound:
140/279
141/279
The "Printer Bug"
The MS-RPRN Print System Remote Protocol (hence the cute
name) defines the communications for print job processing
and print system management between a print client and a
print server.
Lee used
142/279
RpcRemoteFindFirstPrinterChangeNotificationEx(), to
set up a change notification between a print server (Machine
A) and a print client (Machine B).
On SRV-1:
On WKSTN-1:
Where:
143/279
• dc-2 is the "target" server
Constrained Delegation
Constrained delegation was soon released as a safer means for services
to perform Kerberos delegation. It aims to restrict the services to
which the server can act on behalf of a user.
144/279
It no longer allows the server to cache the TGTs of other users, but
allows it to request a TGS for another user with its own TGT.
146/279
Or request one using the NTLM / AES keys:
Where:
148/279
Alternate Service Name
149/279
The eventlog service on DC-2 is not immediately useful for
lateral movement, but the service name is not validated in
s4u.
150/279
S4U2self Abuse
As we saw in the previous two examples of constrained
delegation, there are two S4U (Service for User) extensions.
S4U2self (Service for User to Self) and S4U2proxy (Service
for User to Proxy). S4U2self allows a service to obtain a TGS
to itself on behalf of a user, and S4U2proxy allows the
service to obtain a TGS on behalf of a user to a second
151/279
service.
152/279
This is because machines do not get remote local admin
access to themselves over CIFS. What we can do instead is
abuse S4U2self to obtain a TGS to itself, as a user we know is
a local admin (e.g. a domain admin).
PS C:\> [System.IO.File]::WriteAllBytes("C:
\Users\Administrator\Desktop\wkstn-2-s4u.kirbi",
[System.Convert]::FromBase64String("doIFdD [...snip...] MtMiQ="))
153/279
The ServiceName of WKSTN-2$ is not valid for our use - we
want it to be for CIFS.
154/279
Save the ticket and use Rubeus describe again. Notice how
the ServiceName has now changed.
155/279
Linux Credential Cache
Kerberos Credential Cache (ccache) files hold the Kerberos
credentials for a user authenticated to a domain-joined Linux
machine, often a cached TGT.
The ccache files are stored in /tmp and are prefixed with
krb5cc.
We can see by the permission column that only the user and
157/279
root can access them - so for this to be a useful primitive,
root access is required. In this case, svc_oracle has sudo
privileges.
158/279
Now we can use this kirbi with a sacrificial logon session.
160/279
And enrollment CAs:
161/279
Misconfigured Certificate Templates
AD CS certificate templates are provided by Microsoft as a
starting point for distributing certificates. They are designed
to be duplicated and configured for specific needs.
163/279
Convert cert.pfx into a base64 encoded string: cat cert.pfx
| base64 -w 0 and use Rubeus asktgt to request a TGT using
this certificate.
164/279
In the default configuration, these endpoints are vulnerable
to NTLM relay attacks. A common abuse method is to
coerce a domain controller to authenticate to an attacker-
controller location, relay the request to the CA and obtain a
certificate for that DC, then use it to obtain a TGT.
As SYSTEM on SRV-1:
165/279
Start ntlmrelayx with proxychains:
Where:
• 10.10.15.75 is DC-1.
166/279
Where:
• 10.10.15.254 is WKSTN-3.
• 10.10.17.25 is SRV-1.
User Persistence
In this example, I have a Beacon running as DEV\nlamb.
Use Certify to find all the certificates that permit client
authentication:
168/279
This is the default User template provided by Microsoft. The
important aspects are:
169/279
This certificate allows us to request a TGT for nlamb using
Rubeus. It's valid for 1 year (yes, we can use it to request
TGTs for an entire year), and will continue working even if the
user changes their password. It's an excellent user
persistence method because it doesn't involve touching
LSASS and can be utilised without the need for an elevated
context.
Computer Persistence
AD CS Auditing
170/279
AD CS logging is not enabled by default, so it's unsurprisingly common
for defenders to be blind to this activity in their domain.
Logging must be specifically enabled, for which for the following options
are available:
171/279
This request was generated following the steps in
"Misconfigured Certificate Templates". You'll notice that
there's very little useful information here - the template
name is not logged and neither is the subject alternate
name.
172/279
Only then do we see that iyates obtained a certificate for nglover.
173/279
Group Policy
Group Policy is the central repository in a forest or domain
that controls the configuration of computers and users. Group
Policy Objects (GPOs) are sets of configurations that are
applied to Organisational Units (OUs).
• Create GPOs
• Modify existing GPOs
• Link GPOs to OUs
174/279
This PowerView query will show the Security Identifiers (SIDs)
of principals that can create new GPOs in the domain, which
can be translated via ConvertFrom-SID.
This query will return the principals that can write to the GP-
Link attribute on OUs:
From this output, we can see that the 1st Line Support
domain group can both create new GPOs and link them to
several OUs.
175/279
You'll often find instances where users and / or groups can
modify existing GPOs.
This query will return any GPO in the domain, where a 4-digit
RID has WriteProperty, WriteDacl or WriteOwner.
Filtering on a 4-digit RID is a quick way to eliminate the
default 512, 519, etc results.
Pivot Listeners
176/279
This is a good time to segway to talk about Cobalt Strike's Pivot Listener.
This is another type of P2P listener that (currently only) uses TCP, but it
works in the opposite direction to the regular TCP listener.
When you spawn a Beacon payload that uses the TCP listener, that
Beacon acts as a TCP server and waits for an incoming connection from
an existing Beacon (TCP client).
Pivot Listeners are not created via the Listeners menu, but are bound to
individual Beacons. This existing Beacon will bind a port and listen for
incoming connections (acting as the TCP server), and a Beacon payload
that uses the Pivot Listener will act as the TCP client.
177/279
and act accordingly.
178/279
Remote Server Administration Tools
(RSAT)
RSAT is a management component provided by Microsoft to
help manage components in a domain. Since it's a legitimate
management tool and often found on management
workstations and servers, it can be useful to leverage without
having to bring in external tooling.
180/279
MEJOR PONER %COMSPEC% /b /c start /b /min. en la creacion de la
GPO en vez del comando cmd.exe
181/279
SharpGPOAbuse
SharpGPOAbuse allows a wider range of "abusive"
configurations to be added to a GPO. It cannot create GPOs,
so we must still do that with RSAT or modify one we already
have write access to. In this example, we add an Immediate
Scheduled Task to the PowerShell Logging GPO, which will
execute as soon as it's applied.
As all the machines in the domain refresh their GPOs (or if you do it
manually), many Beacons you shall have!
182/279
Discretionary Access Control Lists
There may be instances across the domain where some
principals have ACLs on more privileged accounts, that allow
them to be abused for account-takeover.
183/279
We could also cast a wider net and target entire OUs.
184/279
Reset User Password
Reset a user's password (pretty bad OPSEC).
185/279
Targeted Kerberoasting
Instead of changing the password we can set an SPN on the
account, kerberoast it and attempt to crack offline.
Targeted ASREPRoasting
This is the same idea as above. Modify the User Account
Control value on the account to disable preauthentication
and then ASREProast it.
186/279
Modify Domain Group Membership
If we have the ACL on a group, we can add and remove
members.
187/279
There are other interesting DACLs that can lead to similar
abuses. For instance with WriteDacl you can grant GenericAll
to any principal. With WriteOwner, you can change the
ownership of the object to any principal which would then
inherit GenericAll over it.
MS SQL Servers
Microsoft SQL Server is a relational database management
system commonly found in Windows environments.
You may also search the domain for groups that sound like
they may have access to database instances (for instance,
there is a MS SQL Admins group).
189/279
SQLConnectionTest can be used to test whether or not we
can connect to the database.
190/279
From this output, we can see that bfarmer has the sysadmin
role on the instance.
191/279
We can use InveighZero to listen to the incoming requests (this
should be run as a local admin).
195/279
EXEC xp_cmdshell 'powershell -w hidden -enc <blah>';
196/279
There is a SQL command length limit that will prevent you
from sending large payloads directly in the query, and the
SQL servers cannot reach your Kali IP directly. Reverse Port
Forwards and Pivot Listeners are your friends.
198/279
This output shows a chain from SRV-1 >
SQL-1.CYBERBOTIC.IO >
SQL01.ZEROPOINTSECURITY.LOCAL, the links are configured
with local sa accounts, and we have sysadmin privileges on
each instance.
199/279
200/279
10.10.17.25 es el SRV-1 donde se esta haciendo el portforwading del
puerto 8080 al 80
201/279
And to execute a shell command on
sql01.zeropointsecurity.local, we have to embed multiple
OpenQuery statements (the single quotes get exponentially
more silly the deeper you go):
202/279
In a nutshell, this privilege allows the user to impersonate a
token that it's able to get a handle to.
203/279
204/279
205/279
SweetPotato needs to be compiled in Release mode, to
ensure the NtApiDotNet assembly is merged.
206/279
Domain Dominance
The term "domain dominance" is used to describe a state
where an attacker has reached a high level of privilege in a
domain (such as Domain or Enterprise Admins) and collected
credential material or placed backdoors that
DCSync Backdoor
DCSync is a technique which replicates the MS-DRSR
protocol to replicate AD information, including password
hashes.
Once the change has been made, inspect the domain object
and you will see the changes that have been made.
208/279
209/279
AdminSDHolder Backdoor
The AdminSDHolder is a DACL template used to protect
sensitive principals from modification.
You can test this in the lab by modifying the DACL on the
Domain Admins domain group (e.g. give bfarmer full
control). Within ~60 minutes, you will find this entry will
have vanished.
Protected objects include Enterprise & Domain Admins,
Schema Admins, Backup Operators and krbtgt.
210/279
Once this propagates, the principal will have full control over
the aforementioned sensitive principals.
211/279
212/279
Remote Registry Backdoor
The DAMP project can implement host-based DACL
backdoors to enable the remote retrieval of secrets from a
machine, including SAM and domain cached hashes.
213/279
Skeleton Key
The Skeleton Key is only applicable to Domain Controllers - it
patches LSASS to hijack the usual NTLM and Kerberos
authentication flows and permits any user to be
authenticated with the password mimikatz (their real
passwords still work too).
214/279
Before:
After:
215/279
The skeleton key cannot be removed unless the domain controller is
rebooted and it can cause side effects such as replication issues.
Silver Tickets
A Silver Ticket is a forged TGS, signed using the secret
material (RC4/AES keys) of a machine account.
You may forge a TGS for any user to any service on that
machine, which is useful for short/medium-term persistence
(until the computer account password changes, which is
every 30 days by default).
216/279
Silver and Golden (below) tickets can be generated "offline"
and imported into your session.
Where:
• /user is the username to impersonate.
• /domain is the current domain name.
• /sid is the current domain SID.
• /target is the target machine.
• /aes256 is the AES256 key for the target machine.
• /ticket is the filename to save the ticket as.
217/279
218/279
Golden Tickets
A Golden Ticket is a forged TGT, signed by the domain's
219/279
krbtgt account. Whereas a Silver Ticket can be used to
impersonate any user, it's limited to either that single service
or to any service but on a single machine.
220/279
There are a few methods to help detect golden tickets. The
221/279
more concrete ways are by inspecting Kerberos traffic on the
wire.
Diamond Tickets
Like a golden ticket, a diamond ticket is a TGT which can be
used to access any service as any user.
223/279
Diamond tickets can now be created with Rubeus.
Where:
• /tgtdeleg uses the Kerberos GSS-API to obtain a useable TGT for the
user without needing to know their password, NTLM/AES hash, or
elevation on the host.
• /ticketuser is the username of the principal to impersonate.
• /ticketuserid is the domain RID of that principal. This can be
obtained using a command like powershell Get-DomainUser -
Identity nlamb -Properties objectsid.
• /groups are the desired group RIDs (512 being Domain Admins).
• /krbkey is the krbtgt AES256 hash.
224/279
Rubeus describe will now show that this is a TGT for the
target user.
225/279
Forged Certificates
In larger organisations, the AD CS roles are installed on
separate servers and not on the domain controllers
themselves.
226/279
Often times, they are also not treated with the same
sensitivity as DCs. So whereas only EAs and DAs can access/
manage DCs, "lower level" roles such as server admins can
often access the CAs.
227/279
You can generally tell this is the private CA key because the
Issuer and Subject are both set to the distinguished name of
the CA.
With any luck, the expiry date will also be long into the
future. Save the output to a .pem file and convert it to a
.pfx with openssl on Kali, then move it back to the attacker-
windows machine.
228/279
Even though you can specify any SubjectAltName, the user
does need to be present in AD.
In this example, the default Administrator account is used.
Then we can simply use Rubeus to request a legitimate TGT
with this forged certificate and use it to access the domain
controller.
230/279
If Domain A trusts Domain B, Domain A is the trusting
domain and Domain B is the trusted domain.
Parent/Child
When a child domain is added to a forest, it automatically
231/279
creates a transitive, two-way trust with its parent.
232/279
Golden Ticket
Where:
• /user is the username to impersonate.
• /domain is the current domain.
• /sid is the current domain SID.
• /sids is the SID of the target group to add ourselves to.
• /aes256 is the AES256 key of the current domain's krbtgt account.
• /startoffset sets the start time of the ticket to 10 mins before the
current time.
• /endin sets the expiry date for the ticket to 60 mins.
• /renewmax sets how long the ticket can be valid for if renewed.
233/279
Diamond Ticket
234/279
If dev.cyberbotic.io also had a child (e.g.
test.dev.cyberbotic.io), then a DA in TEST would be able to
use their krbtgt to hop to DA/EA in cyberbotic.io instantly
because the trusts are transitive.
One-Way (Inbound)
dev.cyberbotic.io has a one-way inbound trust with
subsidiary.external.
235/279
Because the trust is inbound from our perspective, it means
that principals in our domain can be granted access to
resources in the foreign domain. We can enumerate the
foreign domain across the trust.
If you only have the user's RC4/AES keys, we can still request
Kerberos tickets with Rubeus but it's more involved. We need
an inter-realm key which Rubeus won't produce for us
automatically, so we have to do it manually.
238/279
will come from the current domain.
PS C:\> [System.IO.File]::WriteAllBytes("C:
\Users\Administrator\Desktop\subsidiary.kirbi",
[System.Convert]::FromBase64String("doIFiD [...snip...] 5hbA=="))
240/279
Foreign Principals can also have DACL abuse primitives,
where DEV\Subsidiary Admins could have abusable DACLs on
principals within the subsidiary.external domain.
One-Way (Outbound)
This can be the most difficult type of trust to hop. Remember
that if Domain A trusts Domain B, users in Domain B can
access resources in Domain A but users in Domain A should
not be able to access resources in Domain B.
241/279
If we're in Domain A, it's by design that we should not be
able to access Domain B, but there are circumstances in
which we can slide under the radar.
Exception calling "FindAll" with "0" argument(s): "A referral was returned
from the server.
Get-DomainGPOUserLocalGroupMappingand Find-
DomainLocalGroupMember can both work as well.
245/279
Our next set of actions depends on a few things.
251/279
Find GPOs that have "LAPS" or some other descriptive term
in the name.
And also any groups that have an edge to machines via LAPS:
253/279
The native LAPS PowerShell cmdlets can be used if they're
installed on a machine we have access to.
254/279
This isn't particularly useful as if you already have Domain
Admin privileges, you probably don't need to leverage the
LAPS passwords. However, if we have the credentials for
somebody in the 1st Line Support, this could allow us to
move laterally to a machine with an even higher-privileged
user logged on.
bfarmer cannot read the LAPS passwords:
255/279
If you don't have access to the native LAPS cmdlets,
PowerView can find the principals that have ReadPropery on ms-
Mcs-AdmPwd. There are also other tools such as the LAPSToolkit.
256/279
LAPS Persistence
If we have the password for a sensitive machine that we'd
like to maintain access to, we can prevent a machine from
updating its password by setting the expiration date into the
future.
257/279
Now even the native cmdlet reports the expiration date to be
the year 2338.
LAPS Backdoors
The PowerShell cmdlets for LAPS can be found in C:
\Windows\System32\WindowsPowerShell\v1.0\Modules\AdmPwd.PS.
The original source code for LAPS can be found here - we can
compile a new copy of the DLL with some hidden backdoors.
In this example, we backdoor the Get-AdmPwdPassword
method to write the password to a file, so that when an
admin legitimately gets a password, we can have a copy.
The original method is very simple (located in Main/
AdmPwd.PS/Main.cs):
258/279
We can add a simple line to append the computer name and
password to a file.
259/279
Use Beacon's timestomp command to "clone" the timestamp
of AdmPwd.PS.psd1 and apply it to AdmPwd.PS.dll.
260/279
There are clearly more subtle ways to go about this, and
dropping to a text file in C:\ is not the best strategy. But
since we have access to source code, we can do anything we
want.
Bypassing Antivirus
Cobalt Strike has two main flavours of artifact. Compiled
(EXEs and DLLs); and scripts (PowerShell, VBA, SCT, etc).
Each workflow uses a particular artifact - for instance, jump
psexec64 uses a compiled x64 service binary and jump
winrm64 uses x64 PowerShell.
Sometimes you will see commands fail:
261/279
The issue with the winrm64 attempt is obvious if you read
the error (not always easy within the XML): "This script
contains malicious content and has been blocked by
your antivirus software"; and error code 225 is
262/279
"Operation did not complete successfully because the
file contains a virus or potentially unwanted
software."
Get-MpThreatDetection is a Windows Defender cmdlet that
can also show detected threats.
Artifact Kit
The artifact kit produces "placeholder" binaries that contain
263/279
all the logic for executing a Beacon, but without the actual
Beacon payload inside. When a payload is generated from
the Cobalt Strike UI, it takes one of these artifact files and
patches it on-the-fly with Beacon shellcode. When executed,
the artifact will load and run that shellcode.
Most artifacts will inject into themselves using VirtualAlloc/
VirtualProtect/CreateThread. The service binary is the only
one that performs remote injection.
Changing existing, or creating new templates, allows you to
change how that shellcode is actually executed, and
subsequently bypass AV signatures and/or behavioural
analysis.
Before we start messing with changing the payload template,
we need an idea of which part(s) Defender is detecting as
malicious. ThreatCheck takes an input file which it splits into
parts, then scans each part to try and find the smallest
component that triggers a positive detection.
Generate a Windows Service EXE and save it to C:\Payloads,
then scan it with ThreatCheck.
264/279
ThreatCheck attempts to find the end of the "bad bytes" and
produces a hex dump up from that point. So the content
closest to the end is what we want to focus on. It looks like
the detection is coming from the string
%c%c%c%c%c%c%c%c%cMSSE-%d-server, which is a good
starting point.
Searching for where MSSE appears in the kit, we find it's in
bypass-pipe.c.
266/279
Copy the whole dist-pipe directory to C:
\Tools\cobaltstrike\ArtifactKit.
Resource Kit
The Resource Kit contains templates for Cobalt Strike's script-
based payloads including PowerShell, VBA and HTA.
268/279
template.x64.ps1 is the template used in jump winrm64,
so let's focus on that.
If we just scan the template (without any Beacon shellcode
even been there), ThreatCheck will show that it is indeed
detected by AMSI.
269/279
This particular output seems to be complaining about the
small block of code around lines 26-28.
AmsiScanBuffer
270/279
271/279
272/279
273/279
274/279
Exclusions
AppLocker
AppLocker is Microsoft's application whitelisting technology
that can restrict the executables, libraries and scripts that
275/279
are permitted to run on a system. AppLocker rules are split
into 5 categories - Executable, Windows Installer, Script,
Packaged App and DLLs, and each category can have its own
enforcement (enforced, audit only, none).
If an AppLocker category is enforced, then by default
everything within that category is blocked. Rules can then be
added to allow principals to execute files within that category
based on a set of criteria. The rules themselves can be
defined based on file attributes such as path, publisher or
hash. AppLocker has a set of default allow rules such as,
"allow everyone to execute anything within C:\Windows\*" -
the theory being that everything in C:\Windows is trusted
and safe to execute.
277/279
This is an example of an overly permissive rule.
DLL enforcement very rarely enabled due to the additional load it can
278/279
put on a system, and the amount of testing required to ensure nothing
will break.
279/279