Skip to content

Commit b260f22

Browse files
committed
optimized usage instructions, removed full sysctl.conf from README
1 parent f173c2c commit b260f22

File tree

1 file changed

+12
-263
lines changed

1 file changed

+12
-263
lines changed

README.md

Lines changed: 12 additions & 263 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This repository hosts my hardened version of `sysctl.conf`. This configuration f
1313

1414
**Please review the configuration file carefully before applying it.** You are responsible for actions done to your own system. If you need some guidance understanding what each of the settings are for, [sysctl-explorer](https://sysctl-explorer.net/) might come in handy.
1515

16-
Please be careful that this `sysctl.conf` is **designed for endpoint hosts that do not act as a router**. If you would like to use this configuration file on a router, please go over the configuration file and make necessary changes.
16+
Please be careful that this `sysctl.conf` is **designed for 64-bit endpoint hosts that do not act as a router**. If you would like to use this configuration file on a router, please go over the configuration file and make necessary changes.
1717

1818
## Usages
1919

@@ -24,279 +24,28 @@ Please be careful that this `sysctl.conf` is **designed for endpoint hosts that
2424
1. Run command `sudo sysctl -p` or reboot the system to apply the changes
2525

2626
```shell
27-
# clone the repository
28-
git clone https://github.com/k4yt3x/sysctl.git ~/sysctl
27+
# download the configuration file from GitHub using curl
28+
curl https://raw.githubusercontent.com/k4yt3x/sysctl/master/sysctl.conf -o ~/sysctl.conf
29+
30+
# you may also download with wget or other methods if curl is not available
31+
wget https://raw.githubusercontent.com/k4yt3x/sysctl/master/sysctl.conf -O ~/sysctl.conf
2932

3033
# backup the original sysctl.conf
3134
sudo cp /etc/sysctl.conf /etc/sysctl.conf.backup
3235

3336
# replace the old sysctl.conf with the new one
34-
sudo cp ~/sysctl/sysctl.conf /etc/sysctl.conf
37+
sudo mv ~/sysctl.conf /etc/sysctl.conf
3538

36-
# apply changes
37-
sudo sysctl -p
39+
# make sure the file has the correct ownership and permissions
40+
sudo chown root:root /etc/sysctl.conf
41+
sudo chmod 644 /etc/sysctl.conf
3842

39-
# remove the downloaded repository if you don't need it anymore
40-
rm -rf ~/sysctl
43+
# instruct sysctl to load settings from the configuration file into the live kernel
44+
sudo sysctl -p
4145
```
4246

4347
For convenience, I have pointed the URL `https://akas.io/sysctl` to the `sysctl.conf` file. You may therefore download the `sysctl.conf` file with the following command. However, be sure to check the integrity of the file after downloading it if you choose to download using this method.
4448

4549
```shell
4650
curl -sSL akas.io/sysctl -o sysctl.conf
4751
```
48-
49-
## `sysctl.conf` Content
50-
51-
```properties
52-
# Name: K4YT3X Hardened sysctl Configuration
53-
# Author: K4YT3X
54-
# Contributors: IceCodeNew
55-
# Date Created: October 5, 2020
56-
# Last Updated: October 7, 2020
57-
58-
# Licensed under the GNU General Public License Version 3 (GNU GPL v3),
59-
# available at: https://www.gnu.org/licenses/gpl-3.0.txt
60-
# (C) 2020 K4YT3X
61-
62-
# Multiple sources have been consulted while writing this configuration
63-
# file (e.g., nixCraft's sysctl.conf). Sources are not cited since this
64-
# is not an academic document. Please refer to Linux documentations
65-
# should you have any questions.
66-
67-
########## Kernel ##########
68-
69-
# enable ExecShield protection
70-
# 2 enables ExecShield by default unless applications bits are set to disabled
71-
# uncomment on systems without NX/XD protections
72-
# check with: dmesg | grep --color '[NX|DX]*protection'
73-
#kernel.exec-shield = 2
74-
75-
# enable ASLR
76-
# turn on protection and randomize stack, vdso page and mmap + randomize brk base address
77-
kernel.randomize_va_space = 2
78-
79-
# controls the System Request debugging functionality of the kernel
80-
kernel.sysrq = 0
81-
82-
# controls whether core dumps will append the PID to the core filename
83-
# useful for debugging multi-threaded applications
84-
kernel.core_uses_pid = 1
85-
86-
# restrict access to kernel address
87-
# kernel pointers printed using %pK will be replaced with 0’s regardless of privileges
88-
kernel.kptr_restrict = 2
89-
90-
# Ptrace protection using Yama
91-
# - 1: only a parent process can be debugged
92-
# - 2: only admins canuse ptrace (CAP_SYS_PTRACE capability required)
93-
# - 3: disables ptrace completely, reboot is required to re-enable ptrace
94-
kernel.yama.ptrace_scope = 3
95-
96-
# restrict kernel logs to root only
97-
kernel.dmesg_restrict = 1
98-
99-
# restrict BPF JIT compiler to root only
100-
kernel.unprivileged_bpf_disabled = 1
101-
102-
# disables kexec as it can be used to livepatch the running kernel
103-
kernel.kexec_load_disabled = 1
104-
105-
# disable unprivileged user namespaces to decrease attack surface
106-
kernel.unprivileged_userns_clone = 0
107-
108-
# allow for more PIDs
109-
# this value can be up to:
110-
# - 32768 (2^15) on a 32-bit system
111-
# - 4194304 (2^22) on a 64-bit system
112-
kernel.pid_max = 4194304
113-
114-
# reboot machine after kernel panic
115-
#kernel.panic = 10
116-
117-
########## File System ##########
118-
119-
# disallow core dumping by SUID/SGID programs
120-
fs.suid_dumpable = 0
121-
122-
# protect the creation of hard links
123-
# one of the following conditions must be fulfilled
124-
# - the user can only link to files that he or she owns
125-
# - the user must first have read and write access to a file, that he/she wants to link to
126-
fs.protected_hardlinks = 1
127-
128-
# protect the creation of symbolic links
129-
# one of the following conditions must be fulfilled
130-
# - the process following the symbolic link is the owner of the symbolic link
131-
# - the owner of the directory is also the owner of the symbolic link
132-
fs.protected_symlinks = 1
133-
134-
# enable extended FIFO protection
135-
fs.protected_fifos = 2
136-
137-
# similar to protected_fifos, but it avoids writes to an attacker-controlled regular file
138-
fs.protected_regular = 2
139-
140-
# increase system file descriptor limit
141-
# this value can be up to:
142-
# - 2147483647 (0x7fffffff) on a 32-bit system
143-
# - 9223372036854775807 (0x7fffffffffffffff) on a 64-bit system
144-
# be aware that the Linux kernel documentation suggests that inode-max should be 3-4 times
145-
# larger than this value
146-
fs.file-max = 9223372036854775807
147-
148-
########## Virtualization ##########
149-
150-
# improve mmap ASLR effectness
151-
vm.mmap_rnd_bits=32
152-
vm.mmap_rnd_compat_bits=16
153-
154-
########## Networking ##########
155-
156-
# increase the maximum length of processor input queues
157-
net.core.netdev_max_backlog = 250000
158-
159-
# enable BPF JIT hardening for all users
160-
# this trades off performance, but can mitigate JIT spraying
161-
net.core.bpf_jit_harden = 2
162-
163-
# increase TCP max buffer size setable using setsockopt()
164-
#net.core.rmem_max = 8388608
165-
#net.core.wmem_max = 8388608
166-
#net.core.rmem_default = 8388608
167-
#net.core.wmem_default = 8388608
168-
#net.core.optmem_max = 8388608
169-
170-
########## IPv4 Networking ##########
171-
172-
# enable BBR congestion control
173-
net.ipv4.tcp_congestion_control = bbr
174-
175-
# disallow IPv4 packet forwarding
176-
net.ipv4.ip_forward = 0
177-
178-
# enable SYN cookies for SYN flooding protection
179-
net.ipv4.tcp_syncookies = 1
180-
181-
# number of times SYNACKs for a passive TCP connection attempt will be retransmitted
182-
net.ipv4.tcp_synack_retries = 5
183-
184-
# do not send redirects
185-
net.ipv4.conf.default.send_redirects = 0
186-
net.ipv4.conf.all.send_redirects = 0
187-
188-
# do not accept packets with SRR option
189-
net.ipv4.conf.default.accept_source_route = 0
190-
net.ipv4.conf.all.accept_source_route = 0
191-
192-
# enable reverse path source validation
193-
# refer to RFC1812
194-
net.ipv4.conf.default.rp_filter = 1
195-
net.ipv4.conf.all.rp_filter = 1
196-
197-
# log packets with impossible addresses to kernel log
198-
net.ipv4.conf.default.log_martians = 1
199-
net.ipv4.conf.all.log_martians = 1
200-
201-
# do not accept ICMP redirect messages
202-
net.ipv4.conf.default.accept_redirects = 0
203-
net.ipv4.conf.default.secure_redirects = 0
204-
net.ipv4.conf.all.accept_redirects = 0
205-
net.ipv4.conf.all.secure_redirects = 0
206-
207-
# disable sending and receiving of shared media redirects
208-
# this setting overwrites net.ipv4.conf.all.secure_redirects
209-
# refer to RFC1620
210-
net.ipv4.conf.default.shared_media = 0
211-
net.ipv4.conf.all.shared_media = 0
212-
213-
# always use the best local address for announcing local IP via ARP
214-
net.ipv4.conf.default.arp_announce = 2
215-
net.ipv4.conf.all.arp_announce = 2
216-
217-
# reply only if the target IP address is local address configured on the incoming interface
218-
net.ipv4.conf.default.arp_ignore = 1
219-
net.ipv4.conf.all.arp_ignore = 1
220-
221-
# drop Gratuitous ARP frames to prevent ARP poisoning
222-
# this can cause issues when ARP proxies are used in the network
223-
net.ipv4.conf.default.drop_gratuitous_arp = 1
224-
net.ipv4.conf.all.drop_gratuitous_arp = 1
225-
226-
# ignore all ICMP echo requests
227-
#net.ipv4.icmp_echo_ignore_all = 1
228-
229-
# ignore all ICMP echo and timestamp requests sent to broadcast/multicast
230-
net.ipv4.icmp_echo_ignore_broadcasts = 1
231-
232-
# ignore bad ICMP errors
233-
net.ipv4.icmp_ignore_bogus_error_responses = 1
234-
235-
# mitigate TIME-WAIT Assassination hazards in TCP
236-
# refer to RFC1337
237-
net.ipv4.tcp_rfc1337 = 1
238-
239-
# disable TCP window scaling
240-
# this makes the host less susceptible to TCP RST DoS attacks
241-
net.ipv4.tcp_window_scaling = 0
242-
243-
# increase system IP port limits
244-
net.ipv4.ip_local_port_range = 1024 65535
245-
246-
# disable TCP timestamps for better CPU utilization
247-
net.ipv4.tcp_timestamps = 0
248-
249-
# enabling SACK can increase the throughput
250-
# but SACK is commonly exploited and rarely used
251-
net.ipv4.tcp_sack = 0
252-
253-
# divide socket buffer evenly between TCP window size and application
254-
net.ipv4.tcp_adv_win_scale = 1
255-
256-
# increase memory thresholds to prevent packet dropping
257-
#net.ipv4.tcp_rmem = 4096 87380 8388608
258-
#net.ipv4.tcp_wmem = 4096 87380 8388608
259-
260-
########## IPv6 Networking ##########
261-
262-
# disallow IPv6 packet forwarding
263-
net.ipv6.conf.default.forwarding = 0
264-
net.ipv6.conf.all.forwarding = 0
265-
266-
# number of Router Solicitations to send until assuming no routers are present
267-
net.ipv6.conf.default.router_solicitations = 0
268-
net.ipv6.conf.all.router_solicitations = 0
269-
270-
# do not accept Router Preference from RA
271-
net.ipv6.conf.default.accept_ra_rtr_pref = 0
272-
net.ipv6.conf.all.accept_ra_rtr_pref = 0
273-
274-
# learn prefix information in router advertisement
275-
net.ipv6.conf.default.accept_ra_pinfo = 0
276-
net.ipv6.conf.all.accept_ra_pinfo = 0
277-
278-
# setting controls whether the system will accept Hop Limit settings from a router advertisement
279-
net.ipv6.conf.default.accept_ra_defrtr = 0
280-
net.ipv6.conf.all.accept_ra_defrtr = 0
281-
282-
# router advertisements can cause the system to assign a global unicast address to an interface
283-
net.ipv6.conf.default.autoconf = 0
284-
net.ipv6.conf.all.autoconf = 0
285-
286-
# number of neighbor solicitations to send out per address
287-
net.ipv6.conf.default.dad_transmits = 0
288-
net.ipv6.conf.all.dad_transmits = 0
289-
290-
# number of global unicast IPv6 addresses can be assigned to each interface
291-
net.ipv6.conf.default.max_addresses = 1
292-
net.ipv6.conf.all.max_addresses = 1
293-
294-
# enable IPv6 Privacy Extensions (RFC3041) and prefer the temporary address
295-
net.ipv6.conf.default.use_tempaddr = 2
296-
net.ipv6.conf.all.use_tempaddr = 2
297-
298-
# ignore all ICMPv6 echo requests
299-
#net.ipv6.icmp.echo_ignore_all = 1
300-
#net.ipv6.icmp.echo_ignore_anycast = 1
301-
#net.ipv6.icmp.echo_ignore_multicast = 1
302-
```

0 commit comments

Comments
 (0)