Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ AI Agentic SOC Analyst

Python Azure Sentinel OpenAI Security

An autonomous cybersecurity agent that translates natural language into KQL, hunts for threats across Microsoft Sentinel & Defender for Endpoint, performs automated remediation, and engineers detection rules.

πŸ€– Watch the AI Agent hunt threats and write KQL rules in real-time.

πŸ“– Overview

The AI Agentic SOC Analyst is a CLI-based tool designed to act as a force multiplier for Security Operations Centers (SOC). It automates the end-to-end incident response lifecycle:

  1. Observe: Takes natural language queries (e.g., "Check for password sprays on Host-A").
  2. Orient: Translates intent into optimized KQL queries with smart time-range handling.
  3. Decide: Analyzes returned logs using LLMs to identify high-fidelity threats mapped to MITRE ATT&CK.
  4. Act: Offers active remediation (VM Isolation, AV Scans) and automated detection engineering (deploying rules to Sentinel).

✨ Key Features

🧠 Cognitive Threat Hunting

  • NLP to KQL: Converts English requests into precise KQL queries for DeviceProcessEvents, DeviceLogonEvents, AzureActivity, and more.
  • Smart Time Context: Handles relative times ("last 2 hours") and specific ISO ranges ("2023-11-01 to 2023-11-03").
  • LLM Analysis: Analyzes raw logs to determine threat confidence (High/Medium/Low) and extracts IOCs.

πŸ›‘οΈ Active Remediation

  • Host Isolation: Isolate compromised VMs in Defender for Endpoint (MDE) directly from the CLI.
  • Antivirus Scans: Trigger remote Quick/Full AV scans on suspicious hosts.

βš™οΈ Automated Detection Engineering

  • Rule Generation: Automatically writes high-fidelity KQL detection rules based on confirmed threats.
  • Sentinel Deployment: Pushes new rules directly to Microsoft Sentinel via Azure Management API.
  • Guardrails: Validates KQL schema to prevent hallucinations and blocks destructive commands (.drop, .delete).

πŸ’° Enterprise-Grade Controls

  • Cost Optimization: Estimates token usage and asks for model confirmation before expensive tasks.
  • Table Output: Renders log evidence in clean, readable ASCII tables.

πŸ—οΈ Architecture

The agent follows a modular architecture separating logic, API execution, and safety controls.

  • main.py: The orchestrator loop handling the user workflow.
  • executor.py: Handles API interactions (Azure Log Analytics, Graph API, Azure Management API).
  • guardrails.py: Validation logic for KQL schema, destructive commands, and time limits.
  • prompt_management.py: Stores system personas (Threat Hunter, Detection Engineer) and prompt builders.
  • utilities.py: UI formatting (Tabulate) and log parsing.
Binary Decision Flow-2025-12-10-212825

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • Azure Subscription with:
    • Microsoft Sentinel (Log Analytics Workspace)
    • Microsoft Defender for Endpoint (MDE)
  • OpenAI API Key
  • Azure CLI installed and logged in (az login)

Installation

  1. Clone the repository

    git clone [https://github.com/yourusername/ai-soc-analyst.git](https://github.com/yourusername/ai-soc-analyst.git)
    cd ai-soc-analyst
  2. Install dependencies

    pip install -r requirements.txt
  3. Set up Environment Variables Create a .env file in the root directory. Do not commit this file.

    OPENAI_API_KEY=sk-proj-xxxx...
    LOG_ANALYTICS_WORKSPACE_ID=your-workspace-guid
    
    # Required for Sentinel Rule Deployment
    SUBSCRIPTION_ID=your-subscription-id
    RESOURCE_GROUP_NAME=your-resource-group
    SENTINEL_WORKSPACE_NAME=your-workspace-name

πŸ’» Usage Walkthrough

1. Threat Hunting

User: "I'm worried there might be some malicious PowerShell activities going on workstation aniket-ai-soc-l in the past 4 hours."

Agent: Generates KQL, queries Azure, and presents a structured table of evidence.

  • User prompt and mapping to a relevant KQL query demo:
Screenshot 2025-12-10 163808
  • Log Analytics result and model selection based on estimated cost:
Screenshot 2025-12-10 164219
  • Threat hunt result displaying with severity levels and MITRE mapping:
Screenshot 2025-12-10 164810

2. Remediation

If a High Confidence threat is found, the agent offers immediate action.

Agent: "High confidence threat detected on host: aniket-ai-soc-l. Would you like to isolate this VM? (yes/no)"

Screenshot 2025-12-10 165117

3. Rule Creation (Closing the Loop)

The agent generates a KQL rule to prevent future attacks and deploys it to Sentinel.

Agent: "Initiating detection rule generation... Proposed Sentinel Rule: 'User-launched PowerShell_ISE.exe invoked cmd.exe to write 'Initializing Attack' to C:\Temp\Steal_Data\init.txt'. Deploy to Sentinel?"

Screenshot 2025-12-10 165511

πŸ”’ Permissions & Security

To fully utilize the agent, the executing Azure Identity (User or Service Principal) requires the following permissions:

Feature Required Role / Scope
Log Search Log Analytics Reader
VM Isolation MDE Security Admin or Active Remediation Role
Sentinel Rules Microsoft Sentinel Contributor

Note: The agent includes fallback logic. If API deployment fails due to permissions, it will offer to save the rule to a local local_rules.kql file.


πŸ“‚ Project Structure

.
β”œβ”€β”€ main.py                 # Core logic loop
β”œβ”€β”€ executor.py             # API handlers (Azure, OpenAI)
β”œβ”€β”€ guardrails.py           # Safety checks and validation
β”œβ”€β”€ prompt_management.py    # LLM System prompts and templates
β”œβ”€β”€ model_management.py     # Token counting and cost estimation
β”œβ”€β”€ utilities.py            # UI formatting (Tables, Colors)
β”œβ”€β”€ _keys.py                # Environment variable loader
β”œβ”€β”€ .env                    # Secrets (Not committed to Git)
└── requirements.txt        # Python dependencies

About

A modular AI-powered CLI for Azure Sentinel threat hunting & remediation. Features strict guardrails, cost-aware routing, and automated SOAR workflows (VM isolation, rule creation).

Topics

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages