Howto: Harden the Ubuntu Linux Kernel with sysctl

I ran across a nice sysctl.conf file that will help secure your computer and prevent many different attacks on your computer like Man In the Middle Attacks, Syn attacks, source routing scans/attacks, spoofing protection/logging, and many others, read below.

Lets Harden our kernel:
sudo gedit /etc/sysctl.conf
Now lets paste the following example below then ctrl-s save and exit
After you make the changes to the file lets apply the changes without a reboot:
sysctl -p
sysctl -w net.ipv4.route.flush=1

Example:
# 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.

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

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

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

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1

#Prevent SYN attack
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 2

# 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 = 1
net.ipv4.conf.lo.log_martians = 1
net.ipv4.conf.eth0.log_martians = 1

# 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

# Modify system limits for Ensim WEBppliance
fs.file-max = 65000

# 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

# Set maximum amount of memory allocated to shm to 256MB
kernel.shmmax = 268435456

# Improve file system performance
vm.bdflush = 100 1200 128 512 15 5000 500 1884 2

# Improve virtual memory performance
vm.buffermem = 90 10 60

# Increases the size of the socket queue (effectively, q0).
net.ipv4.tcp_max_syn_backlog = 1024

# Increase the maximum total TCP buffer-space allocatable
net.ipv4.tcp_mem = 57344 57344 65536

# Increase the maximum TCP write-buffer-space allocatable
net.ipv4.tcp_wmem = 32768 65536 524288

# Increase the maximum TCP read-buffer space allocatable
net.ipv4.tcp_rmem = 98304 196608 1572864

# Increase the maximum and default receive socket buffer size
net.core.rmem_max = 524280
net.core.rmem_default = 524280

# Increase the maximum and default send socket buffer size
net.core.wmem_max = 524280
net.core.wmem_default = 524280

# 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

# Increase the maximum memory used to reassemble IP fragments
net.ipv4.ipfrag_high_thresh = 512000
net.ipv4.ipfrag_low_thresh = 446464

# Increase the maximum amount of option memory buffers
net.core.optmem_max = 57344

# Increase the maximum number of skb-heads to be cached
net.core.hot_list_length = 1024

## DO NOT REMOVE THE FOLLOWING LINE!
## nsobuild:20051206


The above script was found here

Is there any other sysctl settings worth mentioning for hardening?

Expand full post here...

Comments

Free Up Cache Memory in Linux

In the past, I've been forced to do ridiculous things like cat a file larger than available RAM to /dev/null and edit gigabyte files which flood my cache with this data. Luckily, Linux kernels 2.6.16 and newer provide a mechanism to clear the inode, page, and dentry caches on demand avoiding all this headache. All you have to do is echo a value to the proc filesystem, and you're done.

To use /proc/sys/vm/drop_caches, just echo a number to it.

To free pagecache:
echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation and dirty objects are not freeable, the user should run "sync" first!

This was originally found @ http://www.linuxinsight.com/proc_sys_vm_drop_caches.html

Expand full post here...

Comments

Tweak Page Cache in Ubuntu Linux

Here I will provide you with some information to help you decide exactly how you would like to tweak your system. I have seen many sites with the swappiness tweak for linux without any documentation on what it does, so I'll try my best to explain this in a simple way.

If you want linux to use as little memory as possible for caching files, and as much memory as possible for processes, and only swap when the memory used by processes is more than the physical memory set swappiness to 0, instead of 60. Users who would like to never see application memory swapped out can set swappiness to zero. This setting uses ram efficently and pretty much ignores using swap until it absolutely needs to like if your running 10 openoffice's and a few firefox windows and some multimedia applications, it will be forced to swap, thats the only way it will. Unfortunately it flushes the applications from memory when you load a new one so you will notice a slower restart time when reloading the application

