命令hidepid用于阻止用户查看不属于它们的所有进程,但它不提供选择特定进程的可能性。在Linux机器上只能隐藏一个进程吗?
发布于 2016-05-03 17:57:22
有点脏,而且可能有一个更干净的解决方案(可能使用SELinux或grsec),但是您可以通过在/proc/<pid>中挂载一个空目录来隐藏一个进程。
例如,如下所示:
mount -o bind /empty/dir /proc/42将阻止常规用户查看流程42。
然而,他们将看到某些东西是隐藏的,因为他们将能够看到挂载点。
如果您想为服务执行此操作,则每次启动时都必须使用init脚本或其他任何方法。
如果只想对特定用户隐藏pid,则可以使用名称空间(可能使用pam_namespace)使挂载绑定只在目标用户的命名空间中完成。
为了扭转这一局面,只需运行:
umount /proc/42发布于 2019-01-05 17:43:14
从内核3.3开始,它就实现了一些东西来满足您的需要。
根据第(5)段:
hidepid=n (since Linux 3.3)
This option controls who can access the information in /proc/[pid] directories.
The argument, n, is one of the following values:
0 Everybody may access all /proc/[pid] directories. This is the traditional be‐
havior, and the default if this mount option is not specified.
1 Users may not access files and subdirectories inside any /proc/[pid] directo‐
ries but their own (the /proc/[pid] directories themselves remain visible).
Sensitive files such as /proc/[pid]/cmdline and /proc/[pid]/status are now
protected against other users. This makes it impossible to learn whether any
user is running a specific program (so long as the program doesn't otherwise
reveal itself by its behavior).
2 As for mode 1, but in addition the /proc/[pid] directories belonging to other
users become invisible. This means that /proc/[pid] entries can no longer be
used to discover the PIDs on the system. This doesn't hide the fact that a
process with a specific PID value exists (it can be learned by other means,
for example, by "kill -0 $PID"), but it hides a process's UID and GID, which
could otherwise be learned by employing stat(2) on a /proc/[pid] directory.
This greatly complicates an attacker's task of gathering information about
running processes (e.g., discovering whether some daemon is running with ele‐
vated privileges, whether another user is running some sensitive program,
whether other users are running any program at all, and so on).
gid=gid (since Linux 3.3)
Specifies the ID of a group whose members are authorized to learn process informa‐
tion otherwise prohibited by hidepid (i.e., users in this group behave as though
/proc was mounted with hidepid=0). This group should be used instead of ap‐
proaches such as putting nonroot users into the sudoers(5) file.这很有用,因为您可以选择谁可以读取/proc/PID。
因此,如果您想尝试它,请记住根据您的需要重新装入/proc:
-实际案件:
: su -
Password:
root@foo:~# mount -o remount,hidepid=2 /proc
root@foo:~# exit
logout
:ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
tntx 709 0.0 0.1 33980 8012 tty2 S 18:12 0:00 irssi
tntx 746 0.0 0.0 8868 3880 tty1 S 18:13 0:00 -ksh93因此,现在我除了通过PS(1)或lsof(8)看我的过程之外,没有其他的方法。
https://unix.stackexchange.com/questions/280860
复制相似问题