Getting Data In

How to Traverse Nested JSON Structures in Splunk for Process Event Analysis

snowywar
Engager

This is my JSON data. How should I write a query syntax to directly traverse to the last parentProcess, and then provide the complete process chain?
Like This

timeusername
processInfo
processInfo.pidprocessChain
2024-03-07T07:46:27Zrandomuser:staffbash51097/bin/bash -c pmset -g batt%APPLICATIONS%/randomprocess1.app/contents/macos/randomprocess1 /Applications/RandomProcess1.app/Contents/MacOS/RandomProcess1 -runMode autoLaunched%APPLICATIONS%/randomprocess2.app/contents/macos/randomprocess2 /Applications/RandomProcess2.app/Contents/MacOS/RandomProcess2 -runMode autoLaunched/sbin/launchd/sbin/launchdkernel_taskkernel_task

 

I dont know how to search.....please help me ,Thank you!!,

This is my json data

 

{
  "timestamp": "2024-03-07T07:46:27Z",
  "eventName": "ProcessEvent",
  "computer": {
    "name": "randomMacBook-Pro.local",
    "uuid": "9b85f341-3a24-4f70-a371-8863f8a72f1c"
  },
  "processInfo": {
    "imageName": "bash",
    "pid": 51097,
    "systemProcess": false,
    "imagePath": "/bin/bash",
    "commandLine": "-c pmset -g batt",
    "exeHash": {
      "sha1": "87FD78930606102F09D607FC7305996CEFA6E028",
      "sha256": null
    },
    "sid": "",
    "username": "randomuser:staff",
    "sidNameUse": 0,
    "startTime": "2024-03-07T07:46:27Z",
    "currentDirPath": "/",
    "isCompromised": false,
    "lnkPath": "",
    "parentProcess": {
      "imageName": "randomprocess1",
      "pid": 51097,
      "systemProcess": false,
      "imagePath": "%APPLICATIONS%/randomprocess1.app/contents/macos/randomprocess1",
      "commandLine": "/Applications/RandomProcess1.app/Contents/MacOS/RandomProcess1 -runMode autoLaunched",
      "exeHash": {
        "sha1": "E31C5F2840F47A094D58A181586B802FA8531C7E",
        "sha256": null
      },
      "sid": "",
      "username": "randomuser:staff",
      "sidNameUse": 0,
      "startTime": "2024-03-07T07:46:27Z",
      "currentDirPath": "/",
      "isCompromised": false,
      "lnkPath": "",
      "parentProcess": {
        "imageName": "randomprocess2",
        "pid": 603,
        "systemProcess": false,
        "imagePath": "%APPLICATIONS%/randomprocess2.app/contents/macos/randomprocess2",
        "commandLine": "/Applications/RandomProcess2.app/Contents/MacOS/RandomProcess2 -runMode autoLaunched",
        "exeHash": {
          "sha1": "E31C5F2840F47A094D58A181586B802FA8531C7E",
          "sha256": null
        },
        "sid": "",
        "username": "randomuser:staff",
        "sidNameUse": 0,
        "startTime": "2024-03-01T08:02:32Z",
        "currentDirPath": "/",
        "isCompromised": false,
        "lnkPath": "",
        "parentProcess": {
          "imageName": "launchd",
          "pid": 603,
          "systemProcess": false,
          "imagePath": "/sbin/launchd",
          "commandLine": "",
          "exeHash": {
            "sha1": "AA7A8F25AE7BE3BFF0DB33A8FB0D0C49361D1176",
            "sha256": null
          },
          "sid": "",
          "username": "root:wheel",
          "sidNameUse": 0,
          "startTime": "2024-03-01T08:02:32Z",
          "currentDirPath": "/",
          "isCompromised": false,
          "lnkPath": "",
          "parentProcess": {
            "imageName": "launchd",
            "pid": 1,
            "systemProcess": false,
            "imagePath": "/sbin/launchd",
            "commandLine": "",
            "exeHash": {
              "sha1": "AA7A8F25AE7BE3BFF0DB33A8FB0D0C49361D1176",
              "sha256": null
            },
            "sid": "",
            "username": "root:wheel",
            "sidNameUse": 0,
            "startTime": "2024-03-01T07:57:30Z",
            "currentDirPath": "/",
            "isCompromised": false,
            "lnkPath": "",
            "parentProcess": {
              "imageName": "kernel_task",
              "pid": 1,
              "systemProcess": true,
              "imagePath": "kernel_task",
              "commandLine": "",
              "exeHash": {
                "sha1": "24BF148FA83C8A5D908C33954B5CA91A5E4E3659",
                "sha256": null
              },
              "sid": "",
              "username": "root:wheel",
              "sidNameUse": 0,
              "startTime": "2024-02-27T10:17:35Z",
              "currentDirPath": "",
              "isCompromised": false,
              "lnkPath": "",
              "parentProcess": {
                "imageName": "kernel_task",
                "pid": 0,
                "systemProcess": true,
                "imagePath": "kernel_task",
                "commandLine": "",
                "exeHash": {
                  "sha1": "24BF148FA83C8A5D908C33954B5CA91A5E4E3659",
                  "sha256": null
                },
                "sid": "",
                "username": "root:wheel",
                "sidNameUse": 0,
                "startTime": "2024-02-27T10:17:35Z",
                "currentDirPath": "",
                "isCompromised": false,
                "lnkPath": ""
              }
            }
          }
        }
      }
    }
  },
  "eventType": "Process/PosixExec"
}

 

 

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this:

