Security
  Home arrow Security arrow Page 8 - Unix Host Security: Hacks 11-20
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
SECURITY

Unix Host Security: Hacks 11-20
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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
     
     
    FaxWave - Free Trial.
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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

    - 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
    - Trust, Access Control, and Rights for Web Se...
    - Basic Concepts of Web Services Security
    - Safeguarding the Identity and Integrity of X...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway