DefensiveHub

KQL Hunting Library

مكتبة Queries جاهزة للـ Advanced Hunting و الـ Microsoft Sentinel. كل Query معاه الـ Technique و الـ Table و اللي تعمله بعد النتيجة.

الـ Queries
13 Query
آخر تحديث
10 نوفمبر 2026
اتعمل لـ
الـ SOC analysts، و الـ threat hunters، و الـ detection engineers

قبل ما تستخدمها: الـ Queries دي نقطة بداية للـ Hunting مش Detection جاهز. جرّبها على فترة زمنية قصيرة الأول، و عدّل الـ Thresholds و أسماء الـ Tables على بيئتك و الـ Connectors اللي عندك. النتيجة بتدّيك Lead للـ Investigation مش حكم نهائي.

الـ Identity و الـ Cloud

من الـ Sentinel. الـ Tables دي بتجي من Microsoft Entra ID و Microsoft 365 عن طريق الـ Data Connectors.

Password Spray

T1110.003

عنوان IP واحد بيجرب باسورد على مستخدمين كتير. الكود 50126 معناه باسورد غلط.

SigninLogs
| where TimeGenerated > ago(1d)
| where ResultType == "50126"
| summarize Users = dcount(UserPrincipalName), Attempts = count() by IPAddress, bin(TimeGenerated, 1h)
| where Users >= 10
| order by Users desc

بعد النتيجة: راجع الـ IPs اللي نجح منها Sign-in بعد المحاولات دي (ResultType 0). عدّل الرقم 10 على حجم الـ Tenant.

SigninLogs · الـ Entra ID Sign-in Logs متوصلة بالـ Sentinel

Sign-in ناجح من دولة جديدة

T1078

بيقارن آخر يوم بآخر 30 يوم، ويطلّع المستخدم اللي دخل من دولة عمره ما دخل منها.

let known = SigninLogs
| where TimeGenerated between (ago(30d) .. ago(1d))
| where ResultType == "0"
| extend Country = tostring(LocationDetails.countryOrRegion)
| summarize by UserPrincipalName, Country;
SigninLogs
| where TimeGenerated > ago(1d)
| where ResultType == "0"
| extend Country = tostring(LocationDetails.countryOrRegion)
| join kind=leftanti known on UserPrincipalName, Country
| project TimeGenerated, UserPrincipalName, Country, IPAddress, AppDisplayName

بعد النتيجة: المسافرين و الـ VPN هيطلعوا هنا. الأهم: هل الـ Sign-in عدّى بـ MFA؟ و بعده حصل إيه (Inbox Rule مثلًا)؟

SigninLogs · الـ Entra ID Sign-in Logs

Inbox Rule بتحوّل أو بتمسح

T1114.003

قاعدة جديدة في الـ Mailbox بتعمل Forward أو Redirect أو بتمسح الإيميلات. من أشهر الحاجات بعد اختراق الـ Mailbox.

OfficeActivity
| where TimeGenerated > ago(7d)
| where OfficeWorkload == "Exchange"
| where Operation in ("New-InboxRule", "Set-InboxRule", "UpdateInboxRules")
| where Parameters has_any ("ForwardTo", "ForwardAsAttachmentTo", "RedirectTo", "DeleteMessage")
| project TimeGenerated, UserId, Operation, ClientIP, Parameters

بعد النتيجة: قارن الـ ClientIP بآخر Sign-in للمستخدم. قاعدة جاية من IP غريب بعد Sign-in من دولة جديدة = اختراق لحد ما يثبت العكس.

OfficeActivity · الـ Office 365 connector متوصل بالـ Sentinel

الـ Email

من الـ Advanced Hunting في الـ Microsoft Defender XDR.

Phishing اتسلّم واتداس عليه

T1566.002

إيميل Phishing وصل للـ Inbox، و حد من المستلمين داس على لينك جواه.

EmailEvents
| where Timestamp > ago(7d)
| where DeliveryAction == "Delivered"
| where ThreatTypes has "Phish"
| project NetworkMessageId, RecipientEmailAddress, SenderFromAddress, Subject
| join kind=inner (
    UrlClickEvents
    | where Timestamp > ago(7d)
    | where ActionType == "ClickAllowed"
    | project NetworkMessageId, ClickTime = Timestamp, Url
  ) on NetworkMessageId
| order by ClickTime desc

بعد النتيجة: المستخدمين اللي في النتيجة هما الأولوية: راجع الـ Sign-ins و الـ Inbox Rules بتاعتهم، و اعمل Revoke للـ Sessions لو لزم.

EmailEvents + UrlClickEvents · محتاج Defender for Office 365 و Safe Links شغالين عشان UrlClickEvents يتملي

الـ Endpoint

من الـ Advanced Hunting، بتغطي أجهزة Defender for Endpoint. ممكن تتحول لـ Detection Rule بعد ما تظبط الـ False Positives.

PowerShell بأمر مشفّر

T1059.001

PowerShell شغال بـ Base64 أو بـ -EncodedCommand. الـ Attacker بيستخدمه عشان يخبي الأمر.

DeviceProcessEvents
| where Timestamp > ago(1d)
| where FileName in~ ("powershell.exe", "pwsh.exe")
| where ProcessCommandLine has_any ("-enc", "-encodedcommand", "FromBase64String")
| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine
| order by Timestamp desc

بعد النتيجة: فك الـ Base64 وشوف الأمر الحقيقي. بص على الـ Parent Process: Office أو الـ Browser بيشغّل PowerShell مش طبيعي. أدوات الإدارة ممكن تطلع هنا كـ False Positive.

