File size: 1,043 Bytes
943768f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import ollama

def analyze_threat(summary):
    """Agent 2: Contextualizes the threat and writes the incident report."""
    prompt = f"""
    You are a strict, precise SOC Analyst. Read the log summary below and classify the threat.
    
    CRITICAL INSTRUCTIONS:
    - Output ONLY the Markdown format. Do not add any conversational text.
    - If the IP is missing or null, write "Local/Internal".
    - Risk Score MUST be a number between 1 and 10.

    EXAMPLE GOOD OUTPUT:
    ### Path Traversal (Risk Score: 8)
    **Attacker IP:** 192.168.1.50
    **Summary:** An external IP attempted to read the /etc/passwd file using directory traversal sequences.
    **Recommendation:** Sanitize user input and block URI paths containing '../'.
    
    Now, generate the report for the following log:
    Summary: {summary}
    """
    
    response = ollama.chat(
        model='qwen2:7b', 
        messages=[{'role': 'user', 'content': prompt}],
        options={'temperature': 0.1}
    )
    
    return response['message']['content'].strip()