CGI: Safety First
With the current Web hype a system administrator's nightmare has come true: every user on his system wants to have a home page and wants to do CGI programming. The urge to be on the Web is too strong to keep them off. If they had some elementary knowledge of security, things would not be so bad, but this is not the case: most of those users grew up with MS-DOS, where insecurity is a de facto standard. They have a dangerous attitude toward your system.
One major problem with CGI programming is writing to a file; the web server doesn't run as the user who wrote the CGI script—when it tries to write something in a file, it gets a permission denied error. Lowering the permission of that file isn't a solution—it is just plain disastrous.
As you might know, a web server (typically called httpd) can be run by any user. However, if you want to have the server listening on the HTTP port (port no. 80 according to STD 2, the Internet standard describing “Assigned Numbers”, at this moment, RFC 1700), it must be started up as root. Normally this is done at boot time from one of the rc files located in /etc. Since running the web server as root is a serious breach of security, all web servers can be configured to run as a different user, say user “www”.
You normally would see one server, running as root, which is responsible for opening port 80 and forking off a copy of itself that is running as www. It starts up as many servers as are needed to handle your load (you can often set a minimum and maximum number of servers in the configuration files). The one running as root does no HTTP stuff—that is done by child servers running as www.
There is one inherent security risk in running CGI scripts when everybody can write CGI scripts: the scripts can be read by other users. Even if you remove read permission of others and make the script readable and executable by the server's group only, another person can write a script reading the source of your script. If it is important that the source of the program remains secure, you shouldn't be writing a script. Compiled programs don't have to be readable to be executable, whereas scripts must be both readable and executable.
Before we proceed with the real issue, just consider a few of the consequences of the server running as www. Consider the following script:
#!/bin/sh cp /bin/sh /home/cracker/bin/sh chmod 4755 /home/cracker/bin/sh cat << EOF Content-type: text/plain There is no such thing as a secure server! EOF
You now have created a suid www shell that any cracker can use! For this reason it is important that the user www not have a home directory and not own any important files. Another infamous trick is to send a STOP signal to all servers; that is really sneaky (do you know why?). If you find these kinds of scripts unacceptable, you should ban CGI programming for everybody on your system except a few trusted users.
It should be clear that running all your servers as root is a definite no-no. It is like removing the password entry of root from the password file. If all your servers run as root, dash to your system administrator to correct this and don't leave before it is corrected. If he is hard to convince, well, you have root privileges and maybe you should give him a demonstration of how you can correct his mistake!
The trouble starts when user foo wants to write something in a file. Well, just for the sake of argument we will increment an access counter in a file ~foo/www/access. For example, look at the script counter.sh (it is not very customary to use a Bourne script for CGI programming, but it does the job):
#!/bin/sh ACCESS= ACCESS= rm /home/foo/www/access echo $ACCESS > /home/foo/www/access cat << EOF Content-type: text/plain You are number $ACCESS to visit this page! EOF
A nice little script with one problem: it does not work. It would have worked if foo had executed it, but alas, www was the one who ran the script. User foo might then immediately lower his security by entering: chmod 666 access. And since he noticed his default permissions are always wrong, he makes sure he regularly does a chmod 666 *--being unaware of the option of setting his UMASK. Don't think this doesn't occur in real life—I've had several colleagues doing exactly that. Be assured, they were all dedicated MS-DOS users.
Some of them learned it is easier if he doesn't change the files individually, but rather the directories (I almost jumped out of my room when I heard this one): chmod 777 . He didn't realize the writing succeeded because the daemon was able to remove the file access. But not just www could have done it—anybody could have done it!
Quickly entering chmod 1777 may seem the right thing to do. Don't you believe it. Indeed, it isn't that bad, but still, anybody on your system can remove that file with a CGI script.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- SUSE LLC's SUSE Manager
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- My +1 Sword of Productivity
- Managing Linux Using Puppet
- Non-Linux FOSS: Caffeine!
- Doing for User Space What We Did for Kernel Space
- SuperTuxKart 0.9.2 Released
- Google's SwiftShader Released
- Parsing an RSS News Feed with a Bash Script
- Rogue Wave Software's Zend Server
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide