Detect long running processes with netconn using Splunk subsearches


I have done a couple of posts concerning detecting C2 activity and calculating duration of processes from Carbon Black data in Splunk. In this post I'll show a method of combining the two to detect network connections only from long running processes. This hunt targets script processes which can be a backdoor in themselves but are usually pretty noisy in the enterprise. This also helps close a detection gap in the way that Carbon Black logs are presented. If a single process makes a long running C2 connection the only events seen are the procstart and procend. Within those two events any amount of data can be sent and received.

The term "long running" is arbitrary, after experimenting,  I moved the time down to 5 seconds since it was easily filtered and pretty quiet. This makes sense when you think about it, there should not be many scripts that run for minutes at a time that make external network connections.


Lets start with a profiling search to find long running processes (for each scripting engine)



The event_type is critical, we need both the procstart and procend for stats to aggregate.
The where condition determines the minimum run time.

From there filter out noisy enterprise scripts so that we don't pass too much data to the outer search.

Next we convert the search to a subsearch and export just the process_guid.

Here is the format



Finally add the outer search to complete the search



Note that we now can filter netconn events by remote_ip or domain to clean up our results.
In practice there should be a number of filters necessary to quiet things down.
The search is a bit slow on long time frames but runs fine looking back a couple of days.

This is the example with cscript but wscript, powershell and any other target process will work the same.

- Update -

Alex Teixeira (@ateixei) brought up a pertinent point that subsearches timeout after 60 seconds and have a limit of 10000 results returned. This makes the inner search filtering and profiling very important. I went back and ran just the inner searches up to the point of failure to make sure I could filter them and keep them withing the limits. This brought to light an interesting feature of Carbon Black logs which usually isn't a problem. We actually get three proc logs, one procend and two procstart but one of the procstart logs has limited data (no command line data). It became necessary to filter this event since the normal filter was only filtering the one with the command line data. The added filter is:

NOT ( command_line="" procstart )


Good hunting

Comments

Popular posts from this blog

Misleading extensions Xls.exe Doc.exe Pdf.exe

Netconn from suspicious directories

Powershell DNS C2 Notes