313. Here's How Real Adversaries Abuse PowerShell for Discovery
Hello everyone!
Today we'll look at another example of PowerShell abuse. And this time we'll talk about the Discovery tactic.
So, let's look into the report on Gootloader. There're multiple interesting examples of PowerShell abuse.
The adversary uses it to search for accounts with SPNs:
powershell.exe -command "$search = New-Object DirectoryServices.DirectorySearcher([ADSI]''); $search.Filter = '(&(servicePrincipalName=*)(objectCategory=user))'; $results = $search.FindAll(); foreach ($result in $results) { $u = $result.GetDirectoryEntry(); Write-Host $u.name, $u.samaccountname; foreach ($s in $u.servicePrincipalName) { Write-Host $s; } Write-Host '---'; }"
powershell.exe -ExecutionPolicy bypass -Command "$UBcPGBjR99={param($vars);$nZzkzLTK99=$vars.computer;$Error.clear();Get-WmiObject -Class Win32_OperatingSystem -ComputerName $nZzkzLTK99 -ErrorAction SilentlyContinue;$SBUXiYcH99=$error[0];$out='';if($SBUXiYcH99 -eq $null){$out='Local Admin access on: $nZzkzLTK99';}elseif(-not $SBUXiYcH99.Exception.Message.Contains(\"Access is denied.\")){}else{}$out;};$YSUPVCAn99=New-Object System.DirectoryServices.DirectorySearcher;$YSUPVCAn99.SearchRoot=New-Object System.DirectoryServices.DirectoryEntry;$YSUPVCAn99.Filter='(&(sAMAccountType=805306369))';$zcGEXXZD99=$YSUPVCAn99.FindAll()|%{$_.properties.dnshostname};$rsp=[runspacefactory]::CreateRunspacePool(1,100);$rsp.CleanupInterval=New-TimeSpan -Seconds 10;$rsp.open();$jobs=New-Object System.Collections.ArrayList;$i=0;while($i -lt $zcGEXXZD99.Count){$nZzkzLTK99=$zcGEXXZD99[$i];if($rsp.GetAvailableRunspaces() -gt 0){$vars=[PSCustomObject]@{'computer'=$nZzkzLTK99};$PS3=[PowerShell]::Create();$PS3.AddScript($UBcPGBjR99).AddArgument($vars)|Out-Null;$PS3.RunspacePool=$rsp;$jobs+=[PSCustomObject]@{Pipe=$PS3;Status=$PS3.BeginInvoke()};$i++;}else{Sleep -Milliseconds 500;}}while($jobs.Status.IsCompleted -notcontains $true){Sleep -Milliseconds 500;}foreach($job in $jobs){Write-Host $($job.Pipe.EndInvoke($job.Status));$job.Pipe.Dispose();}$rsp.Close();$rsp.Dispose();"
powershell -NoProfile -Command "Write-Host '===== SERVERS ====='; try { $s=New-Object DirectoryServices.DirectorySearcher; $s.Filter='(objectCategory=Computer)'; 'name','dnshostname','operatingsystem','lastlogontimestamp'|%{$s.PropertiesToLoad.Add($_)}; $s.PageSize=5000; $c=0; $s.FindAll()|%{ if($_.Properties['operatingsystem'] -match 'Windows Server') { $n=$_.Properties['name']; $d=$_.Properties['dnshostname']; $o=$_.Properties['operatingsystem']; $l=if($_.Properties['lastlogontimestamp']) { [datetime]::FromFileTime($_.Properties['lastlogontimestamp'][0]) } else { 'N/A' }; Write-Host \"$n, $d, $o, $l\"; $c++ } }; Write-Host \"nCount of all Windows Servers: $c\" } catch { Write-Host \"nError: $($_.Exception.Message)\" }"
event_type: "processcreatewin"
AND
proc_file_path: "powershell.exe"
AND
cmdline: "DirectorySearcher"
See you tomorrow!

Comments
Post a Comment