加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux文件权限

发布时间:2020-12-14 01:18:10 所属栏目:Linux 来源:网络整理
导读:有一个在root用户下运行的进程. ps aux | grep ProcessXroot 11565 0.0 0.7 82120 22976 ? Ssl 14:57 0:02 ProcessX 现在ls -l / proc / 11565 /(pid)给出了这个结果. total 0dr-xr-xr-x 2 root root 0 Aug 9 16:06 attr-rw-r--r-- 1 root root 0 Aug 9 16:0
有一个在root用户下运行的进程.

ps aux | grep ProcessX
root     11565  0.0  0.7  82120 22976 ?        Ssl  14:57   0:02 ProcessX

现在ls -l / proc / 11565 /(pid)给出了这个结果.

total 0
dr-xr-xr-x 2 root root 0 Aug  9 16:06 attr
-rw-r--r-- 1 root root 0 Aug  9 16:06 autogroup
-r-------- 1 root root 0 Aug  9 16:06 auxv
-r--r--r-- 1 root root 0 Aug  9 16:06 cgroup
--w------- 1 root root 0 Aug  9 16:06 clear_refs
-r--r--r-- 1 root root 0 Aug  9 16:06 cmdline
-rw-r--r-- 1 root root 0 Aug  9 16:06 coredump_filter
-r--r--r-- 1 root root 0 Aug  9 16:06 cpuset
lrwxrwxrwx 1 root root 0 Aug  9 16:06 cwd -> /usr/local/bin
-r-------- 1 root root 0 Aug  9 16:06 environ
lrwxrwxrwx 1 root root 0 Aug  9 16:06 exe -> /usr/local/bin/ProcessX
dr-x------ 2 root root 0 Aug  9 16:06 fd
dr-x------ 2 root root 0 Aug  9 16:06 fdinfo
-r-------- 1 root root 0 Aug  9 16:06 io
-rw------- 1 root root 0 Aug  9 16:06 limits
-rw-r--r-- 1 root root 0 Aug  9 16:06 loginuid
-r--r--r-- 1 root root 0 Aug  9 16:06 maps
-rw------- 1 root root 0 Aug  9 16:06 mem
-r--r--r-- 1 root root 0 Aug  9 16:06 mountinfo
-r--r--r-- 1 root root 0 Aug  9 16:06 mounts
-r-------- 1 root root 0 Aug  9 16:06 mountstats
dr-xr-xr-x 6 root root 0 Aug  9 16:06 net
-r--r--r-- 1 root root 0 Aug  9 16:06 numa_maps
-rw-r--r-- 1 root root 0 Aug  9 16:06 oom_adj
-r--r--r-- 1 root root 0 Aug  9 16:06 oom_score
-rw-r--r-- 1 root root 0 Aug  9 16:06 oom_score_adj
-r--r--r-- 1 root root 0 Aug  9 16:06 pagemap
-r--r--r-- 1 root root 0 Aug  9 16:06 personality
lrwxrwxrwx 1 root root 0 Aug  9 16:06 root -> /
-rw-r--r-- 1 root root 0 Aug  9 16:06 sched
-r--r--r-- 1 root root 0 Aug  9 16:06 schedstat
-r--r--r-- 1 root root 0 Aug  9 16:06 sessionid
-r--r--r-- 1 root root 0 Aug  9 16:06 smaps
-r--r--r-- 1 root root 0 Aug  9 16:06 stack
-r--r--r-- 1 root root 0 Aug  9 16:06 stat
-r--r--r-- 1 root root 0 Aug  9 16:06 statm
-r--r--r-- 1 root root 0 Aug  9 16:06 status
-r--r--r-- 1 root root 0 Aug  9 16:06 syscall
dr-xr-xr-x 6 root root 0 Aug  9 16:06 task
-r--r--r-- 1 root root 0 Aug  9 16:06 wchan

现在状态和地图的文件权限是相同的(-r – r – r–).但是当我用非特权(非root)用户发出cat / proc / 11565 / maps时,它会拒绝我的权限.但对于cat / proc / 11565 / status,它按预期输出.

这里有什么我想念的吗?

解决方法

这是因为文件权限不是您遇到的唯一保护.

这些不仅仅是文件系统上的常规文本文件,procfs是进程内部的窗口,您必须通过文件权限以及其他任何保护措施.

这些地图显示了有关内存使用情况的潜在危险信息以及可执行代码位于进程空间内的位置.如果你看一下ASLR,你会发现这是一种防止潜在攻击者知道代码加载位置的方法,并且在procfs中的世界可读条目中显示它是没有意义的.

此保护已添加way back in 2007:

This change implements a check using “ptrace_may_attach” before allowing access to read the maps contents. To control this protection,the new knob /proc/sys/kernel/maps_protect has been added,with corresponding updates to the procfs documentation.

在ptrace_may_attach()中(实际上在它调用的函数中)存在以下代码:

if (((current->uid != task->euid) ||
     (current->uid != task->suid) ||
     (current->uid != task->uid) ||
     (current->gid != task->egid) ||
     (current->gid != task->sgid) ||
     (current->gid != task->gid))     && !capable(CAP_SYS_PTRACE))
   return -EPERM;

这样,除非你拥有相同的真实用户/组ID,保存的用户/组ID和有效的用户/组ID(即没有偷偷摸摸的setuid东西),并且它们与拥有该进程的用户/组ID相同,你不允许在里面看到那个“文件”(除非你的进程当然具有CAP_SYS_PTRACE功能).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读