(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Kerio Reseller
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":


Hate these ads?



(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 sanbox 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.



Comments /MacOSX/sandbox.html


Sun Dec 30 16:39:11 2007: Subject:   TonyLawrence
Similar ideas for Linux: http://sandbox.sourceforge.net/ seems very similar.^M

^M Plash ( http://www.securiteam.com/tools/5FP052KKAK.html) restricts file access on ly ; I'm sure there are more..

Add your comments

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


ad

Views for this page
Today This Week This Month This Year  Overall
823951,072 1,212

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

pavatar.jpg
More:
       - MacOSX
       - Security
       - Shell




Unix/Linux Consultants

Your ad here - $24.00 yearly!

larryi@ccamedical.com SCO OS5, Debian Linux, RedHat Linux, MySQL, Apache, AJAX development using dXport/dL4/Unibasic, Windows Connectivity, Sharing Resouces, Automation, Shell Scripting


http://www.vss3.com SCO/Caldera OpenServer, Unixware & Linux. Tarantella & Non-stop Clustering


http://www.schewanick.com SCO Unix, Solaris, Linx (various), PHP, MySQL, Apache, uniBasic, dL4, Perl, System Administration and more....







Coming Attractions

My Favorites

Change Congress


Related Posts