Skip to content

Commit 26c9bfa

Browse files
committed
update gitignore
1 parent 2c64bd9 commit 26c9bfa

10 files changed

Lines changed: 1154 additions & 6 deletions

.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
# logs
2-
azurereview.log
32
/log/*.log
43

54
# Data folder
65
monkey-reports*
76

8-
# Azurite
9-
__azurite_db_queue__.json
10-
__azurite_db_queue_extent__.json
11-
12-
site/
137
*.csv
148
*bak
159
*.ps1.bak
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
Function Get-MonkeyCSOMSite{
16+
<#
17+
.SYNOPSIS
18+
Get site from SharePoint Online
19+
20+
.DESCRIPTION
21+
Get site from SharePoint Online
22+
23+
.INPUTS
24+
25+
.OUTPUTS
26+
27+
.EXAMPLE
28+
29+
.NOTES
30+
Author : Juan Garrido
31+
Twitter : @tr1ana
32+
File Name : Get-MonkeyCSOMSite
33+
Version : 1.0
34+
35+
.LINK
36+
https://github.com/silverhack/monkey365
37+
#>
38+
[cmdletbinding()]
39+
Param (
40+
[parameter(Mandatory=$False, HelpMessage="Authentication object")]
41+
[Object]$Authentication,
42+
43+
[parameter(Mandatory=$False, HelpMessage="Endpoint")]
44+
[String]$Endpoint,
45+
46+
[parameter(Mandatory=$false, HelpMessage="All SharePoint web objects")]
47+
[Switch]$All,
48+
49+
[Parameter(Mandatory= $false, ParameterSetName = 'Includes', HelpMessage="Includes")]
50+
[string[]]$Includes
51+
)
52+
Begin{
53+
$select_all_properties = @(
54+
'Folder','Lists',
55+
'RoleDefinitionBindings',
56+
'Member','ParentList',
57+
'RoleAssignments','File',
58+
'RootFolder','Webs',
59+
'CustomScriptSafeDomains'
60+
)
61+
#Get Site
62+
[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>'
63+
#Set properties
64+
$properties = $body_data.CreateElement("Properties", $body_data.NamespaceURI)
65+
#Check if includes
66+
if($PSCmdlet.ParameterSetName -eq 'Includes'){
67+
foreach($include in $Includes){
68+
$prop = $body_data.CreateNode([System.Xml.XmlNodeType]::Element, $body_data.Prefix, 'Property', $body_data.NamespaceURI);
69+
#Set attributes
70+
[void]$prop.SetAttribute('Name',$include)
71+
if($include -in $select_all_properties){
72+
[void]$prop.SetAttribute('SelectAll','true')
73+
}
74+
else{
75+
[void]$prop.SetAttribute('ScalarProperty','true')
76+
}
77+
[void]$properties.AppendChild($prop)
78+
}
79+
}
80+
[void]$body_data.Request.Actions.Query.Query.AppendChild($properties)
81+
[xml]$body_data = $body_data.OuterXml.Replace(" xmlns=`"`"", "")
82+
}
83+
Process{
84+
if($PSBoundParameters.ContainsKey('All') -and $PSBoundParameters['All'].IsPresent){
85+
$p = Set-CommandParameter -Command "Get-MonkeyCSOMSiteProperty" -Params $PSBoundParameters
86+
$Urls = @(Get-MonkeyCSOMSiteProperty @p).Where({$_.Template -notlike "SRCHCEN#0" -and $_.Template -notlike "SPSMSITEHOST*" -and $_.Template -notlike "RedirectSite#0"}) | Select-Object -ExpandProperty Url -ErrorAction Ignore
87+
#$Urls = Get-MonkeyCSOMSiteProperty @p | Select-Object -ExpandProperty Url -ErrorAction Ignore
88+
if($null -ne $Urls){
89+
#Remove All param
90+
[void]$PSBoundParameters.Remove('All');
91+
@($Urls).ForEach({Get-MonkeyCSOMSite -Endpoint $_ @PSBoundParameters}).Where({$null -ne $_})
92+
}
93+
}
94+
Else{
95+
$p = Set-CommandParameter -Command "Invoke-MonkeyCSOMRequest" -Params $PSBoundParameters
96+
#Add authentication header if missing
97+
if(!$p.ContainsKey('Authentication')){
98+
if($null -ne $O365Object.auth_tokens.SharePointOnline){
99+
[void]$p.Add('Authentication',$O365Object.auth_tokens.SharePointOnline);
100+
}
101+
Else{
102+
Write-Warning -Message ($message.NullAuthenticationDetected -f "SharePoint Online")
103+
break
104+
}
105+
}
106+
#Add post Data
107+
[void]$p.Add('Data',$body_data);
108+
#Execute query
109+
Invoke-MonkeyCSOMRequest @p
110+
}
111+
}
112+
End{
113+
#Nothing to do here
114+
}
115+
}
116+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
Function Get-MonkeyCSOMSiteAccessRequest{
17+
<#
18+
.SYNOPSIS
19+
Get Sharepoint Online site access request
20+
21+
.DESCRIPTION
22+
Get Sharepoint Online site access request
23+
24+
.INPUTS
25+
26+
.OUTPUTS
27+
28+
.EXAMPLE
29+
30+
.NOTES
31+
Author : Juan Garrido
32+
Twitter : @tr1ana
33+
File Name : Get-MonkeyCSOMSiteAccessRequest
34+
Version : 1.0
35+
36+
.LINK
37+
https://github.com/silverhack/monkey365
38+
#>
39+
40+
[CmdletBinding(DefaultParameterSetName = 'Current')]
41+
Param (
42+
[parameter(Mandatory=$true, ParameterSetName = 'Web', ValueFromPipeline = $true, HelpMessage="Web Object")]
43+
[Object]$Web,
44+
45+
[Parameter(Mandatory= $false, HelpMessage="Authentication Object")]
46+
[Object]$Authentication,
47+
48+
[parameter(Mandatory=$true, ParameterSetName = 'Endpoint', HelpMessage="SharePoint Url")]
49+
[Object]$Endpoint
50+
)
51+
Process{
52+
try{
53+
If($PSCmdlet.ParameterSetName -eq "Current" -or $PSCmdlet.ParameterSetName -eq "Endpoint"){
54+
$p = Set-CommandParameter -Command "Get-MonkeyCSOMWeb" -Params $PSBoundParameters
55+
$_Web = Get-MonkeyCSOMWeb @p
56+
if($_Web){
57+
#Remove Endpoint if exists
58+
[void]$PSBoundParameters.Remove('Endpoint');
59+
$_Web | Get-MonkeyCSOMSiteAccessRequest @PSBoundParameters
60+
return
61+
}
62+
}
63+
foreach($_Web in @($Web)){
64+
#Check for objectType
65+
$objectType = $_Web | Select-Object -ExpandProperty _ObjectType_ -ErrorAction Ignore
66+
if ($null -ne $objectType -and $objectType -eq 'SP.Web'){
67+
If(($_Web | Test-HasUniqueRoleAssignment)){
68+
#Set command parameters
69+
$p = Set-CommandParameter -Command "Get-MonkeyCSOMList" -Params $PSBoundParameters
70+
#Add Filter
71+
[void]$p.Add('Filter','Access Requests');
72+
#Add Web
73+
$p.Item('Web') = $_Web
74+
#Execute query
75+
$arList = Get-MonkeyCSOMList @p
76+
if($null -ne $arList){
77+
#Set command parameters
78+
$p = Set-CommandParameter -Command "Get-MonkeyCSOMListItem" -Params $PSBoundParameters
79+
#Add List
80+
$p.Item('List') = $arList;
81+
$access_requests = Get-MonkeyCSOMListItem @p
82+
if($null -ne $access_requests){
83+
$access_requests | New-MonkeyCSOMSiteAccesRequestObject
84+
}
85+
}
86+
}
87+
}
88+
Else{
89+
$msg = @{
90+
MessageData = ($message.SPOInvalidWebObjectMessage);
91+
callStack = (Get-PSCallStack | Select-Object -First 1);
92+
logLevel = 'Warning';
93+
InformationAction = $O365Object.InformationAction;
94+
Tags = @('MonkeyCSOMInvalidWebObject');
95+
}
96+
Write-Warning @msg
97+
}
98+
}
99+
}
100+
Catch{
101+
Write-Error $_
102+
}
103+
}
104+
}
105+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
Function Get-MonkeyCSOMSiteCollectionAdministrator{
16+
<#
17+
.SYNOPSIS
18+
Get site collection administrators from SharePoint Online
19+
20+
.DESCRIPTION
21+
Get site collection administrators from SharePoint Online
22+
23+
.INPUTS
24+
25+
.OUTPUTS
26+
27+
.EXAMPLE
28+
29+
.NOTES
30+
Author : Juan Garrido
31+
Twitter : @tr1ana
32+
File Name : Get-MonkeyCSOMSiteCollectionAdministrator
33+
Version : 1.0
34+
35+
.LINK
36+
https://github.com/silverhack/monkey365
37+
#>
38+
[CmdletBinding(DefaultParameterSetName = 'Current')]
39+
#[OutputType([System.Collections.Generic.List[System.Management.Automation.PSObject]])]
40+
Param (
41+
[parameter(Mandatory=$false, HelpMessage="Authentication Object")]
42+
[Object]$Authentication,
43+
44+
[parameter(Mandatory=$false, ParameterSetName = 'Site', ValueFromPipeline = $true, HelpMessage="Web Object")]
45+
[Object]$Site,
46+
47+
[parameter(Mandatory=$false, ParameterSetName = 'Endpoint', HelpMessage="SharePoint Url")]
48+
[Object]$Endpoint
49+
)
50+
Begin{
51+
#Get Site
52+
[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>'
53+
}
54+
Process{
55+
If($PSCmdlet.ParameterSetName -eq "Endpoint" -or $PSCmdlet.ParameterSetName -eq "Current"){
56+
$p = Set-CommandParameter -Command "Get-MonkeyCSOMSite" -Params $PSBoundParameters
57+
$_Site = Get-MonkeyCSOMSite @p
58+
if($_Site){
59+
$_Site | Get-MonkeyCSOMSiteCollectionAdministrator @PSBoundParameters
60+
}
61+
}
62+
}
63+
End{
64+
foreach($_Site in @($PSBoundParameters['Site']).Where({$null -ne $_})){
65+
$objectType = $_Site | Select-Object -ExpandProperty _ObjectType_ -ErrorAction Ignore
66+
if ($null -ne $objectType -and $objectType -eq 'SP.Site'){
67+
#Set command parameters
68+
$p = Set-CommandParameter -Command "Invoke-MonkeyCSOMRequest" -Params $PSBoundParameters
69+
#Add authentication header if missing
70+
if(!$p.ContainsKey('Authentication')){
71+
if($null -ne $O365Object.auth_tokens.SharePointOnline){
72+
[void]$p.Add('Authentication',$O365Object.auth_tokens.SharePointOnline);
73+
}
74+
Else{
75+
Write-Warning -Message ($message.NullAuthenticationDetected -f "SharePoint Online")
76+
break
77+
}
78+
}
79+
#Update EndPoint
80+
$p.Item('Endpoint') = $_Site.Url;
81+
#Add Data
82+
[void]$p.Add('Data',$body_data);
83+
#Execute query
84+
$members = Invoke-MonkeyCSOMRequest @p
85+
$objectType = $members | Select-Object -ExpandProperty _ObjectType_ -ErrorAction Ignore
86+
if ($null -ne $objectType -and $objectType -eq 'SP.UserCollection'){
87+
$p = Set-CommandParameter -Command "Resolve-MonkeyCSOMIdentity" -Params $PSBoundParameters
88+
$members._Child_Items_ | Resolve-MonkeyCSOMIdentity @p
89+
}
90+
}
91+
Else{
92+
$msg = @{
93+
MessageData = ($message.SPOInvalidSiteObjectMessage);
94+
callStack = (Get-PSCallStack | Select-Object -First 1);
95+
logLevel = 'Warning';
96+
InformationAction = $O365Object.InformationAction;
97+
Tags = @('MonkeyCSOMInvalidSiteObject');
98+
}
99+
Write-Warning @msg
100+
}
101+
}
102+
}
103+
}
104+

0 commit comments

Comments
 (0)