stdio 通信的安全性

发布于 2024-08-22 14:11:59 字数 160 浏览 6 评论 0原文

在我正在开发的程序中(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 技术交流群。

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

发布评论

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

评论(4

塔塔猫 2024-08-29 14:11:59

老实说,我认为这取决于您认为您的应用程序需要多少安全性。我在 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.

时光与爱终年不遇 2024-08-29 14:11:59

据我所知,没有“技巧”,其他用户无法读取您的标准输入/标准输出。请记住:

  • 以同一用户身份运行的其他进程可以读取您进程的内存;这是因为安全性可以保护您免受其他用户的侵害。
  • 以超级用户身份运行的进程可以执行所有操作。

也就是说,如果您正在处理敏感数据,请查看 mlock

As far as I know, there are no "tricks" and other users cannot read your stdin/stdout. Just remember that:

  • Other processes running as the same user can read your process' memory; this is because security protects you from other users.
  • A process running as superuser can do everything.

That said, if you are handling sensitive data, have a look at mlock.

半寸时光 2024-08-29 14:11:59

没有任何技巧,我能想到的与检测 stdout 是否重定向到其他地方有关的唯一一个方法就是像在简单的 C 函数中那样执行此操作,如 isredirected 所示,除了责任在于你要确保消息的安全...另一件事是使用 procfs 欺骗需要 root 权限才能访问某些 procfs 功能...因此请确保在那里进行检查以确保它不是以 root 身份运行...

int isredirected(void){
if (!isatty(fileno(stdin))) return 1;
return 0;
}

希望这有帮助,
最好的问候,汤姆。

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...

int isredirected(void){
if (!isatty(fileno(stdin))) return 1;
return 0;
}

Hope this helps,
Best regards, Tom.

苏辞 2024-08-29 14:11:59

在我自己的有限测试中(运行 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. :-)

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