diff --git a/deploy/mariadb/init/001-schema.sql b/deploy/mariadb/init/001-schema.sql index 2789d7e..e5efc36 100644 --- a/deploy/mariadb/init/001-schema.sql +++ b/deploy/mariadb/init/001-schema.sql @@ -85,4 +85,1209 @@ CREATE TABLE IF NOT EXISTS detections ( KEY ix_detections_created (created_at), KEY ix_detections_rule_host_time (rule_name, hostname, created_at), KEY ix_detections_severity_time (severity, created_at) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE detection_rules ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(128) NOT NULL UNIQUE, + description TEXT, + severity VARCHAR(16) NOT NULL DEFAULT 'medium', + + channel VARCHAR(64) NOT NULL DEFAULT 'Security', + event_ids VARCHAR(255) NOT NULL, + + match_field VARCHAR(64) DEFAULT '', + match_operator VARCHAR(16) DEFAULT '', + match_value TEXT, + + threshold_count INT NOT NULL DEFAULT 1, + threshold_window_seconds INT NOT NULL DEFAULT 0, + + suppress_for_seconds INT NOT NULL DEFAULT 3600, + enabled TINYINT(1) NOT NULL DEFAULT 1, + + created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) +); + +CREATE INDEX idx_detection_rules_enabled +ON detection_rules (enabled); + +CREATE INDEX idx_event_logs_dynamic_rules +ON event_logs (channel_name, event_id, ts, hostname); + +INSERT INTO detection_rules +( + name, + description, + severity, + channel, + event_ids, + match_field, + match_operator, + match_value, + threshold_count, + threshold_window_seconds, + suppress_for_seconds, + enabled +) +VALUES + +-- ============================================================ +-- Kritische Manipulationen / Spurenverwischung +-- ============================================================ + +( + 'security_log_cleared', + 'Security Log wurde gelöscht. Das ist fast immer sicherheitsrelevant.', + 'high', + 'Security', + '1102', + '', + '', + '', + 1, + 0, + 86400, + 1 +), + +( + 'audit_policy_changed', + 'Audit Policy wurde geändert.', + 'high', + 'Security', + '4719', + '', + '', + '', + 1, + 0, + 3600, + 1 +), + +( + 'system_audit_policy_changed', + 'System Audit Policy wurde geändert.', + 'high', + 'Security', + '4902,4904,4905,4906,4907,4908,4912', + '', + '', + '', + 1, + 0, + 3600, + 1 +), + +( + 'special_logon', + 'Anmeldung mit speziellen Rechten erkannt.', + 'medium', + 'Security', + '4672', + '', + '', + '', + 1, + 0, + 900, + 1 +), + +( + 'privileged_service_called', + 'Privilegierter Dienst wurde aufgerufen.', + 'medium', + 'Security', + '4673,4674', + '', + '', + '', + 10, + 300, + 1800, + 1 +), + +-- ============================================================ +-- Benutzerverwaltung +-- ============================================================ + +( + 'user_created', + 'Neuer AD-Benutzer wurde erstellt.', + 'medium', + 'Security', + '4720', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'user_enabled', + 'AD-Benutzer wurde aktiviert.', + 'medium', + 'Security', + '4722', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'user_disabled', + 'AD-Benutzer wurde deaktiviert.', + 'low', + 'Security', + '4725', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'user_deleted', + 'AD-Benutzer wurde gelöscht.', + 'medium', + 'Security', + '4726', + '', + '', + '', + 1, + 0, + 3600, + 1 +), + +( + 'user_changed', + 'AD-Benutzerobjekt wurde geändert.', + 'low', + 'Security', + '4738', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'password_changed_by_user', + 'Benutzer hat eigenes Passwort geändert.', + 'low', + 'Security', + '4723', + '', + '', + '', + 1, + 0, + 900, + 1 +), + +( + 'password_reset', + 'Passwort wurde durch Admin oder berechtigten Benutzer zurückgesetzt.', + 'medium', + 'Security', + '4724', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'account_lockout', + 'Benutzerkonto wurde gesperrt.', + 'low', + 'Security', + '4740', + '', + '', + '', + 1, + 0, + 900, + 1 +), + +( + 'account_lockout_spike', + 'Viele Account Lockouts innerhalb kurzer Zeit.', + 'medium', + 'Security', + '4740', + '', + '', + '', + 5, + 300, + 1800, + 1 +), + +-- ============================================================ +-- Gruppenverwaltung allgemein +-- ============================================================ + +( + 'security_group_created', + 'Security-Gruppe wurde erstellt.', + 'medium', + 'Security', + '4727,4731,4754', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'security_group_deleted', + 'Security-Gruppe wurde gelöscht.', + 'medium', + 'Security', + '4730,4734,4758', + '', + '', + '', + 1, + 0, + 3600, + 1 +), + +( + 'security_group_changed', + 'Security-Gruppe wurde geändert.', + 'medium', + 'Security', + '4735,4737,4755', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'group_member_added', + 'Mitglied wurde zu einer Security-Gruppe hinzugefügt.', + 'medium', + 'Security', + '4728,4732,4756', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'group_member_removed', + 'Mitglied wurde aus einer Security-Gruppe entfernt.', + 'medium', + 'Security', + '4729,4733,4757', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +-- ============================================================ +-- Privilegierte Gruppen +-- Achtung: target_user ist hier normalerweise der Gruppenname. +-- ============================================================ + +( + 'privileged_group_member_added', + 'Mitglied wurde zu einer privilegierten AD-Gruppe hinzugefügt.', + 'high', + 'Security', + '4728,4732,4756', + 'target_user', + 'in', + 'Domain Admins,Enterprise Admins,Schema Admins,Administrators,Account Operators,Server Operators,Backup Operators,Print Operators,DNSAdmins,Group Policy Creator Owners,Cert Publishers,Key Admins,Enterprise Key Admins', + 1, + 0, + 3600, + 1 +), + +( + 'privileged_group_member_removed', + 'Mitglied wurde aus einer privilegierten AD-Gruppe entfernt.', + 'medium', + 'Security', + '4729,4733,4757', + 'target_user', + 'in', + 'Domain Admins,Enterprise Admins,Schema Admins,Administrators,Account Operators,Server Operators,Backup Operators,Print Operators,DNSAdmins,Group Policy Creator Owners,Cert Publishers,Key Admins,Enterprise Key Admins', + 1, + 0, + 3600, + 1 +), + +( + 'domain_admins_changed', + 'Änderung an Domain Admins erkannt.', + 'high', + 'Security', + '4728,4729,4735,4737', + 'target_user', + 'eq', + 'Domain Admins', + 1, + 0, + 3600, + 1 +), + +( + 'enterprise_admins_changed', + 'Änderung an Enterprise Admins erkannt.', + 'high', + 'Security', + '4728,4729,4735,4737', + 'target_user', + 'eq', + 'Enterprise Admins', + 1, + 0, + 3600, + 1 +), + +( + 'schema_admins_changed', + 'Änderung an Schema Admins erkannt.', + 'high', + 'Security', + '4728,4729,4735,4737', + 'target_user', + 'eq', + 'Schema Admins', + 1, + 0, + 3600, + 1 +), + +( + 'dnsadmins_changed', + 'Änderung an DNSAdmins erkannt. DNSAdmins können in vielen Umgebungen kritisch sein.', + 'high', + 'Security', + '4728,4729,4732,4733,4756,4757', + 'target_user', + 'eq', + 'DNSAdmins', + 1, + 0, + 3600, + 1 +), + +-- ============================================================ +-- Computer-Konten +-- ============================================================ + +( + 'computer_account_created', + 'Computer-Konto wurde erstellt.', + 'low', + 'Security', + '4741', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'computer_account_changed', + 'Computer-Konto wurde geändert.', + 'low', + 'Security', + '4742', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'computer_account_deleted', + 'Computer-Konto wurde gelöscht.', + 'medium', + 'Security', + '4743', + '', + '', + '', + 1, + 0, + 3600, + 1 +), + +-- ============================================================ +-- Kerberos / Authentifizierung +-- ============================================================ + +( + 'kerberos_preauth_failure', + 'Kerberos PreAuth Fehler erkannt.', + 'low', + 'Security', + '4771', + '', + '', + '', + 1, + 0, + 300, + 1 +), + +( + 'kerberos_preauth_spike', + 'Viele Kerberos PreAuth Fehler. Möglicher Password-Spray oder Bruteforce.', + 'high', + 'Security', + '4771', + '', + '', + '', + 20, + 300, + 1800, + 1 +), + +( + 'kerberos_tgt_failed_spike', + 'Viele fehlgeschlagene Kerberos-TGT-Anfragen.', + 'medium', + 'Security', + '4768', + '', + '', + '', + 30, + 300, + 1800, + 1 +), + +( + 'kerberos_service_ticket_spike', + 'Viele Kerberos-Service-Ticket-Anfragen. Kann auf Kerberoasting oder ungewöhnliche Service-Nutzung hindeuten.', + 'medium', + 'Security', + '4769', + '', + '', + '', + 100, + 300, + 1800, + 1 +), + +( + 'ntlm_authentication_spike', + 'Viele NTLM-Authentifizierungen erkannt.', + 'medium', + 'Security', + '4776', + '', + '', + '', + 50, + 300, + 1800, + 1 +), + +( + 'logon_failed_spike', + 'Viele fehlgeschlagene Logons.', + 'medium', + 'Security', + '4625', + '', + '', + '', + 25, + 300, + 1800, + 1 +), + +( + 'explicit_credentials_used', + 'Anmeldung mit expliziten Anmeldeinformationen erkannt.', + 'medium', + 'Security', + '4648', + '', + '', + '', + 1, + 0, + 900, + 1 +), + +( + 'many_explicit_credentials_used', + 'Viele Anmeldungen mit expliziten Anmeldeinformationen.', + 'high', + 'Security', + '4648', + '', + '', + '', + 20, + 300, + 1800, + 1 +), + +-- ============================================================ +-- Dienste, Tasks, Persistenz +-- ============================================================ + +( + 'service_installed_security', + 'Neuer Dienst laut Security Log installiert.', + 'high', + 'Security', + '4697', + '', + '', + '', + 1, + 0, + 3600, + 1 +), + +( + 'service_installed_system', + 'Neuer Dienst laut System Log installiert.', + 'high', + 'System', + '7045', + '', + '', + '', + 1, + 0, + 3600, + 1 +), + +( + 'scheduled_task_created', + 'Geplanter Task wurde erstellt.', + 'high', + 'Security', + '4698', + '', + '', + '', + 1, + 0, + 3600, + 1 +), + +( + 'scheduled_task_updated', + 'Geplanter Task wurde geändert.', + 'medium', + 'Security', + '4702', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'scheduled_task_deleted', + 'Geplanter Task wurde gelöscht.', + 'medium', + 'Security', + '4699', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'scheduled_task_enabled_disabled', + 'Geplanter Task wurde aktiviert oder deaktiviert.', + 'medium', + 'Security', + '4700,4701', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +-- ============================================================ +-- Prozess / PowerShell / Script Logging +-- Nur aktivieren, wenn diese Events bei dir tatsächlich gesammelt werden. +-- ============================================================ + +( + 'process_created', + 'Neuer Prozess wurde erstellt. Nur sinnvoll bei aktiviertem Process Creation Auditing.', + 'low', + 'Security', + '4688', + '', + '', + '', + 1, + 0, + 300, + 0 +), + +( + 'suspicious_powershell_process', + 'Verdächtiger PowerShell-Aufruf im Prozess-Event.', + 'high', + 'Security', + '4688', + 'msg', + 'contains', + 'powershell', + 1, + 0, + 1800, + 0 +), + +( + 'powershell_script_block', + 'PowerShell Script Block Logging Event erkannt.', + 'medium', + 'Windows PowerShell,Microsoft-Windows-PowerShell/Operational', + '4104', + '', + '', + '', + 1, + 0, + 900, + 0 +), + +( + 'suspicious_powershell_encodedcommand', + 'PowerShell EncodedCommand erkannt.', + 'high', + 'Windows PowerShell,Microsoft-Windows-PowerShell/Operational,Security', + '4104,4688', + 'msg', + 'contains', + 'EncodedCommand', + 1, + 0, + 1800, + 0 +), + +( + 'suspicious_powershell_downloadstring', + 'PowerShell DownloadString erkannt.', + 'high', + 'Windows PowerShell,Microsoft-Windows-PowerShell/Operational,Security', + '4104,4688', + 'msg', + 'contains', + 'DownloadString', + 1, + 0, + 1800, + 0 +), + +( + 'suspicious_powershell_iex', + 'PowerShell Invoke-Expression / IEX erkannt.', + 'high', + 'Windows PowerShell,Microsoft-Windows-PowerShell/Operational,Security', + '4104,4688', + 'msg', + 'contains', + 'Invoke-Expression', + 1, + 0, + 1800, + 0 +), + +-- ============================================================ +-- GPO / AD Objektänderungen +-- Hinweis: 5136/5137/5141 kommen aus Directory Service Changes. +-- Dafür muss das passende Auditing auf DCs aktiv sein. +-- ============================================================ + +( + 'directory_object_modified', + 'AD-Objekt wurde geändert.', + 'medium', + 'Security', + '5136', + '', + '', + '', + 1, + 0, + 900, + 0 +), + +( + 'directory_object_created', + 'AD-Objekt wurde erstellt.', + 'medium', + 'Security', + '5137', + '', + '', + '', + 1, + 0, + 900, + 0 +), + +( + 'directory_object_deleted', + 'AD-Objekt wurde gelöscht.', + 'medium', + 'Security', + '5141', + '', + '', + '', + 1, + 0, + 1800, + 0 +), + +( + 'gpo_changed', + 'Mögliche GPO-Änderung erkannt.', + 'high', + 'Security', + '5136', + 'msg', + 'contains', + 'CN=Policies,CN=System', + 1, + 0, + 3600, + 0 +), + +( + 'adminsdholder_changed', + 'AdminSDHolder wurde geändert. Sehr sicherheitsrelevant.', + 'high', + 'Security', + '5136', + 'msg', + 'contains', + 'CN=AdminSDHolder', + 1, + 0, + 86400, + 0 +), + +( + 'domain_root_changed', + 'Domain-Root-Objekt wurde geändert.', + 'high', + 'Security', + '5136', + 'msg', + 'contains', + 'DC=', + 1, + 0, + 3600, + 0 +), + +-- ============================================================ +-- Objektzugriff / ACL +-- Hinweis: 4662/4670 brauchen passende SACLs. +-- ============================================================ + +( + 'object_permissions_changed', + 'Berechtigungen eines Objekts wurden geändert.', + 'high', + 'Security', + '4670', + '', + '', + '', + 1, + 0, + 3600, + 0 +), + +( + 'directory_service_object_access', + 'Directory-Service-Objektzugriff erkannt.', + 'medium', + 'Security', + '4662', + '', + '', + '', + 10, + 300, + 1800, + 0 +), + +-- ============================================================ +-- Share / SMB / SYSVOL / administrative Zugriffe +-- Hinweis: Kann sehr laut werden. +-- ============================================================ + +( + 'network_share_accessed', + 'Netzwerkfreigabe wurde genutzt.', + 'low', + 'Security', + '5140', + '', + '', + '', + 50, + 300, + 900, + 0 +), + +( + 'network_share_object_checked', + 'Detaillierter Netzwerkfreigabezugriff erkannt.', + 'low', + 'Security', + '5145', + '', + '', + '', + 100, + 300, + 900, + 0 +), + +( + 'sysvol_access_spike', + 'Viele Zugriffe auf SYSVOL erkannt.', + 'low', + 'Security', + '5140,5145', + 'msg', + 'contains', + 'SYSVOL', + 100, + 300, + 900, + 0 +), + +( + 'admin_share_access', + 'Zugriff auf administrative Freigabe erkannt.', + 'medium', + 'Security', + '5140,5145', + 'msg', + 'contains', + 'ADMIN$', + 1, + 0, + 1800, + 0 +), + +( + 'c_share_access', + 'Zugriff auf C$ erkannt.', + 'medium', + 'Security', + '5140,5145', + 'msg', + 'contains', + 'C$', + 1, + 0, + 1800, + 0 +), + +-- ============================================================ +-- System / Neustart / Agent-Kontext +-- ============================================================ + +( + 'system_startup', + 'System wurde gestartet.', + 'low', + 'System', + '6005', + '', + '', + '', + 1, + 0, + 300, + 0 +), + +( + 'system_shutdown', + 'System wurde heruntergefahren.', + 'low', + 'System', + '6006', + '', + '', + '', + 1, + 0, + 300, + 0 +), + +( + 'planned_shutdown_or_restart', + 'Geplanter Shutdown oder Neustart erkannt.', + 'low', + 'System', + '1074', + '', + '', + '', + 1, + 0, + 900, + 1 +), + +( + 'unexpected_shutdown', + 'Unerwarteter Shutdown erkannt.', + 'medium', + 'System', + '6008', + '', + '', + '', + 1, + 0, + 1800, + 1 +), + +( + 'reboot_spike_dynamic', + 'Viele Neustart-/Shutdown-Events in kurzer Zeit.', + 'medium', + 'System', + '1074,6005,6006,6008', + '', + '', + '', + 3, + 900, + 1800, + 0 +), + +-- ============================================================ +-- Windows Defender / Security Center +-- Event IDs können je nach Version/Quelle variieren. +-- ============================================================ + +( + 'defender_malware_detected', + 'Microsoft Defender hat Malware erkannt.', + 'high', + 'Microsoft-Windows-Windows Defender/Operational', + '1116', + '', + '', + '', + 1, + 0, + 3600, + 0 +), + +( + 'defender_malware_remediated', + 'Microsoft Defender hat Malware bereinigt.', + 'medium', + 'Microsoft-Windows-Windows Defender/Operational', + '1117', + '', + '', + '', + 1, + 0, + 1800, + 0 +), + +( + 'defender_action_failed', + 'Microsoft Defender Aktion fehlgeschlagen.', + 'high', + 'Microsoft-Windows-Windows Defender/Operational', + '1118,1119', + '', + '', + '', + 1, + 0, + 3600, + 0 +), + +( + 'defender_disabled_or_config_changed', + 'Defender-Konfiguration wurde geändert oder Schutz deaktiviert.', + 'high', + 'Microsoft-Windows-Windows Defender/Operational', + '5007,5013', + '', + '', + '', + 1, + 0, + 3600, + 0 +), + +-- ============================================================ +-- Zertifikatsdienste / AD CS +-- Nur aktivieren, wenn AD CS vorhanden und Events gesammelt werden. +-- ============================================================ + +( + 'certificate_request_issued', + 'Zertifikat wurde ausgestellt.', + 'medium', + 'Security', + '4886,4887', + '', + '', + '', + 1, + 0, + 1800, + 0 +), + +( + 'certificate_template_changed', + 'Zertifikatstemplate wurde geändert.', + 'high', + 'Security', + '4898,4899,4900', + '', + '', + '', + 1, + 0, + 86400, + 0 +), + +( + 'cert_services_config_changed', + 'AD-CS-Konfiguration wurde geändert.', + 'high', + 'Security', + '4882,4885,4890,4891,4892', + '', + '', + '', + 1, + 0, + 86400, + 0 +); \ No newline at end of file diff --git a/main.go b/main.go index 1730c36..f175454 100644 --- a/main.go +++ b/main.go @@ -63,6 +63,19 @@ const uiTemplates = ` .inline-form { display: inline; } button.danger { background: #dc2626; } button.success { background: #16a34a; } + textarea, select { + width: 100%; + padding: 8px; + border: 1px solid #d1d5db; + border-radius: 8px; + box-sizing: border-box; + } + .badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: bold; } + .badge-on { background: #dcfce7; color: #166534; } + .badge-off { background: #fee2e2; color: #991b1b; } + .inline-form { display: inline; } + button.danger { background: #dc2626; } + button.success { background: #16a34a; } @@ -71,6 +84,7 @@ const uiTemplates = `