Acabei encontrando o script abaixo que era executado para o hardening de alguns servidores Linux que trabalhávamos. Vejam que não há a instalação de nenhum pacote ou módulo adicional ao sistema operacional, somente a sua execução.
Eu revi muitos destes parâmetros e posso dizer que há mais coisa para ser adicionada – mas vai a dica:
Crie um arquivo loco.sh, jogue o código dentro dele
#! /bin/bash
set -x # eu gosto de ver o que e aonde o script pode parar por causa de alguma cagada
# Configurando o path dos executáveis usados no script
export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
# Mudando a permissão dos arquivos com SUID, exceto alguns :
# /sbin/pwdb_chkpwd
# /sbin/unix_chkpwd
# /sbin/pam_timestamp_check
# /bin/su
# /usr/bin/passwd
# /usr/bin/sudo
# /usr/bin/crontab
find / \( -perm -4000 -o -perm -2000 \) -mount -type f -print > /tmp/suids
sed -e '/\/sbin\/pwdb_chkpwd/ d' \
-e '/\/sbin\/unix_chkpwd/ d'\
-e '/\/sbin\/pam_timestamp_check/ d'\
-e '/\/bin\/su/ d'\
-e '/\/usr\/bin\/passwd/ d'\
-e '/\/usr\/bin\/sudo/ d'\
-e '/\/usr\/bin\/crontab/ d'\
/tmp/suids > /tmp/suids2
for arquivo in $(cat /tmp/suids2); do
chmod -s $arquivo
done
rm /tmp/suids /tmp/suids2
# Mundando a permissão dos compiladores
chmod go-rwx /usr/bin/gcc
chmod go-rwx /usr/bin/cc
# Parando os serviços desnecessários
service gpm stop
service apmd stop
service atd stop
service xinetd stop
service sendmail stop
service cups stop
# Retirando do startup os serviços desnecessários
chkconfig --level 12345 cups off
chkconfig --level 12345 sendmail off
chkconfig --level 12345 xinetd off
chkconfig --level 12345 gpm off
chkconfig --level 12345 apmd off
chkconfig --level 12345 atd off
# -> Criado por Robs
# ctrl alt del p/ boot
sed 's/^ca::ctrlaltdel/#ca::ctrlaltdel/' /etc/inittab > tmp.01
mv tmp.01 /etc/inittab
# password no grub
grep ^password /boot/grub/grub.conf >/dev/null 2>&1
case "$?" in
0)
;;
1)
echo -n "senha do LOADER:"
read -r password
if test "x$password" = x; then
echo "password em branco"
fi
md5=`grub --batch --device-map=/dev/null <
cat /boot/grub/grub.conf >> tmp.01
mv tmp.01 /boot/grub/grub.conf
chmod 600 /boot/grub/grub.conf
fi
;;
2)
esac
# seguranca de rede
grep ^net.ipv4.tcp_syncookies=1 /etc/sysctl.conf >/dev/null 2>&1
if test $? = 1; then
echo 'net.ipv4.conf.all.forwarding=0
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.all.log_martians=1
net.ipv4.conf.all.rp_filter=1
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.tcp_syncookies=1
net.ipv4.icmp_ignore_bogus_error_responses=1
#net.ipv4.icmp_echo_ignore_broadcasts=0
#net.ipv4.icmp_ignore_bogus_error_responses=0
net.ipv4.ip_local_port_range = 16384 65535
net.ipv4.ipfrag_high_thresh = 512000
net.ipv4.ipfrag_low_thresh = 446464
net.ipv4.tcp_mem = 688128 737280 786432
net.ipv4.tcp_wmem = 393216 1572864 12582912
net.ipv4.tcp_rmem = 1179648 4718592 37748736
net.ipv4.tcp_max_tw_buckets = 2000000
net.ipv4.tcp_max_syn_backlog = 8192
kernel.msgmni = 1024
kernel.sem = 1000 32000 32 512
kernel.shmmax = 2147483648
fs.file-max = 65535
vm.bdflush = 100 1200 128 512 500 6000 500 0 0
vm.kswapd = 1024 32 16
vm.page-cluster = 16
vm.pagetable_cache = 35 60
net.core.rmem_max = 6291360
net.core.rmem_default = 6291360
net.core.wmem_max = 6291360
net.core.wmem_default = 6291360
net.core.optmem_max = 688128
net.core.hot_list_length = 12288
' >> /etc/sysctl.conf
sysctl -p
fi
# auditagem
chmod o-rwx /var/log/*
# perm xinetd
chmod 700 /etc/xinetd.d
chmod 600 /etc/xinetd.conf
# tamanho e expiracao do password
sed '/^PASS_MIN_LEN/c \
PASS_MIN_LEN 8
/^PASS_MAX_DAYS/c \
PASS_MAX_DAYS 30
' /etc/login.defs > tmp.01
mv tmp.01 /etc/login.defs
# su irrestrito
chgrp wheel /bin/su
chmod 4750 /bin/su
# criando usuarios
useradd -g 10 -u 1505 -d /home/bob -s /bin/bash bob
useradd -g 10 -u 1500 -d /home/buba -s /bin/bash buba
useradd -g 10 -u 1510 -d /home/glima -s /bin/bash glima
chown -R weblogic:as /bea /domains
echo bob!@#' | passwd --stdin bob
echo buba!@#' | passwd --stdin buba
echo glima!@#' | passwd --stdin glima
# Alteração no /etc/security/limits.conf
echo bob soft nofile 50000
bob hard nofile 50000
bob soft nproc 10000
bob hard nproc 10000' >> /etc/security/limits.conf
Quanto aos parâmetros/semáforos do Kernel, eu prefiro a seguinte lista abaixo, mas cuidado, não são todos os ambientes onde estes parâmetros poderão ser configurados. Eu estou me referindo ao mundo virtualizado. Outro ponto de atenção é quanto a parametrização dos buffers e utilização de memória das interfaces de rede. Isso pode mudar e muito de acordo com o modelo de cada interface.
Por isso que eu digo “Lei a porra do manual antes de fazer merda” ou em inglês – Read The Fuck Manual
#Kernel sysctl configuration file for Red Hat Linux
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Disables packet forwarding
net.ipv4.ip_forward=0
# Disables IP source routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.lo.accept_source_route = 0
net.ipv4.conf.eth0.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
# Enable IP spoofing protection, turn on source route verification
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.lo.rp_filter = 1
net.ipv4.conf.eth0.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
# Disable ICMP Redirect Acceptance
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.lo.accept_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
# Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets
net.ipv4.conf.all.log_martians = 0
net.ipv4.conf.lo.log_martians = 0
net.ipv4.conf.eth0.log_martians = 0
# Disables IP source routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.lo.accept_source_route = 0
net.ipv4.conf.eth0.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
# Enable IP spoofing protection, turn on source route verification
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.lo.rp_filter = 1
net.ipv4.conf.eth0.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
# Disable ICMP Redirect Acceptance
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.lo.accept_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
# Disables the magic-sysrq key
kernel.sysrq = 0
# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout = 15
# Decrease the time default value for tcp_keepalive_time connection
net.ipv4.tcp_keepalive_time = 1800
# Turn off the tcp_window_scaling
net.ipv4.tcp_window_scaling = 0
# Turn off the tcp_sack
net.ipv4.tcp_sack = 0
# Turn off the tcp_timestamps
net.ipv4.tcp_timestamps = 0
# Enable TCP SYN Cookie Protection
net.ipv4.tcp_syncookies = 1
# Enable ignoring broadcasts request
net.ipv4.icmp_echo_ignore_broadcasts = 1
# Enable bad error message Protection
net.ipv4.icmp_ignore_bogus_error_responses = 1
# Log Spoofed Packets, Source Routed Packets, Redirect Packets
net.ipv4.conf.all.log_martians = 1
# Increases the size of the socket queue (effectively, q0).
net.ipv4.tcp_max_syn_backlog = 1024
# Increase the tcp-time-wait buckets pool size
net.ipv4.tcp_max_tw_buckets = 1440000
# Allowed local port range
net.ipv4.ip_local_port_range = 16384 65536
O borther Clandestine4 deu a dica de um script feito em perl que faz o hardening de servers CentOS
Bom Dia Gustavo,
Temos também o Bastille que nos ajuda a fazer uma melhor segurança do servidor.
Show de bola os scripts.
Abraços Marcos Carraro
borther?
Valeu Gustavo, vou testa-lo.
Loucuras e devaneios de um mau digitador
Por um acaso essa apostila você vai disponibilizar para quem for no Security Forum? rs
O security fórum foi em Abril de 2011.. 🙂
Ah Gustavo, você entedeu.. no Workshop que irá acontecer amanhã e que inclusive estarei presente..rs rs
Ah Gustavo, você entendeu.. no Workshop que irá acontecer amanhã e que inclusive estarei presente..rs rs
Alguém conhece algum livro bom de hardening voltado para REDHAT ou CENTOS? ou pelo menos genérico?
Obrigado!!
Conheço um execlente para Red Hat 5.x feito pela NSA :
http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdfSimilares
Valeu pela dica..