If you run allot of memory intensive applications like firefox, amarok, and openoffice all the time, you may want to set swappiness to 100 because it will swap more to disk when your current processes run out of physical memory. I noticed that everything was a bit more responsive with this running many programs at once, like when I close firefox and load up xChat then re-open firefox, it loaded a bit quicker since it was swapped. You can take advantage of this setting if you have a fast extra hard drive or a fast usb flash drive which you can use as swap. I have provided a readyboost for linux howto here

Lets get to tweak'n
sudo gedit /etc/sysctl.conf
To disable swapping application memory add the line:
vm.swappiness=0
To Swap more application data to disk when ram is exhausted
vm.swappiness=100

Basically what I would do is experiment with this setting and see what works best when you load up plenty of applications you use daily because leaving it at the default, 0, or 100 may not be the best option.

Please let us all know your specs and what setting works best for you.

Expand full post here...

Comments

Introducing PyTube YouTube leecher & audio/video encoder for Mobile Devices & More

What is PyTube?
PyTube is a another kick-ass application that hasnt gotten enough spotlight, it completely rocks, check out some of its features:

Search & Leech Videos From Youtube
Leech Videos from Other Video sites
Re-Encode Videos to iPhone/iPod/3gp/mp4/ogm/mpg/gif/amv
Insert Audio into Video
Generate Ringtones
Merge multiple Videos together
Resize Videos for Ipods->High Definition
Rotate videos
Construct a List of all your Videos to share with friends


Easy Interface














Integrated Search





















Multimedia Tools















Unlimited Downloads

















Local Multimedia Encoding















How to install PyTube:
Click System->Administration and then open up software sources
Click Add and add:
deb http://www.bashterritory.com/pytube/releases /
Reload then click here to install
or sudo apt-get install pytube
Once installed access PyTube via Applications->Sound & Video->PyTube Multimedia Converter


Have fun
More information from the elite authors site here

Expand full post here...

Comments

Save Streaming Videos in Mplayer in 4 Easy Steps

1. Copy the url of the streaming video mms://etc... or http://...
2. Open up a terminal.
3. mplayer -dumpstream -dumpfile stream_video_name.wmv mms://etc...
4. Wait for the stream dump.

Have any others tools worth mentioning?
Original Content found here

Expand full post here...

Comments

Get your fingerprint reader to work in Ubuntu

Project fprint homepage: http://reactivated.net/fprint/wiki/Main_Page
Packages for fprint: http://www.madman2k.net/comments/105

The fprint project aims to plug a gap in the Linux desktop: support for consumer fingerprint reader devices.


Previously, Linux support for such devices has been scattered amongst different projects (many incomplete) and inconsistent in that application developers would have to implement support for each type of fingerprint reader separately. For more information on where we came from, see the project history page.

We're trying to change that by providing a central system to support all the fingerprint readers we can get our hands on. The software is open source and in the long term we're shooting for adoption by distributions, integration into common desktop environments, etc.
Note: These instructions are intended for Ubuntu Hardy. I have not personally tried this on Gutsy, but if it works, let me know.

First off, remember that fprint is not entirely stable, and may not work all the time. A list of supported devices is here, and the list of unsupported devices is here.

1. First thing to do is add the [third-party] fprint repository to your sources file:
echo -e "# Fingerprint reader support (fprint)\ndeb http://ppa.launchpad.net/madman2k/ubuntu hardy main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list

2. Next, update your sources and install fprint:
sudo apt-get update
sudo apt-get install fprint-demo libfprint-dev libfprint0 libpam-fprint

3. Now you can enroll your fingers using either the terminal or a graphical user interface.
Terminal:
pam_fprint_enroll
GUI:
fprint_demo
4. Last thing to do is configure PAM so that the fingerprint reader can be useful. Open up your PAM authentication file and edit it:
sudo gedit /etc/pam.d/common-auth
5. Edit it to contain:
auth sufficient pam_fprint.so
auth required pam_unix.so nullok_secure

6. Enjoy your fingerprint reader support!

