如何在Windows上自动监控和限制进程资源
在 Linux 上,通常我使用 ptrace 函数来跟踪所有系统调用,并在进程尝试对我的计算机执行任何有害操作时终止该进程,例如 system("shutdown -s -t 00 ”) 左右。
我有办法在 Windows 上执行此操作吗?
编辑:我想编写沙箱程序来限制其子进程的时间和内存使用量,该程序可以在 Windows 和 Linux 上运行,但现在它只能通过 ptrace 在 Linux 上运行
On Linux, normally I use ptrace
function to trace all syscall, and kill the process if the it tries to do anything harmful to my machine, such as system("shutdown -s -t 00")
or so.
Is there a way for me to do this on Windows?
EDIT: I want to write Sandbox program to limit time and memory usage of its child that can work on both Windows and Linux, and now it can only run on Linux via ptrace
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您将流程附加到 作业对象 ,可以限制进程的CPU时间和内存。这不会让您阻止 if 执行恶意操作,但它会让您实现您的要求。
If you attach your process to a Job object, you can limit the CPU time and memory of the process. That won't allow you to prevent if from performing malicious actions but it will allow you to achieve what you asked.
要在沙箱中运行应用程序,您可以使用 CreateRestrictedToken(此处< /a> 有关您可以启用/禁用的权限的一些信息),请调用 ImpersonateLoggedOnUser 使用新令牌,使用 CreateProcess 启动新进程并使用 恢复到自己。我不确定在所有情况下您是否可以直接使用 CreateProcessAsUser,尝试一下。
To run an application in a sandbox you could create a new restricted access token with CreateRestrictedToken (here's some info about the privileges you can enable/disable), call ImpersonateLoggedOnUser with the new token, start the new process with CreateProcess and revert to your old token with RevertToSelf. I'm not sure if in all contexes you can instead directly use CreateProcessAsUser, give it a try.
可能为时已晚,刚刚看到您的帖子,我自己也在寻找相同的功能。
我发现CPU限制1.1
你可以在这里下载它的源代码 http://www.killprog.com/etce .html
我使用得很成功,希望对你有帮助
May be too late, just came across your post looking for the same functionality myself.
I found CPU limit 1.1
You can download it here with source code http://www.killprog.com/etce.html
I'm using it very successfully, hope it helps you