微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Linux中隐藏C程序的命令行参数

如何隐藏在 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);
}

调用

./argumentClear foo  
foo
x.x
done

结果,按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

备注:我的延迟功能无法正常工作.该程序运行时间约为2-3秒而不是11秒.我不是那个大C程序员. :)延迟功能需要改进.

原文地址:https://www.jb51.cc/linux/394410.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