国内流行的内容管理系统(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.

121 lines
4.4KB

  1. <?php
  2. /**
  3. * 安全检测
  4. *
  5. * @version $Id: sys_safetest.php 2 9:25 2010-11-12 tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2022, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__).'/config.php');
  12. require_once(DEDEINC.'/libraries/dedehttpdown.class.php');
  13. CheckPurview('sys_Edit');
  14. if (empty($action)) $action = '';
  15. if (empty($message)) $message = '尚未进行检测……';
  16. if (empty($filetype)) $filetype = 'php|inc';
  17. if (empty($info)) $info = 'eval|cmd|system|exec|_GET|_POST|_REQUEST|base64_decode';
  18. $fileHashURL = "https://cdn.dedebiz.com/release/{$cfg_version_detail}.json";
  19. $del = new DedeHttpDown();
  20. $del->OpenUrl($fileHashURL);
  21. $filelist = $del->GetJSON();
  22. $offFiles = array();
  23. foreach ($filelist as $key => $ff) {
  24. $offFiles[$ff->filename] = $ff->hash;
  25. }
  26. $alter = "";
  27. if (count($offFiles) == 0) {
  28. $alter = '<div class="alert alert-danger maintable" style="margin:12px auto">无法同官方网站文件服务器通信,校验时候无法保证本地文件是否同官方服务器文件是否一致</div>';
  29. }
  30. function TestOneFile($f)
  31. {
  32. global $message, $info, $offFiles;
  33. $str = '';
  34. //排除safefile和data/tplcache目录
  35. if (preg_match("#data/tplcache|.svn|data/cache#", $f)) return -1;
  36. $fp = fopen($f, 'r');
  37. while (!feof($fp)) {
  38. $str .= fgets($fp, 1024);
  39. }
  40. fclose($fp);
  41. if (preg_match("#(".$info.")[ \r\n\t]{0,}([\[\(])#i", $str)) {
  42. $trfile = preg_replace("#^".DEDEROOT."#", '', $f);
  43. $oldTrfile = $trfile;
  44. $trfile = '/'.substr(str_replace("\\", "/", $trfile), 1);
  45. $localFilehash = md5_file($f);
  46. $remoteFilehash = isset($offFiles[$trfile]) ? $offFiles[$trfile] : '';
  47. if ($localFilehash === $remoteFilehash) {
  48. return 0;
  49. }
  50. $message .= "<div style='clear:both;'>
  51. <div style='width:350px;float:left'>可疑文件:{$trfile}</div>
  52. <a class='btn btn-success btn-sm' href='sys_safetest.php?action=viewdiff&filename=$oldTrfile' target='_blank'>修改记录</a>
  53. <a class='btn btn-success btn-sm' href='file_manage_view.php?fmdo=del&filename=$oldTrfile&activepath=' target='_blank'>删除</a>
  54. <a class='btn btn-success btn-sm' href='file_manage_view.php?fmdo=edit&filename=$oldTrfile&activepath=' target='_blank'>查看源码</a>
  55. </div></div><hr>\r\n";
  56. return 1;
  57. }
  58. return 0;
  59. }
  60. function TestSafe($tdir)
  61. {
  62. global $filetype;
  63. $dh = dir($tdir);
  64. while ($fname = $dh->read()) {
  65. $fnamef = $tdir.'/'.$fname;
  66. if (@is_dir($fnamef) && $fname != '.' && $fname != '..') {
  67. TestSafe($fnamef);
  68. }
  69. if (preg_match("#\.(".$filetype.")#i", $fnamef)) {
  70. TestOneFile($fnamef);
  71. }
  72. }
  73. }
  74. //检测
  75. if ($action == 'test') {
  76. $message = '<link rel="stylesheet" href="../static/web/css/bootstrap.min.css"><link rel="stylesheet" href="../static/web/font/css/font-awesome.min.css">';
  77. AjaxHead();
  78. TestSafe(DEDEROOT);
  79. if ($message == '') $message = "<span class='text-dark'>没发现可疑文件</span>";
  80. echo $message;
  81. exit();
  82. } else if ($action == 'viewdiff') {
  83. $filename = isset($filename) ? $filename : "";
  84. if (empty($filename)) {
  85. ShowMsg("没有选择对应的文件", "-1");
  86. exit;
  87. }
  88. $baseFile = "https://cdn.dedebiz.com/release/{$cfg_version_detail}$filename";
  89. $del = new DedeHttpDown();
  90. $del->OpenUrl($baseFile);
  91. $base = $del->GetHTML();
  92. $file = "$cfg_basedir/$filename";
  93. $new = "";
  94. if (is_file($file)) {
  95. $fp = fopen($file, "r");
  96. $new = fread($fp, filesize($file));
  97. fclose($fp);
  98. }
  99. include(dirname(__FILE__).'/templets/sys_safetest_viewdiff.htm');
  100. exit();
  101. }
  102. //清空模板缓存
  103. else if ($action == 'clear') {
  104. global $cfg_tplcache_dir;
  105. $message = '';
  106. $d = DEDEROOT.$cfg_tplcache_dir;
  107. AjaxHead();
  108. sleep(1);
  109. if (preg_match("#data\/#", $cfg_tplcache_dir) && file_exists($d) && is_dir($d)) {
  110. $dh = dir($d);
  111. while ($filename = $dh->read()) {
  112. if ($filename == '.' || $filename == '..' || $filename == 'index.html') continue;
  113. @unlink($d.'/'.$filename);
  114. }
  115. }
  116. $message = "<span class='text-dark'>成功清空模板缓存</span>";
  117. echo $message;
  118. exit();
  119. }
  120. include(dirname(__FILE__).'/templets/sys_safetest.htm');
  121. ?>