Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mod. Refactoring. Tasks saving, and loading refactored. Disable and a…
Browse files Browse the repository at this point in the history
…pprove actions implemented. #1
alexandergull committed Nov 15, 2024
1 parent a30b65e commit 52f3ce0
Showing 12 changed files with 605 additions and 145 deletions.
108 changes: 18 additions & 90 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?php

use CleantalkSP\SpbctWP\AdjustToEnvironmentModule\AdjustToEnvironmentSettings;
use CleantalkSP\SpbctWP\API;
use CleantalkSP\SpbctWP\Cron as SpbcCron;
use CleantalkSP\SpbctWP\Escape;
use CleantalkSP\SpbctWP\Helpers\Arr;
use CleantalkSP\SpbctWP\Helpers\IP;
use CleantalkSP\SpbctWP\HTTP\CDNHeadersChecker;
use CleantalkSP\SpbctWP\Scanner\ScanningLog\ScanningLogFacade;
use CleantalkSP\Variables\Post;
use CleantalkSP\Variables\Server;
use CleantalkSP\SpbctWP\API;
use CleantalkSP\SpbctWP\LinkConstructor;
use CleantalkSP\SpbctWP\ListTable;
use CleantalkSP\SpbctWP\Scanner;
use CleantalkSP\SpbctWP\Helpers\IP;
use CleantalkSP\SpbctWP\Helpers\Arr;
use CleantalkSP\SpbctWP\Helpers\CSV;
use CleantalkSP\SpbctWP\Escape;
use CleantalkSP\SpbctWP\Scanner\OSCron\OSCronModel;
use CleantalkSP\SpbctWP\Scanner\OSCron\OSCronView;
use CleantalkSP\SpbctWP\Scanner\ScanningLog\ScanningLogFacade;
use CleantalkSP\SpbctWP\Variables\Cookie;
use CleantalkSP\SpbctWP\Views\Settings;
use CleantalkSP\SpbctWP\VulnerabilityAlarm\VulnerabilityAlarmView;
use CleantalkSP\SpbctWP\Variables\Cookie;
use CleantalkSP\SpbctWP\LinkConstructor;
use CleantalkSP\Variables\Post;
use CleantalkSP\Variables\Server;

// Scanner AJAX actions
require_once(SPBC_PLUGIN_DIR . 'inc/spbc-scanner.php');
@@ -2911,7 +2912,7 @@ function spbc_field_scanner__prepare_data__analysis_log(&$table)
*/
function spbc_scanner_oscron_count_found()
{
return count(spbc_scanner_oscron_get_scanned());
return OSCronView::getCountOfTasksScanned();
}

/**
@@ -2920,18 +2921,7 @@ function spbc_scanner_oscron_count_found()
*/
function spbc_scanner_oscron_get_scanned()
{
$result = get_option('spbc_oscron_result', []);

if (!empty($result)) {
$result = json_decode($result, true);
}

if (is_null($result)) {
$result = [];
}


return $result;
return OSCronModel::getTasksFromStorage();
}

/**
@@ -2940,63 +2930,7 @@ function spbc_scanner_oscron_get_scanned()
*/
function spbc_scanner_oscron_prepare_data(&$table)
{
foreach ($table->rows as $key => $row) {
$table->items[$key] = array(
'uid' => $row['id'],
'cb' => $row['id'],
'id' => $row['id'],
'repeat' => spbc_scanner_oscron_time_to_human_readable($row['repeat']),
'command' => $row['command'],
// 'actions' => $row['actions'],
);
}
}

/**
* Convert cron time to human readable.
* @param $time
* @return string
*/
function spbc_scanner_oscron_time_to_human_readable($time)
{
$cronParts = explode(' ', $time);

if (count($cronParts) !== 5) {
return __('Invalid cron expression', 'security-malware-firewall');
}

list($minute, $hour, $dayOfMonth, $month, $dayOfWeek) = $cronParts;

$humanReadable = __('At ', 'security-malware-firewall');

// Handle minutes
if ($minute === '*') {
$humanReadable .= __('every minute', 'security-malware-firewall');
} else {
$humanReadable .= __('minute', 'security-malware-firewall') . ' ' . $minute;
}

// Handle hours
if ($hour !== '*') {
$humanReadable .= __(' past hour ', 'security-malware-firewall') . $hour;
}

// Handle days of the month
if ($dayOfMonth !== '*') {
$humanReadable .= __(' on day ', 'security-malware-firewall') . $dayOfMonth;
}

// Handle months
if ($month !== '*') {
$humanReadable .= __(' of month ', 'security-malware-firewall') . $month;
}

// Handle days of the week
if ($dayOfWeek !== '*') {
$humanReadable .= __(' on day of the week ', 'security-malware-firewall') . $dayOfWeek;
}

return $humanReadable;
$table = OSCronView::prepareTableData($table);
}

function spbc_field_scanner__prepare_data__files_quarantine(&$table)
@@ -4118,20 +4052,14 @@ function spbc_list_table__get_args_by_type($table_type)
'func_data_prepare' => 'spbc_scanner_oscron_prepare_data',
'if_empty_items' => '<p class="spbc_hint">' . __('Crontab not found.', 'security-malware-firewall') . '</p>',
'columns' => array(
'cb' => array('heading' => '<input type=checkbox>', 'class' => 'check-column', 'width_percent' => 5),
'id' => array('heading' => 'id', 'primary' => true, 'width_percent' => 15),
'repeat' => array('heading' => 'repeat', 'primary' => true, 'width_percent' => 15),
'command' => array('heading' => 'command', 'primary' => true, 'width_percent' => 65),
'line_number' => array('heading' => 'line_number', 'primary' => true, 'width_percent' => 15),
'command' => array('heading' => 'command', 'primary' => true, 'width_percent' => 50),
),
'actions' => array(
'delete' => array('name' => 'Delete',),
'quarantine' => array('name' => 'Quarantine',),
'approve' => array('name' => 'Approve',),
),
'bulk_actions' => array(
'delete' => array('name' => 'Delete',),
'quarantine' => array('name' => 'Quarantine',),
'approve' => array('name' => 'Approve',),
'disable_oscron_task' => array('name' => 'Disable task',),
'approve_oscron_task' => array('name' => 'Approve task',),
),
)
);
2 changes: 1 addition & 1 deletion js/spbc-scanner-plugin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/spbc-scanner-plugin.min.js.map

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions lib/CleantalkSP/Common/Helpers/CSV.php
Original file line number Diff line number Diff line change
@@ -30,6 +30,27 @@ public static function sanitizeFromEmptyLines($buffer)
return $buffer;
}

/**
* Parse Comma-separated values, without formatting to csv
*
* @param $buffer
*
* @return false|string[]
*/
public static function parseCSVLite($buffer)
{
$buffer = explode("\n", $buffer);
$buffer = self::sanitizeFromEmptyLines($buffer);

foreach ($buffer as &$line) {
if ($line !== '') {
$line = substr($line, 6);
}
}

return $buffer;
}

