-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Support Microsoft Graph API JSON Format #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| Timestamp: '.time' | ||
| Timestamp: '.time|.eventTimestamp' | ||
| RuleTitle: 'sigma.title' | ||
| RuleAuthor: 'sigma.author' | ||
| Level: 'sigma.level' | ||
| Category: '.category' | ||
| OperationName: '.operationName' | ||
| SrcIP: '.callerIpAddress' | ||
| Category: '.category.value|.category' | ||
| OperationName: '.operationName.value|.operationName' | ||
| Entity: '.properties.entity' | ||
| Caller: '.caller' | ||
| SrcIP: '.claims.ipaddr|.callerIpAddress' | ||
| ResourceId: '.resourceId' | ||
| CorrelationId : '.correlationId' | ||
| RuleID: 'sigma.id' |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,6 @@ pub fn scan_file<'a>( | |
| Ok(value) => value, | ||
| Err(_e) => return, | ||
| }; | ||
|
|
||
| detect_events( | ||
| &events, | ||
| context, | ||
|
|
@@ -185,10 +184,24 @@ fn log_contents_to_events(log_contents: &str, log: &LogSource) -> Vec<Value> { | |
| } | ||
| } | ||
| } | ||
| LogSource::Azure => log_contents | ||
| .lines() | ||
| .filter_map(|line| serde_json::from_str::<Value>(line).ok()) | ||
| .collect(), | ||
| LogSource::Azure => { | ||
| // Try parsing as JSON array first | ||
| if let Ok(Value::Array(json_array)) = serde_json::from_str::<Value>(log_contents) { | ||
| return json_array; | ||
| } | ||
| // Try parsing as JSON object with "value" key first | ||
| if let Ok(json_value) = serde_json::from_str::<Value>(log_contents) | ||
| && let Value::Object(ref json_map) = json_value | ||
| && let Some(Value::Array(json_array)) = json_map.get("value") | ||
| { | ||
| return json_array.clone(); | ||
| } | ||
| // Fall back to JSONL format | ||
| log_contents | ||
| .lines() | ||
| .filter_map(|line| serde_json::from_str::<Value>(line).ok()) | ||
| .collect() | ||
| } | ||
| _ => vec![], | ||
| } | ||
| } | ||
|
|
@@ -418,12 +431,35 @@ pub fn load_json_from_file( | |
| } | ||
| } | ||
| LogSource::Azure => { | ||
| log_contents.lines().for_each(|line| { | ||
| if let Ok(json_value) = serde_json::from_str::<Value>(line) { | ||
| events.push(json_value); | ||
| let log_contents_trimmed = log_contents | ||
| .strip_prefix('\u{FEFF}') | ||
| .unwrap_or(log_contents); | ||
| let json_value: Result<Value, _> = serde_json::from_str(log_contents_trimmed); | ||
| match json_value { | ||
| Ok(json_value) => match json_value { | ||
| // JSON array format | ||
| Value::Array(json_array) => { | ||
| events.extend(json_array); | ||
| } | ||
| // JSON object with "value" key | ||
| Value::Object(json_map) => { | ||
| if let Some(Value::Array(json_array)) = json_map.get("value") { | ||
| events.extend(json_array.clone()); | ||
| } | ||
| } | ||
| _ => {} | ||
| }, | ||
| Err(_) => { | ||
| // Fall back to JSONL format | ||
| log_contents.lines().for_each(|line| { | ||
| if let Ok(json_value) = serde_json::from_str::<Value>(line) { | ||
| events.push(json_value); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| _ => {} | ||
| } | ||
| Ok(events) | ||
|
|
@@ -463,4 +499,42 @@ mod tests { | |
| let event = result.unwrap(); | ||
| assert_eq!(event.len(), 29); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_load_azure_value_format() { | ||
| let test_file = "test_files/json/azure_value_format.json"; | ||
fukusuket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let log_contents = fs::read_to_string(test_file).unwrap(); | ||
| let result = load_json_from_file(&log_contents, &LogSource::Azure); | ||
| assert!(result.is_ok()); | ||
| let events = result.unwrap(); | ||
| assert_eq!(events.len(), 1); | ||
| // Verify that the event has expected fields | ||
| assert!(events[0].get("caller").is_some()); | ||
| assert_eq!( | ||
| events[0].get("caller").unwrap().as_str().unwrap(), | ||
| "[email protected]" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_load_azure_graph_api_format() { | ||
| let test_file = "test_files/json/azure_graph_api_format.json"; | ||
fukusuket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let log_contents = fs::read_to_string(test_file).unwrap(); | ||
| let result = load_json_from_file(&log_contents, &LogSource::Azure); | ||
| assert!(result.is_ok()); | ||
| let events = result.unwrap(); | ||
| assert_eq!(events.len(), 3); | ||
|
|
||
| // Verify first event has expected fields | ||
| assert!(events[0].get("eventTimestamp").is_some()); | ||
| assert_eq!( | ||
| events[0].get("eventTimestamp").unwrap().as_str().unwrap(), | ||
| "2025-11-30T01:45:06.4650448Z" | ||
| ); | ||
| assert!(events[0].get("caller").is_some()); | ||
| assert_eq!( | ||
| events[0].get("caller").unwrap().as_str().unwrap(), | ||
| "[email protected]" | ||
| ); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.