Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bfp whitelists.ag #465

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
137b58d
Mod. Bruteforce protection. BFP module now can use FW whitelists.
alexandergull Sep 24, 2024
0a30a8e
Merge branch 'dev' of https://github.com/CleanTalk/security-malware-f…
AntonV1211 Jan 20, 2025
dea9c59
Fix. OSCron. Skip task parsing on regexp empty result.
alexandergull Feb 23, 2025
8a874e0
Version 2.152.99-fix
AntonV1211 Feb 24, 2025
7d53430
Merge branch 'fix' of https://github.com/CleanTalk/security-malware-f…
AntonV1211 Feb 24, 2025
f05f002
Mod. Scanner. Getting approved hashes. Memory usage reduced.
alexandergull Feb 26, 2025
2284787
Merge remote-tracking branch 'origin/fix' into fix
alexandergull Feb 26, 2025
d526058
Merge branch 'refs/heads/fix' into bfp_whitelists.ag
alexandergull Feb 26, 2025
23f6766
Fix. Firewall. BFP logic fixed.
Glomberg Feb 19, 2025
13798ac
Fix. Firewall. BFP was removed from common FW flow.
Glomberg Feb 19, 2025
7bc21c3
Fix. Firewall. Modules running refactored.
Glomberg Mar 4, 2025
493f6d7
Upd. Backup Restore. Collecting a deletion error message from backup …
AntonV1211 Feb 6, 2025
cc29a15
Upd. Backup Restore. Error output, exception handling
AntonV1211 Feb 6, 2025
b68aab1
Mod. Backup Restore. Separation of logic after deleting backup after …
AntonV1211 Feb 19, 2025
6047370
Upd. Backup Restore. Changing the logic of error collection and output
AntonV1211 Feb 20, 2025
5461ef7
Mod. GetKeyAuto. Checking the query result code
AntonV1211 Feb 24, 2025
a1d6765
Fix. GetKeyAuto. Removed localization
AntonV1211 Feb 26, 2025
b25ec95
Version 2.152.99-dev
AntonV1211 Feb 24, 2025
8af5634
Fix. Http. Hard coded cleantalk IPs removed. (#481)
Glomberg Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions inc/spbc-firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function spbc_firewall__check()
{
global $spbc;

$firewall = new Firewall();
$firewall = Firewall::getInstance();

$secfw_enabled_on_main_site = false;
if (!is_main_site() && $spbc->network_settings['ms__work_mode'] == 2) {
Expand Down Expand Up @@ -46,27 +46,6 @@ function spbc_firewall__check()
$GLOBALS['wp_rewrite'] = new WP_Rewrite(); // Fix for early load WP_Rewrite
}

$login_url = wp_login_url();
if ( $spbc->settings['login_page_rename__enabled'] ) {
//todo This rewrite could break permalinks, need to implement new logic
$GLOBALS['wp_rewrite'] = new WP_Rewrite(); // Fix for early load WP_Rewrite
$login_url = RenameLoginPage::getURL($spbc->settings['login_page_rename__name']);
}

$firewall->loadFwModule(
new BFP(
array(
'api_key' => $spbc->api_key,
'state' => $spbc,
'is_login_page' => strpos(trim(Server::getURL(), '/'), trim($login_url, '/')) === 0,
'is_logged_in' => Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . get_option('home')),
'bf_limit' => $spbc->settings['bfp__allowed_wrong_auths'],
'block_period' => $spbc->settings['bfp__block_period__5_fails'],
'count_period' => $spbc->settings['bfp__count_interval'], // Counting login attempts in this interval
)
)
);

if (
$spbc->settings['traffic_control__enabled'] &&
(
Expand Down
144 changes: 96 additions & 48 deletions inc/spbc-scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2103,64 +2103,111 @@ function spbc_restore_file_from_backup_ajax_action_handler($id)
}

// Success: remove all data about backup
try {
$backup_deleted = unlink($full_backup_path);
$error_msg = array(
spbct_delete_backup_file($full_backup_path),
spbct_remove_backup_from_db($file_path),
spbct_update_cure_log($file_path),
spbct_update_scan_results($file_path, $backup_prev_results_state)
);

if ($backup_deleted === false) {
foreach ($error_msg as $value) {
if (array_key_exists('error', $value)) {
return $value;
}
}

return array('success' => true);
}

/**
* Deleting a backup file
* @param string $full_backup_path
* @return array
*/
function spbct_delete_backup_file($full_backup_path)
{
if ($full_backup_path) {
if (!unlink($full_backup_path)) {
return array('error' => esc_html__('Deleting backup error: Permissions denied.', 'security-malware-firewall'));
}
} else {
return array('error' => esc_html__('Deleting backup error: Incorrect backup file path.', 'security-malware-firewall'));
}
return array();
}

// Remove from backup
/**
* Deleting a backup from a database
* @param string $file_path
* @return array
*/
function spbct_remove_backup_from_db($file_path)
{
global $wpdb;
if ($file_path) {
$sql_prepared = $wpdb->prepare(
'DELETE '
. ' FROM ' . SPBC_TBL_BACKUPED_FILES
. ' WHERE real_path="%s";',
'DELETE FROM ' . SPBC_TBL_BACKUPED_FILES . ' WHERE real_path = %s;',
$file_path
);
$delete = $wpdb->query($sql_prepared);

if (is_null($delete)) {
return array('error' => esc_html__('Error: Something is wrong during deleting backup.', 'security-malware-firewall'));
if ($wpdb->query($sql_prepared) === false) {
return array('error' => esc_html__('Deleting backup error: Something is wrong during deleting backup.', 'security-malware-firewall'));
}
} else {
return array('error' => esc_html__('Deleting backup error: Incorrect backup file path for the database query.', 'security-malware-firewall'));
}
return array();
}

// update cure log
/**
* Changing the file information in the cure_log table regarding file recovery
* @param string $file_path
* @return array
*/
function spbct_update_cure_log($file_path)
{
global $wpdb;
if ($file_path) {
$sql_prepared = $wpdb->prepare(
'UPDATE ' . SPBC_TBL_CURE_LOG
. ' SET is_restored = 1, '
. ' cure_status = 0 '
. ' WHERE real_path = %s;',
array($file_path)
'UPDATE ' . SPBC_TBL_CURE_LOG . ' SET is_restored = 1, cure_status = 0 WHERE real_path = %s;',
$file_path
);
$update_cure_log = $wpdb->query($sql_prepared);

if (is_null($update_cure_log)) {
return array('error' => esc_html__('Error: Something is wrong during updating cure log.', 'security-malware-firewall'));
if ($wpdb->query($sql_prepared) === false) {
return array('error' => esc_html__('Error update cure log: Something is wrong during updating cure log.', 'security-malware-firewall'));
}
} else {
return array('error' => esc_html__('Error update cure log: Incorrect backup file path for the database query.', 'security-malware-firewall'));
}
return array();
}

if ($backup_prev_results_state !== null) {
// update scan results table
$sql_prepared = $wpdb->prepare(
'UPDATE ' . SPBC_TBL_SCAN_FILES
. ' SET weak_spots = %s, checked_heuristic = %s, checked_signatures = %s, status = %s, severity = %s'
. ' WHERE path = %s;',
array(
$backup_prev_results_state['weak_spots'],
$backup_prev_results_state['checked_heuristic'],
$backup_prev_results_state['checked_signatures'],
$backup_prev_results_state['status'],
$backup_prev_results_state['severity'],
$file_path)
);
$updated = $wpdb->query($sql_prepared);
if (is_null($updated)) {
return array('error' => esc_html__('Error: Something is wrong during saving previous state of file.', 'security-malware-firewall'));
}
/**
* Changing file information after recovery
* @param string $file_path
* @param array $backup_prev_results_state
* @return array
*/
function spbct_update_scan_results($file_path, $backup_prev_results_state)
{
global $wpdb;
if ($file_path && $backup_prev_results_state !== null) {
$sql_prepared = $wpdb->prepare(
'UPDATE ' . SPBC_TBL_SCAN_FILES . ' SET weak_spots = %s, checked_heuristic = %s, checked_signatures = %s, status = %s, severity = %s WHERE path = %s;',
array(
$backup_prev_results_state['weak_spots'],
$backup_prev_results_state['checked_heuristic'],
$backup_prev_results_state['checked_signatures'],
$backup_prev_results_state['status'],
$backup_prev_results_state['severity'],
$file_path
)
);
if ($wpdb->query($sql_prepared) === false) {
return array('error' => esc_html__('Error update scan results: Something is wrong during saving previous state of file.', 'security-malware-firewall'));
}
} catch (\Exception $e) {
return array('error' => esc_html__('Error: Something is wrong.', 'security-malware-firewall'));
} else {
return array('error' => esc_html__('Error update scan results: Incorrect data for changing the recovery results about the file', 'security-malware-firewall'));
}

return array('success' => true);
return array();
}

function spbc_restore_file_from_backup_ajax_action()
Expand All @@ -2169,12 +2216,13 @@ function spbc_restore_file_from_backup_ajax_action()

$file_fast_hash = isset($_POST['file_fast_hash']) ? esc_sql($_POST['file_fast_hash']) : null;

$result = spbc_restore_file_from_backup_ajax_action_handler($file_fast_hash);
if (isset($result['error'])) {
wp_send_json_error($result['error']);
}
$restore_result = spbc_restore_file_from_backup_ajax_action_handler($file_fast_hash);

wp_send_json_success(esc_html__('Success!', 'security-malware-firewall'));
if (isset($restore_result['success'])) {
wp_send_json_success(esc_html__('Success!', 'security-malware-firewall'));
} elseif (isset($restore_result['error'])) {
wp_send_json_error($restore_result['error']);
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5013,6 +5013,12 @@ function spbc_get_key_auto($direct_call = false)
'reload' => false,
'msg' => $result['error']
);
} elseif (isset($result['error_no']) && $result['error_no'] == '403') {
$out = array(
'success' => true,
'reload' => false,
'error' => isset($result['error_message']) ? esc_html($result['error_message']) : esc_html('Our service is not available in your region.'),
);
} elseif ( ! isset($result['auth_key'])) {
$out = array(
'success' => true,
Expand Down
Loading
Loading