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
|
def collect_evidence(employee_upn, siem_client, lookback_days=30):
"""
Pull behavioural data from multiple sources for the investigation window.
Evidence is collected passively — no action taken at this stage.
"""
evidence = {}
# DLP events — mass download, USB transfers, personal email forwarding
evidence['dlp_events'] = siem_client.search(f"""
index=dlp user="{employee_upn}"
| stats count by policy_name, action, dest_type
| sort -count
""", days_back=lookback_days)
# File server access — unusual shares or bulk operations
evidence['file_access'] = siem_client.search(f"""
index=wineventlog EventCode IN (4663, 4656)
SubjectUserName="{employee_upn.split('@')[0]}"
| stats count, dc(ObjectName) as unique_files by ShareName
| where unique_files > 50
| sort -count
""", days_back=lookback_days)
# Email audit — large attachments sent outbound
evidence['email_anomalies'] = siem_client.search(f"""
index=email_audit sender="{employee_upn}"
| where attachment_size_mb > 5
| where NOT (recipient_domain IN ("company.ae", "company.com"))
| table _time, recipient, subject, attachment_size_mb
""", days_back=lookback_days)
# AD — privilege changes, group additions
evidence['ad_changes'] = siem_client.search(f"""
index=wineventlog EventCode IN (4728, 4732, 4756)
MemberName="*{employee_upn.split('@')[0]}*"
| table _time, EventCode, GroupName, SubjectUserName
""", days_back=lookback_days)
# After-hours access
evidence['after_hours'] = siem_client.search(f"""
index=vpn OR index=identity user="{employee_upn}"
| eval hour=strftime(_time, "%H")
| where hour < 6 OR hour > 22
| stats count by date_mday, hour, src_ip
""", days_back=lookback_days)
return evidence
|