/**
* Parse Comma-separated values
*
25 changes: 25 additions & 0 deletions lib/CleantalkSP/SpbctWP/ListTable.php
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
namespace CleantalkSP\SpbctWP;

use CleantalkSP\SpbctWP\Scanner\Cure;
use CleantalkSP\SpbctWP\Scanner\OSCron\OSCronController;
use CleantalkSP\Variables\Post;

class ListTable
@@ -689,6 +690,12 @@ public static function ajaxRowActionHandler()
case 'copy_file_info':
self::ajaxRowActionHandlerCopyFileInfo();
break;
case 'disable_oscron_task':
self::ajaxRowActionHandlerDisableOSCronTask();
break;
case 'approve_oscron_task':
self::ajaxRowActionHandlerApproveOSCronTask();
break;
default:
wp_send_json(array('temp_html' => '<div class="spbc-popup-msg popup--red">UNKNOWN ACTION</div>'));
}
@@ -697,6 +704,24 @@ public static function ajaxRowActionHandler()
}
}

public static function ajaxRowActionHandlerApproveOSCronTask()
{
$result = OSCronController::approveTask(Post::get('id', null, 'word'));
if ($result) {
wp_send_json_success();
}
wp_send_json_error();
}

public static function ajaxRowActionHandlerDisableOSCronTask()
{
$result = OSCronController::disableTask(Post::get('id', null, 'word'));
if ($result) {
wp_send_json_success();
}
wp_send_json_error();
}

public static function ajaxRowActionHandlerApprove()
{
$out = spbc_scanner_file_approve(true, Post::get('id', null, 'word'));
52 changes: 52 additions & 0 deletions lib/CleantalkSP/SpbctWP/Scanner/OSCron/OSCronController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace CleantalkSP\SpbctWP\Scanner\OSCron;

class OSCronController
{
/**
* @param $uid
* @param $status
* @return bool
* @throws \Exception
*/
private static function updateTask($uid, $status)
{
$line_to_change = OSCronModel::getTaskById($uid);
$line_to_change->setStatus($status);
$result = OSCronModel::updateTaskById($uid, $line_to_change);
if (false === $result) {
return $result;
}
return OSCronModel::rewriteCronTabFile();
}
/**
* @param $uid
* @return bool
* @throws \Exception
*/
public static function approveTask($uid)
{
return static::updateTask($uid, 'approved');
}
/**
* @param $uid
* @return false|int
* @throws \Exception
*/
public static function disableTask($uid)
{
return static::updateTask($uid, 'disabled');
}
/**
* @param $uid
* @return false|int
* @throws \Exception
*/
public static function dangerTask($uid)
{
$line_to_change = OSCronModel::getTaskById($uid);
$line_to_change->setStatus('dangerous');
return OSCronModel::updateTaskById($uid, $line_to_change);
}
}
17 changes: 17 additions & 0 deletions lib/CleantalkSP/SpbctWP/Scanner/OSCron/OSCronGetEnvCron.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace CleantalkSP\SpbctWP\Scanner\OSCron;

class OSCronGetEnvCron
{
private static $read_command = 'crontab -l';

/**
* @return string
* @psalm-suppress ForbiddenCode
*/
public static function get()
{
return (string)@shell_exec(static::$read_command);
}
}
202 changes: 202 additions & 0 deletions lib/CleantalkSP/SpbctWP/Scanner/OSCron/OSCronModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<?php

namespace CleantalkSP\SpbctWP\Scanner\OSCron;

