cel*_*cni 7 c linux command-line-arguments
如何隐藏在Linux中运行的C程序的命令行参数,以便其他用户通过"w","ps auxwww"或类似命令看不到它们?
修改程序中argv的内容:
#include <stdio.h>
#include <time.h>
void delay (long int msecs)
{
clock_t delay = msecs * CLOCKS_PER_SEC / 1000;
clock_t start = clock();
while (clock() - start < delay);
}
void main (int argc, char **argv)
{
if (argc == 2)
{
printf ("%s\n", argv[1]);
delay (6000);
argv[1][0] = 'x';
argv[1][1] = '.';
argv[1][2] = 'x';
printf ("%s\n", argv[1]);
delay (5000);
printf ("done\n");
}
else printf ("argc != 1: %d\n", argc);
}
Run Code Online (Sandbox Code Playgroud)
调用:
./argumentClear foo
foo
x.x
done
Run Code Online (Sandbox Code Playgroud)
结果,按ps查看:
asux:~ > ps auxwww | grep argu
stefan 13439 75.5 0.0 1620 352 pts/5 R+ 17:15 0:01 ./argumentClear foo
stefan 13443 0.0 0.0 3332 796 pts/3 S+ 17:15 0:00 grep argu
asux:~ > ps auxwww | grep argu
stefan 13439 69.6 0.0 1620 352 pts/5 R+ 17:15 0:02 ./argumentClear x.x
stefan 13446 0.0 0.0 3332 796 pts/3 S+ 17:15 0:00 grep argu
Run Code Online (Sandbox Code Playgroud)
备注:我的延迟功能无法正常工作.而不是11秒,程序运行大约2-3.我不是那个大C程序员.:)延迟功能需要改进.
这实际上相当困难(我不会说不可能,因为可能有一种我不知道的方式)这样做,特别是如果用户可以访问/proc您的进程的文件系统.
也许防止人们看到命令行参数的最好方法是不使用命令行参数:-)
您可以将参数存储在一个受到适当保护的文件中(例如),myargs.txt然后运行您的程序:
myprog @myargs.txt
Run Code Online (Sandbox Code Playgroud)
当然,您必须修改myprog以处理"文件中的参数"方案.
或者,您可以将参数设置为环境变量并使用您的程序getenv.
但是,我不知道任何方法可以保护您免受适当授权的进程(例如一个运行root).