# End-to-End Alert Automation: Wazuh → Shuffle → TheHive

## 🏗️ Final Part: SOC Automation Project

* Building the lab diagram
* Installing and configuring tools
* Generating telemetry data

### 🎯 Today's Goal

We'll connect **Shuffle (SOAR platform)** with **Wazuh** and **TheHive**, allowing: \
✅ Wazuh to send alerts to Shuffle \
✅ Shuffle to forward alerts to TheHive and email analysts

***

## 🔗 Installing and Setting Up Shuffle on Ubuntu

### **1. Install Dependencies**

To begin, update the package list and install Docker and Docker Compose:

```bash
sudo apt update && sudo apt install -y docker.io docker-compose
```

Then, enable and start the Docker service:

```bash
sudo systemctl enable docker
sudo systemctl start docker
```

### **2. Clone the Shuffle Repository**

Download the Shuffle source code from GitHub:

```bash
git clone https://github.com/Shuffle/Shuffle.git
cd Shuffle
```

### **3. Deploy Shuffle with Docker Compose**

Run the following command to start the Shuffle services:

```
sudo docker-compose up -d
```

### **4. Access the Web Interface**

Once the installation is complete, open your web browser and navigate to:

```
http://your-server-ip:3001
```

You should now see the Shuffle login page.

***

## **Post-Installation Steps**

### **5. Set File Ownership and Restart Services**

<figure><img src="/files/jKCfyvSpzQJgridVt4dH" alt=""><figcaption></figcaption></figure>

Run the following commands to fix ownership issues and restart necessary services:

```
sudo chown -R 1000:1000 shuffle-database
sudo swapoff -a
sudo docker restart shuffle-opensearch
```

These steps ensure proper functioning of the database and avoid issues related to system swap.<br>

<figure><img src="/files/g6KbYZDrlMFfBo3FV0vg" alt=""><figcaption></figcaption></figure>

***

### **7. Create a New Workflow**

Once Shuffle is installed and running, you can start automating tasks by creating workflows:

#### 1️⃣ Create an Account

* Sign up and log in
* Click **Workflows** > **New Workflow**
* Name it **SOC Automation Lab**
* Select any use case and click **Done.**<br>

  <figure><img src="/files/pFb6UQXINmBJuH4NYjV4" alt="" width="563"><figcaption></figcaption></figure>

#### 2️⃣ Add a Webhook Trigger

* Click **Triggers** (middle tab)
* Drag & drop **Webhook** into the workspace
* Name it **wazuh-alerts**
* Copy the **Webhook URL** (you’ll need it later)<br>

  <figure><img src="/files/0HHRGxYxTjOlxCaa8DxA" alt="" width="563"><figcaption></figcaption></figure>
* Click **Change Me** and set:
  * **Execution type**: Repeat back to me
  * Remove **Hello World**
  * Click **+** > **Execution Argument**
  * Save<br>

    <figure><img src="/files/Yvba66X9RpfOjjkcITJz" alt="" width="563"><figcaption></figcaption></figure>

***

### ⚙️ Configuring Wazuh to Connect with Shuffle

#### 1️⃣ Edit Wazuh’s Configuration

* SSH into Wazuh Manager
* Open the config file:

  ```
  sudo nano /var/ossec/etc/ossec.conf
  ```
* Scroll to the section (or anywhere in the file)
* Add this:

  ```html
  <integration>
      <name>shuffle</name>
      <hook_url>https://shuffler.io/api/v1/hooks/webhook_ad498563-e028-4652-b63f-f918b0abb537 </hook_url>
      <rule_id>100002</rule_id>
      <alert_format>json</alert_format>
    </integration>
  ```

  * Replace `PASTE_WEBHOOK_URL_HERE` with your **copied Webhook URL**
  * Ensure proper indentation (use spaces, not tabs)<br>

    <figure><img src="/files/F1T7djIHGCHldgvN1rWE" alt="" width="563"><figcaption></figcaption></figure>

#### 2️⃣ Restart Wazuh

* Save and exit (`CTRL + X`, then `Y`, then `Enter`)
* Restart Wazuh:

  ```
  sudo systemctl restart wazuh-manager
  ```
* Check the status:

  ```
  sudo systemctl status wazuh-manager
  ```

  If it says **running**, We're good to go :rocket:

***

### 🚀 Testing Mimikatz Alert

#### 1️⃣ Run Mimikatz

* On your **Windows Client**:

  ```
  .\totally-not-mimktaz.exe
  ```
* This simulates an attack and should trigger an alert

#### 2️⃣ Check Shuffle for Events

* Go back to **Shuffle**
* Click on **Webhook**
* Click **Start** > **Person Icon** (bottom tab)<br>

  <figure><img src="/files/0rgAKIjEzPkIsvcJVNuM" alt="" width="563"><figcaption></figcaption></figure>
* Click **Test Workflow**\ <br>

  <figure><img src="/files/MdaBOdcoszFRKA8QKQSD" alt="" width="563"><figcaption></figcaption></figure>

  <figure><img src="/files/IbkgdADQxMn4n5cppcBM" alt="" width="563"><figcaption></figcaption></figure>
* You should see the **execution arguments** (alert details from Wazuh)

***

### 🔄 Automating Further with VirusTotal & TheHive

Once alerts reach Shuffle, we can:

1. **Extract the file hash** (from Mimikatz alert)
2. **Check the reputation on VirusTotal**
3. **Create a case in TheHive**
4. **Send an email to the SOC analyst**

<mark style="color:yellow;">To extract hashes correctly:</mark>

* **Add Action** → Search **"Regex Capture Group"** → Add it.<br>

  <figure><img src="/files/2hLjDyhxj9eLdJyTP9vW" alt="" width="563"><figcaption></figcaption></figure>
* **Set Input** → Use `$exec.text.win.eventdata.hashes`.<br>
* **Enter Regex** → `SHA256=([A-Fa-f0-9]{64})`.<br>

  <figure><img src="/files/63xQJlYqJWb5KKDvBsTO" alt="" width="348"><figcaption></figcaption></figure>
* **Save & Test** → Run to check extraction.\ <br>

  <figure><img src="/files/QLPWH2iN6HAwbe16xpE3" alt="" width="563"><figcaption></figcaption></figure>

***

## 🔍**Send the Hash to VirusTotal**

#### **Get a VirusTotal API Key**

