liveBook · Manning

Anomaly detection

As explained in Data-Driven Cybersecurity

An anomaly is an observation or activity that deviates significantly from an expected pattern or reference value.

Anomaly detection identifies behavior that departs from an expected norm. In cybersecurity, an unusual login, file transfer, or network connection can signal unauthorized access, data exfiltration, or malware activity. A flag is a reason to investigate, not proof of a breach: legitimate activity can also look unusual. section 10.3.1 section 8.6

Detection starts with a picture of normal activity for the organization, such as typical traffic, logins, and file transfers. Continuous monitoring can then surface deviations, including threats that do not match known attack signatures. Analysts need context to determine severity and cause before choosing a response. section 10.3.1 section 10.3 section 8.6

Two alerts, two investigations

A sudden rise in transfers between systems that usually exchange moderate amounts of data led investigators at a financial services company to an insider threat. At an e-commerce company, logins from several geographic regions in a short period prompted an investigation that uncovered an emerging botnet-driven brute force attack. In both cases, the deviation directed attention; investigation established what it meant. section 10.3.1

To turn alerts into useful security decisions:

  • Collect network, system, application, and user-activity data; check data quality before relying on AI-generated findings. section 8.1.2 section 1.6
  • Compare flagged events with normal behavior, then assess their type, severity, organizational effect, and root cause. section 10.3.1 section 8.6
  • Track false positives, missed threats, and response time; refine thresholds and alert priorities rather than treating every flag equally. section 10.3.1 section 3.4.2 section 10.4.3

Different methods expose different kinds of departures. DBSCAN groups similar network-communication records and labels outliers for investigation. Isolation forest separates unusual data points; an autoencoder flags records it cannot reconstruct well from learned normal patterns. These methods identify candidates, not confirmed incidents. section 12.2.1 section 12.3.2

Listing 12.1 DBSCAN for threat detection
import pandas as pd  #1
from sklearn.cluster import DBSCAN  #2
import matplotlib.pyplot as plt  #3

# Create a sample dataset: Network communication patterns
data = {  #4
    'Device': ['Laptop_A', 'Phone_B', 'Printer_C', 'Laptop_B', 'Server_D'],
    'External_Comm': [10, 15, 3, 8, 120],
    #External communications (number of external IPs contacted)
    'Internal_Comm': [100, 95, 200, 90, 80]
    #Internal communications (number of internal IPs contacted)
}

df = pd.DataFrame(data)  #5

# Extract features for clustering
X = df[['External_Comm', 'Internal_Comm']]  #6

# Apply DBSCAN
dbscan = DBSCAN(eps=15, min_samples=2)  #7
df['Cluster'] = dbscan.fit_predict(X)  #8

#Plot the clusters
plt.figure(figsize=(8, 6))  #9
plt.scatter(df['External_Comm'], df['Internal_Comm'],
            c=df['Cluster'], cmap='Greys', 
label='Clusters')  #10
plt.title(('DBSCAN Clustering of Network '
           'Communications'))  #11
plt.xlabel('External Communications')  #12
plt.ylabel('Internal Communications')  #13
plt.grid(True)  #14
plt.show()  #15

#Display the resulting clusters
print(df)  #16

The runnable DBSCAN listing clusters devices by external and internal communications. Its output labels outliers −1, making unusual devices visible for follow-up. section 12.2.1

Report the operational change

After an access-management tool flagged unusual behavior, an investigation found a configuration error that permitted access to sensitive data. Corrective work included adjusting access policies, fine-tuning detection thresholds, and automating escalation. The associated report tracked access-control violations falling from 15 to 0 and average response time falling from 3 hours to 1 hour. The useful conclusion was not merely that an alert fired, but that controls and response improved. section 3.4.2

How Data-Driven Cybersecurity covers it

How deep it goes
Defines behavioral baselines and works through detection examples and Python methods, while treating flags as candidates requiring investigation rather than proof.
Examples
Illustrates suspicious transfers and geographic login patterns, then uses synthetic network-device data for a DBSCAN exercise.
What it assumes
Assumes a cybersecurity monitoring context; supplies synthetic exercise data but calls for Python, Jupyter Notebook, and supporting libraries to follow along.
What you can do after
Apply it via Python examples to flag unusual activity, then investigate alerts and assess detection and response metrics.
How it connects
Connects anomaly detection to continuous monitoring, predictive analytics, incident response, clustering, and false positives.

Also explained in

Compare how 7 books explain anomaly detection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Driven Cybersecurity. The section links point to the parts of the book it draws on.