Skip to content
Neutral Works
Go back

Applying Graph Theory to CTI and Threat Hunting

Tech

In cyber threat intelligence, an accurate and prompt data acquisition is always crucial. This process typically involves extracting, transforming, and loading (ETL) raw data from various sources to identify potential threats and vulnerabilities. By doing so, organisations might get a chance to stay ahead of cybercriminals by obtaining necessary information to detect, analyse, and mitigate threats.

In data science, a ‘graph’ consisting of nodes (also called vertices) and edges (also called links) is commonly used to visualise and analyse relationships and interactions within a network. By representing the data as nodes and edges in an interactive graph, security analysts are able to quickly identify patterns and anomalies that might signify a cyber threat.

For demonstration purpose, we prepared a sample dataset by generating 2000+ random email senders and 500 recipients as well as creating a DataFrame with random relationships between each sender and recipient in a Jupyter Notebook.

# Generate 200 email senders using a same domain
shared_domain = "shared-domain.com"
shared_senders = [generate_random_email(shared_domain) for _ in range(200)]

# Generate 2500 email senders using random domains
random_domains = [
    "example.com", "random.com", "mail.com", "test.com", "demo.com", "sample.com",
    "domain.com", "website.com", "internet.com", "webmail.com", "service.com",
    "company.com", "business.com", "enterprise.com", "organization.com", "firm.com",
    "corporate.com", "startup.com", "agency.com", "consulting.com"
]
other_senders = [generate_random_email(random.choice(random_domains)) for _ in range(2500)]

# Generate 500 recipients with the same domain 'test-recipient.co.nz'
recipient_domain = "test-recipient.co.nz"
unique_recipients = [generate_random_email(recipient_domain, name_length=5) for _ in range(500)]

# Create a DataFrame with random relationships between email_senders and recipients
num_rows = 2500
edges_data = {
    'email_sender': random.choices(email_senders, k=num_rows),
    'email_recipient': random.choices(unique_recipients, k=num_rows)
}

After data cleaning and formatting steps, we set up a graph visualization using nx.spring_layout, applied datashading, customized node colors, and added a bit of interactivity with hover tools.

import networkx as nx
import holoviews as hv
from holoviews import opts, dim

... ...

# Leverage nx.spring_layout
result = directly_connect_edges(layout_nodes(graph, layout=nx.spring_layout))

# Define node options
node_opts = hv.opts.Nodes(color='type', size=8, cmap={'sender': 'green', 'recipient': 'red'}, tools=['hover'])

# Apply datashading and node options
datashade(result) * result.nodes.opts(node_opts)

Now, with the help of this visualised phishing attack attempt network graph, we can clearly identify that:

In summary, a network graph is able to provide a clear visualisation of complex entity relationships and interactions, enabling cybersecurity analysts to detect, analyse, and respond to cyber threats more effectively.

Besides enhancing threat intelligence gathering from phishing attack attempts, a network graph can also be used to analyse network intrusion attempts based on source and destination IPs, malware propagation paths based on OS process relationships, and more.

I hope you find this article useful, and thank you for reading. :)

Reference:


Related: If you’re interested in how threat intelligence feeds into continuous security validation, see Continuous Purple Teaming with CI/CD, IaC, and AI.


Share this post:

Previous Post
Building your own shellcode stager with customised functions
Next Post
C2 Defense Evasion: Avoiding Shell Execution in Node.js