-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdebian_packages.yml
345 lines (336 loc) · 10.6 KB
/
debian_packages.yml
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
---
- name: Install security software
tags: debian
when: ansible_distribution == "Debian" or ansible_distribution == "Kali" or ansible_distribution == "Ubuntu"
become: true
block:
- name: Install security software
ansible.builtin.apt:
name: "{{ packages }}"
update_cache: true
vars:
# checksecurity also brings logcheck
packages:
- bootlogd
- autolog
- needrestart
- arpwatch
- usbguard
- unattended-upgrades
- checksec
- hardening-runtime
- apt-show-versions
tags:
- packages
- services
# This does not exist in Kali
- name: Install checksecurity
when: ansible_distribution == "Debian" or ansible_distribution == "Ubuntu"
ansible.builtin.apt:
name: checksecurity
tags: packages
- name: Install chkrootkit
tags:
- chkrootkit
- packages
ansible.builtin.apt:
name: chkrootkit
- name: Install Tiger
tags:
- tiger
- packages
ansible.builtin.apt:
name: tiger
# The JtR packaged with Debian 12 (1.9.0) doesn't support the modern hashing algorithms
#- name: John
# become: true
# tags:
# - john
# - passwords
# block:
# - name: Check /etc/john
# tags: check
# ansible.builtin.stat:
# path: /etc/john
# register: stat_john
# - name: Check /etc/cron.d/john
# tags: check
# ansible.builtin.stat:
# path: /etc/cron.d/john
# register: stat_john_cron
# - name: Configure John
# tags: configuration
# when:
# - stat_john.stat.exists
# - stat_john.stat.isdir
# - stat_john_cron.stat.exists
# block:
# - name: Copy john-mail.conf
# ansible.builtin.copy:
# dest: /etc/john/john-mail.conf
# src: john-mail.conf
# owner: root
# group: root
# mode: '0600'
# backup: true
# - name: Enable John cronjobs
# ansible.builtin.replace:
# path: /etc/cron.d/john
# regexp: '^#?([0-9]+\s+[0-9]+\s+\*\s+\*\s+\*\s+root\s+\[\s+-x\s+/usr/share/john/cronjob\s+\]\s+&&\s+(nice\s+)?/usr/share/john/cronjob\s+st(art|op))$'
# replace: '\g<1>'
# backup: true
# # https://www.shellcheck.net/wiki/SC2069
# - name: Fix SC2069 in /usr/share/john/cronjob
# ansible.builtin.replace:
# path: /usr/share/john/cronjob
# regexp: '^(\s+/sbin/start-stop-daemon --stop -q -o --pidfile \$PIDDIR/john.pid) 2>&1 >/dev/null$'
# replace: '\g<1> >/dev/null 2>&1'
# backup: true
- name: Tiger
become: true
tags: tiger
block:
- name: Check /etc/tiger
tags: check
ansible.builtin.stat:
path: /etc/tiger
register: stat_tiger
- name: Tiger configs
tags: configuration
when:
- stat_tiger.stat.exists
- stat_tiger.stat.isdir
block:
- name: Copy tiger.ignore
ansible.builtin.copy:
src: tiger.ignore
dest: /etc/tiger/tiger.ignore
owner: root
group: root
mode: '0600'
backup: true
- name: Copy tigerrc
ansible.builtin.template:
src: tigerrc.j2
dest: /etc/tiger/tigerrc
owner: root
group: root
mode: '0600'
backup: true
# [ -L /lib/ ] == false, but [ -L /lib ] == true
# https://git.savannah.nongnu.org/cgit/tiger.git/tree/systems/Linux/2/deb_nopackfiles#n121
# Since Debian's /usr merge the lin001w test will produce megabytes worth of FPs when the symlink test fails.
# https://wiki.debian.org/UsrMerge
# TODO: Add /usr/lib?
- name: Fix deb_nopackfiles
when: ansible_distribution == "Debian"
ansible.builtin.replace:
path: /usr/lib/tiger/systems/Linux/2/deb_nopackfiles
regexp: '^(dirlist=)"/bin/ /usr/bin/ /sbin/ /usr/sbin/ /lib/ /usr/X11R6/bin"$'
replace: '\g<1>"/bin /usr/bin /sbin /usr/sbin /lib /usr/X11R6/bin"'
- name: Comment out user.max_user_namespaces=0 in /usr/lib/sysctl.d/10-hardening.conf
tags:
- debian
- configuration
- kernel
when: ansible_distribution == "Debian" or ansible_distribution == "Kali"
become: true
#notify: "Load sysctl settings"
ansible.builtin.replace:
path: /usr/lib/sysctl.d/10-hardening.conf
regexp: "^(user.max_user_namespaces = 0)$"
replace: '#\1'
register: result
failed_when:
- result.failed
- result.msg != "Path /usr/lib/sysctl.d/10-hardening.conf does not exist !"
# debsecan
- name: debsecan
when: ansible_distribution == "Debian"
tags:
- debsecan
- debian
become: true
block:
- name: Install debsecan
ansible.builtin.apt:
name: debsecan
tags: packages
- name: Configure debsecan
ansible.builtin.debconf:
name: debsecan
question: debsecan/suite
vtype: select
value: "{{ ansible_distribution_release }}"
tags: configuration
- name: Configure debsecan MAILTO
tags:
- configuration
ansible.builtin.replace:
path: '{{ item }}'
regexp: '^(MAILTO)=.*$'
replace: '\g<1>={{ alert_email }}'
validate: '/bin/grep "^MAILTO={{ alert_email }}$" %s'
backup: true
with_items:
- /etc/default/debsecan
- /etc/cron.d/debsecan
# debsums
- name: debsums
when: ansible_distribution == "Debian" or ansible_distribution == "Kali"
become: true
tags:
- debsums
- debian
block:
- name: Install debsums
ansible.builtin.apt:
name: debsums
tags: packages
- name: Enable weekly debsums run
ansible.builtin.replace:
path: /etc/default/debsums
regexp: '^(CRON_CHECK=).*'
replace: '\g<1>weekly'
tags: configuration
- name: Configure chkrootkit
become: true
when: ansible_distribution == "Debian" or ansible_distribution == "Kali" or ansible_distribution == "Ubuntu"
tags:
- chkrootkit
- debian
block:
# See https://github.com/pyllyukko/harden.yml/wiki/chkrootkit
- name: getent passwd
ansible.builtin.getent:
database: passwd
tags: check
- name: Create /etc/chkrootkit/chkrootkit.ignore
tags: configuration
ansible.builtin.template:
dest: "{{ chkrootkit_conf_dir }}/chkrootkit.ignore"
src: chkrootkit.ignore.j2
owner: root
group: root
mode: '0400'
- name: Configure /etc/cron.daily/chkrootkit to use chkrootkit.ignore
tags: configuration
ansible.builtin.replace:
path: /etc/cron.daily/chkrootkit
regexp: '^(IGNORE_FILE=).*'
replace: '\g<1>{{ chkrootkit_conf_dir }}/chkrootkit.ignore'
- name: Configure chkrootkit.conf
tags: configuration
ansible.builtin.template:
dest: "{{ chkrootkit_conf_dir }}/chkrootkit.conf"
src: chkrootkit.conf.j2
owner: root
group: root
mode: '0600'
backup: true
- name: Stat /var/log/chkrootkit/log.today
tags: check
ansible.builtin.stat:
path: /var/log/chkrootkit/log.today
register: stat_log_today
- name: Stat /var/log/chkrootkit/log.expected
tags: check
ansible.builtin.stat:
path: /var/log/chkrootkit/log.expected
register: stat_log_expected
- name: Copy /var/log/chkrootkit/log.today -> /var/log/chkrootkit/log.expected
tags: configuration
when:
- stat_log_today.stat.exists
- not stat_log_expected.stat.exists
ansible.builtin.copy:
src: /var/log/chkrootkit/log.today
dest: /var/log/chkrootkit/log.expected
remote_src: true
owner: root
group: root
mode: '0600'
- name: Debian APT
when: ansible_distribution == "Debian" or ansible_distribution == "Kali"
become: true
tags:
- debian
- configuration
block:
# Ansible's apt module doesn't install suggested packages,
# but we don't want them later on either.
- name: Configure APT not to install suggested packages
ansible.builtin.copy:
content: "APT::Install-Suggests \"false\";\n"
dest: /etc/apt/apt.conf.d/99suggested
owner: root
group: root
mode: '0644'
force: false
# https://www.debian.org/releases/buster/amd64/release-notes/ch-whats-new.en.html#apt-sandboxing
- name: Configure APT to use seccomp-BPF sandboxing
ansible.builtin.copy:
content: "APT::Sandbox::Seccomp \"true\";\n"
dest: /etc/apt/apt.conf.d/40sandbox
owner: root
group: root
mode: '0644'
force: false
- name: Configure email_address in /etc/apt/listchanges.conf
community.general.ini_file:
path: /etc/apt/listchanges.conf
section: apt
option: email_address
value: "{{ alert_email }}"
owner: root
group: root
mode: '0644'
create: false
register: result
failed_when:
- result.failed
- result.msg != "Destination /etc/apt/listchanges.conf does not exist!"
- name: Configure SENDMAILTO in /etc/logcheck/logcheck.conf
become: true
tags:
- debian
- configuration
ansible.builtin.replace:
path: /etc/logcheck/logcheck.conf
regexp: '^(SENDMAILTO=).+$'
replace: '\g<1>"{{ alert_email }}"'
validate: '/bin/grep "^SENDMAILTO=\"{{ alert_email }}\"$" %s'
backup: true
register: result
failed_when:
- result.failed
- result.msg != "Path /etc/logcheck/logcheck.conf does not exist !"
# https://www.whonix.org/wiki/Packages_for_Debian_Hosts
# https://www.kicksecure.com/wiki/Packages_for_Debian_Hosts#Supported_Packages
# https://www.kicksecure.com/wiki/Linux_Kernel_Runtime_Guard_LKRG
#- name: LKRG
# become: true
# tags:
# - lkrg
# - debian
# - packages
# - kernel
# block:
# - name: Add Whonix PGP key
# ansible.builtin.get_url:
# #url: https://www.whonix.org/keys/derivative.asc
# url: https://www.kicksecure.com/keys/derivative.asc
# dest: /usr/share/keyrings/derivative.asc
# owner: root
# group: root
# mode: '0644'
# - name: Add Whonix repository
# ansible.builtin.apt_repository:
# # The Whonix repo didn't seem to contain LKRG
# #repo: "deb [signed-by=/usr/share/keyrings/derivative.asc] https://deb.whonix.org bookworm main contrib non-free"
# repo: "deb [signed-by=/usr/share/keyrings/derivative.asc] https://deb.kicksecure.com bookworm main contrib non-free"
# state: present
# - name: Install LKRG
# ansible.builtin.apt:
# name: lkrg
# update_cache: true