liveBook · Manning

Variance

As explained in Cyber Threat Hunting

Variance is the average squared deviation of values in a data set from its mean and measures the data's spread.

Variance measures how widely values in a data set spread around their mean. Calculate it by finding each value’s deviation from the mean, squaring those deviations, and averaging the results. Squaring prevents positive and negative deviations from canceling each other and gives larger deviations more influence. For a population, the calculation uses every available value; n is the data-set size, xi an individual value, and μ the mean. section 6.1.1

Standard deviation is the square root of variance. Both describe variability, but standard deviation is used directly to assess whether repeated network connections occur at consistent intervals: low values indicate a tighter, more regular pattern. Variance can be calculated alongside it as an additional spread measure. section 6.1.1 section 6.1.5

To use variance while hunting for regular beaconing behavior:

  • Collect timestamped network-connection events with source IP, destination IP, and destination port. section 6.1.1
  • Group events that share the same source IP, destination IP, and destination port, then calculate time differences between consecutive connections. section 6.1.1 section 6.1.5
  • Calculate variance, standard deviation, and connection count for each group; retain one row per group after removing duplicates. section 6.1.5
  • Prioritize sufficiently repeated groups with low standard deviation, then investigate the destination, traffic details, and responsible process. section 6.1.5
Listing 6.14 Calculating standard deviation, variance, and count
df['std1'] = df.groupby(['src_ip', 'dest_ip', \
    'dest_port'])['time_diff_sec'].transform('std')       #1
 
df['var1'] = df.groupby(['src_ip', 'dest_ip', \
    'dest_port'])['time_diff_sec'].transform('var')       #2
 
df['count1'] = df.groupby(['src_ip', 'dest_ip', \
    'dest_port'])['time_diff_sec'].transform('count')     #3

This DataFrame pattern computes variance, standard deviation, and count from connection intervals for each source-IP, destination-IP, and destination-port group. section 6.1.5

Checking repeated connections

For connections between 10.0.0.6 and 208.80.154.224, the interval data contains 4,077 connections. Its reported standard deviation is 78.269678 and variance is 6126.142499. A line graph of intervals over time and a histogram of their distribution help inspect the pattern behind those summary values. section 6.2 section 6.3

How Cyber Threat Hunting covers it

How deep it goes
Defines variance from squared deviations and demonstrates grouped calculation in a DataFrame, while using standard deviation for consistency decisions.
Examples
Works through grouped connection intervals and exercises connections between 10.0.0.6 and 208.80.154.224 using graphs and a histogram.
What it assumes
Introduces the mean, deviations, and population notation needed for the variance calculation from zero.
What you can do after
Apply it via Pandas to calculate grouped variance for connection intervals during a beaconing investigation.
How it connects
Connects variance with mean, deviation, standard deviation, beaconing, network connections, timestamps, and histograms.

Also explained in

Compare how 19 books explain variance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Cyber Threat Hunting. The section links point to the parts of the book it draws on.