/
office.go
376 lines (350 loc) · 14.8 KB
/
office.go
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// Hardentools
// Copyright (C) 2017-2022 Security Without Borders
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"fmt"
"golang.org/x/sys/windows/registry"
)
// Available office versions.
var standardOfficeVersions = []string{
"12.0", // Office 2007.
"14.0", // Office 2010.
"15.0", // Office 2013.
"16.0", // Office 2016, 2019 and Office365 (local client).
}
// Standard office apps to harden.
var standardOfficeApps = []string{"Excel", "PowerPoint", "Word"}
// OfficeRegistryRegExSingleDWORD is the data type for a RegEx Path / Single
// Value DWORD combination.
type OfficeRegistryRegExSingleDWORD struct {
RootKey registry.Key
PathRegEx string
ValueName string
HardenedValue uint32
OfficeApps []string
OfficeVersions []string
shortName string
longName string
description string
hardenByDefault bool
}
// OfficeOLE hardens Office Packager Objects.
// 0 - No prompt from Office when user clicks, object executes.
// 1 - Prompt from Office when user clicks, object executes.
// 2 - No prompt, Object does not execute.
var OfficeOLE = &OfficeRegistryRegExSingleDWORD{
RootKey: registry.CURRENT_USER,
PathRegEx: "SOFTWARE\\Microsoft\\Office\\%s\\%s\\Security",
ValueName: "PackagerPrompt",
HardenedValue: 2,
OfficeApps: standardOfficeApps,
OfficeVersions: standardOfficeVersions,
shortName: "Office OLE",
longName: "Office Packager Objects (OLE)",
description: "Disables OLE object execution within MS Office.\n" +
"Files that use OLE objects might not work as expected.",
hardenByDefault: true,
}
// OfficeMacros contains Macro registry keys.
// 1 - Enable all.
// 2 - Disable with notification.
// 3 - Digitally signed only.
// 4 - Disable all.
var OfficeMacros = &OfficeRegistryRegExSingleDWORD{
RootKey: registry.CURRENT_USER,
PathRegEx: "SOFTWARE\\Microsoft\\Office\\%s\\%s\\Security",
ValueName: "VBAWarnings",
HardenedValue: 4,
OfficeApps: standardOfficeApps,
OfficeVersions: standardOfficeVersions,
shortName: "Office Macros",
longName: "Office Macros",
description: "Disables macros in MS Office. Files\nthat use macros might not work as expected.",
hardenByDefault: true,
}
// OfficeActiveX contains ActiveX registry keys.
var OfficeActiveX = &RegistrySingleValueDWORD{
RootKey: registry.CURRENT_USER,
Path: "SOFTWARE\\Microsoft\\Office\\Common\\Security",
ValueName: "DisableAllActiveX",
HardenedValue: 1,
shortName: "Office ActiveX",
longName: "Office ActiveX",
description: "Disables ActiveX macros in MS Office. Files\n" +
"that use ActiveX macros might not work as expected.",
hardenByDefault: true,
}
// DDE Mitigations for Word, Outlook and Excel
// Doesn't harden OneNote for now (due to high impact).
//
// Microsoft disabled DDE in Word with Office Update ADV170021 update. We make sure
// that it is in default (disabled) state. This update adds a new Windows registry
// key that controls the DDE feature's status for the Word app. The default value
// disables DDE. Here are registry key's values:
// [HKEY_CURRENT_USER\Software\Microsoft\Office\%s\Word\Security] AllowDDE(DWORD)
// AllowDDE(DWORD) = 0: To disable DDE. This is the default setting after you install the update.
// AllowDDE(DWORD) = 1: To allow DDE requests to an already running program, but prevent DDE requests that require another executable program to be launched.
// AllowDDE(DWORD) = 2: To fully allow DDE requests.
// On 1/9/2018, Microsoft released an update for Microsoft Office that adds defense-in-depth configuration options to selectively disable the DDE protocol in all supported editions of Microsoft Excel.
// If you need to change DDE functionality in Excel after installing the update, follow these steps:
// In the Registry Editor navigate to \HKEY_CURRENT_USER\Software\Microsoft\Office<version>\Excel\Security DisableDDEServerLaunch(DWORD)
// Set the DWORD value based on your requirements as follows:
// DisableDDEServerLaunch = 0: Keep DDE server launch settings unchanged from their initial behavior. This is the default setting after you install the update.
// DisableDDEServerLaunch = 1: Do not display the dialog that allows users to choose whether to launch a specific DDE server. Instead, behave automatically as though the user chose the default choice of NO.
// In the Registry Editor navigate to \HKEY_CURRENT_USER\Software\Microsoft\Office<version>\Excel\Security DisableDDEServerLookup(DWORD)
// Set the DWORD value based on your requirements as follows:
// DisableDDEServerLookup = 0: Keep DDE server lookup settings unchanged from their initial behavior. This is the default setting after you install the update.
// DisableDDEServerLookup = 1: Disable querying for DDE Server availability - no query attempt will be made to find DDE servers. .
//
// [HKEY_CURRENT_USER\Software\Microsoft\Office\%s\Word\Options]
// [HKEY_CURRENT_USER\Software\Microsoft\Office\%s\Word\Options\WordMail] (this one is for Outlook)
// [HKEY_CURRENT_USER\Software\Microsoft\Office\%s\Excel\Options]
// "DontUpdateLinks"=dword:00000001
//
// additionally only for Excel:
// [HKEY_CURRENT_USER\Software\Microsoft\Office\%s\Excel\Options]
// "DDEAllowed"=dword:00000000
// "DDECleaned"=dword:00000001
// "Options"=dword:00000117
// [HKEY_CURRENT_USER\Software\Microsoft\Office\<version>\Excel\Security]
// WorkbookLinkWarnings(DWORD) = 2
//
// for Word&Outlook 2007:
// [HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options\vpref]
// fNoCalclinksOnopen_90_1(DWORD)=1
var (
pathRegExOptions = "SOFTWARE\\Microsoft\\Office\\%s\\%s\\Options"
pathRegExWordMail = "SOFTWARE\\Microsoft\\Office\\%s\\%s\\Options\\WordMail"
pathRegExSecurity = "Software\\Microsoft\\Office\\%s\\%s\\Security"
pathWord2007 = "Software\\Microsoft\\Office\\12.0\\Word\\Options\\vpref"
)
// OfficeDDE contains the registry keys for DDE hardening
// please also refer to
// https://docs.microsoft.com/en-us/security-updates/securityadvisories/2017/4053440
var OfficeDDE = &MultiHardenInterfaces{
hardenInterfaces: []HardenInterface{
// AllowDDE: part of Update ADV170021
// disables DDE for Word (default setting after installation of update)
&OfficeRegistryRegExSingleDWORD{
RootKey: registry.CURRENT_USER,
PathRegEx: pathRegExSecurity,
ValueName: "AllowDDE",
HardenedValue: 0,
OfficeApps: []string{"Word"},
OfficeVersions: []string{
"14.0", // Office 2010
"15.0", // Office 2013
"16.0", // Office 2016
},
shortName: "OfficeDDE_AllowDDE_Word",
},
// DisableDDEServerLaunch: part of Update ADV170021
// "0" reflects Microsoft standard settings. If you want to further harden
// your settings you could use "1" and uncomment this
//&OfficeRegistryRegExSingleDWORD{
// RootKey: registry.CURRENT_USER,
// PathRegEx: pathRegExSecurity,
// ValueName: "DisableDDEServerLaunch",
// HardenedValue: 0,
// OfficeApps: []string{"Excel"},
// OfficeVersions: []string{
// "14.0", // Office 2010
// "15.0", // Office 2013
// "16.0", // Office 2016
// },
// shortName: "OfficeDDE_DDEServer_Excel1",
//},
// DisableDDEServerLookup: part of Update ADV170021
// "0" reflects Microsoft standard settings. If you want to further harden
// your settings you could use "1" and uncomment this
//&OfficeRegistryRegExSingleDWORD{
// RootKey: registry.CURRENT_USER,
// PathRegEx: pathRegExSecurity,
// ValueName: "DisableDDEServerLookup",
// HardenedValue: 0,
// OfficeApps: []string{"Excel"},
// OfficeVersions: []string{
// "14.0", // Office 2010
// "15.0", // Office 2013
// "16.0", // Office 2016
// },
// shortName: "OfficeDDE_DDEServer_Excel2",
//},
// the following setting has been removed, because it causes excel files
// that are opened in Windows Explorer not loading anymore (excel is
// started, but file is not opened (which is very inconvenient/unexpected)
// -> https://social.technet.microsoft.com/Forums/en-US/ec1d2f20-ec8a-4c3b-
// 9e1b-ee731981db7c/double-clicking-xlsx-files-opens-a-blank-excel-page
//&OfficeRegistryRegExSingleDWORD{
// RootKey: registry.CURRENT_USER,
// PathRegEx: pathRegExOptions,
// ValueName: "DDEAllowed",
// HardenedValue: 0,
// OfficeApps: []string{"Excel"},
// OfficeVersions: standardOfficeVersions,
// shortName: "OfficeDDE_DDEAllowedExcel",
//},
// the following setting has been removed, because it causes excel files
// that are opened in Windows Explorer not loading anymore (excel is
// started, but file is not opened (which is very inconvenient/unexpected)
// -> https://social.technet.microsoft.com/Forums/en-US/ec1d2f20-ec8a-4c3b-
// 9e1b-ee731981db7c/double-clicking-xlsx-files-opens-a-blank-excel-page
//&OfficeRegistryRegExSingleDWORD{
// RootKey: registry.CURRENT_USER,
// PathRegEx: pathRegExOptions,
// ValueName: "DDECleaned",
// HardenedValue: 1,
// OfficeApps: []string{"Excel"},
// OfficeVersions: standardOfficeVersions,
// shortName: "OfficeDDE_DDECleanedExcel",
//},
// the following setting has been removed, because it causes excel files
// that are opened in Windows Explorer not loading anymore (excel is
// started, but file is not opened (which is very inconvenient/unexpected)
//&OfficeRegistryRegExSingleDWORD{
// RootKey: registry.CURRENT_USER,
// PathRegEx: pathRegExOptions,
// ValueName: "Options",
// HardenedValue: 0x117,
// OfficeApps: []string{"Excel"},
// OfficeVersions: standardOfficeVersions,
// shortName: "OfficeDDE_OptionsExcel",
//},
// WorkbookLinkWarnings
// Impact of mitigation: Disabling this feature could prevent Excel
// spreadsheets from updating dynamically if disabled in the registry.
// Data might not be completely up-to-date because it is no longer being
// updated automatically via live feed. To update the worksheet, the user
// must start the feed manually. In addition, the user will not receive
// prompts to remind them to manually update the worksheet.
&OfficeRegistryRegExSingleDWORD{
RootKey: registry.CURRENT_USER,
PathRegEx: pathRegExSecurity,
ValueName: "WorkbookLinkWarnings",
HardenedValue: 2,
OfficeApps: []string{"Excel"},
OfficeVersions: standardOfficeVersions,
shortName: "OfficeDDE_WorkbookLinksExcel",
},
// fNoCalclinksOnopen_90_1 & DontUpdateLinks:
// Impact of mitigation: Setting this registry key will disable automatic
// update for DDE field and OLE links. Users can still enable the update by
// right-clicking on the field and clicking “Update Field”.
&OfficeRegistryRegExSingleDWORD{
RootKey: registry.CURRENT_USER,
PathRegEx: pathRegExOptions,
ValueName: "DontUpdateLinks",
HardenedValue: 1,
OfficeApps: []string{"Word", "Excel"},
OfficeVersions: []string{
"14.0", // Office 2010
"15.0", // Office 2013
"16.0", // Office 2016
},
shortName: "OfficeDDE_DontUpdateLinksWordExcel",
},
&OfficeRegistryRegExSingleDWORD{
RootKey: registry.CURRENT_USER,
PathRegEx: pathRegExWordMail,
ValueName: "DontUpdateLinks",
HardenedValue: 1,
OfficeApps: []string{"Word"},
OfficeVersions: []string{
"14.0", // Office 2010
"15.0", // Office 2013
"16.0", // Office 2016
},
shortName: "OfficeDDE_DontUpdateLinksWordMail",
},
&RegistrySingleValueDWORD{
RootKey: registry.CURRENT_USER,
Path: pathWord2007,
ValueName: "fNoCalclinksOnopen_90_1",
HardenedValue: 1,
shortName: "OfficeDDE_Word2007",
},
},
shortName: "Office DDE",
longName: "Office DDE Mitigations",
description: "Disables Dynamic Data Exchange (DDE) in MS Office Word and\n" +
"Excel. Files that use DDE might not work as expected.\n" +
"Disabling this feature could prevent Excel spreadsheets\n" +
"from updating dynamically if disabled in the registry.\n" +
"Data that is fetched from other files or systems will\n" +
"not be update automatically. The user must start then\n" +
"update manually.",
hardenByDefault: true,
}
// Harden hardens OfficeRegistryRegExSingleDWORD registry values.
func (officeRegEx OfficeRegistryRegExSingleDWORD) Harden(harden bool) error {
for _, officeVersion := range officeRegEx.OfficeVersions {
for _, officeApp := range officeRegEx.OfficeApps {
path := fmt.Sprintf(officeRegEx.PathRegEx, officeVersion, officeApp)
// Build a RegistrySingleValueDWORD so we can reuse the Harden() method.
var singleDWORD = &RegistrySingleValueDWORD{
RootKey: officeRegEx.RootKey,
Path: path,
ValueName: officeRegEx.ValueName,
HardenedValue: officeRegEx.HardenedValue,
shortName: officeRegEx.shortName,
longName: officeRegEx.longName,
description: officeRegEx.description,
}
// Call RegistrySingleValueDWORD Harden method to Harden or Restore.
err := singleDWORD.Harden(harden)
if err != nil {
return err
}
}
}
return nil
}
// IsHardened verifies if OfficeRegistryRegExSingleDWORD is already hardened.
func (officeRegEx OfficeRegistryRegExSingleDWORD) IsHardened() bool {
var hardened = true
for _, officeVersion := range officeRegEx.OfficeVersions {
for _, officeApp := range officeRegEx.OfficeApps {
path := fmt.Sprintf(officeRegEx.PathRegEx, officeVersion, officeApp)
// Build a RegistrySingleValueDWORD so we can reuse the isHardened() method.
var singleDWORD = &RegistrySingleValueDWORD{
RootKey: officeRegEx.RootKey,
Path: path,
ValueName: officeRegEx.ValueName,
HardenedValue: officeRegEx.HardenedValue,
}
if !singleDWORD.IsHardened() {
hardened = false
}
}
}
return hardened
}
// Name returns the (short) name of the harden item.
func (officeRegEx OfficeRegistryRegExSingleDWORD) Name() string {
return officeRegEx.shortName
}
// LongName returns the long name of the harden item.
func (officeRegEx OfficeRegistryRegExSingleDWORD) LongName() string {
return officeRegEx.longName
}
// Description of the harden item.
func (officeRegEx OfficeRegistryRegExSingleDWORD) Description() string {
return officeRegEx.description
}
// HardenByDefault returns if subject should be hardened by default.
func (officeRegEx OfficeRegistryRegExSingleDWORD) HardenByDefault() bool {
return officeRegEx.hardenByDefault
}