Carbon Black Response: Process GeoIP

TStillz
4 min readNov 19, 2018

Github: https://github.com/tstillz/cbr-process-geoip

In this blog post, I’m releasing another tool for Carbon Black Response called CBR: Process GeoIP. The purpose of this script is to search specified processes in Carbon Black Response that you’d like to check for unusual network connections using GeoIP. I’ve used this script during an engagement to hunt through remote desktop connections, searching for any anomalies. In another engagement, where the malware had injected itself into a legitimate processes such as explorer.exe, I was able to use this script to quickly dump all network connections made by explorer.exe, review the GeoIP information for each connection, protocol, port, direction of traffic and the process specific information.

ProTip

In order to extract the network connections for each process, you have to make an API for each process. To ensure your only getting processes with network connections, ensure you add the syntax netconn_count:[1 TO *] to each of your queries. You may also consider adding in time ranges or target a specific port to filter down the total number of processes for each query.

Like most of the tools I write, this is a very simple script that reads your Carbon Black Response queries and configuration information from a config.json file. For each query in the config.json, you also need to specify an output filename. For development purposes, we’re using the MaxMind geolite2 city database found here: https://dev.maxmind.com/geoip/geoip2/geolite2/, but feel free to tweak the script to use your preferred GeoIP service or database. Once the database is downloaded and saved to this projects working directory (GeoLite2-City.mmdb), we can start by taking a look at the explorer.exe example below:

Once executed, the script will read the query key, iterate over all matching processes, extract out all the network connections, enrich each connection with GeoIP information and write the data to the file explorer_connections.csv file. When the script is running, you should see the following standard output for each query in your console/IDE:

You can see from the image above that a total of 1,341 processes matched our query, and the script is now iterating over each process to extract its network connections. Once the script finishes, you can open up the the corresponding csv file for your query and review the results. As usual, I tend to create a quick pivot table to view the results, as outlined below:

If you really want to have a lot of fun visualizing the data by country, you can use the Maps feature in both excel and google sheets, per the example below:

While the image above isn’t a great example of using the “GeoIP” feature within the script, we can still use the raw data to find out anomalies now that we have extracted out the network connections. If we take a look at the Powershell query inside of the pivot table, we can see a call out to raw[.]githubusercontent[.]com with its Powershell command line argument:

ProTip

If possible, you should consider adding in some threat feed lookups to the post-processed network connections to add additional context to the results.

While this script does a decent job at analyzing targeted processes and extracting out their network connections, for larger environments I would recommend leveraging the Carbon Black event forwarder to send the raw endpoint events to a generic JOSN processing pipeline (covered in the next blog post). The event forwarder documentation can be found here: https://developer.carbonblack.com/reference/enterprise-response/event-forwarder/.

A list of the raw endpoint events can be found at the following link below. The event ID for capturing only the raw endpoint network connections is ingress.event.netconn:

https://developer.carbonblack.com/reference/enterprise-response/event-forwarder/event-schema/.

Leveraging the Carbon Black event forwarder, a storage medium (s3), queuing mechanism (SQS) and workers (Lambda), you can scale out your event processing to broaden your network connection scope vs targeting specific processes to analyze with this script. Again, if you’re interested in how we can leverage services like AWS to scale out event processing, stay tuned for my next blog post.

I hope this script comes in use for those using Carbon Black Response. Happy Hunting!

Acknowledgements

Special thanks to Mike Scutt (@OMGAPT), Jason Garman and the CB team for all the help.

--

--

TStillz

Posting on various topics including incident response, malware analysis, development and finance/investing automation.