Grsecurity Kurulumu (Kernel 2.6.14.3 Fedora, Centos ve Redhat)

From Lapis Wiki

Jump to: navigation, search
Bu makale NASIL bölümü serisinin bir parçasıdır
MasaÜstü Donanım Dağıtımlar
Tarayıcılar Programlama Linux ve Oyunlar


Konu başlıkları

Başlarken

Bu yazıda en son kernel sürümü ile grsecurityin patchlenmesini anlatacağım. Bu yazıda geçenler tüm Redhat ailesinde sorunsuz şekilde uygulanabilir.

Grsecurity Nedir

Grsecurity, Kernel seviyesinde uygulanan güvenliği arttırmak için bir çok yama ve seçenekten oluşmaktadır. Sadece çekirdeği sağlamlaştırmakla kalmayıp, olabilicek açıklara karşı sistemi korumaktadır. Grsecurity temel olarak 3 aşamadan oluşur: Bunlar:

  • Tanımlama
  • Bildirme
  • Önleme

Bu yazı genel olarak sunucular için hazırlanmıştır. Normal ev kullanıcılarının kernellerini grsecurity ile yama yapmaları çok gerekli değildir.

Grsecurity nin genel özellikleri şunlardır.

   * Role-Based Access Control
   * User, group, and special roles
   * Domain support for users and groups
   * Role transition tables
   * IP-based roles
   * Non-root access to special roles
   * Special roles that require no authentication
   * Nested subjects
   * Variable support in configuration
   * And, or, and difference set operations on variables in configuration
   * Object mode that controls the creation of setuid and setgid files
   * Create and delete object modes
   * Kernel interpretation of inheritance
   * Real-time regular-expression resolution
   * Ability to deny ptraces to specific processes
   * User and group transition checking and enforcement on an inclusive or exclusive basis
   * /dev/grsec entry for kernel authentication and learning logs
   * Next-generation code that produces least-privilege policies for the entire system with no configuration
   * Policy statistics for gradm
   * Inheritance-based learning
   * Learning configuration file that allows the administrator to enable inheritance-based learning or disable learning on specific paths
   * Full pathnames for offending process and parent process
   * RBAC status function for gradm
   * /proc/<pid>/ipaddr gives the remote address of the person who started a given process
   * Secure policy enforcement
   * Supports read, write, append, execute, view, and read-only ptrace object permissions
   * Supports hide, protect, and override subject flags
   * Supports the PaX flags
   * Shared memory protection feature
   * Integrated local attack response on all alerts
   * Subject flag that ensures a process can never execute trojaned code
   * Full-featured fine-grained auditing
   * Resource, socket, and capability support
   * Protection against exploit bruteforcing
   * /proc/pid filedescriptor/memory protection
   * Rules can be placed on non-existent files/processes
   * Policy regeneration on subjects and objects
   * Configurable log suppression
   * Configurable process accounting
   * Human-readable configuration
   * Not filesystem or architecture dependent
   * Scales well: supports as many policies as memory can handle with the same performance hit
   * No runtime memory allocation
   * SMP safe
   * O(1) time efficiency for most operations
   * Include directive for specifying additional policies
   * Enable, disable, reload capabilities
   * Option to hide kernel processes

Chroot restrictions

   * No attaching shared memory outside of chroot
   * No kill outside of chroot
   * No ptrace outside of chroot (architecture independent)
   * No capget outside of chroot
   * No setpgid outside of chroot
   * No getpgid outside of chroot
   * No getsid outside of chroot
   * No sending of signals by fcntl outside of chroot
   * No viewing of any process outside of chroot, even if /proc is mounted
   * No mounting or remounting
   * No pivot_root
   * No double chroot
   * No fchdir out of chroot
   * Enforced chdir("/") upon chroot
   * No (f)chmod +s
   * No mknod
   * No sysctl writes
   * No raising of scheduler priority
   * No connecting to abstract unix domain sockets outside of chroot
   * Removal of harmful privileges via capabilities
   * Exec logging within chroot

Address space modification protection

   * PaX: Page-based implementation of non-executable user pages for i386, sparc, sparc64, alpha, parisc, amd64, ia64, and ppc; negligible performance hit on all i386 CPUs but Pentium 4
   * PaX: Segmentation-based implementation of non-executable user pages for i386 with no performance hit
   * PaX: Segmentation-based implementation of non-executable KERNEL pages for i386
   * PaX: Mprotect restrictions prevent new code from entering a task
   * PaX: Randomization of stack and mmap base for i386, sparc, sparc64, alpha, parisc, amd64, ia64, ppc, and mips
   * PaX: Randomization of heap base for i386, sparc, sparc64, alpha, parisc, amd64, ia64, ppc, and mips
   * PaX: Randomization of executable base for i386, sparc, sparc64, alpha, parisc, amd64, ia64, and ppc
   * PaX: Randomization of kernel stack
   * PaX: Automatically emulate sigreturn trampolines (for libc5, glibc 2.0, uClibc, Modula-3 compatibility)
   * PaX: No ELF .text relocations
   * PaX: Trampoline emulation (GCC and linux sigreturn)
   * PaX: PLT emulation for non-i386 archs
   * No kernel modification via /dev/mem, /dev/kmem, or /dev/port
   * Option to disable use of raw I/O
   * Removal of addresses from /proc/<pid>/[maps|stat]

Auditing features

   * Option to specify single group to audit
   * Exec logging with arguments
   * Denied resource logging
   * Chdir logging
   * Mount and unmount logging
   * IPC creation/removal logging
   * Signal logging
   * Failed fork logging
   * Time change logging

Randomization features

   * Larger entropy pools
   * Randomized PIDs
   * Randomized TCP source ports

Other features

   * /proc restrictions that don't leak information about process owners
   * Symlink/hardlink restrictions to prevent /tmp races
   * FIFO restrictions
   * Dmesg(Cool restriction
   * Enhanced implementation of Trusted Path Execution
   * GID-based socket restrictions
   * Nearly all options are sysctl-tunable, with a locking mechanism
   * All alerts and audits support a feature that logs the IP address of the attacker with the log
   * Stream connections across unix domain sockets carry the attacker's IP address with them (on 2.4 only)
   * Detection of local connections: copies attacker's IP address to the other task
   * Automatic deterrence of exploit bruteforcing
   * Low, Medium, High, and Custom security levels
   * Tunable flood-time and burst for logging

Kerneli Güncelleme

2.4.x kernelden 2.6.x kernele çıkıcak olanlar module-init-tools paketini u güncellemeleri gerekir. Bu işlem şu şekilde yapılabilir:

cd /usr/local/src/
wget http://www.kernel.org/pub/linux/kernel/people/rusty/modules/old/module-init-tools-3.0.tar.gz
tar -zxf module-init-tools-3.0.tar.gz
cd module-init-tools-3.0
./configure --prefix=""
make moveold
make install
./generate-modprobe.conf /etc/modprobe.conf
cd ..

Gerekli Paketlerin Yüklenmesi

Gcc ve bağımlılıklarının yüklenmesi

Fedora ve Centos için

yum install gcc

Redhat için

up2date gcc

ncurses.devel

ncurses-devel paketinin ve bağımlılıklarının yüklenmesi menuconfig kısmı için gerekli:

Fedora ve Centos için

yum install ncurses-devel

Redhat için

up2date ncurses-devel

Patch paketi ve bağımlılıklarının yüklenmesi

Fedora ve Centos için

yum install patch

Redhat için

up2date patch

Kurulum

Kerneli ve grsecurity yamasını indiriceğimiz dizine geçelim:

cd /usr/local/src

Kerneli çekelim:

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.3.tar.bz2


Grsecurity yi çekelim:

http://www.grsecurity.org/grsecurity-2.1.7-2.6.14.3-200511291802.patch.gz

Kerneli açalım

tar xvfj linux-2.6.14.3.tar.bz2

Grsecurity yi açalım

gzip -d grsecurity-2.1.7-2.6.14.3-200511291802.patch.gz

Kerneli yamalıyalım

patch -p0 < ./grsecurity-2.1.7-2.6.14.3-200511291802.patch

Kernel kaynak kodunun bulunduğu klasöre girelim

cd /usr/src/linux-2.6.14.3

Eski ayarları temizleyelim

make mrproper

Konfigurasyon menusune geçelim

make menuconfig

Burada sisteminizin ihtiyaçlarınıza göre gerekli modülleri ekleyip çıkardıktan sonra, Security Options kısmına geliyoruz:

NSA SELinux Support kısmını kapatıyoruz. Yani yanındaki işaretini kaldırıyoruz. Sonra grsecurity menusune giriyoruz:


Security Level kısmına gelip custom seçiyoruz. Genelde medium seçeğide bir çok sistemde çok rahat çalışacaktır. Ayar yapmak istemiyorsanız direk medium u seçip derlemeye başlayabilirsiniz. high ı seçerseniz bir çok panelde sorun yaşatıcaktır. Özellikle cpanel ve directadmin de denediğim için söylüyorum. Logrotate olayı düzgün çalışmayacak ve stats programlarıda düzgün şekilde işlemeyecektir.

Adress Space Protectionkısmına giriyoruz

Bu bölümde şu 3 seçeği seçiyoruz:

Deny writing to /dev/kmem, /dev/mem, and /dev/port   
Hide kernel symbols
Disable privileged I/O

Eper x masaüstünü kullanıyorsanız Disable privileged I/O kısmını seçmeyin. Yoksa sisteminiz açılmayacaktır.

Role Based Access Control Options kısmını olduğu gibi bırakın.

Filesystem Protections kısmına gelin burada şu seçenekleri seçin:

*] Proc restrictions                                                   
Restrict /proc to user only                                       
Additional restrictions                                           
Linking restrictions                                               
FIFO restrictions                                                     
Chroot jail restrictions 

Eğer ensim yada plesk kullanıyorsanız, chroot jail restirictions seçeneğini seçmeyin. Yoksa ensimin kendi chroot sisitemini bozacağı gibi, plesk'inde düzgün çalışmamasına neden olacaktır.

Kernel Auduting kısmını olduğu gibi bırakın.

Executable Protections kısmından aşağıdakiler seçin;

Destroy unused shared memory                                       
Dmesg(Cool restriction                       
Randomized PIDs 
Destroy unused shared memory


Network Protections kısmından şunları seçin:

Larger entropy pools                                               
Randomized TCP source ports 

Sysctl support ve logging options kısımlarını geçin. Sysctl support kısmında kernel ayarlarının özellikle yaptığınız grsecurity ayarlarının kerneli yeniden derlemeden değiştirmenizi sağlamaktadır.

Kernel Derleme

Sırasıyla aşağıdaki komutları verin. Eğer monolitnic yani modül desteği olmayan bir kernel hazırladıysanız herşeyi static olarak eklediyseniz make modules ve make modules_install kısımlarını atlayın:

make bzImage
make modules
make modules_install

Son olarak initial ramdisk oluşturucaz. Eğer bunu oluşturmazda grsecurity ile beraber derlerseniz grsecurity ile yamalanmış çekirdeği başlattığınızda alıcağınız hata şu olacaktır:

Kernel panic - not syncing vfs unable to mount root filesystem on unknown block 

initial ram disk oluşturuyoruz

mkinitrd /boot/initrd-2.6.14.3-grsec.img 2.6.14.3

Kerneli kullanım için hazırlıyoruz

cp .config /boot/config-2.6.14.3-grsec
cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.14.3-grsec
cp System.map /boot/System.map-2.6.14.3-grsec
ln -s /boot/System.map-2.6.14.3-grsec /boot/System.map

Olası Hatalar

/dev/mapper/control ile ilgili bir hata alırsanız aşağıdakini uygulayın:

rm -rf /boot/initrd-2.6.14.3-grsec.img
mkinitrd --omit-lvm-modules /boot/initrd-2.6.14.3-grsec.img 2.6.14.3

LILO veya GRUB Ayarlanması

Grub

pico /etc/grub.conf yazarak ayar dosyasını açıyoruz ve aşağıdaki işlemleri yapıyoruz:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd1,0)
#          kernel /boot/vmlinuz-version ro root=/dev/hdb1
#          initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=5
splashimage=(hd1,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.9-22.0.1.EL)
       root (hd1,0)
       kernel /boot/vmlinuz-2.6.9-22.0.1.EL ro root=LABEL=/1 rhgb quiet
       initrd /boot/initrd-2.6.9-22.0.1.EL.img

Yukardaki satırın altına şunu ekliyoruz;

title CentOS (2.6.14.3-grsec)
       root (hd1,0)
       kernel /boot/vmlinuz-2.6.14.3-grsec ro root=LABEL=/1 rhgb quiet
       initrd /boot/initrd-2.6.14.3-grsec.img


Sonra grub yazıyoruz ve yeni kernelle 1 kere başlatmak üzere ayarlıyoruz. Eğer düzgün başlarsa grub.conf ta default yazan değeri 1 yapıyorsunuz:

savedefault --default=1 --once

ve reboot yapın.

LILO

pico /etc/lilo.conf yazarak lilo konfigurasyon dosyasını açıyorsunuz:


prompt
timeout=50
default=2.4.21-32.0.1.E
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
message=/boot/message
lba32
image=/boot/vmlinuz-2.4.21-32.0.1.EL
       label=linux
       initrd=/boot/initrd-2.4.21-32.0.1.EL.img
       read-only
       append="root=LABEL=/"

Bu kısmın altına şunu ekliyoruz:

image=/boot/vmlinuz-2.6.14.3-grsec
       label=linux
       initrd=/boot/initrd-2.6.14.3.-grsec.img
       read-only
       append="root=LABEL=/"

Yeni kernelle 1 kere boot edicek şekilde ayarlıyoruz

lilo -v -v
lilo -R 2.6.14.3.-grsec

Eğer sorunsuz bir şekilde boot ederseniz gene lilo.conf dosyasını açıp default=2.4.21-32.0.1.E yazan kısımı default=2.6.14.3-grsec şeklinde değiştirip konsolda

lilo -v -v 

komutunu vererek mbr ye kaydedin.

Grsec3.jpg


Bağlantılar

Dahili Bağlantılar

Konu ile ilgili fikirlerinizi paylaşmak için; Lapis Wiki Başlığı


Harici Bağlantılar