Using stats, eventstats & streamstats for Threat Hunting…Stat! | Splunk (2024)

Splunk is committed to using inclusive and unbiased language. This blog post might contain terminology that we no longer use. For more information on our updated terminology and our stance on biased language, please visit our blog post. We appreciate your understanding as we work towards making our community more inclusive for everyone.

If you have spent any time searching in Splunk, you have likely done at least one search using the stats command. I won’t belabor the point: stats is a crucial capability in the context of threat hunting — it would be a crime to not talk about it in this series.

Using stats, eventstats & streamstats for Threat Hunting…Stat! | Splunk (1)

When focusing on data sets of interest, it's very easy to use the stats command to perform calculations on any of the returned field values to derive additional information. When I say stats, I am referring to three commands:

  • stats
  • eventstats
  • streamstats

Like many Splunk commands, all three are transformational commands, meaning they take a result set and perform functions on the data.

Let’s dive into stats.

(Part of our Threat Hunting with Splunk series, this article was originally written by John Stoner. We’ve updated it recently to maximize your value.)

The stats command for threat hunting

The stats command is a fundamental Splunk command. It will perform any number of statistical functions on a field, which could be as simple as a count or average, or something more advanced like a percentile or standard deviation.

Using the keyword by within the stats command can group the statistical calculation based on the field or fields listed.

Here is a good basic example of how to apply the stats command during hunting. I might hypothesize that the source destination pairs with the largest amount of connections starting in a specific netblock are of interest to dig deeper into.

sourcetype=fgt_traffic src=192.168.225.* NOT (dest=192.168.* OR dest=10.* OR dest=8.8.4.4 OR dest=8.8.8.8 OR dest=224.*)| stats count by src dest| where count > 1| sort – count

Using stats, eventstats & streamstats for Threat Hunting…Stat! | Splunk (2)

The search is looking at the firewall data originating from the 192.168.225.0/24 netblock and going to destinations that are not internal or DNS. The stats command is generating a count, grouped by source and destination address. Once the count is generated, that output can be manipulated to get rid of single events and then sorted from largest to smallest.

Another use for stats is to sum values together. A hypothesis might be to look at firewall traffic to understand who my top talkers to external hosts are, not from a connection perspective, but from a byte perspective. Using the stats command, multiple fields can be calculated, renamed and grouped.

sourcetype=fgt_traffic src=192.168.225.* NOT (dest=192.168.* OR dest=10.* OR dest=8.8.4.4 OR dest=8.8.8.8 OR dest=224.*) | stats sum(bytes_in) as total_bytes_in sum(bytes_out) as total_bytes_out by src dest | table src dest total_bytes_in total_bytes_out | sort – total_bytes_out

Using stats, eventstats & streamstats for Threat Hunting…Stat! | Splunk (3)

In this example, the same data sets are used, but this time the stats command is used to sum the bytes_in and bytes_out fields. By changing the sort, I can easily pivot to look at things like:

  • The top inbound byte volumes
  • The low talkers based on lowest byte count (which might be its own hypothesis)

As a side note, if I saw the result set above I might ask why I am seeing many hosts from the same subnet all communicating to the same destination IP, with identical byte counts, both in and out. The point is that there are numerous ways to leverage stats.

The eventstats command

With these fundamentals in place, let’s apply these concepts to eventstats. I like to think of eventstats as a method to calculate “grand totals” within a result set that can then be used to manipulate these totals to introspect the data set further.

Another hypothesis I might want to pursue is identifying and investigating the systems with the largest byte counts leaving the network. To effectively hunt, I want to know two key things:

  • All of the external hosts that my system is connecting to
  • How much data is going to each host

Using the same basic search criteria as the earlier search, we slightly augment it to make sure any bytes_out are not zero to keep the result set cleaner. Eventstats is calculating the sum of the bytes_out and renaming it total_bytes_out grouped by source IP address. That output can then be treated as a field value that can be outputted with additional Splunk commands.

