-
Notifications
You must be signed in to change notification settings - Fork 8
/
Block-AttachmentExtensions.ps1
173 lines (169 loc) · 2.87 KB
/
Block-AttachmentExtensions.ps1
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File: Block-AttachmentExtensions.ps1
# Purpose: this script will connect to Exchange Online and block a list of
# abused file extensions.
#
# Copyright (c) 2019, jdgregson
# Author: Jonathan Gregson <[email protected]>
. O365-Auth.ps1
$DefaultRuleName = "Blocked Attachments"
$DefaultBlockedExtensions = "ace",
"ade",
"adp",
"ani",
"app",
"appcontent-ms",
"asp",
"bas",
"bat",
"bin",
"cer",
"chm",
"cla",
"class",
"cmd",
"cnt",
"com",
"cpl",
"crt",
"csh",
"der",
"diagcab",
"dll",
"docm",
"dos",
"email",
"exe",
"fxp",
"gadget",
"grp",
"hlp",
"hpj",
"hta",
#"htm",
#"html",
"img",
"inf",
"ins",
"iso",
"isp",
"its",
"jar",
"jnlp",
"js",
"jse",
"ksh",
"lnk",
"mad",
"maf",
"mag",
"mam",
"maq",
"mar",
"mas",
"mat",
"mau",
"mav",
"maw",
"mcf",
"mda",
"mdb",
"mde",
"mdt",
"mdw",
"mdz",
"ms",
"msc",
"msh",
"msh1",
"msh1xml",
"msh2",
"msh2xml",
"mshxml",
"msi",
"msp",
"mst",
"msu",
"obj",
"ocx",
"ops",
"os2",
"osd",
"pcd",
"pif",
"pl",
"plg",
"prf",
"prg",
"printerexport",
"ps1",
"ps1xml",
"ps2",
"ps2xml",
"psc1",
"psc2",
"psd1",
"psdm1",
"pst",
"py",
"pyc",
"pyo",
"pyw",
"pyz",
"pyzw",
"rar",
"rdp",
"reg",
"rtf",
"scf",
"sct",
"settingcontent-ms",
"shb",
"shs",
"theme",
"tmp",
"url",
"vb",
"vbe",
"vbp",
"vbp",
"vbs",
"vhd",
"vhdx",
"vsmacros",
"vsw",
"vxd",
"w16",
"webpnp",
"website",
"ws",
"wsc",
"wsf",
"wsh",
"xbap",
"xll",
"xlsb",
"xlsm",
"xml",
"xnk"
O365-Auth -Exchange
$existingRule = Get-TransportRule $DefaultRuleName -ErrorAction SilentlyContinue
if ($existingRule -eq $null) {
Write-Host "A rule named `"$DefaultRuleName`" was not found. Would you like to create it?"
$confirm = Read-Host "[Y] Yes [N] No (default is `"N`")"
if ($confirm -eq "y") {
$newRule = New-TransportRule -Name $DefaultRuleName `
-FromScope "NotInOrganization" `
-AttachmentExtensionMatchesWords $DefaultBlockedExtensions `
-SetAuditSeverity "High" `
-Quarantine $true `
-StopRuleProcessing $true
Write-Host "The rule `"$DefaultRuleName`" has been created."
} else {
Write-Host "No rules were created or modified."
exit
}
} else {
Set-TransportRule $DefaultRuleName -AttachmentExtensionMatchesWords $DefaultBlockedExtensions
Write-Host "Extension block list has been applied to the rule `"$DefaultRuleName`"."
}