I want to be able to generically pick a certain executable (potentially malicious) x and run it (from an admin account) with write access restricted to certain directories (dynamically deduced) "${dirs[@]}".
The executable should have access to whatever is globally accessible on the system.
I figured I could use simple user-switching and have a dedicated, stateless system user foreveralone, for running theses executables.
Whenever I would want to run x with these restrictions, I would, flock a lock file, chown -R foreveralone:foreveralone -- "${dirs[@]}" and then do sudo -u foreveralone -g foreveralone $PWD/x.
After that, I would chown the write directories to someone else, so that foreveralone would have no persistent files on the filesystem. I figure I would also need to clean up up global write directories (e.g., /tmp, /dev/shm) from foreveralones files.
My questions are:
- Is this a feasible and secure mechanism for jailing processes, given a standardly setup *nix system?
- What exactly are the standard globally writable places and files on a a standardly setup *nix?
How can I find them better than with something like
sudo -u foreveralone -g foreveralone find / ! -type l -writable 2>/dev/null | grep -v '^/proc'
(My
findgame is very weak./proc/$pidappears to have lots of files that appear writable but, in fact aren't so I'm skipping those (I wonder what's up with that)).
Anyway, on my system, 3. returns (filtered to show filetypes):
character special file /dev/full character special file /dev/fuse character special file /dev/net/tun character special file /dev/null character special file /dev/ptmx character special file /dev/random character special file /dev/tty character special file /dev/urandom character special file /dev/zero character special file /sys/kernel/security/apparmor/.null directory /run/lock directory /run/shm directory /tmp directory /tmp/.ICE-unix directory /tmp/.X11-unix directory /var/local/dumps directory /var/mail directory /var/spool/samba directory /var/tmp regular empty file /run/sendmail/mta/smsocket regular empty file /sys/kernel/security/apparmor/.access socket /dev/log socket /run/acpid.socket socket /run/avahi-daemon/socket socket /run/cups/cups.sock socket /run/dbus/system_bus_socket socket /run/gdm_socket socket /run/mysqld/mysqld.sock socket /run/samba/nmbd/unexpected socket /run/sdp socket /tmp/.ICE-unix/2537 socket /tmp/mongodb-27017.sock socket /tmp/.X11-unix/X0 - Is there a better (simpler/more flexible solution to this)
In my particualar case, x would be a potentially malicious build script which should run without writing to the wrong places or reading things that aren't globally readable.