|By Matt Bishop||
|May 30, 2005 12:15 PM EDT||
The purpose of this article is to show how basic security principles can help you develop programs that are harder for the bad guys to break. We'll examine a simple function that executes a command as though it were typed at the keyboard, exactly what the library function system does. But unlike many system implementations, we'll constrain what happens so the calling program can't trick it into executing some other program.
The system function takes a single argument: a character string with the command to be executed just as it would be typed at the keyboard. The function first invokes the Bourne shell, passing the command to that shell using the "–c" option. The shell then spawns the command. For example:
invokes the command
/bin/sh –c "date"
This executes the program "date," which prints the date on the standard output.
Security issues arise when the program invoking the system function is a privileged program. The "privilege" may consist of having setuid and/or setgid privileges such as su or being able to run one of a specified set of programs such as a Web server serving CGI scripts. The attacker's goal is to trick the program into executing some other program, for example a version of date that's a command interpreter rather than just printing the date.
Problems arise because of the power of the Bourne shell as a command interpreter. That shell takes information from the environment, which consists of shell variables, file descriptors, signal-handling routines, and any other aspects of the process space that could affect program execution. For our purposes, we'll just consider environment variables.
One relevant environment variable is the PATH environment variable. When given a command that doesn't contain a '/' the Bourne shell treats the value of the PATH variable as a sequence of directory names. It looks in each directory in the given order for a program named "date" and executes the first one found. Suppose an attacker finds a setuid-to-root program that uses system to run the "date" command. The attacker can then copy the shell into a file named "date" in her current working directory, prepend "." to the list of directories in the value of PATH, and then execute the program. When system invokes the shell, it searches each directory in the value of PATH in order for a command named "date." The first directory searched will be the current working directory. The shell will find a program called "date" there and execute it, spawning the command interpreter, which will run with root privileges.
Our goal is to construct a version of system that's invulnerable to this kind of attack. Specifically, we want to guarantee that when the caller passes a command name to system, the user can't cause the program to execute a different program.
Applying the Principles
We'll apply two principles of secure design and implementation. They come from a paper by Jerome Saltzer and Michael Schroeder and are central to any security work. In practice, we would also consider the other six, but the two we'll use have more impact on the design and implementation of this particular function than the others.
Principle of Least Privilege
The first principle is the principle of least privilege. This principle, also called the need-to-know principle, says that a process should have the minimum privileges needed to perform its task. For this problem, this rule says that system should execute the command with the privileges of the user, not with those of root, if at all possible. As an example, were the privileged program to print the date and time by using system to run the command "date" as described above, there's no reason that "date" needs to be executed as root. It could just as easily be executed with the user's privileges. Hence the first step in our new system command would be to let the caller reset the privileges to those of the real user and group. Doing this means that the user can only compromise her own account - and as since she already has full access to it such a compromise is meaningless.
If the caller lets the user select one of a set of commands, then a different application of the principle of least privilege provides the required restriction. The program configuration should create a directory into which copies of the commands to be executed are placed. Then the program changes its notion of the root directory to that of the directory containing the commands. Even if the user can enter the name of a different command, only the authorized commands are accessible to the program. So only the authorized commands can be executed, and the user will get an error message. This is the technique that sendmail's restricted shell uses to ensure that sendmail only executes safe programs like procmail and vacation. Web servers should use this technique to ensure that commands to execute CGI programs can only execute the CGI programs in the Web server's directories.
Principle of Fail-Safe Defaults
The principle of fail-safe defaults says that access to resources and objects should be denied by default. If you need access to only one particular object, the usual approach of removing access to all other objects violates this principle. Instead, access to all objects should be removed, and then access privileges for that particular object should be explicitly granted. The distinction is subtle, but critical.
To see this, consider the problem of ensuring the user's PATH environment variable is set appropriately. The naive approach is to search the environment for the PATH environment variable and check that its value is acceptable. This leads to two problems. First, what happens if the value is not acceptable? In this case, the value must be replaced. Second, what happens if there are multiple occurrences of the variable? The values of all must be checked and found satisfactory, or all but one must be deleted.
A second approach is to require that the program use the full path name of the program. So the invocation of the system call would be:
This causes the shell to ignore the PATH setting. Unfortunately, this approach is also flawed.
Environment variables other than PATH affect the executed program. For some versions of the Bourne shell, the value of the environment variable IFS is a string of characters that the shell treats as word separators. (This is particularly useful when a shell script is reading lines from the password file, for example.) In such a shell, the following command prints files X and Y:
IFS="/$IFS"; export IFS; cat/x/y
because the shell sees the "/" character as a word separator, which lets the user thwart the use of a full path name as described above. All she need do is set IFS in her environment to include the "/" character and then create a program called "bin" in her current working directory. She then changes her PATH environment variable to look in the current working directory first. When she runs the command, the privileged program invokes the above system function. The subordinate shell reads the argument of system as having two words, "bin" followed by the argument "date." Hence the user's program "bin" will be executed and the shell will pass "date" to it as an argument.
Again the programmer can try to prevent this by setting IFS explicitly in the environment:
system("IFS=\" \t\n\"; export IFS; /bin/date")
As tempting as this approach is, it suffers from two problems. The first is that the attacker can easily defeat it by adding "I" to the IFS variable. Then the shell sees this as adding the environment variable FS to the environment. The second problem arises when the attacker doesn't do this. There are now two occurrences of the IFS environment variable in the environment. Which one is used? That turns out to be implementation-dependent: some versions of the shell use the first (the user's), and others use the second (the one defined in the system argument.
Following the principle of fail-safe defaults offers a simple answer to all this. First, create an empty environment for the shell. Then add preset, safe values of PATH, IFS, and any other needed environment variables to that environment. Finally, set the shell's environment to be the newly created one. Doing so makes the user's environment irrelevant to the system function and the shell it calls. The shell never refers to the user's environment. The shell only uses the newly created safe environment.
Now the order in which the shell evaluates the variables in the environment is irrelevant, because there is only one occurrence of each variable in the environment. If the user adds "/" to the value of IFS in her environment, or alters the value of the PATH environment variable, the shell ignores those changes because it never sees the values of those variables. It only sees the ones defined in the environment set up by the program.
Programming with security in mind is critical for today's programs. This style of programming requires a methodical approach, not one in which various tricks are used without understanding how and why they work. The problem is that tricks only apply to certain situations, and can only be used effectively if those situations arise. But the principles of secure design and implementation apply always, and dramatically improve both the quality and the security of the programs and systems they are applied to.
“In the past year we've seen a lot of stabilization of WebRTC. You can now use it in production with a far greater degree of certainty. A lot of the real developments in the past year have been in things like the data channel, which will enable a whole new type of application," explained Peter Dunkley, Technical Director at Acision, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Apr. 25, 2015 04:00 PM EDT Reads: 4,439
The best mobile applications are augmented by dedicated servers, the Internet and Cloud services. Mobile developers should focus on one thing: writing the next socially disruptive viral app. Thanks to the cloud, they can focus on the overall solution, not the underlying plumbing. From iOS to Android and Windows, developers can leverage cloud services to create a common cross-platform backend to persist user settings, app data, broadcast notifications, run jobs, etc. This session provides a high level technical overview of many cloud services available to mobile app developers, includi...
Apr. 25, 2015 04:00 PM EDT Reads: 1,391
SYS-CON Events announced today that Ciqada will exhibit at SYS-CON's @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Ciqada™ makes it easy to connect your products to the Internet. By integrating key components - hardware, servers, dashboards, and mobile apps - into an easy-to-use, configurable system, your products can quickly and securely join the internet of things. With remote monitoring, control, and alert messaging capability, you will meet your customers' needs of tomorrow - today! Ciqada. Let your products take flight. For more inform...
Apr. 25, 2015 03:00 PM EDT Reads: 1,915
Containers and microservices have become topics of intense interest throughout the cloud developer and enterprise IT communities. Accordingly, attendees at the upcoming 16th Cloud Expo at the Javits Center in New York June 9-11 will find fresh new content in a new track called PaaS | Containers & Microservices Containers are not being considered for the first time by the cloud community, but a current era of re-consideration has pushed them to the top of the cloud agenda. With the launch of Docker's initial release in March of 2013, interest was revved up several notches. Then late last...
Apr. 25, 2015 03:00 PM EDT Reads: 2,863
Health care systems across the globe are under enormous strain, as facilities reach capacity and costs continue to rise. M2M and the Internet of Things have the potential to transform the industry through connected health solutions that can make care more efficient while reducing costs. In fact, Vodafone's annual M2M Barometer Report forecasts M2M applications rising to 57 percent in health care and life sciences by 2016. Lively is one of Vodafone's health care partners, whose solutions enable older adults to live independent lives while staying connected to loved ones. M2M will continue to gr...
Apr. 25, 2015 03:00 PM EDT Reads: 1,509
Dave will share his insights on how Internet of Things for Enterprises are transforming and making more productive and efficient operations and maintenance (O&M) procedures in the cleantech industry and beyond. Speaker Bio: Dave Landa is chief operating officer of Cybozu Corp (kintone US). Based in the San Francisco Bay Area, Dave has been on the forefront of the Cloud revolution driving strategic business development on the executive teams of multiple leading Software as a Services (SaaS) application providers dating back to 2004. Cybozu's kintone.com is a leading global BYOA (Build Your O...
Apr. 25, 2015 02:00 PM EDT Reads: 1,555
While not quite mainstream yet, WebRTC is starting to gain ground with Carriers, Enterprises and Independent Software Vendors (ISV’s) alike. WebRTC makes it easy for developers to add audio and video communications into their applications by using Web browsers as their platform. But like any market, every customer engagement has unique requirements, as well as constraints. And of course, one size does not fit all. In her session at WebRTC Summit, Dr. Natasha Tamaskar, Vice President, Head of Cloud and Mobile Strategy at GENBAND, will explore what is needed to take a real time communications ...
Apr. 25, 2015 02:00 PM EDT Reads: 1,780
SYS-CON Media announced today that @WebRTCSummit Blog, the largest WebRTC resource in the world, has been launched. @WebRTCSummit Blog offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. @WebRTCSummit Blog can be bookmarked ▸ Here @WebRTCSummit conference site can be bookmarked ▸ Here
Apr. 25, 2015 02:00 PM EDT Reads: 2,498
SYS-CON Events announced today that GENBAND, a leading developer of real time communications software solutions, has been named “Silver Sponsor” of SYS-CON's WebRTC Summit, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. The GENBAND team will be on hand to demonstrate their newest product, Kandy. Kandy is a communications Platform-as-a-Service (PaaS) that enables companies to seamlessly integrate more human communications into their Web and mobile applications - creating more engaging experiences for their customers and boosting collaboration and productiv...
Apr. 25, 2015 01:00 PM EDT Reads: 2,725
SYS-CON Events announced today that BroadSoft, the leading global provider of Unified Communications and Collaboration (UCC) services to operators worldwide, has been named “Gold Sponsor” of SYS-CON's WebRTC Summit, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. BroadSoft is the leading provider of software and services that enable mobile, fixed-line and cable service providers to offer Unified Communications over their Internet Protocol networks. The Company’s core communications platform enables the delivery of a range of enterprise and consumer calling...
Apr. 25, 2015 12:30 PM EDT Reads: 2,534
What exactly is a cognitive application? In her session at 16th Cloud Expo, Ashley Hathaway, Product Manager at IBM Watson, will look at the services being offered by the IBM Watson Developer Cloud and what that means for developers and Big Data. She'll explore how IBM Watson and its partnerships will continue to grow and help define what it means to be a cognitive service, as well as take a look at the offerings on Bluemix. She will also check out how Watson and the Alchemy API team up to offer disruptive APIs to developers.
Apr. 25, 2015 12:00 PM EDT Reads: 1,845
The IoT Bootcamp is coming to Cloud Expo | @ThingsExpo on June 9-10 at the Javits Center in New York. Instructor. Registration is now available at http://iotbootcamp.sys-con.com/ Instructor Janakiram MSV previously taught the famously successful Multi-Cloud Bootcamp at Cloud Expo | @ThingsExpo in November in Santa Clara. Now he is expanding the focus to Janakiram is the founder and CTO of Get Cloud Ready Consulting, a niche Cloud Migration and Cloud Operations firm that recently got acquired by Aditi Technologies. He is a Microsoft Regional Director for Hyderabad, India, and one of the f...
Apr. 25, 2015 12:00 PM EDT Reads: 1,653
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal today!
Apr. 25, 2015 12:00 PM EDT Reads: 2,305
So I guess we’ve officially entered a new era of lean and mean. I say this with the announcement of Ubuntu Snappy Core, “designed for lightweight cloud container hosts running Docker and for smart devices,” according to Canonical. “Snappy Ubuntu Core is the smallest Ubuntu available, designed for security and efficiency in devices or on the cloud.” This first version of Snappy Ubuntu Core features secure app containment and Docker 1.6 (1.5 in main release), is available on public clouds, and for ARM and x86 devices on several IoT boards. It’s a Trend! This announcement comes just as...
Apr. 25, 2015 12:00 PM EDT Reads: 1,395
SYS-CON Media announced today that @ThingsExpo Blog launched with 7,788 original stories. @ThingsExpo Blog offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. @ThingsExpo Blog can be bookmarked. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago.
Apr. 25, 2015 11:00 AM EDT Reads: 2,539
The world's leading Cloud event, Cloud Expo has launched Microservices Journal on the SYS-CON.com portal, featuring over 19,000 original articles, news stories, features, and blog entries. DevOps Journal is focused on this critical enterprise IT topic in the world of cloud computing. Microservices Journal offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. Follow new article posts on Twitter at @MicroservicesE
Apr. 25, 2015 11:00 AM EDT Reads: 2,090
SYS-CON Events announced today that robomq.io will exhibit at SYS-CON's @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. robomq.io is an interoperable and composable platform that connects any device to any application. It helps systems integrators and the solution providers build new and innovative products and service for industries requiring monitoring or intelligence from devices and sensors.
Apr. 25, 2015 11:00 AM EDT Reads: 2,088
Wearable technology was dominant at this year’s International Consumer Electronics Show (CES) , and MWC was no exception to this trend. New versions of favorites, such as the Samsung Gear (three new products were released: the Gear 2, the Gear 2 Neo and the Gear Fit), shared the limelight with new wearables like Pebble Time Steel (the new premium version of the company’s previously released smartwatch) and the LG Watch Urbane. The most dramatic difference at MWC was an emphasis on presenting wearables as fashion accessories and moving away from the original clunky technology associated with t...
Apr. 25, 2015 11:00 AM EDT Reads: 2,090
SYS-CON Events announced today that Litmus Automation will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Litmus Automation’s vision is to provide a solution for companies that are in a rush to embrace the disruptive Internet of Things technology and leverage it for real business challenges. Litmus Automation simplifies the complexity of connected devices applications with Loop, a secure and scalable cloud platform.
Apr. 25, 2015 11:00 AM EDT Reads: 1,738
In 2015, 4.9 billion connected "things" will be in use. By 2020, Gartner forecasts this amount to be 25 billion, a 410 percent increase in just five years. How will businesses handle this rapid growth of data? Hadoop will continue to improve its technology to meet business demands, by enabling businesses to access/analyze data in real time, when and where they need it. Cloudera's Chief Technologist, Eli Collins, will discuss how Big Data is keeping up with today's data demands and how in the future, data and analytics will be pervasive, embedded into every workflow, application and infra...
Apr. 25, 2015 11:00 AM EDT Reads: 1,449