国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.9KB

  1. <?php
  2. /**
  3. * 安全检测
  4. *
  5. * @version $Id: sys_safetest.php 2 9:25 2010-11-12 tianya $
  6. * @package DedeCMS.Administrator
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__).'/config.php');
  12. CheckPurview('sys_Edit');
  13. if(empty($action)) $action = '';
  14. if(empty($message)) $message = '尚未进行检测……';
  15. if(empty($filetype)) $filetype = 'php|inc';
  16. if(empty($info)) $info = 'eval|cmd|_GET|_POST';
  17. $safefile = "data/common.inc.php
  18. index.php
  19. dede/config.php
  20. dede/index_body.php
  21. dede/member_do.php
  22. dede/sys_info_pay.php
  23. dede/mychannel_main.php
  24. group/postform.php
  25. group/reply.php
  26. include/common.inc.php
  27. include/mail.class.php
  28. include/Lurd.class.php
  29. include/payment/alipay.php
  30. include/payment/bank.php
  31. include/payment/cod.php
  32. include/payment/yeepay.php
  33. include/helpers/debug.helper.php
  34. include/request.class.php
  35. include/dedecollection.class.php
  36. include/dedetag.class.php
  37. include/dialog/config.php
  38. include/taglib/php.lib.php
  39. include/FCKeditor/fckeditor.php
  40. include/smtp.class.php
  41. include/zip.class.php
  42. install/common.inc.php
  43. include/json.class.php
  44. include/sphinxclient.class.php
  45. plus/bshare.php
  46. install/index.php";
  47. $adminDir = preg_replace("#(.*)[\/\\\\]#", "", dirname(__FILE__));
  48. $safefile = trim(str_replace('dede/',$adminDir.'/',$safefile));
  49. $safefiles = preg_split("#[\r\n]{1,}#", $safefile);
  50. function TestOneFile($f)
  51. {
  52. global $message, $info;
  53. $str = '';
  54. //排除safefile和data/tplcache目录
  55. if(NotCheckFile($f) || preg_match("#data/tplcache|.svn#", $f)) return -1;
  56. $fp = fopen($f, 'r');
  57. while(!feof($fp)) { $str .= fgets($fp,1024); }
  58. fclose($fp);
  59. if(preg_match("#(".$info.")[ \r\n\t]{0,}([\[\(])#i", $str))
  60. {
  61. $trfile = preg_replace("#^".DEDEROOT."#", '', $f);
  62. $message .= "<div style='clear:both;border-bottom:1px dotted #B8E6A2;line-height:24px'>
  63. <div style='width:350px;float:left'>可疑文件:{$trfile}</div>
  64. <div style='float:left'>[<a href='file_manage_view.php?fmdo=del&filename=$trfile&activepath=' target='_blank'><u>删除</u></a>]
  65. [<a href='file_manage_view.php?fmdo=edit&filename=$trfile&activepath=' target='_blank'><u>查看源码</u></a>]
  66. </div></div>\r\n";
  67. return 1;
  68. }
  69. return 0;
  70. }
  71. function NotCheckFile($f)
  72. {
  73. global $safefiles, $safefile;
  74. if($safefile != '')
  75. {
  76. foreach($safefiles as $v)
  77. {
  78. //if(empty($v)) continue;
  79. if( preg_match("#".$v."#i", $f) ) return TRUE;
  80. }
  81. }
  82. return false;
  83. }
  84. function TestSafe($tdir)
  85. {
  86. global $filetype;
  87. $dh = dir($tdir);
  88. while($fname=$dh->read())
  89. {
  90. $fnamef = $tdir.'/'.$fname;
  91. if(@is_dir($fnamef) && $fname != '.' && $fname != '..')
  92. {
  93. TestSafe($fnamef);
  94. }
  95. if(preg_match("#\.(" . $filetype . ")#i", $fnamef))
  96. {
  97. TestOneFile($fnamef);
  98. }
  99. }
  100. }
  101. //检测
  102. if($action=='test')
  103. {
  104. $message = '';
  105. AjaxHead();
  106. TestSafe(DEDEROOT);
  107. if($message=='') $message = "<font color='green' style='font-size:14px'>没发现可疑文件!</font>";
  108. echo $message;
  109. exit();
  110. }
  111. //清空模板缓存
  112. else if($action=='clear')
  113. {
  114. global $cfg_tplcache_dir;
  115. $message = '';
  116. $d = DEDEROOT.$cfg_tplcache_dir;
  117. AjaxHead();
  118. sleep(1);
  119. if(preg_match("#data\/#", $cfg_tplcache_dir) && file_exists($d) && is_dir($d))
  120. {
  121. $dh = dir($d);
  122. while($filename = $dh->read())
  123. {
  124. if($filename=='.'||$filename=='..'||$filename=='index.html') continue;
  125. @unlink($d.'/'.$filename);
  126. }
  127. }
  128. $message = "<font color='green' style='font-size:14px'>成功清空模板缓存!</font>";
  129. echo $message;
  130. exit();
  131. }
  132. include(dirname(__FILE__).'/templets/sys_safetest.htm');