File manager - Edit - /home/decorea/www/wp-includes/certificates/XML/mu-plugins.tar
Back
wp-toolkit/Waf/FirewallEngine.php 0000644 00000010766 15231023503 0013002 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Waf; use Patchstack\Processor; use Webpros\WptkWpPlugin\WpToolkit\Common\WordPressHelper; use Webpros\WptkWpPlugin\WpToolkit\Waf\Extensions\HttpRequestExtension; use Webpros\WptkWpPlugin\WpToolkit\Waf\RulesConverter\PatchstackRuleConverter; final class FirewallEngine { const ENGINE_PATCHSTACK = 'fw-engine'; const OPTION_ACTIVE_RULES = 'wp-toolkit_waf_active_rules'; const OPTION_RULES = 'wp-toolkit_waf_rules'; /** * @param string[] $vulnerabilityIds * * @return void */ public static function deleteRules($vulnerabilityIds) { $groupedRules = (array)get_option(self::OPTION_RULES, []); foreach ($vulnerabilityIds as $vulnerabilityId) { unset($groupedRules[$vulnerabilityId]); } self::saveRules($groupedRules); } /** * @return bool */ public static function launch($mustUsePluginCall = false) { $firewallRules = self::getFirewallRules(); if (\count($firewallRules) === 0) { return true; } $whitelistRules = []; $settings = [ 'mustUsePluginCall' => $mustUsePluginCall, ]; $firewall = new Processor( new HttpRequestExtension(), $firewallRules, $whitelistRules, $settings ); return $firewall->launch(); } /** * @return string[] */ public static function listActiveRules() { return \array_keys(self::getFirewallRules()); } /** * @param array $rules * * @return void */ public static function setRules($rules) { $groupedRules = self::groupByVulnerabilityId($rules); self::saveRules($groupedRules); } /** * @param array $rules * * @return void */ public static function upsertRules($rules) { $currentRules = (array)get_option(self::OPTION_RULES, []); $groupedRules = self::groupByVulnerabilityId($rules); foreach ($groupedRules as $vulnerabilityId => $vulnerabilityRules) { $currentRules[$vulnerabilityId] = $vulnerabilityRules; } self::saveRules($currentRules); } /** * @param array $rule * * @return array */ private static function convertRule($rule) { switch (self::getPreferredEngine()) { case self::ENGINE_PATCHSTACK: return PatchstackRuleConverter::convert($rule); default: return $rule; } } /** * @param array $groupedRules * * @return array */ private static function filterActiveRules($groupedRules) { $activeRules = []; foreach ($groupedRules as $vulnerabilityId => $rules) { $filteredRules = self::filterRulesByPreferredEngine($rules); if (\count($filteredRules) > 0) { // We use first suitable rule for preferred engine $rule = \array_shift($filteredRules); $activeRules[$vulnerabilityId] = self::convertRule($rule); } } return $activeRules; } /** * @param array $rules * * @return array */ private static function filterRulesByPreferredEngine($rules) { return \array_filter( $rules, static function ($r) { return $r['engine'] === self::getPreferredEngine(); } ); } /** * @return array */ private static function getFirewallRules() { return (array)get_option(self::OPTION_ACTIVE_RULES, []); } /** * @return string */ private static function getPreferredEngine() { return self::ENGINE_PATCHSTACK; } /** * @param array $rules * * @return array */ private static function groupByVulnerabilityId($rules) { return \array_reduce( $rules, static function ($c, $r) { $c[$r['vulnerabilityId']][] = $r; return $c; }, [] ); } /** * @param array $groupedRules * * @return void */ private static function saveRules($groupedRules) { WordPressHelper::upsert_option(self::OPTION_RULES, $groupedRules); WordPressHelper::upsert_option(self::OPTION_ACTIVE_RULES, self::filterActiveRules($groupedRules)); } } wp-toolkit/Waf/waf-bootstrap.php 0000644 00000001562 15231023503 0012671 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. /* Do not access this file directly */ if (!defined('ABSPATH')) { header('Content-Type: text/plain'); die(<<<MSG __________ < Go away > ---------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || MSG ); } use Webpros\WptkWpPlugin\WpToolkit\Common\CliHelper; use Webpros\WptkWpPlugin\WpToolkit\Waf\Cli\WafCommand; use Webpros\WptkWpPlugin\WpToolkit\Waf\FirewallEngine; if (CliHelper::is_cli()) { if (\class_exists(\WP_CLI::class, false)) { WP_CLI::add_command('wp-toolkit waf', WafCommand::class); } return; } if (!\get_option('wp-toolkit_waf_status', false)) { return; } FirewallEngine::launch(true); define('PS_FW_MU_RAN', true); add_action('init', [FirewallEngine::class, 'launch']); wp-toolkit/Waf/RulesConverter/RuleConverterInterface.php 0000644 00000000411 15231023503 0017473 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Waf\RulesConverter; interface RuleConverterInterface { /** * @return array */ public static function convert(array $rule); } wp-toolkit/Waf/RulesConverter/PatchstackRuleConverter.php 0000644 00000000654 15231023503 0017671 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Waf\RulesConverter; final class PatchstackRuleConverter implements RuleConverterInterface { public static function convert(array $rule) { return [ 'id' => \crc32($rule['vulnerabilityId']), 'rules' => $rule['rules'], 'type' => 'BLOCK', ]; } } wp-toolkit/Waf/Cli/WafCommand.php 0000644 00000004437 15231023503 0012630 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Waf\Cli; use Webpros\WptkWpPlugin\WpToolkit\Common\SwitchableCommandTrait; use Webpros\WptkWpPlugin\WpToolkit\Waf\FirewallEngine; use Webpros\WptkWpPlugin\WpToolkit\Waf\Validator\RuleCollectionValidator; use WP_CLI; use WP_CLI_Command; /** * Common structure of incoming data: * array<int, array{vulnerabilityId: string, engine: string, provider: string, rules: array}> */ class WafCommand extends WP_CLI_Command { use SwitchableCommandTrait; /** * @param array $args * @param array $assoc_args * * @return void * * @throws WP_CLI\ExitException */ public function delete($args, $assoc_args) { $value = WP_CLI::get_value_from_arg_or_stdin($args, 0); $vulnerabilityIds = WP_CLI::read_value($value, $assoc_args); if (!\is_array($vulnerabilityIds)) { WP_CLI::error('Passed vulnerability ids has an incompatible format'); } FirewallEngine::deleteRules($vulnerabilityIds); } /** * @subcommand list * * @param array $args * @param array $assoc_args * * @return void */ public function list_($args, $assoc_args) { WP_CLI::print_value(FirewallEngine::listActiveRules(), $assoc_args); } /** * @param array $args * @param array $assoc_args * * @return void * @throws WP_CLI\ExitException */ public function set($args, $assoc_args) { $value = WP_CLI::get_value_from_arg_or_stdin($args, 0); $rules = WP_CLI::read_value($value, $assoc_args); RuleCollectionValidator::validate($rules); FirewallEngine::setRules($rules); } /** * @param array $args * @param array $assoc_args * * @return void * @throws WP_CLI\ExitException */ public function upsert($args, $assoc_args) { $value = WP_CLI::get_value_from_arg_or_stdin($args, 0); $rules = WP_CLI::read_value($value, $assoc_args); RuleCollectionValidator::validate($rules); FirewallEngine::upsertRules($rules); } /** * @return string */ protected function getSwitchOption() { return 'wp-toolkit_waf_status'; } } wp-toolkit/Waf/Extensions/HttpRequestExtension.php 0000644 00000003044 15231023503 0016422 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Waf\Extensions; use Patchstack\Extensions\ExtensionInterface; class HttpRequestExtension implements ExtensionInterface { /** * @param int $ruleId * @param string $bodyData * @param string $blockType * @return void */ public function logRequest($ruleId, $bodyData, $blockType) { } /** * @return false */ public function canBypass($isMuCall) { return false; } /** * @param int $minutes * @param int $blockTime * @param int $attempts * @return false */ public function isBlocked($minutes, $blockTime, $attempts) { return false; } /** * @param int $ruleId * @return never */ public function forceExit($ruleId) { exit; } /** * @return string */ public function getIpAddress() { return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; } /** * @return string */ public function getHostName() { return isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; } /** * @param array $whitelistRules * @param array $request * @return false */ public function isWhitelisted($whitelistRules, $request) { return false; } /** * @return bool */ public function isFileUploadRequest() { return isset($_FILES) && count($_FILES) > 0; } } wp-toolkit/Waf/Validator/RuleValidator.php 0000644 00000003457 15231023503 0014610 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Waf\Validator; use WP_CLI; final class RuleValidator { const STRING_FIELDS = [ 'vulnerabilityId', 'engine', 'provider', ]; /** * @param array $rule * * @return void * @throws \WP_CLI\ExitException */ public static function validate($rule) { if (\is_array($rule) === false) { WP_CLI::error('Rule is not an array'); } foreach (self::STRING_FIELDS as $field) { self::validateStringField($field, $rule); } self::validateArrayField('rules', $rule); } /** * @param string $field * @param array $rule * * @return void * @throws \WP_CLI\ExitException */ private static function validateArrayField($field, $rule) { $value = isset($rule[$field]) ? $rule[$field] : null; if ($value === null) { WP_CLI::error($field . ' is not set'); } if (\is_array($value) === false) { WP_CLI::error($field . ' is not an array'); } if (empty($value)) { WP_CLI::error($field . ' is empty'); } } /** * @param string $field * @param array $rule * * @return void * @throws \WP_CLI\ExitException */ private static function validateStringField($field, $rule) { $value = isset($rule[$field]) ? $rule[$field] : null; if ($value === null) { WP_CLI::error($field . ' is not set'); } if (\is_string($value) === false) { WP_CLI::error($field . ' is not a string'); } if (empty($value)) { WP_CLI::error($field . ' is empty'); } } } wp-toolkit/Waf/Validator/RuleCollectionValidator.php 0000644 00000001045 15231023503 0016613 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Waf\Validator; use WP_CLI; final class RuleCollectionValidator { /** * @param array $rules * * @return void * @throws \WP_CLI\ExitException */ public static function validate($rules) { if (\is_array($rules) === false) { WP_CLI::error('Rules is not an array'); } foreach ($rules as $rule) { RuleValidator::validate($rule); } } } wp-toolkit/Common/WordPressHelper.php 0000644 00000000504 15231023503 0013677 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Common; class WordPressHelper { public static function upsert_option($option, $value) { if (!add_option($option, $value)) { update_option($option, $value); } } } wp-toolkit/Common/SwitchableCommandTrait.php 0000644 00000002151 15231023503 0015177 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Common; use WP_CLI; trait SwitchableCommandTrait { /** * @return string */ abstract protected function getSwitchOption(); /** * @subcommand enable * @return void */ public function enable() { WordPressHelper::upsert_option($this->getSwitchOption(), true); } /** * @subcommand disable * @return void */ public function disable() { WordPressHelper::upsert_option($this->getSwitchOption(), false); } /** * @subcommand status * @return void */ public function status() { $status = get_option($this->getSwitchOption(), false); WP_CLI::print_value((int)$status); } private function isEnabled() { return (bool) get_option($this->getSwitchOption(), false); } private function ensureCommandEnabled() { if (!$this->isEnabled()) { WP_CLI::error(sprintf("Command `%s` isn't enabled", get_class($this))); } } } wp-toolkit/Common/CliHelper.php 0000644 00000000374 15231023503 0012463 0 ustar 00 <?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace Webpros\WptkWpPlugin\WpToolkit\Common; class CliHelper { public static function is_cli() { return php_sapi_name() === 'cli'; } } wp-toolkit/vendor/autoload.php 0000644 00000001403 15231023503 0012463 0 ustar 00 <?php // autoload.php @generated by Composer if (PHP_VERSION_ID < 50600) { if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; if (!ini_get('display_errors')) { if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { fwrite(STDERR, $err); } elseif (!headers_sent()) { echo $err; } } trigger_error( $err, E_USER_ERROR ); } require_once __DIR__ . '/composer/autoload_real.php'; return ComposerAutoloaderInit1bb2fd870bbd3a762bb067ebd1a880d9::getLoader(); wp-toolkit/vendor/patchstack/engine-php/.gitignore 0000644 00000001216 15231023503 0016313 0 ustar 00 # These are some examples of commonly ignored file patterns. # You should customize this list as applicable to your project. # Learn more about .gitignore: # https://www.atlassian.com/git/tutorials/saving-changes/gitignore # PHP artifact files vendor/ # Node artifact files node_modules/ dist/ # Compiled Java class files *.class # Compiled Python bytecode *.py[cod] # Log files *.log # Package files *.jar # Maven target/ dist/ # JetBrains IDE .idea/ # Unit test reports TEST*.xml # Generated by MacOS .DS_Store # Generated by Windows Thumbs.db # Applications *.app *.exe *.war # Large media files *.mp4 *.tiff *.avi *.flv *.mov *.wmv wp-toolkit/vendor/patchstack/engine-php/.gitattributes 0000644 00000000024 15231023503 0017212 0 ustar 00 /tests export-ignore wp-toolkit/vendor/patchstack/engine-php/phpcs.xml 0000644 00000001103 15231023503 0016155 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <ruleset name="Patchstack CS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Patchstack"> <arg name="colors"/> <arg name="extensions" value="php"/> <file>./src</file> <file>./tests</file> <exclude-pattern>*/vendor/*</exclude-pattern> <rule ref="PSR12"> <exclude name="Generic.Files.LineLength.TooLong" /> <exclude name="Generic.Files.LowercasedFilename.NotFound" /> <exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" /> </rule> </ruleset>