* @license PHP License * @package WB * @subpackage service */ WBClass::load('WBService' , 'WBString' ); /** * Detect Junk Requests * * See if request path looks like junk and change it to invalid URL * * Usually there are lots of requests just to check for any volnerability * Those request are useless and polute logs and database, therefore this services tries * to detect those request in an early stage and replaces the request path to something harmless * * @version 0.2.0 * @package WB * @subpackage service */ class WBService_Junk extends WBStdClass { /** * Logger * @var WBLog */ private $log; /** * Constructor * */ public function __construct($parameter = array()) { $this->log = WBLog::start(__CLASS__); } /** * Clean Path * * @param array */ public function cleanPath(&$path) { $log = array( 'status' => 'check', 'path' => implode('/', $path) ); $junkPath = array('junk_path'); if(!$this->checkChars($path)) { $log['status'] = 'chars'; $this->log->warn($log); $path = $junkPath; return; } if(!$this->checkUsualSuspects($path)) { $log['status'] = 'usualSuspect'; $this->log->warn($log); $path = $junkPath; return; } if(!$this->checkExtension($path)) { $log['status'] = 'extension'; $this->log->warn($log); $path = $junkPath; return; } $log['status'] = 'passed'; $this->log->debug($log); } /** * Check Path for Well Known * * @param array */ private function checkChars($path) { if (empty($path[0])) { return true; } $bad = array( '{', '\\' ); if (in_array($path[0][0], $bad)) { return false; } return true; } /** * Check Path for Well Known * * @param array */ private function checkUsualSuspects($path) { $bad = array( '..', '.ds_store', '.env', '.ftpconfig', '.git', '.svn', '.vscode', 'alfa_data', 'cgi-bin', 'ftp-sync.json', 'gponform', 'jenkins', 'mailman', 'mysql', 'phpmyadmin', 'pma', 'sftp.json', 'sftp-config.json', 'script', 'tmp', 'wp-admin', 'wp-includes', 'wp-content', '_ignition' ); // check if first part of path is bad if (in_array(strtolower($path[0]), $bad)) { return false; } // cgi-bin is bad everywhere if (in_array('cgi-bin', $path)) { return false; } return true; } /** * Check if File-Name-Extension is OK * * @param array */ private function checkExtension($path) { $last = end($path); if (!strstr($last, '.')) { return true; } $ext = strtolower(trim(array_pop(explode('.', $last)))); // list is bad extensions $bad = array( 'asp', 'cfg', 'cfm', 'cgi', 'env', 'html', 'jsp', 'local', 'ows', 'php', 'settings', 'shtml', 'tpl', 'tmpl' ); if (in_array($ext, $bad)) { return false; } return true; } }