0

Consider this C snippet:

snprintf(buf, sizeof(buf), "<LONG PROCESS WITH PARAMETERS HAVING SENSITIVE INFO>";
system(buf);

Now on compiling and executing this, the "sensitive" parameters of the process can be seen on programs like htop And I don't want that.

I would like to know if there's a way to hide everything passed in system() such that htop will only show the name of the compiled executable (i.e htop just displays a.out all the time)

RuMAN S
  • 123
  • 7
  • you could use a wrapper which reads an environment variable instead. – Jean-François Fabre Nov 01 '17 at 07:06
  • 2
    Possible duplicate of [Hiding secret from command line parameter on Unix](https://stackoverflow.com/questions/3830823/hiding-secret-from-command-line-parameter-on-unix) – e.dan Nov 01 '17 at 07:12

1 Answers1

0

In all the Unix-like systems I've used, including many Linux variants, it's possible for a program to overwrite it's command-line arguments "from inside". So in C we might use, for example, strcnpy() just to blank the values of argv[1], argv[2], etc. Of course, you need to have processed or copied these arguments first, and you need to be careful not to overwrite memory outside the specific limits of each argv.

I don't think anything about Unix guarantees the portability or continued applicability of this approach, but I have been using it for at least twenty years. It conceals the command from casual uses of ps, etc., and also from /proc/NN/cmdline, but it won't stop the shell storing the command line somewhere (e.g., in a shell history file). So it only prevents casual snooping.

A better approach is not to get into the situation in the first place -- have the program take its input from files (which could be encrypted), or environment variables, or use certificates. Or almost anything, in fact, except the command line.

Kevin Boone
  • 4,092
  • 1
  • 11
  • 15