应用程序的沙盒虚拟机(概念) [英] Sandbox Virtual Machine for an Application (concept)

查看:58
本文介绍了应用程序的沙盒虚拟机(概念)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个沙盒虚拟机来执行一个已编译的程序.我的目标是将该程序与操作系统的其余部分隔离并控制其执行,使其不会对主机造成任何危害.

I'd like to write a sandbox virtual machine for executing a compiled program. My goal is to isolate that program from the rest of operating system and control its execution so that it can't do anything harmful to a host computer.

我假设:

  • 执行的程序被编译为可移植的可执行格式,它是机器代码,而不是任何类型的字节码或 CLR,
  • 执行的程序不允许与打印机、扫描仪等外围设备通信,并且不使用任何 GUI,
  • 执行程序的主要任务是处理存储在本地文件中的一些数据(例如计算),并将其结果放在另一个本地文件中,
  • 执行的程序不应该直接与操作系统通信,每个请求都应该由虚拟机处理,任何可能对操作系统造成损害的请求都应该被阻止.

我对沙盒虚拟机的架构和操作的概念:

My concept of sandbox virtual machine's architecture and operation:

  • 应用程序由几个模拟对象组成:处理器、内存、文件的 I/O 操作,
  • 有一个模块可以读取编译文件并将可执行代码加载到虚拟内存中,
  • 然后虚拟处理器从第一个字节开始处理,读取操作码、参数,如果需要从内存加载它们,执行命令并将结果放在适当的位置,如果需要设置虚拟标志,然后读取下一个命令,直到程序执行到最后.

您认为:这是一个好概念吗?你会改变什么来改进它?

What do you think: is it a good concept? What would you change to improve it?

推荐答案

模拟一台完整的机器似乎是执行本机代码的一种非常缓慢的方式.大量的加载、查找、执行、存储等操作仅针对一条原生指令.

Simulating a complete machine seems like a very slow way to execute native code. Lots of operations with load, lookup, execute, store, etc just for a single native instruction.

我会尝试至少在本地执行一些代码块.想想下面的代码.

I would try to execute at least some blocks of code natively. Think of the following code.

int sum = 0;
for (int i = 0; i < 10; i++)
{
    sum += i;
}

此代码在您的虚拟机中本地执行是完全安全的.只需确保向虚拟机代码注入返回调用即可.

This code is completely safe to execute native in your virtual machine. Just make sure that you inject a return call to your virtual machine code.

但我会尝试更进一步,本地执行除库/操作系统调用之外的所有代码.在加载沙盒应用程序之前,扫描文件并将所有危险"调用替换为对虚拟机中的处理程序的调用.
代码

But I would try to go a step further and execute all code natively except for library/os calls. Before loading the sandboxed application, scan through the file and replace all "dangerous" calls with calls to handlers in your virtual machine.
The code

printf("Hello World\n");

将替换为对您的库的调用

would be replaced with calls to your library

myVM_printf("Hello World\n");

然后您可以以本机速度执行整个程序,并且仍然能够处理虚拟机中的所有危险代码.

Then you can execute the whole program at native speed and still be able to handle all the dangerous code in your virtual machine.

这篇关于应用程序的沙盒虚拟机(概念)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