class OSCronModel
{
private static $tasks_storage_name = 'spbc_oscron_tasks';
private static $file_storage_name = 'spbc_oscron_file';
private static $spbc_marker = '# Disabled by Security by CleanTalk #';

/**
* @return string|true
*/
public static function run()
{
try {
$new_cron_file = static::getEnvCrontab();

if (static::loadCrontabFile() === $new_cron_file) {
throw new \Exception(__('No difference found since last check.', 'security-malware-firewall'));
}
static::saveCrontabFile($new_cron_file);
$tasks = static::parseTasks($new_cron_file);
static::saveTasksToStorage($tasks);
} catch (\Exception $error) {
return (string)$error;
}
return true;
}

/**
* @param $cron_file
* @return OSCronTask[]
* @throws \Exception
*/
private static function parseTasks($cron_file)
{
$result = explode("\n", $cron_file);

$result = array_map('trim', $result);

$tasks = array();

$line_number = 0;

foreach ($result as $item) {
$line_number++;
if (empty($item) || strpos($item, '#') === 0) {
continue;
}
$parts = preg_split('/\s+/', $item, 6);
$time_pattern = implode(' ', array_slice($parts, 0, 5));
$command = $parts[5];
$task = new OSCronTask();
$tasks[] = $task->setCommand($command)
->setStatus('found')
->setLineNumber($line_number)
->setRepeatsPattern($time_pattern)
->validate();
}

return $tasks;
}

/**
* @param $tasks
* @return void
*/
public static function saveTasksToStorage($tasks)
{
update_option(static::$tasks_storage_name, $tasks);
}

/**
* @return OSCronTask[]|array
*/
public static function getTasksFromStorage($as_array = true)
{
$tasks = get_option('spbc_oscron_result', []);

if (is_null($tasks) || false === $tasks) {
return array();
}

if ($as_array) {
$result_array = array();
foreach ($tasks as $task) {
$result_array[] = $task->getArray();
}
return $result_array;
}

return $tasks;
}

/**
* @param string $uid
* @return OSCronTask|false
*/
public static function getTaskById($uid)
{
$tasks = static::getTasksFromStorage(false);
foreach ($tasks as $task) {
if ($task->id === $uid) {
return $task;
}
}
return false;
}

/**
* @param string $uid
* @param OSCronTask $new_task
* @return int|false
* @throws \Exception
*/
public static function updateTaskById($uid, $new_task)
{
$new_task->validate();
$tasks = static::getTasksFromStorage(false);
foreach ($tasks as $key => $task) {
if ($task->id === $uid) {
$tasks[$key] = $new_task;
static::saveTasksToStorage($tasks);
return $key;
}
}
return false;
}

/**
* @return bool
* @throws \Exception
*/
public static function rewriteCronTabFile()
{
$tasks = static::getTasksFromStorage(false);
$new_cron_file = static::loadCrontabFile();
foreach ($tasks as $task) {
$the_word = $task->repeats . ' ' . $task->command;
if ($task->status === 'disabled') {
$new_cron_file = str_replace($the_word, static::$spbc_marker . $the_word, $new_cron_file);
}
if ($task->status === 'approved') {
$new_cron_file = str_replace(static::$spbc_marker, '', $new_cron_file);
}
}
static::saveCrontabFile($new_cron_file);
static::saveEnvCronTab($new_cron_file);
return true;
}

/**
* @param $cron_file
* @return void
*/
public static function saveCrontabFile($cron_file)
{
update_option(static::$file_storage_name, @base64_encode($cron_file));
}

/**
* @return string
* @throws \Exception
*/
public static function loadCrontabFile()
{
$result = get_option(static::$file_storage_name);
if ($result) {
$result = @base64_decode($result);
if ($result) {
return $result;
}
}
throw new \Exception(__('Cannot load crontab file from storage', 'security-malware-firewall'));
}

/**
* @return string
* @throws \Exception
*/
private static function getEnvCrontab()
{
$cron_file = OSCronGetEnvCron::get();
//test
// $cron_file = '1 * * * * echo
//
//
//
//5 * * * * bash
//#not a valid string';
if (empty($cron_file)) {
throw new \Exception(__('No crontab file found in the server environment.', 'security-malware-firewall'));
}
return $cron_file;
}

private static function saveEnvCronTab($changed_file_content)
{
OSCronSetEnvCron::set($changed_file_content);
}
}
20 changes: 20 additions & 0 deletions lib/CleantalkSP/SpbctWP/Scanner/OSCron/OSCronSetEnvCron.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace CleantalkSP\SpbctWP\Scanner\OSCron;

class OSCronSetEnvCron
{
private static $write_command_template = 'echo "%s"| crontab -';

/**
* @return string
* @psalm-suppress ForbiddenCode
*/
public static function set($command)
{
//probably need to sanitize $command
//$command = escapeshellarg($command);
$command = sprintf(static::$write_command_template, $command);
return (string)@shell_exec($command);
}
}
128 changes: 128 additions & 0 deletions lib/CleantalkSP/SpbctWP/Scanner/OSCron/OSCronTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

namespace CleantalkSP\SpbctWP\Scanner\OSCron;

class OSCronTask
{
/**
* @var string
*/
public $id;
/**
* @var string
*/
public $status;
/**
* @var int
*/
public $repeats;
/**
* @var int
*/
public $command;
/**
* @var int
*/
public $line_number;

private $statuses_list = array(
'found',
'approved',
'disabled',
'dangerous',
);

public function __construct()
{
$this->setID();
}

private function setID()
{
$this->id = uniqid();
}

/**
* @param string $status
* @return OSCronTask
* @throws \Exception
*/
public function setStatus($status)
{
if (!is_string($status) || !in_array($status, $this->statuses_list)) {
throw new \Exception(__CLASS__ . '::' . __FUNCTION__ . 'invalid arg');
}

$this->status = $status;
return $this;
}

/**
* @param string $command
* @return OSCronTask
* @throws \Exception
*/
public function setCommand($command)
{
if (!is_string($command)) {
throw new \Exception(__CLASS__ . '::' . __FUNCTION__ . 'invalid arg');
}
$this->command = $command;
return $this;
}

/**
* @param string $repeats
* @return OSCronTask
* @throws \Exception
*/
public function setRepeatsPattern($repeats)
{
if (!is_string($repeats)) {
throw new \Exception(__CLASS__ . '::' . __FUNCTION__ . 'invalid arg');
}
$this->repeats = $repeats;
return $this;
}

/**
* @param int $line_number
* @return OSCronTask
* @throws \Exception
*/
public function setLineNumber($line_number)
{
if (!is_int($line_number)) {
throw new \Exception(__CLASS__ . '::' . __FUNCTION__ . 'invalid arg');
}
$this->line_number = $line_number;
return $this;
}

/**
* @return OSCronTask
* @throws \Exception
*/
public function validate()
{
foreach (get_object_vars($this) as $property => $value) {
if (is_null($value)) {
throw new \Exception(__CLASS__ . '::' . __FUNCTION__ . ' - ' . $property . ' is not set');
}
}
return $this;
}

/**
* @return array
*/
public function getArray()
{
$result = array();
foreach (get_object_vars($this) as $property => $value) {
$result[$property] = $value;
}
unset($result['statuses_list']);
return $result;
}
}
87 changes: 87 additions & 0 deletions lib/CleantalkSP/SpbctWP/Scanner/OSCron/OSCronView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace CleantalkSP\SpbctWP\Scanner\OSCron;

