You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first thing to do after the first boot is to update the system. In most Debian-based flavors of Linux, you achieve this by executing the commands below:
12
12
13
-
```text
13
+
```bash
14
14
sudo apt update && sudo apt upgrade -y
15
15
```
16
16
@@ -29,7 +29,7 @@ Remember that disabling unnecessary services will reduce the attack surface, so
29
29
30
30
`yum` for RedHat based systems. `apt` for debian based systems.
@@ -38,14 +38,14 @@ Remember that disabling unnecessary services will reduce the attack surface, so
38
38
39
39
If you don't want to completely uninstall a service, you can simply disable it until it is needed. A lot of services and daemons are started during system boot and disabling those that are not being used can help with system hardening and can improve boot time. Since most modern distributions use `systemd` instead of init scripts, you can use `systemctl` to list running services.
40
40
41
-
```text
41
+
```bash
42
42
sudo systemctl list-unit-files --type=service
43
43
sudo systemctl list-dependencies graphical.target
44
44
```
45
45
46
46
These commands will display such service and daemons. You can disable a specific service by using the below commands.
Identifying open connections to the internet is critical to understanding your attack surface. In Kali Linux, use the following commands to identify open ports:
56
56
57
-
```text
57
+
```bash
58
58
netstat -tulpn
59
59
ss -tulpn
60
60
lsof -i
@@ -82,7 +82,7 @@ First of all, if you do not need SSH, disable it. However, if you want to use it
82
82
83
83
6. Check the manual for SSH to understand all the configurations in `/etc/ssh/sshd_config`. Some other examples of recommended configuration options are:
84
84
85
-
```text
85
+
```bash
86
86
AuthorizedKeysFile /etc/ssh/authorized-keys/%u #removes this file from user's folder and puts its in more secure /etc folder
87
87
Protocol2
88
88
IgnoreRhosts to yes
@@ -121,15 +121,15 @@ The boot directory contains important files related to the Linux kernel, so you
121
121
122
122
Admins should make sure that users can’t log into their server after a certain number of failed attempts. This increases the overall security of the system by mitigating password attacks. You can use the Linux `faillog` command to see the failed login attempts.
123
123
124
-
```text
124
+
```bash
125
125
# faillog
126
126
# faillog -m 3
127
127
# faillog -l 1800
128
128
```
129
129
130
130
The first command will display the failed login attempts for users from the `/var/log/faillog` database. The second command sets the maximum number of allowed failed login attempts to 3. The third one sets a lock of 1800 seconds or 30 minutes after the allowed number of failed login attempts.
131
131
132
-
```text
132
+
```bash
133
133
# faillog -r -u <username>
134
134
```
135
135
@@ -139,14 +139,14 @@ Use this command to unlock a user once they’re prohibited from login. The max
139
139
140
140
[Fail2Ban](https://www.fail2ban.org/) is one of the most popular IPS solutions for Unix-like systems. It is written using Python and is available on all POSIX-compliant platforms. It will look for obtrusive network requests all the time and block them as soon as possible. Install Fail2Ban using the below command.
141
141
142
-
```text
142
+
```bash
143
143
apt install -y fail2ban
144
144
yum install -y fail2ban
145
145
```
146
146
147
147
[DenyHosts](https://github.com/denyhosts/denyhosts) is another popular IPS solution for Linux hardening. It will protect your ssh servers from intrusive brute force attempts. Use the following commands to install in on your Debian or Centos servers.
148
148
149
-
```text
149
+
```bash
150
150
apt install -y denyhosts
151
151
yum install -y denyhosts
152
152
```
@@ -171,22 +171,73 @@ yum install -y denyhosts
171
171
172
172
If you want to read the contents of the binary files `wtmp`, `utmp` or `btmp`, use the command:
173
173
174
-
```text
174
+
```bash
175
175
sudo utmpdump /var/run/utmp
176
176
sudo utmpdump /var/log/wtmp
177
177
sudo utmpdump /var/log/btmp
178
178
```
179
179
180
180
`who`, `w`, and `last <username>` will also give you information about users logged into your machine.
181
181
182
-
### with `logcheck`
182
+
### `logcheck`
183
183
184
-
TODO: Clean up description (issue [#12](https://github.com/zweilosec/Infosec-Notes/issues/12))
185
-
* Description is a mass block of text. Add formatting,
186
-
* Put code into code blocks
187
-
* Ensure clarity and brevity
184
+
**Logcheck** is a powerful tool for monitoring system logs and identifying potential security threats. It works by monitoring log files for changes (every hour by default) and sends log messages it determines to be 'unusual' to the administrator via email for further analysis. The list of monitored files is stored in `/etc/logcheck/logcheck.logfiles`. The default settings work well unless the `/etc/rsyslog.conf` file has undergone significant customization.
188
185
189
-
The logcheck program monitors log files every hour by default and sends unusual log messages in emails to the administrator for further analysis. The list of monitored files is stored in /etc/logcheck/logcheck.logfiles. The default values work fine if the /etc/rsyslog.conf file has not been completely overhauled. logcheck can report in various levels of detail: paranoid, server, and workstation. paranoid is very verbose and should probably be restricted to specific servers such as firewalls. server is the default mode and is recommended for most servers. workstation is obviously designed for workstations and is extremely terse, filtering out more messages than the other options. In all three cases, logcheck should probably be customized to exclude some extra messages \(depending on installed services\), unless you really want to receive hourly batches of long uninteresting emails. Since the message selection mechanism is rather complex, /usr/share/doc/logcheck-database/README.logcheck-database.gz is a required—if challenging—read. The applied rules can be split into several types: those that qualify a message as a cracking attempt \(stored in a file in the /etc/logcheck/cracking.d/directory\); ignored cracking attempts \(/etc/logcheck/cracking.ignore.d/\); those classifying a message as a security alert \(/etc/logcheck/violations.d/\); ignored security alerts \(/etc/logcheck/violations.ignore.d/\); finally, those applying to the remaining messages \(considered as system events\). ignore.d files are used to \(obviously\) ignore messages. For example, a message tagged as a cracking attempt or a security alert \(following a rule stored in a /etc/logcheck/violations.d/myfile file\) can only be ignored by a rule in a /etc/logcheck/violations.ignore.d/myfile or /etc/logcheck/violations.ignore.d/myfile-extension file. A system event is always signaled unless a rule in one of the /etc/logcheck/ignore.d.{paranoid,server,workstation}/ directories states the event should be ignored. Of course, the only directories taken into account are those corresponding to verbosity levels equal or greater than the selected operation mode.
186
+
**logcheck** provides three reporting levels:
187
+
188
+
-**Paranoid**: Highly detailed and best suited for security-critical servers like firewalls.
189
+
-**Server** (default mode): Recommended for most servers.
190
+
-**Workstation**: Designed for workstations, offering minimal reporting by filtering out more messages.
191
+
192
+
Regardless of the chosen mode, customizing **logcheck** to exclude unnecessary messages is advised. Due to its complex message selection mechanism, reading `/usr/share/doc/logcheck-database/README.logcheck-database.gz` is essential to understanding logcheck's Rule Classifications and how to ingore messages.
193
+
194
+
Here are some ways to use **logcheck** to harden a Linux system:
195
+
196
+
#### **Fine-Tune Log Monitoring**
197
+
198
+
- Customize the list of monitored log files in `/etc/logcheck/logcheck.logfiles` to include critical logs like:
199
+
-`/var/log/auth.log` (Authentication logs)
200
+
-`/var/log/kern.log` (Kernel logs)
201
+
-`/var/log/secure` (Security-related logs)
202
+
-`/var/log/btmp` (Failed login attempts)
203
+
- Regularly review these logs to detect unauthorized access attempts or system anomalies.
204
+
205
+
#### **Adjust Filtering Rules**
206
+
207
+
- Modify rules in `/etc/logcheck/ignore.d.{paranoid,server,workstation}/` to exclude unnecessary messages while ensuring security alerts are not ignored.
208
+
- Use `/etc/logcheck/violations.d/` to classify security alerts and `/etc/logcheck/violations.ignore.d/` to filter out false positives.
209
+
210
+
##### Rule Classification
211
+
212
+
**logcheck** applies rules to categorize messages into the following types:
213
+
214
+
-**Cracking attempts** → Stored in `/etc/logcheck/cracking.d/`
215
+
-**Ignored cracking attempts** → Stored in `/etc/logcheck/cracking.ignore.d/`
216
+
-**Security alerts** → Stored in `/etc/logcheck/violations.d/`
217
+
-**Ignored security alerts** → Stored in `/etc/logcheck/violations.ignore.d/`
218
+
-**System events** → General logs unless explicitly ignored
219
+
220
+
##### Ignoring Messages
221
+
222
+
Messages can only be ignored if rules are defined in specific directories:
223
+
224
+
- A **cracking attempt** or **security alert** (classified under `/etc/logcheck/violations.d/`) can only be ignored by rules in `/etc/logcheck/violations.ignore.d/`.
225
+
-**System events** are always reported unless ignored by rules within `/etc/logcheck/ignore.d.{paranoid,server,workstation}/`, and only those matching or exceeding the selected verbosity level are considered.
226
+
227
+
#### **Enhance Logcheck with SELinux**
228
+
229
+
- Enable **SELinux** (`sudo setenforce 1`) to enforce strict access control policies.
230
+
- Combine **Logcheck** with SELinux logs (`/var/log/audit/audit.log`) to detect unauthorized access attempts.
231
+
232
+
#### **Automate Log Analysis**
233
+
234
+
- Schedule **Logcheck** to run more frequently than the default hourly interval by adjusting the cron job (`/etc/cron.d/logcheck`).
235
+
- Set up email alerts to notify administrators immediately of critical security events.
236
+
237
+
#### **Integrate with Other Security Tools**
238
+
239
+
- Pair **Logcheck** with **Fail2Ban** to automatically block IPs attempting brute-force attacks.
240
+
- Use **Auditd** for deeper system auditing and correlate logs with **Logcheck** for enhanced security insights.
190
241
191
242
## Enable SELinux
192
243
@@ -196,33 +247,47 @@ Security Enhanced Linux is a Kernel security mechanism for supporting access con
196
247
197
248
[SELinux](https://en.wikipedia.org/wiki/Security-Enhanced_Linux), short for Security Enhanced Linux, is a security mechanism that implements various methods for access control at the kernel level. It was developed by Red Hat but has been added to many [modern Linux distributions.](https://ubuntupit.com/best-linux-distro-top-recommendation-to-boost-up-your-linux-experience/) You can check whether SELinux is enabled in your system or not by using the below command.
198
249
199
-
```text
250
+
```bash
200
251
sudo getenforce
201
252
```
202
253
203
-
If it returns `enforcing` , your system is protected by SELinux. If the result says `permissive` your system has SELinux but it’s not enforced. It will return `disabled` for systems where SELinux is completely disabled. You can enforce SELinux by using the below command.
254
+
If it returns `enforcing` , your system is protected by SELinux. If the result says `permissive` your system has SELinux but it’s not enforced. It will return `disabled` for systems where SELinux is completely disabled.
255
+
256
+
You can enforce SELinux by using the below command:
204
257
205
-
```text
258
+
```bash
206
259
sudo setenforce 1
207
260
```
208
261
209
-
SELinux has three configuration modes:
262
+
Or, using a text editor, open the config file `/etc/selinux/config` and make sure that the policy is enforced by changing the line starting with `SELINUX=`.
263
+
264
+
```bash
265
+
# This file controls the state of SELinux on the system.
266
+
# SELINUX can take one of these values:
267
+
# enforcing - SELinux security policy is enforced.
268
+
# permissive - SELinux prints warnings instead of enforcing.
269
+
# disabled - No SELinux policy is loaded.
270
+
271
+
SELINUX=enforcing
272
+
SELINUXTYPE=targeted # Targeted means only selected processes are protected.
273
+
```
274
+
275
+
SELinux has three configuration mode options:
210
276
211
277
* Disabled: Turned-off
212
-
* Permissive: Prints warnings
278
+
* Permissive: Prints warnings, but does not block
213
279
* Enforcing: Policy is enforced
214
280
215
-
Using a text editor, open the config file `/etc/selinux/config` and make sure that the policy is enforced by changing the line `SELINUX=enforcing`.
216
281
217
-
```text
218
-
add example of config file - image?
219
-
```
282
+
### Visualizing the Configuration
283
+
If you need an image representation of the configuration file, a simple screenshot of a terminal displaying the file’s contents would be the most practical. You can generate this by running:
284
+
220
285
221
286
## Permissions and verifications
222
287
223
-
Prepare yourself mentally because this is going to be a long list. But, permissions is one of the most important and critical tasks to achieve the security goal on a Linux host. Set User/Group Owner and Permissions to `root` on `/etc/anacrontab`, `/etc/crontab` and `/etc/cron.*` by executing the following commands: \(as `root`\)
288
+
Setting permissions is one of the most important and critical tasks to achieve the security goal on a Linux host. Set User/Group Owner and Permissions to `root` on `/etc/anacrontab`, `/etc/crontab` and `/etc/cron.*` by executing the following commands: \(as `root`\)
224
289
225
-
```text
290
+
```bash
226
291
chown root:root /etc/anacrontab
227
292
chmod og-rwx /etc/anacrontab
228
293
chown root:root /etc/crontab
@@ -241,42 +306,44 @@ chmod og-rwx /etc/cron.d
241
306
242
307
Set the permissions and owner on `/var/spool/cron` for the `root` crontab.
243
308
244
-
```text
309
+
```bash
245
310
chown root:root <crontabfile>
246
311
chmod og-rwx <crontabfile>
247
312
```
248
313
249
314
Set permissions and owner on `/etc/passwd` file \(this file must be readable by all users\).
250
315
251
-
```text
316
+
```bash
252
317
chmod 644 /etc/passwd
253
318
chown root:root /etc/passwd
254
319
```
255
320
256
321
Set permissions and owner on the `/etc/group` file \(this file must be readable by all users\).
257
322
258
-
```text
323
+
```bash
259
324
chmod 644 /etc/group
260
325
chown root:root /etc/group
261
326
```
262
327
263
328
Set permissions and owner on the `/etc/shadow` file.
264
329
265
-
```text
330
+
```bash
266
331
chmod 600 /etc/shadow
267
332
chown root:root /etc/shadow
268
333
```
269
334
270
335
Set permissions and owner on the `/etc/gshadow` file.
271
336
272
-
```text
337
+
```bash
273
338
chmod 600 /etc/gshadow
274
339
chown root:root /etc/gshadow
275
340
```
276
341
277
342
278
343
279
-
## Misc
344
+
## Misc
345
+
346
+
TODO: expand this
280
347
281
348
* Use strong passwords
282
349
* Set up `fail2ban`, which will make it much harder to brute-force passwords over the network by filtering IP addresses that exceed a limit of failed login attempts. `apt install fail2ban`
@@ -289,7 +356,7 @@ chown root:root /etc/gshadow
289
356
290
357
Any extra repositories needs to be placed into their own file in the directory `/etc/apt/sources.list.d/` with files named as such: `/etc/apt/sources.list.d/repo-name.list`\(replacing `repo-name` with the mirror name\). This may break things over time so be careful.
291
358
292
-
```text
359
+
```bash
293
360
deb http://http.kali.org/kali kali-rolling main non-free contrib
294
361
<Archive><Mirror><Branch><Component>
295
362
```
@@ -310,7 +377,7 @@ To add kali's repository to another distro use the line: `deb http://http.kali.o
310
377
311
378
**lynis** - open source security auditing tool. Comes with Kali
312
379
313
-
```text
380
+
```bash
314
381
lynis --update
315
382
lynis audit system
316
383
```
@@ -329,7 +396,7 @@ If you’re not happy with the changes Bastille makes to your computer, you can
329
396
330
397
When using ssh and scp you can deploy Bastille using the commands:
@@ -342,7 +409,7 @@ Tmux can keep alive sessions if you lose ssh sessions etc, can split panes and m
342
409
343
410
Config from [ippsec](https://www.youtube.com/watch?v=Lqehvpe_djs).
344
411
345
-
```text
412
+
```bash
346
413
#set prefix
347
414
set -g prefix C-a
348
415
bind C-a send-prefix
@@ -396,7 +463,7 @@ Kill pane: `prefix + &`
396
463
397
464
Here’s a cool and interesting use of iptables. You can turn any computer with a wireless interface into a wireless access point with hostapd. This solution comes from [https://seravo.fi/2014/create-wireless-access-point-hostapd](https://seravo.fi/2014/create-wireless-access-point-hostapd):
398
465
399
-
```text
466
+
```bash
400
467
iptables -t nat -F
401
468
iptables -F
402
469
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
0 commit comments