C++:有什么方法可以“监狱功能”吗?

发布于 2024-08-23 09:45:19 字数 407 浏览 2 评论 0原文

嗯,它是一种网络服务器。

我加载 .dll(.a) 文件并将它们用作程序模块。

我递归地遍历目录并将这些库中的“_main”函子放入名称下的 std::map 中,该名称包含在特殊的“.m”文件中。

主目录为每个主机提供了几个目录。

问题是我需要阻止使用“fopen”或任何其他与此主机目录之外的目录一起使用的文件系统函数。

我能看到的唯一方法是为 stdio.h 编写一个扭曲(我的意思是,编写具有文件名检查的 s_stdio.h )。

也许它可能是一个守护进程,捕获系统调用并识别某些东西?

add

那么,如果我只上传souses,然后检查后直接在我的服务器上编译呢?嗯,这是我发现的唯一方法(仍然将所有内容保留在一个地址空间内)。

Well, it's a kind of a web server.

I load .dll(.a) files and use them as program modules.

I recursively go through directories and put '_main' functors from these libraries into std::map under name, which is membered in special '.m' files.

The main directory has few directories for each host.

The problem is that I need to prevent usage of 'fopen' or any other filesystem functions working with directory outside of this host directory.

The only way I can see for that - write a warp for stdio.h (I mean, write s_stdio.h that has a filename check).

May be it could be a deamon, catching system calls and identifying something?

add

Well, and what about such kind of situation: I upload only souses and then compile it directly on my server after checking up? Well, that's the only way I found (having everything inside one address space still).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

厌倦 2024-08-30 09:45:20

如果您是加载该模块的人,您可以对代码执行静态分析以验证它调用了哪些 API,如果它没有检查(即如果它进行任何类型的可疑调用),则拒绝链接它。

话虽如此,这样做需要做很多工作,而且不太便携。

If you are the one loading the module, you can perform a static analysis on the code to verify what APIs it calls, and refuse to link it if it doesn't check out (i.e. if it makes any kind of suspicious call at all).

Having said that, it's a lot of work to do this, and not very portable.

べ繥欢鉨o。 2024-08-30 09:45:19

由于 C++ 是低级语言,并且 DLL 被编译为机器代码,因此它们可以做任何事情。即使您包装了标准库函数,代码也可以直接执行系统调用,从而重新实现您所包装的功能。

有效沙箱此类 DLL 的唯一方法可能是某种虚拟化,因此代码不是直接运行,而是在虚拟机中运行。

更简单的解决方案是对应该沙箱化的可加载模块使用一些高级语言。一些高级语言更擅长沙箱(Lua、Java),其他语言则不太好(例如,据我所知,目前还没有为 Python 实现的官方限制环境)。

As C++ is low level language and the DLLs are compiled to machine code they can do anything. Even if you wrap the standard library functions the code can do the system calls directly, reimplementing the functionality you have wrapped.

Probably the only way to effectively sandbox such a DLL is some kind of virtualisation, so the code is not run directly but in a virtual machine.

The simpler solution is to use some higher level language for the loadable modules that should be sandboxed. Some high level languages are better at sandboxing (Lua, Java), other are not so good (e.g. AFAIK currently there is no official restricted environment implemented for Python).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文