Maybe: run a command, see what it does to your files without actually doing it
github.com
github.com
The tool seems to work by intercepting individual "blacklisted" system calls and then - instead of executing them - returning a nonsense value.
The issue is that this breaks every single POSIX spec and will therefore break any program that does more than a few trivial IO operations and relies on those operations to behave as specified.
So it might work for a simple demo case where a small script only does a single file modification and never checks the results, but for any serious program (think a database, a complex on-disk format or really anything that does network IO) this will lead to corruption and undefined behaviour as system calls will return erroneous success values or invalid file descriptors.
I think to actually make this work one would have to emulate the system calls and make sure everything stays POSIX compliant. Doing this correctly for calls like mmap might get tricky though (and won't be possible from within a python runtime). And even then it isn't obvious how something like network IO would be handled.
At this point, it will only work for the most trivial of demo cases. Still IMO it's a cool demonstration of the linux ptrace facility. And if the author implements the missing sandboxing/emulation layer in a future version and switches to whitelisting instead of blacklisting syscalls I think it could actually run a limited number of programs (forbidding stuff like mmap and network IO).
> That being said, maybe should :warning: NEVER :warning: be used to run untrusted code on a system you care about! A process running under maybe can still do serious damage to your system because only a handful of syscalls are blocked. Currently, maybe is best thought of as an (alpha-quality) "what exactly will this command I typed myself do?" tool.
What happens if the program writes a bunch of stuff to disk then later on tries to read it?
#!/bin/bash
touch x
if [ -f "x" ]; then
rm -rf /
else
echo "I'm just an innocent little script."
fihttps://www.kernel.org/doc/Documentation/filesystems/overlay...
I got so used to this being relatively easy on linux (grsec, firejail, seccomp, etc.), but never heard of easy ways to apply it on win.
Please give me an example how to launch a program in a sandbox incl virtual FS on Linux - with Sandboxie it takes a single mouse click
But usually I just prefer to run apps without a sandbox, and ensure they can't touch anything important (new role + apparmor/selinux/grsec).
sandbox commandfluxcapacitor
https://github.com/majek/fluxcapacitor#fluxcapacitor
https://idea.popcount.org/2013-07-19-how-to-sleep-a-million-...
maybe find ~/ | grep . | parallel rm {}
...and be fairly surprised to find everything deleted. It wasn't find's fault!
sudo sh -c "echo 'foo' >> /etc/file"
just stubbing out the system calls sounds like it'll quickly break down once the programs try to do something more complicated with the files.
https://pdos.csail.mit.edu/archive/mbox/
It's a bit more complete than this.
mbox COMMAND
run COMMAND and shows you what files changed. Then you can select drop or commit those files. $ mbox mktemp
/tmp/tmp.cfJElOQmNK
Sandbox Root:
> /tmp/sandbox-30749
> F: /tmp/sandbox-30749/tmp/tmp.cfJElOQmNK
F:/tmp/tmp.cfJElOQmNK
[C]ommit all, [c]ommit, [i]gnore, [d]iff, [l]ist tree, [q]uit ?> q
$
firejail --private=/path/to/home-for-command COMMAND
does similar things. But it only sandbox $HOME. Also does not show what is changed by defult.Ideally, Docker could offer ad hoc commands to launch an process in a sandbox. And then you launch a file explorer process in the same sandbox (like Sandboxie) to inspect or run a diff-tool that outputs statistics like the tool in the headline.
A similar idea is used to trace what 'make install' does so that stuff can be uninstalled later - or made into a package (rpm, dpkg etc)
I forget what that tool is called.
Even though I had read all of the man pages and knew the commands inside and out, it still seemed incredibly risky and scary to me to run rsync with the --delete function when I was backing up my main USB drive for the very first time.
Basically my biggest fear was that I had source and destination mixed up, which I didn't, but it would have been nice to run a test trial of that command before doing so.
-n, --dry-run perform a trial run with no changes made
This probably also would have helped> maybe should :warning: NEVER :warning: be used to run untrusted code on a system you care about! A process running under maybe can still do serious damage to your system because only a handful of syscalls are blocked. Currently, maybe is best thought of as an (alpha-quality) "what exactly will this command I typed myself do?" tool.
1) Boot up a new Ubuntu docker container 2) Run command / script 3) Use `docker diff` to see what changes to the filesystem were made
Obviously it's only useful for some commands, but at least it's safe :-)
I would then want to capture all disk and network i/o that the "maybed" command generated in the VM.
Even that wouldn't be that secure, because the command would still be able to send sensitive data out. You could intercept the network i/o, but that would cause most installers to fail.
I use to implement a --trial in my shell scripts, which covers reporting of ALL operations (local and remote).
Anyway, this is a nice discover and nice hack.
In Linux, a program that is being ptraced is not allowed to ptrace another program.
strace -f strace -f ls
I guess this isn't possible because the kernel developers only envisioned ptrace to be useful for debugging (they supposedly didn't think about sandboxing applications), and implementing a "recursive" version of ptrace is probably more difficult.It might be possible to implement `maybe` as a dtrace program by instrumenting syscall entry and raising a signal or stopping the program immediately, which you can recover in your debugger (though I'm not sure if this actually stops the syscall). That said, I tried it and OS X doesn't seem to allow "destructive" dtrace actions even as root with SIP disabled:
$ sudo dtrace -n 'syscall::open:entry { stop(); }' -c 'cat Makefile'
dtrace: could not enable tracing: Destructive actions not allowed
$ sudo dtrace -n 'syscall::open:entry { raise(9); }' -c 'cat Makefile'
dtrace: could not enable tracing: Destructive actions not allowed
Alternately you can use dynamorio, intel pin, qemu, or a quick instruction scan/patch for SYSCALL to manually break on syscalls.Either way you almost certainly will not be able to do this with python-ptrace alone. I filed an issue to write a `maybe` tool using Usercorn [1] (which supports OS X) with my VFS overlay work, which means writes could still succeed but be non-destructive.
Anything reliable would check that its operations went through as expected and bail really early.
When I do tests, they are the unmistakable sign of good careful programming.
When you do tests it's an expression of lack of confidence.
Whey they do tests it's a sure sign that really don't know what the hell they're doing.
:-) in case it's needed
I might not want to actually delete them without confirming it.
Then I open up script B in an editor and review the planned changes. Once I like what I see (potentially after a few edits) I run 'bash B'.