(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



sandbox-exec (Mac sandbox wrapper)


2007/12/30

Mac OS X Leopard includes a new command line tool called "sandbox-exec". What it does is provide a "sandbox" - a restricted environment. You can use this to provide more safety when testing unknown software (such as that whiz-bang thingy you just downloaded) or to provide additional security for our ordinary applications and daemons..

Let's try something very simple. First we need to create a sandbox profile. There are pre-made profiles in /usr/share/sandbox, but we'll make our own here. I'll call it "my.sb":



(version 1)
(allow default)
(deny network*)
 

Not much to it, is there? Yes, just three lines: I didn't leave anything out. Let's take it for a spin.

new-host-2:~ apl$ sandbox-exec -f ./my.sb /bin/bash
bash-3.2$ # we're in the sandbox running bash
bash-3.2$ date
Sat Dec 29 19:22:05 EST 2007
bash-3.2$ echo "I'm in a sandbox"
I'm in a sandbox
bash-3.2$ ping aplawrence.com
bash: /sbin/ping: Operation not permitted
bash-3.2$ ssh aplawrence.com
ssh: connect to host aplawrence.com port 22: Operation not permitted
bash-3.2$ exit
new-host-2:~ apl$ 
 

The "deny network*" in our profile stopped us from using the network. There are other restrictions we can enforce in our sandbox: we can prohibit file system writes, prohibit writes except to /tmp or other specific places, allow only certain libraries to be read , and much more. The best place to get an idea of what's possible is to look at the /usr/share/sandbox files: strangely, they aren't XML as most of Mac OS X is now, but they are easy enough to understand in spite of being undocumented.

If we had a suspicious binary, we could run it within a sandbox that locked it down from doing anything potentially harmful. We could also run processes that we fear might be subverted - a web server or ssh server, for example. Any sub-process started by a sandboxed process will be just as restricted, so this would let us very specifically allow only what our process needs to do its work. If it were hacked, the resulting process would be prevented from doing anything more. In combination with our normal security measures (permissions, acl's and so on), this could provide a very large degree of security.

A comment in one of the /usr/share/sandbox files might indicate that a different name for this was contemplated:

 Use "debug deny" to log only operations that are denied by seatbelt
 

Seatbelt? OK, a seatbelt restrains you and keeps you from hurting yourself..

There is, of course, a system call for the same purpose - sandbox_init() - and a man page. There's also a "sandbox" man page that is supposedly an overview of this facilty, but neither of them are very helpful. A little experimentation would probably tease out their secrets.


;


Click here to add your comments





Sun Dec 30 16:39:11 2007: Subject:   TonyLawrence

gravatar
Similar ideas for Linux: http://sandbox.sourceforge.net/ seems very similar. Plash ( http://www.securiteam.com/tools/5FP052KKAK.html) restricts file access only ; I'm sure there are more..



Mon Mar 2 23:53:32 2009: Subject:   anonymous

gravatar
great article, thanks for sharing this!

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar




Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - MacOSX
       - Security
       - Shell


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress