Document machine-readable output fields for scripting (to_json, to_ioc_format, suspicious_connections, iocs)
Browse files- API_REFERENCE.md +129 -0
API_REFERENCE.md
CHANGED
|
@@ -306,6 +306,73 @@ Dataclass containing analysis results.
|
|
| 306 |
| `service_type` | str | Detected service type |
|
| 307 |
| `recommendations` | List[str] | Suggested follow-up actions |
|
| 308 |
| `features` | List[float] | Raw 40-dimensional feature vector |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
### Methods
|
| 311 |
|
|
@@ -321,6 +388,68 @@ Convert result to dictionary.
|
|
| 321 |
|
| 322 |
---
|
| 323 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
## ConnectionContext Class
|
| 325 |
|
| 326 |
Dataclass for providing additional context to improve detection accuracy.
|
|
|
|
| 306 |
| `service_type` | str | Detected service type |
|
| 307 |
| `recommendations` | List[str] | Suggested follow-up actions |
|
| 308 |
| `features` | List[float] | Raw 40-dimensional feature vector |
|
| 309 |
+
| `connections_analyzed` | int | Number of connections processed |
|
| 310 |
+
| `suspicious_connections` | List[Dict] | All connections with individual scores (if C2 detected) |
|
| 311 |
+
| `iocs` | Dict | Extracted IOCs for threat intel (if C2 detected) |
|
| 312 |
+
| `time_range` | Dict | Start, end, and duration of analyzed traffic |
|
| 313 |
+
| `destination_summary` | Dict | Destination IPs, ports, and byte totals |
|
| 314 |
+
|
| 315 |
+
### Machine-Readable Output Fields
|
| 316 |
+
|
| 317 |
+
When C2 is detected, these fields are populated for scripting and automation:
|
| 318 |
+
|
| 319 |
+
**suspicious_connections** - List of all connections with scores:
|
| 320 |
+
```python
|
| 321 |
+
[
|
| 322 |
+
{
|
| 323 |
+
'index': 0,
|
| 324 |
+
'timestamp': 1705600000,
|
| 325 |
+
'src_ip': '192.168.1.100',
|
| 326 |
+
'src_port': 52341,
|
| 327 |
+
'dst_ip': '45.33.32.156',
|
| 328 |
+
'dst_port': 443,
|
| 329 |
+
'bytes_sent': 200,
|
| 330 |
+
'bytes_recv': 500,
|
| 331 |
+
'score': 0.92
|
| 332 |
+
},
|
| 333 |
+
...
|
| 334 |
+
]
|
| 335 |
+
```
|
| 336 |
+
|
| 337 |
+
**iocs** - Indicators of Compromise for threat intel:
|
| 338 |
+
```python
|
| 339 |
+
{
|
| 340 |
+
'ip_addresses': ['45.33.32.156'],
|
| 341 |
+
'ports': [443],
|
| 342 |
+
'c2_type': 'cobalt_strike',
|
| 343 |
+
'timing_signature': {
|
| 344 |
+
'mean_interval': 60.0,
|
| 345 |
+
'interval_cv': 0.05
|
| 346 |
+
},
|
| 347 |
+
'size_signature': {
|
| 348 |
+
'mean_bytes_sent': 200.0,
|
| 349 |
+
'mean_bytes_recv': 500.0,
|
| 350 |
+
'sent_cv': 0.02,
|
| 351 |
+
'recv_cv': 0.03
|
| 352 |
+
},
|
| 353 |
+
'behavioral_indicators': ['Regular timing with consistent sizes', ...]
|
| 354 |
+
}
|
| 355 |
+
```
|
| 356 |
+
|
| 357 |
+
**time_range** - Temporal bounds of analyzed traffic:
|
| 358 |
+
```python
|
| 359 |
+
{
|
| 360 |
+
'start': 1705600000.0,
|
| 361 |
+
'end': 1705600420.0,
|
| 362 |
+
'duration': 420.0
|
| 363 |
+
}
|
| 364 |
+
```
|
| 365 |
+
|
| 366 |
+
**destination_summary** - Traffic summary:
|
| 367 |
+
```python
|
| 368 |
+
{
|
| 369 |
+
'unique_ips': ['45.33.32.156'],
|
| 370 |
+
'unique_ports': [443],
|
| 371 |
+
'destinations': {'45.33.32.156:443': 8},
|
| 372 |
+
'total_bytes_sent': 1600,
|
| 373 |
+
'total_bytes_recv': 4000
|
| 374 |
+
}
|
| 375 |
+
```
|
| 376 |
|
| 377 |
### Methods
|
| 378 |
|
|
|
|
| 388 |
|
| 389 |
---
|
| 390 |
|
| 391 |
+
#### to_json
|
| 392 |
+
|
| 393 |
+
```python
|
| 394 |
+
def to_json(self, indent: int = 2) -> str
|
| 395 |
+
```
|
| 396 |
+
|
| 397 |
+
Convert result to JSON string for scripting.
|
| 398 |
+
|
| 399 |
+
| Parameter | Type | Default | Description |
|
| 400 |
+
|-----------|------|---------|-------------|
|
| 401 |
+
| `indent` | int | 2 | JSON indentation level |
|
| 402 |
+
|
| 403 |
+
**Returns:** JSON string of all attributes
|
| 404 |
+
|
| 405 |
+
**Example:**
|
| 406 |
+
```python
|
| 407 |
+
result = sentinel.analyze(connections)
|
| 408 |
+
json_output = result.to_json()
|
| 409 |
+
|
| 410 |
+
# Write to file
|
| 411 |
+
with open('detection_result.json', 'w') as f:
|
| 412 |
+
f.write(result.to_json())
|
| 413 |
+
|
| 414 |
+
# Parse in pipeline
|
| 415 |
+
import json
|
| 416 |
+
data = json.loads(result.to_json())
|
| 417 |
+
```
|
| 418 |
+
|
| 419 |
+
---
|
| 420 |
+
|
| 421 |
+
#### to_ioc_format
|
| 422 |
+
|
| 423 |
+
```python
|
| 424 |
+
def to_ioc_format(self) -> Dict[str, Any]
|
| 425 |
+
```
|
| 426 |
+
|
| 427 |
+
Convert result to STIX-like format for threat intelligence platforms.
|
| 428 |
+
|
| 429 |
+
**Returns:**
|
| 430 |
+
```python
|
| 431 |
+
{
|
| 432 |
+
'type': 'indicator',
|
| 433 |
+
'spec_version': '2.1',
|
| 434 |
+
'pattern_type': 'c2-beacon',
|
| 435 |
+
'valid_from': timestamp,
|
| 436 |
+
'labels': ['malicious-activity', 'c2'],
|
| 437 |
+
'confidence': 92,
|
| 438 |
+
'indicators': { ... } # Same as iocs field
|
| 439 |
+
}
|
| 440 |
+
```
|
| 441 |
+
|
| 442 |
+
**Example:**
|
| 443 |
+
```python
|
| 444 |
+
result = sentinel.analyze(connections)
|
| 445 |
+
if result.is_c2:
|
| 446 |
+
stix_indicator = result.to_ioc_format()
|
| 447 |
+
# Send to threat intel platform
|
| 448 |
+
send_to_misp(stix_indicator)
|
| 449 |
+
```
|
| 450 |
+
|
| 451 |
+
---
|
| 452 |
+
|
| 453 |
## ConnectionContext Class
|
| 454 |
|
| 455 |
Dataclass for providing additional context to improve detection accuracy.
|