DeviceProcessEvents · الجهاز متضاف على Defender for Endpoint

Office بيشغّل Shell

T1204.002

Word أو Excel أو Outlook فتح cmd أو PowerShell أو Script Host. غالبًا مرفق فيه Macro.

DeviceProcessEvents
| where Timestamp > ago(1d)
| where InitiatingProcessFileName in~ ("winword.exe", "excel.exe", "powerpnt.exe", "outlook.exe")
| where FileName in~ ("cmd.exe", "powershell.exe", "wscript.exe", "cscript.exe", "mshta.exe")
| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, FileName, ProcessCommandLine

بعد النتيجة: ابدأ من الإيميل أو الملف اللي اتفتح قبلها بدقايق. قليل جدًا من الحالات دي تبقى شرعية.

DeviceProcessEvents · الجهاز متضاف على Defender for Endpoint

Scheduled Task جديدة بـ schtasks

T1053.005

حد عمل Scheduled Task من سطر الأوامر. طريقة شائعة للـ Persistence.

DeviceProcessEvents
| where Timestamp > ago(1d)
| where FileName =~ "schtasks.exe"
| where ProcessCommandLine has "/create"
| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine

بعد النتيجة: بص على الأمر اللي الـ Task بتشغله ومسارها. Task بتشغّل Script من فولدر مؤقت أو بحساب SYSTEM تستاهل Investigation.

DeviceProcessEvents · الجهاز متضاف على Defender for Endpoint

مسح الـ Shadow Copies و الـ Backups

T1490

الـ Ransomware بيمسح النسخ الاحتياطية المحلية قبل ما يشفّر.

DeviceProcessEvents
| where Timestamp > ago(7d)
| where (FileName =~ "vssadmin.exe" and ProcessCommandLine has "delete" and ProcessCommandLine has "shadows")
    or (FileName =~ "wbadmin.exe" and ProcessCommandLine has "delete" and ProcessCommandLine has "catalog")
| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine

بعد النتيجة: لو ظهر على جهاز، اعزله فورًا. الـ Containment الأول، وبعدها التحقيق.

DeviceProcessEvents · الجهاز متضاف على Defender for Endpoint

certutil بينزّل ملف

T1105

certutil أداة شرعية، بس الـ Attackers بيستخدموها لتنزيل ملفات من الإنترنت.

DeviceProcessEvents
| where Timestamp > ago(7d)
| where FileName =~ "certutil.exe"
| where ProcessCommandLine has_any ("urlcache", "-split", "-decode")
| where ProcessCommandLine has_any ("http://", "https://")
| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine

بعد النتيجة: راجع الـ URL و الـ Domain، وشوف الملف اللي اتحفظ اتشغّل ولا لأ.

DeviceProcessEvents · الجهاز متضاف على Defender for Endpoint

الـ Logon على الأجهزة

من الـ Advanced Hunting. بتدور على الدخول عن بعد و الـ Brute Force.

RDP ناجح من IP عام

T1021.001

حد دخل على جهاز بـ Remote Desktop من عنوان مش داخلي.

DeviceLogonEvents
| where Timestamp > ago(7d)
| where ActionType == "LogonSuccess"
| where LogonType == "RemoteInteractive"
| where isnotempty(RemoteIP)
| where ipv4_is_private(RemoteIP) == false
| project Timestamp, DeviceName, AccountName, RemoteIP

بعد النتيجة: الـ RDP المفتوح على الإنترنت من أشهر طرق الـ Initial Access. اربط النتيجة بمحاولات فاشلة قبلها من نفس الـ IP.

DeviceLogonEvents · الجهاز متضاف على Defender for Endpoint

Brute Force على الأجهزة

T1110

مصدر واحد عنده محاولات Logon فاشلة كتير على نفس الجهاز.

DeviceLogonEvents
| where Timestamp > ago(1d)
| where ActionType == "LogonFailed"
| summarize Failures = count(), Accounts = dcount(AccountName) by RemoteIP, DeviceName
| where Failures >= 20
| order by Failures desc

بعد النتيجة: حسابات كتير = Spray. حساب واحد = Brute Force. وشوف لو فيه LogonSuccess من نفس الـ IP بعدها.

DeviceLogonEvents · الجهاز متضاف على Defender for Endpoint

الـ Windows Events

من الـ Sentinel، جدول SecurityEvent. محتاجة الـ Audit Policy مظبوطة، وإلا الـ Events مش هتتسجل.

عضو اتضاف لـ Group حساس

T1098

الأحداث 4728 و 4732 و 4756 على Domain Admins أو Administrators أو غيرهم.

SecurityEvent
| where TimeGenerated > ago(7d)
| where EventID in (4728, 4732, 4756)
| where TargetUserName in ("Domain Admins", "Enterprise Admins", "Schema Admins", "Administrators")
| project TimeGenerated, Computer, SubjectUserName, MemberName, TargetUserName, EventID

بعد النتيجة: قارنها بطلب تغيير معتمد. لو الإضافة بعد 4720 على طول، يبقى فيه Backdoor Account.

SecurityEvent · Windows Security Events متجمعة في الـ Sentinel

الـ Audit Log اتمسح

T1070.001

الحدث 1102. تقريبًا عمره ما بيبقى شرعي.

SecurityEvent
| where TimeGenerated > ago(30d)
| where EventID == 1102
| project TimeGenerated, Computer, SubjectUserName, SubjectDomainName

بعد النتيجة: اعتبره Alert عالي. اعرف مين الحساب، وراجع اللي حصل على الجهاز قبل المسح.

SecurityEvent · Windows Security Events متجمعة في الـ Sentinel