Bad Behavior - Version 2.1.9

Version Description

Download this release

Release Info

Developer error
Plugin Icon wp plugin Bad Behavior
Version 2.1.9
Comparing to
See all releases

Code changes from version 2.1.8 to 2.1.9

README.txt CHANGED
@@ -1,6 +1,6 @@
1
  === Bad Behavior ===
2
  Tags: comment,trackback,referrer,spam,robot,antispam
3
- Contributors: error, MarkJaquith, Firas, skeltoac
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=error%40ioerror%2eus&item_name=Bad%20Behavior%20%28From%20WordPress%20Page%29&no_shipping=1&cn=Comments%20about%20Bad%20Behavior&tax=0&currency_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8
5
  Requires at least: 2.7
6
  Tested up to: 3.0.4
@@ -64,6 +64,10 @@ the following:
64
  For complete documentation and installation instructions, please visit
65
  http://www.bad-behavior.ioerror.us/
66
 
 
 
 
 
67
  == Release Notes ==
68
 
69
  = Bad Behavior 2.0 Known Issues =
1
  === Bad Behavior ===
2
  Tags: comment,trackback,referrer,spam,robot,antispam
3
+ Contributors: error, markjaquith, skeltoac
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=error%40ioerror%2eus&item_name=Bad%20Behavior%20%28From%20WordPress%20Page%29&no_shipping=1&cn=Comments%20about%20Bad%20Behavior&tax=0&currency_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8
5
  Requires at least: 2.7
6
  Tested up to: 3.0.4
64
  For complete documentation and installation instructions, please visit
65
  http://www.bad-behavior.ioerror.us/
66
 
67
+ == Screenshots ==
68
+
69
+ 1. Most of the time, only spammers see this. In the event a human winds up here, a way out is provided.
70
+
71
  == Release Notes ==
72
 
73
  = Bad Behavior 2.0 Known Issues =
bad-behavior-generic.php CHANGED
@@ -143,5 +143,3 @@ require_once(BB2_CWD . "/bad-behavior/core.inc.php");
143
  bb2_install(); // FIXME: see above
144
 
145
  bb2_start(bb2_read_settings());
146
-
147
- ?>
143
  bb2_install(); // FIXME: see above
144
 
145
  bb2_start(bb2_read_settings());
 
 
bad-behavior-mediawiki.php CHANGED
@@ -39,6 +39,9 @@ $bb2_settings_defaults = array(
39
  'httpbl_threat' => '25',
40
  'httpbl_maxage' => '30',
41
  'offsite_forms' => false,
 
 
 
42
  );
43
 
44
  define('BB2_CWD', dirname(__FILE__));
@@ -162,5 +165,3 @@ $wgExtensionCredits['other'][] = array(
162
 
163
  #$wgHooks['ParserAfterTidy'][] = 'bb2_mediawiki_timer';
164
  $wgExtensionFunctions[] = 'bb2_mediawiki_entry';
165
-
166
- ?>
39
  'httpbl_threat' => '25',
40
  'httpbl_maxage' => '30',
41
  'offsite_forms' => false,
42
+ 'reverse_proxy' => false,
43
+ 'reverse_proxy_header' => 'X-Forwarded-For',
44
+ 'reverse_proxy_addresses' => array(),
45
  );
46
 
47
  define('BB2_CWD', dirname(__FILE__));
165
 
166
  #$wgHooks['ParserAfterTidy'][] = 'bb2_mediawiki_timer';
167
  $wgExtensionFunctions[] = 'bb2_mediawiki_entry';
 
 
