Skip to content
ImagineWorld

Threat Intelligence

node_idnode-book_artificial-intelligence-for-cybersecurity_chapter-11-threat-intelligence
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num11
chapter_titleThreat Intelligence
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

In cybersecurity, it’s important to stay on top of changes in the threat landscape and investigate how threat actors behave and what are the emerging risks. This means that we cannot rely only on our detections; we need to seek information from outside sources as well to enhance our knowledge and make better decisions. Therefore, one of the most important parts of the detection and analysis of cyber threats is the analysis of various sources of information and the synthesis of knowledge from it. Apart from internal detection mechanisms, there are many public and non-public sources of information describing current cyber threats that can be used to prepare defenses, improve cybersecurity analytics, and shed light on cybersecurity risks.

In this chapter, we will cover an introduction to threat intelligence and explain how artificial intelligence (AI) can be helpful in retrieving information from various threat intelligence data sources. Furthermore, we include a practical exercise with an example of information retrieval from public data.

To summarize, in this chapter, we are going to cover the following topics:

  • Understanding threat intelligence
  • Working with AI for threat intelligence
  • Exercise – retrieval of threat intelligence from X (formerly Twitter) using AI

This chapter has a practical component and requires the following Python libraries:

  • numpy
  • pandas
  • gensim
  • PyLDAvis
  • collections
  • ntlk

For the best learning performance, it’s recommended to use notebook libraries and platforms, like the following:

  • jupyter
  • google-colab
  • Databricks

Cyber threat intelligence (CTI) consists of the collection, analysis, correlation, and sharing of cybersecurity-related data from public and non-public data sources. The information retrieved through CTI is used not only to adapt and strengthen defenses but also to assess risk and justify funding for these improvements. Therefore, accurate and complete information retrieval is crucial for cybersecurity in enterprises and other organizations.

We can differentiate the following types of threat intelligence:

  • Tactical: Tactical threat intelligence focuses on providing data about potential attacker activity. This means to gather data about malware, network traffic patterns, malicious URLs, phishing, and similar. The data is structured as tactics, techniques, and procedures (TTPs) and can be used to adjust the defensive security tools to provide optimal protection.
  • Strategic: While tactical threat intelligence provides more particular and fine-grained information about attacker activity, in strategic threat intelligence, the focus is on high-level information that can be used by the cybersecurity leadership to understand risk and the cybersecurity posture. Furthermore, there is other non-technical information useful for strategic decisions, such as legal information or social media. This strategic information directly impacts business decisions.
  • Operational: In operational threat intelligence, the idea is to complement the tactical technical information with other data about the attacker’s motive and activity. Common data sources for this are the social media of the attacker, forums, chats, and so on. This data should be directly useful in operational activity, for example, to inform the people performing operational activities if there is an ongoing attack.

Organizations need all three types of threat intelligence to work together to provide proper insight into current cybersecurity posture, assess risk, and improve defenses.

CTI includes a large set of activities that should be structured optimally. Broadly speaking, there are six phases in the CTI life cycle:

  1. Planning: Here, we gather requirements and set the roadmap for the threat intelligence process.
  2. Collection: In this part, we collect data relevant to our requirements, from different public or non-public sources.
  3. Processing: The data could be collected in various formats and have variable quality. Here, we process collected data to transform it into the form needed for analysis.
  4. Analysis: In the analysis part, we take a deeper look to obtain insight from the transformed data that can be used to inform our threat investigation and the impact of threats on cybersecurity risk.
  5. Dissemination: In this step, we share the information and insights obtained through the analysis of CTI data. The information could be shared within the organization, externally with organizations in the same area, or even publicly.
  6. Feedback: Here, we gather feedback from the recipient of the CTI information. Furthermore, we will possibly be directed to the planning phase again if there are any further requirements.

In the next section, we will describe how AI fits into this life cycle and what value it can bring to the CTI analysts and the recipients of CTI information.

