Ir para o conteúdo

Linux Hardening - arquivo sysctl.conf

Banner

O sysctl é um utilitário que permite modificar os atributos do kernel do sistema e consequentemente habilitar algumas configurações de segurança. Este artigo tem por objetivo mostrar como aumentar o nível de segurança do kernel do linux com o hardening do arquivo sysctl.conf.

📚 Ajustando as configurações

Iniciaremos o processo de hardening editando o arquivo /etc/sysctl.conf.

Comando
sudo nano /etc/sysctl.conf

Em seguida devemos adicionar as seguintes linhas ao final do arquivo:

Configuração :
 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
##-------------------------------------------
# Ajustes de Segurança
##-------------------------------------------
# IP Spoofing protection
##-------------------------------------------
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1

##-------------------------------------------
# Ignore ICMP broadcast requests
##-------------------------------------------
net.ipv4.icmp_echo_ignore_broadcasts = 1

##-------------------------------------------
# Disable source packet routing
##-------------------------------------------
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0

##-------------------------------------------
# Block SYN attacks
##-------------------------------------------
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 5

##-------------------------------------------
# Ignore ICMP redirects
##-------------------------------------------
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.accept_redirects = 0

##-------------------------------------------
# Ignore send redirects
##-------------------------------------------
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0

##-------------------------------------------
# Log Martians (http://en.wikipedia.org/wiki/Martian_packet)
##-------------------------------------------
net.ipv4.conf.all.log_martians = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.default.secure_redirects = 0

##-------------------------------------------
# Disable IPv6 support
##-------------------------------------------
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

##-------------------------------------------
# Controls IP packet forwarding
##-------------------------------------------
net.ipv4.ip_forward = 0

##-------------------------------------------
# Controls the System Request debugging functionality of the kernel
##-------------------------------------------
kernel.sysrq = 0

##-------------------------------------------
# increase system file descriptor limit   
##-------------------------------------------    
fs.file-max = 65535

 ##-------------------------------------------
#Allow for more PIDs 
##-------------------------------------------
kernel.pid_max = 65536

##-------------------------------------------
#Increase system IP port limits
##-------------------------------------------
net.ipv4.ip_local_port_range = 2000 65000

##-------------------------------------------
# RFC 1337 fix
##-------------------------------------------
net.ipv4.tcp_rfc1337=1

##-------------------------------------------
#Addresses of mmap base, heap, stack and VDSO page are randomized
##-------------------------------------------
kernel.randomize_va_space=2

##-------------------------------------------
#Ignore bad ICMP errors
##-------------------------------------------
net.ipv4.icmp_ignore_bogus_error_responses=1

##-------------------------------------------
#Protects against creating or following links under certain conditions
##-------------------------------------------
fs.protected_hardlinks=1
fs.protected_symlinks=1

📚 Aplicando as novas configurações

Para carregar as novas configurações execute:

Comando
sudo sysctl -p



Banner

🔖 Referências

✅ Linux Kernel /etc/sysctl.conf Security Hardening



Banner


Última atualização: 2 de novembro de 2020

Comentários