Get Application, System and Security Logs from an Endpoint Using PowerShell Script in Falcon RTR #406
Unanswered
usmanzargar
asked this question in
Q&A
Replies: 1 comment 3 replies
-
I'm working on adding two new
function Convert-Hashtable([Parameter(Mandatory=$true)][psobject]$Object){
[hashtable]$i=@{}
$Object.PSObject.Properties|?{![string]::IsNullOrEmpty($_.Value)}|%{
$i[($_.Name -replace '\s','_' -replace '\W',$null)]=$_.Value
}
$i
}
function Convert-Json([Parameter(Mandatory=$true)][string]$String){
if($PSVersionTable.PSVersion.ToString() -lt 3.0){
$Serializer.DeserializeObject($String)
}else{
$Object=$String|ConvertFrom-Json
if($Object){Convert-Hashtable $Object}
}
}
function Format-Result([Parameter(Mandatory=$true)][hashtable[]]$Hashtable,[string]$String){
[void]([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$env:ComputerName)|%{
try{
$_.OpenSubKey('SYSTEM\\CurrentControlSet\\Services\\CSAgent\\Sim')|%{
foreach($i in @('AG','CU')){
nv -Name $i -Value ([System.BitConverter]::ToString($_.GetValue($i))).Replace('-',$null).ToLower()
}
}
}catch{}
})
[hashtable]@{script=$String;cid=$CU;aid=$AG;result=$Hashtable}
}
function Write-Json([Parameter(Mandatory=$true)][hashtable]$Hashtable){
if($PSVersionTable.PSVersion.ToString() -lt 3.0){
$Serializer.Serialize($Hashtable)
}else{
ConvertTo-Json $Hashtable -Depth 8 -Compress
}
}
function Get-EventLog{
param(
[Parameter(ParameterSetName='LogName',Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$LogName,
[Parameter(ParameterSetName='ProviderName',Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$ProviderName,
[Parameter(ParameterSetName='LogName')]
[Parameter(ParameterSetName='ProviderName')]
[int32]$MaxEvents
)
[void](Get-WinEvent @PSBoundParameters -EA 0 -OV Log)
if($Log){$Log}else{throw ($Error[0]).Exception.Message}
}
try{
if($PSVersionTable.PSVersion.ToString() -lt 3.0){
Add-Type -AssemblyName System.Web.Extensions
$Serializer=New-Object System.Web.Script.Serialization.JavascriptSerializer
}
if($args[0]){$Param=Convert-Json $args[0]}
$Id=if($Param.Id){$Param.Id;[void]$Param.Remove('Id')}
$Param['MaxEvents']=if($Id){1000}else{100}
$Result=Get-EventLog @Param
if($Result){
if($Id){$Result=$Result|?{$_.Id -eq $Id}|select -First 100}
[hashtable[]]$Output=$Result|%{@{TimeCreated=$_.TimeCreated.ToFileTimeUtc();Id=$_.Id;
ProviderName=$_.ProviderName;LogName=$_.LogName;LevelDisplayName=$_.LevelDisplayName;
TaskDisplayName=$_.TaskDisplayName;Message=$_.Message;ProcessId=$_.ProcessId;ThreadId=$_.ThreadId}}
if($Output){
Write-Json (Format-Result $Output EventLog)
}else{
throw ("No result(s) for Id {0} in the 1,000 most recent log entries." -f $Id)
}
}
}catch{
throw $_
} Input schema:
Output schema:
function Convert-Hashtable([Parameter(Mandatory=$true)][psobject]$Object){
[hashtable]$i=@{}
$Object.PSObject.Properties|?{![string]::IsNullOrEmpty($_.Value)}|%{
$i[($_.Name -replace '\s','_' -replace '\W',$null)]=$_.Value
}
$i
}
function Convert-Json([Parameter(Mandatory=$true)][string]$String){
if($PSVersionTable.PSVersion.ToString() -lt 3.0){
$Serializer.DeserializeObject($String)
}else{
$Object=$String|ConvertFrom-Json
if($Object){Convert-Hashtable $Object}
}
}
function Format-Result([Parameter(Mandatory=$true)][hashtable[]]$Hashtable,[string]$String){
[void]([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$env:ComputerName)|%{
try{
$_.OpenSubKey('SYSTEM\\CurrentControlSet\\Services\\CSAgent\\Sim')|%{
foreach($i in @('AG','CU')){
nv -Name $i -Value ([System.BitConverter]::ToString($_.GetValue($i))).Replace('-',$null).ToLower()
}
}
}catch{}
})
[hashtable]@{script=$String;cid=$CU;aid=$AG;result=$Hashtable}
}
function Write-Json([Parameter(Mandatory=$true)][hashtable]$Hashtable){
if($PSVersionTable.PSVersion.ToString() -lt 3.0){
$Serializer.Serialize($Hashtable)
}else{
ConvertTo-Json $Hashtable -Depth 8 -Compress
}
}
try{
if($PSVersionTable.PSVersion.ToString() -lt 3.0){
Add-Type -AssemblyName System.Web.Extensions
$Serializer=New-Object System.Web.Script.Serialization.JavascriptSerializer
}
if($args[0]){$Param=Convert-Json $args[0]}
[hashtable[]]$Output=Get-WinEvent -ListLog * -EA 0|?{$_.RecordCount -gt 0}|%{@{LogName=$_.LogName;
RecordCount=$_.RecordCount;ProviderNames=$_.ProviderNames}}
if($Output -and $Param.Match){$Output=$Output|?{$_.LogName -match $Param.Match}}
if($Output){
Write-Json (Format-Result $Output EventSource)
}elseif($Param.Match){
throw ('No LogNames matching "{0}".' -f $Param.Match)
}else{
throw "No result(s)."
}
}catch{
throw $_
} Input schema:
Output schema:
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey Guys,
I am looking to find something in PowerShell that would help us in getting and downloading the Application, System and Security Logs from an endpoint using Falcon RTR (Edit and Run Scripts section). I know Analysts usually uses commands in the "Run Commands" section, which upload the logs to the CrowdStrike cloud and then we can download it using a get command (Windows). I am looking to create a script that could be utilized to run in the RTR (Edit and Run Scripts section) and running tat that would fetch the types of logs from endpoints (both Windows & Linux) and also download it in our systems for analysis.
Is this possible in Falcon RTR? If yes, is there any documentation available online that can assist me with it? Assistance on this would be highly appreciated.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions