ps 如何知道隐藏密码?

dot*_*hen 23 security ps arguments

证人:

$ 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
Run Code Online (Sandbox Code Playgroud)

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

jof*_*fel 24

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 = ' ';
    }

    // ...
}
Run Code Online (Sandbox Code Playgroud)

查看/sf/ask/50720771//sf/ask/268157641/ .


sch*_*acs 7

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

while (*argument) *argument++= 'x';     // Destroy argument
Run Code Online (Sandbox Code Playgroud)

  • 不幸的是,这并不像它可能的那样安全。您可以知道密码的长度。最好将其替换为“\0”,以便您需要额外的信息来查找密码长度(不带 UB / SEGFAULT)。 (4认同)