24 "sessionDir" =>
array(
25 "method" =>
"checkPhpSessionDir"
27 "collectivePhpSession" =>
array(
28 "method" =>
"checkCollectivePhpSession"
30 "uploadScriptExecution" =>
array(
31 "method" =>
"checkUploadScriptExecution"
33 "uploadNegotiationEnabled" =>
array(
34 "method" =>
"checkUploadNegotiationEnabled"
36 "privilegedPhpUserOrGroup" =>
array(
37 "method" =>
"checkPhpUserAndGroup"
39 "bitrixTempPath" =>
array(
40 "method" =>
"checkBitrixTempPath"
53 $sessionConfig = $resolver->getSessionConfig();
55 return $sessionConfig[
'handlers'][
'general'][
'type'] ??
null;
64 $baseMessageKey =
"SECURITY_SITE_CHECKER_UPLOAD_EXECUTABLE";
66 $isHtaccessOverrided =
false;
74 $isPhpExecutable =
false;
76 if(self::isScriptExecutable(
"test.php",
"<?php echo '{$uniqueString}'; ?>", $uniqueString))
78 $isPhpExecutable =
true;
82 $isPhpDoubleExtensionExecutable =
false;
83 if(!$isPhpExecutable && self::isScriptExecutable(
"test.php.any",
"<?php echo '{$uniqueString}'; ?>", $uniqueString))
85 $isPhpDoubleExtensionExecutable =
true;
89 $isPythonCgiExecutable =
false;
90 if(self::isScriptExecutable(
"test.py",
"print 'Content-type:text/html\\r\\n\\r\\n{$uniqueString}'", $uniqueString))
92 $isPythonCgiExecutable =
true;
96 if ($isPhpExecutable || $isPhpDoubleExtensionExecutable || $isHtaccessOverrided || $isPythonCgiExecutable)
97 return self::STATUS_FAILED;
99 return self::STATUS_PASSED;
108 $testingText =
"test";
111Content-type: text/html;
118 if(self::isScriptExecutable(
"test.var.jpg", $testFileContent, $testingText))
121 return self::STATUS_FAILED;
124 return self::STATUS_PASSED;
134 $uploadPathTestFile = $uploadDir.
'test/test.php';
135 $uploadPathHtaccessFile = $uploadDir.
'test/.htaccess';
136 $uploadPathTestUri = $uploadDir.
'test/test_notexist.php';
141 $testingText =
"testing text here...";
142 $htaccessText = <<<HTACCESS
143ErrorDocument 404 ${uploadPathTestFile}
145<IfModule mod_rewrite.c>
151 if(file_put_contents(
$_SERVER[
'DOCUMENT_ROOT'].$uploadPathTestFile, $testingText))
153 if(file_put_contents(
$_SERVER[
'DOCUMENT_ROOT'].$uploadPathHtaccessFile, $htaccessText))
160 unlink(
$_SERVER[
'DOCUMENT_ROOT'].$uploadPathHtaccessFile);
162 unlink(
$_SERVER[
'DOCUMENT_ROOT'].$uploadPathTestFile);
176 if(self::isRunOnWin())
177 return self::STATUS_PASSED;
179 $uid = self::getCurrentUID();
180 $uidCheckFailed =
false;
182 $uidCheckFailed =
true;
184 $gid = self::getCurrentGID();
185 $gidCheckFailed =
false;
186 if($gid !==
null && $gid < $minGid)
187 $gidCheckFailed =
true;
189 if ($uidCheckFailed || $gidCheckFailed)
192 'SECURITY_SITE_CHECKER_PHP_PRIVILEGED_USER',
194 getMessage(
'SECURITY_SITE_CHECKER_PHP_PRIVILEGED_USER_ADDITIONAL',
array(
195 '#UID#' => static::formatUID(
$uid),
196 '#GID#' => static::formatGID($gid)
199 return self::STATUS_FAILED;
202 return self::STATUS_PASSED;
211 return "/".COption::GetOptionString(
"main",
"upload_dir",
"upload").
"/tmp/";
231 $url =
$_SERVER[
'HTTPS'] ==
'on' ?
'https://' :
'http://';
233 $url .=
$_SERVER[
'SERVER_PORT'] ?
':'.$_SERVER[
'SERVER_PORT'] :
'';
246 $url .=
"?".mt_rand();
263 if(file_put_contents(
$_SERVER[
'DOCUMENT_ROOT'].$uploadPath, $pText))
273 unlink(
$_SERVER[
'DOCUMENT_ROOT'].$uploadPath);
286 return realpath($_ENV[
"TMP"]);
290 return realpath($_ENV[
"TMPDIR"]);
294 return realpath($_ENV[
"TEMP"]);
307 protected static function getTmpDir($pPhpSettingKey =
"upload_tmp_dir")
309 $result = ini_get($pPhpSettingKey);
312 if (function_exists(
"sys_get_temp_dir"))
322 return preg_replace(
'#[\\\/]+#',
'/',
$result);
340 if(self::isRunOnWin())
341 return self::STATUS_PASSED;
344 return self::STATUS_PASSED;
346 if(ini_get(
"session.save_handler") !=
"files")
347 return self::STATUS_PASSED;
351 return self::STATUS_PASSED;
353 $additionalInfo =
"";
355 $currentUID = self::getCurrentUID();
357 foreach (glob($tmpDir.
"/sess_*", GLOB_NOSORT) as
$fileName)
360 if($currentUID !==
null)
363 if($currentUID != $fileOwner)
365 $additionalInfo = getMessage(
"SECURITY_SITE_CHECKER_COLLECTIVE_SESSION_ADDITIONAL_OWNER",
array(
367 "#FILE_ONWER#" => $fileOwner,
368 "#CURRENT_OWNER#" => $currentUID,
380 $additionalInfo = getMessage(
"SECURITY_SITE_CHECKER_COLLECTIVE_SESSION_ADDITIONAL_SIGN",
array(
383 "#SIGN#" => $sessionSign
394 "SECURITY_SITE_CHECKER_COLLECTIVE_SESSION",
398 return self::STATUS_FAILED;
401 return self::STATUS_PASSED;
410 if (self::isRunOnWin())
411 return self::STATUS_PASSED;
414 return self::STATUS_PASSED;
416 if (ini_get(
"session.save_handler") !=
"files")
417 return self::STATUS_PASSED;
421 return self::STATUS_PASSED;
426 $perms = static::getFilePerm(
$dir);
427 if (($perms & 0x0001) === 0)
428 return self::STATUS_PASSED;
434 "SECURITY_SITE_CHECKER_SESSION_DIR",
436 getMessage(
"SECURITY_SITE_CHECKER_SESSION_DIR_ADDITIONAL",
array(
438 "#PERMS#" => self::formatFilePermissions(static::getFilePerm($tmpDir)),
442 return self::STATUS_FAILED;
450 protected static function getCurrentUID()
452 if(is_callable(
"getmyuid"))
456 elseif(is_callable(
"posix_geteuid"))
458 return posix_geteuid();
471 protected static function getCurrentGID()
473 if(is_callable(
"getmygid"))
477 elseif(is_callable(
"posix_getegid"))
479 return posix_getegid();
493 protected static function formatUID(
$uid)
495 if(is_callable(
"posix_getpwuid"))
498 return sprintf(
'%s(%s)',
$uid[
'name'],
$uid[
'uid']);
510 protected static function formatGID($gid)
512 if(is_callable(
"posix_getgrgid"))
514 $gid = posix_getgrgid($gid);
515 return sprintf(
'%s(%s)', $gid[
'name'], $gid[
'gid']);
521 protected static function formatFilePermissions($perms)
525 if (($perms & 0xC000) == 0xC000)
530 elseif (($perms & 0xA000) == 0xA000)
535 elseif (($perms & 0x8000) == 0x8000)
540 elseif (($perms & 0x6000) == 0x6000)
545 elseif (($perms & 0x4000) == 0x4000)
550 elseif (($perms & 0x2000) == 0x2000)
555 elseif (($perms & 0x1000) == 0x1000)
567 $info .= (($perms & 0x0100) ?
'r' :
'-');
568 $info .= (($perms & 0x0080) ?
'w' :
'-');
569 $info .= (($perms & 0x0040) ?
570 (($perms & 0x0800) ?
's' :
'x' ) :
571 (($perms & 0x0800) ?
'S' :
'-'));
574 $info .= (($perms & 0x0020) ?
'r' :
'-');
575 $info .= (($perms & 0x0010) ?
'w' :
'-');
576 $info .= (($perms & 0x0008) ?
577 (($perms & 0x0400) ?
's' :
'x' ) :
578 (($perms & 0x0400) ?
'S' :
'-'));
581 $info .= (($perms & 0x0004) ?
'r' :
'-');
582 $info .= (($perms & 0x0002) ?
'w' :
'-');
583 $info .= (($perms & 0x0001) ?
584 (($perms & 0x0200) ?
't' :
'x' ) :
585 (($perms & 0x0200) ?
'T' :
'-'));
600 $path = CTempFile::GetAbsoluteRoot();
609 "SECURITY_SITE_CHECKER_BITRIX_TMP_DIR",
611 getMessage(
"SECURITY_SITE_CHECKER_BITRIX_TMP_DIR_ADDITIONAL",
array(
616 return static::STATUS_FAILED;
619 return static::STATUS_PASSED;
static ToASCII($domainName, &$arErrors)
static sGet($url, $follow_redirect=false)
addUnformattedDetailError($baseMessageKey, $critical, $additionalInfo="")
getParam($name, $defaultValue="")
static getCurrentSiteUrl()
static getSessionUniqID()
static getTmpDir($pPhpSettingKey="upload_tmp_dir")
checkPhpUserAndGroup($minUid=self::MIN_UID, $minGid=self::MIN_GID)
isScriptExecutable($pFileName, $pText, $pSearch)
checkUploadScriptExecution()
checkCollectivePhpSession()
checkUploadNegotiationEnabled()
static getTmpDirFromEnv()
static doRequestToLocalhost($pPath)
getSessionGeneralHandlerType()
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
foreach(['Bitrix\\Main'=> '/lib', 'Psr\\Container'=> '/vendor/psr/container/src', 'Psr\\Log'=> '/vendor/psr/log/src', 'Psr\\Http\\Message'=> '/vendor/psr/http-message/src', 'Psr\\Http\\Client'=> '/vendor/psr/http-client/src', 'Http\\Promise'=> '/vendor/php-http/promise/src', 'PHPMailer\\PHPMailer'=> '/vendor/phpmailer/phpmailer/src', 'GeoIp2'=> '/vendor/geoip2/geoip2/src', 'MaxMind\\Db'=> '/vendor/maxmind-db/reader/src/MaxMind/Db', 'PhpParser'=> '/vendor/nikic/php-parser/lib/PhpParser', 'Recurr'=> '/vendor/simshaun/recurr/src/Recurr',] as $namespace=> $namespacePath) $documentRoot
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
randString($pass_len=10, $pass_chars=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)