quinta-feira, 29 de maio de 2014

Aumentando a segurança dos arquivos no FreeBSD.


Dica importante para administradores.

Você deve ser um usuário root para configurar chflags.

Use o comando chflags da seguinte forma:

# chflags schg /etc/resolv.conf

Tente remover ou modificar arquivo :

# rm -f /etc/resolv.conf

Você verá uma saída:

  rm: /etc/resolv.conf:  Operation not permitted

Agora o usuário root não tem permissão para remover ou modificar o arquivo resolv.conf .
Isso é útil para proteger arquivos importantes como /etc/passwd, /etc/master.passwd  e etc... Ou mesmo o /etc/resolv.conf que teima em ser modificado a cada boot .

como saber se o arquivo possui o chflags ligado ou desligado

# ls -lo /etc/resolv.conf

Você verá uma saída:

  -rw-r--r-- 1 root wheel schg,uarch 65 May 29 12:30 /etc/resolv.conf

Limpar o chflags :

# chflags noschg /etc/resolv.conf

Agora você pode remover ou modificar o arquivo.

Mais opções :

arch: definir a flag arquivado
nodump: definir a flag nodump
sappnd: definir a flag somente append do sistema
schg: definir a flag imutável do sistema
sunlnk: definir a flag undeletable do sistema
uappnd: definir a flag somente append do usuário
uchg: definir a flag imutável do usuário
uunlnk: definir a flag undeletable do usuário


Há também a opção de securelevel nativa no Kernel FreeBSD, que está nas referências - muito bem escrita pelo site bsdinfo.


Referências:

http://www.bsdinfo.com.br/2012/05/04/melhorando-a-seguranca-no-freebsd-com-securelevel-chflags/

http://www.cyberciti.biz/tips/howto-write-protect-file-with-immutable-bit.html

Compilando um kernel FreeBSD 10.0

Compilando um kernel FreeBSD 10.0

Dica para "não esquecer".

Um kernel FreeBSD é extremamente simples de se compilar, basta adicionar as opções no arquivo TXT.

Obtendo o Kernel

# pkg install subversion

# rehash

# svn checkout svn://svn.freebsd.org/base/releng/10.0/ /usr/src


Dicas para o arquivo de configuração.

# cd /usr/src/sys/amd64/conf

# cp GENERIC NOVOKERNEL

# ee NOVOKERNEL

##No inicio substitua o GENERIC

ident                 NOVOKERNEL
machine amd64


###Eu adiciono tudo no final
device          pf
device          pflog
options         ALTQ
options         ALTQ_CBQ        # Class Bases Queuing (CBQ)
options         ALTQ_RED        # Random Early Detection (RED)
options         ALTQ_RIO        # RED In/Out
options         ALTQ_HFSC       # Hierarchical Packet Scheduler (HFSC)
options         ALTQ_PRIQ       # Priority Queuing (PRIQ)
options         ALTQ_NOPCC      # Required for SMP build

options         IPFIREWALL
options         IPDIVERT
options         IPFIREWALL_VERBOSE
options         IPFIREWALL_VERBOSE_LIMIT=10
options         IPFIREWALL_DEFAULT_TO_ACCEPT
options         IPFIREWALL_FORWARD
options         IPFIREWALL_NAT
options         LIBALIAS

#Squid Options
options         MSGMNB=16384
options         MSGMNI=41
options         MSGSEG=2049
options         MSGSSZ=64
options         MSGTQL=512
options         SHMSEG=16
options         SHMMNI=32
options         SHMMAX=2097152
options         SHMALL=3096

#Qos
options         DUMMYNET

# Support TCP sign. Used for IPSec
options         TCP_SIGNATURE
options         IPSEC

# Change normal|kernel messages color
options         SC_NORM_ATTR=(FG_GREEN|BG_BLACK)
options         SC_KERNEL_CONS_ATTR=(FG_YELLOW|BG_BLACK)
# # More scroll space
options         SC_HISTORY_SIZE=8192
#
# # Adding hardware crypto device
device          crypto
device          cryptodev

# Useful network interfaces
device          tap                     #Virtual Ethernet driver
device          gre                     #IP over IP tunneling
device          if_bridge               #Bridge interface
device          pfsync                  #synchronization interface for PF
device          carp                    #Common Address Redundancy Protocol
device          enc                     #IPsec interface
device          lagg                    #Link aggregation interface
device          stf                     #IPv4-IPv6 port

options    ROUTETABLES=6

# Virtual networking for jail
options         VIMAGE
device          epair
#
# The nullFS to mount local directory
options         NULLFS

#####EOF

Compilando o Kernel :

# cd /usr/src

Para compilar:

# make buildkernel KERNCONF=NOVOKERNEL

Para instalar:

# make installkernel KERNCONF=NOVOKERNEL


Assim que terminar ...

# reboot

Feito isso basta esperar a máquina subir para conferir com:

# uname -a

Se o seu NOVOKERNEL estará na descrição.

um abraço.

Referências:

https://www.freebsd.org/doc/handbook/kernelconfig.html

http://www.freebsd.org/doc/handbook/kernelconfig-building.html