久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php淺析反序列化結(jié)構(gòu)知識點(diǎn)

      本篇文章主要給大家介紹了關(guān)于PHP的相關(guān)知識,序列化其實(shí)就是將數(shù)據(jù)轉(zhuǎn)化成一種可逆的數(shù)據(jù)結(jié)構(gòu),自然,逆向的過程就叫做反序列化。php將數(shù)據(jù)序列化和反序列化會用到兩個函數(shù):serialize 將對象格式化成有序的字符串、unserialize 將字符串還原成原來的對象,希望對大家有幫助。

      php淺析反序列化結(jié)構(gòu)知識點(diǎn)

      (推薦教程:PHP視頻教程)

      簡介

      序列化的目的是方便數(shù)據(jù)的傳輸和存儲,在PHP中,序列化和反序列化一般用做緩存,比如session緩存,cookie等。

      反序列化中常見的魔術(shù)方法

      • __wakeup() //執(zhí)行unserialize()時,先會調(diào)用這個函數(shù)

      • __sleep() //執(zhí)行serialize()時,先會調(diào)用這個函數(shù)

      • __destruct() //對象被銷毀時觸發(fā)

      • __call() //在對象上下文中調(diào)用不可訪問的方法時觸發(fā)

      • __callStatic() //在靜態(tài)上下文中調(diào)用不可訪問的方法時觸發(fā)

      • __get() //用于從不可訪問的屬性讀取數(shù)據(jù)或者不存在這個鍵都會調(diào)用此方法

      • __set() //用于將數(shù)據(jù)寫入不可訪問的屬性

      • __isset() //在不可訪問的屬性上調(diào)用isset()或empty()觸發(fā)

      • __unset() //在不可訪問的屬性上使用unset()時觸發(fā)

      • __toString() //把類當(dāng)作字符串使用時觸發(fā)

      • __invoke() //當(dāng)嘗試將對象調(diào)用為函數(shù)時觸發(fā)

      反序列化繞過小Trick

      php7.1+反序列化對類屬性不敏感

      我們前面說了如果變量前是protected,序列化結(jié)果會在變量名前加上x00*x00

      但在特定版本7.1以上則對于類屬性不敏感,比如下面的例子即使沒有x00*x00也依然會輸出abc

      <?php class test{     protected $a;     public function __construct(){         $this->a = 'abc';     }     public function  __destruct(){         echo $this->a;     } } unserialize('O:4:"test":1:{s:1:"a";s:3:"abc";}');

      繞過_wakeup(CVE-2016-7124)

      版本:

      PHP5 < 5.6.25

      PHP7 < 7.0.10

      利用方式:序列化字符串中表示對象屬性個數(shù)的值大于真實(shí)的屬性個數(shù)時會跳過__wakeup的執(zhí)行

      對于下面這樣一個自定義類

      <?php class test{     public $a;     public function __construct(){         $this->a = 'abc';     }     public function __wakeup(){         $this->a='666';     }     public function  __destruct(){         echo $this->a;     } }

      如果執(zhí)行unserialize('O:4:"test":1:{s:1:"a";s:3:"abc";}');輸出結(jié)果為666

      而把對象屬性個數(shù)的值增大執(zhí)行unserialize('O:4:"test":2:{s:1:"a";s:3:"abc";}');輸出結(jié)果為abc

      繞過部分正則

      preg_match('/^O:d+/')匹配序列化字符串是否是對象字符串開頭,這在曾經(jīng)的CTF中也出過類似的考點(diǎn)

      利用加號繞過(注意在url里傳參時+要編碼為%2B)

      serialize(array(a ) ) ; / / a));//a));//a為要反序列化的對象(序列化結(jié)果開頭是a,不影響作為數(shù)組元素的$a的析構(gòu))

      <?php class test{     public $a;     public function __construct(){         $this->a = 'abc';     }     public function  __destruct(){         echo $this->a.PHP_EOL;     } } function match($data){     if (preg_match('/^O:d+/',$data)){         die('you lose!');     }else{         return $data;     } } $a = 'O:4:"test":1:{s:1:"a";s:3:"abc";}'; // +號繞過 $b = str_replace('O:4','O:+4', $a); unserialize(match($b)); // serialize(array($a)); unserialize('a:1:{i:0;O:4:"test":1:{s:1:"a";s:3:"abc";}}');

      利用引用

      <?php class test{     public $a;     public $b;     public function __construct(){         $this->a = 'abc';         $this->b= &$this->a;     }     public function  __destruct(){          if($this->a===$this->b){             echo 666;         }     } } $a = serialize(new test());

      上面這個例子將$b設(shè)置為$a的引用,可以使$a永遠(yuǎn)與$b相等

      16進(jìn)制繞過字符的過濾

      O:4:“test”:2:{s:4:“%00*%00a”;s:3:“abc”;s:7:“%00test%00b”;s:3:“def”;}

      可以寫成

      O:4:“test”:2:{S:4:“