sourcetype=fgt_traffic src=192.168.225.* NOT (dest=192.168.* OR dest=10.* OR dest=8.8.4.4 OR dest=8.8.8.8 OR dest=224.*) bytes_out>0| eventstats sum(bytes_out) AS total_bytes_out by src| table src dest bytes_out total_bytes_out| sort src – bytes_out

Using stats, eventstats & streamstats for Threat Hunting…Stat! | Splunk (4)

The bands highlighted in red show the source IP address with the bytes_out summed to equal the total_bytes_out.

Another hypothesis that I could pursue using eventstats would be to look for systems that have more than 60% of their traffic going to a single destination. If a system is talking nearly exclusively to a single external host, that might be cause for concern or at least an opportunity to investigate further.

Going back to the earlier example that looked for large volumes of bytes_out by source and destination IP addresses, we could evolve this and use eventstats to look at the bytes_out by source as a percentage of the total byte volume going to a specific destination.

sourcetype=fgt_traffic src=192.168.225.* NOT (dest=192.168.* OR dest=10.* OR dest=8.8.4.4 OR dest=8.8.8.8 OR dest=224.*)| eventstats sum(bytes_out) AS total_bytes_out by src| eval percent_bytes_out = bytes_out/total_bytes_out * 100| table src dest bytes_in bytes_out total_bytes_out percent_bytes_out| where percent_bytes_out > 60| sort - percent_bytes_out dest

Using stats, eventstats & streamstats for Threat Hunting…Stat! | Splunk (5)

Building on the previous search criteria, I calculate the eventstats by summing the bytes_out grouped by source IP address to get that “grand total.”

Now I can start transforming that data using stats like I did earlier and grouping by source and destination IP. If I stopped there, I would have the sum of the bytes_in, bytes_out, the total_bytes_out and the source and destination IP.

That’s great — but I need to filter down on the outliers that I'm hypothesizing about.

Using the eval command, the bytes_out and total_bytes_out can be used to calculate a percentage of the overall traffic. At that point, I'm formatting the data using the table command and then filtering down on the percentages that are greater than 60 and sorting the output.

I now have a set of source IP addresses that I can continue to interrogate with the knowledge that a high percentage of the data is going to a single destination. In fact, when I look at my output, I find an interesting outcome which is that my top 14 source addresses are all communicating to the same external IP address.

That alone might be something interesting to dig further on, or it might be a destination that should be whitelisted using a lookup. This approach though allows me to further refine my search and reinforce or disprove my hypothesis.

The streamstats command

On to streamstats. Streamstats builds upon the basics of the stats command but it provides a way for statistics to be generated as each event is seen. This can be very useful for things like running totals or looking for averages as data is coming into the result set.

If I were to take the results from our earlier hunt, I could further hypothesize that communications outbound from my host occur in bursts. I could then use streamstats to visualize and confirm that hypothesis.

sourcetype=fgt_traffic src=192.168.225.* NOT (dest=192.168.* OR dest=10.* OR dest=8.8.4.4 OR dest=8.8.8.8 OR dest=224.*) bytes_out>0| sort date| streamstats sum(bytes_out) as total_bytes_out by src| table date bytes_out total_bytes_out

Using stats, eventstats & streamstats for Threat Hunting…Stat! | Splunk (6)

Building off the previous example, the source IP address 192.168.225.80 generated 77% of its traffic to a specific destination. We could investigate further and look at the data volume over time originating from that address.

The search I start with is the same basic search as the other examples with one exception — the source is no longer a range but a specific address.

Because I would like the information to aggregate on a daily basis, I'm sorting by date. Streamstats is then used to get the sum of the bytes_out, renamed as total_bytes_out and grouped by source IP address. Finally, we table the output, specifically date, bytes_out and the total_bytes_out.

The output can be viewed in a tabular format or visualized, preferably as a line chart or area chart. As you can see from the output, the daily bytes_out added to the previous day’s total_bytes_out will equal today’s total_bytes_out.

Other ways to use stats, eventstats & streamstats

Stats, eventstats and streamstats are all very powerful tools that can refine the result set to identify outliers within the environment. While this blog focused on network traffic and used sums and counts, there is no reason not to use it for host-based analysis as well as leveraging statistics like standard deviations, medians and percentiles.

Happy hunting!

Using stats, eventstats & streamstats for Threat Hunting…Stat! | Splunk (7)

Tamara Chacon

Tamara is a member of Splunk's SURGe team, where she helps with the behind the scenes work for the team. Before joining Splunk, she worked as a network engineer.

Using stats, eventstats & streamstats for Threat Hunting…Stat! | Splunk (2024)

FAQs

What is Streamstats Eventstats stats? ›

Eventstats performs calculations on events within a single search, while streamstats calculate statistics over the entire search result set in a streaming fashion.

How do streamstats work in Splunk? ›

The SPL2 streamstats command adds a cumulative statistical value to each search result as each result is processed. For example, you can calculate the running total for a particular field, or compare a value in a search result with a the cumulative value, such as a running average.

What is the difference between stats and tstats in Splunk? ›

tstats is faster than stats since tstats only looks at the indexed metadata (the . tsidx files in the buckets on the indexers) whereas stats is working off the data (in this case the raw events) before that command. Since tstats can only look at the indexed metadata it can only search fields that are in the metadata.

What is the eventstats command in Splunk? ›

The eventstats command looks for events that contain the field that you want to use to generate the aggregation. The command creates a new field in every event and places the aggregation in that field. The aggregation is added to every event, even events that were not used to generate the aggregation.

How accurate are StreamStats? ›

Generally, StreamStats is able to delineate basins with reasonable accuracy down to around 0.05 square miles (32 acres) in terrain with moderate relief.

What method does StreamStats use? ›

StreamStats incorporates (1) a map-based user interface for the site selection; (2) a relational data base that contains information for data-collection stations and regression equations used to estimate flow statistics for ungaged sites; (3) a GIS program that allows locating sites of interest in the user interface, ...

How to use eval in stats Splunk? ›

This example uses eval expressions to specify the different field values for the stats command to count.
  1. The first clause uses the count() function to count the Web access events that contain the method field value GET . ...
  2. The second clause does the same for POST events.

What are streaming commands in Splunk? ›

A streaming command applies a transformation to each event returned by a search. For example, the rex command is streaming because it extracts and adds fields to events at search time.

How to pull data from Splunk? ›

There are three common ways to extract data from Splunk Infrastructure Monitoring: by using SignalFlow, Splunk's streaming analytics API; by using the /timeserieswindow endpoint in the Splunk API; or from the Splunk UI.

What is the difference between events and statistics in Splunk? ›

The difference is that with the eventstats command aggregation results are added inline to each event and added only if the aggregation is pertinent to that event. let me know if this helps ! stats - Calculates aggregate statistics over the results set, such as average, count, and sum.

What is the use of stats in Splunk? ›

The stats command is a fundamental Splunk command. It will perform any number of statistical functions on a field, which could be as simple as a count or average, or something more advanced like a percentile or standard deviation.

What is the difference between events and logs in Splunk? ›

An event is a thing that happened anywhere at any time. It might be in Splunk and it might not. A log is the digital exhaust of that event; it is the plain-text vestige that indicates than an event happened. A result is each thing that is returned from a Splunk search.

What is the limit of eventstats? ›

By default, eventstats can aggregate up to 50,000 events at a time. You can change this limit with the MaxNoOfa*ggregatedEvents parameter.

What is the 50000 limit in Splunk stats? ›

The limit you're talking about is the one where, if your base search is just returning raw event rows, Splunk only keeps 50,000 events in the search result. This means that later when you run your postprocess there can be misleading results.

How to check events per second in Splunk? ›

Use tstats and specify the variables:
  1. index=main.
  2. earliest=-30d.
  3. groupby (_time, sourcetype)
  4. span=1s. | tstats count as COUNT where index=main earliest=-30d by _time,sourcetype span=1s | timechart span=1h max(COUNT) as eps by sourcetype.
