Thursday, December 20, 2007

A Quick and Dirty Guide To Kernel Hardening with GrSecurity

The combination of the Linux kernel and GNU packages has always been regarded as a secure operating system, but can it be more secure? Kernel hardening is the answer to tightening up the Linux backbone. GrSecurity, a kernel patch for Linux, is one of the more popular approaches. After applying this patch and compiling a fresh kernel, your system will have a plethora of new security features.

The most significant feature is the addition of a role-based access control system (RBAC) that monitors what each user can execute based on their role and denies execution if they overstep their pre-defined rules. Other useful features include ip-based rules, extensive chroot restrictions, address space modification restrictions (PaX), auditing/logging features and /proc and dmesg anti-leak features. A full feature list can be found at the Grsecurity homepage.

Installing Grsecurity:

First we need to download the Linux kernel and Grsec patch.
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.19.2.tar.gz
$ wget http://grsecurity.net/grsecurity-2.1.10-2.6.19.2-200701222307.patch.gz
For your convenience, the PGP keys are located at:

http://GRSecurity.net/spender-gpg-key.asc
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.19.2.tar.gz.sign

Move the kernel and patch into the /usr/src directory.

$ su -c “cp linux-2.6* /usr/src; cp grsec* /usr/src”
Extract the kernel and patch (you need to be in root since you're working in /usr/src).
$ su
# tar zxvf linux-2.6.19.2.tar.gz
# gunzip grsecurity-2.1.10-2.6.19.2-200701222307.patch.gz
# patch -p0 < grsecurity-2.1.10-2.6.19.2-200701222307.patch
Start with the kernel configuration.
# make clean
# make mrproper
# make menuconfig
Choose all of the options that are required for your hardware, or use “make oldconfig” and se an old configuration file. When you arrive at the “GRSECURITY” section, enable it by hitting the spacebar. You are now prompted with an array of security features. Building a custom scheme is as easy as selecting a few features, or select a pre-defined security level based on your needs. Taylor Merry created a fantastic list that shows what each level of security provides. His table is listed below:

Low Security:
  • linking restrictions
  • fifo restrictions
  • random pids
  • enforcing nproc on execve()
  • restricted dmesg
  • random ip ids
  • enforced chdir("/") on chroot< /li>

Medium Security (includes all of the Low Security options):
  • random tcp source ports
  • altered ping ids
  • failed fork logging
  • time change logging
  • signal logging
  • deny mounts in chroot
  • deny double chrooting
  • deny sysctl writes in chroot
  • deny mknod in chroot
  • deny access to abstract AF_UNIX sockets out of chroot
  • deny pivot_root in chroot
  • denied writes of /dev/kmem, /dev/mem, and /dev/port• /proc restrictions with special gid set to 10 (usually wheel)
  • address space layout randomization

High Security (includes all of the Low and Medium Security options):
  • additional /proc restrictions
  • chmod restrictions in chroot
  • no signals, ptrace, or viewing processes outside of chroot
  • capability restrictions in chroot
  • deny fchdir out of chroot
  • priority restrictions in chroot
  • segmentation-based implementation of PaX
  • mprotect restrictions
  • removal of /proc//[maps|mem]
  • kernel stack randomization
  • mount/unmount/remount logging
  • kernel symbol hiding(18)
Outside of the options in these categories are a few additional options that can be enabled manually:
  • PaX: PAGEEXEC
  • PaX: EMUTRAMP
  • PaX: EMUSIGRT
  • PaX: Disallow ELF text relocations (DANGEROUS)
  • Disable privileged I/O (should not use with XFree86)
  • Hide kernel processes
  • Allow a user group access to /proc
  • Auditing options
  • Set up a single group that is the only one audited
  • Exec logging
  • Log execs within chroot
  • Chdir logging
  • IPC logging
  • Trusted path execution
  • Socket restrictions
  • Sysctl support
  • Netfilter Configuration: stealth match support(18) *1
For personal computers, I select “Low security” and enable all of the logging and auditing features. For servers and mission critical machines, I start with “Medium security” and add additional elements based on my own discretion.

After you have selected all of the necessary options, lets compile the kernel.

# make modules modules_install bzImage

Finally, copy the new kernel into your /boot directory and adjust your bootloader to load the new kernel. Your new kernel will be located in "usr/src/linux/arch/i386/boot/." At this point, you now have a Linux kernel with copious amounts of added security and protection.

Check back soon because our next article will show you how to use the role based access control system and how to compile programs to take advantage of the PaX address space modification restrictions!

References:
*1 Merry, Taylor. Linux Kernel Hardening. 18 November 2003

GrSecurity Homepage

PaX Homepage

5 comments:

Tacita said...

You write very well.

roshid said...

nice article.... nice writing skills... nice topic....

roshid

Access control system chennai

roshid said...

nice article.... nice writing skills... nice topic....

roshid

Access control system chennai

Smith said...

Hi,
You have done a great job, the points mentioned are quite interesting, you can find more on kernel security at:
http://www.eccouncil.org/training/course_outline/ceh_course_outline.aspx

Anonymous said...

Do You interesting of [b]Female use of Viagra[/b]? You can find below...
[size=10]>>>[url=http://listita.info/go.php?sid=1][b]Female use of Viagra[/b][/url]<<<[/size]

[URL=http://imgwebsearch.com/30269/link/viagra%2C%20tramadol%2C%20zithromax%2C%20carisoprodol%2C%20buy%20cialis/1_valentine3.html][IMG]http://imgwebsearch.com/30269/img0/viagra%2C%20tramadol%2C%20zithromax%2C%20carisoprodol%2C%20buy%20cialis/1_valentine3.png[/IMG][/URL]
[URL=http://imgwebsearch.com/30269/link/buy%20viagra/3_headsex1.html][IMG]http://imgwebsearch.com/30269/img0/buy%20viagra/3_headsex1.png[/IMG][/URL]
[b]Bonus Policy[/b]
Order 3 or more products and get free Regular Airmail shipping!
Free Regular Airmail shipping for orders starting with $200.00!

Free insurance (guaranteed reshipment if delivery failed) for orders starting with $300.00!
[b]Description[/b]

Generic Viagra (sildenafil citrate; brand names include: Aphrodil / Edegra / Erasmo / Penegra / Revatio / Supra / Zwagra) is an effective treatment for erectile dysfunction regardless of the cause or duration of the problem or the age of the patient.
Sildenafil Citrate is the active ingredient used to treat erectile dysfunction (impotence) in men. It can help men who have erectile dysfunction get and sustain an erection when they are sexually excited.
Generic Viagra is manufactured in accordance with World Health Organization standards and guidelines (WHO-GMP). Also you can find on our sites.
Generic [url=http://viagra.wilantion.ru]Viagra 100mg pills[/url] is made with thorough reverse engineering for the sildenafil citrate molecule - a totally different process of making sildenafil and its reaction. That is why it takes effect in 15 minutes compared to other drugs which take 30-40 minutes to take effect.
[b]online viagra pills
viagra insurance coverage
pfizer viagra discount
Viagra Nebenwirkung
how viagra saves chrismas
compare levitra and viagra
Viagra Turkey
[/b]
Even in the most sexually liberated and self-satisfied of nations, many people still yearn to burn more, to feel ready for bedding no matter what the clock says and to desire their partner of 23 years as much as they did when their love was brand new.
The market is saturated with books on how to revive a flagging libido or spice up monotonous sex, and sex therapists say “lack of desire” is one of the most common complaints they hear from patients, particularly women.