Security
  Home arrow Security arrow Page 8 - Unix Host Security: Hacks 11-20
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
SECURITY

Unix Host Security: Hacks 11-20
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 31
    2004-05-10


    Table of Contents:
  • Unix Host Security: Hacks 11-20
  • Prevent Stack-Smashing AttacksHack #12
  • Lock Down Your Kernel with grsecurity Hack #13
  • Restrict Applications with grsecurity Hack #14
  • Restrict System Calls with Systrace Hack #15
  • Automated Systrace Policy Creation Hack #16
  • Control Login Access with PAM Hack #17
  • Restricted Shell Environments Hack #18
  • Enforce User and Group Resource Limits Hack #19
  • Automate System Updates Hack #20

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Unix Host Security: Hacks 11-20 - Restricted Shell Environments Hack #18
    ( Page 8 of 10 )

    Keep your users from shooting themselves (and you) in the foot.

    Sometimes a sandboxed environment [Hack #10] is overkill for your needs. If you want to set up a restricted environment for a group of users that only allows them to run a few particular commands, you’ll have to duplicate all of the libraries and binaries for those commands for each user. This is where restricted shells come in handy. Many shells include such a feature, which is usually invoked by running the shell with the -r switch. While not as secure as a system call–based sandbox environment, it can work well if you trust your users not to be malicious, but worry that some might be curious to an unhealthy degree.

    Some common features of restricted shells are the ability to prevent a program from changing directories, to only allow the execution of commands using absolute pathnames, and to prohibit executing commands in other subdirectories. In addition to these restrictions, all of the command-line redirection operators are disabled. With these features, restricting the commands a user can execute is as simple as picking and choosing which commands should be available and making symbolic links to them inside the user’s home directory. If a sequence of commands needs to be executed, you can also create shell scripts owned by another user. These scripts will execute in a nonrestricted environment and can’t be edited within the environment by the user.

    Let’s try running a restricted shell and see what happens:

    $ bash -r
    bash: SHELL: readonly variable
    bash: PATH: readonly variable
    bash-2.05b$ ls
    bash: ls: No such file or directory
    bash-2.05b$ /bin/ls
    bash: /sbin/ls: restricted: cannot specify `/' in command names
    bash-2.05b$ exit
    $ ln -s /bin/ls .
    $ bash -r
    bash-2.05b$ ls -la
    total 24
    drwx------ 2 andrew andrew 4096 Oct 20 08:01 .
    drwxr-xr-x 4 root root 4096 Oct 20 14:16 ..
    -rw------- 1 andrew andrew 18 Oct 20 08:00 .bash_history
    -rw-r--r-- 1 andrew andrew 24 Oct 20 14:16 .bash_logout
    -rw-r--r-- 1 andrew andrew 197 Oct 20 07:59 .bash_profile
    -rw-r--r-- 1 andrew andrew 127 Oct 20 07:57 .bashrc
    lrwxrwxrwx 1 andrew andrew 7 Oct 20 08:01 ls -> /bin/ls

    Restricted ksh is a little different in that it will allow you to run scripts and binaries that are in your PATH, which can be set before entering the shell:

    $ rksh
    $ ls -la
    total 24
    drwx------ 2 andrew andrew 4096 Oct 20 08:01 .
    drwxr-xr-x 4 root root 4096 Oct 20 14:16 ..
    -rw------- 1 andrew andrew 18 Oct 20 08:00 .bash_history
    -rw-r--r-- 1 andrew andrew 24 Oct 20 14:16 .bash_logout
    -rw-r--r-- 1 andrew andrew 197 Oct 20 07:59 .bash_profile
    -rw-r--r-- 1 andrew andrew 127 Oct 20 07:57 .bashrc
    lrwxrwxrwx 1 andrew andrew 7 Oct 20 08:01 ls -> /bin/ls
    $ which ls
    /bin/ls
    $ exit

    This worked because /bin was in the PATH before we invoked ksh. Now let’s change the PATH and run rksh again:

    $ export PATH=.
    $ /bin/rksh
    $ /bin/ls
    /bin/rksh: /bin/ls: restricted
    $ exit
    $ ln -s /bin/ls .
    $ ls -la
    total 24
    drwx------ 2 andrew andrew 4096 Oct 20 08:01 .
    drwxr-xr-x 4 root root 4096 Oct 20 14:16 ..
    -rw------- 1 andrew andrew 18 Oct 20 08:00 .bash_history
    -rw-r--r-- 1 andrew andrew 24 Oct 20 14:16 .bash_logout
    -rw-r--r-- 1 andrew andrew 197 Oct 20 07:59 .bash_profile
    -rw-r--r-- 1 andrew andrew 127 Oct 20 07:57 .bashrc
    lrwxrwxrwx 1 andrew andrew 7 Oct 20 08:01 ls -> /bin/ls

    Restricted shells are incredibly easy to set up and can provide minimal restricted access. They may not be able to keep out determined attackers, but they certainly make a hostile user’s job much more difficult. 

    Buy the book! If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!

    Visit the O'Reilly Network http://www.oreillynet.com for more online content.



     
     
    >>> More Security Articles          >>> More By O'Reilly Media
     

       

    SECURITY ARTICLES

    - Critical Microsoft Visual Studio Security Pa...
    - US Faces Tech Security Expert Deficit
    - LAN Reconnaissance
    - An Epilogue to Cryptography
    - A Sequel to Cryptography
    - An Introduction to Cryptography
    - Security Overview
    - Network Security Assessment
    - Firewalls
    - What’s behind the curtain? Part II
    - What’s behind the curtain? Part I
    - Vectors
    - PKI: Looking at the Risks
    - A Quick Look at Cross Site Scripting
    - PKI Architectures: How to Choose One





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek