Changeset 2851085
- Timestamp:
- 01/19/2023 01:21:39 PM (3 years ago)
- Location:
- traffic-jammer/trunk
- Files:
-
- 1 added
- 3 edited
-
README.md (modified) (1 diff)
-
includes/class-trafficjammer-abuseipdb.php (added)
-
readme.txt (modified) (2 diffs)
-
traffic-jammer.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
traffic-jammer/trunk/README.md
r2845288 r2851085 8 8 Tested up to: 6.1 9 9 10 Stable tag: 1.0. 610 Stable tag: 1.0.7 11 11 12 12 Requires PHP: 7.4 -
traffic-jammer/trunk/readme.txt
r2845288 r2851085 5 5 Requires at least: 4.7 6 6 Tested up to: 6.1 7 Stable tag: 1.0. 67 Stable tag: 1.0.7 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 39 39 40 40 == Changelog == 41 = 1.0.7 = 42 * added AbuseIPDB feature to block malicious traffic 43 41 44 = 1.0.6 = 42 45 * added feature to automatically block IPs which have failed login -
traffic-jammer/trunk/traffic-jammer.php
r2845288 r2851085 9 9 * Plugin URI: https://wordpress.org/plugins/traffic-jammer/ 10 10 * Description: WordPress plugin to block IP and bots that causes malicious traffic. 11 * Version: 1.0. 611 * Version: 1.0.7 12 12 * Requires at least: 5.2 13 13 * Requires PHP: 7.4 … … 119 119 $table_name = $wpdb->prefix . 'trafficjammer_traffic'; 120 120 $setting_options = get_option( 'wp_traffic_jammer_options' ); 121 122 if ( isset( $setting_options['abuseipdb_key'] ) ) { 123 $blocklist = get_option( 'wp_traffic_jammer_blocklist' ); 124 $blocklist = array_map( 'trim', explode( ',', $blocklist ) ); 125 126 $abuse = new Traffic_Jammer_AbuseIPDB(); 127 128 // Check the top ip, add IP to blocklist with 100% confidence of abuse. 129 $traffic_logs = $wpdb->get_results( 'SELECT count(*) as num_visits, IP FROM ' . $wpdb->prefix . 'trafficjammer_traffic where IP is not null GROUP BY IP ORDER BY num_visits DESC LIMIT 10' ); 130 131 foreach ( $traffic_logs as $value ) { 132 // skip if it is in the blocklist. 133 if ( trafficjammer_check_ip( $value->IP, $blocklist ) ) { 134 continue; 135 } else { 136 $abuse_result = $abuse->check( $value->IP ); 137 if ( $abuse_result['data']['abuseConfidenceScore'] == '100' ) { 138 trafficjammer_block_ip( $value->IP ); 139 } 140 } 141 } 142 } 143 144 // Cleanup Logs. 121 145 $interval_day = isset( $settting_option['log_retention'] ) ? $settting_option['log_retention'] : 3; 122 146 $wpdb->query( 'DELETE FROM ' . $table_name . ' WHERE `date` < DATE_SUB( NOW(), INTERVAL ' . $interval_day . ' DAY );' ); 123 147 } 124 148 add_action( 'trafficjammer_cron_hook', 'trafficjammer_cron_exec' ); 149 125 150 126 151 … … 165 190 global $wpdb, $cef6d44b_server; 166 191 $setting_options = get_option( 'wp_traffic_jammer_options' ); 167 192 $blocklist = get_option( 'wp_traffic_jammer_blocklist' ); 193 $blocklist = array_map( 'trim', explode( ',', $blocklist ) ); 194 195 // Check settings for the threshold. 168 196 if ( isset( $setting_options['login_attempts'] ) ) { 169 197 $num_tries = $setting_options['login_attempts']; … … 192 220 $result = $wpdb->get_row( $wpdb->prepare( $sql ) ); 193 221 if ( ( ! empty( $result->ctr ) ) && $result->ctr > $num_tries ) { 194 trafficjammer_block_ip( $ip ); 222 // We don't want duplicate values on the blocklist. 223 if ( ! trafficjammer_check_ip( $ip, $blocklist ) ) { 224 trafficjammer_block_ip( $ip ); 225 } 195 226 } 196 227 } … … 404 435 405 436 add_settings_field( 437 'trafficjammer_settings_abusipdb_key', 438 __( 'AbuseIPDB' ), 439 'trafficjammer_abuseipdb_key', 440 'wp_traffic_jammer', 441 'trafficjammer_settings_section' 442 ); 443 444 add_settings_field( 406 445 'trafficjammer_settings_qs_busting', 407 446 __( 'Block query pattern' ), … … 503 542 echo '> <code>/?{timestamp}</code>'; 504 543 echo '<br>'; 505 echo '<br>';506 544 echo 'Block execesive request, example: <code>/?1234567890</code> '; 507 545 … … 522 560 echo '/>'; 523 561 echo '<br>'; 524 } 562 echo 'Automatically block IPs based on failed login attempts.'; 563 } 564 565 /** 566 * AbuseIPDB API 567 * 568 * @return void 569 */ 570 function trafficjammer_abuseipdb_key() { 571 $setting_options = get_option( 'wp_traffic_jammer_options' ); 572 echo '<input type="text" name="wp_traffic_jammer_options[abuseipdb_key]" size="50" '; 573 if ( isset( $setting_options['abuseipdb_key'] ) ) { 574 echo ' value="' . esc_attr( $setting_options['abuseipdb_key'] ) . '"'; 575 } 576 echo '/>'; 577 echo '<br>'; 578 echo 'Block execessive hits from IPs with 100% abuse score.'; 579 echo '<br>'; 580 } 581 582 525 583 526 584 /** … … 539 597 * Block IP 540 598 * 541 * @param string $ip value otadd.599 * @param string $ip value to add. 542 600 * 543 601 * @return void … … 662 720 // include wp-cli file. 663 721 require plugin_dir_path( __FILE__ ) . 'includes/class-wp-traffic-jammer-cli.php'; 722 require plugin_dir_path( __FILE__ ) . 'includes/class-trafficjammer-abuseipdb.php';
Note: See TracChangeset
for help on using the changeset viewer.