<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -119,28 +119,31 @@ type track_count: record {
 	index: count &amp;default=0;
 };
 
+function default_track_count(a: addr): track_count
+	{
+	local x: track_count;
+	return x;
+	}
+
 const default_notice_thresholds: vector of count = {
-	20, 100, 1000, 10000, 100000, 1000000, 10000000,
+	30, 100, 1000, 10000, 100000, 1000000, 10000000,
 } &amp;redef;
 
 # This is total rip off from scan.bro, but placed in the global namespace
 # and slightly reworked to be easier to work with and more general.
-function thresh_check(v: vector of count, tracker: track_count): bool
+function check_threshold(v: vector of count, tracker: track_count): bool
 	{
 	if ( tracker$index &lt;= |v| &amp;&amp; tracker$n &gt;= v[tracker$index] )
 		{
 		++tracker$index;
 		return T;
 		}
-	else
-		{
-		return F;
-		}
+	return F;
 	}
 
-function default_thresh_check(tracker: track_count): bool
+function default_check_threshold(tracker: track_count): bool
 	{
-	return thresh_check(default_notice_thresholds, tracker);
+	return check_threshold(default_notice_thresholds, tracker);
 	}
 	
 # This can be used for &amp;default values on tables when the index is an addr.</diff>
      <filename>functions-ext.bro</filename>
    </modified>
    <modified>
      <diff>@@ -170,7 +170,7 @@ event http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &amp;
 		
 		++activity_counters[id$orig_h]$sql_injections$n;
 		
-		if ( default_thresh_check(activity_counters[id$orig_h]$sql_injections) )
+		if ( default_check_threshold(activity_counters[id$orig_h]$sql_injections) )
 			{
 			NOTICE([$note=HTTP_SQL_Injection_Attack,
 			        $msg=fmt(&quot;SQL injection attack (n=%d): %s -&gt; %s&quot;,
@@ -185,7 +185,7 @@ event http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &amp;
 		sess_ext$force_log=T;
 		add sess_ext$force_log_reasons[&quot;sql_injection_probe&quot;];
 		
-		if ( default_thresh_check(activity_counters[c$id$orig_h]$sql_injection_probes) )
+		if ( default_check_threshold(activity_counters[c$id$orig_h]$sql_injection_probes) )
 			{
 			NOTICE([$note=HTTP_SQL_Injection_Heavy_Probing, 
 			        $msg=fmt(&quot;Heavy probing from %s&quot;, id$orig_h), </diff>
      <filename>http-ext.bro</filename>
    </modified>
    <modified>
      <diff>@@ -27,8 +27,7 @@ event bro_init()
 	                                       &quot;resp_h&quot;, &quot;resp_p&quot;,
 	                                       &quot;force_log_reasons&quot;,
 	                                       &quot;method&quot;, &quot;url&quot;, &quot;referrer&quot;,
-	                                       &quot;user_agent&quot;, &quot;proxied_for&quot;,
-	                                       &quot;force_log_reasons&quot;));
+	                                       &quot;user_agent&quot;, &quot;proxied_for&quot;));
 	
 	# Set this log to always accept output because the POST logging
 	# must be specifically enabled per-request anyway.</diff>
      <filename>logging.http-ext.bro</filename>
    </modified>
    <modified>
      <diff>@@ -22,8 +22,19 @@ export {
 	const authentication_data_size = 5500 &amp;redef;
 	const guessing_timeout = 30 mins;
 	
+	redef enum Notice += {
+		SSH_Login,
+		SSH_PasswordGuessing,
+		SSH_LoginByPasswordGuesser,
+		SSH_Login_From_Strange_Hostname,
+		SSH_Bytecount_Inconsistency,
+	};
+	
 	# Keeps count of how many rejections a host has had
-	global password_rejections: table[addr] of count &amp;default=0 &amp;write_expire=guessing_timeout;
+	global password_rejections: table[addr] of track_count 
+		&amp;default=default_track_count
+		&amp;write_expire=guessing_timeout;
+	
 	# Keeps track of hosts identified as guessing passwords
 	global password_guessers: set[addr] &amp;read_expire=guessing_timeout+1hr;
 	
@@ -49,14 +60,6 @@ export {
 
 	# This is a table with orig subnet as the key, and subnet as the value.
 	const ignore_guessers: table[subnet] of subnet &amp;redef;
-	
-	redef enum Notice += {
-		SSH_Login,
-		SSH_PasswordGuessing,
-		SSH_LoginByPasswordGuesser,
-		SSH_Login_From_Strange_Hostname,
-		SSH_Bytecount_Inconsistency,
-	};
 } 
 
 # Examples for how to handle notices from this script.
@@ -88,7 +91,7 @@ event check_ssh_connection(c: connection, done: bool)
 	# If this is no longer a known SSH connection, just return.
 	if ( c$id !in active_ssh_conns )
 		return;
-	
+
 	# If this is still a live connection and the byte count has not
 	# crossed the threshold, just return and let the resheduled check happen later.
 	if ( !done &amp;&amp; c$resp$size &lt; authentication_data_size )
@@ -99,7 +102,7 @@ event check_ssh_connection(c: connection, done: bool)
 	# doesn't send back at least 50 bytes.
 	if (c$resp$size &lt; 50)
 		return;
-	
+
 	local ssh_conn = active_ssh_conns[c$id];
 	local status = &quot;failure&quot;;
 	local direction = is_local_addr(c$id$orig_h) ? &quot;to&quot; : &quot;from&quot;;
@@ -113,20 +116,22 @@ event check_ssh_connection(c: connection, done: bool)
 		if ( log_geodata_on_failure )
 			location = (direction == &quot;to&quot;) ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);
 
+		if ( c$id$orig_h !in password_rejections )
+			password_rejections[c$id$orig_h] = default_track_count(c$id$orig_h);
+			
 		# Track the number of rejections
 		if ( !(c$id$orig_h in ignore_guessers &amp;&amp;
 		       c$id$resp_h in ignore_guessers[c$id$orig_h]) )
-			password_rejections[c$id$orig_h] += 1;
+			++password_rejections[c$id$orig_h]$n;
 
-		if ( password_rejections[c$id$orig_h] &gt; password_guesses_limit &amp;&amp; 
-		     c$id$orig_h !in password_guessers )
+		if ( default_check_threshold(password_rejections[c$id$orig_h]) )
 			{
 			add password_guessers[c$id$orig_h];
 			NOTICE([$note=SSH_PasswordGuessing,
 			        $conn=c,
 			        $msg=fmt(&quot;SSH password guessing by %s&quot;, c$id$orig_h),
-			        $sub=fmt(&quot;%d failed logins&quot;, password_rejections[c$id$orig_h]),
-			        $n=password_rejections[c$id$orig_h]]);
+			        $sub=fmt(&quot;%d failed logins&quot;, password_rejections[c$id$orig_h]$n),
+			        $n=password_rejections[c$id$orig_h]$n]);
 			}
 		} 
 	# TODO: This is to work around a quasi-bug in Bro which occasionally 