bad-behavior-wordpress-admin.php CHANGED
@@ -128,7 +128,7 @@ function bb2_manage() {
128
  <h2><?php _e("Bad Behavior"); ?></h2>
129
  <form method="post" action="<?php echo $request_uri; ?>">
130
  <p>For more information please visit the <a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> homepage.</p>
131
- <p>If you find Bad Behavior valuable, please consider making a <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=error%40ioerror%2eus&item_name=Bad%20Behavior%20<?php echo BB2_VERSION; ?>%20%28From%20Admin%29&no_shipping=1&cn=Comments%20about%20Bad%20Behavior&tax=0&currency_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8">financial contribution</a> to further development of Bad Behavior.</p>
132
 
133
  <div class="tablenav">
134
  <?php
@@ -262,6 +262,21 @@ function bb2_options()
262
  } else {
263
  $settings['offsite_forms'] = false;
264
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  bb2_write_settings($settings);
266
  ?>
267
  <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
@@ -301,6 +316,16 @@ function bb2_options()
301
  <tr><td><label><input type="text" size="3" maxlength="3" name="httpbl_maxage" value="<?php echo $settings['httpbl_maxage']; ?>" /> Maximum Age of Data (30 is recommended)</label></td></tr>
302
  </table>
303
 
 
 
 
 
 
 
 
 
 
 
304
  <p class="submit"><input class="button" type="submit" name="submit" value="<?php _e('Update &raquo;'); ?>" /></p>
305
  </form>
306
  </div>
@@ -318,5 +343,3 @@ function bb2_plugin_action_links($links, $file) {
318
  return $links;
319
  }
320
  add_filter("plugin_action_links", "bb2_plugin_action_links", 10, 2);
321
-
322
- ?>
128
  <h2><?php _e("Bad Behavior"); ?></h2>
129
  <form method="post" action="<?php echo $request_uri; ?>">
130
  <p>For more information please visit the <a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> homepage.</p>
131
+ <p>If you find Bad Behavior valuable, please consider <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=error%40ioerror%2eus&item_name=Bad%20Behavior%20<?php echo BB2_VERSION; ?>%20%28From%20Admin%29&no_shipping=1&cn=Comments%20about%20Bad%20Behavior&tax=0&currency_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8">donating</a> to help further development of Bad Behavior.</p>
132
 
133
  <div class="tablenav">
134
  <?php
262
  } else {
263
  $settings['offsite_forms'] = false;
264
  }
265
+ if ($_POST['reverse_proxy']) {
266
+ $settings['reverse_proxy'] = true;
267
+ } else {
268
+ $settings['reverse_proxy'] = false;
269
+ }
270
+ if ($_POST['reverse_proxy_header']) {
271
+ $settings['reverse_proxy_header'] = uc_all($_POST['reverse_proxy_header']);
272
+ } else {
273
+ $settings['reverse_proxy_header'] = 'X-Forwarded-For';
274
+ }
275
+ if ($_POST['reverse_proxy_addresses']) {
276
+ $settings['reverse_proxy_addresses'] = preg_split("/[\s,]+/m", $_POST['reverse_proxy_addresses']);
277
+ } else {
278
+ $settings['reverse_proxy_addresses'] = array();
279
+ }
280
  bb2_write_settings($settings);
281
  ?>
282
  <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
316
  <tr><td><label><input type="text" size="3" maxlength="3" name="httpbl_maxage" value="<?php echo $settings['httpbl_maxage']; ?>" /> Maximum Age of Data (30 is recommended)</label></td></tr>
317
  </table>
318
 
319
+ <h3><?php _e('Reverse Proxy/Load Balancer'); ?></h3>
320
+ <p>If you are using Bad Behavior behind a reverse proxy, load balancer, HTTP accelerator, content cache or similar technology, enable the Reverse Proxy option.</p>
321
+ <p>If you have a chain of two or more reverse proxies between your server and the public Internet, you must specify <em>all</em> of the IP address ranges (in CIDR format) of all of your proxy servers, load balancers, etc. Otherwise, Bad Behavior may be unable to determine the client's true IP address.</p>
322
+ <p>In addition, your reverse proxy servers must set the IP address of the Internet client from which they received the request in an HTTP header. If you don't specify a header, <a href="http://en.wikipedia.org/wiki/X-Forwarded-For">X-Forwarded-For</a> will be used. Most proxy servers already support X-Forwarded-For and you would then only need to ensure that it is enabled on your proxy servers. Some other header names in common use include <u>X-Real-Ip</u> (nginx) and <u>Cf-Connecting-Ip</u> (CloudFlare).</p>
323
+ <table class="form-table">
324
+ <tr><td><label><input type="checkbox" name="reverse_proxy" value="true" <?php if ($settings['reverse_proxy']) { ?>checked="checked" <?php } ?>/> <?php _e('Enable Reverse Proxy'); ?></label></td></tr>
325
+ <tr><td><label><input type="text" size="32" name="reverse_proxy_header" value="<?php echo $settings['reverse_proxy_header']; ?>" /> Header containing Internet clients' IP address</label></td></tr>
326
+ <tr><td><label>IP address or CIDR format address ranges for your proxy servers (one per line)<br/><textarea cols="24" rows="6" name="reverse_proxy_addresses"><?php echo implode("\n", $settings['reverse_proxy_addresses']); ?></textarea></td></tr>
327
+ </table>
328
+
329
  <p class="submit"><input class="button" type="submit" name="submit" value="<?php _e('Update &raquo;'); ?>" /></p>
330
  </form>
331
  </div>
343
  return $links;
344
  }
345
  add_filter("plugin_action_links", "bb2_plugin_action_links", 10, 2);
 
 
