Cortex XSOAR Transform Language (DT)
Cortex XSOAR Transform Language (commonly referred to as DT) is used for various Context related functions in Cortex XSOAR. DT is a query language for JSON objects, similar to JSONQuery.
#
Context ExampleThe following sample Context data will be used to show the various ways DT can access, aggregate, and mutate data.
#
Nested ValuesDT can access keys from nested dictionaries as well as dictionaries.
Using the above Context data sample, you can access the following key values:
- The "Continent" key value, located in the "Geo" dictionary, which is located in the "MaxMind" dictionary.
- The "Hostname" key value, located in the "IP" dictionary.
- The "FirstSeen" key value, located in the "RecordedFuture" dictionary, which is located in the "IP" dictionary.
Access the key values using the following DT statements:
Example | Result |
---|---|
${MaxMind.Geo.Continent} | North America |
${IP.Hostname} | google-public-dns-a.google.com |
${IP.RecordedFuture.FirstSeen} | 2010-04-27T12:46:51.000Z |
#
Dealing with ArraysAccess array values as you access any other dictionary (or JSON) key in dot notation, with an index.
Note:
Indices start with 0, not 1.
Using the above Context data sample:
Under "URLScan", there is an array called "Certificates". If you want to access the "SubjectName" value of the first entry, use the following DT statement.
Example | Result |
---|---|
${URLScan.Certificates.SubjectName} | ["www.google.com", "*.google.com", "www.google.de", "*.g.doubleclick.net", "*.apis.google.com"] |
${URLScan.Certificates.[0].SubjectName} | www.google.com |
${URLScan.Certificates.[0:2].SubjectName} | ["www.google.com", "*.google.com", "www.google.de"] |
If you want to retrieve a range of results, you can use [0:9]
where "0" is the beginning of the array and "9" is the 9th position in the array.
#
SelectorsDT also allows for conditions within the statement itself and uses Javascript to select the Context items. This is a way to bind results together by embedding a selection into the DT string.
You will notice that val
is used quite often in the DT string. This is a Javascript method that exposes the value at the given Context path.
The following are a few examples of selector methods:
Example | Result | Description |
---|---|---|
${DBotScore.Vendor(val == 'urlscan.io')} | urlscan.io | will return only Vendors that exactly match the urlscan.io description. |
${URLScan.Certificates.SubjectName( val.indexOf('www') == 0)} | [<span>www.google</span>.com, <span>www.google</span>.de] | will return any SubjectName that starts with "www" |
${URLScan.Certificates.SubjectName( val.indexOf('doubleclick') >= 0)} | *.g.doubleclick.net | will return any SubjectName that contains doubleclick. |
${URLScan.Country( val.toUpperCase().indexOf('IE') >= 0)} | IE | will return any Country that contains IE or ie or any mixed case. |
${URLScan.Certificates(val.SubjectName.indexOf('de') == val.length-2).ValidTo} | 2019-03-13 08:16:00 | will return all ValidTo for certificates that have SubjectName ending with de. Please notice that we tested a relative path to “SubjectName” (“de”) and returned a different path (“ValidTo”). |
${URLScan.Certificates(val.ValidFrom == val1---URLScan.Certificates.[0].ValidFrom).SubjectName} | ["<span>www.google</span>.com", "<span>www.google</span>.de", "*.apis.google.com"] | will return all SubjectNames for Certificates that have the same ValidTo time as the first Certificate in the array. Note that the bind value (val1) does not start with ‘.’ and will DT the Context from the top Context. |
Selectors help avoiding duplicate entries and can be used to add context to existing entries.
An example of how this may be used in your code is the following:
The code snippet 'URL(val.Data && val.Data == obj.Data)'
will look for entries in the Context whose name found under "Data" are the same. If it finds a match, it will update the existing Context, If it does not, it will create a new entry in the Context because it views the entry as "unique" to the existing values.
#
MutatorsSince DT is Javascript based, it can also mutate a result if your integration needs a different result format. A classic use case for this is joining a server address obtained from another integration to an endpoint found by your integration to create a URL which may be used by your integration at a later time.
Here are a few examples:
Example | Result | Description |
---|---|---|
${URLScan.Certificates(val.SubjectName.indexOf("doubleclick") > -1).ValidFrom=foo(val);function foo(aa) { return aa + "Z"; }} | 2018-12-19 08:17:00Z | Returns the timestamp where the SubjectName contains the word "doubleclick". Then it appends "Z" to the value |
${MaxMind.Organization=val.toLowerCase()} | google llc | returns all the organizations but in lower case. |
${DBotScore.Vendor(val.indexOf('Recorded')>=0)=val.toLowerCase()} | "recorded future" | returns all the Vendors containing “Recorded” but in lower case. |
${DBotScore.type=val.ip +': ' + val.Vendor} | ["ip: ipinfo", "ip: Recorded Future", "ip: VirusTotal"] | returns the concatenated ip and vendor for all DBotScores. |