@@ -137,15 +142,15 @@ event check_ssh_connection(c: connection, done: bool)
 		status = &quot;success&quot;;
 		location = (direction == &quot;to&quot;) ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);
 
-		if ( password_rejections[c$id$orig_h] &gt; password_guesses_limit &amp;&amp;
+		if ( password_rejections[c$id$orig_h]$n &gt; password_guesses_limit &amp;&amp;
 		     c$id$orig_h !in password_guessers)
 			{
 			add password_guessers[c$id$orig_h];
 			NOTICE([$note=SSH_LoginByPasswordGuesser,
 			        $conn=c,
-			        $n=password_rejections[c$id$orig_h],
+			        $n=password_rejections[c$id$orig_h]$n,
 			        $msg=fmt(&quot;Successful SSH login by password guesser %s&quot;, c$id$orig_h),
-			        $sub=fmt(&quot;%d failed logins&quot;, password_rejections[c$id$orig_h])]);
+			        $sub=fmt(&quot;%d failed logins&quot;, password_rejections[c$id$orig_h]$n)]);
 			}
 
 		local message = fmt(&quot;SSH login %s %s \&quot;%s\&quot; \&quot;%s\&quot; %f %f %s (triggered with %d bytes)&quot;,</diff>
      <filename>ssh-ext.bro</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>93b819b51912747623e65aea714a53be1b82199b</id>
    </parent>
  </parents>
  <author>
    <name>Seth Hall</name>
    <email>hall.692@osu.edu</email>
  </author>
  <url>http://github.com/sethhall/bro_scripts/commit/7d4f8eff57f1c3aff362a7db6982882ee4f61260</url>
  <id>7d4f8eff57f1c3aff362a7db6982882ee4f61260</id>
  <committed-date>2009-11-02T19:28:06-08:00</committed-date>
  <authored-date>2009-11-02T19:28:06-08:00</authored-date>
  <message>SSH now uses default_check_threshold
Fixed a number of bugs.</message>
  <tree>ec3025c1297d5c8ad67e4559b21e31ea0d3d3ff0</tree>
  <committer>
    <name>Seth Hall</name>
    <email>hall.692@osu.edu</email>
  </committer>
</commit>
