Skip to content

Commit

Permalink
Fix gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
silverhack committed May 25, 2023
1 parent 34139be commit 7cd95c1
Show file tree
Hide file tree
Showing 8 changed files with 822 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ monkey-reports*
__azurite_db_queue__.json
__azurite_db_queue_extent__.json

site/

*.csv
*bak
*.ps1.bak
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Function Get-MonkeyCSOMSite{
<#
.SYNOPSIS
Get site from SharePoint Online
.DESCRIPTION
Get site from SharePoint Online
.INPUTS
.OUTPUTS
.EXAMPLE
.NOTES
Author : Juan Garrido
Twitter : @tr1ana
File Name : Get-MonkeyCSOMSite
Version : 1.0
.LINK
https://github.com/silverhack/monkey365
#>
[cmdletbinding()]
Param (
[parameter(Mandatory=$True, HelpMessage="Authentication object")]
[Object]$Authentication,

[parameter(Mandatory=$False, HelpMessage="Endpoint")]
[String]$Endpoint,

[Parameter(Mandatory= $false, ParameterSetName = 'Includes', HelpMessage="Includes")]
[string[]]$Includes
)
Begin{
$select_all_properties = @(
'Folder','Lists',
'RoleDefinitionBindings',
'Member','ParentList',
'RoleAssignments','File',
'RootFolder','Webs'
)
#Set False
$Verbose = $Debug = $False;
$InformationAction = 'SilentlyContinue'
if($PSBoundParameters.ContainsKey('Verbose') -and $PSBoundParameters.Verbose){
$Verbose = $True
}
if($PSBoundParameters.ContainsKey('Debug') -and $PSBoundParameters.Debug){
$Debug = $True
}
if($PSBoundParameters.ContainsKey('InformationAction')){
$InformationAction = $PSBoundParameters['InformationAction']
}
#Get Site
[xml]$body_data = '<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="Monkey 365" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="2" ObjectPathId="1"/><ObjectPath Id="4" ObjectPathId="3"/><Query Id="5" ObjectPathId="3"><Query SelectAllProperties="true"></Query></Query></Actions><ObjectPaths><StaticProperty Id="1" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current"/><Property Id="3" ParentId="1" Name="Site"/></ObjectPaths></Request>'
#Set properties
$properties = $body_data.CreateElement("Properties", $body_data.NamespaceURI)
#Check if includes
if($PSCmdlet.ParameterSetName -eq 'Includes'){
foreach($include in $Includes){
$prop = $body_data.CreateNode([System.Xml.XmlNodeType]::Element, $body_data.Prefix, 'Property', $body_data.NamespaceURI);
#Set attributes
[void]$prop.SetAttribute('Name',$include)
if($include -in $select_all_properties){
[void]$prop.SetAttribute('SelectAll','true')
}
else{
[void]$prop.SetAttribute('ScalarProperty','true')
}
[void]$properties.AppendChild($prop)
}
}
[void]$body_data.Request.Actions.Query.Query.AppendChild($properties)
[xml]$body_data = $body_data.OuterXml.Replace(" xmlns=`"`"", "")
}
Process{
$p = @{
Authentication = $Authentication;
Data = $body_data;
Endpoint = $Endpoint;
Verbose = $Verbose;
Debug = $Debug;
InformationAction = $InformationAction;
}
#Execute query
$raw_sps_site = Invoke-MonkeyCSOMRequest @p
}
End{
if($raw_sps_site){
return $raw_sps_site
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


Function Get-MonkeyCSOMSiteAccessRequest{
<#
.SYNOPSIS
Get Sharepoint Online site access request
.DESCRIPTION
Get Sharepoint Online site access request
.INPUTS
.OUTPUTS
.EXAMPLE
.NOTES
Author : Juan Garrido
Twitter : @tr1ana
File Name : Get-MonkeyCSOMSiteAccessRequest
Version : 1.0
.LINK
https://github.com/silverhack/monkey365
#>

[cmdletbinding()]
[OutputType([System.Collections.Generic.List[System.Management.Automation.PSObject]])]
Param (
[Parameter(Mandatory= $true, HelpMessage="Authentication Object")]
[Object]$Authentication,

[Parameter(Mandatory= $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage="SharePoint Web Object")]
[Object]$Web
)
Begin{
#Set generic list
$siteAccessList = [System.Collections.Generic.List[System.Management.Automation.PSObject]]::new()
}
Process{
#Check for objectType
if ($Web.psobject.properties.Item('_ObjectType_') -and $Web._ObjectType_ -eq 'SP.Web'){
$access_request = $null;
#Get Lists
$p = @{
Authentication = $Authentication;
ClientObject = $Web;
Properties = 'Lists';
Endpoint = $Web.Url;
InformationAction = $O365Object.InformationAction;
Verbose = $O365Object.verbose;
Debug = $O365Object.debug;
}
$all_lists = Get-MonkeyCSOMProperty @p
if($all_lists){
#Get access request list
$access_request = $all_lists.Lists | Where-Object { $_.Title -eq 'Access Requests' }
}
if($null -ne $access_request){
foreach($ar in @($access_request)){
#Getting access requests
$msg = @{
MessageData = ($message.SPSCheckSiteAccessRequests -f $Web.Url);
callStack = (Get-PSCallStack | Select-Object -First 1);
logLevel = 'verbose';
InformationAction = $O365Object.InformationAction;
Verbose = $O365Object.verbose;
Tags = @('SPSAccessRequestInfo');
}
Write-Verbose @msg
$p = @{
Authentication = $Authentication;
List = $ar;
Endpoint = $Web.Url;
InformationAction = $O365Object.InformationAction;
Verbose = $O365Object.verbose;
Debug = $O365Object.debug;
}
$access_list = Get-MonkeyCSOMListItem @p
if($null -ne $access_list){
foreach($access in @($access_list)){
$access_dict = [ordered]@{
Title = $access.Title;
Message = $access.Conversation;
RequestedObjectUrl = $access.RequestedObjectUrl.Url;
RequestedObjectTitle = $access.RequestedObjectTitle;
RequestedBy = $access.RequestedBy;
RequestedFor = $access.RequestedFor;
RequestDate = $access.RequestDate;
Expires = $access.Expires;
Status = [ChangeRequestStatus]$access.Status;
PermissionType = $access.PermissionType;
IsInvitation = $access.IsInvitation;
RawObject = $access;
}
#Add to List
$accessListObject = New-Object PSObject -Property $access_dict
[void]$siteAccessList.Add($accessListObject)
}
}
}
}
}
else{
$msg = @{
MessageData = ($message.SPOInvalieWebObjectMessage);
callStack = (Get-PSCallStack | Select-Object -First 1);
logLevel = 'Warning';
InformationAction = $InformationAction;
Tags = @('SPOInvalidWebObject');
}
Write-Warning @msg
}
}
End{
#return list
#return , $siteAccessList
Write-Output $siteAccessList -NoEnumerate
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Function Get-MonkeyCSOMSiteCollectionAdministrator{
<#
.SYNOPSIS
Get site collection administrators from SharePoint Online
.DESCRIPTION
Get site collection administrators from SharePoint Online
.INPUTS
.OUTPUTS
.EXAMPLE
.NOTES
Author : Juan Garrido
Twitter : @tr1ana
File Name : Get-MonkeyCSOMSiteCollectionAdministrator
Version : 1.0
.LINK
https://github.com/silverhack/monkey365
#>
[cmdletbinding()]
[OutputType([System.Collections.Generic.List[System.Management.Automation.PSObject]])]
Param (
[parameter(Mandatory=$True, HelpMessage="Authentication object")]
[Object]$Authentication,

[parameter(Mandatory=$True, HelpMessage="SPO Web")]
[Object]$Web
)
Begin{
#Get Site
[xml]$body_data = '<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="Monkey 365" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="6" ObjectPathId="5" /><Query Id="7" ObjectPathId="5"><Query SelectAllProperties="false"><Properties /></Query><ChildItemQuery SelectAllProperties="false"><Properties><Property Name="Id" ScalarProperty="true" /><Property Name="Title" ScalarProperty="true" /><Property Name="LoginName" ScalarProperty="true" /><Property Name="Email" ScalarProperty="true" /><Property Name="IsShareByEmailGuestUser" ScalarProperty="true" /><Property Name="IsSiteAdmin" ScalarProperty="true" /><Property Name="UserId" ScalarProperty="true" /><Property Name="IsHiddenInUI" ScalarProperty="true" /><Property Name="PrincipalType" ScalarProperty="true" /><Property Name="Alerts"><Query SelectAllProperties="false"><Properties /></Query><ChildItemQuery SelectAllProperties="false"><Properties><Property Name="Title" ScalarProperty="true" /><Property Name="Status" ScalarProperty="true" /></Properties></ChildItemQuery></Property><Property Name="Groups"><Query SelectAllProperties="false"><Properties /></Query><ChildItemQuery SelectAllProperties="false"><Properties><Property Name="Id" ScalarProperty="true" /><Property Name="Title" ScalarProperty="true" /><Property Name="LoginName" ScalarProperty="true" /></Properties></ChildItemQuery></Property></Properties><QueryableExpression><Where><Test><Parameters><Parameter Name="u" /></Parameters><Body><ExpressionProperty Name="IsSiteAdmin"><ExpressionParameter Name="u" /></ExpressionProperty></Body></Test><Object><QueryableObject /></Object></Where></QueryableExpression></ChildItemQuery></Query></Actions><ObjectPaths><Property Id="5" ParentId="3" Name="SiteUsers" /><Property Id="3" ParentId="1" Name="Web" /><StaticProperty Id="1" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current" /></ObjectPaths></Request>'
#Set generic list
$siteAdminCollection = New-Object System.Collections.Generic.List[System.Management.Automation.PSObject]
}
Process{
$effectiveUsers = $all_users = $null
#Check for objectType
if ($Web.psobject.properties.Item('_ObjectType_') -and $Web._ObjectType_ -eq 'SP.Web'){
$p = @{
Authentication = $Authentication;
Data = $body_data;
ChildItems = $True;
Endpoint = $Web.Url;
InformationAction = $O365Object.InformationAction;
Verbose = $O365Object.verbose;
Debug = $O365Object.debug;
}
#Execute query
$siteAdmins = Invoke-MonkeyCSOMRequest @p
if($siteAdmins){
$p = @{
Groups = $siteAdmins;
InformationAction = $O365Object.InformationAction;
Verbose = $O365Object.verbose;
Debug = $O365Object.debug;
}
#Execute query
$all_admins = Resolve-MonkeyCSOMToM365GroupMember @p
if($null -ne $all_admins){
[array]$all_users = $all_admins | Where-Object { $_.principalType -eq [PrincipalType]::User }
#Add group members
[array]$effectiveUsers = $all_admins | Where-Object { $_.principalType -eq [PrincipalType]::SecurityGroup } | Select-Object -ExpandProperty Members -ErrorAction Ignore
$rest_users = @()
if($null -ne $all_users -and $null -ne $effectiveUsers){
#Check email
foreach($user in @($all_users)){
$match = $effectiveUsers | Where-Object {$_.UserPrincipalName -eq $user.Email} -ErrorAction Ignore
if($null -eq $match){
#Add user
$rest_users+=$user;
}
}
if($rest_users.Count -gt 0){
$effectiveUsers+=$rest_users
}
}
else{
if($all_users){
$effectiveUsers = $all_users
}
}
$site_admins = [pscustomobject]@{
site = $Web.Url;
Title = $Web.Title;
users = ($all_admins | Where-Object { $_.principalType -eq [PrincipalType]::User })
aad_groups = ($all_admins | Where-Object { $_.principalType -eq [PrincipalType]::SecurityGroup })
effective_users = $effectiveUsers;
raw = $all_admins;
}
#Add to list
[void]$siteAdminCollection.Add($site_admins)
}
}
}
else{
$msg = @{
MessageData = ($message.SPOInvalieWebObjectMessage);
callStack = (Get-PSCallStack | Select-Object -First 1);
logLevel = 'Warning';
InformationAction = $InformationAction;
Tags = @('SPOInvalidWebObject');
}
Write-Warning @msg
}
}
End{
#return , $siteAdminCollection
Write-Output $siteAdminCollection -NoEnumerate
}
}
Loading

0 comments on commit 7cd95c1

Please sign in to comment.