-
Notifications
You must be signed in to change notification settings - Fork 126
Azurehound enhancement - Local group user rights from Intune #140
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
Open
manas-metron
wants to merge
34
commits into
SpecterOps:main
Choose a base branch
from
metron-labs:vishalk-local-group-user-rights-metron
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
af39e51
Updated to the latest commit of main branch on the original repo
vishalk-metron 848b218
Update .gitignore
vishalk-metron 62498f4
Partial code completion for fetching devices from intune
vishalk-metron 0d5c890
sample integration example (partial, may not work)
vishalk-metron 45f8965
Merge remote-tracking branch 'spectreops-ah-repo/main' into vishalk-m…
vishalk-metron a62a190
Intune basic APIs have been implemented
vishalk-metron 688ccf2
Added powershell script to get JWT Token from graph
vishalk-metron c6a476f
Update .gitignore
vishalk-metron 373cfc2
Updated the file 'list-intune-script-results.go' to get results from …
vishalk-metron c85f340
Added files for Registry values module - incomplete
vishalk-metron ab1d17b
Removed Registry Values Files to clean up the PR
vishalk-metron 8c4e2a8
Delete registry.go
vishalk-metron 6c20e19
Removed references for script execution module
vishalk-metron 14f9461
Removed Duplicate Code, Unused Code
vishalk-metron 5fcda19
Reduced Code Duplication
vishalk-metron 414247f
Working Unoptimised version
vishalk-metron a63b083
Implemented Real API instead of mock results
vishalk-metron 160a712
Delete cla.yml
vishalk-metron 97867d2
Removing Action / Checks
vishalk-metron fd673c1
test commit
vishalk-metron e1c2866
Revert "test commit"
vishalk-metron ba2d4f3
Revert "Removing Action / Checks"
vishalk-metron 8ebed47
Revert "Delete cla.yml"
vishalk-metron 5a48c7d
Delete intune_converter.go
vishalk-metron 39bdfca
Update list-intune-registry-analysis.go
vishalk-metron 5811b81
Delete get_token.ps1
vishalk-metron 6b0d8a9
Active sessions data fetching through Intune
vishalk-metron 65d402b
Updated with real API calls and to use existing config file
vishalk-metron 27aee2e
Completed/Corrected the Session Collection Module
vishalk-metron 229243c
Improved the module and added detailed analysis --verbose flag
vishalk-metron 4a32b78
Membership Membership & User Rights
vishalk-metron 75217ec
Removed unnecessarily collected data
vishalk-metron f003aec
CodeRabbit PR comments Resolved
vishalk-metron 61b90b5
Updated Go dependency
vishalk-metron 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
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 |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // File: client/intune_devices.go | ||
| // Copyright (C) 2022 SpecterOps | ||
| // Implementation of Intune device management API calls | ||
|
|
||
| package client | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/bloodhoundad/azurehound/v2/client/query" | ||
| "github.com/bloodhoundad/azurehound/v2/constants" | ||
| "github.com/bloodhoundad/azurehound/v2/models/intune" | ||
| ) | ||
|
|
||
| func setDefaultParams(params *query.GraphParams) { | ||
| if params.Top == 0 { | ||
| params.Top = 999 | ||
| } | ||
| } | ||
|
|
||
| // ListIntuneManagedDevices retrieves all managed devices from Intune | ||
| // GET /deviceManagement/managedDevices | ||
| func (s *azureClient) ListIntuneManagedDevices(ctx context.Context, params query.GraphParams) <-chan AzureResult[intune.ManagedDevice] { | ||
| var ( | ||
| out = make(chan AzureResult[intune.ManagedDevice]) | ||
| path = fmt.Sprintf("/%s/deviceManagement/managedDevices", constants.GraphApiVersion) | ||
| ) | ||
|
|
||
| setDefaultParams(¶ms) | ||
|
|
||
| go getAzureObjectList[intune.ManagedDevice](s.msgraph, ctx, path, params, out) | ||
| return out | ||
| } | ||
|
|
||
| // GetIntuneDeviceCompliance retrieves compliance information for a specific device | ||
| // GET /deviceManagement/managedDevices/{id}/deviceCompliancePolicyStates | ||
| func (s *azureClient) GetIntuneDeviceCompliance(ctx context.Context, deviceId string, params query.GraphParams) <-chan AzureResult[intune.ComplianceState] { | ||
| var ( | ||
| out = make(chan AzureResult[intune.ComplianceState]) | ||
| path = fmt.Sprintf("/%s/deviceManagement/managedDevices/%s/deviceCompliancePolicyStates", constants.GraphApiVersion, deviceId) | ||
| ) | ||
|
|
||
| setDefaultParams(¶ms) | ||
|
|
||
| go getAzureObjectList[intune.ComplianceState](s.msgraph, ctx, path, params, out) | ||
| return out | ||
| } | ||
|
|
||
| // GetIntuneDeviceConfiguration retrieves configuration information for a specific device | ||
| // GET /deviceManagement/managedDevices/{id}/deviceConfigurationStates | ||
| func (s *azureClient) GetIntuneDeviceConfiguration(ctx context.Context, deviceId string, params query.GraphParams) <-chan AzureResult[intune.ConfigurationState] { | ||
| var ( | ||
| out = make(chan AzureResult[intune.ConfigurationState]) | ||
| path = fmt.Sprintf("/%s/deviceManagement/managedDevices/%s/deviceConfigurationStates", constants.GraphApiVersion, deviceId) | ||
| ) | ||
|
|
||
| setDefaultParams(¶ms) | ||
|
|
||
| go getAzureObjectList[intune.ConfigurationState](s.msgraph, ctx, path, params, out) | ||
| return out | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| // client/intune_data_collection.go | ||
| package client | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/bloodhoundad/azurehound/v2/client/query" | ||
| "github.com/bloodhoundad/azurehound/v2/constants" | ||
| "github.com/bloodhoundad/azurehound/v2/models/azure" | ||
| ) | ||
|
|
||
| // ListUserAppRoleAssignments - Get app role assignments for a user (User Rights) | ||
| func (s *azureClient) ListUserAppRoleAssignments(ctx context.Context, userID string, params query.GraphParams) <-chan AzureResult[azure.AppRoleAssignment] { | ||
| var ( | ||
| out = make(chan AzureResult[azure.AppRoleAssignment]) | ||
| path = fmt.Sprintf("/%s/users/%s/appRoleAssignments", constants.GraphApiVersion, userID) | ||
| ) | ||
|
|
||
| if params.Top == 0 { | ||
| params.Top = 999 | ||
| } | ||
|
|
||
| go getAzureObjectList[azure.AppRoleAssignment](s.msgraph, ctx, path, params, out) | ||
| return out | ||
| } | ||
|
|
||
| // ListSignIns - Get sign-in activity (for active sessions context) | ||
| func (s *azureClient) ListSignIns(ctx context.Context, params query.GraphParams) <-chan AzureResult[azure.SignIn] { | ||
| var ( | ||
| out = make(chan AzureResult[azure.SignIn]) | ||
| path = fmt.Sprintf("/%s/auditLogs/signIns", constants.GraphApiVersion) | ||
| ) | ||
|
|
||
| if params.Top == 0 { | ||
| params.Top = 100 // Sign-ins can be large datasets | ||
| } | ||
|
|
||
| go getAzureObjectList[azure.SignIn](s.msgraph, ctx, path, params, out) | ||
| return out | ||
| } | ||
|
|
||
| // GetDeviceRegisteredUsers - Get users registered to a device | ||
| func (s *azureClient) GetDeviceRegisteredUsers(ctx context.Context, deviceId string, params query.GraphParams) <-chan AzureResult[json.RawMessage] { | ||
| var ( | ||
| out = make(chan AzureResult[json.RawMessage]) | ||
| path = fmt.Sprintf("/%s/devices/%s/registeredUsers", constants.GraphApiVersion, deviceId) | ||
| ) | ||
|
|
||
| go getAzureObjectList[json.RawMessage](s.msgraph, ctx, path, params, out) | ||
| return out | ||
| } | ||
|
|
||
| // GetDeviceRegisteredOwners - Get owners of a device | ||
| func (s *azureClient) GetDeviceRegisteredOwners(ctx context.Context, deviceId string, params query.GraphParams) <-chan AzureResult[json.RawMessage] { | ||
| var ( | ||
| out = make(chan AzureResult[json.RawMessage]) | ||
| path = fmt.Sprintf("/%s/devices/%s/registeredOwners", constants.GraphApiVersion, deviceId) | ||
| ) | ||
|
|
||
| go getAzureObjectList[json.RawMessage](s.msgraph, ctx, path, params, out) | ||
| return out | ||
| } | ||
|
|
||
| // CollectGroupMembershipData - Collect all group membership data using existing methods | ||
| func (s *azureClient) CollectGroupMembershipData(ctx context.Context) <-chan AzureResult[azure.GroupMembershipData] { | ||
| out := make(chan AzureResult[azure.GroupMembershipData]) | ||
|
|
||
| go func() { | ||
| defer close(out) | ||
|
|
||
| // Use existing ListAzureADGroups method | ||
| groups := s.ListAzureADGroups(ctx, query.GraphParams{}) | ||
|
|
||
| for groupResult := range groups { | ||
| if groupResult.Error != nil { | ||
| out <- AzureResult[azure.GroupMembershipData]{Error: groupResult.Error} | ||
| continue | ||
| } | ||
|
|
||
| group := groupResult.Ok | ||
|
|
||
| // Use existing ListAzureADGroupMembers method - fix field name | ||
| members := s.ListAzureADGroupMembers(ctx, group.Id, query.GraphParams{}) | ||
|
|
||
| var membersList []json.RawMessage | ||
| for memberResult := range members { | ||
| if memberResult.Error != nil { | ||
| continue // Skip individual member errors | ||
| } | ||
| membersList = append(membersList, memberResult.Ok) | ||
| } | ||
|
|
||
| // Use existing ListAzureADGroupOwners method - fix field name | ||
| owners := s.ListAzureADGroupOwners(ctx, group.Id, query.GraphParams{}) | ||
|
|
||
| var ownersList []json.RawMessage | ||
| for ownerResult := range owners { | ||
| if ownerResult.Error != nil { | ||
| continue // Skip individual owner errors | ||
| } | ||
| ownersList = append(ownersList, ownerResult.Ok) | ||
| } | ||
|
|
||
| groupData := azure.GroupMembershipData{ | ||
| Group: group, | ||
| Members: membersList, | ||
| Owners: ownersList, | ||
| } | ||
|
|
||
| out <- AzureResult[azure.GroupMembershipData]{Ok: groupData} | ||
| } | ||
| }() | ||
|
|
||
| return out | ||
| } | ||
|
|
||
| // CollectUserRoleAssignments - Collect user rights assignments from Graph API | ||
| func (s *azureClient) CollectUserRoleAssignments(ctx context.Context) <-chan AzureResult[azure.UserRoleData] { | ||
| out := make(chan AzureResult[azure.UserRoleData]) | ||
|
|
||
| go func() { | ||
| defer close(out) | ||
|
|
||
| // Use existing ListAzureADUsers method | ||
| users := s.ListAzureADUsers(ctx, query.GraphParams{}) | ||
|
|
||
| for userResult := range users { | ||
| if userResult.Error != nil { | ||
| out <- AzureResult[azure.UserRoleData]{Error: userResult.Error} | ||
| continue | ||
| } | ||
|
|
||
| user := userResult.Ok | ||
|
|
||
| // Get app role assignments for this user - fix field name | ||
| roleAssignments := s.ListUserAppRoleAssignments(ctx, user.Id, query.GraphParams{}) | ||
|
|
||
| var assignments []azure.AppRoleAssignment | ||
| for assignmentResult := range roleAssignments { | ||
| if assignmentResult.Error != nil { | ||
| continue // Skip individual assignment errors | ||
| } | ||
| assignments = append(assignments, assignmentResult.Ok) | ||
| } | ||
|
|
||
| userData := azure.UserRoleData{ | ||
| User: user, | ||
| RoleAssignments: assignments, | ||
| } | ||
|
|
||
| out <- AzureResult[azure.UserRoleData]{Ok: userData} | ||
| } | ||
| }() | ||
|
|
||
| return out | ||
| } | ||
|
|
||
| // CollectDeviceAccessData - Collect device access and ownership data | ||
| func (s *azureClient) CollectDeviceAccessData(ctx context.Context) <-chan AzureResult[azure.DeviceAccessData] { | ||
| out := make(chan AzureResult[azure.DeviceAccessData]) | ||
|
|
||
| go func() { | ||
| defer close(out) | ||
|
|
||
| // Get all Intune devices | ||
| devices := s.ListIntuneDevices(ctx, query.GraphParams{}) | ||
|
|
||
| for deviceResult := range devices { | ||
| if deviceResult.Error != nil { | ||
| out <- AzureResult[azure.DeviceAccessData]{Error: deviceResult.Error} | ||
| continue | ||
| } | ||
|
|
||
| device := deviceResult.Ok | ||
|
|
||
| // Try to find corresponding Azure AD device using existing method | ||
| azureDevices := s.ListAzureDevices(ctx, query.GraphParams{ | ||
| Filter: fmt.Sprintf("deviceId eq '%s'", device.AzureADDeviceID), | ||
| }) | ||
|
|
||
| var azureDevice *azure.Device | ||
| for azureDeviceResult := range azureDevices { | ||
| if azureDeviceResult.Error == nil { | ||
| deviceData := azureDeviceResult.Ok | ||
| azureDevice = &deviceData | ||
| break | ||
| } | ||
| } | ||
|
|
||
| var registeredUsers []json.RawMessage | ||
| var registeredOwners []json.RawMessage | ||
|
|
||
| if azureDevice != nil { | ||
| // Get registered users - fix field name | ||
| users := s.GetDeviceRegisteredUsers(ctx, azureDevice.Id, query.GraphParams{}) | ||
| for userResult := range users { | ||
| if userResult.Error == nil { | ||
| registeredUsers = append(registeredUsers, userResult.Ok) | ||
| } | ||
| } | ||
|
|
||
| // Get registered owners - fix field name | ||
| owners := s.GetDeviceRegisteredOwners(ctx, azureDevice.Id, query.GraphParams{}) | ||
| for ownerResult := range owners { | ||
| if ownerResult.Error == nil { | ||
| registeredOwners = append(registeredOwners, ownerResult.Ok) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| deviceAccessData := azure.DeviceAccessData{ | ||
| IntuneDevice: device, | ||
| AzureDevice: azureDevice, | ||
| RegisteredUsers: registeredUsers, | ||
| RegisteredOwners: registeredOwners, | ||
| } | ||
|
|
||
| out <- AzureResult[azure.DeviceAccessData]{Ok: deviceAccessData} | ||
| } | ||
| }() | ||
|
|
||
| return out | ||
| } | ||
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.