danielostrow commited on
Commit
22db0ff
·
verified ·
1 Parent(s): 9638fcb

Remove examples folder

Browse files
Files changed (1) hide show
  1. examples/basic_usage.py +0 -105
examples/basic_usage.py DELETED
@@ -1,105 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- C2Sentinel Basic Usage Example
4
-
5
- Demonstrates loading the model and analyzing network connections
6
- for C2 beacon detection.
7
- """
8
-
9
- from c2sentinel import C2Sentinel
10
-
11
- def main():
12
- # Load the model
13
- sentinel = C2Sentinel.load('c2_sentinel')
14
-
15
- # Example 1: Analyze a series of connections to a single destination
16
- # This pattern shows regular 60-second intervals with consistent packet sizes
17
- # - a common C2 beacon signature
18
-
19
- connections = []
20
- timestamp = 1705600000 # Starting timestamp
21
-
22
- for i in range(10):
23
- connections.append({
24
- 'timestamp': timestamp + (i * 60), # 60-second intervals
25
- 'dst_ip': '10.0.0.100',
26
- 'dst_port': 443,
27
- 'bytes_sent': 200,
28
- 'bytes_recv': 500,
29
- })
30
-
31
- result = sentinel.analyze(connections)
32
-
33
- print("Example 1: Regular beacon pattern")
34
- print(f" Is C2: {result.is_c2}")
35
- print(f" Probability: {result.c2_probability:.2f}")
36
- print(f" C2 Type: {result.c2_type}")
37
- print(f" Detection Method: {result.detection_method}")
38
- print()
39
-
40
- # Example 2: Legitimate SSH keepalive traffic
41
- # Small symmetric packets on port 22 at regular intervals
42
-
43
- ssh_connections = []
44
- timestamp = 1705600000
45
-
46
- for i in range(10):
47
- ssh_connections.append({
48
- 'timestamp': timestamp + (i * 30), # 30-second keepalive
49
- 'dst_ip': '192.168.1.50',
50
- 'dst_port': 22,
51
- 'bytes_sent': 48,
52
- 'bytes_recv': 48,
53
- })
54
-
55
- result = sentinel.analyze(ssh_connections)
56
-
57
- print("Example 2: SSH keepalive pattern")
58
- print(f" Is C2: {result.is_c2}")
59
- print(f" Matched Pattern: {result.matched_legitimate_pattern}")
60
- print(f" Service Type: {result.service_type}")
61
- print()
62
-
63
- # Example 3: High-confidence C2 on known malicious port
64
-
65
- c2_connections = []
66
- timestamp = 1705600000
67
-
68
- for i in range(10):
69
- c2_connections.append({
70
- 'timestamp': timestamp + (i * 30),
71
- 'dst_ip': '45.33.32.156',
72
- 'dst_port': 4444, # Metasploit default
73
- 'bytes_sent': 150,
74
- 'bytes_recv': 300,
75
- })
76
-
77
- result = sentinel.analyze(c2_connections)
78
-
79
- print("Example 3: High-confidence C2 port")
80
- print(f" Is C2: {result.is_c2}")
81
- print(f" C2 Type: {result.c2_type}")
82
- print(f" Probability: {result.c2_probability:.2f}")
83
- print(f" Immediate Detection: {result.immediate_detection}")
84
- print(f" Risk Factors: {result.risk_factors}")
85
- print()
86
-
87
- # Example 4: Using threshold adjustment
88
-
89
- print("Example 4: Threshold adjustment")
90
-
91
- # Lower threshold for higher sensitivity
92
- result_low = sentinel.analyze(connections, threshold=0.3)
93
- print(f" Low threshold (0.3): is_c2={result_low.is_c2}, prob={result_low.c2_probability:.2f}")
94
-
95
- # Higher threshold for higher precision
96
- result_high = sentinel.analyze(connections, threshold=0.7)
97
- print(f" High threshold (0.7): is_c2={result_high.is_c2}, prob={result_high.c2_probability:.2f}")
98
-
99
- # Strict mode (minimum 0.7 threshold)
100
- result_strict = sentinel.analyze(connections, strict_mode=True)
101
- print(f" Strict mode: is_c2={result_strict.is_c2}, prob={result_strict.c2_probability:.2f}")
102
-
103
-
104
- if __name__ == '__main__':
105
- main()