bad-behavior-wordpress.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Bad Behavior
4
- Version: 2.1.8
5
  Description: Deny automated spambots access to your PHP-based Web site.
6
  Plugin URI: http://www.bad-behavior.ioerror.us/
7
  Author: Michael Hampton
@@ -102,7 +102,9 @@ function bb2_read_settings() {
102
  // Add in default settings when they aren't yet present in WP
103
  $settings = get_settings('bad_behavior_settings');
104
  if (!$settings) $settings = array();
105
- return array_merge(array('log_table' => $wpdb->prefix . 'bad_behavior', 'display_stats' => true, 'strict' => false, 'verbose' => false, 'logging' => true, 'httpbl_key' => '', 'httpbl_threat' => '25', 'httpbl_maxage' => '30', 'offsite_forms' => false), $settings);
 
 
106
  }
107
 
108
  // write settings to database
@@ -167,5 +169,3 @@ $_SESSION['BB2_RESULT'] = bb2_start(bb2_read_settings());
167
  $bb2_mtime = explode(" ", microtime());
168
  $bb2_timer_stop = $bb2_mtime[1] + $bb2_mtime[0];
169
  $bb2_timer_total = $bb2_timer_stop - $bb2_timer_start;
170
-
171
- ?>
1
  <?php
2
  /*
3
  Plugin Name: Bad Behavior
4
+ Version: 2.1.9
5
  Description: Deny automated spambots access to your PHP-based Web site.
6
  Plugin URI: http://www.bad-behavior.ioerror.us/
7
  Author: Michael Hampton
102
  // Add in default settings when they aren't yet present in WP
103
  $settings = get_settings('bad_behavior_settings');
104
  if (!$settings) $settings = array();
105
+ return array_merge(array('log_table' => $wpdb->prefix . 'bad_behavior', 'display_stats' => true, 'strict' => false, 'verbose' => false, 'logging' => true, 'httpbl_key' => '', 'httpbl_threat' => '25', 'httpbl_maxage' => '30', 'offsite_forms' => false, 'reverse_proxy' => false, 'reverse_proxy_header' => 'X-Forwarded-For', 'reverse_proxy_addresses' => array(),), $settings);
106
+
107
+
108
  }
109
 
110
  // write settings to database
169
  $bb2_mtime = explode(" ", microtime());
170
  $bb2_timer_stop = $bb2_mtime[1] + $bb2_mtime[0];
171
  $bb2_timer_total = $bb2_timer_stop - $bb2_timer_start;
 
 
bad-behavior/banned.inc.php CHANGED
@@ -61,5 +61,3 @@ function bb2_log_denial($settings, $package, $key, $previous_key=false)
61
  if (!$settings['logging']) return;
62
  bb2_db_query(bb2_insert($settings, $package, $key));
63
  }
64
-
65
- ?>
61
  if (!$settings['logging']) return;
62
  bb2_db_query(bb2_insert($settings, $package, $key));
63
  }
 
 
bad-behavior/blackhole.inc.php CHANGED
@@ -61,4 +61,3 @@ function bb2_httpbl($settings, $package) {
61
  }
62
  return false;
63
  }
64
- ?>
61
  }
62
  return false;
63
  }
 
bad-behavior/blacklist.inc.php CHANGED
@@ -125,5 +125,3 @@ function bb2_blacklist($package) {
125
 
126
  return FALSE;
127
  }
128
-
129
- ?>
125
 
126
  return FALSE;
127
  }
 
 
bad-behavior/browser.inc.php CHANGED
@@ -82,5 +82,3 @@ function bb2_safari($package)
82
  }
83
  return false;
84
  }
85
-
86
- ?>
82
  }
83
  return false;
84
  }
 
 
bad-behavior/cloudflare.inc.php CHANGED
@@ -12,5 +12,3 @@ function bb2_cloudflare($package)
12
  # }
13
  return false;
14
  }
15
-
16
- ?>
12
  # }
13
  return false;
14
  }
 
 
bad-behavior/common_tests.inc.php CHANGED
@@ -146,5 +146,3 @@ function bb2_misc_headers($settings, $package)
146
 
147
  return false;
148
  }
149
-
150
- ?>
146
 
147
  return false;
148
  }
 
 
bad-behavior/core.inc.php CHANGED
@@ -1,5 +1,5 @@
1
  <?php if (!defined('BB2_CWD')) die("I said no cheating!");
2
- define('BB2_VERSION', "2.1.8");
3
 
4
  // Bad Behavior entry point is bb2_start()
5
  // If you're reading this, you are probably lost.
@@ -40,6 +40,19 @@ function bb2_approved($settings, $package)
40
  }
41
  }
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  // Let God sort 'em out!
45
  function bb2_start($settings)
@@ -67,11 +80,15 @@ function bb2_start($settings)
67
  $request_uri = $_SERVER["REQUEST_URI"];
68
  if (!$request_uri) $request_uri = $_SERVER['SCRIPT_NAME']; # IIS
69
 
70
- # Nasty CloudFlare hack provided by butchs at simplemachines
71
- $ip_temp = preg_replace("/^::ffff:/", "", (array_key_exists('Cf-Connecting-Ip', $headers_mixed)) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR']);
72
- $cloudflare_ip = preg_replace("/^::ffff:/", "", $_SERVER['REMOTE_ADDR']);
 
 
 
 
73
 
74
- @$package = array('ip' => $ip_temp, 'headers' => $headers, 'headers_mixed' => $headers_mixed, 'request_method' => $_SERVER['REQUEST_METHOD'], 'request_uri' => $request_uri, 'server_protocol' => $_SERVER['SERVER_PROTOCOL'], 'request_entity' => $request_entity, 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'is_browser' => false, 'cloudflare' => $cloudflare_ip);
75
 
76
  $result = bb2_screen($settings, $package);
77
  if ($result && !defined('BB2_TEST')) bb2_banned($settings, $package, $result);
@@ -142,7 +159,7 @@ function bb2_screen($settings, $package)
142
  } elseif (stripos($ua, "MovableType") !== FALSE) {
143
  require_once(BB2_CORE . "/movabletype.inc.php");
144
  if ($r = bb2_movabletype($package)) return $r;
145
- } elseif (stripos($ua, "msnbot") !== FALSE || stripos($ua, "MS Search") !== FALSE) {
146
  require_once(BB2_CORE . "/searchengine.inc.php");
147
  if ($r = bb2_msnbot($package)) return $r;
148
  } elseif (stripos($ua, "Googlebot") !== FALSE || stripos($ua, "Mediapartners-Google") !== FALSE || stripos($ua, "Google Wireless") !== FALSE) {
@@ -172,4 +189,3 @@ function bb2_screen($settings, $package)
172
  bb2_approved($settings, $package);
173
  return false;
174
  }
175
- ?>
1
  <?php if (!defined('BB2_CWD')) die("I said no cheating!");
2
+ define('BB2_VERSION', "2.1.9");
3
 
4
  // Bad Behavior entry point is bb2_start()
5
  // If you're reading this, you are probably lost.
40
  }
41
  }
42
 
43
+ // If this is reverse-proxied or load balanced, obtain the actual client IP
44
+ function bb2_reverse_proxy($settings, $headers_mixed)
45
+ {
46
+ $addrs = array_reverse(preg_split("/[\s,]+/", $headers_mixed[$settings['reverse_proxy_header']]));
47
+ if (!empty($settings['reverse_proxy_addresses'])) {
48
+ foreach ($addrs as $addr) {
49
+ if (!match_cidr($addr, $settings['reverse_proxy_addresses'])) {
50
+ return $addr;
51
+ }
52
+ }
53
+ }
54
+ return $addrs[0];
55
+ }
56
 
57
  // Let God sort 'em out!
58
  function bb2_start($settings)
80
  $request_uri = $_SERVER["REQUEST_URI"];
81
  if (!$request_uri) $request_uri = $_SERVER['SCRIPT_NAME']; # IIS
82
 
83
+ if ($settings['reverse_proxy']) {
84
+ $headers['X-Bad-Behavior-Remote-Address'] = $_SERVER['REMOTE_ADDR'];
85
+ $headers_mixed['X-Bad-Behavior-Remote-Address'] = $_SERVER['REMOTE_ADDR'];
86
+ $ip = bb2_reverse_proxy($settings, $headers_mixed);
87
+ } else {
88
+ $ip = $_SERVER['REMOTE_ADDR'];
89
+ }
90
 
91
+ @$package = array('ip' => $ip, 'headers' => $headers, 'headers_mixed' => $headers_mixed, 'request_method' => $_SERVER['REQUEST_METHOD'], 'request_uri' => $request_uri, 'server_protocol' => $_SERVER['SERVER_PROTOCOL'], 'request_entity' => $request_entity, 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'is_browser' => false,);
92
 
93
  $result = bb2_screen($settings, $package);
94
  if ($result && !defined('BB2_TEST')) bb2_banned($settings, $package, $result);
159
  } elseif (stripos($ua, "MovableType") !== FALSE) {
160
  require_once(BB2_CORE . "/movabletype.inc.php");
161
  if ($r = bb2_movabletype($package)) return $r;
162
+ } elseif (stripos($ua, "bingbot") !== FALSE || stripos($ua, "msnbot") !== FALSE || stripos($ua, "MS Search") !== FALSE) {
163
  require_once(BB2_CORE . "/searchengine.inc.php");
164
  if ($r = bb2_msnbot($package)) return $r;
165
  } elseif (stripos($ua, "Googlebot") !== FALSE || stripos($ua, "Mediapartners-Google") !== FALSE || stripos($ua, "Google Wireless") !== FALSE) {
189
  bb2_approved($settings, $package);
190
  return false;
191
  }
 
bad-behavior/functions.inc.php CHANGED
@@ -46,6 +46,7 @@ function match_cidr($addr, $cidr) {
46
  foreach ($cidr as $cidrlet) {
47
  if (match_cidr($addr, $cidrlet)) {
48
  $output = true;
 
49
  }
50
  }
51
  } else {
@@ -71,5 +72,3 @@ function bb2_load_headers() {
71
  }
72
  return $headers;
73
  }
74
-
75
- ?>
46
  foreach ($cidr as $cidrlet) {
47
  if (match_cidr($addr, $cidrlet)) {
48
  $output = true;
49
+ break;
50
  }
51
  }
52
  } else {
72
  }
73
  return $headers;
74
  }
 
 
bad-behavior/movabletype.inc.php CHANGED
@@ -10,5 +10,3 @@ function bb2_movabletype($package)
10
  }
11
  return false;
12
  }
13
-
14
- ?>
10
  }
11
  return false;
12
  }
 
 
bad-behavior/post.inc.php CHANGED
@@ -54,7 +54,7 @@ function bb2_post($settings, $package)
54
  }
55
 
56
  // If Referer exists, it should refer to a page on our site
57
- if ($settings['offsite_forms'] && array_key_exists('Referer', $package['headers_mixed']) && stripos($package['headers_mixed']['Referer'], $package['headers_mixed']['Host']) === FALSE) {
58
  return "cd361abb";
59
  }
60
 
@@ -100,5 +100,3 @@ function bb2_post($settings, $package)
100
 
101
  return false;
102
  }
103
-
104
- ?>
54
  }
55
 
56
  // If Referer exists, it should refer to a page on our site
57
+ if (!$settings['offsite_forms'] && array_key_exists('Referer', $package['headers_mixed']) && stripos($package['headers_mixed']['Referer'], $package['headers_mixed']['Host']) === FALSE) {
58
  return "cd361abb";
59
  }
60
 
100
 
101
  return false;
102
  }
 
 
bad-behavior/responses.inc.php CHANGED
@@ -49,4 +49,3 @@ function bb2_get_response($key) {
49
  if (array_key_exists($key, $bb2_responses)) return $bb2_responses[$key];
50
  return array('00000000');
51
  }
52
- ?>
49
  if (array_key_exists($key, $bb2_responses)) return $bb2_responses[$key];
50
  return array('00000000');
51
  }
 
bad-behavior/screener.inc.php CHANGED
@@ -60,4 +60,3 @@ function bb2_screener($settings, $package)
60
  bb2_screener_cookie($settings, $package, BB2_COOKIE, $cookie_value);
61
  bb2_screener_javascript($settings, $package, BB2_COOKIE, $cookie_value);
62
  }
63
- ?>
60
  bb2_screener_cookie($settings, $package, BB2_COOKIE, $cookie_value);
61
  bb2_screener_javascript($settings, $package, BB2_COOKIE, $cookie_value);
62
  }
 
bad-behavior/searchengine.inc.php CHANGED
@@ -43,5 +43,3 @@ function bb2_yahoo($package)
43
  # }
44
  return false;
45
  }
46
-
47
- ?>
43
  # }
44
  return false;
45
  }
 
 
bad-behavior/whitelist.inc.php CHANGED
@@ -26,5 +26,3 @@ function bb2_whitelist($package)
26
  }
27
  return false;
28
  }
29
-
30
- ?>
26
  }
27
  return false;
28
  }
 
 
screenshot-1.png ADDED
Binary file
settings.ini CHANGED
@@ -7,3 +7,7 @@ httpbl_key = ""
7
  httpbl_threat = 25
8
  httpbl_maxage = 30
9
  offsite_forms = false
 
 
 
 
7
  httpbl_threat = 25
8
  httpbl_maxage = 30
9
  offsite_forms = false
10
+ reverse_proxy = false
11
+ reverse_proxy_header = "X-Forwarded-For"
12
+ ;reverse_proxy_addresses[] =
13
+ ;reverse_proxy_addresses[] =