class OSCronView
{
/**
* @return int
*/
public static function getCountOfTasksScanned()
{
return count(OSCronModel::getTasksFromStorage());
}

/**
* @param object $table
* @return object
*/
public static function prepareTableData($table)
{
foreach ($table->rows as $key => $row) {
$actions = $row['actions'];
if ($row['status'] === 'approved') {
unset($actions['approve_oscron_task']);
}
if ($row['status'] === 'disabled') {
unset($actions['disable_oscron_task']);
}
$table->items[$key] = array(
'uid' => $row['id'],
'cb' => $row['id'],
'id' => $row['id'],
'repeat' => static::timePatternToHumanReadable($row['repeats']),
'command' => $row['command'],
'actions' => $actions,
);
}
return $table;
}

/**
* Convert cron time to human readable.
* @param $time
* @return string
*/
private static function timePatternToHumanReadable($time)
{
$cronParts = explode(' ', $time);

if (count($cronParts) !== 5) {
return __('Invalid cron expression', 'security-malware-firewall');
}

list($minute, $hour, $dayOfMonth, $month, $dayOfWeek) = $cronParts;

$humanReadable = __('At ', 'security-malware-firewall');

// Handle minutes
if ($minute === '*') {
$humanReadable .= __('every minute', 'security-malware-firewall');
} else {
$humanReadable .= __('minute', 'security-malware-firewall') . ' ' . $minute;
}

// Handle hours
if ($hour !== '*') {
$humanReadable .= __(' past hour ', 'security-malware-firewall') . $hour;
}

// Handle days of the month
if ($dayOfMonth !== '*') {
$humanReadable .= __(' on day ', 'security-malware-firewall') . $dayOfMonth;
}

// Handle months
if ($month !== '*') {
$humanReadable .= __(' of month ', 'security-malware-firewall') . $month;
}

// Handle days of the week
if ($dayOfWeek !== '*') {
$humanReadable .= __(' on day of the week ', 'security-malware-firewall') . $dayOfWeek;
}

return $humanReadable;
}
}
86 changes: 33 additions & 53 deletions lib/CleantalkSP/SpbctWP/Scanner/ScannerQueue.php
Original file line number Diff line number Diff line change
@@ -2,58 +2,59 @@

namespace CleantalkSP\SpbctWP\Scanner;

