Chinaunix首页 | 论坛 | 博客
  • 博客访问: 20274
  • 博文数量: 2
  • 博客积分: 96
  • 博客等级: 民兵
  • 技术积分: 31
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-08 09:22
文章分类

全部博文(2)

文章存档

2014年(1)

2011年(1)

我的朋友

分类: LINUX

2014-10-16 14:40:20

本人水平非常有限,权当笔记看
Linux kernel 3.2以上,root用户可以设置内核,让普通用户看不到其它用户的进程。适用于有多个用户使用的系统。该功能由内核提供,因此本教程适用于Debian/Ubuntu/RHEL/CentOS等。

原理

Linux中,可以通过/proc文件系统访问到许多内核的内部信息。/proc文件系统最初的设计也是用于方便地访问进程相关的信息,因此命名为proc。现在这个文件系统已用于反映系统中方方面面的信息,例如/proc/modules是模块的列表,/proc/meminfo则是内存使用的统计。/proc文件系统中的目录并非持久存储的信息,也就是说,其目录并不“真实”地存在于磁盘,而是在访问时动态生成。

我们感兴趣的是/proc文件系统中关于进程的信息。每一个进程在/proc文件系统中有一个目录即(/proc/),目录名即进程号。self目录是一个链接,指向当前进程。

ps命令和top命令从/proc文件系统中读取进程信息并显示出来。因此,如果一个进程的进程号没有在/proc文件系统中反映出来,则这个进程被“隐藏”了,“隐藏”进程在pstop命令的输出不出现。

hidepid 选项解释

该选项定义了一个Linux用户可以查看到多少其它用户的信息。保护级别分0、1、2三个等级,由底到高防御增强。

  1. hidepid=0 - 经典模式 - 任何人都可以访问/proc//*文件夹下所有的可阅读文件 (默认).
  2. hidepid=1 - 敏感保护 - 文件夹/proc/下敏感的文件如:cmdline, sched*, status不被允许他人访问
  3. hidepid=2 - 强力保护 - It means hidepid=1 plus all /proc/PID/ will be invisible to other users. It compicates intruder's task of gathering info about running processes, whether some daemon runs with elevated privileges, whether another user runs some sensitive program, whether other users run any program at all, etc.

内核保护:隐藏其它用户的进程

通过下面命令可令配置立即生效:

# mount -o remount,rw,hidepid=2 /proc

 

编辑/etc/fstab文件,使配置在服务器启动时自动生效

# vi /etc/fstab

 

proc    /proc    proc    defaults,hidepid=2     0     0

保存退出。

举例:防止用户查看他人的进程

下面是一个例子

$ ssh vivek@cbz-test
$ ps -ef
$ sudo -s
# mount -o remount,rw,hidepid=2 /proc
$ ps -ef
$ top
$ htop
实战记录:

 

gif动画: hidepid 实战

 

Tip: Dealing with apps that breaks when you implement this technique

You need to use gid=VALUE_HERE option:

gid=XXX defines a group that will be able to gather all processes' info (as in hidepid=0 mode). This group should be used instead of putting nonroot user in sudoers file or something. However, untrusted users (like daemons, etc.) which are not supposed to monitor the tasks in the whole system should not be added to the group.

So add the user called see process information and mount /proc as follows in /etc/fstab:

proc /proc proc defaults,hidepid=2,gid=admin 0 0 

原文: 译文: 转载请保留链接
阅读(2565) | 评论(0) | 转发(0) |
1

上一篇:博客已升级,请注意变更地址

下一篇:没有了

给主人留下些什么吧!~~