Having in mind that Steps 3 and 4 in the CTI life cycle are about processing and analysis of data, we can anticipate that some form of intelligent data analytics techniques are beneficial to obtain information from threat intelligence data. Open-source intelligence (OSINT) data sources, such as online publications, media, blogs, newspapers, and so on offer a large volume of mainly textual data that may contain useful information for cyber threat investigation. Having in mind the volume and variety of information, we could benefit from natural language processing (NLP) techniques and machine learning techniques to automate and accelerate information extraction.

There were multiple academic and industrial approaches to such information extraction. They are based on extracting topics or keywords related to cyber threats in general or to a specific topic of investigation. For instance, we could be investigating a particular vulnerability and attempting to extract information about this, or similar vulnerabilities that affect a particular type of devices. On the other hand, we could be extracting information about zero-day vulnerabilities in general, or about a topic such as denial of service attacks or ransomware.

To extract features from textual documents, we can employ a typical sequence of steps:

  1. Tokenization: In this step, we parse the text data into tokens (usually words). This is a very common first step in text processing.
  2. Stemming: This step is to remove prefixes and suffixes to get the root of the word, which enables us to look at the words with the same root to have the same meaning. For instance, the words “hacking,” “hack,” and “hacked” might be stemmed from a root “hack,” as they have essentially the same meaning, from the NLP standpoint.
  3. Lemmatization: We group different forms of the same word to map to the same token (e.g., different tenses), for instance, the words “is” and “be.”
  4. Part of speech tagging: In this step, we identify parts of speech for different tokens (e.g. nouns, verbs, etc.) These steps enable us to extract knowledge or meaning from textual documents, which is often the form of data in CTI. It is not obligatory to perform all the steps in each CTI analysis; the exact steps depend on the task and the data at hand.
  5. Machine learning: After these processing stages, it’s possible to apply AI methods to further analyze the CTI data. We can employ typical methods, which were described in Chapter 5, such as classification, regression, or clustering, to classify documents into predefined categories, predict some properties of documents, or cluster the documents to discover the underlying structure. Furthermore, there are other AI, or, in particular, machine learning methods that could be interesting to do even deeper analysis. One of them is topic modeling.

Topic modeling is a set of methods for uncovering groups of words that happen to be together in documents. These groups are called topics. The assumption is that a set of texts comes from a discrete set of topics, and one text can belong to one or more topics.

During the training, we can determine the topics as distributions over words, and documents also belong to different topics with different probabilities. This is different than just clustering or classification because we don’t just group documents into different clusters or categories.

In topic modeling, we assume that documents can belong to different “groups” at the same time, as they can contain text from multiple topics. Furthermore, the words don’t necessarily point to one topic, but they can be characteristic of multiple topics at the same time. One common example of topics is in the analysis of newspaper articles, where topics would be politics, sports, business, and so on. Words belonging to sports could be “football,” “game,” or “match,” and words belonging to politics could be “election,” “president,” or “debate.” However, some words don’t have a clear assignment. For instance, words such as “agreement” or “deal” could belong to both politics and business. One article could also encompass multiple topics, such as business and politics, or business and sports. Therefore, topic modeling needs to take account of those cases.

In the next section, we present an exercise where topic modeling is applied to the problem of information extraction from X.

Exercise – extracting CTI information from X data

Section titled “Exercise – extracting CTI information from X data”

Social media can be a fascinating and useful source of information for discovering new vulnerabilities and investigating trends in the threat landscape through acquiring data that are publicly released by experts or organizations. X is a way to quickly publish short text content and is often used to share news about new vulnerabilities.

However, the volume of data from X can pose a challenge, as we try to retrieve information from text and find what’s important for our analysis. Tools that can help us automate this analysis and increase its accuracy in potentially noisy data are always welcome. Intelligent data processing is exactly what AI methods excel at, and given that the data is textual, we can apply methods that are used in NLP, which is a discipline that also intersects with AI.

In the next subsection, we describe the preprocessing of data as a preceding step to applying NLP methods.

