File size: 8,663 Bytes
a54cecb 1ee971d a54cecb 1ee971d 3751c05 1ee971d e3e3b6b 1ee971d 3751c05 1ee971d 3751c05 1ee971d 4ad28eb 1ee971d 3751c05 1ee971d 3751c05 1ee971d 3751c05 1ee971d |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
---
license: mit
language:
- en
library_name: pytorch
tags:
- security
- cybersecurity
- network-security
- c2-detection
- beacon-detection
- threat-detection
- malware-detection
- logbert
- transformer
- safetensors
pipeline_tag: other
---
# C2Sentinel
[](https://huggingface.co/danielostrow/c2sentinel)
[](https://opensource.org/licenses/MIT)
[](https://huggingface.co/spaces/danielostrow/c2sentinel)
A machine learning model for detecting Command and Control (C2) beacon communications in network traffic. Built on a fine-tuned [LogBERT](https://arxiv.org/abs/2103.04475) transformer architecture.
**Author:** Daniel Ostrow
**Website:** [neuralintellect.com](https://neuralintellect.com)
**Release Date:** January 18, 2026
---
## Base Model
This model is fine-tuned from the LogBERT architecture for log anomaly detection.
- **Paper:** [LogBERT: Log Anomaly Detection via BERT](https://arxiv.org/abs/2103.04475) (Guo, Yuan, Wu - IJCNN 2021)
- **Original Implementation:** [github.com/HelenGuohx/logbert](https://github.com/HelenGuohx/logbert)
---
## Overview
C2Sentinel analyzes network connection patterns to identify C2 beacon activity. The model uses behavioral analysis rather than port-based filtering, enabling detection of C2 communications on any port. This approach catches C2 activity regardless of whether attackers use expected ports (4444) or attempt to blend in on common ports (443, 80, 53).
### Capabilities
- Detection of 34+ C2 framework behavioral patterns across all ports
- Slow beacon detection (intervals from seconds to hours)
- Legitimate traffic pattern recognition (SSH keepalive, health checks, database connections)
- Optional context enrichment (process information, reputation scores, threat intelligence)
- IP reconnaissance and IOC generation
- Safetensors format for secure model loading
---
## Installation
```bash
pip install torch numpy safetensors huggingface_hub
```
---
## Usage
### Loading from HuggingFace Hub
```python
from c2sentinel import C2Sentinel
sentinel = C2Sentinel.from_pretrained('danielostrow/c2sentinel')
```
### Loading from Local Files
```python
from c2sentinel import C2Sentinel
sentinel = C2Sentinel.load('c2_sentinel')
```
### Analyzing Connections
```python
connections = [
{
'timestamp': 1000000,
'dst_ip': '10.0.0.1',
'dst_port': 443,
'bytes_sent': 200,
'bytes_recv': 500
},
{
'timestamp': 1000060,
'dst_ip': '10.0.0.1',
'dst_port': 443,
'bytes_sent': 200,
'bytes_recv': 500
},
]
result = sentinel.analyze(connections)
if result.is_c2:
print(f"C2 detected: {result.c2_type}")
print(f"Probability: {result.c2_probability}")
else:
print("No C2 detected")
```
---
## Connection Record Format
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `timestamp` | float | Yes | Unix timestamp |
| `dst_ip` | str | Yes | Destination IP address |
| `dst_port` | int | Yes | Destination port |
| `bytes_sent` | int | Yes | Bytes sent |
| `bytes_recv` | int | Yes | Bytes received |
| `src_ip` | str | No | Source IP address |
| `src_port` | int | No | Source port |
| `protocol` | str | No | Protocol (tcp/udp) |
| `duration` | float | No | Connection duration in seconds |
---
## Analysis Options
### Threshold
```python
# Default threshold (0.5)
result = sentinel.analyze(connections)
# Lower threshold for higher sensitivity
result = sentinel.analyze(connections, threshold=0.3)
# Higher threshold for higher precision
result = sentinel.analyze(connections, threshold=0.7)
# Strict mode enforces minimum 0.7 threshold
result = sentinel.analyze(connections, strict_mode=True)
```
### Context
```python
from c2sentinel import ConnectionContext
context = ConnectionContext(
process_name='sshd',
known_good=True,
ip_reputation=0.95,
dns_queries=['api.example.com']
)
result = sentinel.analyze(connections, context=context)
```
### Whitelist and Blacklist
```python
sentinel.add_whitelist(ips=['8.8.8.8'], domains=['google.com'])
sentinel.add_blacklist(ips=['10.10.10.10'], domains=['malware.example'])
```
---
## Result Object
The `AnalysisResult` object contains:
| Attribute | Type | Description |
|-----------|------|-------------|
| `is_c2` | bool | True if C2 detected |
| `c2_probability` | float | Probability score (0.0-1.0) |
| `c2_type` | str | Detected C2 framework type |
| `confidence` | float | Model confidence |
| `detection_method` | str | Method used (signature/ml/context/whitelist) |
| `immediate_detection` | bool | True if signature-based |
| `risk_factors` | list | Factors supporting C2 classification |
| `mitigating_factors` | list | Factors against C2 classification |
| `matched_legitimate_pattern` | str | Matched legitimate pattern name |
| `service_type` | str | Detected service type |
| `recommendations` | list | Suggested actions |
---
## Batch Analysis
```python
connection_groups = [
[conn1, conn2, conn3],
[conn4, conn5, conn6],
]
results = sentinel.analyze_batch(connection_groups)
```
---
## Log File Parsing
```python
with open('conn.log', 'r') as f:
log_lines = f.readlines()
results = sentinel.analyze_logs(log_lines, group_by_dst=True)
```
Supported formats: JSON, Zeek conn.log, syslog
---
## Reconnaissance
### IP Analysis
```python
info = sentinel.recon.analyze_ip('104.16.132.229')
# Returns: is_valid, is_private, is_cdn, cdn_provider, reverse_dns
```
### Pattern Analysis
```python
patterns = sentinel.recon.analyze_connection_patterns(connections)
# Returns: timing stats, volume stats, behavioral indicators
```
### IOC Generation
```python
if result.is_c2:
iocs = sentinel.recon.generate_iocs(connections, result.to_dict())
# Returns: ips, ports, timing_signatures, behavioral_indicators
```
---
## Detection Methodology
### C2 Indicators
- Consistent beacon intervals (low timing variance)
- Consistent packet sizes (low size variance)
- Single persistent destination
- Balanced request/response ratio
### Signature Detection
Immediate detection for high-confidence C2 ports with matching behavioral patterns:
- Port 4444 (Metasploit default)
- Port 5555 (Metasploit alternative)
- Port 31337 (Sliver)
- Port 40056 (Havoc)
### Legitimate Traffic Indicators
- High response size variance
- Asymmetric traffic patterns (small requests, large responses)
- Multiple destinations
- SSH keepalive patterns (small symmetric packets on port 22)
- Health check patterns (regular intervals, variable response sizes)
---
## Model Specifications
| Specification | Value |
|---------------|-------|
| Architecture | LogBERT Transformer |
| Parameters | 4.9 million |
| Feature Dimensions | 40 |
| Encoder Layers | 6 |
| Attention Heads | 8 |
| Hidden Dimension | 256 |
| Format | Safetensors |
| Size | 20 MB |
---
## Repository Contents
| File | Description |
|------|-------------|
| `c2sentinel.py` | Main module with model and analysis code |
| `c2_sentinel.safetensors` | Trained model weights |
| `c2_sentinel.json` | Model configuration |
| `normalization_params.npz` | Feature normalization parameters |
| `API_REFERENCE.md` | Complete API documentation for scripting |
| `LICENSE` | MIT License |
---
## License
MIT License
Copyright (c) 2026 Daniel Ostrow
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|