Security
  Home arrow Security arrow 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
    ( Page 1 of 10 )

    Security isn't a noun, it's a verb; not a product, but a process. Today, learn the hacks involved in reducing the risks involved in offering services on a Unix-based system. This the second part of chapter one in Network Security Hacks, by Andrew Lockhart (ISBN 0-596-00643-8, O'Reilly & Associates, 2004).

    Use proftp with a MySQL Authentication Source Hack #11

    Make sure that your database system’s OS is running as efficiently as possible with these tweaks.

    Networ Security Hacksproftpd is a powerful FTP daemon with a configuration syntax much like Apache. It has a whole slew of options not available in most FTP daemons, including ratios, virtual hosting, and a modularized design that allows people to write their own modules.

    One such module is mod_sql, which allows proftpd to use a SQL database as its back-end authentication source. Currently, mod_sql supports MySQL and PostgreSQL. This can be a good way to help lock down access to your server, as inbound users will authenticate against the database (and therefore not require an actual shell account on the server). In this hack, we’ll get proftpd authenticating against a MySQL database.

    First, download and build the source to proftpd and mod_sql:

    ~$ bzcat proftpd-1.2.6.tar.bz2 | tar xf -
    ~/proftpd-1.2.6/contrib$ tar zvxf ../../mod_sql-4.08.tar.gz
    ~/proftpd-1.2.6/contrib$ cd ..
    ~/proftpd-1.2.6$ ./configure --with-modules=mod_sql:mod_sql_mysql
    --with-includes=/usr/local/mysql/include/
    --with-libraries=/usr/local/mysql/lib/

    (Naturally, substitute the path to your mySQL install, if it isn’t in /usr/local/mysql/.) Now, build the code and install it:

    rob@catlin:~/proftpd-1.2.6$ make && sudo make install

    Next, create a database for proftpd to use (assuming that you already have mysql up and running):

    $ mysqladmin create proftpd

    Then, permit read-only access to it from proftpd:

    $ mysql -e "grant select on proftpd.* to proftpd@localhost
    identified by 'secret';"

    Create two tables in the database, with this schema:

    CREATE TABLE users (
    userid varchar(30) NOT NULL default '',
    password varchar(30) NOT NULL default '',
    uid int(11) default NULL,
    gid int(11) default NULL,
    homedir varchar(255) default NULL,
    shell varchar(255) default NULL,
    UNIQUE KEY uid (uid),
    UNIQUE KEY userid (userid)
    ) TYPE=MyISAM;


    CREATE TABLE groups (
    groupname varchar(30) NOT NULL default '',
    gid int(11) NOT NULL default '0',
    members varchar(255) default NULL
    ) TYPE=MyISAM;

    One quick way to create the tables is to save this schema to a file called proftpd.schema and run a command like mysql proftpd < proftpd.schema.

    Now we need to tell proftpd to use this database for authentication. Add the following lines to /usr/local/etc/proftpd.conf:

    SQLConnectInfo proftpd proftpd secret
    SQLAuthTypes crypt backend
    SQLMinUserGID 111
    SQLMinUserUID 111

    The SQLConnectInfo line takes the form database user password. You could also specify a database on another host (even on another port) with something like:

    SQLConnectInfo proftpd@dbhost:5678 somebody somepassword

    The SQLAuthTypes line lets you create users with passwords stored in the standard Unix crypt format, or mysql’s PASSWORD( ) function. Be warned that if you’re using mod_sql’s logging facilities, the password may be exposed in plain text, so keep those logs private.

    The SQLAuthTypes line as specified won’t allow blank passwords; if you need that functionality, also include the empty keyword. The SQLMinUserGID and SQLMinUserUID lines specify the minimum group and user ID that proftpd will permit on login. It’s a good idea to make this greater than 0 (to prohibit root logins), but it should be as low as you need to allow proper permissions in the filesystem. On this system, we have a user and group called www, with both its uid and gid set to 111. As we’ll want web developers to be able to log in with these permissions, we’ll need to set the minimum values to 111.

    Finally, we’re ready to create users in the database. This will create the user jimbo, with effective user rights as www/www, and dump him in the /usr/local/apache/htdocs/ directory at login:

    mysql -e "insert into users values ('jimbo',PASSWORD('sHHH'),'111',
    '111', '/usr/local/apache/htdocs','/bin/bash');" proftpd

    The password for jimbo is encrypted with mysql’s PASSWORD( ) function before being stored. The /bin/bash line is passed to proftpd to pass proftpd’s RequireValidShell directive. It has no bearing on granting actual shell access to the user jimbo.

    At this point, you should be able to fire up proftpd and log in as user jimbo, with a password of sHHH. If you are having trouble getting connected, try running proftpd in the foreground with debugging on, like this:

    # proftpd -n -d 5

    Watch the messages as you attempt to connect, and you should be able to track down the source of difficulty. In my experience, it’s almost always due to a failure to set something properly in proftpd.conf, usually regarding permissions.

    The mod_sql module can do far more than I’ve shown here; it can connect to existing mysql databases with arbitrary table names, log all activity to the database, modify its user lookups with an arbitrary WHERE clause, and much more.

    See Also

    • The mod_sql home page at http://www.lastditcheffort.org/~aah/proftpd/mod_sql/

    • The proftpd home page at http://www.proftpd.org/

    —Rob Flickenger (Linux Server Hacks)

    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 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek