stdio 通信的安全性
在我正在开发的程序中(Linux),我需要非常简单的基于文本的 IPC。为此使用标准输入/输出管道将非常容易。我可以相信发送到进程标准输入的消息不能被任何人读取吗?另外,我可以相信,如果我将管道保留到其标准输出,那么只有我可以读取它输出的内容吗?我只是想确保没有基于 procfs 的技巧可以读取这些内容。
In a program I am developing (Linux), I need very simple text-based IPC. It would be very easy to use a standard input/output pipe for this. Can I trust that messages sent to a process' stdin cannot be read by anyone? Also, can I trust that if I kept the pipe to its stdout, only I can read what it outputs? I just want to make sure there's no procfs-based trick that can read from these.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
老实说,我认为这取决于您认为您的应用程序需要多少安全性。我在 stdin 上输入我的 GPG 密钥密码。我总是问“可接受的风险是多少?”这个问题。
也就是说,没有任何东西可以保护您的应用程序免受内核空间中的 rootkit 的侵害。它不仅可以读取标准输入/输出终端,还可以读取运行时的整个进程内存。并且可能会覆盖您已经采取的一些保护措施。
您可能会考虑将 SELinux 沙箱与您正在做的事情结合使用 - 请访问 http://danwalsh 阅读更多相关信息。 livejournal.com/ 如果您确实需要这种级别的保护。 libselinux 允许您与它交互以检查保护是否存在等。
Honestly, I think it depends on how much security you think your application needs. I input my GPG key password on stdin. I always ask the question "what is the acceptable risk?".
That said, nothing will protect your application from a rootkit in kernel-space. It can read not just the std in/out terminals but your entire processes memory as it runs. And probably override a few protections you've got in place.
You might look at using SELinux sandboxing in combination with what you're doing - read more about it at http://danwalsh.livejournal.com/ if you really need that level of protection. libselinux lets you interface with it for checking protection exists etc.
据我所知,没有“技巧”,其他用户无法读取您的标准输入/标准输出。请记住:
也就是说,如果您正在处理敏感数据,请查看 mlock。
As far as I know, there are no "tricks" and other users cannot read your stdin/stdout. Just remember that:
That said, if you are handling sensitive data, have a look at mlock.
没有任何技巧,我能想到的与检测 stdout 是否重定向到其他地方有关的唯一一个方法就是像在简单的 C 函数中那样执行此操作,如
isredirected
所示,除了责任在于你要确保消息的安全...另一件事是使用 procfs 欺骗需要 root 权限才能访问某些 procfs 功能...因此请确保在那里进行检查以确保它不是以 root 身份运行...希望这有帮助,
最好的问候,汤姆。
There's no tricks, the only one I can think of in relation to detecting if stdout is redirected to elsewhere is to do this like in a simple C function as shown here
isredirected
, other than that the onus rests with you to ensure the messages are kept secure...The other thing, is using procfs trickery requires root privileges to access certain procfs features...so ensure that you put a check in there to ensure it is not running as root...Hope this helps,
Best regards, Tom.
在我自己的有限测试中(运行
uniq | sort
然后尝试通过/proc/XXX/fd
监听管道的两端),似乎我不能读取发送到管道中的内容,但我可以将数据注入其中。换句话说,做你自己的测试,看看你能做什么和不能做什么。 :-)
In my own limited testing (running
uniq | sort
then trying to snoop on both ends of the pipe via/proc/XXX/fd
), it seems that I can't read what gets sent into the pipe, but I can inject data into it.In other words, do your own testing to see what you can and can't do. :-)