| makeresults
| fields - _time
| eval _raw="{
  \"timestamp\": \"2024-03-07T07:46:27Z\",
  \"eventName\": \"ProcessEvent\",
  \"computer\": {
    \"name\": \"randomMacBook-Pro.local\",
    \"uuid\": \"9b85f341-3a24-4f70-a371-8863f8a72f1c\"
  },
  \"processInfo\": {
    \"imageName\": \"bash\",
    \"pid\": 51097,
    \"systemProcess\": false,
    \"imagePath\": \"/bin/bash\",
    \"commandLine\": \"-c pmset -g batt\",
    \"exeHash\": {
      \"sha1\": \"87FD78930606102F09D607FC7305996CEFA6E028\",
      \"sha256\": null
    },
    \"sid\": \"\",
    \"username\": \"randomuser:staff\",
    \"sidNameUse\": 0,
    \"startTime\": \"2024-03-07T07:46:27Z\",
    \"currentDirPath\": \"/\",
    \"isCompromised\": false,
    \"lnkPath\": \"\",
    \"parentProcess\": {
      \"imageName\": \"randomprocess1\",
      \"pid\": 51097,
      \"systemProcess\": false,
      \"imagePath\": \"%APPLICATIONS%/randomprocess1.app/contents/macos/randomprocess1\",
      \"commandLine\": \"/Applications/RandomProcess1.app/Contents/MacOS/RandomProcess1 -runMode autoLaunched\",
      \"exeHash\": {
        \"sha1\": \"E31C5F2840F47A094D58A181586B802FA8531C7E\",
        \"sha256\": null
      },
      \"sid\": \"\",
      \"username\": \"randomuser:staff\",
      \"sidNameUse\": 0,
      \"startTime\": \"2024-03-07T07:46:27Z\",
      \"currentDirPath\": \"/\",
      \"isCompromised\": false,
      \"lnkPath\": \"\",
      \"parentProcess\": {
        \"imageName\": \"randomprocess2\",
        \"pid\": 603,
        \"systemProcess\": false,
        \"imagePath\": \"%APPLICATIONS%/randomprocess2.app/contents/macos/randomprocess2\",
        \"commandLine\": \"/Applications/RandomProcess2.app/Contents/MacOS/RandomProcess2 -runMode autoLaunched\",
        \"exeHash\": {
          \"sha1\": \"E31C5F2840F47A094D58A181586B802FA8531C7E\",
          \"sha256\": null
        },
        \"sid\": \"\",
        \"username\": \"randomuser:staff\",
        \"sidNameUse\": 0,
        \"startTime\": \"2024-03-01T08:02:32Z\",
        \"currentDirPath\": \"/\",
        \"isCompromised\": false,
        \"lnkPath\": \"\",
        \"parentProcess\": {
          \"imageName\": \"launchd\",
          \"pid\": 603,
          \"systemProcess\": false,
          \"imagePath\": \"/sbin/launchd\",
          \"commandLine\": \"\",
          \"exeHash\": {
            \"sha1\": \"AA7A8F25AE7BE3BFF0DB33A8FB0D0C49361D1176\",
            \"sha256\": null
          },
          \"sid\": \"\",
          \"username\": \"root:wheel\",
          \"sidNameUse\": 0,
          \"startTime\": \"2024-03-01T08:02:32Z\",
          \"currentDirPath\": \"/\",
          \"isCompromised\": false,
          \"lnkPath\": \"\",
          \"parentProcess\": {
            \"imageName\": \"launchd\",
            \"pid\": 1,
            \"systemProcess\": false,
            \"imagePath\": \"/sbin/launchd\",
            \"commandLine\": \"\",
            \"exeHash\": {
              \"sha1\": \"AA7A8F25AE7BE3BFF0DB33A8FB0D0C49361D1176\",
              \"sha256\": null
            },
            \"sid\": \"\",
            \"username\": \"root:wheel\",
            \"sidNameUse\": 0,
            \"startTime\": \"2024-03-01T07:57:30Z\",
            \"currentDirPath\": \"/\",
            \"isCompromised\": false,
            \"lnkPath\": \"\",
            \"parentProcess\": {
              \"imageName\": \"kernel_task\",
              \"pid\": 1,
              \"systemProcess\": true,
              \"imagePath\": \"kernel_task\",
              \"commandLine\": \"\",
              \"exeHash\": {
                \"sha1\": \"24BF148FA83C8A5D908C33954B5CA91A5E4E3659\",
                \"sha256\": null
              },
              \"sid\": \"\",
              \"username\": \"root:wheel\",
              \"sidNameUse\": 0,
              \"startTime\": \"2024-02-27T10:17:35Z\",
              \"currentDirPath\": \"\",
              \"isCompromised\": false,
              \"lnkPath\": \"\",
              \"parentProcess\": {
                \"imageName\": \"kernel_task\",
                \"pid\": 0,
                \"systemProcess\": true,
                \"imagePath\": \"kernel_task\",
                \"commandLine\": \"\",
                \"exeHash\": {
                  \"sha1\": \"24BF148FA83C8A5D908C33954B5CA91A5E4E3659\",
                  \"sha256\": null
                },
                \"sid\": \"\",
                \"username\": \"root:wheel\",
                \"sidNameUse\": 0,
                \"startTime\": \"2024-02-27T10:17:35Z\",
                \"currentDirPath\": \"\",
                \"isCompromised\": false,
                \"lnkPath\": \"\"
              }
            }
          }
        }
      }
    }
  },
  \"eventType\": \"Process/PosixExec\"
}"
| spath
| eval processChain='processInfo.imagePath'." ".'processInfo.commandLine'
| foreach processInfo*.parentProcess.imagePath
    [| eval processChain=mvappend(processChain,'<<FIELD>>'." ".'processInfo<<MATCHSEG1>>.parentProcess.commandLine')]