Mar 17, 2015

Search Command> stats, eventstats and ...Splunkhttps://www.splunk.com ›

Getting started with stats, eventstats and streamstats. When I first joined Splunk, like many newbies I needed direction on where to start. Someone gave me some...
In most of the complex queries written in splunk stats, eventstats and streamstats commands are widely used lets look about them in this blog.
Splunk statistical commands allow you to quickly analyze and summarize data. Learn how to use Eventstats and Streamstats for advanced statistical analysis in Sp...

What are StreamStats? ›

StreamStats is a Web application that provides access to an assortment of Geographic Information Systems (GIS) analytical tools that are useful for water-resources planning and management, and for engineering and design purposes.

How do StreamStats estimate flood frequencies? ›

After StreamStats measures the drainage-basin characteristics for a selected site, the values are sent to the National Streamflow Statistics (NSS) Services, which contain all of the USGS-developed equations for estimating flood-frequency statistics in the Nation.

How do you cite StreamStats? ›

If you want to cite the program in general or data collected from a StreamStats report, use: U.S. Geological Survey, 2019, The StreamStats program, online at https://streamstats.usgs.gov/ss/, accessed on (give date of access).

How to delineate a watershed in StreamStats? ›

Basin Delineated
  1. Step 1: Zoom in to level 15 or greater to enable the delineation tool.
  2. Step 2: Click the 'Delineate' button to activate the delineation tool.
  3. Step 3: Use your mouse or finger to click or tap a blue stream cell on the map.
  4. Step 4: Wait for delineation process to complete...

References

Top Articles
Kimchi Fried Rice Recipe
6 Gluten-Free Asian Recipes You MUST TRY - Tiffy Cooks
Tears Of The Fallen Moon Bdo
Craigslist Lititz
Melissababyxo Cam
Stolen Touches Neva Altaj Read Online Free
Fresenius Medical Care to launch 5008 dialysis machine: improved patients` quality of life and efficient use of resources
Joann Ally Employee Portal
FREE Houses! All You Have to Do Is Move Them. - CIRCA Old Houses
Bookmark Cshive
Iapd Lookup
Haktuts Coin Master Link
J. Foster Phillips Funeral Home Obituaries
Blind Guardian - The God Machine Review • metal.de
Hose Woe Crossword Clue
Asoiaf Spacebattles
How 'The Jordan Rules' inspired template for Raiders' 'Mahomes Rules'
Worlds Hardest Game Tyrone
The Perfect Couple Episode 5 Cast & Characters - Eve Hewson, Nicole Kidman & More (Photos)
Bank Of America.aomc
Stafford Rotoworld
Mighty B Wcostream
Covenant Funeral Service Stafford Obituaries
Hannaford Weekly Flyer Manchester Nh
Dr. Nicole Arcy Dvm Married To Husband
Advance Auto Parts Near Me Open Now
Www.statefarm
Lewelling Garden Supply
Lost Ark Thar Rapport Unlock
Apple Watch 9 vs. 10 im Vergleich: Unterschiede & Neuerungen
Ny Trapping Forum
Here's everything Apple just announced: iPhone 16, iPhone 16 Pro, Apple Watch Series 10, AirPods 4 and more
Cbs Scores Mlb
Bridger Elementary Logan
Www.publicsurplus.com Motor Pool
Champaign County Mugshots 2023
99 Cents Food Handler
Kutty Com Movies
Burkes Outlet Credit Card Sign In
Tamusso
Everything 2023's 'The Little Mermaid' Changes From the Original Disney Classic
Cranes for sale - used and new - TrucksNL
Metrocast Channel Lineup
University of Nevada, Las Vegas
Unity Webgl Car Tag
Travelvids October 2022
Leslie Pool Supply Simi Valley
Skagit.craigslist
Espn Masters Leaderboard
Myrtle Beach Pelicans Stadium Seating Chart
Fantasy Football News, Stats and Analysis
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 5516

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.