Skip to content

Commit 46e9bca

Browse files
authored
Merge pull request #84 from BloodHoundAD/BED-4586-pt-2
feat: Add --select flag suport to list group-members
2 parents ed6bdf0 + 5e157cf commit 46e9bca

File tree

120 files changed

+893
-4325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+893
-4325
lines changed

client/app_role_assignments.go

+7-83
Original file line numberDiff line numberDiff line change
@@ -20,100 +20,24 @@ package client
2020
import (
2121
"context"
2222
"fmt"
23-
"net/url"
24-
"strings"
2523

2624
"github.com/bloodhoundad/azurehound/v2/client/query"
27-
"github.com/bloodhoundad/azurehound/v2/client/rest"
2825
"github.com/bloodhoundad/azurehound/v2/constants"
2926
"github.com/bloodhoundad/azurehound/v2/models/azure"
30-
"github.com/bloodhoundad/azurehound/v2/panicrecovery"
31-
"github.com/bloodhoundad/azurehound/v2/pipeline"
3227
)
3328

34-
func (s *azureClient) GetAzureADAppRoleAssignments(ctx context.Context, servicePrincipalId string, filter, search, orderBy, expand string, selectCols []string, top int32, count bool) (azure.AppRoleAssignmentList, error) {
29+
// GetAzureADAppRoleAssignments https://learn.microsoft.com/en-us/graph/api/serviceprincipal-list-approleassignedto?view=graph-rest-1.0
30+
func (s *azureClient) ListAzureADAppRoleAssignments(ctx context.Context, servicePrincipalId string, params query.GraphParams) <-chan AzureResult[azure.AppRoleAssignment] {
3531
var (
36-
path = fmt.Sprintf("/%s/servicePrincipals/%s/appRoleAssignedTo", constants.GraphApiVersion, servicePrincipalId)
37-
params = query.Params{Filter: filter, Search: search, OrderBy: orderBy, Select: selectCols, Top: top, Count: count, Expand: expand}
38-
headers map[string]string
39-
response azure.AppRoleAssignmentList
32+
out = make(chan AzureResult[azure.AppRoleAssignment])
33+
path = fmt.Sprintf("/%s/servicePrincipals/%s/appRoleAssignedTo", constants.GraphApiVersion, servicePrincipalId)
4034
)
4135

42-
count = count || search != "" || (filter != "" && orderBy != "") || strings.Contains(filter, "endsWith")
43-
if count {
44-
headers = make(map[string]string)
45-
headers["ConsistencyLevel"] = "eventual"
36+
if params.Top == 0 {
37+
params.Top = 999
4638
}
47-
if res, err := s.msgraph.Get(ctx, path, params.AsMap(), headers); err != nil {
48-
return response, err
49-
} else if err := rest.Decode(res.Body, &response); err != nil {
50-
return response, err
51-
} else {
52-
return response, nil
53-
}
54-
}
55-
56-
func (s *azureClient) ListAzureADAppRoleAssignments(ctx context.Context, servicePrincipal, filter, search, orderBy, expand string, selectCols []string) <-chan azure.AppRoleAssignmentResult {
57-
out := make(chan azure.AppRoleAssignmentResult)
58-
59-
go func() {
60-
defer panicrecovery.PanicRecovery()
61-
defer close(out)
62-
63-
var (
64-
errResult = azure.AppRoleAssignmentResult{}
65-
nextLink string
66-
)
6739

68-
if list, err := s.GetAzureADAppRoleAssignments(ctx, servicePrincipal, filter, search, orderBy, expand, selectCols, 999, false); err != nil {
69-
errResult.Error = err
70-
if ok := pipeline.Send(ctx.Done(), out, errResult); !ok {
71-
return
72-
}
73-
} else {
74-
for _, u := range list.Value {
75-
if ok := pipeline.Send(ctx.Done(), out, azure.AppRoleAssignmentResult{Ok: u}); !ok {
76-
return
77-
}
78-
}
40+
go getAzureObjectList[azure.AppRoleAssignment](s.msgraph, ctx, path, params, out)
7941

80-
nextLink = list.NextLink
81-
for nextLink != "" {
82-
var list azure.AppRoleAssignmentList
83-
if url, err := url.Parse(nextLink); err != nil {
84-
errResult.Error = err
85-
if ok := pipeline.Send(ctx.Done(), out, errResult); !ok {
86-
return
87-
}
88-
nextLink = ""
89-
} else if req, err := rest.NewRequest(ctx, "GET", url, nil, nil, nil); err != nil {
90-
errResult.Error = err
91-
if ok := pipeline.Send(ctx.Done(), out, errResult); !ok {
92-
return
93-
}
94-
nextLink = ""
95-
} else if res, err := s.msgraph.Send(req); err != nil {
96-
errResult.Error = err
97-
if ok := pipeline.Send(ctx.Done(), out, errResult); !ok {
98-
return
99-
}
100-
nextLink = ""
101-
} else if err := rest.Decode(res.Body, &list); err != nil {
102-
errResult.Error = err
103-
if ok := pipeline.Send(ctx.Done(), out, errResult); !ok {
104-
return
105-
}
106-
nextLink = ""
107-
} else {
108-
for _, u := range list.Value {
109-
if ok := pipeline.Send(ctx.Done(), out, azure.AppRoleAssignmentResult{Ok: u}); !ok {
110-
return
111-
}
112-
}
113-
nextLink = list.NextLink
114-
}
115-
}
116-
}
117-
}()
11842
return out
11943
}

0 commit comments

Comments
 (0)