In this exercise, we analyze data from posts (posts) about vulnerabilities, gathered by the CyberTweets project and posted on GitHub by Bezhadan et al. (Behzadan, Vahid, et al. Corpus and Deep Learning Classifier for Collection of Cyber Threat Indicators in Twitter Stream. 2018 IEEE International Conference on Big Data (Big Data). IEEE, 2018). We use the data available in a tweets.bson file from a MongoDB database snapshot.

The data is available on a public GitHub repository:

https://github.com/behzadanksu/cybertweets/tree/master/threat

You need to download the tweets.bson file. Since it’s a .bson (Binary JSON) file, you need the bson library to read this file. For example, you can install it using pip:

%pip install bson

We decode the contents of the file and load them into a list of post (earlier called a tweet) strings using the following code:

Import bson
posts_text = []
with open('tweets.bson', 'rb') as f:
content = f.read()
base = 0
while base < len(content):
base, d = bson.decode_document(content, base)
posts_text.append(d['text'])

We can output a sample of posts using the following code:

[print(t) for i,t in enumerate(posts_text) if i<num_posts]

This can give us the following sample:

Best way to build empathy is through honesty and vulnerability. Cryptocurrency Scams Replacing Ransomware as Attackers' Fave | https://t.co/zesoY4oLQs
Cryptocurrency Scams Replacing Ransomware as Attackers' Fave https://t.co/2jCvL5ZvpQ
Protect your customers access Prestashop Anti DDoS Attack #Prestashop https://t.co/xUGxiI8zw8 https://t.co/hXmPX30FmK
Data leak from Huazhu Hotels may affect 130 million customers https://t.co/RRXVTAWnIu
Instagram App 41.1788.50991.0 #Denial Of #Service https://t.co/pTsuQe2HT9 #PacketStorm (good slides):

To further analyze and process the text, we use the ntlk and gensim libraries. The following code sample enables us to import the required libraries:

from gensim import models, corpora
from collections import defaultdict
import nltk

The next step is to preprocess the text. In our case, we tokenize the text by splitting the string into an array and removing stopwords and common words that likely don’t contribute to the model.

Luckily, we don’t need to know all the stopwords for this. We can use the nltk library and its stopwords function. This module doesn’t necessarily come with the library. If you don’t have this module, you can use the following line to run the download:

nltk.download()

Furthermore, you need to select stopwords when asked about the module to download, to download the right module.

Once you have the stopwords module, you can import and use it as follows:

from nltk.corpus import stopwords
s=set(stopwords.words('english'))
texts = [
[word for word in document.lower().split() if word not in s]
for document in posts_text
]

Furthermore, we can remove some custom stopwords or common words that we find in the text using the following code lines:

stoplist = set('for a of the and to in is
you are I this that - ='.split())
texts = [
[word for word in document if word not in stoplist]
for document in texts
]

Lastly, we can remove the words that only appear once:

frequency = defaultdict(int)
for text in texts:
for token in text:
frequency[token] += 1
texts = [
[token for token in text if frequency[token] > 1]
for text in texts
]

Once the preprocessing is done and the texts are prepared, we can apply AI models for NLP. We describe our modeling approach in the next subsection.

To build the model, we need to define the following:

  • Corpus: A set of documents considered when training the model
  • Dictionary: A set of tokens (words) taken into account by the model
  • Model type and hyperparameters: The type of AI model we are using and the hyperparameters that predefine model adjustments

There are many possible ways to model a set of texts. In our case, we are trying to uncover the underlying structure of our set of documents. One good way to do that is topic modeling, described in the previous section.

One of the most common methods of topic modeling is the latent Dirichlet allocation (LDA). LDA is a probabilistic topic modeling method where we define an assumption that the content of our posts belongs to a small set of topics of a predefined size. In training time, we adjust the parameters of the topic in a way that a small set of topics can cover all the documents in our corpus. The Gensim library has an implementation of LDA, and we will use this implementation in our exercise. The idea is to uncover the structure of our set of posts, to see what kind of content we can find, without manually going through all the data.

In the following lines, we define the dictionary and the corpus based on the preprocessed texts:

dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]

We create a model using the following lines:

model = models.LdaModel(
corpus, id2word=dictionary, num_topics=num_topics)

This creates a model that defines the topics present in our set of texts. One important condition is that we need to predefine the number of topics. This means that we need to have a good guess of how many topics there might be or find it by experimentation. There are methods such as hierarchical Dirichlet processes that don’t require a predefined number of topics, but they do have different hyperparameters that need to be defined before training the model.

To get an insight into the topics, we can use the print_topics method, like the following:

>>> model.print_topics(num_topics)
[(0,
'0.028*"vulnerability" + 0.017*"ddos" + 0.008*"security" + 0.006*"attack" + 0.005*"one" + 0.005*"like" + 0.005*"businesses" + 0.004*"know" + 0.004*"&amp;" + 0.004*"fake"'),
(1,
'0.026*"ransomware" + 0.025*"vulnerability" + 0.010*"new" + 0.008*"buffer" + 0.008*"#ransomware" + 0.007*"#cybersecurity" + 0.007*"via" + 0.007*"overflow" + 0.006*"#infosec" + 0.005*"exploit"'),
(2,
'0.032*"vulnerability" + 0.014*"1,0day" + 0.009*"&lt;=" + 0.009*"alarm" + 0.009*"gsm2" + 0.009*"[hw1.4]" + 0.009*"calibration" + 0.009*"cb_xlabor-dauertest" + 0.009*"kunde:" + 0.009*"mydatasens"')]

From the distributions of the three topics, it seems like the first topic is largely dedicated to the Distributed Denial of Service (DDoS) attacks, the second topic can be attributed to ransomware and buffer overflow, and the third is mostly to ransomware and 1- or 0-day attacks.

The Gensim library also enables us to print topic distribution for documents in our corpus, or outside of it.

Here are two examples:

>>>print(posts_text[1])
Cryptocurrency Scams Replacing Ransomware as Attackers' Fave | https://t.co/zesoY4oLQs
>>>model[corpus][1]
[(0, 0.047974426), (1, 0.9041977), (2, 0.047827844)]
>>>print(posts_text[3])
Protect your customers access Prestashop Anti DDoS Attack #Prestashop https://t.co/xUGxiI8zw8 https://t.co/hXmPX30FmK
>>>model[corpus][3]
[(0, 0.93299556), (1, 0.033533014), (2, 0.03347142)]

These two documents decisively contain one topic. The first document belongs mostly to topic 1 (second topic, ransomware), whereas the second document belongs to topic 0 (first topic, DDoS).

Topics can be understood better using visualization. Luckily, there is the pyLDAvis library that can help us with that. This library enables interactive topic visualization and is also interoperable with Gensim. This means that we can use Gensim models as input for the visualization functions of this library.

We can use the plotting functions by executing the following code:

import pyLDAvis
import pyLDAvis.gensim_models
pyLDAvis.enable_notebook()
pyLDAvis.gensim_models.prepare(model, corpus, dictionary)

This should generate two images:

  • Intertopic distance map: This shows the distances between topics
  • Top 30 model salient terms: This shows terms (words) that are most important, or most common in particular topics or overall, in the corpus

The following figures show the example images for the corpus that we used in this exercise. The first figure shows the intertopic distance map:

Figure 11.1 – A visualization of topic models using the pyLDAvis library – intertopic distance map

Figure 11.1 – A visualization of topic models using the pyLDAvis library – intertopic distance map

The preceding figure is an illustration of the distance between topics (i.e., how different the topics are in the distribution of words (tokens)).

The next figure shows the top 30 model salient terms.

Figure 11.2 – A visualization of topic models using the pyLDAvis library – the top 30 model salient terms

Figure 11.2 – A visualization of topic models using the pyLDAvis library – the top 30 model salient terms

The second figure shows which words are most important in the corpus. Furthermore, in the interactive figure that would be generated, it’s possible to select a specific topic and review the word distribution for that topic.

Topics can also be used further as features for clustering, regression, or classification methods. For example, if we had labeled posts by assigning importance labels, we could try to train a model to classify each post into one of the predefined classes, by using topic probabilities for each document as a feature set.

This exercise shows one example of how we can use AI methods to retrieve information from CTI data. In the next section, we summarize the content of this chapter and review what we have learned.

Expanding on use cases of AI in threat intelligence

Section titled “Expanding on use cases of AI in threat intelligence”

Apart from posts, there are many other datasets where NLP is relevant. For instance, in threat intelligence, the source of information could be blogs, news posts, but also security-specific data such as IP blacklists or malware data. Aggregating this threat data using big data platforms and applying machine learning algorithms can enable us to get important information that can be intractable or just be missed by a human analyst.

For instance, Microsoft, in their blog, described their application of machine learning to get information about advanced persistent threats (https://www.microsoft.com/en-us/security/blog/2019/08/08/from-unstructured-data-to-actionable-intelligence-using-machine-learning-for-threat-intelligence/).

Another company called Abnormal Security used machine learning to analyze email threats (https://abnormalsecurity.com/blog/using-artificial-intelligence-address-email-threats).

In recent years, we have also seen an expansion of the use of large language models (LLMs) in many areas to improve search through textual information. This is also a promising avenue for threat intelligence analysts. For instance, they can use the power of LLMs to improve the search for information about indicators of compromise, improve the aggregation of various types of information, and interact with it more naturally. Furthermore, it can help threat analysts make more accurate conclusions, for instance, about attack attribution.

In this chapter, we were introduced to CTI and the possibility of using AI methods to improve CTI workflows by making information extraction faster and more insightful. This chapter teaches you how to recognize opportunities to apply AI in CTI problems, design the right approach, and implement it. Moreover, we saw a concrete CTI problem and were guided through an exercise using topic modeling to process CTI data.

The next chapter contains a description of a problem with increasing importance – detecting security anomalies in industrial control systems, and AI approaches to solve this problem.

  • Qamar, Sara, Zahid Anwar, Mohammad Ashiqur Rahman, Ehab Al-Shaer, and Bei-Tseng Chu. “Data-driven analytics for cyber-threat intelligence and information sharing.” Computers & Security 67 (2017): 35-58.
  • Wheelus, Charles, Elias Bou-Harb, and Xingquan Zhu. “Towards a big data architecture for facilitating cyber threat intelligence.” In 2016 8th IFIP international conference on new technologies, mobility and security (NTMS), pp. 1-5. IEEE, 2016.
  • Chen, Haipeng, Rui Liu, Noseong Park, and V. S. Subrahmanian. “Using twitter to predict when vulnerabilities will be exploited.” In Proceedings of the 25th ACM SIGKDD international conference on knowledge discovery & data Mining, pp. 3143-3152. 2019.
  • Mittal, Sudip, Prajit Kumar Das, Varish Mulwad, Anupam Joshi, and Tim Finin. “Cybertwitter: Using twitter to generate alerts for cybersecurity threats and vulnerabilities.” In 2016 IEEE/ACM International Conference on Advances in Social Networks Analysis and Mining (ASONAM), pp. 860-867. IEEE, 2016.
  • Manning, Christopher D. Foundations of statistical natural language processing. The MIT Press, 1999.
  • Blei, David M., Andrew Y. Ng, and Michael I. Jordan. “Latent dirichlet allocation.” Journal of machine Learning research 3, no. Jan (2003): 993-1022.
  • Teh, Yee, Michael Jordan, Matthew Beal, and David Blei. “Sharing clusters among related groups: Hierarchical Dirichlet processes.” Advances in neural information processing systems 17 (2004).
  • https://www.crowdstrike.com/cybersecurity-101/machine-learning-cybersecurity/
  • https://www.recordedfuture.com/threat-intelligence
  • https://www.silobreaker.com/glossary/ai-in-threat-intelligence/
  • https://www.secureworks.com/blog/automating-threat-intel-with-machine-learning