use CleantalkSP\SpbctWP\API;
use CleantalkSP\SpbctWP\Cron;
use CleantalkSP\SpbctWP\DB;
use CleantalkSP\SpbctWP\Helpers\CSV;
use CleantalkSP\SpbctWP\Helpers\Helper as QueueHelper;
use CleantalkSP\SpbctWP\Helpers\HTTP;
use CleantalkSP\SpbctWP\RemoteCalls;
use CleantalkSP\SpbctWP\Scanner\OSCron\OSCronModel;
use CleantalkSP\SpbctWP\Scanner\ScannerInteractivity\ScannerInteractivityData;
use CleantalkSP\SpbctWP\Scanner\ScanningLog\ScanningLogFacade;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\ScannerFileStatuses;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\ScanningStagesStorage;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\ScheduleSendHeuristicSuspiciousFiles;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\FileSystemAnalysis;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\FrontendAnalysis;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\GetApprovedHashes;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\GetCmsHashes;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\GetDeniedHashes;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\GetModulesHashes;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\HeuristicAnalysis;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\OSCronAnalysis;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\OutboundLinks;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\ScheduleSendHeuristicSuspiciousFiles;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\SignatureAnalysis;
use CleantalkSP\SpbctWP\Scanner\Stages\CureStage;
use CleantalkSP\SpbctWP\Scanner\Stages\SendResultsStage;
use CleantalkSP\SpbctWP\Scanner\Stages\SignatureAnalysis\SignatureAnalysisFacade;
use CleantalkSP\SpbctWP\Scanner\UnsafePermissionsModule\UnsafePermissionsHandler;
use CleantalkSP\SpbctWP\Scanner\ScannerInteractivity\ScannerInteractivityData;
use CleantalkSP\Variables\Request;
use CleantalkSP\SpbctWP\DB;
use CleantalkSP\SpbctWP\Cron;
use CleantalkSP\SpbctWP\Transaction;
use CleantalkSP\SpbctWP\State;
use CleantalkSP\SpbctWP\API;
use CleantalkSP\SpbctWP\Helpers\HTTP;
use CleantalkSP\SpbctWP\Helpers\Helper as QueueHelper;
use CleantalkSP\SpbctWP\Helpers\CSV;
use CleantalkSP\SpbctWP\RemoteCalls;
use CleantalkSP\SpbctWP\Scanner\ScanningStagesModule\Stages\OSCronAnalysis;
use CleantalkSP\SpbctWP\Scanner\Stages\SendResultsStage;
use CleantalkSP\SpbctWP\Scanner\Stages\CureStage;
use CleantalkSP\SpbctWP\Transaction;
use CleantalkSP\Variables\Request;

class ScannerQueue
{
/**
* @var string[] List of scan stages
*/
public static $stages = array(
'get_cms_hashes',
'get_modules_hashes',
'clean_results',
'file_system_analysis',
// 'get_cms_hashes',
// 'get_modules_hashes',
// 'clean_results',
// 'file_system_analysis',
'os_cron_analysis',
'get_denied_hashes',
'get_approved_hashes',
'signature_analysis',
'heuristic_analysis',
'schedule_send_heuristic_suspicious_files',
'auto_cure_backup',
'auto_cure',
'outbound_links',
'frontend_analysis',
'important_files_listing',
'send_results',
// 'get_denied_hashes',
// 'get_approved_hashes',
// 'signature_analysis',
// 'heuristic_analysis',
// 'schedule_send_heuristic_suspicious_files',
// 'auto_cure_backup',
// 'auto_cure',
// 'outbound_links',
// 'frontend_analysis',
// 'important_files_listing',
// 'send_results',
);

/**
@@ -1031,39 +1032,18 @@ public function os_cron_analysis() // phpcs:ignore PSR1.Methods.CamelCapsMethodN
$scanning_stages_storage->converter->loadCollection();
$stage_data_obj = $scanning_stages_storage->getStage(OSCronAnalysis::class);

/* */
$result = shell_exec('crontab -l');
$result = OSCronModel::run();

if (!$result) {
if (true !== $result) {
ScanningLogFacade::writeToLog(
'<b>' . $stage_data_obj::getTitle() . '</b> ' . __('No crontab found.', 'security-malware-firewall')
'<b>' . $stage_data_obj::getTitle() . '</b> ' . $result
);

return array(
'end' => 1,
);
}

$result = explode("\n", $result);
$result = array_map('trim', $result);
$result = array_filter($result, function ($item) {
return !empty($item);
});

$result = array_map(function ($item) {
$parts = preg_split('/\s+/', $item, 6);
$timePattern = implode(' ', array_slice($parts, 0, 5));
$command = $parts[5];
return [
'id' => uniqid(),
'status' => 'found',
'repeat' => $timePattern,
'command' => $command,
];
}, $result);

update_option('spbc_oscron_result', json_encode($result));

ScanningLogFacade::writeToLog(
'<b>' . $stage_data_obj::getTitle() . '</b> ' . $stage_data_obj->getDescription()
);

0 comments on commit 52f3ce0

Please sign in to comment.