princemaxp commited on
Commit
1b03224
·
verified ·
1 Parent(s): 830c0e2

Update behavioral_analyzer.py

Browse files
Files changed (1) hide show
  1. behavioral_analyzer.py +43 -193
behavioral_analyzer.py CHANGED
@@ -1,197 +1,47 @@
1
-
2
- from typing import Dict, List, Tuple
3
-
4
-
5
- # =========================
6
- # BEHAVIORAL PATTERN SETS
7
- # =========================
8
-
9
- BEHAVIOR_PATTERNS = {
10
- "sextortion": {
11
- "device_compromise": [
12
- "i have full access",
13
- "total access to your devices",
14
- "installed a trojan",
15
- "infected your device",
16
- "remote access",
17
- "spyware",
18
- ],
19
- "surveillance": [
20
- "i am watching you",
21
- "i monitor",
22
- "recorded you",
23
- "captured video",
24
- "webcam",
25
- "microphone",
26
- ],
27
- "sexual_blackmail": [
28
- "porn",
29
- "masturbation",
30
- "adult content",
31
- "sexual video",
32
- "explicit video",
33
- "nasty videos",
34
- ],
35
- "payment_demand": [
36
- "bitcoin",
37
- "btc",
38
- "crypto",
39
- "wallet",
40
- "send money",
41
- "payment",
42
- ],
43
- "time_pressure": [
44
- "48 hours",
45
- "24 hours",
46
- "countdown",
47
- "time is running out",
48
- "last chance",
49
- ],
50
- },
51
-
52
- "phishing": {
53
- "credential_theft": [
54
- "verify your account",
55
- "login immediately",
56
- "confirm your password",
57
- "update your account",
58
- ],
59
- "impersonation": [
60
- "security team",
61
- "support team",
62
- "admin",
63
- "it department",
64
- ],
65
- "urgency": [
66
- "urgent",
67
- "immediately",
68
- "action required",
69
- "account suspended",
70
- ],
71
- },
72
-
73
- "bec": {
74
- "financial_request": [
75
- "wire transfer",
76
- "bank details",
77
- "invoice attached",
78
- "payment request",
79
- ],
80
- "authority_pressure": [
81
- "ceo",
82
- "director",
83
- "urgent request",
84
- "confidential",
85
- ],
86
- }
87
- }
88
-
89
-
90
- # =========================
91
- # SCORING WEIGHTS
92
- # =========================
93
-
94
- BEHAVIOR_WEIGHTS = {
95
- "sextortion": {
96
- "device_compromise": 25,
97
- "surveillance": 20,
98
- "sexual_blackmail": 30,
99
- "payment_demand": 20,
100
- "time_pressure": 15,
101
- },
102
- "phishing": {
103
- "credential_theft": 30,
104
- "impersonation": 20,
105
- "urgency": 20,
106
- },
107
- "bec": {
108
- "financial_request": 35,
109
- "authority_pressure": 25,
110
- }
111
- }
112
-
113
-
114
- # =========================
115
- # MAIN ANALYZER
116
- # =========================
117
-
118
- def analyze_behavior(body: str) -> Dict:
119
- """
120
- Analyze email body for behavioral attack patterns.
121
- Returns detailed signals, scores, and verdict.
122
- """
123
-
124
- body_l = body.lower()
125
-
126
- findings = {}
127
- scores = {}
128
- matched_indicators = {}
129
-
130
- for attack_type, categories in BEHAVIOR_PATTERNS.items():
131
- findings[attack_type] = {}
132
- matched_indicators[attack_type] = []
133
-
134
- for category, patterns in categories.items():
135
- matched = any(p in body_l for p in patterns)
136
- findings[attack_type][category] = matched
137
-
138
- if matched:
139
- matched_indicators[attack_type].append(category)
140
-
141
- # Score calculation
142
- score = 0
143
- for category, matched in findings[attack_type].items():
144
- if matched:
145
- score += BEHAVIOR_WEIGHTS.get(attack_type, {}).get(category, 0)
146
-
147
- scores[attack_type] = min(score, 100)
148
-
149
- # Determine dominant attack
150
- dominant_attack = max(scores, key=scores.get)
151
- dominant_score = scores[dominant_attack]
152
-
153
- verdict = "Safe"
154
- if dominant_score >= 60:
155
- verdict = "Malicious"
156
 
157
  return {
158
- "verdict": verdict,
159
- "dominant_attack": dominant_attack if dominant_score >= 40 else "None",
160
- "confidence_score": dominant_score,
161
- "scores": scores,
162
- "signals": findings,
163
- "matched_indicators": matched_indicators,
164
  }
165
 
166
-
167
- # =========================
168
- # HUMAN-READABLE SUMMARY
169
- # =========================
170
-
171
- def behavioral_summary(result: Dict) -> str:
172
- if result["verdict"] == "Safe":
173
- return "No strong malicious behavioral patterns detected."
174
-
175
- attack = result["dominant_attack"]
176
- indicators = result["matched_indicators"].get(attack, [])
177
-
178
- return (
179
- f"Behavioral analysis strongly indicates **{attack.upper()}**.\n"
180
- f"Detected indicators: {', '.join(indicators)}.\n"
181
- f"Confidence Score: {result['confidence_score']}/100"
182
- )
183
-
184
-
185
- # =========================
186
- # STANDALONE TEST (OPTIONAL)
187
- # =========================
188
-
189
- if __name__ == "__main__":
190
- sample_text = """
191
- I have full access to your devices and recorded you via webcam.
192
- You must send bitcoin within 48 hours or the videos will be shared.
193
- """
194
-
195
- result = analyze_behavior(sample_text)
196
- print(result)
197
- print(behavioral_summary(result))
 
1
+ # behavioral_analyzer.py
2
+
3
+ import re
4
+
5
+ SEXTORTION_PATTERNS = [
6
+ "i have access to all your devices",
7
+ "i recorded you",
8
+ "i installed a trojan",
9
+ "i have your webcam",
10
+ "masturbation",
11
+ "adult websites",
12
+ "send bitcoin",
13
+ "btc",
14
+ "wallet address",
15
+ "48 hours",
16
+ "countdown",
17
+ "i will share the video",
18
+ "i will expose",
19
+ ]
20
+
21
+ def analyze_behavior(body: str):
22
+ body_l = (body or "").lower()
23
+
24
+ matched = [p for p in SEXTORTION_PATTERNS if p in body_l]
25
+
26
+ if len(matched) >= 3:
27
+ return {
28
+ "dominant_attack": "sextortion",
29
+ "confidence_score": 90, # 🔥 authoritative
30
+ "verdict": "🚨 Malicious",
31
+ "findings": matched,
32
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  return {
35
+ "dominant_attack": "None",
36
+ "confidence_score": 0,
37
+ "verdict": "Unknown",
38
+ "findings": [],
 
 
39
  }
40
 
41
+ def behavioral_summary(result: dict) -> str:
42
+ if result["dominant_attack"] == "sextortion":
43
+ return (
44
+ "Email exhibits sextortion behavior: claims of device compromise, "
45
+ "recorded explicit content, cryptocurrency extortion, and urgency."
46
+ )
47
+ return "No strong behavioral threat detected."