This script enrich data available in workflow by reading an AD user's description and exposes it in workflow. CrowdStrike exposes limited user attributes in Identity Account Event or Identity Protection Detections, even with the help of action 'Get User Context'. If we need any attribute outside of what CS exposes, RTR is probably the best tool at our disposal.
The key point about an RTR script to be shared in workflow is : CS packages all mapped input parameters into a JSON text blob and passes it to RTR action as the first and only arg. As a result, named parameter doesn't really work (or required). All we need is to parse args[0] as a JSON text stream.
$inputJSON = $args[0] | ConvertFrom-Json
$EntitySID = $inputJSON.EntitySID
$domainName = $inputJSON.domainName
Similarly, the script should also do the same to package all data into a JSON blob for subsequent actions in workflow to consume:
$result | ConvertTo-Json -Compress | Write-Output
NOTE: CrowdStrike doesn't like null in output fields. If it's null, replace it with a empty string etc.
The sample:
#
# Getting description attrbitue based on user SID
# This is necessary because none of CrowdStrike builtin action gets description for workflow use
#
# John.Lan@gmail.com
#
<#
As per https://docs.crowdstrike.com/r/en-US/a5kj6wfu/j42eeacd
RTR used in workflow doesn't accept named parameters, it reads input from args[0] as a json text blob
For debugging purpose, we can put below in a text file:
{
"EntitySID": "S-1-5-21-12345678-12345678-612345678-12345678",
"domainName": "foo.bar"
}
Then read the file into a variable:
$inputJSON = get-content 'input.json'
Finally test this RTR in command line as
./get-UserDetails-JSON $inputJSON
#>
$inputJSON = $args[0] | ConvertFrom-Json
$EntitySID = $inputJSON.EntitySID
$domainName = $inputJSON.domainName
import-module ActiveDirectory -ErrorAction Stop -WarningAction SilentlyContinue
$result = [ordered]@{
description = ""
UserGUID = ""
getUserDetailsErrorMsg = "$($EntitySID)||$($domainName)"
}
#
# Validate SID
#
if ([string]::IsNullOrWhiteSpace($EntitySID)) {
$result.getUserDetailsErrorMsg = "$($EntitySID)||$($domainName) || EntitySID is null or blank" # This should never happen as CS shouldn't pass in an invalid SID
$result | ConvertTo-Json -Compress | Write-Output
exit
}
#
# Validate DomainName
#
if ([string]::IsNullOrWhiteSpace($domainName)) {
$result.getUserDetailsErrorMsg = "$($EntitySID)||$($domainName) || domainName is null or blank" # This should never happen as CS shouldn't pass in an invalid SID
$result | ConvertTo-Json -Compress | Write-Output
exit
}
#
# Ensure execution host has AD Module
#
if (-not (Get-Module -ListAvailable -Name ActiveDirectory)) {
$result.getUserDetailsErrorMsg = "ActiveDirectory Module is not available on the RTR execution host"
$result | ConvertTo-Json -Compress | Write-Output
Exit
}
#
# Query AD
#
$user = $null
$filter = "(ObjectSID=$($EntitySID))"
try {
$user = Get-ADUser -server $domainName -LDAPFilter $filter -Properties description,objectGUID -ErrorAction Stop
if ($null -ne $user){
if ($null -ne $user.description) {$result.description = $user.description}
$result.userGUID = $user.ObjectGUID
$result.getUserDetailsErrorMsg = "Success"
} else{
$result.getUserDetailsErrorMsg = "SID not found."
}
}
catch {
$result.getUserDetailsErrorMsg = "Failed to retrieve user from AD, domainName passed from input: $domainName error: $_"
}
$result | ConvertTo-Json -Compress | Write-Output