1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-06 03:50:04 +02:00

TALOS-2023-1900

CVE-2023-49599
This commit is contained in:
Daniel Neto 2023-12-18 13:47:25 -03:00
parent aca09187c6
commit 0827a0f6be
3 changed files with 83 additions and 67 deletions

View file

@ -356,68 +356,58 @@ class AVideoConf extends ObjectYPT{
$this->autoplay = ($autoplay == 'true' || $autoplay == '1') ? 1 : 0; $this->autoplay = ($autoplay == 'true' || $autoplay == '1') ? 1 : 0;
} }
// end version 2.7 static function updateConfigFile($additions, $replacements, $newVersion) {
global $global;
public static function rewriteConfigFile() $filePath = "{$global['systemRootPath']}videos/configuration.php"; // Hardcoded file path
{
global $global, $mysqlHost, $mysqlUser, $mysqlPass, $mysqlDatabase; // Check if the file exists
if (empty($global['salt'])) { if (!file_exists($filePath)) {
$global['salt'] = uniqid(); return false;
} }
if (empty($global['disableTimeFix'])) {
$global['disableTimeFix'] = 0; // Read the file into an array
$lines = file($filePath);
// Check if the configuration version is already the new version
foreach ($lines as $line) {
if (preg_match('/\$global\[\'configurationVersion\'\] = ([0-9]+(?:\.[0-9]+)?);/', $line, $matches)) {
if (isset($matches[1]) && (float)$matches[1] === (float)$newVersion) {
// Version is already the new version, no need to modify the file
return false;
}
break; // Break out of the loop once the version line is found
}
} }
if (empty($global['logfile'])) {
$global['logfile'] = $global['systemRootPath'] . 'videos/avideo.log'; // Create a backup of the file
copy($filePath, "{$global['systemRootPath']}videos/configuration_bkp_".date('YmdHis').".php");
// Process each line for replacements
foreach ($lines as &$line) {
foreach ($replacements as $pattern => $replacement) {
if (preg_match($pattern, $line)) {
$line = preg_replace($pattern, $replacement, $line);
}
}
if(preg_match('/\$global\[\'configurationVersion\'\] = [0-9]+(\.[0-9]+)?;/', $line)){
$line = "\$global['configurationVersion'] = {$newVersion};".PHP_EOL;
}
} }
$content = "<?php
\$global['configurationVersion'] = 3.1; // Process each line for additions
\$global['disableAdvancedConfigurations'] = {$global['disableAdvancedConfigurations']}; foreach ($additions as $pattern => $addition) {
\$global['videoStorageLimitMinutes'] = {$global['videoStorageLimitMinutes']}; foreach ($lines as $index => &$line) {
\$global['disableTimeFix'] = {$global['disableTimeFix']}; if (preg_match($pattern, $line)) {
\$global['logfile'] = '{$global['logfile']}'; array_splice($lines, $index + 1, 0, $addition . "\n");
if(!empty(\$_SERVER['SERVER_NAME']) && \$_SERVER['SERVER_NAME']!=='localhost' && !filter_var(\$_SERVER['SERVER_NAME'], FILTER_VALIDATE_IP)) { break; // Assuming only one addition per pattern
// get the subdirectory, if exists }
\$file = str_replace(\"\\\\\", \"/\", __FILE__); }
\$subDir = str_replace(array(\$_SERVER[\"DOCUMENT_ROOT\"], 'videos/configuration.php'), array('',''), \$file); }
\$global['webSiteRootURL'] = \"http\".(!empty(\$_SERVER['HTTPS'])?\"s\":\"\").\"://\".\$_SERVER['SERVER_NAME'].\$subDir;
}else{ // Write the array back to the file
\$global['webSiteRootURL'] = '{$global['webSiteRootURL']}'; return file_put_contents($filePath, implode('', $lines));;
}
\$global['systemRootPath'] = '{$global['systemRootPath']}';
\$global['salt'] = '{$global['salt']}';
\$global['enableDDOSprotection'] = {$global['enableDDOSprotection']};
\$global['ddosMaxConnections'] = {$global['ddosMaxConnections']};
\$global['ddosSecondTimeout'] = {$global['ddosSecondTimeout']};
\$global['strictDDOSprotection'] = {$global['strictDDOSprotection']};
\$global['noDebug'] = 0;
\$global['webSiteRootPath'] = '';
if(empty(\$global['webSiteRootPath'])){
preg_match('/https?:\/\/[^\/]+(.*)/i', \$global['webSiteRootURL'], \$matches);
if(!empty(\$matches[1])){
\$global['webSiteRootPath'] = \$matches[1];
}
}
if(empty(\$global['webSiteRootPath'])){
die('Please configure your webSiteRootPath');
}
\$mysqlHost = '{$mysqlHost}';
\$mysqlUser = '{$mysqlUser}';
\$mysqlPass = '{$mysqlPass}';
\$mysqlDatabase = '{$mysqlDatabase}';
/**
* Do NOT change from here
*/
require_once \$global['systemRootPath'].'objects/include_config.php';
";
$fp = fopen($global['systemRootPath'] . "videos/configuration.php", "wb");
fwrite($fp, $content);
fclose($fp);
} }
public function getTheme() public function getTheme()
{ {

View file

@ -5701,7 +5701,6 @@ function encrypt_decrypt($string, $action)
return false; return false;
} }
$encrypt_method = "AES-256-CBC"; $encrypt_method = "AES-256-CBC";
$secret_key = 'This is my secret key';
$secret_iv = $global['systemRootPath']; $secret_iv = $global['systemRootPath'];
while (strlen($secret_iv) < 16) { while (strlen($secret_iv) < 16) {
$secret_iv .= $global['systemRootPath']; $secret_iv .= $global['systemRootPath'];
@ -5709,8 +5708,9 @@ function encrypt_decrypt($string, $action)
if (empty($secret_iv)) { if (empty($secret_iv)) {
$secret_iv = '1234567890abcdef'; $secret_iv = '1234567890abcdef';
} }
$salt = empty($global['saltV2'])?$global['salt']:$global['saltV2'];
// hash // hash
$key = hash('sha256', $global['salt']); $key = hash('sha256', $salt);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $secret_iv), 0, 16); $iv = substr(hash('sha256', $secret_iv), 0, 16);
@ -11976,3 +11976,22 @@ function getValueOrBlank($array, $default=''){
} }
return $text; return $text;
} }
/*
secure salt in PHP using standard characters and numbers.
This code will generate a 10 to 32-character string
*/
function _uniqid() {
// Generate 16 bytes of random data
$randomBytes = random_bytes(16);
// Convert the binary data to a hexadecimal string
$hex = bin2hex($randomBytes);
// If you want a variable length output, you can truncate the MD5 hash
// For example, to get a random length between 10 and 32 characters:
$randomLength = rand(10, 32);
$randomString = substr($hex, 0, $randomLength);
return $randomString;
}

View file

@ -12,7 +12,7 @@ if (!empty($doNotIncludeConfig)) {
return false; return false;
} }
if(!isset($global['skippPlugins'])){ if (!isset($global['skippPlugins'])) {
$global['skippPlugins'] = array(); $global['skippPlugins'] = array();
} }
/* /*
@ -47,12 +47,13 @@ if (!empty($global['stopBotsList']) && is_array($global['stopBotsList'])) {
$global['avideoStartMicrotime'] = microtime(true); $global['avideoStartMicrotime'] = microtime(true);
function includeConfigLog($line, $desc=''){ function includeConfigLog($line, $desc = '')
if(empty($_REQUEST['debug'])){ {
if (empty($_REQUEST['debug'])) {
return false; return false;
} }
global $global, $_includeConfigLogID, $_includeConfigLogLastCheck; global $global, $_includeConfigLogID, $_includeConfigLogLastCheck;
if(!isset($_includeConfigLogID)){ if (!isset($_includeConfigLogID)) {
$_includeConfigLogID = date('H:i:s'); $_includeConfigLogID = date('H:i:s');
} }
$_includeConfigLogLastCheck = microtime(true); $_includeConfigLogLastCheck = microtime(true);
@ -123,8 +124,14 @@ includeConfigLog(__LINE__);
require_once $global['systemRootPath'] . 'objects/images.php'; require_once $global['systemRootPath'] . 'objects/images.php';
includeConfigLog(__LINE__); includeConfigLog(__LINE__);
// for update config from old versions 2020-05-11 // for update config from old versions 2020-05-11
if (empty($global['webSiteRootPath']) || $global['configurationVersion'] < 3.1) { if ($global['configurationVersion'] < 4.0 && empty($global['saltV2'])) {
Configuration::rewriteConfigFile(); $additions = [
'/\$global\[\'salt\'\].*/' => "\$global['saltV2'] = '"._uniqid()."';", // Add this line below the line that matches the pattern
];
$replacements = [];
Configuration::updateConfigFile($additions, $replacements, 4.0);
} }
includeConfigLog(__LINE__); includeConfigLog(__LINE__);
@ -261,4 +268,4 @@ if (!empty($_GET['type'])) {
$metaDescription = " {$_GET['showOnly']}"; $metaDescription = " {$_GET['showOnly']}";
} }
includeConfigLog(__LINE__); includeConfigLog(__LINE__);