There are some interesting php pop chain I really enjoy it.
Tools: vscode,PHP IntelliSense
1. Laravel Unserialize Pop Chain
Laravel is a php framework for web artisans,website https://laravel.com/. build this laravel i think is diffcute so i use docker to build them.in vendor/laravel/framework/src/Illuminate/Foundation/Application.php Line 32 you can see which version you build
1.1. Laravel 5.8.X
Run by dockerdocker run -d -p 8000:8000 --name laravel oubingbing/laravel5.8:v1. vim /routes/web.php
so if $this->queueResolver && $this->commandShouldBeQueued($command) is true,we can invoke call_user_func function. so we analy how to do it. first the queueResolver we can define and is invoke function name so we need define ‘system’ or other function. $this->commandShouldBeQueued is return $command instanceof ShouldQueue; so we need find a class implements ShouldQueue and get him a connection attribute for system function invoke. so we need search implements ShouldQueue
those are ok. we use namespace Illuminate\Events;class CallQueuedListener implements ShouldQueue finall exp1
so if $this->events define to class Validator. when call dispatch function will into __call magic method. so we let class $parameters Validatorextensions rule =system,and PendingBroadcast->event==whoami.
so we need analy how to set Validator->extensions[$rule] ,first we need learn in laravel $rule = Str::snake(substr($method, 8));
The Str::snake method converts the given string to snake_case. but if the given string not a suitable string will return null. for example,if rule set dispatch
the result is
1 2
string(8) "dispatch" string(0) ""
so we just need set $this->extensions=array(‘’=>’system’)
Lastly we need invoke call_user_func_array,and the $arguments==$attributes==$this->event==ls /, the $events=class Generator,and Generator->getFormatter($formatter)==Generator->formatters[$formatter]==Generator->formatters[$method]==Generator->formatters["dispatch"]==system so final exp3
'debug' => env('APP_DEBUG', false), to 'debug' => env('APP_DEBUG', true),
change .env.example to .env then run
1 2
composer install php artisan key:generate
Good job. Enjoy it
tips. the difference between laravel 5.7 and laravel 5.8
1.1.1. laravel 5.8 exp1 and 1.1.2. laravel 5.8 exp2 In laravel 5.7 as usual.but 1.1.3. laravel 5.8 exp3 is unuseful And Laravel 5.7.X exp1/2 is as same useful for laravel 5.8 why? In laravel 5.7 Generator.php Line 295
call_user_func("system","ls /"); call_user_func_array("system",["ls /"]); classTest { staticpublicfunctiondemo($a, $b) { echo$a + $b; } publicfunctionshow($a, $b) { echo$a + $b; } } // call the static function by array method call_user_func(['Test', 'demo'], 1, 2); // 3 call_user_func_array(['Test', 'demo'], [1, 2]); // 3 // Class name method name in string form call_user_func('Test::demo', 1, 2); // 3 call_user_func_array('Test::demo', [1, 2]); // 3
// Call the dynamic method in the class. The object and method must be passed in the form of array call_user_func([newTest, 'show'], 1, 2); // 3 call_user_func_array([newTest, 'show'], [1, 2]); // 3 ?>
2.1.1. CVE-2020-15148 Yii2 less than 2.0.38 exp1
as usual . search __destruct(). in namespace yii\db;,class BatchQueryResult
1 2 3 4 5 6 7 8 9 10 11
publicfunction__destruct() { $this->reset(); }
publicfunctionreset() { if ($this->_dataReader !== null) { $this->_dataReader->close(); } }
thought we can’t find other close() function but we can search __call function to invoke it.so we find namespace Faker;class Generator
but $attributes is array(),and we can’t set value for it. so we need set $method==$this->getFormatter($formatter)==$this->formatters[$formatter]==$this->formatters['close']==some funtion had't attributes. infact we can’t find proper function. for example-phpinfo exp
so we need search other dangerous function which param can be array(); in vscode we can search by regular expression call_user_func\(\$this->([a-zA-Z0-9]+), \$this->([a-zA-Z0-9]+)or call_user_func_array\(\$this->([a-zA-Z0-9]+), \$this->([a-zA-Z0-9]+) in namespace yii\rest;,class IndexAction
1 2 3 4 5 6 7
publicfunctionrun() { if ($this->checkAccess) { call_user_func($this->checkAccess, $this->id); } ..... }
or namespace yii\rest; class IndexAction so we need set $this->checkAccess as system.$this->id as whoami then set $this->formatters['close'] as [new CreateAction, 'run'] so final exp