SOC Operations & Automated Incident Response

Problem Statement

Phishing reports submitted by employees flood security operation queues. Manually inspecting raw email headers, extracting URLs, checking domain registration ages, querying sandbox analysis APIs, and deleting malicious emails across all tenant mailboxes takes significant time per incident.

Goal

Develop an agentic pipeline that ingests reported .eml payload metadata, safely parses headers/URLs, analyzes malice, and formats orchestration payloads for email deletion.

Outcome Measurement

  1. Phishing Response Time: Time from user report to enterprise inbox removal reduced from 45 minutes to < 30 seconds.
  2. Accuracy: Zero false-positive removals on legitimate internal corporate communications.

How the Code was Built

The script uses python standard libraries (urllib, re) for deterministic extraction combined with LLM semantic verification of email urgency/phishing language patterns.

Executable Code

import re
from typing import List
from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAI
class PhishingAnalysis(BaseModel):
is_phishing: bool = Field(description="True if email is malicious phishing attempt")
confidence: float = Field(description="Confidence score 0.0 to 1.0")
suspicious_indicators: List[str] = Field(description="List of detected anomalies")
action_item: str = Field(description="Action to take, e.g., PURGE_MAILBOX, WHITE_LIST, NO_ACTION")
def analyze_phishing_email(headers: str, body: str) -> PhishingAnalysis:
llm = ChatOpenAI(model="gpt-4o", temperature=0)
structured_llm = llm.with_structured_output(PhishingAnalysis)
urls = re.findall(r'https?://[^\s<>"]+', body)
prompt = f"""
Analyze the following email for phishing indicators:
HEADERS:
{headers}
BODY:
{body}
EXTRACTED URLS:
{urls}
Evaluate domain spoofing, urgency indicators, mismatch between link text and href destination, and overall intent.
"""
return structured_llm.invoke(prompt)
if __name__ == "__main__":
sample_headers = "From: IT Support <support@secure-update-login-portal.com>\nTo: victim@company.com\nSubject: URGENT: Password Expired"
sample_body = "Your corporate password expires today. Click here to retain access: http://secure-update-login-portal.com/login"
res = analyze_phishing_email(sample_headers, sample_body)
print(f"Is Phishing: {res.is_phishing}")
print(f"Action Item: {res.action_item}")
print(f"Indicators: {res.suspicious_indicators}")

Leave a Reply

Trending