-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentra.go
More file actions
55 lines (49 loc) · 2.14 KB
/
entra.go
File metadata and controls
55 lines (49 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package cmd
import (
"strings"
"github.com/Method-Security/methodazure/internal/entra"
"github.com/spf13/cobra"
)
// InitEntraCommand initializes the `methodazure entra` subcommand that deals with enumerating Entra related resources in the Azure environment.
func (a *MethodAzure) InitEntraCommand() {
entraCmd := &cobra.Command{
Use: "entra",
Short: "Audit and command Azure Entra ID",
Long: `Audit and command Azure Entra ID`,
}
enumerateCmd := &cobra.Command{
Use: "enumerate",
Short: "Enumerate Entra ID users, groups, and service principals in a given Tenant",
Long: `Enumerate Entra ID users, groups, and service principals in a given Tenant`,
Run: func(cmd *cobra.Command, args []string) {
// If the graph-service-endpoint flag is not set, default to the --cloud-config mapped value
graphServiceEndpoint, err := cmd.Flags().GetString("graph-service-endpoint")
if err != nil {
errorMessage := err.Error()
a.OutputSignal.ErrorMessage = &errorMessage
a.OutputSignal.Status = 1
return
}
if graphServiceEndpoint == "" {
if strings.Contains(a.AzureConfig.CloudConfig.ActiveDirectoryAuthorityHost, ".com") {
graphServiceEndpoint = "https://graph.microsoft.com/.default"
} else if strings.Contains(a.AzureConfig.CloudConfig.ActiveDirectoryAuthorityHost, ".us") {
graphServiceEndpoint = "https://graph.microsoft.us/.default"
} else if strings.Contains(a.AzureConfig.CloudConfig.ActiveDirectoryAuthorityHost, ".cn") {
graphServiceEndpoint = "https://microsoftgraph.chinacloudapi.cn/.default"
}
}
a.AzureConfig.GraphServiceEndpoint = graphServiceEndpoint
report, err := entra.EnumerateEntra(cmd.Context(), a.AzureConfig)
if err != nil {
errorMessage := err.Error()
a.OutputSignal.ErrorMessage = &errorMessage
a.OutputSignal.Status = 1
}
a.OutputSignal.Content = report
},
}
enumerateCmd.PersistentFlags().StringP("graph-service-endpoint", "g", "", "Scope of Microsoft Graph Service Endpoint (e.g. https://graph.microsoft.com/.default), this is automatically defaulted based on --cloud-config value")
entraCmd.AddCommand(enumerateCmd)
a.RootCmd.AddCommand(entraCmd)
}