1. Go to 🔗 [VirusTotal](https://www.virustotal.com/) and **Sign Up**.
2. After signing up, go to your **account settings** and **copy the API key**.\
   ![](/files/sFPtF6CMUcGcsSHvPtni)

#### **Connect VirusTotal to Shuffle**

1. In **Shuffle**, go to **Apps** and search for **VirusTotal**.
2. Click on **VirusTotal** and **activate it**.
3. Drag it into your **workflow**.

#### **Set Up the VirusTotal Action**

1. Rename it to **VirusTotal**.
2. Under **Find Actions**, choose **"Get a hash report"**.
3. Paste your **API key** in the authentication field.<br>

   <figure><img src="/files/JwPjTS2eERp9bM7wYcCH" alt="" width="563"><figcaption></figcaption></figure>
4. In the **Hash Section**, select the **Regex Output** from the previous step.<br>

   <figure><img src="/files/gQLUvpaCnmeATpcohdPI" alt=""><figcaption></figcaption></figure>

***

### **Now, get the Reputation Score**

#### **Verify VirusTotal's Output**

1. **Run the workflow again**.
2. Expand **VirusTotal's output** → Go to **Body Data → Attributes → Last Analysis Stats**.<br>

   <figure><img src="/files/SwFVXE6GW4GF3nMMobPI" alt="" width="563"><figcaption></figcaption></figure>
3. Look for the **Malicious Score** (e.g., `65 scanners detected as malicious`).
4. This number represents how many scanners flagged the file as a **threat**.

***

### &#x20;📤**Send Data to TheHive**

#### **Add TheHive to Shuffle**

1. Search for **TheHive** in **Shuffle Apps** and add it to your **workflow**.
2. Drag it into your **workflow** and **connect it** to **VirusTotal**.
3. Wait for **TheHive actions** to load (refresh if needed).<br>

   <figure><img src="/files/7sI5MYAVMuezqFmtxvCM" alt="" width="563"><figcaption></figcaption></figure>

#### **Configure TheHive**

1. Go to **TheHive Web Interface**.

2. Log in with **default credentials**:

   ```
   Username: admin@thehive.local  
   Password: Secret
   ```

3. Create a **new organization** (e.g., "Osama Team").<br>

   <figure><img src="/files/yEY3AWztwF7yg7RDSdY4" alt=""><figcaption></figcaption></figure>

   <figure><img src="/files/Z7YbiLedwzGKrBxF8Hzc" alt=""><figcaption></figcaption></figure>

4. Add **two users**:
   * **Analyst**: <theuser@test.com><br>

     <figure><img src="/files/byZ5kTLPsYtH2GQD7vX1" alt="" width="563"><figcaption></figcaption></figure>
   * **Service Account**: <shuffle@test.com> (give it **least privilege** access).<br>

     <figure><img src="/files/kLHI8SstsHlfqLB8FKMr" alt="" width="563"><figcaption></figcaption></figure>

5. We need to set a password for Karims's account and generate an API key for the SOAR account.\ <br>

   <figure><img src="/files/CppzqGYkFjhUrVjCnTpE" alt=""><figcaption></figcaption></figure>

   <figure><img src="/files/1vufP7qEjKO01zmRjnr9" alt=""><figcaption></figcaption></figure>

6. In **Shuffle**, configure **TheHive action** to send **alerts** based on **VirusTotal results**.\ <br>

   <figure><img src="/files/MsOcVqjigvVI7yozsm0u" alt=""><figcaption></figcaption></figure>

7. Now, we must setup the alert configurations details for TheHive and VirusTotal :\ <br>

   Fields (Summary ,Description ):

   ```
   Summary -> Mimikatz Activity Detected on host: $exec.text.win.system.computer and the Process Id: $exec.text.win.eventdata.processId and the Commandline: $exec.text.win.eventdata.commandLine
   Description -> Mimikatz Detected on host:$exec.text.win.system.computer
   ```

   <br>

   <figure><img src="/files/7VTN6qINA6MtpecmNjdo" alt=""><figcaption></figcaption></figure>

   <figure><img src="/files/JkeD3slSku7S7v4pYJSG" alt=""><figcaption></figcaption></figure>

   <figure><img src="/files/DNjB5JAwKF2Djjqp6cBa" alt=""><figcaption></figcaption></figure>

## :warning: Note: You might have the same problem here as me

<figure><img src="/files/4HNteRHqHPhjNwfslP8k" alt="" width="563"><figcaption></figcaption></figure>

### Fixing JSON Issues in TheHive (Shuffle Integration)

### Problem

When sending alerts from **Shuffle** to **TheHive**, you may encounter a **400 Bad Request** error due to an **invalid JSON format**.

### Cause

* The **execution argument auto-completion** in Shuffle inserts incorrect JSON paths.
* TheHive requires properly formatted JSON, and incorrect paths cause errors.

### Solution

#### Step 1: Use the Advanced Field

1. Open your **Shuffle Workflow**.
2. Navigate to the **TheHive** action node.
3. Click **Advanced** to manually input the JSON body.<br>

   <figure><img src="/files/WNOjA1OL0yyKbwerJFIN" alt="" width="563"><figcaption></figcaption></figure>

#### Step 2: Paste the Correct JSON Format

Copy and paste the following JSON into the **Body** field:

```json
{
  "description": "Mimikatz Detected on host: test-host",
  "externallink": "",
  "pap": 2,
  "severity": 2,
  "source": "Wazuh",
  "sourceRef": "Rule: 100002",
  "status": "New",
  "summary": "Mimikatz Activity Detected on host: test-host and the Process Id: 1234 and the Commandline: mimikatz.exe",
  "tags": ["T1003"],
  "title": "Test Alert",
  "tlp": 2,
  "type": "Internal"
}
```

#### Step 3: Save & Test

1. Save the workflow.
2. Rerun the execution.
3. The error should be resolved, and TheHive will receive the alert correctly. 🎯<br>

   <figure><img src="/files/2rwgPgjR7oZB6UiVHz2K" alt=""><figcaption></figcaption></figure>

## **Now, Log in to TheHive and Check Alerts**

To verify any alerts in TheHive, log in using the previously created account:

1. Open your web browser and navigate to TheHive's login page.
2. Enter the credentials for the account **"Karim" .**
3. Check the dashboard for any **alerts** or **notifications**.<br>

   <figure><img src="/files/kxs70j8TWKfZGwOtoC5C" alt="" width="563"><figcaption></figcaption></figure>

   <figure><img src="/files/9lC7QqZESLBI4vuCv2AA" alt="" width="563"><figcaption></figcaption></figure>

## **Sending a Telegram Message via Shuffle**

<figure><img src="/files/as62m1ubPmJIKaY5d24v" alt=""><figcaption></figcaption></figure>

**Steps:**

1️⃣ **Install & Configure Shuffle**

* Ensure Shuffle is running on your Ubuntu server.

2️⃣ **Use the HTTP App in Shuffle**

* Go to **Shuffle UI → Apps** → Install **HTTP App**.

3️⃣ **Create a Workflow**

* Add **HTTP Request** as an action.
* Set **POST** as the request method.
* URL:

  ```
  https://api.telegram.org/bot<YOUR-TOKEN>/sendMessage
  ```
* Body (JSON):

  ```json
  jsonCopyEdit{
    "chat_id": "<CHAT_ID>",
    "text": "Mimiktaz Detected!"
  }
  ```

<figure><img src="/files/t5RWbkQuXYBqzajkhBDV" alt=""><figcaption></figcaption></figure>

4️⃣ **Fix Connectivity Issues (if needed)**

* Restart HTTP App:

  ```bash
  docker restart <http_container_name>
  ```

5️⃣ **Run the Workflow**

* Execute the workflow → **Message sent to Telegram! ✅**<br>

  <figure><img src="/files/p4QUeoXYJMnZwlYnCJ28" alt="" width="381"><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://osamaa.gitbook.io/osama_homepage/cybersecurity-soc-analyst-labs/automation-lab-home-project/end-to-end-alert-automation-wazuh-shuffle-thehive.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
