[SWPU2019]Web4-WP
题目来源:BUUCTF
题目类型:WEB
设计考点:sql盲注,MSV,变量覆盖


时间盲注爆破得到:glzjin_wants_a_girl_friend.zip
代码审计可以发现他的整体逻辑
首先关注他的URL:http://fab20018-12d4-4251-a25f-8c6635e869ea.node5.buuoj.cn:81/index.php?r=User/Index
它读取了一个值$r$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| if(!empty($_REQUEST['r'])) { $r = explode('/', $_REQUEST['r']); list($controller,$action) = $r; $controller = "{$controller}Controller"; $action = "action{$action}";
if(class_exists($controller)) { if(method_exists($controller,$action)) { } else { $action = "actionIndex"; } } else { $controller = "LoginController"; $action = "actionIndex"; } $data = call_user_func(array( (new $controller), $action));
|
然后调用/前对应的Controller并且执行对应的action方法
接下来关注所有controller的父类,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?php
class BaseController {
private $viewPath; public function loadView($viewName ='', $viewData = []) { $this->viewPath = BASE_PATH . "/View/{$viewName}.php"; if(file_exists($this->viewPath)) { extract($viewData); include $this->viewPath; } } }
|
它的方法 $loadView$ 中有 $extract$ 函数我们可以变量覆盖,然后它执行了一个include,我们就去寻找对应的漏洞
在User Controller中我们发现它调用loadView方法
1 2 3 4 5
| public function actionIndex() { $listData = $_REQUEST; $this->loadView('userIndex',$listData); }
|
他的actionIndex函数中的listdata值可控,我们继续跟进,按照代码逻辑,他会包含userIndex.php,我们继续跟进代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <?php function imgToBase64($img_file) {
$img_base64 = ''; if (file_exists($img_file)) { $app_img_file = $img_file; $img_info = getimagesize($app_img_file);
$fp = fopen($app_img_file, "r");
if ($fp) { $filesize = filesize($app_img_file); $content = fread($fp, $filesize); $file_content = chunk_split(base64_encode($content)); switch ($img_info[2]) { case 1: $img_type = "gif"; break; case 2: $img_type = "jpg"; break; case 3: $img_type = "png"; break; }
$img_base64 = 'data:image/' . $img_type . ';base64,' . $file_content;
} fclose($fp); }
return $img_base64; } ?>
|
发现它会获取一个img_file值然后尝试输出一个base64格式的图片文件,那么这题的攻击逻辑就很清楚了,
我们构造url的r值为user/Index,让他调用userController中的actionIndex方法,然后传值给img_file=/../flag.php在baseController中的extract方法会创造img_file变量值为/../flag.php,然后include userIndex.php文件,这就会让userIndex.php文件尝试读取flag.php文件然后把他的base64加密字符串输出,最后回显

