ps如何知道隐藏密码?


22

见证人:

$ ps f
  PID TTY      STAT   TIME COMMAND
31509 pts/3    Ss     0:01 -bash
27266 pts/3    S+     0:00  \_ mysql -uroot -p
25210 pts/10   Ss+    0:00 /bin/bash
24444 pts/4    Ss     0:00 -bash
29111 pts/4    S+     0:00  \_ tmux attach
 4833 pts/5    Ss+    0:00 -bash
 9046 pts/6    Ss     0:00 -bash
17749 pts/6    R+     0:00  \_ ps f
 4748 pts/0    Ss     0:00 -bash
14635 pts/0    T      0:02  \_ mysql -uroot -px xxxxxxxxxxxxxxxx
16210 pts/0    S+     0:01  \_ mysql -uroot -px xxxxxxxxxxxxxxxx

ps如何知道隐藏mysql密码?我可以将其合并到自己的脚本中以隐藏特定的CLI属性吗?


6
这可能是另一种方式,mysql并且ps发挥了魔力,而不是:“ MySQL客户端通常在初始化序列期间用零覆盖命令行密码参数。” – 最终用户密码安全准则
manatwork 2013年

谢谢,这是一个内容翔实的文件。我将了解如何在自己的脚本中覆盖cli参数。
dotancohen

1
@manatwork我想以此为答案,因为这正是正在发生的事情-对于涉及mysql的安全性问题,它是一个有用的链接。:)
Drav Sloan

请注意,虽然可以监听命令行参数,但环境变量是safe
吉尔斯(Gillles)“所以-别再邪恶了”

有关更多信息,请参见unix.stackexchange.com/q/385339/135943
通配符

Answers:


23

ps不隐藏密码。像mysql这样的应用程序会覆盖它们获得的参数列表。请注意,这是一个很小的时间范围(可能会因系统负载高而扩展),在此之前,其他应用程序可以看到这些参数,直到它们被覆盖为止。将流程隐藏给其他用户可能会有所帮助。通常,通过文件传递密码比通过命令行传递密码要好得多。

本文中,它针对C进行了介绍。以下示例隐藏/删除所有命令行参数:

#include <string.h>

int main(int argc, char **argv)
{
    // process command line arguments....

    // hide command line arguments
    if (argc > 1) {
        char *arg_end;    
        arg_end = argv[argc-1] + strlen (argv[argc-1]);
        *arg_end = ' ';
    }

    // ...
}

请参阅/programming/724582/hide-arguments-from-ps/programming/3830823/hiding-secret-from-command-line-parameter-on-unix


很好,谢谢。我没有意识到论点本身是可变的。
dotancohen

另请注意,并非所有程序都将使用密码来执行此操作。
2013年

这篇文章的链接已断开。有人为我解释代码吗?(为什么代码起作用,只设置\0为空格?)有任何链接setproctitle()吗?
schemacs 2014年

还是答案就在这里
schemacs 2014年

7

MySQL的程序替换的命令行的密码与x这行代码

while (*argument) *argument++= 'x';     // Destroy argument

3
不幸的是,这并不安全。您可以告诉密码多长时间。最好将其替换为,\0以便您需要其他信息来查找密码长度(不包括UB / SEGFAULT)。
wizzwizz4
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.