1+ <#
2+ . SYNOPSIS
3+ Checks if the common attachment types filter is comprehensive
4+
5+ . DESCRIPTION
6+ The common attachment types filter should be comprehensive
7+
8+ . EXAMPLE
9+ Test-MtCisAttachmentFilterComprehensive
10+
11+ Returns true if the attachment types match the comprehensive list supplied by CIS
12+
13+ . LINK
14+ https://maester.dev/docs/commands/Test-MtCisAttachmentFilterComprehensive
15+ #>
16+ function Test-MtCisAttachmentFilterComprehensive {
17+ [CmdletBinding ()]
18+ [OutputType ([bool ])]
19+ param ()
20+
21+ if (! (Test-MtConnection ExchangeOnline)) {
22+ Add-MtTestResultDetail - SkippedBecause NotConnectedExchange
23+ return $null
24+ }
25+ elseif (! (Test-MtConnection SecurityCompliance)) {
26+ Add-MtTestResultDetail - SkippedBecause NotConnectedSecurityCompliance
27+ return $null
28+ }
29+
30+ Write-Verbose " Executing checks"
31+
32+ # Set CIS supplied comprehensive extension list
33+ $L2Extensions = @ (
34+ " 7z" , " a3x" , " ace" , " ade" , " adp" , " ani" , " app" , " appinstaller" ,
35+ " applescript" , " application" , " appref-ms" , " appx" , " appxbundle" , " arj" ,
36+ " asd" , " asx" , " bas" , " bat" , " bgi" , " bz2" , " cab" , " chm" , " cmd" , " com" ,
37+ " cpl" , " crt" , " cs" , " csh" , " daa" , " dbf" , " dcr" , " deb" ,
38+ " desktopthemepackfile" , " dex" , " diagcab" , " dif" , " dir" , " dll" , " dmg" ,
39+ " doc" , " docm" , " dot" , " dotm" , " elf" , " eml" , " exe" , " fxp" , " gadget" , " gz" ,
40+ " hlp" , " hta" , " htc" , " htm" , " htm" , " html" , " html" , " hwpx" , " ics" , " img" ,
41+ " inf" , " ins" , " iqy" , " iso" , " isp" , " jar" , " jnlp" , " js" , " jse" , " kext" ,
42+ " ksh" , " lha" , " lib" , " library-ms" , " lnk" , " lzh" , " macho" , " mam" , " mda" ,
43+ " mdb" , " mde" , " mdt" , " mdw" , " mdz" , " mht" , " mhtml" , " mof" , " msc" , " msi" ,
44+ " msix" , " msp" , " msrcincident" , " mst" , " ocx" , " odt" , " ops" , " oxps" , " pcd" ,
45+ " pif" , " plg" , " pot" , " potm" , " ppa" , " ppam" , " ppkg" , " pps" , " ppsm" , " ppt" ,
46+ " pptm" , " prf" , " prg" , " ps1" , " ps11" , " ps11xml" , " ps1xml" , " ps2" ,
47+ " ps2xml" , " psc1" , " psc2" , " pub" , " py" , " pyc" , " pyo" , " pyw" , " pyz" ,
48+ " pyzw" , " rar" , " reg" , " rev" , " rtf" , " scf" , " scpt" , " scr" , " sct" ,
49+ " searchConnector-ms" , " service" , " settingcontent-ms" , " sh" , " shb" , " shs" ,
50+ " shtm" , " shtml" , " sldm" , " slk" , " so" , " spl" , " stm" , " svg" , " swf" , " sys" ,
51+ " tar" , " theme" , " themepack" , " timer" , " uif" , " url" , " uue" , " vb" , " vbe" ,
52+ " vbs" , " vhd" , " vhdx" , " vxd" , " wbk" , " website" , " wim" , " wiz" , " ws" , " wsc" ,
53+ " wsf" , " wsh" , " xla" , " xlam" , " xlc" , " xll" , " xlm" , " xls" , " xlsb" , " xlsm" ,
54+ " xlt" , " xltm" , " xlw" , " xml" , " xnk" , " xps" , " xsl" , " xz" , " z"
55+ )
56+
57+ # Duplicate the array, so we are left with a list of extensions missing at the end
58+ $missingExtensionList = $L2Extensions
59+
60+ Write-Verbose " Getting Attachment Types Filter..."
61+ $policies = Get-MtExo - Request MalwareFilterPolicy
62+
63+ # For each policy, run checks
64+ foreach ($policyId in $policies.Id ) {
65+
66+ # We grab the policy we are checking
67+ $policy = $policies | Where-Object { $_.Id -eq $policyId }
68+
69+ if ($policy.EnableFileFilter -ne " True" ) {
70+ # If the policy isn't enabled, skip
71+ break
72+ }
73+
74+ foreach ($extension in $L2Extensions ) {
75+
76+ $checkResult = $policy | Where-Object { $_.FileTypes -contains $extension }
77+
78+ if ($checkResult ) {
79+
80+ # If the check finds extension, remove it from the list as it is covered
81+ $missingExtensionList = $missingExtensionList | Where-Object { $_ –ne $extension }
82+
83+ }
84+
85+ }
86+
87+ }
88+
89+ $testResult = ($missingExtensionList | Measure-Object ).Count -eq 0
90+
91+ if ($testResult ) {
92+ $testResultMarkdown = " Well done. Your tenant covers all CIS recommended file attachment extensions:`n`n %TestResult%"
93+ }
94+ else {
95+ $testResultMarkdown = " Your tenant does not cover all CIS recommended file attachment extensions:`n`n %TestResult%"
96+ }
97+
98+ $resultMd = " | Extension Name | Result |`n "
99+ $resultMd += " | --- | --- |`n "
100+ foreach ($item in $missingExtensionList ) {
101+ $itemResult = " ❌ Fail"
102+ $resultMd += " | $ ( $item ) | $ ( $itemResult ) |`n "
103+ }
104+
105+ $testResultMarkdown = $testResultMarkdown -replace " %TestResult%" , $resultMd
106+
107+ Add-MtTestResultDetail - Result $testResultMarkdown
108+
109+ return $testResult
110+ }
0 commit comments