PowerShell ืืื ืืื ืืืืืืฆืื ื ืคืืฅ ืืืื, ืืืฉืืฉ ืืขืชืื ืงืจืืืืช ืื ืืคืชืื ืชืืื ืืช ืืืื ืืืช ืืื ืืืืื ืืืืืช ืืืืข.
ืืืืจ ืื ืืืื ืืืคืฉืจืืช ืฉื ืฉืืืืฉ ื- PowerShell ืืืืกืืฃ ืืจืืืง ื ืชืื ืื ืืืืฉืืจื ืงืฆื ืืขืช ืชืืืื ืืืืจืืขื ืืืืืช ืืืืข. ืืฉื ืื ืชืฆืืจืื ืืืชืื ืกืงืจืืคื ืฉืืคืขื ืขื ืืืฉืืจ ืืงืฆื ืืืืืจ ืืื ืืืื ืชืืืืจ ืืคืืจื ืฉื ืืกืงืจืืคื ืืื.
function CSIRT{
param($path)
if ($psversiontable.psversion.major -ge 5)
{
$date = Get-Date -Format dd.MM.yyyy_hh_mm
$Computer = $env:COMPUTERNAME
New-Item -Path $path$computer$date -ItemType 'Directory' -Force | Out-Null
$path = "$path$computer$date"
$process = get-ciminstance -classname win32_process | Select-Object creationdate, processname,
processid, commandline, parentprocessid
$netTCP = Get-NetTCPConnection | select-object creationtime, localaddress,
localport, remoteaddress, remoteport, owningprocess, state
$netUDP = Get-NetUDPEndpoint | select-object creationtime, localaddress,
localport, remoteaddress, remoteport, owningprocess, state
$task = get-ScheduledTask | Select-Object author, actions, triggers, state, description, taskname|
where author -notlike '*ะะฐะนะบัะพัะพัั*' | where author -ne $null |
where author -notlike '*@%systemroot%*' | where author -notlike '*microsoft*'
$job = Get-ScheduledJob
$ADS = get-item * -stream * | where stream -ne ':$Data'
$user = quser
$runUser = Get-ItemProperty "HKCU:SoftwareMicrosoftWindowsCurrentVersionRun"
$runMachine = Get-ItemProperty "HKLM:SoftwareMicrosoftWindowsCurrentVersionRun"
$array = $process, $netTCP, $netUDP, $task, $user, $runUser, $runMachine, $job, $ADS
$arrayName = "Processes", "TCPConnect", "UDPConnect", "TaskScheduled", "Users", "RunUser", "RunMachine",
"ScheduledJob", "AlternativeDataStream"
for ($w = 0; $w -lt $array.count; $w++){
$name = $arrayName[$w]
$array[$w] >> $path$name.txt
}
}
}
ืืื ืืืชืืื, ืฆืืจ ืคืื ืงืฆืื ืกืืืืช CSIRT, ืฉืืืงื ืืจืืืื ื - ืื ืชืื ืืฉืืืจืช ืื ืชืื ืื ืฉืืชืงืืื. ืืฉื ืืขืืืื ืฉืจืื ื-cmdlets ืคืืขืืื ื-Powershell v5, ืืจืกืช PowerShell ื ืืืงื ืืคืขืืื ื ืืื ื.
function CSIRT{
param($path)# ะฟัะธ ะทะฐะฟััะบะต ัะบัะธะฟัะฐ ะฝะตะพะฑั
ะพะดะธะผะพ ัะบะฐะทะฐัั ะดะธัะตะบัะพัะธั ะดะปั ัะพั
ัะฐะฝะตะฝะธั
if ($psversiontable.psversion.major -ge 5)
ืืื ืืืงื ืขื ืื ืืืื ืืื ืืงืืฆืื ืฉื ืืฆืจื, ืฉื ื ืืฉืชื ืื ืืืืชืืืื: $date ื-$Computer, ืฉืืืงืฆื ืืื ืฉื ืืืืฉื ืืืชืืจืื ืื ืืืื.
$date = Get-Date -Format dd.MM.yyyy_hh_mm
$Computer = $env:COMPUTERNAME
New-Item -Path $path$computer$date โItemType 'Directory' -Force | Out-Null
$path = "$path$computer$date"
ืื ื ืืงืืืื ืืช ืจืฉืืืช ืืชืืืืืื ืืจืฆืื ืืืขื ืืืฉืชืืฉ ืื ืืืื ืืืืคื ืืื: ืฆืืจ ืืฉืชื ื $process, ืืงืฆื ืื ืืช ื-cmdlet get-ciminstance ืขื ืืืืืงื win32_process. ืืืืฆืขืืช ื-cmdlet Select-Object, ื ืืชื ืืืืกืืฃ ืคืจืืืจื ืคืื ื ืืกืคืื, ืืืงืจื ืฉืื ื ืืื ืืืื parentprocessid (ืืืื ืชืืืื ืื PPID), ืชืืจืื ืืฆืืจื (ืชืืจืื ืืฆืืจืช ืชืืืื), ืืขืืื (ืืืื ืชืืืื PID), ืฉื ืชืืืื (ืฉื ืชืืืื), ืฉืืจืช ืคืงืืื ( ืืคืขื ืคืงืืื).
$process = get-ciminstance -classname win32_process | Select-Object creationdate, processname, processid, commandline, parentprocessid
ืืื ืืงืื ืจืฉืืื ืฉื ืื ืืืืืจื TCP ื-UDP, ืฆืืจ ืืช ืืืฉืชื ืื $netTCP ื-$netUDP ืขื ืืื ืืงืฆืืช ื-cmdlets Get-NetTCPConnection ื-Get-NetTCPConnection, ืืืชืืื.
$netTCP = Get-NetTCPConnection | select-object creationtime, localaddress, localport, remoteaddress, remoteport, owningprocess, state
$netUDP = Get-NetUDPEndpoint | select-object creationtime, localaddress, localport, remoteaddress, remoteport, owningprocess, state
ืืฉืื ืืืื ืืืจืจ ืืช ืจืฉืืืช ืืืฉืืืืช ืืืืฉืืืืช ืืืชืืื ื ืืช. ืืฉื ืื, ืื ื ืืฉืชืืฉืื ื-cmdlets get-ScheduledTask ื-Get-ScheduledJob. ืืืื ื ืงืฆื ืืื ืืช ืืืฉืชื ืื $task ื-$job, ืื ืืชืืืื ืืฉ ืืจืื ืืฉืืืืช ืืชืืืื ืืช ืืืขืจืืช, ืืื ืืื ืืืืืช ืคืขืืืืช ืืืื ืืช ืืืื ืืกื ื ืืฉืืืืช ืืชืืืื ืืช ืืืืืืืืืช. ื-cmdlet Select-Object ืืขืืืจ ืื ื ืืื.
$task = get-ScheduledTask | Select-Object author, actions, triggers, state, description, taskname| where author -notlike '*ะะฐะนะบัะพัะพัั*' | where author -ne $null | where author -notlike '*@%systemroot%*' | where author -notlike '*microsoft*' # $task ะธัะบะปััะฐะตั ะฐะฒัะพัะพะฒ, ัะพะดะตัะถะฐัะธั
โะะฐะนะบัะพัะพััโ, โMicrosoftโ, โ*@%systemroot%*โ, ะฐ ัะฐะบะถะต ยซะฟััััั
ยป ะฐะฒัะพัะพะฒ
$job = Get-ScheduledJob
ืืืขืจืืช ืืงืืฆืื NTFS ืืฉ ืืืจ ืืื ืืื ืืจืื ื ืชืื ืื ืืืืจื ืืืืืื (ADS). ืืฉืืขืืช ืืืืจ ืืื ืฉื ืืชื ืืฉืืื ืงืืืฅ ื-NTFS ืืืกืคืจ ืืจืื ื ืชืื ืื ืืืืื ืฉืจืืจืืชื. ืืืืฆืขืืช ADS, ืืชื ืืืื ืืืกืชืืจ ื ืชืื ืื ืฉืื ืืืื ืืืืืื ืืืืฆืขืืช ืืืืงืืช ืืขืจืืช ืจืืืืืช. ืื ืืืคืฉืจ ืืืืืืจ ืงืื ืืืื ื ื/ืื ืืืกืชืืจ ื ืชืื ืื.
ืืื ืืืฆืื ืืจืื ื ืชืื ืื ืืืืคืืื ื-PowerShell, ื ืฉืชืืฉ ื-get-item cmdlet ืืืืื ืืืจื ืืืืื ื ืฉื Windows ืขื ืืกืื * ืืื ืืืฆืื ืืช ืื ืืืจืืื ืืืคืฉืจืืื, ืืฉื ืื ื ืืฆืืจ ืืช ืืืฉืชื ื $ADS.
$ADS = get-item * -stream * | where stream โne ':$Data'
ืื ืืืื ืฉืืืืฉื ืืืจืจ ืืช ืจืฉืืืช ืืืฉืชืืฉืื ืืืืืืจืื ืืืขืจืืช; ืืฉื ืื ื ืืฆืืจ ืืฉืชื ื $user ืื ืงืฆื ืืืชื ืืืืฆืืข ืชืืื ืืช quser.
$user = quser
ืชืืงืคืื ืืืืืื ืืืฆืข ืฉืื ืืืื ืืืคืขืื ืืืืืืืืช ืืื ืืืฉืื ืืจืืกืช ืจืื ืืืขืจืืช. ืืื ืืืฆืื ืืืืืืงืื ืืคืขืื, ืืชื ืืืื ืืืฉืชืืฉ ื-cmdlet Get-ItemProperty.
ืืืื ื ืืฆืืจ ืฉื ื ืืฉืชื ืื: $runUser - ืืฆืคืืื ืืืชืืื ืืืขื ืืืฉืชืืฉ ื-$runMachine - ืืฆืคืืื ืืืคืขืื ืืืขื ืืืืฉื.
$runUser = Get-ItemProperty
"HKCU:SoftwareMicrosoftWindowsCurrentVersionRun"
$runMachine = Get-ItemProperty
"HKLM:SoftwareMicrosoftWindowsCurrentVersionRun"
ืืื ืฉืื ืืืืืข ื ืืชื ืืงืืฆืื ืฉืื ืื, ืื ื ืืืฆืจืื ืืขืจื ืขื ืืฉืชื ืื ืืืขืจื ืขื ืฉืืืช ืงืืฆืื.
$array = $process, $netTCP, $netUDP, $task, $user, $runUser, $runMachine, $job, $ADS
$arrayName = "Processes", "TCPConnect", "UDPConnect" "TaskScheduled", "Users", "RunUser", "RunMachine",
"ScheduledJob", "Alternative Data Stream"
ืืืืืฆืขืืช ืืืืืช for, ืื ืชืื ืื ืฉืืชืงืืื ืืืืชืื ืืงืืฆืื.
for ($w = 0; $w -lt $array.count; $w++){
$name = $arrayName[$w]
$array[$w] >> $path$name.txt
ืืืืจ ืืืฆืืข ืืกืงืจืืคื, ืืืืืฆืจื 9 ืงืืฆื ืืงืกื ืืืืืืื ืืช ืืืืืข ืืืจืืฉ.
ืืืื, ืื ืฉื ืืืืืช ืกืืืืจ ืืืืืื ืืืฉืชืืฉ ื-PowerShell ืืื ืืืขืฉืืจ ืืช ืืืืืข ืื ืืืฅ ืืื ืืคืชืจืื ืืืืื ืืฉืืืืช ืืขืืืืชื. ืขื ืืื ืืืกืคืช ืกืงืจืืคื ืืืคืขืื, ืืชื ืืืื ืืงืื ืงืฆืช ืืืืข ืืืื ืืืกืืจ dumps, ืชืืื ืืช ืืื'.
ืืงืืจ: www.habr.com