首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
systemd Local Privilege Escalation
来源:vfocus.net 作者:Orlitzky 发布时间:2018-02-01  
Product: systemd (systemd-tmpfiles)
Versions-affected: 236 and earlier
Author: Michael Orlitzky
Fixed-in: commit 5579f85 , version 237
Bug-report: https://github.com/systemd/systemd/issues/7736
Acknowledgments: Lennart Poettering who, instead of calling me an idiot
  for not realizing that systemd enables fs.protected_hardlinks by
  default, went out of his way to harden the non-default configuration.
 
 
== Summary ==
 
Before version 237, the systemd-tmpfiles program will change the
permissions and ownership of hard links. If the administrator disables
the fs.protected_hardlinks sysctl, then an attacker can create hard
links to sensitive files and subvert systemd-tmpfiles, particularly
with "Z" type entries.
 
Systemd as PID 1 with the default fs.protected_hardlinks=1 is safe.
 
 
== Details ==
 
When running as PID 1, systemd enables the fs.protected_hardlinks
sysctl by default; that prevents an attacker from creating hard links
to files that he can't write to. If, however, the administrator should
decide to disable that sysctl, then hard links may be created to any
file (on the same filesystem).
 
Before version 237, the systemd-tmpfiles program will voluntarily
change the permissions and ownership of a hard link, and that is
exploitable in a few scenarios. The most problematic and easiest to
exploit is the "Z" type tmpfiles.d entry, which changes ownership and
permissions recursively. For an example, consider the following
tmpfiles.d entries,
 
  d /var/lib/systemd-exploit-recursive 0755 mjo mjo
  Z /var/lib/systemd-exploit-recursive 0755 mjo mjo
 
Whenever systemd-tmpfiles is run, those entries make mjo the owner of
everything under and including /var/lib/systemd-exploit-recursive. After
the first run, mjo can create a hard link inside that directory pointing
to /etc/passwd. The next run (after a reboot, for example) changes the
ownership of /etc/passwd.
 
A proof-of-concept can be run from the systemd source tree, using
either two separate terminals or sudo:
 
  root # sysctl -w fs.protected_hardlinks=0
  root # sysctl -w kernel.grsecurity.linking_restrictions=0
  root # ./build/systemd-tmpfiles --create
  mjo $ ln /etc/passwd /var/lib/systemd-exploit-recursive/x
  root # ./build/systemd-tmpfiles --create
  mjo $ /bin/ls -l /etc/passwd
  -rwxr-xr-x 2 mjo mjo 1504 Dec 20 14:27 /etc/passwd
 
More elaborate exploits are possible, and not only the "Z" type is
vulnerable.
 
 
== Resolution ==
 
The recursive change of ownership/permissions does not seem to be safely
doable without fs.protected_hardlinks enabled.
 
In version 237 and later, systemd-tmpfiles calls fstatat() immediately
after obtaining a file descriptor from open():
 
  fd = open(path, O_NOFOLLOW|O_CLOEXEC|O_PATH);
  if (fd < 0) {
    ...
  }
  if (fstatat(fd, "", &st, AT_EMPTY_PATH) < 0)
 
The st->st_nlink field is then checked to determine whether or not fd
describes a hard link. If it does, the ownership/permissions are not
changed, and an error is displayed:
 
  if (hardlink_vulnerable(&st)) {
    log_error("Refusing to set permissions on hardlink...", path);
    return -EPERM;
  }
 
There is still a tiny window between open() and fstatat() where the
attacker can fool this countermeasure by removing an existing hard
link to, say, /etc/passwd. In that case, st->st_nlink will be 1, but
fd still references /etc/passwd. The attack succeeds, but is much
harder to do, and the window is as narrow as possible. More to the
point, it seems unavoidable when implementing the tmpfiles.d
specification.
 
 
== Mitigation ==
 
Leave the fs.protected_hardlinks sysctl enabled



 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·Dup Scout Enterprise 10.4.16 I
·BMC Server Automation RSCD Age
·BMC BladeLogic RSCD Agent 8.3.
·Sync Breeze Enterprise 10.4.18
·LabF nfsAxe 3.7 TFTP Client -
·WebKit - 'detachWrapper' Use-A
·System Shield 5.0.0.136 - Priv
·WebKit - 'WebCore::FrameView::
·Advantech WebAccess < 8.3 - SQ
·Oracle Hospitality Simphony (M
·Arq 5.10 - Local Privilege Esc
·Microsoft Windows Subsystem fo
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved