通过命令行安全地发送密码而不暴露在 ps/wmic (Windows,Unix)

Sending passwords securely via command line without being exposed in ps/wmic (Windows,Unix)

我们在 Windows 和 Unix 中有一个 launcher 应用程序,它执行(使用 exec 系统调用启动应用程序)RDP、putty、MSSQL 等应用程序。为了调用它,我们将参数传递给用户名、密码、IP 等。 最近我们发现,使用wmic或ps可以查出传递给它的参数是什么,从而暴露密码等敏感信息。 有什么方法可以隐藏这些密码或隐藏所有参数。 注意:我的启动器从其他服务获取参数,因此在调用应用程序后询问密码不是一个选项!密码必须作为参数传递给应用程序。 任何解决方案?

这是不可能的(至少在 Linux 上不能以可靠的方式)安全地传递程序参数。

一种可能的解决方法是传递包含该密码的文件名(或其他一些资源 - 例如某些 "reference" 到某些数据库条目),或使用其他一些 inter-process communication facility (e.g. on Linux, fifo(7), shm_overview(7), pipe(7), unix(7), etc...) to pass these sensitive informations. You might also consider using environment variables (see environ(7) & getenv(3))。

在 Linux 上也查看 proc(5) to understand what it is able to show about processes - thru /proc/1234/ for the process of pid 1234. Maybe you want seccomp 设施。

在 Unix 上,请注意 setuid mechanism -tricky to understand-. Use it carefully (it is the basic block of most security or authentication machinery such as sudo and login) since a simple mistake could open a huge vulnerability.

对于为在 Unix 和 Windows 上运行而编写的软件,我建议在某些文件中传递密码(例如在 /tmp/secretpassword 中)并给出名称 /tmp/secretpassword(或一些D:\foo\bar 在 Windows) 上通过一些程序参数访问该文件,并确保明智地使用文件权限机制以确保不需要文件的人无法读取该文件。