1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| function Invoke-ProcessBehaviorAnalysis { [CmdletBinding()] param( [Parameter(ValueFromPipeline=$true)] [string]$ComputerName = $env:COMPUTERNAME )
$techniques = Invoke-RestMethod -Uri 'https://attack.mitre.org/api/techniques/' $processes = Get-CimInstance -ClassName Win32_Process -ComputerName $ComputerName
$report = [PSCustomObject]@{ Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' SuspiciousProcesses = @() MITRETechniques = @() }
$processes | ForEach-Object { $behaviorScore = 0 $matchedTechs = @()
if ($_.ParentProcessId -ne 1 -and -not (Get-Process -Id $_.ParentProcessId -ErrorAction SilentlyContinue)) { $behaviorScore += 20 $matchedTechs += 'T1055' }
if ($_.WorkingSetSize -gt 1GB) { $behaviorScore += 15 $matchedTechs += 'T1056' }
if ($behaviorScore -gt 25) { $report.SuspiciousProcesses += [PSCustomObject]@{ ProcessName = $_.Name ProcessId = $_.ProcessId Score = $behaviorScore CommandLine = $_.CommandLine } $report.MITRETechniques += $matchedTechs | Select-Object @{n='TechniqueID';e={$_}}, @{n='Description';e={$techniques.techniques.Where{$_.id -eq $_}.name}} } }
$report | ConvertTo-Json -Depth 3 | Out-File "$env:TEMP/ProcessAnalysis_$(Get-Date -Format yyyyMMdd).json" return $report }
|