Steps 4 and 5 tell Ubuntu to check your fingerprint, and if that fails, then ask your password. This rule has some exceptions, one that I have encountered is on the login screen. I have to scan my fingerprint before typing my password. One thing I did notice is that when you use sudo in the terminal, it asks for your fingerprint, which I thought was pretty cool. One disadvantage is that anything using gksu does not seem to work properly, specifically because it does not tell you to scan your finger when needed.

Troubleshooting:
The one problem I ran into when using fprint was that I could not run fprint_demo without sudo. It failed with the error message below:

uru4000:error [dev_init] interface claim failed
fp:error [fp_dev_open] device initialisation failed, driver=uru4000


I decided to post my problem here on the forums.
Here is the solution. You have to add yourself to the plugdev group and then change the permissions of the usb folder to allow access to the plugdev group. You can verify you are in the plugdev group by using groups:
sudo usermod -a -G plugdev $USER
groups | grep plugdev # Make sure there is output from this
sudo chgrp -R plugdev /dev/bus/usb/

Then try running fprint_demo, and hopefully it will work:
fprint_demo

This content was found on the Ubuntu forums, please see here for updates

Expand full post here...

Comments

Easily Create Seperate Home partition with existing Drive or Partition without the need for a livecd in Ubuntu Linux

I recently wanted to create a seperate /home partition since I installed home on / and didnt want the hassle of waiting for the livecd to boot, so here is an easy tutorial that will explain how to setup a seperate /home partition with an existing empty drive or partition you already have without using a livecd.

Ok I have almost always had a seperate home partition, excluding the 3 times I have completely crashed my system and had to redo it all.

Reasons you should use a seperate home partition:
1. Easy backup/restore.
2. You can simply rm -rf / and pop in a livecd and be able to mount your home partition as /home without deleting users home directories and files.
3. You can use multiple linux Distro's with the /home partition
4. You dont have to worrie about the hassle of re-installing or upgrading ubuntu because everything you need is in your /home directory, you can simply backup all your apt packages via aptoncd.
5. You will get better performance accessing files in your /home directory since it is seperate from the filesystem.

First we sudo root then open/edit our /etc/fstab:
sudo -s
sudo gedit /etc/fstab

Now this is the line my fstab contained that we will comment out by putting a "#" symbol in front of the UUID of the empty drive
# /dev/sdb1
UUID=ffa4a03e-116f-4c41-8bb6-4f60bca8f7f9 /media/sdb1 ext3 defaults,noatime,errors=remount-ro 0 0

It will then look like this:
# /dev/sdb1
# UUID=ffa4a03e-116f-4c41-8bb6-4f60bca8f7f9 /media/sdb1 ext3 defaults,noatime,errors=remount-ro 0 0


Now lets scroll down to the bottom of the file and Create a new Line to make our empty disk be mounted as /home
# /dev/sdb1
UUID=ffa4a03e-116f-4c41-8bb6-4f60bca8f7f9 /home ext3 defaults,noatime,errors=remount-ro 0 0


Ok the Hard stuff is done, so we Save /etc/fstab with ctrl-s and exit, lets go back to the terminal and cd to /home:
cd /home
Ok now that we are in home we can issue our copy command to copy the contents of /home to our existing partition in /media/sdb1 as an example:
find . -depth -print0 | sudo cpio --null --sparse -pvd /media/sdb1/
Once this completes which will take a while if you have allot of data we mv the contents of our existing /home to a backup directory:
mkdir /oldhome
mv -R * /oldhome

Ok we are done, simply reboot and everything should be successful, if for some reason this doesn't work all you do is uncomment the fstab line we first edited and comment out the newest line or completely remove it, then umount /dev/"yourdrive" if it mounted, and cd /oldhome/ mv -R * /home and everything should be back to what it was when you rebooted

This took me 5 min to create and is very dangerous if you dont know what you are doing, do not attempt this.

I have an alternate tutorial that explains how to do the same thing above with instructions on creating a new partition here

Expand full post here...

Comments

Clicky Web Analytics