-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for MSOL Proxy, custom Rules, and $OCCAM environment vari…
…ables (#1) * initial work proxying MSOnline cmdlets Adds functionality that dyanmically builds an MSOnline proxy module that wraps each MSOnline function, strips the `-TenantId` param, and auto-fills it so that rule evaluation can just use the `Get-MsolUser` or similar cmdlets and have it automatically scoped to the tenant ID * Add support for MSOnline proxying and $OCCAM environment variables * Refactor MSOL Proxy as a dynamic in-memory module The MSOL proxy module previously worked by saving all portions of the module to disk and then importing it. This required clean up after the fact and was unneccessary. Now, it uses PowerShell's Dynamic Module feature to store everything in memory. * Add rule for finding users with non-default authentication policy also remove old reference to cleaning up tmp directory * Add support for custom rule files OCCAM now parses any files ending in `.Rule.ps1` while building the ruleset * Update auth policy users rule * Update Find-ExplicitAuthPolicyUsers.Rule.ps1 Made more robust
- Loading branch information
1 parent
dc4e59a
commit 3df6a7a
Showing
11 changed files
with
214 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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,4 @@ | ||
.DS_Store | ||
Thumbs.db | ||
|
||
Office365**/ |
This file contains 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 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,48 @@ | ||
function Build-MsolProxy { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[System.Guid]$TenantId | ||
) | ||
|
||
$commands = Get-Command -Module MSOnline | ||
|
||
$functionsToExport = @() | ||
|
||
foreach ($command in $commands) { | ||
$metadata = New-Object System.Management.Automation.CommandMetaData $command | ||
|
||
# remove TenantId from command metadata | ||
$hasTenantIdParam = $metadata.Parameters.ContainsKey("TenantId") | ||
if ($hasTenantIdParam) { | ||
$metadata.Parameters.Remove("TenantId") | Out-Null | ||
} | ||
|
||
# create a proxy function that wraps the initial MSOnline cmdlet | ||
$proxy = [System.Management.Automation.ProxyCommand]::Create($metadata) | ||
|
||
# string-replace the PSBoundParameters splat operation to insert the -TenantId parameter | ||
# into the underlying command being called/wrapped | ||
if ($hasTenantIdParam) { | ||
$proxy = $proxy -replace '@PSBoundParameters', ('@PSBoundParameters -TenantId {0}' -f $TenantId) | ||
} | ||
|
||
# Pack the internals as a function | ||
$proxyAsFunction = "function $($command.Name) { `n $proxy `n }" | ||
|
||
# Append the full proxy function as a string onto an array | ||
$functionsToExport += $proxyAsFunction | ||
} | ||
|
||
# Concatenate all functions into one large string with new lines separating each | ||
$ScriptString = ($functionsToExport -join("`n")) | ||
|
||
# Convert the string to a scriptblock | ||
$ScriptBlock = [Scriptblock]::Create($ScriptString) | ||
|
||
# Load the proxy functions as a dynamic module into memory, and pipe to | ||
# the Import-Module command so we can clean it up with Remove-Module later | ||
New-Module -Name "MSOL_$TenantId" -ScriptBlock $ScriptBlock | Import-Module | ||
|
||
return "MSOL_$TenantId" | ||
} |
This file contains 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 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 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 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,43 @@ | ||
<# | ||
.SYNOPSIS | ||
Report users assigned an explicit authentication policy | ||
.OUTPUTS | ||
#> | ||
function Find-ExplicitAuthPolicyUsers { | ||
param () | ||
Begin { | ||
$Users = @(Get-User -ResultSize Unlimited) | ||
|
||
$Properties = @( | ||
"UserPrincipalName", | ||
"DisplayName", | ||
"AuthenticationPolicy", | ||
"AccountDisabled", | ||
"Guid", | ||
"SID" | ||
) | ||
} | ||
Process { | ||
|
||
# Find users without the default authentication policy | ||
$NonDefaultAuthPolicyUsers = $Users | Where-Object { [string]::IsNullOrEmpty($_.AuthenticationPolicy) } | ||
|
||
# Filter out only select properties | ||
$NonDefaultAuthPolicyUsers = $NonDefaultAuthPolicyUsers | Select-Object -Property $Properties | ||
|
||
if ($NonDefaultAuthPolicyUsers.Count) { | ||
# Create an output directory and export as CSV | ||
New-Item -ItemType Directory -Force -Path $OCCAM:OutputDir | Out-Null | ||
$NonDefaultAuthPolicyUsers | ConvertTo-Csv -NoTypeInformation | Out-File ('{0}/users.csv' -f $OCCAM:OutputDir) -Force | ||
} | ||
|
||
|
||
$output = @{} | ||
|
||
return $output | ||
} | ||
End { | ||
|
||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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