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
|
# pam_bloom
`pam_bloom` is a Linux PAM password module that rejects passwords
found in one or more Bloom filters.
It can be used to prevent users from choosing passwords found in known
password lists such as RockYou, organization-specific password lists,
or other administrator-provided dictionaries.
The package includes:
* `pam_bloom.so` — PAM module
* `pam_bloom_create` — utility for creating Bloom filters from wordlists
WARNING: This software modifies PAM configuration. There is always
risk involved with re-configuring the system's authentication system
such as locking legitimate users out. Administrators are responsible
for testing their PAM configuration before deployment.
## Requirements
On Debian or Ubuntu, install the compiler, PAM development files, and
other build tools:
```sh
sudo apt update
sudo apt install build-essential libpam0g-dev
```
The Makefile also uses `dpkg-architecture` to determine Debian's
multiarch PAM module directory. This is normally already available on
Debian systems.
## Build
Clone or unpack the source and run:
```sh
make
```
This builds:
```text
pam_bloom.so
pam_bloom_create
```
Install them with:
```sh
sudo make install
```
On a typical x86-64 Debian system this installs:
```text
/usr/bin/pam_bloom_create
/usr/lib/x86_64-linux-gnu/security/pam_bloom.so
/etc/security/pam_bloom/filters.d/
```
Finally, run `pam-auth-update` to enable `pam_bloom`:
```sh
sudo pam-auth-update
```
## Create a Bloom filter
`pam_bloom_create` creates a Bloom filter from a wordlist:
```sh
pam_bloom_create WORDLIST OUTPUT NAME
```
For example:
```sh
pam_bloom_create rockyou.txt rockyou.bloom rockyou
```
The default false-positive rate is `0.001`.
A different false-positive rate can be selected with `-p`:
```sh
pam_bloom_create -p 0.000001 rockyou.txt rockyou.bloom rockyou
```
Install the resulting filter:
```sh
sudo cp rockyou.bloom /etc/security/pam_bloom/filters.d/
```
The PAM module checks every `.bloom` file in this directory. A
password matching any installed filter is rejected.
## Configure PAM
**Be careful when modifying PAM configuration. An incorrect PAM
configuration can prevent authentication or password changes. Keep a
root session open while testing changes.**
On Debian and Ubuntu, edit:
```text
/etc/pam.d/common-password
```
Add `pam_bloom.so` before the `pam_unix.so` password entry.
For example:
```text
password requisite pam_bloom.so
password [success=1 default=ignore] pam_unix.so obscure yescrypt use_authtok
password requisite pam_deny.so
password required pam_permit.so
```
The important points are that `pam_bloom.so` runs before `pam_unix.so`
and that `pam_unix.so` uses `use_authtok`.
`pam_bloom` obtains the new password through PAM, checks it against
the installed Bloom filters, and rejects it if a match is
found. `pam_unix` then uses the same password token.
## Test
Change a test user's password normally:
```sh
passwd
```
Try selecting a password contained in one of the installed wordlists.
`pam_bloom` should reject the password and identify the Bloom filter
that matched it.
A password that does not match any filter is passed on to the rest of
the PAM password stack.
## Custom filter directory
The default filter directory is:
```text
/etc/security/pam_bloom/filters.d
```
A different directory can be configured with the PAM `dir=` option:
```text
password requisite pam_bloom.so dir=/srv/security/bloom
```
The directory and filter files must satisfy `pam_bloom`'s ownership
and permission checks.
## Included RockYou filter
`pam_bloom` includes a pre-built Bloom filter generated from the
RockYou password list:
```text
rockyou.txt.bloom
```
The supplied filter was created with a false-positive rate of:
```text
0.001
```
This filter is installed to
`/etc/security/pam_bloom/filters.d/rockyou.txt.bloom` by default.
Because this is a Bloom filter, there is a small probability of false
positives. With the supplied filter, the configured false-positive
probability is 0.001 (approximately 0.1%). In the 1 in 1000 chance
that there is a false-positive, the user will simply have to choose
another password.
The original RockYou plaintext wordlist is not required at runtime.
## Creating your own filters
Additional Bloom filters can be created with:
```sh
pam_bloom_create WORDLIST OUTPUT NAME
```
For example:
```sh
pam_bloom_create passwords.txt passwords.bloom passwords
```
The default false-positive rate is `0.001`, the same value used for
the supplied RockYou filter.
A different false-positive rate can be selected with `-p`:
```sh
pam_bloom_create -p 0.000001 passwords.txt passwords.bloom passwords
```
Install the resulting filter by copying it into the filter directory:
```sh
sudo cp passwords.bloom /etc/security/pam_bloom/filters.d/
```
Multiple `.bloom` files may be installed at the same time. A password
matching any installed filter is rejected.
## Adding multiple filters
Multiple filters can be installed simply by copying additional
`.bloom` files into the filter directory:
```text
/etc/security/pam_bloom/filters.d/rockyou.bloom
/etc/security/pam_bloom/filters.d/company.bloom
/etc/security/pam_bloom/filters.d/banned-passwords.bloom
```
If the candidate password matches **any** filter, it is rejected.
## Removing a filter
Remove the corresponding `.bloom` file:
```sh
sudo rm /etc/security/pam_bloom/filters.d/rockyou.bloom
```
No rebuild of the PAM module is necessary.
## Uninstall
uninstall the binaries:
```sh
sudo make uninstall
```
`make uninstall` deliberately does not remove:
```text
/etc/security/pam_bloom/filters.d/
```
or any Bloom filters stored there. Administrator-created filters are
preserved.
Finally, update PAM configuration to remove `pam_bloom`:
```sh
sudo pam-auth-update
```
Alternatively, edit `/etc/pam.d/common-password` to remove `pam_bloom`
## Security
Bloom filters can produce false positives. The false-positive
probability can be controlled when creating a filter with
`pam_bloom_create -p`.
The PAM module treats installed Bloom filters as trusted
administrative data. Filter directories and files are checked for
appropriate ownership and permissions before they are used.
Malformed, inaccessible, or otherwise invalid filters cause the
password check to fail closed rather than silently bypassing the
password policy.
## Murmur3
The mmh3 implementation by Austin Appleby was referenced when
implementing this. Appleby's implementation was released under the
public domain.
|