iflow-mcp-m507_ai-soc-agent 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iflow_mcp_m507_ai_soc_agent-1.0.0.dist-info/METADATA +410 -0
- iflow_mcp_m507_ai_soc_agent-1.0.0.dist-info/RECORD +85 -0
- iflow_mcp_m507_ai_soc_agent-1.0.0.dist-info/WHEEL +5 -0
- iflow_mcp_m507_ai_soc_agent-1.0.0.dist-info/entry_points.txt +2 -0
- iflow_mcp_m507_ai_soc_agent-1.0.0.dist-info/licenses/LICENSE +21 -0
- iflow_mcp_m507_ai_soc_agent-1.0.0.dist-info/top_level.txt +1 -0
- src/__init__.py +8 -0
- src/ai_controller/README.md +139 -0
- src/ai_controller/__init__.py +12 -0
- src/ai_controller/agent_executor.py +596 -0
- src/ai_controller/cli/__init__.py +2 -0
- src/ai_controller/cli/main.py +243 -0
- src/ai_controller/session_manager.py +409 -0
- src/ai_controller/web/__init__.py +2 -0
- src/ai_controller/web/server.py +1181 -0
- src/ai_controller/web/static/css/README.md +102 -0
- src/api/__init__.py +13 -0
- src/api/case_management.py +271 -0
- src/api/edr.py +187 -0
- src/api/kb.py +136 -0
- src/api/siem.py +308 -0
- src/core/__init__.py +10 -0
- src/core/config.py +242 -0
- src/core/config_storage.py +684 -0
- src/core/dto.py +50 -0
- src/core/errors.py +36 -0
- src/core/logging.py +128 -0
- src/integrations/__init__.py +8 -0
- src/integrations/case_management/__init__.py +5 -0
- src/integrations/case_management/iris/__init__.py +11 -0
- src/integrations/case_management/iris/iris_client.py +885 -0
- src/integrations/case_management/iris/iris_http.py +274 -0
- src/integrations/case_management/iris/iris_mapper.py +263 -0
- src/integrations/case_management/iris/iris_models.py +128 -0
- src/integrations/case_management/thehive/__init__.py +8 -0
- src/integrations/case_management/thehive/thehive_client.py +193 -0
- src/integrations/case_management/thehive/thehive_http.py +147 -0
- src/integrations/case_management/thehive/thehive_mapper.py +190 -0
- src/integrations/case_management/thehive/thehive_models.py +125 -0
- src/integrations/cti/__init__.py +6 -0
- src/integrations/cti/local_tip/__init__.py +10 -0
- src/integrations/cti/local_tip/local_tip_client.py +90 -0
- src/integrations/cti/local_tip/local_tip_http.py +110 -0
- src/integrations/cti/opencti/__init__.py +10 -0
- src/integrations/cti/opencti/opencti_client.py +101 -0
- src/integrations/cti/opencti/opencti_http.py +418 -0
- src/integrations/edr/__init__.py +6 -0
- src/integrations/edr/elastic_defend/__init__.py +6 -0
- src/integrations/edr/elastic_defend/elastic_defend_client.py +351 -0
- src/integrations/edr/elastic_defend/elastic_defend_http.py +162 -0
- src/integrations/eng/__init__.py +10 -0
- src/integrations/eng/clickup/__init__.py +8 -0
- src/integrations/eng/clickup/clickup_client.py +513 -0
- src/integrations/eng/clickup/clickup_http.py +156 -0
- src/integrations/eng/github/__init__.py +8 -0
- src/integrations/eng/github/github_client.py +169 -0
- src/integrations/eng/github/github_http.py +158 -0
- src/integrations/eng/trello/__init__.py +8 -0
- src/integrations/eng/trello/trello_client.py +207 -0
- src/integrations/eng/trello/trello_http.py +162 -0
- src/integrations/kb/__init__.py +12 -0
- src/integrations/kb/fs_kb_client.py +313 -0
- src/integrations/siem/__init__.py +6 -0
- src/integrations/siem/elastic/__init__.py +6 -0
- src/integrations/siem/elastic/elastic_client.py +3319 -0
- src/integrations/siem/elastic/elastic_http.py +165 -0
- src/mcp/README.md +183 -0
- src/mcp/TOOLS.md +2827 -0
- src/mcp/__init__.py +13 -0
- src/mcp/__main__.py +18 -0
- src/mcp/agent_profiles.py +408 -0
- src/mcp/flow_agent_profiles.py +424 -0
- src/mcp/mcp_server.py +4086 -0
- src/mcp/rules_engine.py +487 -0
- src/mcp/runbook_manager.py +264 -0
- src/orchestrator/__init__.py +11 -0
- src/orchestrator/incident_workflow.py +244 -0
- src/orchestrator/tools_case.py +1085 -0
- src/orchestrator/tools_cti.py +359 -0
- src/orchestrator/tools_edr.py +315 -0
- src/orchestrator/tools_eng.py +378 -0
- src/orchestrator/tools_kb.py +156 -0
- src/orchestrator/tools_siem.py +1709 -0
- src/web/__init__.py +8 -0
- src/web/config_server.py +511 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Low-level HTTP client for Elasticsearch/Elastic SIEM.
|
|
3
|
+
|
|
4
|
+
This module is responsible for:
|
|
5
|
+
- authentication (API key or username/password)
|
|
6
|
+
- building URLs
|
|
7
|
+
- making HTTP requests
|
|
8
|
+
- basic error handling
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from typing import Any, Dict, Optional
|
|
16
|
+
|
|
17
|
+
import requests
|
|
18
|
+
|
|
19
|
+
from ....core.errors import IntegrationError
|
|
20
|
+
from ....core.logging import get_logger
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
logger = get_logger("sami.integrations.elastic.http")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class ElasticHttpClient:
|
|
28
|
+
"""
|
|
29
|
+
Simple HTTP client for Elasticsearch/Elastic SIEM API.
|
|
30
|
+
|
|
31
|
+
Supports both API key and username/password authentication.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
base_url: str
|
|
35
|
+
api_key: Optional[str] = None
|
|
36
|
+
username: Optional[str] = None
|
|
37
|
+
password: Optional[str] = None
|
|
38
|
+
timeout_seconds: int = 30
|
|
39
|
+
verify_ssl: bool = True
|
|
40
|
+
|
|
41
|
+
def _headers(self) -> Dict[str, str]:
|
|
42
|
+
"""Build request headers with authentication."""
|
|
43
|
+
headers = {
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
"Accept": "application/json",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if self.api_key:
|
|
49
|
+
# Elastic API key format: "ApiKey <base64-encoded-key>"
|
|
50
|
+
if not self.api_key.startswith("ApiKey "):
|
|
51
|
+
headers["Authorization"] = f"ApiKey {self.api_key}"
|
|
52
|
+
else:
|
|
53
|
+
headers["Authorization"] = self.api_key
|
|
54
|
+
elif self.username and self.password:
|
|
55
|
+
# Basic auth
|
|
56
|
+
import base64
|
|
57
|
+
credentials = base64.b64encode(f"{self.username}:{self.password}".encode()).decode()
|
|
58
|
+
headers["Authorization"] = f"Basic {credentials}"
|
|
59
|
+
|
|
60
|
+
return headers
|
|
61
|
+
|
|
62
|
+
def _build_url(self, endpoint: str) -> str:
|
|
63
|
+
"""
|
|
64
|
+
Build a full URL from a base URL and an endpoint.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
endpoint: API endpoint path (e.g., "/_search" or "_search")
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
Full URL string
|
|
71
|
+
"""
|
|
72
|
+
base = self.base_url.rstrip("/")
|
|
73
|
+
endpoint = endpoint.lstrip("/")
|
|
74
|
+
|
|
75
|
+
return f"{base}/{endpoint}"
|
|
76
|
+
|
|
77
|
+
def _handle_elastic_error(self, response: requests.Response) -> None:
|
|
78
|
+
"""
|
|
79
|
+
Raise IntegrationError if the response indicates an error.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
response: HTTP response object
|
|
83
|
+
|
|
84
|
+
Raises:
|
|
85
|
+
IntegrationError: If the response indicates an error
|
|
86
|
+
"""
|
|
87
|
+
if response.status_code < 400:
|
|
88
|
+
return
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
error_data = response.json()
|
|
92
|
+
error_type = error_data.get("error", {}).get("type", "Unknown")
|
|
93
|
+
error_reason = error_data.get("error", {}).get("reason", f"HTTP {response.status_code}")
|
|
94
|
+
full_message = f"{error_type}: {error_reason}"
|
|
95
|
+
except Exception:
|
|
96
|
+
full_message = f"HTTP {response.status_code}: {response.text[:200]}"
|
|
97
|
+
|
|
98
|
+
raise IntegrationError(f"Elastic API error: {full_message}")
|
|
99
|
+
|
|
100
|
+
def request(
|
|
101
|
+
self,
|
|
102
|
+
method: str,
|
|
103
|
+
endpoint: str,
|
|
104
|
+
json_data: Optional[Dict[str, Any]] = None,
|
|
105
|
+
params: Optional[Dict[str, Any]] = None,
|
|
106
|
+
) -> Dict[str, Any]:
|
|
107
|
+
"""
|
|
108
|
+
Make an HTTP request to Elasticsearch API.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
method: HTTP method (GET, POST, PUT, PATCH, DELETE)
|
|
112
|
+
endpoint: API endpoint path
|
|
113
|
+
json_data: JSON payload (for POST, PUT, PATCH)
|
|
114
|
+
params: Query parameters (for GET, etc.)
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
Response JSON as dictionary
|
|
118
|
+
|
|
119
|
+
Raises:
|
|
120
|
+
IntegrationError: If the request fails
|
|
121
|
+
"""
|
|
122
|
+
url = self._build_url(endpoint)
|
|
123
|
+
headers = self._headers()
|
|
124
|
+
|
|
125
|
+
try:
|
|
126
|
+
logger.debug(f"Elastic {method} {url}")
|
|
127
|
+
if params:
|
|
128
|
+
logger.debug(f" Query params: {params}")
|
|
129
|
+
if json_data:
|
|
130
|
+
logger.debug(f" JSON payload: {json.dumps(json_data)[:200]}...")
|
|
131
|
+
|
|
132
|
+
response = requests.request(
|
|
133
|
+
method=method,
|
|
134
|
+
url=url,
|
|
135
|
+
headers=headers,
|
|
136
|
+
json=json_data,
|
|
137
|
+
params=params,
|
|
138
|
+
timeout=self.timeout_seconds,
|
|
139
|
+
verify=self.verify_ssl,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
logger.debug(f"Elastic response status: {response.status_code}")
|
|
143
|
+
if response.status_code >= 400:
|
|
144
|
+
logger.error(f"Elastic API error - Status: {response.status_code}, URL: {url}, Response: {response.text[:500]}")
|
|
145
|
+
|
|
146
|
+
self._handle_elastic_error(response)
|
|
147
|
+
|
|
148
|
+
if response.status_code == 204: # No Content
|
|
149
|
+
return {}
|
|
150
|
+
|
|
151
|
+
return response.json()
|
|
152
|
+
|
|
153
|
+
except requests.exceptions.Timeout as e:
|
|
154
|
+
raise IntegrationError(f"Elastic API request timeout: {e}") from e
|
|
155
|
+
except requests.exceptions.RequestException as e:
|
|
156
|
+
raise IntegrationError(f"Elastic API request failed: {e}") from e
|
|
157
|
+
|
|
158
|
+
def get(self, endpoint: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
159
|
+
"""GET request."""
|
|
160
|
+
return self.request("GET", endpoint, params=params)
|
|
161
|
+
|
|
162
|
+
def post(self, endpoint: str, json_data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
163
|
+
"""POST request."""
|
|
164
|
+
return self.request("POST", endpoint, json_data=json_data)
|
|
165
|
+
|
src/mcp/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# SamiGPT MCP Server
|
|
2
|
+
|
|
3
|
+
This directory contains the Model Context Protocol (MCP) server implementation for SamiGPT, which exposes all investigation and response capabilities as tools that can be used by AI assistants and automation systems.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The MCP server enables integration with various LLM clients including:
|
|
8
|
+
- **Cursor IDE** - AI-powered code editor
|
|
9
|
+
- **Claude Desktop** - Anthropic's Claude AI assistant
|
|
10
|
+
- **Open WebUI** - Web-based LLM interface
|
|
11
|
+
- **Cline** - VS Code extension for AI assistance
|
|
12
|
+
- Any MCP-compatible client
|
|
13
|
+
|
|
14
|
+
## Files
|
|
15
|
+
|
|
16
|
+
- **`mcp_server.py`**: Main MCP server implementation
|
|
17
|
+
- Implements JSON-RPC 2.0 over stdio
|
|
18
|
+
- Handles tool registration and execution
|
|
19
|
+
- Manages client connections and protocol negotiation
|
|
20
|
+
|
|
21
|
+
- **`rules_engine.py`**: Rules/workflow engine
|
|
22
|
+
- Executes automated investigation workflows
|
|
23
|
+
- Chains together multiple investigation skills
|
|
24
|
+
- Supports custom rule definitions
|
|
25
|
+
|
|
26
|
+
- **`TOOLS.md`**: Comprehensive tool documentation
|
|
27
|
+
- Detailed documentation for all available tools
|
|
28
|
+
- Usage examples and best practices
|
|
29
|
+
- Parameter descriptions and return values
|
|
30
|
+
|
|
31
|
+
## Available Tools
|
|
32
|
+
|
|
33
|
+
### Case Management Tools (8 tools)
|
|
34
|
+
Tools for managing security incidents and cases:
|
|
35
|
+
- `review_case` - Get complete case details
|
|
36
|
+
- `list_cases` - List cases with optional filters
|
|
37
|
+
- `search_cases` - Advanced case search
|
|
38
|
+
- `add_case_comment` - Add notes to cases
|
|
39
|
+
- `attach_observable_to_case` - Track IOCs
|
|
40
|
+
- `update_case_status` - Update case workflow
|
|
41
|
+
- `assign_case` - Assign to analysts
|
|
42
|
+
- `get_case_timeline` - View case history
|
|
43
|
+
|
|
44
|
+
### SIEM Tools (7 tools)
|
|
45
|
+
Tools for security event analysis:
|
|
46
|
+
- `search_security_events` - Query security logs
|
|
47
|
+
- `get_file_report` - Analyze files by hash
|
|
48
|
+
- `get_file_behavior_summary` - File behavior analysis
|
|
49
|
+
- `get_entities_related_to_file` - Find related entities
|
|
50
|
+
- `get_ip_address_report` - IP reputation and context
|
|
51
|
+
- `search_user_activity` - User activity investigation
|
|
52
|
+
- `pivot_on_indicator` - IOC-based investigation
|
|
53
|
+
|
|
54
|
+
### EDR Tools (6 tools)
|
|
55
|
+
Tools for endpoint investigation and response:
|
|
56
|
+
- `get_endpoint_summary` - Endpoint overview
|
|
57
|
+
- `get_detection_details` - Detection analysis
|
|
58
|
+
- `isolate_endpoint` - Network isolation (critical)
|
|
59
|
+
- `release_endpoint_isolation` - Restore connectivity
|
|
60
|
+
- `kill_process_on_endpoint` - Terminate processes (disruptive)
|
|
61
|
+
- `collect_forensic_artifacts` - Evidence collection
|
|
62
|
+
|
|
63
|
+
### Rules Engine Tools (2 tools)
|
|
64
|
+
Tools for automated workflows:
|
|
65
|
+
- `list_rules` - List available workflows
|
|
66
|
+
- `execute_rule` - Run automated playbooks
|
|
67
|
+
|
|
68
|
+
## Quick Start
|
|
69
|
+
|
|
70
|
+
### Running the Server
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
python -m src.mcp.mcp_server
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The server communicates via stdio using JSON-RPC 2.0 protocol.
|
|
77
|
+
|
|
78
|
+
### Configuration
|
|
79
|
+
|
|
80
|
+
The server automatically loads configuration from `config.json` in the project root. Configure integrations using the web configuration UI:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
python -m src.web.config_server
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Tool Usage
|
|
87
|
+
|
|
88
|
+
All tools are documented in **[TOOLS.md](TOOLS.md)** with:
|
|
89
|
+
- Detailed parameter descriptions
|
|
90
|
+
- Return value specifications
|
|
91
|
+
- Usage examples
|
|
92
|
+
- Best practices
|
|
93
|
+
- Workflow examples
|
|
94
|
+
|
|
95
|
+
## Protocol Support
|
|
96
|
+
|
|
97
|
+
The server supports MCP protocol versions:
|
|
98
|
+
- `2024-11-05` (default)
|
|
99
|
+
- `2025-06-18` (auto-negotiated with compatible clients)
|
|
100
|
+
|
|
101
|
+
## Logging
|
|
102
|
+
|
|
103
|
+
MCP-specific logs are written to `logs/mcp/`:
|
|
104
|
+
- `mcp_all.log` - All MCP activity (DEBUG level)
|
|
105
|
+
- `mcp_requests.log` - Incoming requests
|
|
106
|
+
- `mcp_responses.log` - Outgoing responses
|
|
107
|
+
- `mcp_errors.log` - Errors only
|
|
108
|
+
|
|
109
|
+
## Integration Examples
|
|
110
|
+
|
|
111
|
+
### Cursor IDE
|
|
112
|
+
|
|
113
|
+
See [CURSOR_INTEGRATION.md](../../CURSOR_INTEGRATION.md) for setup instructions.
|
|
114
|
+
|
|
115
|
+
### Claude Desktop
|
|
116
|
+
|
|
117
|
+
Add to `claude_desktop_config.json`:
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"mcpServers": {
|
|
121
|
+
"sami-gpt": {
|
|
122
|
+
"command": "python",
|
|
123
|
+
"args": ["-m", "src.mcp.mcp_server"],
|
|
124
|
+
"cwd": "/path/to/SamiGPT"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Open WebUI
|
|
131
|
+
|
|
132
|
+
Configure via environment variables or UI settings.
|
|
133
|
+
|
|
134
|
+
## Tool Availability
|
|
135
|
+
|
|
136
|
+
Tools are conditionally available based on configured integrations:
|
|
137
|
+
|
|
138
|
+
- **Case Management Tools**: Require TheHive or IRIS configuration
|
|
139
|
+
- **SIEM Tools**: Require Elastic or other SIEM configuration
|
|
140
|
+
- **EDR Tools**: Require EDR platform configuration
|
|
141
|
+
- **Rules Engine Tools**: Always available
|
|
142
|
+
|
|
143
|
+
Use `list_rules` to discover available automated workflows.
|
|
144
|
+
|
|
145
|
+
## Security Considerations
|
|
146
|
+
|
|
147
|
+
⚠️ **Critical Actions**: Some tools perform disruptive operations:
|
|
148
|
+
- `isolate_endpoint` - Disconnects endpoint from network
|
|
149
|
+
- `kill_process_on_endpoint` - Terminates running processes
|
|
150
|
+
|
|
151
|
+
Always verify parameters before executing critical actions. These operations are logged at WARNING level.
|
|
152
|
+
|
|
153
|
+
## Development
|
|
154
|
+
|
|
155
|
+
### Adding New Tools
|
|
156
|
+
|
|
157
|
+
1. Implement the tool function in the appropriate `tools_*.py` module
|
|
158
|
+
2. Register the tool in `mcp_server.py` using `_register_*_tools()` methods
|
|
159
|
+
3. Add comprehensive documentation to `TOOLS.md`
|
|
160
|
+
4. Update this README if adding a new tool category
|
|
161
|
+
|
|
162
|
+
### Testing
|
|
163
|
+
|
|
164
|
+
Test the MCP server manually:
|
|
165
|
+
```bash
|
|
166
|
+
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | python -m src.mcp.mcp_server
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Documentation
|
|
170
|
+
|
|
171
|
+
- **[TOOLS.md](TOOLS.md)** - Complete tool documentation
|
|
172
|
+
- **[../CURSOR_INTEGRATION.md](../CURSOR_INTEGRATION.md)** - Cursor setup guide
|
|
173
|
+
- **[../MCP_CLIENT_EXAMPLES.md](../MCP_CLIENT_EXAMPLES.md)** - Client configuration examples
|
|
174
|
+
- **[../README.md](../README.md)** - Main project documentation
|
|
175
|
+
|
|
176
|
+
## Support
|
|
177
|
+
|
|
178
|
+
For issues or questions:
|
|
179
|
+
1. Check the logs in `logs/mcp/`
|
|
180
|
+
2. Review tool documentation in `TOOLS.md`
|
|
181
|
+
3. Verify configuration in `config.json`
|
|
182
|
+
4. Check integration-specific documentation
|
|
183
|
+
|