What is the safest way to run an executable on Lin

2020-01-31 03:26发布

I am trying to run a program compiled from C code from an unknown source. I want to make sure that the program does not harm my system in anyway. Like for instance, the program might have soemthing like system("rm -rf /") in the source, which is un-detectable, unless the code is thoroughly examined.

I thought of the following 2 ways

  1. Run it inside a VM like VMWare
  2. Build a windows exe on linux and run on wine

Both are not very elegant solutions and I cannot automate them. and also, in case of 1, it can harm the VM.

Any help would be appreciated.

I want to run the program in what we can call a "sandbox".

9条回答
Viruses.
2楼-- · 2020-01-31 03:58

Check out seccomp. It was designed for this use case.

查看更多
SAY GOODBYE
3楼-- · 2020-01-31 03:58

chroot is one possibility if you want to isolate it from everything else but still have an environment for it to run in.

http://en.wikipedia.org/wiki/chroot

https://help.ubuntu.com/community/BasicChroot

查看更多
虎瘦雄心在
4楼-- · 2020-01-31 04:00

Run it on a non-networked computer that you will re-image once it's done. There is no safe way to run it on a machine and continue to trust that machine afterwards.

查看更多
祖国的老花朵
5楼-- · 2020-01-31 04:04

Geordi uses a combination of chroot and interception of syscalls to compile and then sandbox arbitrary code.

查看更多
Explosion°爆炸
6楼-- · 2020-01-31 04:11

You can use something like schroot and chroot the program, but anything of sufficient nastiness will bust out of that.

You best bet is probably a virtual machine (vmware or virtualbox) and taking a snapshot before compiling and running the program. That way you can roll back if something goes horribly wrong.

查看更多
男人必须洒脱
7楼-- · 2020-01-31 04:16

I wrote an overview of sandboxing methods on Linux (archived) here. You are best off using Linux containers (lxc) or selinux, in my view. You could use a virtualisation solution and automate it, but it is a lot more effort.

lxc will isolate your processes, filesystem and network, and you can set resource limits on the container. There are still risks of a kernel attack, but they are much reduced.

查看更多
登录 后发表回答