AL, AI, and Sigma: Automating Threat Hunting With OpenAI

Traditional threat hunting involves taking some threat intelligence, such as Palo Alto Unit 42 (https://unit42.paloaltonetworks.com/), and searching for malicious activity. More often than not, we find nothing and then forget how we searched for the malicious activity. This is why one of the products of any threat hunt should be a Sigma rule. 

A Sigma rule is a standardized format for creating rules to detect suspicious activities or anomalies in log data across various security information and event management (SIEM) systems. What sets Sigma apart is its normalization to YAML format, making it SIEM-agnostic and allowing for seamless conversion to the querying language of your preferred SIEM, giving you the freedom to use it in the system that best suits your needs. 

Reading through article after article, and extracting the necessary details to write a Sigma rule can be time-consuming and tedious. I remember a quote from a system administrator when I worked at the service desk decades ago: "If you need to type a command more than once, write a script." Let's take a modern twist on that: "If you need to do a task more than once, have AI do it."

 This post will discuss training an OpenAI GPT4 model to learn a Sigma rule, search the Unit 42 blog, and write a Sigma rule for each post. This post will go over the steps for training a module; however, it will not go over setting up your OpenAI account. 

First, open OpenAI Playground, create a new project called sigma-rule, navigate to the Completions section, and tell our module what a SigmaHQ rule is. The output is pretty good.

Next, let's go to the chat and select our module (gpt-4o), adjust our Maximum Tokens (the length of response) to the largest amount, and ask our module to write a Sigma rule for a specific Unit 42 article. Yet again, the output looks good.
Let's check the rule with sigconverter.io; it was successful again.
Now, let's see if our module is smart enough to search the home page for Unit 42 (https://unit42.paloaltonetworks.com/) and write rules for the articles from the last ten days. Amazing!!!
We need an API key for our script to interact with our OpenAI module. In the left-hand panel, navigate to API keys and select Create new secret key. Please take note of your key. We will need it later.
Let's put our websites in a text file called feeds.txt text.
After we update our script (I'll post the code below so that you can copy and paste it) with the API key, we read in the feeds.txt file to a list and then perform a request to create a Sigma rule for the last ten posts.
Success!!!
Here's gist for the script.

Comments

Popular posts from this blog

Mapping CIS Critical Controls to Gartner Markets

Malware Can Hide But It Must Run

PCAP Doesn't Lie Part 2