Repository navigation
Box: fix Abnormal user activity rule that could never alert - #15764
Open
Rafi (Muhammad-Rafiullah) wants to merge 3 commits into
Open
Rafi (Muhammad-Rafiullah) wants to merge 3 commits into
Rafi (Muhammad-Rafiullah) wants to merge 3 commits into
Conversation
The query could not return rows. The baseline counted rows after a union instead of adding up events, then divided by 29 with integers, so the daily average was always 0. The "last hour" parts had no time filter and grouped by SourceName (the file) instead of the user, the join on a constant key kept a single user, and the comparison pointed the wrong way. The new query counts each user's events per hour over 14 days, takes the newest hour as the current activity and the earlier active hours as the baseline, and alerts when the last hour has at least 50 events and is more than three standard deviations above the user's own average. Users are keyed on SrcUserUpn instead of the display name. Description updated to match and rule version bumped to 1.0.2. Fixes Azure#15664
Contributor
|
Hi Rafi (@Muhammad-Rafiullah) I have a few points to clarify before approval:
Once these points are addressed, we can proceed with the review. |
Users with fewer than two earlier active hours now get a baseline stdev of 0 set in the query, instead of relying on what stdevif returns for an empty group. Results are the same as before. Bump the solution to 3.1.8, add a ReleaseNotes row and rebuild the package with the V3 packaging tool.
Contributor
Author
|
Thanks for taking a look.
|
Contributor
|
Hi Rafi (@Muhammad-Rafiullah)
|
Add a table description and a description for each of the 42 columns in BoxEvents_table.json, as required by the custom table schema check (VAL-TBL-01/02), and rebuild the 3.1.8 package so mainTemplate.json carries the same text (VAL-TBL-03). Fix "Abmormal" to "Abnormal" in the rule name and the ReleaseNotes row.
Contributor
Author
|
Thanks. Pushed a new commit with these:
I ran the custom table check from master ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change(s):
Solutions/Box/Analytic Rules/BoxAbnormalUserActivity.yaml(rule id1139230c-cf10-45db-b616-fed0d1415c05).SrcUserUpninstead of the display name, and that value is what goes intoAccountCustomEntity. The entity mapping itself is unchanged.queryFrequency,queryPeriod, tactics, techniques and connectors are unchanged.BaselineStdevis set to 0 explicitly when the user has fewer than two earlier active hours.Solutions/Box/ReleaseNotes.md, and the package rebuilt withTools/Create-Azure-Sentinel-Solution/V3/createSolutionV3.ps1(mainTemplate.json,createUiDefinition.json,3.1.8.zip).BoxEventsV2_CLinSolutions/Box/Data Connectors/BoxEvents_ccp/BoxEvents_table.json(VAL-TBL-01/02), rebuilt the package somainTemplate.jsoncarries the same text (VAL-TBL-03), and fixed the "Abmormal" typo in the rule name and the ReleaseNotes row.Reason for Change(s):
union(1 or 2 per user) instead of adding up events, then divided by 29 with integers, soEventsPerDaywas always 0SourceName, which is the file or folder, not the userjoin ... on kwith a constant key uses the default join kind, which kept one row from the left sideEventsPerDay > TotalEventsH, which is the wrong way round for a spike and can never be true when the left side is 0BoxEventsonce instead of twice and to line the hourly buckets up with the run time, so every baseline hour is a full hour.Version Updated:
Testing Completed:
BoxEventsreplaced by generated rows (let BoxEvents = union (range ...)). 19 cases, including:SrcUserUpn: ignoredBoxEventsparser on a generatedBoxEventsV2_CLtable with the columns fromBoxEvents_table.json. It returned the two expected users.BoxEvents_CLtable, and the rule running on a schedule in Sentinel. The 50 event floor and the three standard deviation threshold are a starting point and may need tuning on real traffic. Expect alerts for legitimate bulk activity such as a first Box Drive sync, migrations, service accounts and new users with no history.Checked that the validations are passing and have addressed any issues that are present:
PRNUMset to this PR:.script/tests/KqlvalidationsTests: 13/13 passed, includingValidate_DetectionQueries_HaveValidKqlforBoxAbnormalUserActivity.yaml.script/tests/detectionTemplateSchemaValidation: 6/6 passed (run on the .NET 8 runtime, since the project targets .NET Core 3.1)DataConnectorValidationsandSolutionValidationsfailed on the previous commit with VAL-TBL-01/02/03 forBoxEventsV2_CL. I ran the check behind them (.script/utils/dataConnectorCheckers/customTableSchemaChecker.tsfrom master) locally with Node against the Box connector files and the package: it passes now. Against the previous package it reports the same errors as CI. I have not run the full CI jobs.Note on the package diff: the packaging tool reads rule YAML into unordered hashtables, so on each run it shuffles key order inside
requiredDataConnectorsandentityMappingsfor every rule. Apart from that reordering, the template changes are the version numbers, this rule's name, description and query, theBoxEventsV2_CLtable and column descriptions, and one workbook metadata description that the 3.1.7 package had as a stringified PowerShell object.