You end up with a multi-value field which you can use mvjoin to format as you wish

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this:

| makeresults
| fields - _time
| eval _raw="{
  \"timestamp\": \"2024-03-07T07:46:27Z\",
  \"eventName\": \"ProcessEvent\",
  \"computer\": {
    \"name\": \"randomMacBook-Pro.local\",
    \"uuid\": \"9b85f341-3a24-4f70-a371-8863f8a72f1c\"
  },
  \"processInfo\": {
    \"imageName\": \"bash\",
    \"pid\": 51097,
    \"systemProcess\": false,
    \"imagePath\": \"/bin/bash\",
    \"commandLine\": \"-c pmset -g batt\",
    \"exeHash\": {
      \"sha1\": \"87FD78930606102F09D607FC7305996CEFA6E028\",
      \"sha256\": null
    },
    \"sid\": \"\",
    \"username\": \"randomuser:staff\",
    \"sidNameUse\": 0,
    \"startTime\": \"2024-03-07T07:46:27Z\",
    \"currentDirPath\": \"/\",
    \"isCompromised\": false,
    \"lnkPath\": \"\",
    \"parentProcess\": {
      \"imageName\": \"randomprocess1\",
      \"pid\": 51097,
      \"systemProcess\": false,
      \"imagePath\": \"%APPLICATIONS%/randomprocess1.app/contents/macos/randomprocess1\",
      \"commandLine\": \"/Applications/RandomProcess1.app/Contents/MacOS/RandomProcess1 -runMode autoLaunched\",
      \"exeHash\": {
        \"sha1\": \"E31C5F2840F47A094D58A181586B802FA8531C7E\",
        \"sha256\": null
      },
      \"sid\": \"\",
      \"username\": \"randomuser:staff\",
      \"sidNameUse\": 0,
      \"startTime\": \"2024-03-07T07:46:27Z\",
      \"currentDirPath\": \"/\",
      \"isCompromised\": false,
      \"lnkPath\": \"\",
      \"parentProcess\": {
        \"imageName\": \"randomprocess2\",
        \"pid\": 603,
        \"systemProcess\": false,
        \"imagePath\": \"%APPLICATIONS%/randomprocess2.app/contents/macos/randomprocess2\",
        \"commandLine\": \"/Applications/RandomProcess2.app/Contents/MacOS/RandomProcess2 -runMode autoLaunched\",
        \"exeHash\": {
          \"sha1\": \"E31C5F2840F47A094D58A181586B802FA8531C7E\",
          \"sha256\": null
        },
        \"sid\": \"\",
        \"username\": \"randomuser:staff\",
        \"sidNameUse\": 0,
        \"startTime\": \"2024-03-01T08:02:32Z\",
        \"currentDirPath\": \"/\",
        \"isCompromised\": false,
        \"lnkPath\": \"\",
        \"parentProcess\": {
          \"imageName\": \"launchd\",
          \"pid\": 603,
          \"systemProcess\": false,
          \"imagePath\": \"/sbin/launchd\",
          \"commandLine\": \"\",
          \"exeHash\": {
            \"sha1\": \"AA7A8F25AE7BE3BFF0DB33A8FB0D0C49361D1176\",
            \"sha256\": null
          },
          \"sid\": \"\",
          \"username\": \"root:wheel\",
          \"sidNameUse\": 0,
          \"startTime\": \"2024-03-01T08:02:32Z\",
          \"currentDirPath\": \"/\",
          \"isCompromised\": false,
          \"lnkPath\": \"\",
          \"parentProcess\": {
            \"imageName\": \"launchd\",
            \"pid\": 1,
            \"systemProcess\": false,
            \"imagePath\": \"/sbin/launchd\",
            \"commandLine\": \"\",
            \"exeHash\": {
              \"sha1\": \"AA7A8F25AE7BE3BFF0DB33A8FB0D0C49361D1176\",
              \"sha256\": null
            },
            \"sid\": \"\",
            \"username\": \"root:wheel\",
            \"sidNameUse\": 0,
            \"startTime\": \"2024-03-01T07:57:30Z\",
            \"currentDirPath\": \"/\",
            \"isCompromised\": false,
            \"lnkPath\": \"\",
            \"parentProcess\": {
              \"imageName\": \"kernel_task\",
              \"pid\": 1,
              \"systemProcess\": true,
              \"imagePath\": \"kernel_task\",
              \"commandLine\": \"\",
              \"exeHash\": {
                \"sha1\": \"24BF148FA83C8A5D908C33954B5CA91A5E4E3659\",
                \"sha256\": null
              },
              \"sid\": \"\",
              \"username\": \"root:wheel\",
              \"sidNameUse\": 0,
              \"startTime\": \"2024-02-27T10:17:35Z\",
              \"currentDirPath\": \"\",
              \"isCompromised\": false,
              \"lnkPath\": \"\",
              \"parentProcess\": {
                \"imageName\": \"kernel_task\",
                \"pid\": 0,
                \"systemProcess\": true,
                \"imagePath\": \"kernel_task\",
                \"commandLine\": \"\",
                \"exeHash\": {
                  \"sha1\": \"24BF148FA83C8A5D908C33954B5CA91A5E4E3659\",
                  \"sha256\": null
                },
                \"sid\": \"\",
                \"username\": \"root:wheel\",
                \"sidNameUse\": 0,
                \"startTime\": \"2024-02-27T10:17:35Z\",
                \"currentDirPath\": \"\",
                \"isCompromised\": false,
                \"lnkPath\": \"\"
              }
            }
          }
        }
      }
    }
  },
  \"eventType\": \"Process/PosixExec\"
}"
| spath
| eval processChain='processInfo.imagePath'." ".'processInfo.commandLine'
| foreach processInfo*.parentProcess.imagePath
    [| eval processChain=mvappend(processChain,'<<FIELD>>'." ".'processInfo<<MATCHSEG1>>.parentProcess.commandLine')]

You end up with a multi-value field which you can use mvjoin to format as you wish

snowywar
Engager

You are genius!,thank you!!!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...