{"commit":"1bf23738da05a5663d006a234d4dd611c5c7db3a","subject":"Comments","message":"Comments\n\nAdded comments for SMTP event.","repos":"albertzaharovits\/cs-bro,kingtuna\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,CrowdStrike\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/shellshock\/detect-shellshock.bro","new_file":"bro-scripts\/shellshock\/detect-shellshock.bro","new_contents":"# Monitors traffic for Shellshock exploit attempts\n# When exploits are seen containing IP addresses and domain values, monitors traffic for 60 minutes watching for endpoints to connect to IP addresses and domains seen in exploit attempts\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n@load base\/protocols\/dhcp\n@load base\/protocols\/smtp\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Shellshock_DHCP,\n Shellshock_HTTP,\n Shellshock_SMTP,\n Shellshock_Successful_Conn\n };\n}\n\nconst shellshock_pattern = \/((\\(|%28)(\\)|%29)( |%20)(\\{|%7B)|(\\{|%7B)(\\:|%3A)(\\;|%3B))\/ &redef;\n\nconst shellshock_commands = \/wget\/ | \/curl\/;\n\nglobal shellshock_servers: set[addr] &create_expire=60min &synchronized;\nglobal shellshock_hosts: set[string] &create_expire=60min &synchronized;\n\n# function to locate and extract domains seen in shellshock exploit attempts\nfunction find_domain(ss: string)\n{\nlocal parts1 = split_all(ss,\/[[:space:]]\/);\nfor ( p in parts1 )\n if ( \"http\" in parts1[p] )\n {\n local parts2 = split_all(parts1[p],\/\\\/\/);\n local output = parts2[5];\n }\n\nif ( output !in shellshock_hosts )\n add shellshock_hosts[output];\n}\n\n# function to locate and extract IP addresses seen in shellshock exploit attempts\nfunction find_ip(ss: string): bool\n{\nlocal b = F;\nlocal remote_servers = find_ip_addresses(ss);\n\nif ( |remote_servers| > 0 )\n {\n b = T;\n for ( rs in remote_servers )\n {\n local s = to_addr(remote_servers[rs]);\n if ( s !in shellshock_servers )\n add shellshock_servers[s];\n }\n }\n\nreturn b;\n}\n\n# event to identify shellshock HTTP exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3\n{\nif ( ! is_orig ) return;\nif ( shellshock_pattern !in value ) return;\n\n# generate a notice of the HTTP exploit attempt\nNOTICE([$note=Shellshock_HTTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock HTTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in value )\n find_domain(value);\n}\n\n# event to identify shellshock DHCP exploit attempts\nevent dhcp_ack(c: connection, msg: dhcp_msg, mask: addr, router: dhcp_router_list, lease: interval, serv_addr: addr, host_name: string)\n{\nif ( shellshock_pattern !in host_name ) return;\n\n# generate a notice of the DHCP exploit attempt\nNOTICE([$note=Shellshock_DHCP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock DHCP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",host_name),\n $identifier=cat(c$id$orig_h,c$id$resp_h,host_name)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(host_name) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in host_name )\n find_domain(host_name);\n}\n\n# event to identify endpoints connecting to domains seen in shellshock exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=5\n{\nif ( name != \"HOST\" ) return;\nif ( value in shellshock_hosts )\n # generate a notice of HTTP connection to domain seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to a domain seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"Domain: %s\",value),\n $identifier=cat(c$id$orig_h,value)]);\n}\n\n# event to identify shellshock SMTP exploit attempts\nevent mime_one_header(c: connection, h: mime_header_rec)\n{\nif ( ! c?$smtp || ! h?$value ) return;\nif ( shellshock_pattern !in h$value ) return;\n\n# generate a notice of the SMTP exploit attempt\nNOTICE([$note=Shellshock_SMTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock SMTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",h$value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,h$value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(h$value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in h$value )\n find_domain(h$value);\n}\n\n# event to identify endpoints connecting to IP addresses seen in shellshock exploit attempts\nevent connection_state_remove(c: connection)\n{\nif ( c$id$resp_h in shellshock_servers )\n # generate a notice of connection to IP address seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to an IP address seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"IP address: %s\",c$id$resp_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"# Monitors traffic for Shellshock exploit attempts\n# When exploits are seen containing IP addresses and domain values, monitors traffic for 60 minutes watching for endpoints to connect to IP addresses and domains seen in exploit attempts\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n@load base\/protocols\/dhcp\n@load base\/protocols\/smtp\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Shellshock_DHCP,\n Shellshock_HTTP,\n Shellshock_SMTP,\n Shellshock_Successful_Conn\n };\n}\n\nconst shellshock_pattern = \/((\\(|%28)(\\)|%29)( |%20)(\\{|%7B)|(\\{|%7B)(\\:|%3A)(\\;|%3B))\/ &redef;\n\nconst shellshock_commands = \/wget\/ | \/curl\/;\n\nglobal shellshock_servers: set[addr] &create_expire=60min &synchronized;\nglobal shellshock_hosts: set[string] &create_expire=60min &synchronized;\n\n# function to locate and extract domains seen in shellshock exploit attempts\nfunction find_domain(ss: string)\n{\nlocal parts1 = split_all(ss,\/[[:space:]]\/);\nfor ( p in parts1 )\n if ( \"http\" in parts1[p] )\n {\n local parts2 = split_all(parts1[p],\/\\\/\/);\n local output = parts2[5];\n }\n\nif ( output !in shellshock_hosts )\n add shellshock_hosts[output];\n}\n\n# function to locate and extract IP addresses seen in shellshock exploit attempts\nfunction find_ip(ss: string): bool\n{\nlocal b = F;\nlocal remote_servers = find_ip_addresses(ss);\n\nif ( |remote_servers| > 0 )\n {\n b = T;\n for ( rs in remote_servers )\n {\n local s = to_addr(remote_servers[rs]);\n if ( s !in shellshock_servers )\n add shellshock_servers[s];\n }\n }\n\nreturn b;\n}\n\n# event to identify shellshock HTTP exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3\n{\nif ( ! is_orig ) return;\nif ( shellshock_pattern !in value ) return;\n\n# generate a notice of the HTTP exploit attempt\nNOTICE([$note=Shellshock_HTTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock HTTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in value )\n find_domain(value);\n}\n\n# event to identify shellshock DHCP exploit attempts\nevent dhcp_ack(c: connection, msg: dhcp_msg, mask: addr, router: dhcp_router_list, lease: interval, serv_addr: addr, host_name: string)\n{\nif ( shellshock_pattern !in host_name ) return;\n\n# generate a notice of the DHCP exploit attempt\nNOTICE([$note=Shellshock_DHCP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock DHCP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",host_name),\n $identifier=cat(c$id$orig_h,c$id$resp_h,host_name)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(host_name) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in host_name )\n find_domain(host_name);\n}\n\n# event to identify endpoints connecting to domains seen in shellshock exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=5\n{\nif ( name != \"HOST\" ) return;\nif ( value in shellshock_hosts )\n # generate a notice of HTTP connection to domain seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to a domain seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"Domain: %s\",value),\n $identifier=cat(c$id$orig_h,value)]);\n}\n\nevent mime_one_header(c: connection, h: mime_header_rec)\n{\nif ( ! c?$smtp || ! h?$value ) return;\nif ( shellshock_pattern !in h$value ) return;\n\nNOTICE([$note=Shellshock_SMTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock SMTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",h$value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,h$value)]);\n\nif ( find_ip(h$value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in h$value )\n find_domain(h$value);\n}\n\n# event to identify endpoints connecting to IP addresses seen in shellshock exploit attempts\nevent connection_state_remove(c: connection)\n{\nif ( c$id$resp_h in shellshock_servers )\n # generate a notice of connection to IP address seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to an IP address seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"IP address: %s\",c$id$resp_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"50a865a75918f388823f62c4077a7081810d6f26","subject":"Renamed log file for consistency and corrected a comment error.","message":"Renamed log file for consistency and corrected a comment error.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t};\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=10secs;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal text_ip = \"\";\n\tlocal parts: string_array;\n\tif ( \/\\[.*\\]\/ in header )\n\t\tparts = split(header, \/[\\[\\]]\/);\n\telse if ( \/\\(.*\\)\/ in header )\n\t\tparts = split(header, \/[\\(\\)]\/);\n\n\tif (|parts| > 1)\n\t\t{\n\t\tif ( |parts| > 3 && parts[4] == ip_addr_regex )\n\t\t\ttext_ip = parts[4];\n\t\telse if ( parts[2] == ip_addr_regex )\n\t\t\ttext_ip = parts[2];\n\t\t}\n\treturn text_ip;\n}\n\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\t\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\n\tif ( \/^[^[:blank:]]*?:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tdelete in_received_from_headers[id];\n\tif ( \/^Received:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tadd in_received_from_headers[id];\n\t\n\tlocal session = smtp_sessions[id];\n\t\n\tif ( session$in_header && # headers are currently being analyzed \n\t id in in_received_from_headers && # currently seeing received from headers\n\t id !in smtp_received_finished && # we don't want to stop seeing this message yet\n\t \/[\\[\\(]\/ in data ) # the line might contain an ip address\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n \n\t\t# check for valid-ish ip - some mtas are weird.\n\t\tif ( is_valid_ip(text_ip) )\n\t\t\t{\n\t\t\tlocal ip = to_addr(text_ip);\n\t\t\t\n\t\t\t# I don't care if mail bounces around on localhost\n\t\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\t\n\t\t\tif ( ip_matches_hosts(ip, mail_path_capture) || \n\t\t\t ip in private_address_space )\n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t} \n\t\t\telse \n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t\n\t\t\t\tadd smtp_received_finished[id]; \n\t\t\t\t}\n\t\t\t}\n\t\t} \n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\t{\n\t\tadd smtp_received_finished[id];\n\t\t}\n\t}\n\n\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tif ( id !in conn_info )\n\t\treturn;\n\tlocal conn_log = conn_info[id];\n\t\n\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t conn_log$helo, conn_log$msg_id, conn_log$in_reply_to, \n\t conn_log$mailfrom, fmt_str_set(conn_log$rcptto, \/[\\\"\\'<>]|([[:blank:]].*$)\/),\n\t conn_log$date, conn_log$from, conn_log$reply_to, fmt_str_set(conn_log$to, \/[\\\"\\']\/),\n\t conn_log$last_reply, smtp_forward_paths[id]);\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( code >= 400 && id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# If a local MTA receives a message from a remote host telling it that it's on a block list, raise a notice.\n\t\tif ( smtp_bl_error_messages in msg && is_local_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\t# TODO: make this work with IPv6\n\t\t\tlocal msg_parts = split_all(msg, \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |msg_parts| > 2 )\n\t\t\t\ttext_ip = msg_parts[2];\n\t\t\tif ( is_valid_ip(text_ip) && to_addr(text_ip) == c$id$orig_h )\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\n\t\t\tNOTICE([$note=note, \n\t\t\t $conn=c, \n\t\t\t $msg=fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h),\n\t\t\t $sub=fmt(\"Remote host said: %s\", msg)]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id in smtp_sessions )\n\t\t{\n\t\tif ( id !in conn_info )\n\t\t\tconn_info[id] = default_session_info();\n\t\tlocal conn_log = conn_info[id];\n\t\t\n\t\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\t\tconn_log$helo = arg;\n\t\t\n\t\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\t\n\t\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t\t{\n\t\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t \treturn;\n\n\tlocal conn_log = conn_info[id];\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]\/ in data )\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[dD][aA][tT][eE]:[[:blank:]]\/ in data )\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[fF][rR][oO][mM]:[[:blank:]]\/ in data )\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[tT][oO]:[[:blank:]]\/ in data )\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\n\tif ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp_ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t};\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# ExternalHosts - only capture the path until an internal host is found.\n\t# InternalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=10secs;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal text_ip = \"\";\n\tlocal parts: string_array;\n\tif ( \/\\[.*\\]\/ in header )\n\t\tparts = split(header, \/[\\[\\]]\/);\n\telse if ( \/\\(.*\\)\/ in header )\n\t\tparts = split(header, \/[\\(\\)]\/);\n\n\tif (|parts| > 1)\n\t\t{\n\t\tif ( |parts| > 3 && parts[4] == ip_addr_regex )\n\t\t\ttext_ip = parts[4];\n\t\telse if ( parts[2] == ip_addr_regex )\n\t\t\ttext_ip = parts[2];\n\t\t}\n\treturn text_ip;\n}\n\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\t\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\n\tif ( \/^[^[:blank:]]*?:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tdelete in_received_from_headers[id];\n\tif ( \/^Received:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tadd in_received_from_headers[id];\n\t\n\tlocal session = smtp_sessions[id];\n\t\n\tif ( session$in_header && # headers are currently being analyzed \n\t id in in_received_from_headers && # currently seeing received from headers\n\t id !in smtp_received_finished && # we don't want to stop seeing this message yet\n\t \/[\\[\\(]\/ in data ) # the line might contain an ip address\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n \n\t\t# check for valid-ish ip - some mtas are weird.\n\t\tif ( is_valid_ip(text_ip) )\n\t\t\t{\n\t\t\tlocal ip = to_addr(text_ip);\n\t\t\t\n\t\t\t# I don't care if mail bounces around on localhost\n\t\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\t\n\t\t\tif ( ip_matches_hosts(ip, mail_path_capture) || \n\t\t\t ip in private_address_space )\n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t} \n\t\t\telse \n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t\n\t\t\t\tadd smtp_received_finished[id]; \n\t\t\t\t}\n\t\t\t}\n\t\t} \n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\t{\n\t\tadd smtp_received_finished[id];\n\t\t}\n\t}\n\n\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tif ( id !in conn_info )\n\t\treturn;\n\tlocal conn_log = conn_info[id];\n\t\n\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t conn_log$helo, conn_log$msg_id, conn_log$in_reply_to, \n\t conn_log$mailfrom, fmt_str_set(conn_log$rcptto, \/[\\\"\\'<>]|([[:blank:]].*$)\/),\n\t conn_log$date, conn_log$from, conn_log$reply_to, fmt_str_set(conn_log$to, \/[\\\"\\']\/),\n\t conn_log$last_reply, smtp_forward_paths[id]);\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( code >= 400 && id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# If a local MTA receives a message from a remote host telling it that it's on a block list, raise a notice.\n\t\tif ( smtp_bl_error_messages in msg && is_local_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\t# TODO: make this work with IPv6\n\t\t\tlocal msg_parts = split_all(msg, \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |msg_parts| > 2 )\n\t\t\t\ttext_ip = msg_parts[2];\n\t\t\tif ( is_valid_ip(text_ip) && to_addr(text_ip) == c$id$orig_h )\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\n\t\t\tNOTICE([$note=note, \n\t\t\t $conn=c, \n\t\t\t $msg=fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h),\n\t\t\t $sub=fmt(\"Remote host said: %s\", msg)]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id in smtp_sessions )\n\t\t{\n\t\tif ( id !in conn_info )\n\t\t\tconn_info[id] = default_session_info();\n\t\tlocal conn_log = conn_info[id];\n\t\t\n\t\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\t\tconn_log$helo = arg;\n\t\t\n\t\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\t\n\t\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t\t{\n\t\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t \treturn;\n\n\tlocal conn_log = conn_info[id];\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]\/ in data )\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[dD][aA][tT][eE]:[[:blank:]]\/ in data )\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[fF][rR][oO][mM]:[[:blank:]]\/ in data )\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[tT][oO]:[[:blank:]]\/ in data )\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\n\tif ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"8e63557ff03d6ae17b0de104bcfda29d4c4d353b","subject":"only keep track of individual connections for 1 minute.","message":"only keep track of individual connections for 1 minute.\n\nA machine spamming wouldn't have the same connection open for very long.\nEven if it does, if we see more rejects after 1 minute, it doesn't hurt to\ncount them. This would esentially count '1 rejection per connection per\nminute', instead of 'at most 1 rejection per connection'\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id] &create_expire=1m;\n local blarg: set[conn_id] &create_expire=1m;\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id];\n local blarg: set[conn_id];\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"4a823880a48e238941ab3b093c1f4c5596ccef99","subject":"Delete detect-mac-iworm.bro","message":"Delete detect-mac-iworm.bro\n\nIneffective w\/o TLS termination","repos":"unusedPhD\/CrowdStrike_cs-bro,CrowdStrike\/cs-bro,albertzaharovits\/cs-bro,kingtuna\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/mac-backdoor-iworm\/detect-mac-iworm.bro","new_file":"bro-scripts\/mac-backdoor-iworm\/detect-mac-iworm.bro","new_contents":"","old_contents":"# Detects endpoints searching Reddit for values related to the Mac.BackDoor.iWorm malware\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/http\n@load base\/frameworks\/notice\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Mac_BackDoor_iWorm,\n };\n}\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat)\n{\n# stop processing the event if an endpoint is not searching Reddit\nif ( ! is_orig || ! c$http?$host || ! c$http?$uri ) return;\nif ( c$http$host != \"www.reddit.com\" ) return;\nif ( \"?q=\" !in c$http$uri ) return;\n\n# locate and extract the Reddit search value\nlocal clean_reddit_uri = find_last(c$http$uri,\/\\?q\\=.*\/);\nlocal uri_parts = split_all(clean_reddit_uri,\/&\/);\nlocal extract_reddit_search = split1(uri_parts[1],\/\\?q\\=\/);\n\n# confirm that the search value is 8 bytes of an MD5 hash\nif ( |extract_reddit_search[2]| == 16 && extract_reddit_search[2] == \/^[A-Fa-f0-9]{16}$\/ )\n NOTICE([$note=Mac_BackDoor_iWorm,\n $conn=c,\n $msg=fmt(\"%s connected to a Reddit page that may be related to Mac.BackDoor.iWorm\",c$id$orig_h),\n $sub=c$http$uri,\n $identifier=cat(c$id$orig_h,c$http$uri)]);\n}\n\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"e86bdb4b22ccf7e0468c58a7a08dbd5b7739cb09","subject":"unregister balanced connectors on broken pipe.","message":"unregister balanced connectors on broken pipe.\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_receiver.bro","new_file":"scripts_master\/bro_receiver.bro","new_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n log_bro(\"Bro Master log access event!\");\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n log_bro(\"Bro Master log mysql event!\");\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n local inc: string = \"Incoming connection extablished \" + peer_name;\n log_bro(inc);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local inc: string = \"Incoming connection broken for \" + peer_name;\n log_bro(inc);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Registering new slave \" + peer_name);\n slaves[peer_name] = 0;\n # TODO realance clients to this new slave\n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Registering new connector \" + peer_name);\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n local size = |slaves|;\n\n if (size <= 0) {\n log_bro(\"No slaves are registered, cannot register connector \" + peer_name);\n print \"should return\";\n return;\n }\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n \n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n if (best_slave != \"\") {\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not register connector \", peer_name;\n log_bro(\"Could not register connector \" + peer_name);\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Unregistering old slave \" + peer_name);\n delete slaves[peer_name];\n # TODO rebalance\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n }\n Broker::erase(connectors, Broker::data(peer_name));\n print \"Unregistered old connector\", peer_name, \"leaving slave table\", slaves;\n log_bro(\"Unregistered old connector \" + peer_name);\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}","old_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n log_bro(\"Bro Master log access event!\");\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n log_bro(\"Bro Master log mysql event!\");\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n local inc: string = \"Incoming connection extablished \" + peer_name;\n log_bro(inc);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local inc: string = \"Incoming connection broken for \" + peer_name;\n log_bro(inc);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Registering new slave \" + peer_name);\n slaves[peer_name] = 0;\n # TODO balance clients to this new slave\n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Registering new connector \" + peer_name);\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n local size = |slaves|;\n\n print \"size\", size;\n if (size <= 0) {\n log_bro(\"No slaves are registered, cannot register connector \" + peer_name);\n print \"should return\";\n return;\n }\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n print \"slave\", slave, \"count_conn\", count_conn;\n \n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n if (best_slave != \"\") {\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n print \"Registered connector \", peer_name, \" and balanced to \", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not register connector \", peer_name;\n log_bro(\"Could not register connector \" + peer_name);\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Unregistering old slave \" + peer_name);\n delete slaves[peer_name];\n # TODO rebalance\n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Unregistering old connector \" + peer_name);\n Broker::erase(connectors, Broker::data(peer_name));\n # TODO decrement slaves for the connector\n }\n}","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"52704ce44238692cdba18a364b5420111840f498","subject":"don't keep track of connections at all","message":"don't keep track of connections at all\n\ndon't even bother keeping track of connections, just count status codes\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes)\n ++foo$rejects;\n\n ++foo$total;\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id] &create_expire=1m;\n local blarg: set[conn_id] &create_expire=1m;\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"befca51d54a699b6503224ba5a79ead16f2ca9e1","subject":"log clear text password users.. for now just pop3","message":"log clear text password users.. for now just pop3\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"simple-clear-passwords.bro","new_file":"simple-clear-passwords.bro","new_contents":"global clear_log_file = open_log_file(\"clear-password-users\") &raw_output;\n\nredef capture_filters += { [\"pop3\"] = \"port 110\" };\n\nglobal pop3_ports = { 110\/tcp } &redef;\nredef dpd_config += { [ANALYZER_POP3] = [$ports = pop3_ports] };\n\nevent pop3_request(c: connection, is_orig: bool, command: string, arg: string)\n{\n}\n\n\nevent pop3_login_success(c: connection, is_orig: bool,\n user: string, password: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n print clear_log_file, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n c$id$orig_h,\n c$id$resp_h,\n port_to_count(c$id$resp_p),\n \"success\",\n user);\n}\n\n\nevent pop3_login_failure(c: connection, is_orig: bool,\n user: string, password: string)\n{\n if(!is_local_addr(c$id$orig_h))\n return;\n print clear_log_file, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n c$id$orig_h,\n c$id$resp_h,\n port_to_count(c$id$resp_p),\n \"failure\",\n user);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'simple-clear-passwords.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"90aa07de342d35f7438beabc2221123b0ce392ac","subject":"only log incoming","message":"only log incoming\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"log-http-sqli.bro","new_file":"log-http-sqli.bro","new_contents":"event bro_init()\n{\n Log::add_filter(HTTP::LOG, [$name = \"http-sqli\",\n $path = \"http_sqli\",\n $pred(rec: HTTP::Info) = { return HTTP::URI_SQLI in rec$tags && Site::is_local_addr(rec$id$resp_h); }\n ]);\n}\n","old_contents":"event bro_init()\n{\n Log::add_filter(HTTP::LOG, [$name = \"http-sqli\",\n $path = \"http_sqli\",\n $pred(rec: HTTP::Info) = { return HTTP::URI_SQLI in rec$tags ; }\n ]);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"3516396f8b9b4fe58988d00adc375d7b7bf44e1c","subject":"Fixed a problem with the list of HTTP proxying headers. They were using underscores instead of hyphens so most were never matching.","message":"Fixed a problem with the list of HTTP proxying headers. They were using underscores instead of hyphens so most were never matching.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext.bro","new_file":"http-ext.bro","new_contents":"@load global-ext\n@load http-request\n@load http-entity\n\ntype http_ext_session_info: record {\n\tstart_time: time;\n\tmethod: string &default=\"\";\n\thost: string &default=\"\";\n\turi: string &default=\"\";\n\turl: string &default=\"\";\n\treferrer: string &default=\"\";\n\tuser_agent: string &default=\"\";\n\tproxied_for: string &default=\"\";\n\n\tforce_log: bool &default=F; # This will force the request to be logged (if doing any logging)\n\tforce_log_client_body: bool &default=F; # This will force the client body to be logged.\n\tforce_log_reasons: set[string]; # Reasons why the forced logging happened.\n\t\n\t# This is internal state tracking.\n\tfull: bool &default=F;\n\tnew_user_agent: bool &default=F;\n};\n\nfunction default_http_ext_session_info(): http_ext_session_info\n\t{\n\tlocal x: http_ext_session_info;\n\tlocal tmp: set[string] = set();\n\tx$start_time=network_time();\n\tx$force_log_reasons=tmp;\n\treturn x;\n\t}\n\ntype http_ext_activity_count: record {\n\tsql_injections: track_count;\n\tsql_injection_probes: track_count;\n\tsuspicious_posts: track_count;\n};\n\nfunction default_http_ext_activity_count(a:addr):http_ext_activity_count \n\t{\n\tlocal x: http_ext_activity_count; \n\treturn x; \n\t}\n\n# Define the generic http_ext events that can be handled from other scripts\nglobal http_ext: event(id: conn_id, si: http_ext_session_info);\n\nmodule HTTP;\n\n# Uncomment the following lines if you have these data sets available and would\n# like to use them.\n#@load malware_com_br_block_list-data\n#@load zeus-data\n#@load malwaredomainlist-data\n\nexport {\n\tredef enum Notice += { \n\t\tHTTP_Suspicious,\n\t\tHTTP_SQL_Injection_Attack,\n\t\tHTTP_SQL_Injection_Heavy_Probing,\n\n\t\tHTTP_Malware_com_br_Block_List,\n\t\tHTTP_Zeus_Communication,\n\t\tHTTP_MalwareDomainList_Communication,\n\t};\n\n\t# This is the regular expression that is used to match URI based SQL injections\n\tconst sql_injection_regex = \n\t\t \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[iI][nN][sS][eE][rR][tT])[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([oO][rR]|[aA][nN][dD])([[:blank:]]|\\\/\\*.*?\\*\\\/)+['\"]?[^a-zA-Z&]+?=\/\n\t\t| \/[\\?&][^[:blank:]]+?=[\\-0-9%]*([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/)*(\\-|\\+|\\|\\|)([[:blank:]]|\\\/\\*.*?\\*\\\/)*([0-9]|\\(?[cC][oO][nN][vV][eE][rR][tT]|[cC][aA][sS][tT])\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/|;)*([oO][rR]|[aA][nN][dD]|[hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[rR][eE][gG][eE][xX][pP]|[iI][nN][sS][eE][rR][tT]|\\()[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]]+?=[^\\.]*?([cC][hH][aA][rR]|[aA][sS][cC][iI][iI]|[sS][uU][bB][sS][tT][rR][iI][nN][gG]|[tT][rR][uU][nN][cC][aA][tT][eE]|[vV][eE][rR][sS][iI][oO][nN]|[lL][eE][nN][gG][tT][hH])\\(\/ &redef;\n\n\t# SQL injection probes are considered to be:\n\t# 1. A single single-quote at the end of a URL with no other single-quotes.\n\t# 2. URLs with one single quote at the end of a normal GET value.\n\tconst sql_injection_probe_regex =\n\t\t \/^[^\\']+\\'$\/\n\t\t| \/^[^\\']+\\'&[^\\']*$\/ &redef;\n\n\t# Define which hosts user-agents you'd like to track.\n\tconst track_user_agents_for = LocalHosts &redef;\n\n\t# If there is something creating large number of strange user-agent,\n\t# you can filter those out with this pattern.\n\tconst ignored_user_agents = \/DONT_MATCH_ANYTHING\/ &redef;\n\n\t# HTTP post data contents that appear suspicious.\n\t# This is usually spammy forum postings and the like.\n\tconst suspicious_http_posts = \n\t\t\/[vV][iI][aA][gG][rR][aA]\/ | \n\t\t\/[tT][rR][aA][mM][aA][dD][oO][lL]\/ |\n\t\t\/[cC][iI][aA][lL][iI][sS]\/ | \n\t\t\/[sS][oO][mM][aA]\/ | \n\t\t\/[hH][yY][dD][rR][oO][cC][oO][dD][oO][nN][eE]\/ |\n\t\t\/[cC][aA][nN][aA][dD][iI][aA][nN].{0,15}[pP][hH][aA][rR][mM][aA][cC][yY]\/ |\n\t\t\/[rR][iI][nN][gG].?[tT][oO][nN][eE]\/ |\n\t\t\/[pP][eE][nN][iI][sS]\/ |\n\t\t\/[oO][nN][lL][iI][nN][eE].?[cC][aA][sS][iI][nN][oO]\/ |\n\t\t\/[rR][eE][mM][oO][rR][tT][gG][aA][gG][eE][sS]\/ |\n\t\t# more than 4 bbcode style links in a POST is deemed suspicious\n\t\t\/(url=http:.*){4}\/ | \n\t\t# more that 4 html links is also suspicious\n\t\t\/(a.href(=|%3[dD]).*){4}\/ &redef;\n\t\t\n\t# The list of HTTP headers typically used to indicate a proxied request.\n\tconst http_forwarded_headers: set[string] = {\n\t\t\"HTTP-FORWARDED\",\n\t\t\"FORWARDED\",\n\t\t\"HTTP-X-FORWARDED-FOR\",\n\t\t\"X-FORWARDED-FOR\",\n\t\t\"HTTP-X-FORWARDED-FROM\",\n\t\t\"X-FORWARDED-FROM\",\n\t\t\"HTTP-CLIENT-IP\",\n\t\t\"CLIENT-IP\",\n\t\t\"HTTP-FROM\",\n\t\t\"FROM\",\n\t\t\"HTTP-VIA\",\n\t\t\"VIA\",\n\t\t\"HTTP-XROXY-CONNECTION\",\n\t\t\"XROXY-CONNECTION\",\n\t\t\"HTTP-PROXY-CONNECTION\",\n\t\t\"PROXY-CONNECTION\",\n\t} &redef;\n\n\tglobal conn_info: table[conn_id] of http_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\n\tglobal activity_counters: table[addr] of http_ext_activity_count \n\t\t&create_expire=1day \n\t\t&synchronized\n\t\t&default=default_http_ext_activity_count\n\t\t&redef;\n\n\t# You can inspect this during runtime from other modules to see what\n\t# user-agents a host has used.\n\tglobal known_user_agents: table[addr] of set[string] \n\t\t&create_expire=3hrs\n\t\t&synchronized\n\t\t&default=addr_empty_string_set\n\t\t&redef;\n}\n\n# This is called from signatures (theoretically)\nfunction log_post(state: signature_state, data: string): bool\n\t{\n\t# Log the post data when it becomes available.\n\tif ( state$conn$id in conn_info )\n\t\t{\n\t\tconn_info[state$conn$id]$force_log_client_body = T;\n\t\tadd conn_info[state$conn$id]$force_log_reasons[fmt(\"matched_signature_%s\",state$id)];\n\t\t}\n\t\n\t# We'll always allow the signature to fire\n\treturn T;\n\t}\n\t\nevent http_request(c: connection, method: string, original_URI: string,\n\t unescaped_URI: string, version: string)\n\t{\n\tif ( c$id !in conn_info )\n\t\t{\n\t\tlocal x = default_http_ext_session_info();\n\t\tconn_info[c$id] = x;\n\t\t}\n\t\n\tlocal sess_ext = conn_info[c$id];\n\tsess_ext$method = method;\n\tsess_ext$uri = unescaped_URI;\n\t}\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &priority=5\n\t{\n\tif ( !is_orig )\n\t\treturn; \n\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t\treturn;\n\t\n\tlocal sess_ext = conn_info[id];\n\tsess_ext$url = fmt(\"http:\/\/%s%s\", sess_ext$host, sess_ext$uri);\n\n\t# Detect and log SQL injection attempts in their own log file\n\tif ( sql_injection_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection\"];\n\t\t\n\t\t++(activity_counters[id$orig_h]$sql_injections$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[id$orig_h]$sql_injections) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Attack,\n\t\t\t $msg=fmt(\"SQL injection attack (n=%d): %s -> %s\",\n\t\t\t activity_counters[id$orig_h]$sql_injections$n,\n\t\t\t numeric_id_string(id), sess_ext$url),\n\t\t\t $conn=c,\n\t\t\t $n=activity_counters[id$orig_h]$sql_injections$n]);\n\t\t\t}\n\t\t}\n\tif ( sql_injection_probe_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection_probe\"];\n\t\t++(activity_counters[id$orig_h]$sql_injection_probes$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[c$id$orig_h]$sql_injection_probes) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Heavy_Probing, \n\t\t\t $msg=fmt(\"Heavy probing from %s\", id$orig_h), \n\t\t\t $n=activity_counters[c$id$orig_h]$sql_injection_probes$n, \n\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\n@ifdef ( MalwareComBr_BlockList )\n\tif ( MalwareComBr_BlockList in sess_ext$url )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malware_com_br\"];\n\t\tlocal malware_com_br_msg = fmt(\"%s %s %s\", sess_ext$method, sess_ext$url, sess_ext$referrer);\n\t\tNOTICE([$note=HTTP_Malware_com_br_Block_List, $msg=malware_com_br_msg, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( ZeusDomains )\n\tif ( sess_ext$host in ZeusDomains )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"zeustracker\"];\n\t\tlocal zeus_msg = fmt(\"%s communicated with likely Zeus controller at %s\", c$id$orig_h, sess_ext$host);\n\t\tNOTICE([$note=HTTP_Zeus_Communication, $msg=zeus_msg, $sub=sess_ext$url, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( MalwareDomainList )\n\tif ( sess_ext$url in MalwareDomainList )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malwaredomainlist\"];\n\t\tlocal mdl_msg = fmt(\"%s communicated with malwaredomainlist.com URL at %s\", c$id$orig_h, sess_ext$url);\n\t\tNOTICE([$note=HTTP_MalwareDomainList_Communication, $msg=mdl_msg, $sub=MalwareDomainList[sess_ext$url], $conn=c]);\n\t\t}\n@endif\n\n\tevent http_ext(id, sess_ext);\n\t\n\t# No data from the reply is supported yet, so it's ok to delete here.\n\tdelete conn_info[c$id];\n\t}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in conn_info )\n\t\tconn_info[c$id] = default_http_ext_session_info();\n\n\tlocal ci = conn_info[c$id];\n\n\tif ( name == \"REFERER\" )\n\t\tci$referrer = value;\n\t\t\n\telse if ( name == \"HOST\" )\n\t\tci$host = value;\n\n\telse if ( name == \"USER-AGENT\" )\n\t\t{\n\t\tci$user_agent = value;\n\t\t\n\t\tif ( ignored_user_agents in value ) \n\t\t\treturn;\n\t\t\t\n\t\tif ( addr_matches_hosts(c$id$orig_h, track_user_agents_for) &&\n\t\t\t value !in known_user_agents[c$id$orig_h] )\n\t\t\t{\n\t\t\tif ( c$id$orig_h !in known_user_agents )\n\t\t\t\tknown_user_agents[c$id$orig_h] = set();\n\t\t\tadd known_user_agents[c$id$orig_h][value];\n\t\t\tci$new_user_agent = T;\n\t\t\t}\n\t\t}\n\n\telse if ( name in http_forwarded_headers )\n\t\t{\n\t\tif ( ci$proxied_for == \"\" )\n\t\t\tci$proxied_for = fmt(\"(%s::%s)\", name, value);\n\t\telse\n\t\t\tci$proxied_for = fmt(\"%s, (%s::%s)\", ci$proxied_for, name, value);\n\t\t}\n\t\t\n\telse if ( name == \"X-FLASH-VERSION\" )\n\t\t{\n\t\tlocal vt = split_all(value, \/,\/);\n\t\tif ( |vt| > 3 )\n\t\t\t{\n\t\t\tlocal v: software_version = [$major=to_int(vt[1]),\n\t\t\t $minor=to_int(vt[2]),\n\t\t\t $minor2=to_int(vt[3]),\n\t\t\t $addl=vt[4]];\n\t\t\tlocal s: software = [$name=\"AdobeFlashPlayer\", $version=v];\n\t\t\tevent software_version_found(c, c$id$orig_h, s, \"\");\n\t\t\t}\n\t\t}\n\t}\n","old_contents":"@load global-ext\n@load http-request\n@load http-entity\n\ntype http_ext_session_info: record {\n\tstart_time: time;\n\tmethod: string &default=\"\";\n\thost: string &default=\"\";\n\turi: string &default=\"\";\n\turl: string &default=\"\";\n\treferrer: string &default=\"\";\n\tuser_agent: string &default=\"\";\n\tproxied_for: string &default=\"\";\n\n\tforce_log: bool &default=F; # This will force the request to be logged (if doing any logging)\n\tforce_log_client_body: bool &default=F; # This will force the client body to be logged.\n\tforce_log_reasons: set[string]; # Reasons why the forced logging happened.\n\t\n\t# This is internal state tracking.\n\tfull: bool &default=F;\n\tnew_user_agent: bool &default=F;\n};\n\nfunction default_http_ext_session_info(): http_ext_session_info\n\t{\n\tlocal x: http_ext_session_info;\n\tlocal tmp: set[string] = set();\n\tx$start_time=network_time();\n\tx$force_log_reasons=tmp;\n\treturn x;\n\t}\n\ntype http_ext_activity_count: record {\n\tsql_injections: track_count;\n\tsql_injection_probes: track_count;\n\tsuspicious_posts: track_count;\n};\n\nfunction default_http_ext_activity_count(a:addr):http_ext_activity_count \n\t{\n\tlocal x: http_ext_activity_count; \n\treturn x; \n\t}\n\n# Define the generic http_ext events that can be handled from other scripts\nglobal http_ext: event(id: conn_id, si: http_ext_session_info);\n\nmodule HTTP;\n\n# Uncomment the following lines if you have these data sets available and would\n# like to use them.\n#@load malware_com_br_block_list-data\n#@load zeus-data\n#@load malwaredomainlist-data\n\nexport {\n\tredef enum Notice += { \n\t\tHTTP_Suspicious,\n\t\tHTTP_SQL_Injection_Attack,\n\t\tHTTP_SQL_Injection_Heavy_Probing,\n\n\t\tHTTP_Malware_com_br_Block_List,\n\t\tHTTP_Zeus_Communication,\n\t\tHTTP_MalwareDomainList_Communication,\n\t};\n\n\t# This is the regular expression that is used to match URI based SQL injections\n\tconst sql_injection_regex = \n\t\t \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[iI][nN][sS][eE][rR][tT])[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([oO][rR]|[aA][nN][dD])([[:blank:]]|\\\/\\*.*?\\*\\\/)+['\"]?[^a-zA-Z&]+?=\/\n\t\t| \/[\\?&][^[:blank:]]+?=[\\-0-9%]*([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/)*(\\-|\\+|\\|\\|)([[:blank:]]|\\\/\\*.*?\\*\\\/)*([0-9]|\\(?[cC][oO][nN][vV][eE][rR][tT]|[cC][aA][sS][tT])\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/|;)*([oO][rR]|[aA][nN][dD]|[hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[rR][eE][gG][eE][xX][pP]|[iI][nN][sS][eE][rR][tT]|\\()[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]]+?=[^\\.]*?([cC][hH][aA][rR]|[aA][sS][cC][iI][iI]|[sS][uU][bB][sS][tT][rR][iI][nN][gG]|[tT][rR][uU][nN][cC][aA][tT][eE]|[vV][eE][rR][sS][iI][oO][nN]|[lL][eE][nN][gG][tT][hH])\\(\/ &redef;\n\n\t# SQL injection probes are considered to be:\n\t# 1. A single single-quote at the end of a URL with no other single-quotes.\n\t# 2. URLs with one single quote at the end of a normal GET value.\n\tconst sql_injection_probe_regex =\n\t\t \/^[^\\']+\\'$\/\n\t\t| \/^[^\\']+\\'&[^\\']*$\/ &redef;\n\n\t# Define which hosts user-agents you'd like to track.\n\tconst track_user_agents_for = LocalHosts &redef;\n\n\t# If there is something creating large number of strange user-agent,\n\t# you can filter those out with this pattern.\n\tconst ignored_user_agents = \/DONT_MATCH_ANYTHING\/ &redef;\n\n\t# HTTP post data contents that appear suspicious.\n\t# This is usually spammy forum postings and the like.\n\tconst suspicious_http_posts = \n\t\t\/[vV][iI][aA][gG][rR][aA]\/ | \n\t\t\/[tT][rR][aA][mM][aA][dD][oO][lL]\/ |\n\t\t\/[cC][iI][aA][lL][iI][sS]\/ | \n\t\t\/[sS][oO][mM][aA]\/ | \n\t\t\/[hH][yY][dD][rR][oO][cC][oO][dD][oO][nN][eE]\/ |\n\t\t\/[cC][aA][nN][aA][dD][iI][aA][nN].{0,15}[pP][hH][aA][rR][mM][aA][cC][yY]\/ |\n\t\t\/[rR][iI][nN][gG].?[tT][oO][nN][eE]\/ |\n\t\t\/[pP][eE][nN][iI][sS]\/ |\n\t\t\/[oO][nN][lL][iI][nN][eE].?[cC][aA][sS][iI][nN][oO]\/ |\n\t\t\/[rR][eE][mM][oO][rR][tT][gG][aA][gG][eE][sS]\/ |\n\t\t# more than 4 bbcode style links in a POST is deemed suspicious\n\t\t\/(url=http:.*){4}\/ | \n\t\t# more that 4 html links is also suspicious\n\t\t\/(a.href(=|%3[dD]).*){4}\/ &redef;\n\t\t\n\tconst http_forwarded_headers = {\n\t\t\"HTTP_FORWARDED\",\n\t\t\"FORWARDED\",\n\t\t\"HTTP_X_FORWARDED_FOR\",\n\t\t\"X_FORWARDED_FOR\",\n\t\t\"HTTP_X_FORWARDED_FROM\",\n\t\t\"X_FORWARDED_FROM\",\n\t\t\"HTTP_CLIENT_IP\",\n\t\t\"CLIENT_IP\",\n\t\t\"HTTP_FROM\",\n\t\t\"FROM\",\n\t\t\"HTTP_VIA\",\n\t\t\"VIA\",\n\t\t\"HTTP_XROXY_CONNECTION\",\n\t\t\"XROXY_CONNECTION\",\n\t\t\"HTTP_PROXY_CONNECTION\",\n\t\t\"PROXY_CONNECTION\",\n\t} &redef;\n\n\tglobal conn_info: table[conn_id] of http_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\n\tglobal activity_counters: table[addr] of http_ext_activity_count \n\t\t&create_expire=1day \n\t\t&synchronized\n\t\t&default=default_http_ext_activity_count\n\t\t&redef;\n\n\t# You can inspect this during runtime from other modules to see what\n\t# user-agents a host has used.\n\tglobal known_user_agents: table[addr] of set[string] \n\t\t&create_expire=3hrs\n\t\t&synchronized\n\t\t&default=addr_empty_string_set\n\t\t&redef;\n}\n\n# This is called from signatures (theoretically)\nfunction log_post(state: signature_state, data: string): bool\n\t{\n\t# Log the post data when it becomes available.\n\tif ( state$conn$id in conn_info )\n\t\t{\n\t\tconn_info[state$conn$id]$force_log_client_body = T;\n\t\tadd conn_info[state$conn$id]$force_log_reasons[fmt(\"matched_signature_%s\",state$id)];\n\t\t}\n\t\n\t# We'll always allow the signature to fire\n\treturn T;\n\t}\n\t\nevent http_request(c: connection, method: string, original_URI: string,\n\t unescaped_URI: string, version: string)\n\t{\n\tif ( c$id !in conn_info )\n\t\t{\n\t\tlocal x = default_http_ext_session_info();\n\t\tconn_info[c$id] = x;\n\t\t}\n\t\n\tlocal sess_ext = conn_info[c$id];\n\tsess_ext$method = method;\n\tsess_ext$uri = unescaped_URI;\n\t}\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &priority=5\n\t{\n\tif ( !is_orig )\n\t\treturn; \n\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t\treturn;\n\t\n\tlocal sess_ext = conn_info[id];\n\tsess_ext$url = fmt(\"http:\/\/%s%s\", sess_ext$host, sess_ext$uri);\n\n\t# Detect and log SQL injection attempts in their own log file\n\tif ( sql_injection_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection\"];\n\t\t\n\t\t++(activity_counters[id$orig_h]$sql_injections$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[id$orig_h]$sql_injections) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Attack,\n\t\t\t $msg=fmt(\"SQL injection attack (n=%d): %s -> %s\",\n\t\t\t activity_counters[id$orig_h]$sql_injections$n,\n\t\t\t numeric_id_string(id), sess_ext$url),\n\t\t\t $conn=c,\n\t\t\t $n=activity_counters[id$orig_h]$sql_injections$n]);\n\t\t\t}\n\t\t}\n\tif ( sql_injection_probe_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection_probe\"];\n\t\t++(activity_counters[id$orig_h]$sql_injection_probes$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[c$id$orig_h]$sql_injection_probes) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Heavy_Probing, \n\t\t\t $msg=fmt(\"Heavy probing from %s\", id$orig_h), \n\t\t\t $n=activity_counters[c$id$orig_h]$sql_injection_probes$n, \n\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\n@ifdef ( MalwareComBr_BlockList )\n\tif ( MalwareComBr_BlockList in sess_ext$url )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malware_com_br\"];\n\t\tlocal malware_com_br_msg = fmt(\"%s %s %s\", sess_ext$method, sess_ext$url, sess_ext$referrer);\n\t\tNOTICE([$note=HTTP_Malware_com_br_Block_List, $msg=malware_com_br_msg, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( ZeusDomains )\n\tif ( sess_ext$host in ZeusDomains )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"zeustracker\"];\n\t\tlocal zeus_msg = fmt(\"%s communicated with likely Zeus controller at %s\", c$id$orig_h, sess_ext$host);\n\t\tNOTICE([$note=HTTP_Zeus_Communication, $msg=zeus_msg, $sub=sess_ext$url, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( MalwareDomainList )\n\tif ( sess_ext$url in MalwareDomainList )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malwaredomainlist\"];\n\t\tlocal mdl_msg = fmt(\"%s communicated with malwaredomainlist.com URL at %s\", c$id$orig_h, sess_ext$url);\n\t\tNOTICE([$note=HTTP_MalwareDomainList_Communication, $msg=mdl_msg, $sub=MalwareDomainList[sess_ext$url], $conn=c]);\n\t\t}\n@endif\n\n\tevent http_ext(id, sess_ext);\n\t\n\t# No data from the reply is supported yet, so it's ok to delete here.\n\tdelete conn_info[c$id];\n\t}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in conn_info )\n\t\tconn_info[c$id] = default_http_ext_session_info();\n\n\tlocal ci = conn_info[c$id];\n\n\tif ( name == \"REFERER\" )\n\t\tci$referrer = value;\n\t\t\n\telse if ( name == \"HOST\" )\n\t\tci$host = value;\n\n\telse if ( name == \"USER-AGENT\" )\n\t\t{\n\t\tci$user_agent = value;\n\t\t\n\t\tif ( ignored_user_agents in value ) \n\t\t\treturn;\n\t\t\t\n\t\tif ( addr_matches_hosts(c$id$orig_h, track_user_agents_for) &&\n\t\t\t value !in known_user_agents[c$id$orig_h] )\n\t\t\t{\n\t\t\tif ( c$id$orig_h !in known_user_agents )\n\t\t\t\tknown_user_agents[c$id$orig_h] = set();\n\t\t\tadd known_user_agents[c$id$orig_h][value];\n\t\t\tci$new_user_agent = T;\n\t\t\t}\n\t\t}\n\n\telse if ( name in http_forwarded_headers )\n\t\t{\n\t\tif ( ci$proxied_for == \"\" )\n\t\t\tci$proxied_for = fmt(\"(%s::%s)\", name, value);\n\t\telse\n\t\t\tci$proxied_for = fmt(\"%s, (%s::%s)\", ci$proxied_for, name, value);\n\t\t}\n\t\t\n\telse if ( name == \"X-FLASH-VERSION\" )\n\t\t{\n\t\tlocal vt = split_all(value, \/,\/);\n\t\tif ( |vt| > 3 )\n\t\t\t{\n\t\t\tlocal v: software_version = [$major=to_int(vt[1]),\n\t\t\t $minor=to_int(vt[2]),\n\t\t\t $minor2=to_int(vt[3]),\n\t\t\t $addl=vt[4]];\n\t\t\tlocal s: software = [$name=\"AdobeFlashPlayer\", $version=v];\n\t\t\tevent software_version_found(c, c$id$orig_h, s, \"\");\n\t\t\t}\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1746a7b1b2792bef6df06191188cdf354e9ea4a1","subject":"Remove double-comment marker to prevent Broxygen syntax warnings","message":"Remove double-comment marker to prevent Broxygen syntax warnings\n","repos":"salesforce\/ja3","old_file":"bro\/ja3.bro","new_file":"bro\/ja3.bro","new_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n## LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","old_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n## LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n## LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n## FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"78c1845ecd5db803a9b2b5fb52ccf3ca98cd6df5","subject":"Lots of fixes to dns-passive-replication. Including moving it to the logging framework.","message":"Lots of fixes to dns-passive-replication. Including moving it to the logging framework.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"dns-passive-replication.bro","new_file":"dns-passive-replication.bro","new_contents":"@load global-ext\n@load dns\n\n# Modify the DNS analyzer to give us Authority and Additional section responses.\nredef dns_skip_all_auth = F;\nredef dns_skip_all_addl = F;\n\nmodule DNS;\n\nexport {\n\t# If set to T, this will split the log into separate files.\n\t# F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t\n\t# Which DNS servers replies should be logged.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts, NoHosts\n\tconst logging_replies = AllHosts &redef;\n}\n\n# Turn off the dns.log file.\nredef logging = F;\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"dns-passive-replication\", logging_replies, split_log_file, T);\n\t\n\tLOG::define_header(\"dns-passive-replication\",\n\t cat_sep(\"\\t\", \"\\\\N\", \n\t \"ts\",\n\t \"orig_h\", \"orig_p\", \"resp_h\", \"resp_p\",\n\t \"proto\", \"query\",\n\t \"AA\", \"TTL\", \"query_class\", \"query_type\",\n\t \"annotation\", \"response\"));\n\t}\n\nconst dns_response_sections: table[count] of string = {\n\t[0] = \"QUERY\",\n\t[1] = \"ANS\",\n\t[2] = \"AUTH\",\n\t[3] = \"ADDL\",\n};\n\nfunction print_DNS_RR(c: connection, msg: dns_msg, ans: dns_answer, anno: string)\n\t{\n\tlocal log = LOG::get_file_by_addr(\"dns-passive-replication\", c$id$resp_h, F);\n\tprint log, cat_sep(\"\\t\", \"\\\\N\",\n\t network_time(),\n\t c$id$orig_h, port_to_count(c$id$orig_p),\n\t c$id$resp_h, port_to_count(c$id$resp_p),\n\t get_port_transport_proto(c$id$resp_p),\n\t ans$query,\n\t msg$AA,\n\t fmt(\"%.0f\", interval_to_double(ans$TTL)),\n\t dns_class[ans$qclass],\n\t query_types[ans$qtype],\n\t anno, \n\t dns_response_sections[ans$answer_type]);\n\t}\n\nevent dns_A_reply(c: connection, msg: dns_msg, ans: dns_answer, a: addr)\n\t{\n\tprint_DNS_RR(c, msg, ans, fmt(\"%s\", a));\n\t}\n\nevent dns_TXT_reply(c: connection, msg: dns_msg, ans: dns_answer, str: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, str);\n\t}\n\nevent dns_AAAA_reply(c: connection, msg: dns_msg, ans: dns_answer, a: addr, \n astr: string)\n\t{\n\t# TODO: not sure what's in astr\n\tprint_DNS_RR(c, msg, ans, fmt(\"%s\", a));\n\t}\n\nevent dns_MX_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string,\n preference: count)\n\t{\n\t# TODO: maybe deal with preference?\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\nevent dns_PTR_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\nevent dns_NS_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\nevent dns_CNAME_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\nevent dns_SRV_reply(c: connection, msg: dns_msg, ans: dns_answer)\n\t{\n\t# need to make a function to log this...\n\t}\n\nevent dns_SOA_reply(c: connection, msg: dns_msg, ans: dns_answer, soa: dns_soa)\n\t{\n\tprint_DNS_RR(c, msg, ans, soa$mname);\n\t}\n\nevent dns_WKS_reply(c: connection, msg: dns_msg, ans: dns_answer)\n\t{\n\t# need to make a function to log this...\n\t}\n\nevent dns_HINFO_reply(c: connection, msg: dns_msg, ans: dns_answer)\n\t{\n\t# need to make a function to log this...\n\t}\n","old_contents":"@load global-ext\n@load dns\n\n# Modify the DNS analyzer to give us Authority and Additional section responses.\nredef dns_skip_all_auth = F;\nredef dns_skip_all_addl = F;\n\nmodule DNS;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Replies to which queries to log.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\n# Turn off the dns.log file.\nredef logging = F;\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"dns-passive-replication\", logging, split_log_file, T);\n\tLOG::define_header(\"dns-passive-replication\",\n\t cat_sep(\"\\t\", \"\", \n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"username\", \"password\",\n\t \"command\", \"url\",\n\t \"reply_code\", \"reply\", \"reply_message\"));\n\t}\n\n\nconst dns_response_sections: table[count] of string = {\n\t[0] = \"QUERY\",\n\t[1] = \"ANS\",\n\t[2] = \"AUTH\",\n\t[3] = \"ADDL\",\n};\n\nfunction print_DNS_RR(c: connection, msg: dns_msg, ans: dns_answer, anno: string)\n\t{\n\tlocal output = cat_sep(\"\\t\", \"\\\\N\",\n\t network_time(),\n\t c$id$orig_h, port_to_count(c$id$orig_p),\n\t c$id$resp_h, port_to_count(c$id$resp_p),\n\t get_port_transport_proto(c$id$resp_p),\n\t ans$query,\n\t msg$AA ? 1 : 0,\n\t fmt(\"%.0f\", interval_to_double(ans$TTL)),\n\t dns_class[ans$qclass],\n\t query_types[ans$qtype],\n\t anno, \n\t dns_response_sections[ans$answer_type]);\n\t\n\tprint dns_pr_log, output;\n\t}\n\n#event dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n#\t{\n#\tprint_query(c, msg, query, qtype, qclass);\n#\t}\n\nevent dns_A_reply(c: connection, msg: dns_msg, ans: dns_answer, a: addr)\n\t{\n\tprint_DNS_RR(c, msg, ans, fmt(\"%s\", a));\n\t}\n\t\nevent dns_TXT_reply(c: connection, msg: dns_msg, ans: dns_answer, str: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, str);\n\t}\n\t\nevent dns_AAAA_reply(c: connection, msg: dns_msg, ans: dns_answer, a: addr, \n astr: string)\n\t{\n\t# TODO: not sure what's in astr\n\tprint_DNS_RR(c, msg, ans, fmt(\"%s\", a));\n\t}\n\nevent dns_MX_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string,\n preference: count)\n\t{\n\t# TODO: maybe deal with preference?\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\t\nevent dns_PTR_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\t\nevent dns_NS_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\t\nevent dns_CNAME_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\t\nevent dns_SRV_reply(c: connection, msg: dns_msg, ans: dns_answer)\n\t{\n\t# need to make a function to log this...\n\t}\n\t\nevent dns_SOA_reply(c: connection, msg: dns_msg, ans: dns_answer, soa: dns_soa)\n\t{\n\tprint_DNS_RR(c, msg, ans, soa$mname);\n\t}\n\nevent dns_WKS_reply(c: connection, msg: dns_msg, ans: dns_answer)\n\t{\n\t# need to make a function to log this...\n\t}\n\nevent dns_HINFO_reply(c: connection, msg: dns_msg, ans: dns_answer)\n\t{\n\t# need to make a function to log this...\n\t}\n\n\n\n\t\n#event dns_query_reply(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n#\t{\n#\tprint query;\n#\t}\n\n\t\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"2aa79923eecca32930bd889682f7b42436e21f41","subject":"Changed slave to use Beemaster::proto_to_string","message":"Changed slave to use Beemaster::proto_to_string\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_slave\/bro_slave.bro","new_file":"scripts_slave\/bro_slave.bro","new_contents":"@load .\/beemaster_events\n@load .\/beemaster_types\n@load .\/beemaster_log\n@load .\/beemaster_util\n\n@load base\/bif\/plugins\/Bro_TCP.events.bif\n@load base\/bif\/plugins\/Bro_UDP.events.bif\n@load base\/protocols\/conn\/main\n\nredef exit_only_after_terminate = T;\n\n# Broker setup\n# the ports and IPs that are externally routable for a master and this slave\nconst slave_broker_port: string = getenv(\"SLAVE_PUBLIC_PORT\") &redef;\nconst slave_broker_ip: string = getenv(\"SLAVE_PUBLIC_IP\") &redef;\nconst master_broker_port: port = to_port(cat(getenv(\"MASTER_PUBLIC_PORT\"), \"\/tcp\")) &redef;\nconst master_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-slave-\", slave_broker_ip, \":\", slave_broker_port);\n\nglobal base_events: set[string] = { \"Beemaster::log_conn\" };\n\nglobal tcp_events: set[string] = { \"Beemaster::tcp_event\" };\n\nglobal lattice_events: set[string] = { \"Beemaster::lattice_event\"};\n\nevent bro_init() {\n Beemaster::log(\"bro_slave.bro: bro_init()\");\n\n # Enable broker and listen for incoming connectors\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Connect to bro-master for load-balancing and relaying events\n Broker::connect(master_broker_ip, master_broker_port, 1sec);\n\n # Publish our local events to forward them to master\/acus\n Broker::register_broker_events(\"beemaster\/bro\/base\", base_events);\n\n # Publish our tcp events\n Broker::register_broker_events(\"beemaster\/bro\/tcp\", tcp_events);\n\n # Publish our lattice_events\n Broker::register_broker_events(\"beemaster\/bro\/lattice\", lattice_events);\n\n Beemaster::log(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n Beemaster::log(\"bro_slave.bro: bro_done()\");\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n Beemaster::log(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n Beemaster::log(msg);\n}\n\n# forwarding when some local connection is beeing logged. Throws an explicit beemaster event to forward.\nevent Conn::log_conn(rec: Conn::Info) {\n event Beemaster::log_conn(rec);\n event Beemaster::lattice_event(Beemaster::conninfo_to_alertinfo(c), Beemaster::proto_to_string(rec$proto)();\n}\n\nevent connection_SYN_packet(c: connection, pkt: SYN_packet) {\n event Beemaster::tcp_event(Beemaster::connection_to_alertinfo(c), 1);\n}\n","old_contents":"@load .\/beemaster_types\n@load .\/beemaster_log\n@load .\/beemaster_events\n\n@load base\/bif\/plugins\/Bro_TCP.events.bif\n@load base\/bif\/plugins\/Bro_UDP.events.bif\n@load base\/protocols\/conn\/main\n\nredef exit_only_after_terminate = T;\n\n# Broker setup\n# the ports and IPs that are externally routable for a master and this slave\nconst slave_broker_port: string = getenv(\"SLAVE_PUBLIC_PORT\") &redef;\nconst slave_broker_ip: string = getenv(\"SLAVE_PUBLIC_IP\") &redef;\nconst master_broker_port: port = to_port(cat(getenv(\"MASTER_PUBLIC_PORT\"), \"\/tcp\")) &redef;\nconst master_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-slave-\", slave_broker_ip, \":\", slave_broker_port);\n\nglobal base_events: set[string] = { \"Beemaster::log_conn\" };\n\nglobal tcp_events: set[string] = { \"Beemaster::tcp_event\" };\n\nglobal lattice_events: set[string] = { \"Beemaster::lattice_event\"};\n\nevent bro_init() {\n Beemaster::log(\"bro_slave.bro: bro_init()\");\n\n # Enable broker and listen for incoming connectors\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Connect to bro-master for load-balancing and relaying events\n Broker::connect(master_broker_ip, master_broker_port, 1sec);\n\n # Publish our local events to forward them to master\/acus\n Broker::register_broker_events(\"beemaster\/bro\/base\", base_events);\n\n # Publish our tcp events\n Broker::register_broker_events(\"beemaster\/bro\/tcp\", tcp_events);\n\n # Publish our lattice_events\n Broker::register_broker_events(\"beemaster\/bro\/lattice\", lattice_events);\n\n Beemaster::log(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n Beemaster::log(\"bro_slave.bro: bro_done()\");\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n Beemaster::log(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n Beemaster::log(msg);\n}\n\n# forwarding when some local connection is beeing logged. Throws an explicit beemaster event to forward.\nevent Conn::log_conn(rec: Conn::Info) {\n event Beemaster::log_conn(rec);\n}\n\nevent connection_SYN_packet(c: connection, pkt: SYN_packet) {\n event Beemaster::tcp_event(Beemaster::connection_to_alertinfo(c), 1);\n event Beemaster::lattice_event(Beemaster::connection_to_alertinfo(c), \"TCP\");\n}\n\nevent udp_request(c: connection) {\n Beemaster::log(\"udp_request on slave\");\n event Beemaster::lattice_event(Beemaster::connection_to_alertinfo(c), \"UDP\");\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"3131f2a1204c20f8a2b333ef4ec738ae9a11fcbb","subject":"Work on IP address support functions.","message":"Work on IP address support functions.\n\nReworked is_valid_ip function to be more accurate.\nip_valid_ip has now started to support IPv6 addresses.\nNew function for extracting all discovered IP addresses from strings.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"functions-ext.bro","new_file":"functions-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\nfunction numeric_id_string(id: conn_id): string\n\t{\n\treturn fmt(\"%s:%d > %s:%d\",\n\t id$orig_h, id$orig_p,\n\t id$resp_h, id$resp_p);\n\t}\n\nfunction fmt_str_set(input: string_set, strip: pattern): string\n\t{\n\tlocal output = \"{\";\n\tlocal tmp = \"\";\n\tlocal len = length(input);\n\tlocal i = 1;\n\t\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", gsub(item, strip, \"\"));\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s, \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s}\", output);\n\t}\n\n# Regular expressions for matching IP addresses in strings.\nconst ipv4_addr_regex = \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/;\nconst ipv6_8hex_regex = \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/;\nconst ipv6_compressed_hex_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/;\nconst ipv6_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\nconst ipv6_compressed_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\n\n# These are only commented out until this bug is fixed:\n# http:\/\/www.bro-ids.org\/wiki\/index.php\/Known_Issues#Bug_with_OR-ing_together_pattern_variables\n#const ipv6_addr_regex = ipv6_8hex_regex |\n# ipv6_compressed_hex_regex |\n# ipv6_hex4dec_regex |\n# ipv6_compressed_hex4dec_regex;\n#const ip_addr_regex = ipv4_addr_regex | ipv6_addr_regex;\n\nconst ipv6_addr_regex = \n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nconst ip_addr_regex = \n \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/ |\n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nfunction is_valid_ip(ip_str: string): bool\n\t{\n\tif ( ip_str == ipv4_addr_regex )\n\t\t{\n\t\tlocal octets = split(ip_str, \/\\.\/);\n\t\tif ( |octets| > 4 )\n\t\t\treturn F;\n\t\t\n\t\tlocal num=0;\n\t\tfor ( i in octets )\n\t\t\t{\n\t\t\tnum = to_count(octets[i]);\n\t\t\tif ( num < 0 || 255 < num )\n\t\t\t\treturn F;\n\t\t\t}\n\t\treturn T;\n\t\t}\n\telse if ( ip_str == ipv6_addr_regex )\n\t\t{\n\t\t# TODO: make this work correctly.\n\t\treturn T;\n\t\t}\n\treturn F;\n\t}\n\n# This output a string_array of ip addresses extracted from a string.\n# given: \"this is 1.1.1.1 a test 2.2.2.2 string with ip addresses 3.3.3.3\"\n# outputs: { [1] = 1.1.1.1, [2] = 2.2.2.2, [3] = 3.3.3.3 }\nfunction find_ip_addresses(input: string): string_array\n\t{\n\tlocal parts = split_all(input, ip_addr_regex);\n\tlocal output: string_array;\n\t\n\tfor ( i in parts )\n\t\t{\n\t\tif ( i % 2 == 0 && is_valid_ip(parts[i]) )\n\t\t\toutput[i\/2] = parts[i];\n\t\t}\n\treturn output;\n\t}\n\n\t\n# Some enums for deciding what and when to log.\ntype Direction: enum { Inbound, Outbound, BiDirectional };\ntype Hosts: enum { LocalHosts, RemoteHosts, AllHosts };\n\nfunction orig_h_matches_direction(ip: addr, d: Direction): bool\n\t{\n\treturn ( (d == Outbound && is_local_addr(ip)) ||\n\t (d == Inbound && !is_local_addr(ip)) ||\n\t d == BiDirectional );\n\t}\nfunction conn_matches_direction(id: conn_id, d: Direction): bool\n\t{\n\treturn orig_h_matches_direction(id$orig_h, d);\n\t}\nfunction addr_matches_hosts(ip: addr, d: Hosts): bool\n\t{\n\treturn ( (d == LocalHosts && is_local_addr(ip)) ||\n\t (d == RemoteHosts && !is_local_addr(ip)) ||\n\t d == AllHosts );\n\t}","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\nfunction numeric_id_string(id: conn_id): string\n\t{\n\treturn fmt(\"%s:%d > %s:%d\",\n\t id$orig_h, id$orig_p,\n\t id$resp_h, id$resp_p);\n\t}\n\nfunction fmt_str_set(input: string_set, strip: pattern): string\n\t{\n\tlocal output = \"{\";\n\tlocal tmp = \"\";\n\tlocal len = length(input);\n\tlocal i = 1;\n\t\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", gsub(item, strip, \"\"));\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s, \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s}\", output);\n\t}\n\n# TODO: include IPv6 regexes\nconst ip_addr_regex = \/^[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}$\/;\nfunction is_valid_ip(ip_str: string): bool\n\t{\n\treturn (ip_str == ip_addr_regex);\n\t}\n\t\n# Some enums for deciding what and when to log.\ntype Direction: enum { Inbound, Outbound, BiDirectional };\ntype Hosts: enum { LocalHosts, RemoteHosts, AllHosts };\n\nfunction orig_h_matches_direction(ip: addr, d: Direction): bool\n\t{\n\treturn ( (d == Outbound && is_local_addr(ip)) ||\n\t (d == Inbound && !is_local_addr(ip)) ||\n\t d == BiDirectional );\n\t}\nfunction conn_matches_direction(id: conn_id, d: Direction): bool\n\t{\n\treturn orig_h_matches_direction(id$orig_h, d);\n\t}\nfunction addr_matches_hosts(ip: addr, d: Hosts): bool\n\t{\n\treturn ( (d == LocalHosts && is_local_addr(ip)) ||\n\t (d == RemoteHosts && !is_local_addr(ip)) ||\n\t d == AllHosts );\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"68b9ca8f850611d5951682bd04a309193977302a","subject":"filter mdns log in bro","message":"filter mdns log in bro\n","repos":"MelvinTo\/firewalla,MelvinTo\/firewalla,MelvinTo\/firewalla,firewalla\/firewalla,firewalla\/firewalla,firewalla\/firewalla,firewalla\/firewalla,firewalla\/firewalla,MelvinTo\/firewalla,MelvinTo\/firewalla","old_file":"etc\/local.bro","new_file":"etc\/local.bro","new_contents":"##! Local site policy. Customize as appropriate. \n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\nredef ignore_checksums = T;\nredef SSL::disable_analyzer_after_detection = F;\n\n#@load site\/sqlite.bro\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n@load tuning\/json-logs\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Log some information about web applications being used by users \n# on your network.\n@load misc\/app-stats\n\n# Detect traceroute being run on the network. \n@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more \n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n@load frameworks\/software\/windows-version-detection\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when \n# running on live traffic. Enable it cautiously.\n#@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets \n# where the name is not part of your local DNS zone and is being hosted \n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n# @load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and \n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\n\n# enable link-layer address information to connection logs\n#@load policy\/protocols\/conn\/mac-logging\n\nredef restrict_filters += [[\"not-mdns\"] = \"not port 5353\"];\n\nredef SSL::disable_analyzer_after_detection = F;\nredef Communication::listen_interface = 127.0.0.1;\n\n@load base\/protocols\/dhcp\n","old_contents":"##! Local site policy. Customize as appropriate. \n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\nredef ignore_checksums = T;\nredef SSL::disable_analyzer_after_detection = F;\n\n#@load site\/sqlite.bro\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n@load tuning\/json-logs\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Log some information about web applications being used by users \n# on your network.\n@load misc\/app-stats\n\n# Detect traceroute being run on the network. \n@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more \n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n@load frameworks\/software\/windows-version-detection\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when \n# running on live traffic. Enable it cautiously.\n#@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets \n# where the name is not part of your local DNS zone and is being hosted \n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n# @load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and \n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\n\n# enable link-layer address information to connection logs\n#@load policy\/protocols\/conn\/mac-logging\n\nredef SSL::disable_analyzer_after_detection = F;\nredef Communication::listen_interface = 127.0.0.1;\n\n@load base\/protocols\/dhcp\n","returncode":0,"stderr":"","license":"agpl-3.0","lang":"Bro"} {"commit":"f70870e0c10dba33e264de982e2113e63ca0bd08","subject":"initial policy to log http requests to hosts not on your domain","message":"initial policy to log http requests to hosts not on your domain\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-external-names.bro","new_file":"http-ext-external-names.bro","new_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)albany\\.edu$\/ &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=10\n{\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'http-ext-external-names.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"05b40d1ccb4ae57872518510bf1cdd00f77eacca","subject":"Short circuit in the simple case of being interested in everything. This avoids running is_local_addr *a lot* of times.","message":"Short circuit in the simple case of being interested in everything. This avoids running is_local_addr *a lot* of times.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"functions-ext.bro","new_file":"functions-ext.bro","new_contents":"function numeric_id_string(id: conn_id): string\n\t{\n\treturn fmt(\"%s:%d > %s:%d\",\n\t id$orig_h, id$orig_p,\n\t id$resp_h, id$resp_p);\n\t}\n\nfunction fmt_addr_set(input: addr_set): string\n\t{\n\tlocal output = \"\";\n\tlocal tmp = \"\";\n\tlocal len = length(input);\n\tlocal i = 1;\n\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", item);\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s\", output);\n\t}\n\t\nfunction fmt_str_set(input: string_set, strip: pattern): string\n\t{\n\tlocal len = length(input);\n\tif ( len == 0 )\n\t\treturn \"{}\";\n\t\n\tlocal output = \"{\";\n\tlocal tmp = \"\";\n\tlocal i = 1;\n\t\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", gsub(item, strip, \"\"));\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s, \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s}\", output);\n\t}\n\n# Regular expressions for matching IP addresses in strings.\nconst ipv4_addr_regex = \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/;\nconst ipv6_8hex_regex = \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/;\nconst ipv6_compressed_hex_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/;\nconst ipv6_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\nconst ipv6_compressed_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\n\n# These are only commented out until this bug is fixed:\n# http:\/\/www.bro-ids.org\/wiki\/index.php\/Known_Issues#Bug_with_OR-ing_together_pattern_variables\n#const ipv6_addr_regex = ipv6_8hex_regex |\n# ipv6_compressed_hex_regex |\n# ipv6_hex4dec_regex |\n# ipv6_compressed_hex4dec_regex;\n#const ip_addr_regex = ipv4_addr_regex | ipv6_addr_regex;\n\nconst ipv6_addr_regex = \n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nconst ip_addr_regex = \n \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/ |\n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nfunction is_valid_ip(ip_str: string): bool\n\t{\n\tif ( ip_str == ipv4_addr_regex )\n\t\t{\n\t\tlocal octets = split(ip_str, \/\\.\/);\n\t\tif ( |octets| != 4 )\n\t\t\treturn F;\n\t\t\n\t\tlocal num=0;\n\t\tfor ( i in octets )\n\t\t\t{\n\t\t\tnum = to_count(octets[i]);\n\t\t\tif ( num < 0 || 255 < num )\n\t\t\t\treturn F;\n\t\t\t}\n\t\treturn T;\n\t\t}\n\telse if ( ip_str == ipv6_addr_regex )\n\t\t{\n\t\t# TODO: make this work correctly.\n\t\treturn T;\n\t\t}\n\treturn F;\n\t}\n\n# This output a string_array of ip addresses extracted from a string.\n# given: \"this is 1.1.1.1 a test 2.2.2.2 string with ip addresses 3.3.3.3\"\n# outputs: { [1] = 1.1.1.1, [2] = 2.2.2.2, [3] = 3.3.3.3 }\nfunction find_ip_addresses(input: string): string_array\n\t{\n\tlocal parts = split_all(input, ip_addr_regex);\n\tlocal output: string_array;\n\t\n\tfor ( i in parts )\n\t\t{\n\t\tif ( i % 2 == 0 && is_valid_ip(parts[i]) )\n\t\t\toutput[i\/2] = parts[i];\n\t\t}\n\treturn output;\n\t}\n\n\n\t\n# Some enums for deciding what and when to log.\ntype Direction: enum { Inbound, Outbound, All };\ntype Hosts: enum { LocalHosts, RemoteHosts, AllHosts };\n\nfunction orig_matches_direction(ip: addr, d: Direction): bool\n\t{\n\tif ( d == None ) return F;\n\n\treturn ( d == All ||\n\t (d == Outbound && is_local_addr(ip)) ||\n\t (d == Inbound && !is_local_addr(ip)) );\n\t}\n\t\nfunction resp_matches_direction(ip: addr, d: Direction): bool\n\t{\n\tif ( d == None ) return F;\n\t\n\treturn ( d == All ||\n\t (d == Inbound && is_local_addr(ip)) ||\n\t (d == Outbound && !is_local_addr(ip)) );\n\t}\n\nfunction conn_matches_direction(id: conn_id, d: Direction): bool\n\t{\n\tif ( d == None ) return F;\n\t\n\treturn orig_matches_direction(id$orig_h, d);\n\t}\n\t\nfunction resp_matches_hosts(ip: addr, d: Hosts): bool\n\t{\n\treturn ( d == AllHosts ||\n\t (d == LocalHosts && is_local_addr(ip)) ||\n\t (d == RemoteHosts && !is_local_addr(ip)) );\n\t}\n","old_contents":"function numeric_id_string(id: conn_id): string\n\t{\n\treturn fmt(\"%s:%d > %s:%d\",\n\t id$orig_h, id$orig_p,\n\t id$resp_h, id$resp_p);\n\t}\n\nfunction fmt_addr_set(input: addr_set): string\n\t{\n\tlocal output = \"\";\n\tlocal tmp = \"\";\n\tlocal len = length(input);\n\tlocal i = 1;\n\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", item);\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s\", output);\n\t}\n\t\nfunction fmt_str_set(input: string_set, strip: pattern): string\n\t{\n\tlocal len = length(input);\n\tif ( len == 0 )\n\t\treturn \"{}\";\n\t\n\tlocal output = \"{\";\n\tlocal tmp = \"\";\n\tlocal i = 1;\n\t\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", gsub(item, strip, \"\"));\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s, \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s}\", output);\n\t}\n\n# Regular expressions for matching IP addresses in strings.\nconst ipv4_addr_regex = \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/;\nconst ipv6_8hex_regex = \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/;\nconst ipv6_compressed_hex_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/;\nconst ipv6_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\nconst ipv6_compressed_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\n\n# These are only commented out until this bug is fixed:\n# http:\/\/www.bro-ids.org\/wiki\/index.php\/Known_Issues#Bug_with_OR-ing_together_pattern_variables\n#const ipv6_addr_regex = ipv6_8hex_regex |\n# ipv6_compressed_hex_regex |\n# ipv6_hex4dec_regex |\n# ipv6_compressed_hex4dec_regex;\n#const ip_addr_regex = ipv4_addr_regex | ipv6_addr_regex;\n\nconst ipv6_addr_regex = \n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nconst ip_addr_regex = \n \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/ |\n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nfunction is_valid_ip(ip_str: string): bool\n\t{\n\tif ( ip_str == ipv4_addr_regex )\n\t\t{\n\t\tlocal octets = split(ip_str, \/\\.\/);\n\t\tif ( |octets| != 4 )\n\t\t\treturn F;\n\t\t\n\t\tlocal num=0;\n\t\tfor ( i in octets )\n\t\t\t{\n\t\t\tnum = to_count(octets[i]);\n\t\t\tif ( num < 0 || 255 < num )\n\t\t\t\treturn F;\n\t\t\t}\n\t\treturn T;\n\t\t}\n\telse if ( ip_str == ipv6_addr_regex )\n\t\t{\n\t\t# TODO: make this work correctly.\n\t\treturn T;\n\t\t}\n\treturn F;\n\t}\n\n# This output a string_array of ip addresses extracted from a string.\n# given: \"this is 1.1.1.1 a test 2.2.2.2 string with ip addresses 3.3.3.3\"\n# outputs: { [1] = 1.1.1.1, [2] = 2.2.2.2, [3] = 3.3.3.3 }\nfunction find_ip_addresses(input: string): string_array\n\t{\n\tlocal parts = split_all(input, ip_addr_regex);\n\tlocal output: string_array;\n\t\n\tfor ( i in parts )\n\t\t{\n\t\tif ( i % 2 == 0 && is_valid_ip(parts[i]) )\n\t\t\toutput[i\/2] = parts[i];\n\t\t}\n\treturn output;\n\t}\n\n\n\t\n# Some enums for deciding what and when to log.\ntype Direction: enum { Inbound, Outbound, All };\ntype Hosts: enum { LocalHosts, RemoteHosts, AllHosts };\n\nfunction orig_matches_direction(ip: addr, d: Direction): bool\n\t{\n\tif ( d == None ) return F;\n\n\treturn ( (d == Outbound && is_local_addr(ip)) ||\n\t (d == Inbound && !is_local_addr(ip)) ||\n\t d == All );\n\t}\n\t\nfunction resp_matches_direction(ip: addr, d: Direction): bool\n\t{\n\tif ( d == None ) return F;\n\t\n\treturn ( (d == Inbound && is_local_addr(ip)) ||\n\t (d == Outbound && !is_local_addr(ip)) ||\n\t d == All );\n\t}\n\nfunction conn_matches_direction(id: conn_id, d: Direction): bool\n\t{\n\tif ( d == None ) return F;\n\t\n\treturn orig_matches_direction(id$orig_h, d);\n\t}\n\t\nfunction resp_matches_hosts(ip: addr, d: Hosts): bool\n\t{\n\treturn ( (d == LocalHosts && is_local_addr(ip)) ||\n\t (d == RemoteHosts && !is_local_addr(ip)) ||\n\t d == AllHosts );\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"d4d7cc14ea13e0cc2dfc071c93865b1dfd001e59","subject":"Forgot to include a connection with the notices.","message":"Forgot to include a connection with the notices.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\tlocal session = smtp_sessions[id];\n\n\tif ( id !in conn_info || \n\t\t !session$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\n# This is a locally defined event. Handle it with a priority greater than\n# negative 5 if you want to dig into the conn_info record before it's deleted.\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\tlocal session = smtp_sessions[id];\n\n\tif ( id !in conn_info || \n\t\t !session$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\n# This is a locally defined event. Handle it with a priority greater than\n# negative 5 if you want to dig into the conn_info record before it's deleted.\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(id);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"42316a4ebb71d5dc9d9b4c1f502fd6a3494b6602","subject":"subscribe master to dionaea as fallback","message":"subscribe master to dionaea as fallback\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_receiver.bro","new_file":"scripts_master\/bro_receiver.bro","new_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n log_bro(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n log_bro(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n log_bro(\"Registered new slave \" + peer_name);\n \n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n log_bro(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n log_bro(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n log_bro(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_bro(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n log_bro(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_bro(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n log_bro(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}","old_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n log_bro(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n log_bro(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n log_bro(\"Registered new slave \" + peer_name);\n \n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n log_bro(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n log_bro(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n log_bro(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_bro(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n log_bro(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_bro(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n log_bro(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"abe44cf5e2293478237d20cd6d0da39a2acf08c7","subject":"correct host variable","message":"correct host variable\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logging = Outbound &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", logging, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !orig_matches_direction(c$id$resp_h, logging) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logging = Outbound &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", logging, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !orig_matches_direction(c$id$resp_h, logging) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", info$c$id$orig_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"8ac39172b6a17665397577d87018dee0509bc1c7","subject":"tweak expire time, synchronize variables","message":"tweak expire time, synchronize variables\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext-block.bro","new_file":"ssh-ext-block.bro","new_contents":"@load global-ext\n@load ssh-ext\n@load subnet-helper\n@load notice\n\nmodule SSH;\n\nexport {\n global ssh_attacked: table[addr] of addr_set &create_expire=30mins &synchronized;# default isn't working &default=function(a:addr):addr_set { print a;return set();};\n global libssh_scanners: set[addr] &create_expire=10mins &synchronized;\n const subnet_threshold = 3 &redef;\n\n redef enum Notice += {\n SSH_Libssh_Scanner,\n };\n}\n\nfunction notice_exec_test(n: notice_info, a: NoticeAction): NoticeAction\n{\n #execute_with_notice(\"\/usr\/local\/bin\/bro_ipblocker_block\", n);\n execute_with_notice(\"\/tmp\/test\", n);\n return NOTICE_ALARM_ALWAYS;\n}\n\nredef notice_action_filters += {\n [SSH_Libssh_Scanner] = notice_exec_test,\n};\n\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info) &priority=-10\n{\n if(is_local_addr(id$orig_h) ||\n \/libssh\/ !in si$client ||\n si$status == \"success\")\n return;\n\n local subnets = add_attack(ssh_attacked, id$orig_h, id$resp_h);\n print fmt(\"%s scanned %d subnets\", id$orig_h, subnets);\n \n if(subnets >= subnet_threshold && id$orig_h !in libssh_scanners){\n add libssh_scanners[id$orig_h];\n\n NOTICE([$note=SSH_Libssh_Scanner,\n $id=id,\n $msg=fmt(\"SSH libssh scanning. %s scanned %d subnets\", id$orig_h, subnets),\n $sub=\"ssh-ext\",\n $n=subnets]);\n }\n\n}\n","old_contents":"@load global-ext\n@load ssh-ext\n@load subnet-helper\n@load notice\n\nmodule SSH;\n\nexport {\n global ssh_attacked: table[addr] of addr_set &create_expire=30mins;# default isn't working &default=function(a:addr):addr_set { print a;return set();};\n global libssh_scanners: set[addr] &read_expire=1hr;\n const subnet_threshold = 3 &redef;\n\n redef enum Notice += {\n SSH_Libssh_Scanner,\n };\n}\n\nfunction notice_exec_test(n: notice_info, a: NoticeAction): NoticeAction\n{\n #execute_with_notice(\"\/usr\/local\/bin\/bro_ipblocker_block\", n);\n execute_with_notice(\"\/tmp\/test\", n);\n return NOTICE_ALARM_ALWAYS;\n}\n\nredef notice_action_filters += {\n [SSH_Libssh_Scanner] = notice_exec_test,\n};\n\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info) &priority=-10\n{\n if(is_local_addr(id$orig_h) ||\n \/libssh\/ !in si$client ||\n si$status == \"success\")\n return;\n\n local subnets = add_attack(ssh_attacked, id$orig_h, id$resp_h);\n print fmt(\"%s scanned %d subnets\", id$orig_h, subnets);\n \n if(subnets >= subnet_threshold && id$orig_h !in libssh_scanners){\n add libssh_scanners[id$orig_h];\n\n NOTICE([$note=SSH_Libssh_Scanner,\n $id=id,\n $msg=fmt(\"SSH libssh scanning. %s scanned %d subnets\", id$orig_h, subnets),\n $sub=\"ssh-ext\",\n $n=subnets]);\n }\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"31eb420c198689adfcac7c631fe2d41a7ac64eba","subject":"small bug in logging.smtp-ext.bro","message":"small bug in logging.smtp-ext.bro\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"logging.smtp-ext.bro","new_file":"logging.smtp-ext.bro","new_contents":"@load global-ext\n@load smtp-ext\n\nmodule SMTP;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t\n\t# Which mail transactions to log.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"smtp-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"smtp-ext\", cat_sep(\"\\t\", \"\", \n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"helo\", \"message-id\", \"in-reply-to\", \n\t \"mailfrom\", \"rcptto\",\n\t \"date\", \"from\", \"reply_to\", \"to\",\n\t \"files\", \"last_reply\", \"x-originating-ip\",\n\t \"path\", \"is_webmail\", \"agent\"));\n\t}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n\t{\n\tif ( si$mailfrom != \"\" )\n\t\t{\n\t\tlocal log = LOG::get_file(\"smtp-ext\", id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\",\n\t\t network_time(),\n\t\t id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n\t\t si$helo,\n\t\t si$msg_id,\n\t\t si$in_reply_to,\n\t\t si$mailfrom,\n\t\t fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t si$date, \n\t\t si$from, \n\t\t si$reply_to, \n\t\t fmt_str_set(si$to, \/[\"']\/),\n\t\t fmt_str_set(si$files, \/[\"']\/),\n\t\t si$last_reply, \n\t\t si$x_originating_ip,\n\t\t si$path,\n\t\t si$is_webmail,\n\t\t si$agent);\n\t\t}\n\n\t}","old_contents":"@load global-ext\n@load smtp-ext\n\nmodule SMTP;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t\n\t# Which mail transactions to log.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"smtp-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"smtp-ext\", cat_sep(\"\\t\", \"\", \n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"helo\", \"message-id\", \"in-reply-to\", \n\t \"mailfrom\", \"rcptto\",\n\t \"date\", \"from\", \"reply_to\", \"to\",\n\t \"files\", \"last_reply\", \"x-originating-ip\",\n\t \"path\", \"is_webmail\", \"agent\"));\n\t}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n\t{\n\tif ( si$mailfrom != \"\" )\n\t\tlocal log = LOG::get_file(\"smtp-ext\", id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\",\n\t\t network_time(),\n\t\t id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n\t\t si$helo,\n\t\t si$msg_id,\n\t\t si$in_reply_to,\n\t\t si$mailfrom,\n\t\t fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t si$date, \n\t\t si$from, \n\t\t si$reply_to, \n\t\t fmt_str_set(si$to, \/[\"']\/),\n\t\t fmt_str_set(si$files, \/[\"']\/),\n\t\t si$last_reply, \n\t\t si$x_originating_ip,\n\t\t si$path,\n\t\t si$is_webmail,\n\t\t si$agent);\n\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"19bd837054cd4915398ae68b83c9608769c86ba3","subject":"Create expand-query.bro","message":"Create expand-query.bro\n\nInit of expand-query.bro.","repos":"CrowdStrike\/cs-bro","old_file":"bro-scripts\/extensions\/dns\/expand-query.bro","new_file":"bro-scripts\/extensions\/dns\/expand-query.bro","new_contents":"# Creates a vector from a DNS query\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n# @jshlbrd\n\n@load base\/protocols\/dns\n@load base\/protocols\/http\n\nmodule DNS;\n\nredef record DNS::Info += {\n\tquery_vec: vector of string &log &optional;\n\tquery_vec_size: count &log &optional;\n};\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\nc$dns$query_vec = HTTP::extract_keys(query,\/\\.\/);\nc$dns$query_vec_size = |c$dns$query_vec|;\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/extensions\/dns\/expand-query.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"3fec79be253c5b144a40e9eb47295c38899b84cd","subject":"Small comment change.","message":"Small comment change.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext-logging.bro","new_file":"ssh-ext-logging.bro","new_contents":"@load ssh-ext\n\nmodule SSH;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Which SSH logins to record.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssh-ext\", logging, split_log_file);\n\t}\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info)\n\t{\n\tlocal log = LOG::choose(\"ssh-ext\", id$resp_h);\n\n\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t si$start_time,\n\t id$orig_h, fmt(\"%d\", id$orig_p),\n\t id$resp_h, fmt(\"%d\", id$resp_p),\n\t si$status, si$direction, \n\t si$location$country_code, si$location$region,\n\t si$client, si$server,\n\t si$resp_size);\n\t}","old_contents":"@load ssh-ext\n\nmodule SSH;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Which mail transactions to log.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssh-ext\", logging, split_log_file);\n\t}\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info)\n\t{\n\tlocal log = LOG::choose(\"ssh-ext\", id$resp_h);\n\n\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t si$start_time,\n\t id$orig_h, fmt(\"%d\", id$orig_p),\n\t id$resp_h, fmt(\"%d\", id$resp_p),\n\t si$status, si$direction, \n\t si$location$country_code, si$location$region,\n\t si$client, si$server,\n\t si$resp_size);\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"0aaa9fad776a15778d844134b694ab599cfb4db8","subject":"Using complex structs with multiple enums with bro results in the following error:","message":"Using complex structs with multiple enums with bro results in the following\nerror:\n\n error: identifier or enumerator value in enumerated type definition already exists\n","repos":"FrozenCaribou\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti","old_file":"bro\/tests\/pac2\/double-types.bro","new_file":"bro\/tests\/pac2\/double-types.bro","new_contents":"#\n# @TEST-EXEC: bro .\/dtest.evt %INPUT\n#\n# @TEST-KNOWN-FAILURE: enum convert problem. Comment line 16 to toggle error.\n\n# @TEST-START-FILE dtest.evt\n\ngrammar dtest.pac2;\n\nprotocol analyzer pac2::dtest over UDP:\n parse with dtest::Message,\n port 47808\/udp;\n\non dtest::Message -> event dtest_message(self.func);\n\non dtest::Message -> event dtest_result (self.sub.result);\n\n# @TEST-END-FILE\n# @TEST-START-FILE dtest.pac2\n\nmodule dtest;\n\ntype FUNCS = enum {\n A, B, C, D, E, F\n};\n\ntype RESULT = enum {\n A, B, C, D, E, F\n};\n\nexport type Message = unit {\n func: uint8 &convert=FUNCS($$);\n sub: SubMessage;\n};\n\ntype SubMessage = unit {\n result: uint8 &convert=RESULT($$);\n};\n\n# @TEST-END-FILE\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro\/tests\/pac2\/double-types.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"b702e9e6cde5e0e517b3e4bbffdfc0018612eb62","subject":"fix notice suppression","message":"fix notice suppression\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"log-external-dns.bro","new_file":"log-external-dns.bro","new_contents":"module DNS;\n\nexport {\n redef record Info += {\n is_external: bool &default=F;\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n 208.67.220.220\/32, #opendns\n } &redef;\n\n redef enum Notice::Type += {\n ## Indicates that a user is using an external DNS server\n EXTERNAL_DNS,\n\n ## Indicates that a user is using an external DNS server in \n ## a foreign country.\n EXTERNAL_FOREIGN_DNS,\n };\n\n const local_countries: set[string] = {\n \"US\",\n } &redef;\n\n}\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\n local rec = c$dns;\n if(!rec$RD)\n return;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return;\n\n rec$is_external=T;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n\n when (local hostname = lookup_addr(resp_h)) {\n #Doesn't work for the log, but we can use it here :-(\n #rec$resp_h_hostname = hostname;\n\n local note = EXTERNAL_DNS;\n local nmsg = fmt(\"An external DNS server is in use %s(%s)\", resp_h, hostname);\n\n if(rec$cc !in local_countries){\n note = EXTERNAL_FOREIGN_DNS;\n nmsg = fmt(\"An external foreign(%s) DNS server is in use %s(%s).\", rec$cc, resp_h, hostname);\n }\n local ident = fmt(\"%s-%s\", orig_h, resp_h);\n NOTICE([$note=note,\n $msg=nmsg,\n $sub=hostname,\n $identifier=ident,\n $remote_location=loc,\n $suppress_for=1day,\n $conn=c]);\n }\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n return rec$is_external;\n } ]);\n}\n","old_contents":"module DNS;\n\nexport {\n redef record Info += {\n is_external: bool &default=F;\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n 208.67.220.220\/32, #opendns\n } &redef;\n\n redef enum Notice::Type += {\n ## Indicates that a user is using an external DNS server\n EXTERNAL_DNS,\n\n ## Indicates that a user is using an external DNS server in \n ## a foreign country.\n EXTERNAL_FOREIGN_DNS,\n };\n\n redef Notice::type_suppression_intervals += {\n [EXTERNAL_DNS] = 12hr,\n [EXTERNAL_FOREIGN_DNS] = 12hr,\n };\n\n const local_countries: set[string] = {\n \"US\",\n } &redef;\n\n}\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\n local rec = c$dns;\n if(!rec$RD)\n return;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return;\n\n rec$is_external=T;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n\n when (local hostname = lookup_addr(resp_h)) {\n #Doesn't work for the log, but we can use it here :-(\n #rec$resp_h_hostname = hostname;\n\n local note = EXTERNAL_DNS;\n local nmsg = fmt(\"An external DNS server is in use %s(%s)\", resp_h, hostname);\n\n if(rec$cc !in local_countries){\n note = EXTERNAL_FOREIGN_DNS;\n nmsg = fmt(\"An external foreign(%s) DNS server is in use %s(%s).\", rec$cc, resp_h, hostname);\n }\n local ident = fmt(\"%s-%s\", orig_h, resp_h);\n NOTICE([$note=note,\n $msg=nmsg,\n $sub=hostname,\n $identifier=ident,\n $remote_location=loc,\n $conn=c]);\n }\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n return rec$is_external;\n } ]);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1193effc3ea9ad40fd80b963fa0057b8245388b1","subject":"fix Zeek SMB module loading","message":"fix Zeek SMB module loading\n\nSMB location has changed","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nmodule ROCK;\n\nexport {\n const sensor_id = gethostname() &redef;\n}\n\n#=== Bro built-ins ===================================\n\n# Collect on SMB protocol\n@load base\/protocols\/smb\n\n# Enable VLAN Logging\n@load policy\/protocols\/conn\/vlan-logging\n\n# Log MAC addresses\n@load policy\/protocols\/conn\/mac-logging\n\n# Log (All) Client and Server HTTP Headers\n@load policy\/protocols\/http\/header-names.bro\n\n#== ROCK specific scripts ============================\n# Add empty Intel framework database\n@load .\/frameworks\/intel\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n\n#== 3rd Party Scripts =================================\n# Add Salesforce's JA3 SSL fingerprinting\n@load .\/misc\/ja3\n\n### Sensor specific scripts ######################\n\n# Configure AF_PACKET, if in use\n@load .\/plugins\/afpacket\n","old_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nmodule ROCK;\n\nexport {\n const sensor_id = gethostname() &redef;\n}\n\n#=== Bro built-ins ===================================\n\n# Collect on SMB protocol\n@load policy\/protocols\/smb\n\n# Enable VLAN Logging\n@load policy\/protocols\/conn\/vlan-logging\n\n# Log MAC addresses\n@load policy\/protocols\/conn\/mac-logging\n\n# Log (All) Client and Server HTTP Headers\n@load policy\/protocols\/http\/header-names.bro\n\n#== ROCK specific scripts ============================\n# Add empty Intel framework database\n@load .\/frameworks\/intel\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n\n#== 3rd Party Scripts =================================\n# Add Salesforce's JA3 SSL fingerprinting\n@load .\/misc\/ja3\n\n### Sensor specific scripts ######################\n\n# Configure AF_PACKET, if in use\n@load .\/plugins\/afpacket\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"b7e35199ed0f2b0456d5fc721710d8c740f3effd","subject":"Bro: \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043b\u043e\u0433\u043e\u0432 HTTP \u0438 \u0444\u0430\u0439\u043b\u043e\u0432","message":"Bro: \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043b\u043e\u0433\u043e\u0432 HTTP \u0438 \u0444\u0430\u0439\u043b\u043e\u0432\n","repos":"valery1707\/test-sorm,valery1707\/test-sorm,valery1707\/test-sorm,valery1707\/test-sorm","old_file":"src\/main\/resources\/bro\/amt_init.bro","new_file":"src\/main\/resources\/bro\/amt_init.bro","new_contents":"##! \u0421\u043a\u0440\u0438\u043f\u0442 \u0441 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438: \n##! * \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0432 \u043b\u043e\u0433\u0438\n##! * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414\n##! * \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432\n\n@load base\/protocols\/conn\/main.bro\n\n#https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-fa_file\n@load base\/frameworks\/files\/main.bro\n@load base\/protocols\/ftp\/files.bro\n@load base\/protocols\/http\/entities.bro\n\n#https:\/\/www.bro.org\/sphinx\/scripts\/base\/frameworks\/files\/main.bro.html#type-Files::Info\n@load base\/files\/hash\/main.bro\n@load base\/files\/extract\/main.bro\n\n#https:\/\/www.bro.org\/sphinx\/frameworks\/logging-input-sqlite.html#id6\n#@load frameworks\/files\/hash-all-files\n\nmodule AMT;\n\n# \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0442\u0438\u043a\u0435\u0442 \u0432 conn \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u043b\u043e\u0433\u043e\u0432 \u0433\u0434\u0435 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e\n#--------------------------------------------------#\n#--------------------------------------------------#\n#--------------------------------------------------#\nredef record Conn::Info += {\n\tamt_tasks: set[count] &default=set();\n\tamt_tasks_list: string &default=\"\" &log;\n};\n\nexport {\n\t## \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0435\n\t##\n\t## c: \u041a\u043e\u043d\u043d\u0435\u043a\u0442\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal catch_conn: function(c: connection, taskId: count): bool;\n\n\t## \u0421\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0437\u0430 \u043f\u043e\u0447\u0442\u043e\u0439\n\t##\n\t## s: eMail\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal watch_email: function(s: string, taskId: count);\n\n\t## \u0421\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0437\u0430 \u0442\u0440\u0430\u0444\u0438\u043a\u043e\u043c \u043f\u043e IP\n\t##\n\t## target: IPv4\/IPv6\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal watch_ip_addr: function(target: addr, taskId: count);\n}\n\n#--------------------------------------------------#\n# \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432 - \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439\n#--------------------------------------------------#\n## table[conn$uid] => set[taskId]\nglobal catched_conn_uid: table[string] of set[count] = {};\n#todo Remove?\nglobal catched_conn_id: set[conn_id] = {};\n\n#--------------------------------------------------#\n# \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d\n#--------------------------------------------------#\nfunction is_catched_conn_single(conn_uid: string): bool {\n\treturn conn_uid in catched_conn_uid;\n}\nfunction is_catched_conn_set(conn_uids: set[string]): bool {\n\tfor (uid in conn_uids) {\n\t\tif (uid in catched_conn_uid) {\n\t\t\treturn T;\n\t\t}\n\t}\n\treturn F;\n}\nfunction is_catched_conn_table(conn: table[conn_id] of connection): bool {\n\tfor (id in conn) {\n\t\tif (is_catched_conn_single(conn[id]$uid)) {\n\t\t\treturn T;\n\t\t}\n\t}\n\treturn F;\n}\n\n\n#--------------------------------------------------#\n# \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043b\u043e\u0433\u043e\u0432\n#--------------------------------------------------#\nfunction filter_conn(rec: Conn::Info): bool {\n\tif (rec$uid in catched_conn_uid) {\n\t\tlocal tasks_list = \"\";\n\t\tfor (taskId in catched_conn_uid[rec$uid]) {\n\t\t\ttasks_list = cat(tasks_list, \",\", taskId);\n\t\t}\n\t\trec$amt_tasks_list = tasks_list + \",\";\n\t\treturn T;\n\t}\n\treturn F;\n}\nfunction filter_smtp(rec: SMTP::Info): bool {\n\treturn is_catched_conn_single(rec$uid);\n}\nfunction filter_http(rec: HTTP::Info): bool {\n\treturn is_catched_conn_single(rec$uid);\n}\nfunction filter_files(rec: Files::Info): bool {\n\treturn is_catched_conn_set(rec$conn_uids);\n}\n\n\n#--------------------------------------------------#\n# \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432\n#--------------------------------------------------#\nevent bro_init() {\n\tprint \"AMT::start\";\n\n\t# Conn\n\tlocal filter = Log::get_filter(Conn::LOG, \"default\");\n\tfilter$pred = filter_conn;\n\tLog::add_filter(Conn::LOG, filter);\n\n\t# SMTP\n\tfilter = Log::get_filter(SMTP::LOG, \"default\");\n\tfilter$pred = filter_smtp;\n\tLog::add_filter(SMTP::LOG, filter);\n\n\t# HTTP\n\tfilter = Log::get_filter(HTTP::LOG, \"default\");\n\tfilter$pred = filter_http;\n\tLog::add_filter(HTTP::LOG, filter);\n\n\t# Files\n\tfilter = Log::get_filter(Files::LOG, \"default\");\n\tfilter$pred = filter_files;\n\tLog::add_filter(Files::LOG, filter);\n}\nevent bro_done() {\n\tprint \"AMT::stop\";\n}\n\n\n#--------------------------------------------------#\n# \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438\n#--------------------------------------------------#\nfunction catch_conn(c: connection, taskId: count): bool {\n\tlocal tasks: set[count];\n\tif (c$uid in catched_conn_uid) {\n\t\ttasks = catched_conn_uid[c$uid];\n\t} else {\n\t\ttasks = set();\n\t}\n\tif (taskId in tasks) {\n\t\t# Already catched\n\t\treturn F;\n\t}\n\tadd tasks[taskId];\n\tcatched_conn_uid[c$uid] = tasks;\n\treturn T;\n}\nfunction catch_conn_multi(c: connection, taskIds: set[count]): bool {\n\tlocal tasks: set[count];\n\tif (c$uid in catched_conn_uid) {\n\t\ttasks = catched_conn_uid[c$uid];\n\t} else {\n\t\ttasks = set();\n\t}\n\tlocal catchedNow = F;\n\tfor (task in taskIds) {\n\t\tif (! (task in tasks)) {\n\t\t\tcatchedNow = T;\n\t\t\tadd tasks[task];\n\t\t}\n\t}\n\tif (catchedNow) {\n\t\tcatched_conn_uid[c$uid] = tasks;\n\t}\n\treturn catchedNow;\n}\n\n## table[email] => set[taskId]\nglobal watch_emails: table[string] of set[count] = {};\n## table[email] => pattern\nglobal watch_emails_p: table[string] of pattern = {};\nfunction watch_email(s: string, taskId: count) {\n\tlocal p: pattern = string_to_pattern(s, T);\n\tlocal tasks: set[count] = set();\n\tif (s in watch_emails) {\n\t\ttasks = watch_emails[s];\n\t}\n\tadd tasks[taskId];\n\twatch_emails[s] = tasks;\n\twatch_emails_p[s] = p;\n}\n\n## table[addr] => set[taskId]\nglobal watch_ip_addrs: table[addr] of set[count] = {};\nfunction watch_ip_addr(target: addr, taskId: count) {\n\tlocal tasks: set[count] = set();\n\tif (target in watch_ip_addrs) {\n\t\ttasks = watch_ip_addrs[target];\n\t}\n\tadd tasks[taskId];\n\twatch_ip_addrs[target] = tasks;\n}\n\n\n#--------------------------------------------------#\n#---------- \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 ---------#\n#--------------------------------------------------#\n\n# \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432 \u043f\u043e IP\nevent new_connection(c: connection) {\n\tif (! is_catched_conn_single(c$uid)) {\n\t\tif (c$id$orig_h in watch_ip_addrs) {\n\t\t\tcatch_conn_multi(c, watch_ip_addrs[c$id$orig_h]);\n\t\t} else if (c$id$resp_h in watch_ip_addrs) {\n\t\t\tcatch_conn_multi(c, watch_ip_addrs[c$id$resp_h]);\n\t\t}\n\t}\n}\n\n# \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 eMail\nevent mime_one_header(c: connection, h: mime_header_rec) {\n#\tprint fmt(\"mime_one_header(c: {uid: '%s'}, h: {name: '%s', value: '%s'})\", c$uid, h$name, h$value);\n\tif (! is_catched_conn_single(c$uid)) {\n\t\tif (h$name == \"FROM\" || h$name == \"TO\") {\n#\t\t\tprint fmt(\"Header: %s=%s\", h$name, h$value);\n\t\t\tfor (p in watch_emails) {\n#\t\t\t\tprint fmt(\"Pattern: %s\", p);\n\t\t\t\tif (watch_emails_p[p] in h$value) {\n\t\t\t\t\tprint fmt(\"Catch Mime: conn$uid=%s, h$name=%s, h$value=%s\", c$uid, h$name, h$value);\n\t\t\t\t\tcatch_conn_multi(c, watch_emails[p]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n# \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u0437 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432\nevent file_new(f: fa_file) {\n\tif (is_catched_conn_table(f$conns)) {\n\t\tFiles::add_analyzer(f, Files::ANALYZER_EXTRACT);\n\t}\n}\n\nevent file_sniff(f: fa_file, meta: fa_metadata) {\n#\tlocal fname = fmt(\"%s-%s.%s\", f$source, f$id, meta$mime_type);\n#\tprint fmt(\"Extracting file %s\", fname);\n#\tlocal mime_type = (meta?$mime_type) ? meta$mime_type : \"NONE\";\n#\tprint fmt(\"Source: %s; ID: %s; Mime: %s\", f$source, f$id, mime_type);\n#\tif (f?$info) {\n#\t\tprint fmt(\" Info! ts: %s; mime: %s; filename: %s; md5: %s\", f$info$ts, f$info?$mime_type ? f$info$mime_type : \"NONE\", f$info?$filename ? f$info$filename : \"???\", f$info?$md5 ? f$info$md5 : \"000\");\n#\t}\n}\n","old_contents":"##! \u0421\u043a\u0440\u0438\u043f\u0442 \u0441 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438: \n##! * \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0432 \u043b\u043e\u0433\u0438\n##! * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414\n##! * \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432\n\n@load base\/protocols\/conn\/main.bro\n\n#https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-fa_file\n@load base\/frameworks\/files\/main.bro\n@load base\/protocols\/ftp\/files.bro\n@load base\/protocols\/http\/entities.bro\n\n#https:\/\/www.bro.org\/sphinx\/scripts\/base\/frameworks\/files\/main.bro.html#type-Files::Info\n@load base\/files\/hash\/main.bro\n@load base\/files\/extract\/main.bro\n\n#https:\/\/www.bro.org\/sphinx\/frameworks\/logging-input-sqlite.html#id6\n#@load frameworks\/files\/hash-all-files\n\nmodule AMT;\n\n# \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0442\u0438\u043a\u0435\u0442 \u0432 conn \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u043b\u043e\u0433\u043e\u0432 \u0433\u0434\u0435 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e\n#--------------------------------------------------#\n#--------------------------------------------------#\n#--------------------------------------------------#\nredef record Conn::Info += {\n\tamt_tasks: set[count] &default=set();\n\tamt_tasks_list: string &default=\"\" &log;\n};\n\nexport {\n\t## \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0435\n\t##\n\t## c: \u041a\u043e\u043d\u043d\u0435\u043a\u0442\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal catch_conn: function(c: connection, taskId: count): bool;\n\n\t## \u0421\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0437\u0430 \u043f\u043e\u0447\u0442\u043e\u0439\n\t##\n\t## s: eMail\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal watch_email: function(s: string, taskId: count);\n\n\t## \u0421\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0437\u0430 \u0442\u0440\u0430\u0444\u0438\u043a\u043e\u043c \u043f\u043e IP\n\t##\n\t## target: IPv4\/IPv6\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal watch_ip_addr: function(target: addr, taskId: count);\n}\n\n#--------------------------------------------------#\n# \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432 - \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439\n#--------------------------------------------------#\n## table[conn$uid] => set[taskId]\nglobal catched_conn_uid: table[string] of set[count] = {};\n#todo Remove?\nglobal catched_conn_id: set[conn_id] = {};\n\n#--------------------------------------------------#\n# \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d\n#--------------------------------------------------#\nfunction is_catched_conn_single(conn_uid: string): bool {\n\treturn conn_uid in catched_conn_uid;\n}\nfunction is_catched_conn_set(conn_uids: set[string]): bool {\n\tfor (uid in conn_uids) {\n\t\tif (uid in catched_conn_uid) {\n\t\t\treturn T;\n\t\t}\n\t}\n\treturn F;\n}\nfunction is_catched_conn_table(conn: table[conn_id] of connection): bool {\n\tfor (id in conn) {\n\t\tif (is_catched_conn_single(conn[id]$uid)) {\n\t\t\treturn T;\n\t\t}\n\t}\n\treturn F;\n}\n\n\n#--------------------------------------------------#\n# \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043b\u043e\u0433\u043e\u0432\n#--------------------------------------------------#\nfunction filter_conn(rec: Conn::Info): bool {\n\tif (rec$uid in catched_conn_uid) {\n\t\tlocal tasks_list = \"\";\n\t\tfor (taskId in catched_conn_uid[rec$uid]) {\n\t\t\ttasks_list = cat(tasks_list, \",\", taskId);\n\t\t}\n\t\trec$amt_tasks_list = tasks_list + \",\";\n\t\treturn T;\n\t}\n\treturn F;\n}\nfunction filter_smtp(rec: SMTP::Info): bool {\n\treturn is_catched_conn_single(rec$uid);\n}\n\n\n#--------------------------------------------------#\n# \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432\n#--------------------------------------------------#\nevent bro_init() {\n\tprint \"AMT::start\";\n\tlocal filter = Log::get_filter(Conn::LOG, \"default\");\n\tfilter$pred = filter_conn;\n\tLog::add_filter(Conn::LOG, filter);\n\tfilter = Log::get_filter(SMTP::LOG, \"default\");\n\tfilter$pred = filter_smtp;\n\tLog::add_filter(SMTP::LOG, filter);\n}\nevent bro_done() {\n\tprint \"AMT::stop\";\n}\n\n\n#--------------------------------------------------#\n# \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438\n#--------------------------------------------------#\nfunction catch_conn(c: connection, taskId: count): bool {\n\tlocal tasks: set[count];\n\tif (c$uid in catched_conn_uid) {\n\t\ttasks = catched_conn_uid[c$uid];\n\t} else {\n\t\ttasks = set();\n\t}\n\tif (taskId in tasks) {\n\t\t# Already catched\n\t\treturn F;\n\t}\n\tadd tasks[taskId];\n\tcatched_conn_uid[c$uid] = tasks;\n\treturn T;\n}\nfunction catch_conn_multi(c: connection, taskIds: set[count]): bool {\n\tlocal tasks: set[count];\n\tif (c$uid in catched_conn_uid) {\n\t\ttasks = catched_conn_uid[c$uid];\n\t} else {\n\t\ttasks = set();\n\t}\n\tlocal catchedNow = F;\n\tfor (task in taskIds) {\n\t\tif (! (task in tasks)) {\n\t\t\tcatchedNow = T;\n\t\t\tadd tasks[task];\n\t\t}\n\t}\n\tif (catchedNow) {\n\t\tcatched_conn_uid[c$uid] = tasks;\n\t}\n\treturn catchedNow;\n}\n\n## table[email] => set[taskId]\nglobal watch_emails: table[string] of set[count] = {};\n## table[email] => pattern\nglobal watch_emails_p: table[string] of pattern = {};\nfunction watch_email(s: string, taskId: count) {\n\tlocal p: pattern = string_to_pattern(s, T);\n\tlocal tasks: set[count] = set();\n\tif (s in watch_emails) {\n\t\ttasks = watch_emails[s];\n\t}\n\tadd tasks[taskId];\n\twatch_emails[s] = tasks;\n\twatch_emails_p[s] = p;\n}\n\n## table[addr] => set[taskId]\nglobal watch_ip_addrs: table[addr] of set[count] = {};\nfunction watch_ip_addr(target: addr, taskId: count) {\n\tlocal tasks: set[count] = set();\n\tif (target in watch_ip_addrs) {\n\t\ttasks = watch_ip_addrs[target];\n\t}\n\tadd tasks[taskId];\n\twatch_ip_addrs[target] = tasks;\n}\n\n\n#--------------------------------------------------#\n#---------- \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 ---------#\n#--------------------------------------------------#\n\n# \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432 \u043f\u043e IP\nevent new_connection(c: connection) {\n\tif (! is_catched_conn_single(c$uid)) {\n\t\tif (c$id$orig_h in watch_ip_addrs) {\n\t\t\tcatch_conn_multi(c, watch_ip_addrs[c$id$orig_h]);\n\t\t} else if (c$id$resp_h in watch_ip_addrs) {\n\t\t\tcatch_conn_multi(c, watch_ip_addrs[c$id$resp_h]);\n\t\t}\n\t}\n}\n\n# \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 eMail\nevent mime_one_header(c: connection, h: mime_header_rec) {\n#\tprint fmt(\"mime_one_header(c: {uid: '%s'}, h: {name: '%s', value: '%s'})\", c$uid, h$name, h$value);\n\tif (! is_catched_conn_single(c$uid)) {\n\t\tif (h$name == \"FROM\" || h$name == \"TO\") {\n#\t\t\tprint fmt(\"Header: %s=%s\", h$name, h$value);\n\t\t\tfor (p in watch_emails) {\n#\t\t\t\tprint fmt(\"Pattern: %s\", p);\n\t\t\t\tif (watch_emails_p[p] in h$value) {\n\t\t\t\t\tprint fmt(\"Catch Mime: conn$uid=%s, h$name=%s, h$value=%s\", c$uid, h$name, h$value);\n\t\t\t\t\tcatch_conn_multi(c, watch_emails[p]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n# \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u0437 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432\nevent file_new(f: fa_file) {\n\tif (is_catched_conn_table(f$conns)) {\n\t\tFiles::add_analyzer(f, Files::ANALYZER_EXTRACT);\n\t}\n}\n\nevent file_sniff(f: fa_file, meta: fa_metadata) {\n#\tlocal fname = fmt(\"%s-%s.%s\", f$source, f$id, meta$mime_type);\n#\tprint fmt(\"Extracting file %s\", fname);\n#\tlocal mime_type = (meta?$mime_type) ? meta$mime_type : \"NONE\";\n#\tprint fmt(\"Source: %s; ID: %s; Mime: %s\", f$source, f$id, mime_type);\n#\tif (f?$info) {\n#\t\tprint fmt(\" Info! ts: %s; mime: %s; filename: %s; md5: %s\", f$info$ts, f$info?$mime_type ? f$info$mime_type : \"NONE\", f$info?$filename ? f$info$filename : \"???\", f$info?$md5 ? f$info$md5 : \"000\");\n#\t}\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"bd032ac1ca7bcfefc7bd54e55d7dfe565a99ae26","subject":"Rename event definition","message":"Rename event definition\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_shared\/beemaster_events.bro","new_file":"scripts_shared\/beemaster_events.bro","new_contents":"module Beemaster;\n\n@load .\/beemaster_types\n\nexport {\n # ## DIONAEA EVENTS ##\n # Basic access\n global dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count,\n src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\n # HTTP(?) download completed\n global dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\n # HTTP(?) download offered\n global dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, origin: string, connector_id: string);\n # FTP connection\n global dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n command: string, arguments: string, origin: string, connector_id: string);\n # MySQL command execution\n global dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n args: string, origin: string, connector_id: string);\n # MySQL login\n global dionaea_login: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n username: string, password: string, origin: string, connector_id: string);\n # SMB connection established(?)\n global dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n transfersyntax: string, uuid: string, origin: string, connector_id: string);\n # SMB file requested\n global dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n opnum: count, uuid: string, origin: string, connector_id: string);\n\n # ## ACU EVENTS ##\n\n # ## MISC EVENTS ##\n\n # Conn::log_conn forwarding\n global log_conn: event(rec: Conn::Info);\n}\n","old_contents":"module Beemaster;\n\n@load .\/beemaster_types\n\nexport {\n # ## DIONAEA EVENTS ##\n # Basic access\n global dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count,\n src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\n # HTTP(?) download completed\n global dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\n # HTTP(?) download offered\n global dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, origin: string, connector_id: string);\n # FTP connection\n global dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n command: string, arguments: string, origin: string, connector_id: string);\n # MySQL command execution\n global dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n args: string, origin: string, connector_id: string);\n # MySQL login\n global dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n username: string, password: string, origin: string, connector_id: string);\n # SMB connection established(?)\n global dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n transfersyntax: string, uuid: string, origin: string, connector_id: string);\n # SMB file requested\n global dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n opnum: count, uuid: string, origin: string, connector_id: string);\n\n # ## ACU EVENTS ##\n\n # ## MISC EVENTS ##\n\n # Conn::log_conn forwarding\n global log_conn: event(rec: Conn::Info);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"1e669c1972125dc2f275f49b52bacef01e708595","subject":"Removed duplicate comment","message":"Removed duplicate comment\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_shared\/beemaster_events.bro","new_file":"scripts_shared\/beemaster_events.bro","new_contents":"module Beemaster;\n\n@load .\/beemaster_types\n\nexport {\n # ## DIONAEA EVENTS ##\n # Basic access\n global dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count,\n src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\n # HTTP(?) download completed\n global dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\n # HTTP(?) download offered\n global dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, origin: string, connector_id: string);\n # FTP connection\n global dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n command: string, arguments: string, origin: string, connector_id: string);\n # MySQL command execution\n global dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n args: string, origin: string, connector_id: string);\n # MySQL login\n global dionaea_login: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n username: string, password: string, origin: string, connector_id: string);\n # SMB connection established(?)\n global dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n transfersyntax: string, uuid: string, origin: string, connector_id: string);\n # SMB file requested\n global dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n opnum: count, uuid: string, origin: string, connector_id: string);\n # Blackhole service accessed\n global dionaea_blackhole: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string,\n length: count, origin: string, connector_id: string);\n\n # ## ACU EVENTS ##\n global tcp_event: event(rec: AlertInfo, discriminant: count);\n global lattice_event: event(rec: AlertInfo, protocol: string);\n\n # ## ACU METAALERTS ##\n global acu_meta_alert: event(timestamp: time, attack: string);\n global portscan_meta_alert: event(timestamp: time, attack: string, ips: vector of string);\n global lattice_meta_alert: event(timestamp: time, attack: string);\n\n # ## MISC EVENTS ##\n\n # Conn::log_conn forwarding\n global log_conn: event(rec: Conn::Info);\n}\n","old_contents":"module Beemaster;\n\n@load .\/beemaster_types\n\nexport {\n # ## DIONAEA EVENTS ##\n # Basic access\n global dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count,\n src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\n # HTTP(?) download completed\n global dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\n # HTTP(?) download offered\n global dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, origin: string, connector_id: string);\n # FTP connection\n global dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n command: string, arguments: string, origin: string, connector_id: string);\n # MySQL command execution\n global dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n args: string, origin: string, connector_id: string);\n # MySQL login\n global dionaea_login: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n username: string, password: string, origin: string, connector_id: string);\n # SMB connection established(?)\n global dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n transfersyntax: string, uuid: string, origin: string, connector_id: string);\n # SMB file requested\n global dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n opnum: count, uuid: string, origin: string, connector_id: string);\n # Blackhole service accessed\n global dionaea_blackhole: event(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string,\n length: count, origin: string, connector_id: string);\n\n # ## ACU EVENTS ##\n global tcp_event: event(rec: AlertInfo, discriminant: count);\n global lattice_event: event(rec: AlertInfo, protocol: string);\n\n # ## ACU METAALERTS ##\n global acu_meta_alert: event(timestamp: time, attack: string);\n global lattice_meta_alert: event(timestamp: time, attack: string);\n\n # ## ACU METAALERTS ##\n global portscan_meta_alert: event(timestamp: time, attack: string, ips: vector of string);\n\n # ## MISC EVENTS ##\n\n # Conn::log_conn forwarding\n global log_conn: event(rec: Conn::Info);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"9ee837f234abd21ed7ccd1d5c0405d5552ef3b71","subject":"see FPs where last_len = len","message":"see FPs where last_len = len\n\nAdded check for this so the script will exit if this is indeed the case. Let me know if my reasoning is off.","repos":"theflakes\/quantuminsert,theflakes\/quantuminsert,theflakes\/quantuminsert","old_file":"detection\/bro\/old\/qi.bro","new_file":"detection\/bro\/old\/qi.bro","new_contents":"##! Detect Quantum Insert\n#\n# qi.bro\n#\n# Fox-IT Security Research Team \n# \n\n@load base\/frameworks\/notice\n\nmodule QuantumInsert;\n\nexport {\n redef enum Notice::Type += {\n ## Indicates that a host performed a possible Quantum Insert\n PayloadDiffers,\n };\n}\n\nexport {\n redef record connection += {\n last_seq: count &optional;\n last_payload: string &optional;\n };\n}\n\nevent tcp_packet (c: connection, is_orig: bool, flags: string, seq: count, ack: count, len: count, payload: string)\n{\n # only process first server response and responses with data and only if the connection is established\n if (c$resp$state != TCP_ESTABLISHED || is_orig || len == 0) {\n return;\n }\n\n # check if we receive a packet with duplicate sequence numbers (only track the last seq)\n if (c?$last_payload && seq == c$last_seq) {\n local last_payload = c$last_payload;\n local last_len = |last_payload|;\n\n # if payloads are of equal length then this is a false positive more than likely so exit\n if (last_len == len) {\n return;\n } else {\n local other_payload = payload;\n }\n\n # one side of the payload can be smaller, so only compare the smallest.\n if (last_len < len) {\n other_payload = sub_bytes(payload, 0, last_len);\n } else if (last_len > len) {\n last_payload = sub_bytes(last_payload, 0, len);\n }\n\n # if payload differs it's a possible QI\n if (last_payload != other_payload) {\n print(fmt(\"POSSIBLE QI: sequence %s: %s:%s <- %s:%s -- [%s] differs from [%s]\", \n seq, c$id$orig_h, c$id$orig_p, c$id$resp_h, c$id$resp_p,\n payload, other_payload));\n NOTICE([$note=QuantumInsert::PayloadDiffers,\n $msg=fmt(\"Possible QuantumInsert detected. Payload differs (%s, %s): [%s], [%s]\",\n last_len, len, last_payload, other_payload),\n $conn=c,\n $identifier=c$uid\n ]);\n }\n }\n \n # keep track of payload and seq from server\n c$last_payload = payload;\n c$last_seq = seq;\n}\n","old_contents":"##! Detect Quantum Insert\n#\n# qi.bro\n#\n# Fox-IT Security Research Team \n# \n\n@load base\/frameworks\/notice\n\nmodule QuantumInsert;\n\nexport {\n redef enum Notice::Type += {\n ## Indicates that a host performed a possible Quantum Insert\n PayloadDiffers,\n };\n}\n\nexport {\n redef record connection += {\n last_seq: count &optional;\n last_payload: string &optional;\n };\n}\n\nevent tcp_packet (c: connection, is_orig: bool, flags: string, seq: count, ack: count, len: count, payload: string)\n{\n # only process first server response and responses with data and only if the connection is established\n if (c$resp$state != TCP_ESTABLISHED || is_orig || len == 0) {\n return;\n }\n\n # check if we receive a packet with duplicate sequence numbers (only track the last seq)\n if (c?$last_payload && seq == c$last_seq) {\n local other_payload = payload;\n local last_payload = c$last_payload;\n local last_len = |last_payload|;\n\n # one side of the payload can be smaller, so only compare the smallest.\n if (last_len < len) {\n other_payload = sub_bytes(payload, 0, last_len);\n } else if (last_len > len) {\n last_payload = sub_bytes(last_payload, 0, len);\n }\n\n # if payload differs it's a possible QI\n if (last_payload != other_payload) {\n print(fmt(\"POSSIBLE QI: sequence %s: %s:%s <- %s:%s -- [%s] differs from [%s]\", \n seq, c$id$orig_h, c$id$orig_p, c$id$resp_h, c$id$resp_p,\n payload, other_payload));\n NOTICE([$note=QuantumInsert::PayloadDiffers,\n $msg=fmt(\"Possible QuantumInsert detected. Payload differs (%s, %s): [%s], [%s]\",\n last_len, len, last_payload, other_payload),\n $conn=c,\n $identifier=c$uid\n ]);\n }\n }\n \n # keep track of payload and seq from server\n c$last_payload = payload;\n c$last_seq = seq;\n}\n","returncode":0,"stderr":"","license":"unlicense","lang":"Bro"} {"commit":"15ee686fd4b14e3e7ce820f9f74647339fbd80c0","subject":"only look at local ips","message":"only look at local ips\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"rogue-access-points.bro","new_file":"rogue-access-points.bro","new_contents":"@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nexport {\n\tredef enum Notice::Type += { \n\t\tRogue_Access_Point\n\t};\n\n const mobile_browsers =\n \/i(Phone|Pod|Pad)\/ |\n \/Android\/ &redef;\n\n const wireless_nets: set[subnet] &redef;\n global rogue_access_points : set[addr] &redef;\n}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=2\n{\n if (!is_orig )\n return;\n local ip = c$id$orig_h;\n\n if (!is_local_addr(ip) || ip in wireless_nets || ip in rogue_access_points)\n return;\n\n if ( name == \"USER-AGENT\" && mobile_browsers in value){\n local message = \"Rogue access point detected\";\n local submessage = value;\n NOTICE([$note=Rogue_Access_Point, $msg=message, $sub=submessage,\n $id=c$id]);\n add rogue_access_points[ip];\n }\n}\n","old_contents":"@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nexport {\n\tredef enum Notice::Type += { \n\t\tRogue_Access_Point\n\t};\n\n const mobile_browsers =\n \/i(Phone|Pod|Pad)\/ |\n \/Android\/ &redef;\n\n const wireless_nets: set[subnet] &redef;\n global rogue_access_points : set[addr] &redef;\n}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=2\n{\n if (!is_orig )\n return;\n local ip = c$id$orig_h;\n if (ip in wireless_nets || ip in rogue_access_points)\n return;\n\n if ( name == \"USER-AGENT\" && mobile_browsers in value){\n local message = \"Rogue access point detected\";\n local submessage = value;\n NOTICE([$note=Rogue_Access_Point, $msg=message, $sub=submessage,\n $id=c$id]);\n add rogue_access_points[ip];\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f4b71627284dafff81971bfb3b8dabc396ba79cf","subject":"Added new DNSBLs for finding blocked SMTP deliverers.","message":"Added new DNSBLs for finding blocked SMTP deliverers.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"@load global-ext\n@load smtp\n\ntype smtp_ext_session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tfirst_received: string &default=\"\";\n\tsecond_received: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: set[string];\n\tpath: string &default=\"\";\n\tis_webmail: bool &default=F; # This is not being set yet.\n\tagent: string &default=\"\";\n\t\n\t# These are used during processing and are likely less useful.\n\tcurrent_header: string &default=\"\";\n\tin_received_from_headers: bool &default=F;\n\treceived_finished: bool &default=F;\n};\n\nfunction default_smtp_ext_session_info(): smtp_ext_session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\tlocal tmp3: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2, $files=tmp3];\n\t}\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, si: smtp_ext_session_info);\n\nmodule SMTP;\n\nexport {\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Direction to capture the full \"Received from\" path.\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/b\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/\n\t | \/uceprotect\\.net\\\/\/\n\t | \/hostkarma\\.junkemailfilter\\.com\\\/\/ &redef;\n\t\n\tglobal conn_info: table[conn_id] of smtp_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\t\n}\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\telse if ( |ips| > 0 )\n\t\treturn ips[1];\n\telse\n\t\treturn \"\";\n}\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\t# Throw the event for other scripts to handle\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_smtp_ext_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_smtp_ext_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\t\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tadd conn_info[id]$files[data];\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$current_header == \"received\" )\n\t\t\tconn_log$first_received += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\telse if ( conn_log$current_header == \"agent\" )\n\t\t\tconn_log$agent += data;\t\t\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\n\telse if ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$second_received = conn_log$first_received;\n\t\tconn_log$first_received = split1(data, \/:[[:blank:]]*\/)[2];\n\t\t# Fill in the second value in case there is only one hop in the message.\n\t\tif ( conn_log$second_received == \"\" )\n\t\t\tconn_log$second_received = conn_log$first_received;\n\t\t\n\t\tconn_log$current_header = \"received\";\n\t\t}\n\t\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tlocal addresses = find_ip_addresses(data);\n\t\tif ( |addresses| > 0 )\n\t\t\tconn_log$x_originating_ip = addresses[1];\n\t\telse\n\t\t\tconn_log$x_originating_ip = data;\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\telse if ( \/^[xX]-[mM][aA][iI][lL][eE][rR]:[[:blank:]]*.\/ | \n\t \/^[uU][sS][eE][rR]-[aA][gG][eE][nN][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$agent = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"agent\";\n\t\t}\n\t\n\t}\n\t\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header )\n\t\treturn;\n\n\tlocal conn_log = conn_info[id];\n\t\n\t# If we've decided that we're done watching the received headers, we're done.\n\tif ( conn_log$received_finished )\n\t\treturn;\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tconn_log$in_received_from_headers = T;\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tconn_log$in_received_from_headers = F;\n\n\tif ( conn_log$in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\n\t\tlocal ip = to_addr(text_ip);\n\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tconn_log$received_finished=T;\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && !conn_log$received_finished ) \n\t\tconn_log$received_finished=T;\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"@load global-ext\n@load smtp\n\ntype smtp_ext_session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tfirst_received: string &default=\"\";\n\tsecond_received: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: set[string];\n\tpath: string &default=\"\";\n\tis_webmail: bool &default=F; # This is not being set yet.\n\tagent: string &default=\"\";\n\t\n\t# These are used during processing and are likely less useful.\n\tcurrent_header: string &default=\"\";\n\tin_received_from_headers: bool &default=F;\n\treceived_finished: bool &default=F;\n};\n\nfunction default_smtp_ext_session_info(): smtp_ext_session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\tlocal tmp3: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2, $files=tmp3];\n\t}\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, si: smtp_ext_session_info);\n\nmodule SMTP;\n\nexport {\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Direction to capture the full \"Received from\" path.\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n\t\n\tglobal conn_info: table[conn_id] of smtp_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\t\n}\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\telse if ( |ips| > 0 )\n\t\treturn ips[1];\n\telse\n\t\treturn \"\";\n}\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\t# Throw the event for other scripts to handle\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_smtp_ext_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_smtp_ext_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\t\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tadd conn_info[id]$files[data];\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$current_header == \"received\" )\n\t\t\tconn_log$first_received += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\telse if ( conn_log$current_header == \"agent\" )\n\t\t\tconn_log$agent += data;\t\t\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\n\telse if ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$second_received = conn_log$first_received;\n\t\tconn_log$first_received = split1(data, \/:[[:blank:]]*\/)[2];\n\t\t# Fill in the second value in case there is only one hop in the message.\n\t\tif ( conn_log$second_received == \"\" )\n\t\t\tconn_log$second_received = conn_log$first_received;\n\t\t\n\t\tconn_log$current_header = \"received\";\n\t\t}\n\t\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tlocal addresses = find_ip_addresses(data);\n\t\tif ( |addresses| > 0 )\n\t\t\tconn_log$x_originating_ip = addresses[1];\n\t\telse\n\t\t\tconn_log$x_originating_ip = data;\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\telse if ( \/^[xX]-[mM][aA][iI][lL][eE][rR]:[[:blank:]]*.\/ | \n\t \/^[uU][sS][eE][rR]-[aA][gG][eE][nN][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$agent = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"agent\";\n\t\t}\n\t\n\t}\n\t\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header )\n\t\treturn;\n\n\tlocal conn_log = conn_info[id];\n\t\n\t# If we've decided that we're done watching the received headers, we're done.\n\tif ( conn_log$received_finished )\n\t\treturn;\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tconn_log$in_received_from_headers = T;\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tconn_log$in_received_from_headers = F;\n\n\tif ( conn_log$in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\n\t\tlocal ip = to_addr(text_ip);\n\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tconn_log$received_finished=T;\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && !conn_log$received_finished ) \n\t\tconn_log$received_finished=T;\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"0b2e7f5c007f7a02179169207e6b47a49ab31a5e","subject":"Remove double-comment marker to prevent Broxygen syntax warnings","message":"Remove double-comment marker to prevent Broxygen syntax warnings","repos":"salesforce\/ja3","old_file":"bro\/ja3.bro","new_file":"bro\/ja3.bro","new_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n# LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","old_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n## LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"5902cd11c045f26b5fed75c5d118486906deb76a","subject":"Create __load__.bro","message":"Create __load__.bro","repos":"CrowdStrike\/cs-bro","old_file":"bro-scripts\/extensions\/__load__.bro","new_file":"bro-scripts\/extensions\/__load__.bro","new_contents":"@load .\/dns\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/extensions\/__load__.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"dda7d22206d3a62454e7ab57acc9b18f532c145c","subject":"bro-scripts: ntp-audit.bro: updated script to use the NTP analyzer and a separate namespace","message":"bro-scripts: ntp-audit.bro: updated script to use the NTP analyzer and a separate namespace\n","repos":"unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts,jonschipp\/bro-scripts,unusedPhD\/jonschipp_bro-scripts","old_file":"ntp-audit.bro","new_file":"ntp-audit.bro","new_contents":"# Written by Jon Schipp, 01-10-2013\n#\n# Detects when hosts send NTP messages to NTP servers not defined in time_servers.\n# To use:\n# 1. Enable the NTP analyzer:\n#\n# If running Bro 2.1 add lines to local.bro:\n#\n# global ports = set(123\/udp);\n# redef dpd_config += { [ANALYZER_NTP] = [$ports = ports]\n# };\n# \n# If running Bro 2.2 add lines to local.bro:\n#\n# event bro_init()\n# {\n# local ports = set(123\/udp);\n# Analyzer::register_for_ports(Analyzer::ANALYZER_NTP,\n# ports);\n# }\n#\n# 2. Copy ntp-audit.bro script to $BROPREFIX\/share\/bro\/site\n# 3. Place the following line into local.bro and put above code from step 1:\n# @load ntp-audit.bro\n# 4. Run commands to validate the script, install it, and put into production: \n# $ broctl check && broctl install && broctl restart\n#\n# If you would like to receive e-mails when a notice event is generated add to emailed_types in local.bro:\n# e.g.\n# redef Notice::emailed_types += {\n# MyScripts::Query_Sent_To_Wrong_Server,\n# };\n\n\n@load base\/frameworks\/notice\n\n# Use namespace so variables don't conflict with those in other scripts\nmodule MyScripts;\n\n# Export sets and types so that they can be redefined outside of this script\nexport {\n\n redef enum Notice::Type += {\n Query_Sent_To_Wrong_Server\n };\n\n # List your NTP servers here \n const time_servers: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n } &redef;\n\n # List any source addresses that should be excluded\n const time_exclude: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n 192.168.1.1, # Gateway\/NAT\/WAN uses external source for time\n } &redef;\n\n}\n\nevent ntp_message(u: connection, msg: ntp_msg, excess: string)\n {\n if ( u$id$orig_h !in time_exclude && u$id$resp_h !in time_servers )\n {\n NOTICE([$note=Query_Sent_To_Wrong_Server,\n $msg=\"NTP query destined to non-defined NTP servers\", $conn=u,\n $identifier=cat(u$id$orig_h),\n $suppress_for=1day]);\n }\n }\n~ \n","old_contents":"# Written by Jon Schipp\n# Detects when hosts send NTP queries to NTP servers not defined in time_servers.\n# \tTo use:\n# \t\t1. Add script to configuration local.bro: $ echo '@load ntp-audit.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# \t\t2. Copy script to $BROPREFIX\/share\/bro\/site\n# \t\t3. $ broctl check && broctl install && broctl restart\n\n@load base\/frameworks\/notice\n\n# List your NTP servers here\t\nconst time_servers: set[addr] = {\n\t192.168.1.250,\n\t192.168.1.251,\n} &redef;\n\n# List any source addresses that should be excluded\nconst time_exclude: set[addr] = {\n\t192.168.1.250,\n\t192.168.1.251,\n\t192.168.1.1, # Gateway\/NAT \n} &redef;\n\nexport {\n\n redef enum Notice::Type += {\n NTP::Query_Sent_To_Wrong_Server\n };\n}\n\nredef Notice::emailed_types += {\n NTP::Query_Sent_To_Wrong_Server\n};\n\nevent udp_request(u: connection)\n {\n if ( u$id$orig_h !in time_exclude && u$id$resp_h !in time_servers && u$id$resp_p == 123\/udp )\n {\n NOTICE([$note=NTP::Query_Sent_To_Wrong_Server,\n $msg=\"NTP query destined to non-defined NTP servers\", $conn=u,\n $identifier=cat(u$id$orig_h),\n $suppress_for=1day]);\n }\n }\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"c409de6e91102c16560a70a4a4bf23516ba67339","subject":"Bro-Unterst\u00fctzung f\u00fcr SMB (schlie\u00dft Dateidownloads ein) hinzugef\u00fcgt.","message":"Bro-Unterst\u00fctzung f\u00fcr SMB (schlie\u00dft Dateidownloads ein) hinzugef\u00fcgt.\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dionaea_receiver.bro","new_file":"custom_scripts\/dionaea_receiver.bro","new_contents":"@load .\/dio_incident_log.bro\n@load .\/dio_json_log.bro\n@load .\/dio_mysql_log.bro\n@load .\/dio_download_complete_log.bro\n@load .\/dio_download_offer_log.bro\n@load .\/dio_smb_bind_log.bro\n@load .\/dio_smb_request_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string);\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, md5hash: string, file: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_incident::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $connector_id=connector_id];\n\n Log::write(Dio_incident::LOG, rec);\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n\n Log::write(Dio_mysql::LOG, rec);\n}\n\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, md5hash: string, file: string, origin: string, connector_id: string) { \n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_download_complete: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, url=%s, md5hash=%s, file=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, url, md5hash, file, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $url=url, $md5hash=md5hash, $file=file, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, origin: string, connector_id: string) {\n{\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_download_offer: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, url=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, url, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_smb_request: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, opnum=%d, uuid=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, opnum, uuid, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_smb_bind: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, transfersyntax=%s, uuid=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, transfersyntax, uuid, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","old_contents":"@load .\/dio_incident_log.bro\n@load .\/dio_json_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string);\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_incident::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $connector_id=connector_id];\n\n Log::write(Dio_incident::LOG, rec);\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n\n Log::write(Dio_mysql::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"24931a58d22e03b24588cfa078a8fe13108fe4ba","subject":"HTTP proxy headers moved into a set. Thanks Justin!","message":"HTTP proxy headers moved into a set. Thanks Justin!\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext.bro","new_file":"http-ext.bro","new_contents":"@load global-ext\n@load http-request\n@load http-entity\n\ntype http_ext_session_info: record {\n\tstart_time: time;\n\tmethod: string &default=\"\";\n\thost: string &default=\"\";\n\turi: string &default=\"\";\n\turl: string &default=\"\";\n\treferrer: string &default=\"\";\n\tuser_agent: string &default=\"\";\n\tproxied_for: string &default=\"\";\n\n\tforce_log: bool &default=F; # This will force the request to be logged (if doing any logging)\n\tforce_log_client_body: bool &default=F; # This will force the client body to be logged.\n\tforce_log_reasons: set[string]; # Reasons why the forced logging happened.\n\t\n\t# This is internal state tracking.\n\tfull: bool &default=F;\n\tnew_user_agent: bool &default=F;\n};\n\nfunction default_http_ext_session_info(): http_ext_session_info\n\t{\n\tlocal x: http_ext_session_info;\n\tlocal tmp: set[string] = set();\n\tx$start_time=network_time();\n\tx$force_log_reasons=tmp;\n\treturn x;\n\t}\n\ntype http_ext_activity_count: record {\n\tsql_injections: track_count;\n\tsql_injection_probes: track_count;\n\tsuspicious_posts: track_count;\n};\n\nfunction default_http_ext_activity_count(a:addr):http_ext_activity_count \n\t{\n\tlocal x: http_ext_activity_count; \n\treturn x; \n\t}\n\n# Define the generic http_ext events that can be handled from other scripts\nglobal http_ext: event(id: conn_id, si: http_ext_session_info);\n\nmodule HTTP;\n\n# Uncomment the following lines if you have these data sets available and would\n# like to use them.\n#@load malware_com_br_block_list-data\n#@load zeus-data\n#@load malwaredomainlist-data\n\nexport {\n\tredef enum Notice += { \n\t\tHTTP_Suspicious,\n\t\tHTTP_SQL_Injection_Attack,\n\t\tHTTP_SQL_Injection_Heavy_Probing,\n\n\t\tHTTP_Malware_com_br_Block_List,\n\t\tHTTP_Zeus_Communication,\n\t\tHTTP_MalwareDomainList_Communication,\n\t};\n\n\t# This is the regular expression that is used to match URI based SQL injections\n\tconst sql_injection_regex = \n\t\t \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[iI][nN][sS][eE][rR][tT])[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([oO][rR]|[aA][nN][dD])([[:blank:]]|\\\/\\*.*?\\*\\\/)+['\"]?[^a-zA-Z&]+?=\/\n\t\t| \/[\\?&][^[:blank:]]+?=[\\-0-9%]*([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/)*(\\-|\\+|\\|\\|)([[:blank:]]|\\\/\\*.*?\\*\\\/)*([0-9]|\\(?[cC][oO][nN][vV][eE][rR][tT]|[cC][aA][sS][tT])\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/|;)*([oO][rR]|[aA][nN][dD]|[hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[rR][eE][gG][eE][xX][pP]|[iI][nN][sS][eE][rR][tT]|\\()[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]]+?=[^\\.]*?([cC][hH][aA][rR]|[aA][sS][cC][iI][iI]|[sS][uU][bB][sS][tT][rR][iI][nN][gG]|[tT][rR][uU][nN][cC][aA][tT][eE]|[vV][eE][rR][sS][iI][oO][nN]|[lL][eE][nN][gG][tT][hH])\\(\/ &redef;\n\n\t# SQL injection probes are considered to be:\n\t# 1. A single single-quote at the end of a URL with no other single-quotes.\n\t# 2. URLs with one single quote at the end of a normal GET value.\n\tconst sql_injection_probe_regex =\n\t\t \/^[^\\']+\\'$\/\n\t\t| \/^[^\\']+\\'&[^\\']*$\/ &redef;\n\n\t# Define which hosts user-agents you'd like to track.\n\tconst track_user_agents_for = LocalHosts &redef;\n\n\t# If there is something creating large number of strange user-agent,\n\t# you can filter those out with this pattern.\n\tconst ignored_user_agents = \/DONT_MATCH_ANYTHING\/ &redef;\n\n\t# HTTP post data contents that appear suspicious.\n\t# This is usually spammy forum postings and the like.\n\tconst suspicious_http_posts = \n\t\t\/[vV][iI][aA][gG][rR][aA]\/ | \n\t\t\/[tT][rR][aA][mM][aA][dD][oO][lL]\/ |\n\t\t\/[cC][iI][aA][lL][iI][sS]\/ | \n\t\t\/[sS][oO][mM][aA]\/ | \n\t\t\/[hH][yY][dD][rR][oO][cC][oO][dD][oO][nN][eE]\/ |\n\t\t\/[cC][aA][nN][aA][dD][iI][aA][nN].{0,15}[pP][hH][aA][rR][mM][aA][cC][yY]\/ |\n\t\t\/[rR][iI][nN][gG].?[tT][oO][nN][eE]\/ |\n\t\t\/[pP][eE][nN][iI][sS]\/ |\n\t\t\/[oO][nN][lL][iI][nN][eE].?[cC][aA][sS][iI][nN][oO]\/ |\n\t\t\/[rR][eE][mM][oO][rR][tT][gG][aA][gG][eE][sS]\/ |\n\t\t# more than 4 bbcode style links in a POST is deemed suspicious\n\t\t\/(url=http:.*){4}\/ | \n\t\t# more that 4 html links is also suspicious\n\t\t\/(a.href(=|%3[dD]).*){4}\/ &redef;\n\t\t\n\t\tconst http_forwarded_headers = {\n\t\t \"HTTP_FORWARDED\",\n\t\t \"FORWARDED\",\n\t\t \"HTTP_X_FORWARDED_FOR\",\n\t\t \"X_FORWARDED_FOR\",\n\t\t \"HTTP_X_FORWARDED_FROM\",\n\t\t \"X_FORWARDED_FROM\",\n\t\t \"HTTP_CLIENT_IP\",\n\t\t \"CLIENT_IP\",\n\t\t \"HTTP_FROM\",\n\t\t \"FROM\",\n\t\t \"HTTP_VIA\",\n\t\t \"VIA\",\n\t\t \"HTTP_XROXY_CONNECTION\",\n\t\t \"XROXY_CONNECTION\",\n\t\t \"HTTP_PROXY_CONNECTION\",\n\t\t \"PROXY_CONNECTION\",\n\t\t} &redef;\n\n\tglobal conn_info: table[conn_id] of http_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\n\tglobal activity_counters: table[addr] of http_ext_activity_count \n\t\t&create_expire=1day \n\t\t&synchronized\n\t\t&default=default_http_ext_activity_count\n\t\t&redef;\n\n\t# You can inspect this during runtime from other modules to see what\n\t# user-agents a host has used.\n\tglobal known_user_agents: table[addr] of set[string] \n\t\t&create_expire=3hrs\n\t\t&synchronized\n\t\t&default=addr_empty_string_set\n\t\t&redef;\n}\n\n# This is called from signatures (theoretically)\nfunction log_post(state: signature_state, data: string): bool\n\t{\n\t# Log the post data when it becomes available.\n\tif ( state$conn$id in conn_info )\n\t\t{\n\t\tconn_info[state$conn$id]$force_log_client_body = T;\n\t\tadd conn_info[state$conn$id]$force_log_reasons[fmt(\"matched_signature_%s\",state$id)];\n\t\t}\n\t\n\t# We'll always allow the signature to fire\n\treturn T;\n\t}\n\t\nevent http_request(c: connection, method: string, original_URI: string,\n\t unescaped_URI: string, version: string)\n\t{\n\tif ( c$id !in conn_info )\n\t\t{\n\t\tlocal x = default_http_ext_session_info();\n\t\tconn_info[c$id] = x;\n\t\t}\n\t\n\tlocal sess_ext = conn_info[c$id];\n\tsess_ext$method = method;\n\tsess_ext$uri = unescaped_URI;\n\t}\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &priority=5\n\t{\n\tif ( !is_orig )\n\t\treturn; \n\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t\treturn;\n\t\n\tlocal sess_ext = conn_info[id];\n\tsess_ext$url = fmt(\"http:\/\/%s%s\", sess_ext$host, sess_ext$uri);\n\n\t# Detect and log SQL injection attempts in their own log file\n\tif ( sql_injection_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection\"];\n\t\t\n\t\t++(activity_counters[id$orig_h]$sql_injections$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[id$orig_h]$sql_injections) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Attack,\n\t\t\t $msg=fmt(\"SQL injection attack (n=%d): %s -> %s\",\n\t\t\t activity_counters[id$orig_h]$sql_injections$n,\n\t\t\t numeric_id_string(id), sess_ext$url),\n\t\t\t $conn=c,\n\t\t\t $n=activity_counters[id$orig_h]$sql_injections$n]);\n\t\t\t}\n\t\t}\n\tif ( sql_injection_probe_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection_probe\"];\n\t\t++(activity_counters[id$orig_h]$sql_injection_probes$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[c$id$orig_h]$sql_injection_probes) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Heavy_Probing, \n\t\t\t $msg=fmt(\"Heavy probing from %s\", id$orig_h), \n\t\t\t $n=activity_counters[c$id$orig_h]$sql_injection_probes$n, \n\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\n@ifdef ( MalwareComBr_BlockList )\n\tif ( MalwareComBr_BlockList in sess_ext$url )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malware_com_br\"];\n\t\tlocal malware_com_br_msg = fmt(\"%s %s %s\", sess_ext$method, sess_ext$url, sess_ext$referrer);\n\t\tNOTICE([$note=HTTP_Malware_com_br_Block_List, $msg=malware_com_br_msg, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( ZeusDomains )\n\tif ( sess_ext$host in ZeusDomains )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"zeustracker\"];\n\t\tlocal zeus_msg = fmt(\"%s communicated with likely Zeus controller at %s\", c$id$orig_h, sess_ext$host);\n\t\tNOTICE([$note=HTTP_Zeus_Communication, $msg=zeus_msg, $sub=sess_ext$url, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( MalwareDomainList )\n\tif ( sess_ext$url in MalwareDomainList )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malwaredomainlist\"];\n\t\tlocal mdl_msg = fmt(\"%s communicated with malwaredomainlist.com URL at %s\", c$id$orig_h, sess_ext$url);\n\t\tNOTICE([$note=HTTP_MalwareDomainList_Communication, $msg=mdl_msg, $sub=MalwareDomainList[sess_ext$url], $conn=c]);\n\t\t}\n@endif\n\n\tevent http_ext(id, sess_ext);\n\t\n\t# No data from the reply is supported yet, so it's ok to delete here.\n\tdelete conn_info[c$id];\n\t}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in conn_info )\n\t\tconn_info[c$id] = default_http_ext_session_info();\n\n\tlocal ci = conn_info[c$id];\n\n\tif ( name == \"REFERER\" )\n\t\tci$referrer = value;\n\t\t\n\telse if ( name == \"HOST\" )\n\t\tci$host = value;\n\n\telse if ( name == \"USER-AGENT\" )\n\t\t{\n\t\tci$user_agent = value;\n\t\t\n\t\tif ( ignored_user_agents in value ) \n\t\t\treturn;\n\t\t\t\n\t\tif ( addr_matches_hosts(c$id$orig_h, track_user_agents_for) ||\n\t\t\t value in known_user_agents[c$id$orig_h] )\n\t\t\t{\n\t\t\tif ( c$id$orig_h !in known_user_agents )\n\t\t\t\t{\n\t\t\t\tknown_user_agents[c$id$orig_h] = set();\n\t\t\t\tci$new_user_agent = T;\n\t\t\t\t}\n\t\t\tadd known_user_agents[c$id$orig_h][value];\n\t\t\t}\n\t\t}\n\n\telse if ( name in http_forwarded_headers )\n\t\t{\n\t\tif ( ci$proxied_for == \"\" )\n\t\t\tci$proxied_for = fmt(\"(%s::%s)\", name, value);\n\t\telse\n\t\t\tci$proxied_for = fmt(\"%s, (%s::%s)\", ci$proxied_for, name, value);\n\t\t}\n\t}\n","old_contents":"@load global-ext\n@load http-request\n@load http-entity\n\ntype http_ext_session_info: record {\n\tstart_time: time;\n\tmethod: string &default=\"\";\n\thost: string &default=\"\";\n\turi: string &default=\"\";\n\turl: string &default=\"\";\n\treferrer: string &default=\"\";\n\tuser_agent: string &default=\"\";\n\tproxied_for: string &default=\"\";\n\n\tforce_log: bool &default=F; # This will force the request to be logged (if doing any logging)\n\tforce_log_client_body: bool &default=F; # This will force the client body to be logged.\n\tforce_log_reasons: set[string]; # Reasons why the forced logging happened.\n\t\n\t# This is internal state tracking.\n\tfull: bool &default=F;\n\tnew_user_agent: bool &default=F;\n};\n\nfunction default_http_ext_session_info(): http_ext_session_info\n\t{\n\tlocal x: http_ext_session_info;\n\tlocal tmp: set[string] = set();\n\tx$start_time=network_time();\n\tx$force_log_reasons=tmp;\n\treturn x;\n\t}\n\ntype http_ext_activity_count: record {\n\tsql_injections: track_count;\n\tsql_injection_probes: track_count;\n\tsuspicious_posts: track_count;\n};\n\nfunction default_http_ext_activity_count(a:addr):http_ext_activity_count \n\t{\n\tlocal x: http_ext_activity_count; \n\treturn x; \n\t}\n\n# Define the generic http_ext events that can be handled from other scripts\nglobal http_ext: event(id: conn_id, si: http_ext_session_info);\n\nmodule HTTP;\n\n# Uncomment the following lines if you have these data sets available and would\n# like to use them.\n#@load malware_com_br_block_list-data\n#@load zeus-data\n#@load malwaredomainlist-data\n\nexport {\n\tredef enum Notice += { \n\t\tHTTP_Suspicious,\n\t\tHTTP_SQL_Injection_Attack,\n\t\tHTTP_SQL_Injection_Heavy_Probing,\n\n\t\tHTTP_Malware_com_br_Block_List,\n\t\tHTTP_Zeus_Communication,\n\t\tHTTP_MalwareDomainList_Communication,\n\t};\n\n\t# This is the regular expression that is used to match URI based SQL injections\n\tconst sql_injection_regex = \n\t\t \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[iI][nN][sS][eE][rR][tT])[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([oO][rR]|[aA][nN][dD])([[:blank:]]|\\\/\\*.*?\\*\\\/)+['\"]?[^a-zA-Z&]+?=\/\n\t\t| \/[\\?&][^[:blank:]]+?=[\\-0-9%]*([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/)*(\\-|\\+|\\|\\|)([[:blank:]]|\\\/\\*.*?\\*\\\/)*([0-9]|\\(?[cC][oO][nN][vV][eE][rR][tT]|[cC][aA][sS][tT])\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/|;)*([oO][rR]|[aA][nN][dD]|[hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[rR][eE][gG][eE][xX][pP]|[iI][nN][sS][eE][rR][tT]|\\()[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]]+?=[^\\.]*?([cC][hH][aA][rR]|[aA][sS][cC][iI][iI]|[sS][uU][bB][sS][tT][rR][iI][nN][gG]|[tT][rR][uU][nN][cC][aA][tT][eE]|[vV][eE][rR][sS][iI][oO][nN]|[lL][eE][nN][gG][tT][hH])\\(\/ &redef;\n\n\t# SQL injection probes are considered to be:\n\t# 1. A single single-quote at the end of a URL with no other single-quotes.\n\t# 2. URLs with one single quote at the end of a normal GET value.\n\tconst sql_injection_probe_regex =\n\t\t \/^[^\\']+\\'$\/\n\t\t| \/^[^\\']+\\'&[^\\']*$\/ &redef;\n\n\t# Define which hosts user-agents you'd like to track.\n\tconst track_user_agents_for = LocalHosts &redef;\n\n\t# If there is something creating large number of strange user-agent,\n\t# you can filter those out with this pattern.\n\tconst ignored_user_agents = \/DONT_MATCH_ANYTHING\/ &redef;\n\n\t# HTTP post data contents that appear suspicious.\n\t# This is usually spammy forum postings and the like.\n\tconst suspicious_http_posts = \n\t\t\/[vV][iI][aA][gG][rR][aA]\/ | \n\t\t\/[tT][rR][aA][mM][aA][dD][oO][lL]\/ |\n\t\t\/[cC][iI][aA][lL][iI][sS]\/ | \n\t\t\/[sS][oO][mM][aA]\/ | \n\t\t\/[hH][yY][dD][rR][oO][cC][oO][dD][oO][nN][eE]\/ |\n\t\t\/[cC][aA][nN][aA][dD][iI][aA][nN].{0,15}[pP][hH][aA][rR][mM][aA][cC][yY]\/ |\n\t\t\/[rR][iI][nN][gG].?[tT][oO][nN][eE]\/ |\n\t\t\/[pP][eE][nN][iI][sS]\/ |\n\t\t\/[oO][nN][lL][iI][nN][eE].?[cC][aA][sS][iI][nN][oO]\/ |\n\t\t\/[rR][eE][mM][oO][rR][tT][gG][aA][gG][eE][sS]\/ |\n\t\t# more than 4 bbcode style links in a POST is deemed suspicious\n\t\t\/(url=http:.*){4}\/ | \n\t\t# more that 4 html links is also suspicious\n\t\t\/(a.href(=|%3[dD]).*){4}\/ &redef;\n\n\tglobal conn_info: table[conn_id] of http_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\n\tglobal activity_counters: table[addr] of http_ext_activity_count \n\t\t&create_expire=1day \n\t\t&synchronized\n\t\t&default=default_http_ext_activity_count\n\t\t&redef;\n\n\t# You can inspect this during runtime from other modules to see what\n\t# user-agents a host has used.\n\tglobal known_user_agents: table[addr] of set[string] \n\t\t&create_expire=3hrs\n\t\t&synchronized\n\t\t&default=addr_empty_string_set\n\t\t&redef;\n}\n\n# This is called from signatures (theoretically)\nfunction log_post(state: signature_state, data: string): bool\n\t{\n\t# Log the post data when it becomes available.\n\tif ( state$conn$id in conn_info )\n\t\t{\n\t\tconn_info[state$conn$id]$force_log_client_body = T;\n\t\tadd conn_info[state$conn$id]$force_log_reasons[fmt(\"matched_signature_%s\",state$id)];\n\t\t}\n\t\n\t# We'll always allow the signature to fire\n\treturn T;\n\t}\n\t\nevent http_request(c: connection, method: string, original_URI: string,\n\t unescaped_URI: string, version: string)\n\t{\n\tif ( c$id !in conn_info )\n\t\t{\n\t\tlocal x = default_http_ext_session_info();\n\t\tconn_info[c$id] = x;\n\t\t}\n\t\n\tlocal sess_ext = conn_info[c$id];\n\tsess_ext$method = method;\n\tsess_ext$uri = unescaped_URI;\n\t}\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &priority=5\n\t{\n\tif ( !is_orig )\n\t\treturn; \n\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t\treturn;\n\t\n\tlocal sess_ext = conn_info[id];\n\tsess_ext$url = fmt(\"http:\/\/%s%s\", sess_ext$host, sess_ext$uri);\n\n\t# Detect and log SQL injection attempts in their own log file\n\tif ( sql_injection_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection\"];\n\t\t\n\t\t++(activity_counters[id$orig_h]$sql_injections$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[id$orig_h]$sql_injections) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Attack,\n\t\t\t $msg=fmt(\"SQL injection attack (n=%d): %s -> %s\",\n\t\t\t activity_counters[id$orig_h]$sql_injections$n,\n\t\t\t numeric_id_string(id), sess_ext$url),\n\t\t\t $conn=c,\n\t\t\t $n=activity_counters[id$orig_h]$sql_injections$n]);\n\t\t\t}\n\t\t}\n\tif ( sql_injection_probe_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection_probe\"];\n\t\t++(activity_counters[id$orig_h]$sql_injection_probes$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[c$id$orig_h]$sql_injection_probes) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Heavy_Probing, \n\t\t\t $msg=fmt(\"Heavy probing from %s\", id$orig_h), \n\t\t\t $n=activity_counters[c$id$orig_h]$sql_injection_probes$n, \n\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\n@ifdef ( MalwareComBr_BlockList )\n\tif ( MalwareComBr_BlockList in sess_ext$url )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malware_com_br\"];\n\t\tlocal malware_com_br_msg = fmt(\"%s %s %s\", sess_ext$method, sess_ext$url, sess_ext$referrer);\n\t\tNOTICE([$note=HTTP_Malware_com_br_Block_List, $msg=malware_com_br_msg, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( ZeusDomains )\n\tif ( sess_ext$host in ZeusDomains )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"zeustracker\"];\n\t\tlocal zeus_msg = fmt(\"%s communicated with likely Zeus controller at %s\", c$id$orig_h, sess_ext$host);\n\t\tNOTICE([$note=HTTP_Zeus_Communication, $msg=zeus_msg, $sub=sess_ext$url, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( MalwareDomainList )\n\tif ( sess_ext$url in MalwareDomainList )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malwaredomainlist\"];\n\t\tlocal mdl_msg = fmt(\"%s communicated with malwaredomainlist.com URL at %s\", c$id$orig_h, sess_ext$url);\n\t\tNOTICE([$note=HTTP_MalwareDomainList_Communication, $msg=mdl_msg, $sub=MalwareDomainList[sess_ext$url], $conn=c]);\n\t\t}\n@endif\n\n\tevent http_ext(id, sess_ext);\n\t\n\t# No data from the reply is supported yet, so it's ok to delete here.\n\tdelete conn_info[c$id];\n\t}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in conn_info )\n\t\tconn_info[c$id] = default_http_ext_session_info();\n\n\tlocal ci = conn_info[c$id];\n\n\tif ( name == \"REFERER\" )\n\t\tci$referrer = value;\n\t\t\n\telse if ( name == \"HOST\" )\n\t\tci$host = value;\n\n\telse if ( name == \"USER-AGENT\" )\n\t\t{\n\t\tci$user_agent = value;\n\t\t\n\t\tif ( ignored_user_agents in value ) \n\t\t\treturn;\n\t\t\t\n\t\tif ( addr_matches_hosts(c$id$orig_h, track_user_agents_for) ||\n\t\t\t value in known_user_agents[c$id$orig_h] )\n\t\t\t{\n\t\t\tif ( c$id$orig_h !in known_user_agents )\n\t\t\t\t{\n\t\t\t\tknown_user_agents[c$id$orig_h] = set();\n\t\t\t\tci$new_user_agent = T;\n\t\t\t\t}\n\t\t\tadd known_user_agents[c$id$orig_h][value];\n\t\t\t}\n\t\t}\n\n\telse if ( name == \"HTTP_FORWARDED\" ||\n\t name == \"FORWARDED\" ||\n\t name == \"HTTP_X_FORWARDED_FOR\" ||\n\t name == \"X_FORWARDED_FOR\" ||\n\t name == \"HTTP_X_FORWARDED_FROM\" ||\n\t name == \"X_FORWARDED_FROM\" ||\n\t name == \"HTTP_CLIENT_IP\" ||\n\t name == \"CLIENT_IP\" ||\n\t name == \"HTTP_FROM\" ||\n\t name == \"FROM\" ||\n\t name == \"HTTP_VIA\" ||\n\t name == \"VIA\" ||\n\t name == \"HTTP_XROXY_CONNECTION\" ||\n\t name == \"XROXY_CONNECTION\" ||\n\t name == \"HTTP_PROXY_CONNECTION\" ||\n\t name == \"PROXY_CONNECTION\")\n\t\t{\n\t\tif ( ci$proxied_for == \"\" )\n\t\t\tci$proxied_for = fmt(\"(%s::%s)\", name, value);\n\t\telse\n\t\t\tci$proxied_for = fmt(\"%s, (%s::%s)\", ci$proxied_for, name, value);\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"408e3a33563a5e70ae4857e95016c5a216ef4465","subject":"comment out incorret bro load","message":"comment out incorret bro load\n","repos":"firewalla\/firewalla,firewalla\/firewalla,MelvinTo\/firewalla,firewalla\/firewalla,MelvinTo\/firewalla,firewalla\/firewalla,firewalla\/firewalla,MelvinTo\/firewalla,MelvinTo\/firewalla,MelvinTo\/firewalla","old_file":"platform\/gold\/hooks\/before_bro\/local.bro","new_file":"platform\/gold\/hooks\/before_bro\/local.bro","new_contents":"##! Local site policy. Customize as appropriate. \n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\nredef ignore_checksums = T;\nredef SSL::disable_analyzer_after_detection = F;\n\n#@load site\/sqlite.bro\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n@load tuning\/json-logs\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Log some information about web applications being used by users \n# on your network.\n#@load misc\/app-stats\n\n# Detect traceroute being run on the network. \n@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more \n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n@load frameworks\/software\/windows-version-detection\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when \n# running on live traffic. Enable it cautiously.\n#@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets \n# where the name is not part of your local DNS zone and is being hosted \n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n# @load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and \n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\n\n# enable link-layer address information to connection logs\n@load policy\/protocols\/conn\/mac-logging\n\nredef restrict_filters += [[\"not-mdns\"] = \"not port 5353\"];\n\nredef SSL::disable_analyzer_after_detection = F;\n#redef Communication::listen_interface = 127.0.0.1;\n\n@load base\/protocols\/dhcp\n#@load \/home\/pi\/.zkg\/script_dir\/packages\n","old_contents":"##! Local site policy. Customize as appropriate. \n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\nredef ignore_checksums = T;\nredef SSL::disable_analyzer_after_detection = F;\n\n#@load site\/sqlite.bro\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n@load tuning\/json-logs\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Log some information about web applications being used by users \n# on your network.\n#@load misc\/app-stats\n\n# Detect traceroute being run on the network. \n@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more \n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n@load frameworks\/software\/windows-version-detection\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when \n# running on live traffic. Enable it cautiously.\n#@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets \n# where the name is not part of your local DNS zone and is being hosted \n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n# @load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and \n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\n\n# enable link-layer address information to connection logs\n@load policy\/protocols\/conn\/mac-logging\n\nredef restrict_filters += [[\"not-mdns\"] = \"not port 5353\"];\n\nredef SSL::disable_analyzer_after_detection = F;\n#redef Communication::listen_interface = 127.0.0.1;\n\n@load base\/protocols\/dhcp\n@load \/home\/pi\/.zkg\/script_dir\/packages\n","returncode":0,"stderr":"","license":"agpl-3.0","lang":"Bro"} {"commit":"b191cf3c398e29d9ab6f6801190a37b960f55f2c","subject":"try to detect phishing and phishing replies","message":"try to detect phishing and phishing replies\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-phish-passwords.bro","new_file":"smtp-ext-phish-passwords.bro","new_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &write_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_threshold = 50;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(\/[pP][aA][sS][sS][wW][oO][rR][dD]\/ in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s\", si$mailfrom, to),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(++(phishing_counter[si$mailfrom]) > phishing_threshold){\n if(si$reply_to != \"\")\n add phishing_reply_tos[si$reply_to];\n else \n add phishing_reply_tos[si$mailfrom];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing\", si$mailfrom, si$reply_to),\n $sub=si$mailfrom\n ]);\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","old_contents":"@load global-ext\n@load smtp-ext\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(\/[pP][aA][sS][sS][wW][oO][rR][dD]\/ in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h))\n return;\n if (id !in smtp_password_conns)\n return;\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"acfb25c5528764470ca62dbe5bf441e6697a22e4","subject":"Re-Add Balance log","message":"Re-Add Balance log\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/balance.bro","new_file":"scripts_master\/balance.bro","new_contents":"module Balance;\n\nexport {\n redef enum Log::ID += { LOG };\n redef LogAscii::empty_field = \"EMPTY\";\n\n type Info: record {\n connector: string &log;\n slave: string &log;\n };\n}\n\nevent bro_init() &priority=5 {\n Log::create_stream(Balance::LOG, [$columns=Info, $path=\"balance\"]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'scripts_master\/balance.bro' did not match any file(s) known to git\n","license":"mit","lang":"Bro"} {"commit":"c65fc80a2e98b9ba7b4dccad54990c03714738a4","subject":"Update ssl-certificates.bro","message":"Update ssl-certificates.bro","repos":"unusedPhD\/CrowdStrike_cs-bro,CrowdStrike\/cs-bro,albertzaharovits\/cs-bro,theflakes\/cs-bro,kingtuna\/cs-bro","old_file":"bro-scripts\/intel-extensions\/seen\/ssl-certificates.bro","new_file":"bro-scripts\/intel-extensions\/seen\/ssl-certificates.bro","new_contents":"# Intel framework support for SSL certificate subjects\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/ssl\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent ssl_established(c: connection)\n{\nif ( c$ssl?$subject )\n Intel::seen([$indicator=c$ssl$subject,\n $indicator_type=Intel::CERT_SUBJECT,\n $conn=c,\n $where=SSL::IN_SERVER_CERT]);\n\nif ( c$ssl?$client_subject )\n Intel::seen([$indicator=c$ssl$client_subject,\n $indicator_type=Intel::CERT_SUBJECT,\n $conn=c,\n $where=SSL::IN_CLIENT_CERT]);\n}\n","old_contents":"@load base\/protocols\/ssl\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent ssl_established(c: connection)\n{\nif ( c$ssl?$subject )\n Intel::seen([$indicator=c$ssl$subject,\n $indicator_type=Intel::CERT_SUBJECT,\n $conn=c,\n $where=SSL::IN_SERVER_CERT]);\n\nif ( c$ssl?$client_subject )\n Intel::seen([$indicator=c$ssl$client_subject,\n $indicator_type=Intel::CERT_SUBJECT,\n $conn=c,\n $where=SSL::IN_CLIENT_CERT]);\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"5f30ec631de929435eb54cb7a2c37c6265ee9cba","subject":"Fixing test.","message":"Fixing test.\n","repos":"rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,FrozenCaribou\/hilti","old_file":"bro\/tests\/pac2\/type-converter.bro","new_file":"bro\/tests\/pac2\/type-converter.bro","new_contents":"#\n# @TEST-EXEC: bro -r ${TRACES}\/ssh-single-conn.trace .\/conv.evt %INPUT >output\n# @TEST-EXEC: btest-diff output\n#\n\n@TEST-START-FILE conv.pac2\n\nmodule Conv;\n\nexport type Test = unit {\n a: bytes &length=5;\n b: int<16>;\n c: uint<16>;\n d: bytes &length=1 &convert=3.14;\n e: bytes &length=1 &convert=1.2.3.4;\n f: bytes &length=1 &convert=[2001:0db8::1428:57ab];\n g: bytes &length=1 &convert=True;\n h: bytes &length=1 &convert=\"MyString\";\n\n on %done { print self; }\n};\n\n@TEST-END-FILE\n\n\n@TEST-START-FILE conv.evt\n\ngrammar conv;\n\nprotocol analyzer Conv over TCP:\n parse originator with Conv::Test,\n port 22\/tcp;\n\non Conv::Test -> event conv::test($conn,\n $is_orig,\n self.a,\n self.b,\n self.c,\n self.d,\n self.e,\n self.f,\n self.g,\n self.h\n );\n\n@TEST-END-FILE\n\n\nevent conv::test(x: connection,\n is_orig: bool,\n a: string,\n b: int,\n c: count,\n d: double,\n e: addr,\n f: addr,\n g: bool,\n h: string\n )\n\t{\n\tprint x$id;\n\tprint is_orig;\n\tprint a;\n\tprint b;\n\tprint c;\n\tprint d;\n\tprint e;\n\tprint f;\n\tprint g;\n\tprint h;\n\t}\n\n","old_contents":"#\n# @TEST-EXEC: bro -r ${TRACES}\/ssh-single-conn.trace .\/conv.evt %INPUT >output\n# @TEST-EXEC: btest-diff output\n#\n\n@TEST-START-FILE conv.pac2\n\nmodule Conv;\n\nexport type Test = unit {\n a: bytes &length=5;\n b: int<16>;\n c: uint<16>;\n d: bytes &length=1 &convert=3.14;\n e: bytes &length=1 &convert=1.2.3.4;\n f: bytes &length=1 &convert=[2001:0db8::1428:57ab];\n g: bytes &length=1 &convert=True;\n h: bytes &length=1 &convert=\"MyString\";\n\n on %done { print self; }\n};\n\n@TEST-END-FILE\n\n\n@TEST-START-FILE conv.evt\n\ngrammar conv;\n\nanalyzer Conv over TCP:\n parse originator with Conv::Test,\n port 22\/tcp;\n\non Conv::Test -> event conv::test($conn,\n $is_orig,\n self.a,\n self.b,\n self.c,\n self.d,\n self.e,\n self.f,\n self.g,\n self.h\n );\n\n@TEST-END-FILE\n\n\nevent conv::test(x: connection,\n is_orig: bool,\n a: string,\n b: int,\n c: count,\n d: double,\n e: addr,\n f: addr,\n g: bool,\n h: string\n )\n\t{\n\tprint x$id;\n\tprint is_orig;\n\tprint a;\n\tprint b;\n\tprint c;\n\tprint d;\n\tprint e;\n\tprint f;\n\tprint g;\n\tprint h;\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"feba16978408ecf9ee847cda0723b10cddf33c85","subject":"add in ipblocker_types shortcut for blocking addresses","message":"add in ipblocker_types shortcut for blocking addresses\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ipblocker.bro","new_file":"ipblocker.bro","new_contents":"module Notice;\n\nexport {\n redef enum Action += {\n ## Indicates that the notice should be sent to ipblocker to block\n ACTION_IPBLOCKER\n };\n const ipblocker_types: set[Notice::Type] = {} &redef;\n ## Add a helper to the notice policy for blocking addresses\n redef Notice::policy += {\n [$pred(n: Notice::Info) = { return (n$note in Notice::ipblocker_types); },\n $action = ACTION_IPBLOCKER,\n $priority = 10],\n };\n}\n\nevent notice(n: Notice::Info) &priority=-5\n{\n if (ACTION_IPBLOCKER !in n$actions)\n return;\n local id = n$id;\n \n # The IP to block is whichever one is not the local address.\n if(Site::is_local_addr(id$orig_h))\n local ip = id$resp_h;\n else\n local ip = id$orig_h;\n\n local cmd = fmt(\"\/usr\/local\/bin\/bro_ipblocker_block %s\", ip);\n execute_with_notice(cmd, n);\n}\n","old_contents":"module Notice;\n\nexport {\n redef enum Action += {\n ## Indicates that the notice should be sent to ipblocker to block\n ACTION_IPBLOCKER\n };\n}\n\nevent notice(n: Notice::Info) &priority=-5\n{\n if (ACTION_IPBLOCKER !in n$actions)\n return;\n local id = n$id;\n \n # The IP to block is whichever one is not the local address.\n if(Site::is_local_addr(id$orig_h))\n local ip = id$resp_h;\n else\n local ip = id$orig_h;\n\n local cmd = fmt(\"\/usr\/local\/bin\/bro_ipblocker_block %s\", ip);\n execute_with_notice(cmd, n);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"a4bc1894bbbadae8337990e6261df028e4d3ded0","subject":"Small changes to ssn-exposure. - Added redef to a number of options. - Changed some regexes to fully support SSNs in double byte strings. - Added an option for choosing to count 9 digit strings as SSNs.","message":"Small changes to ssn-exposure.\n - Added redef to a number of options.\n - Changed some regexes to fully support SSNs in double byte strings.\n - Added an option for choosing to count 9 digit strings as SSNs.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssn-exposure.bro","new_file":"ssn-exposure.bro","new_contents":"\n@load notice\n\nmodule SSN;\n\nexport {\n\t# You must redef this variable with a normalized list of SSNs.\n\t# If you would like or require trivial obfuscation, you can set \n\t# the use_md5_hashed_ssns variable to T and put md5 hashed SSNs\n\t# into the list.\n\t# Example for redefining this variable... (huge sets are handled easily)\n\t# redef SSN::SSN_list = {\"264439985\", \"351669087\"};\n\tconst SSN_list: set[string] &redef;\n\n\t# As commented above, set this to T if you are using hashed SSNs in your \n\t# SSN_list variable.\n\tconst use_md5_hashed_ssns = F &redef;\n\t\n\t# If you think that there could be SSNs passed around without separators\n\t# (just 9 digit integers), then set this to T. \n\tconst check_with_no_separator = F &redef;\n\n\tconst ssn_log = open_log_file(\"ssn-exposure\") &raw_output &redef;\n\n\tredef enum Notice += {\n\t SSN_Exposure,\n\t SSN_MassExposure,\n\t};\n\n\t# The threshold of SSNs that you want to qualify as a mass disclosure.\n\t# This allows you to only alarm on more significant disclosures \n\t# (instead of people sending their own SSN).\n\t# NOT CURRENTLY WORKING!\n\tconst mass_exposure_num = 5 &redef;\n\n\t# Put the following line in your local config before @load-ing this script\n\t# if you'd like to use the signature based technique.\n\t#const use_ssn_sigs = T;\n}\n\n# This variable is for tracking the valid SSNs detected per-connection.\n# This should catch SSN leakage over email.\nglobal ssn_conn_tracker: table[conn_id] of set[string] &create_expire=5mins &default=function(id:conn_id):string_set { return set(); };\n\n# This variable tracks the valid SSNs detected per-service.\n# The idea is that this would catch SSN leakage through an SQL injection attack.\nglobal ssn_serv_tracker: table[addr, port] of set[string] &create_expire=5mins &default=function(a:addr, p:port):string_set { return set(); };\n\n@ifdef (use_ssn_sigs)\n@load signatures\nredef signature_files += \"ssn.sig\";\nredef signature_actions += { [\"ssn-match\"] = SIG_IGNORE };\n@else \n# Conn is needed because of a small dependency between smtp.bro and conn.bro\n@load conn\n@load smtp\n@load http-reply\n@endif\n\n#redef notice_action_filters += { [SSN::SSN_Exposure] = ignore_notice };\n\nconst ssn_regex = \/[^0-9\\\/]\\0?[0-6](\\0?[0-9]){2}\\0?[ \\-]?(\\0?[0-9]){2}\\0?[ \\-]?(\\0?[0-9]){4}(\\0?[[:blank:]\\r\\n<\\\"\\'])\/;\n\n# This function is used for validating and notifying about SSNs in a string.\nfunction check_ssns(c: connection, data: string): bool\n\t{\n\tlocal ssnps = find_all(data, ssn_regex);\n\t\n\tfor ( ssnp in ssnps )\n\t\t{\n\t\t# Make sure the number has either 2 hyphens, 2 spaces, or no separators.\n\t\tif ( \/[\\x000-9]{3}\\x00?-[\\x000-9]{2}\\x00?-[\\x000-9]{4}\/ in ssnp ||\n\t\t \/[\\x000-9]{3}\\x00?[[:blank:]][\\x000-9]{2}\\x00?[[:blank:]][\\x000-9]{4}\/ in ssnp ||\n\t\t (check_with_no_separator && \/[\\x000-9]{9}\/ in ssnp) )\n\t\t\t{\n\t\t\t# Remove all non-numerics\n\t\t\tlocal clean_ssnp = gsub(ssnp, \/[^0-9]\/, \"\");\n\t\t\t# Strip off any leading chars\n\t\t\tlocal ssn = sub_bytes(clean_ssnp, byte_len(clean_ssnp)-8, 9);\n\t\t\t\n\t\t\t#print fmt(\"Checking on -%s-\", ssn);\n\t\t\tlocal hash_ssn: string;\n\t\t\tif ( use_md5_hashed_ssns )\n\t\t\t\thash_ssn = md5_hash(ssn);\n\t\t\telse\n\t\t\t\thash_ssn = ssn;\n\t\t\t\t\n\t\t\tif ( hash_ssn in SSN_list )\n\t\t\t\t{\n\t\t\t\tlocal id = c$id;\n\t\t\t\t#print fmt(\" %s - Found it! (%s)\", ssn, md5_hash(ssn));\n\t\t\t\tadd ssn_conn_tracker[id][ssn];\n\t\t\t\tif ( |ssn_conn_tracker[id]| >= mass_exposure_num )\n\t\t\t\t\t{\n\t\t\t\t\tNOTICE([$note=SSN_MassExposure,\n\t\t\t\t\t $conn=c,\n\t\t\t\t\t $msg=fmt(\"More than %i SSNs disclosed in one connection.\", mass_exposure_num)]);\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tNOTICE([$note=SSN_Exposure,\n\t\t\t\t\t $conn=c,\n\t\t\t\t\t $msg=fmt(\"Contents of disclosed ssn session: %s\", data),\n\t\t\t\t\t $sub=hash_ssn]);\n\t\t\t\t\t}\n\t\t\t\n\t\t\t\tprint ssn_log, cat_sep(\"\\t\", \"\\\\N\", network_time(),\n\t\t\t\t id$orig_h, fmt(\"%d\", id$orig_p), \n\t\t\t\t id$resp_h, fmt(\"%d\", id$resp_p), \n\t\t\t\t ssn, data);\n\t\t\t\treturn T;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn F;\n\t}\n\n# This is used if the mime event parsing technique is used.\n# This seems to be the better technique if HTTP and SMTP are where\n# the SSN leakage problems are in your environment (especially if you \n# are able to use DPD).\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\t# Only looking at outbound SMTP.\n\tif ( is_orig && is_local_addr(c$id$orig_h) && \n\t c$start_time > network_time()-10secs && ssn_regex in data )\n\t\tcheck_ssns(c, data);\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\t# We're looking for outbound POST data and outbound HTTP data contents.\n\tif ( ((is_local_addr(c$id$resp_h) && !is_orig) || (is_local_addr(c$id$orig_h) && is_orig)) &&\n\t c$start_time > network_time()-10secs && ssn_regex in data )\n\t\tcheck_ssns(c, data);\n\t}\n\t\n# This event is broken in Robin's branch currently\n#event mime_all_data(c: connection, length: count, data: string)\n#\t{\n#\t# Only check the regex for connections younger than 10 seconds.\n#\t# This helps avoid load during large and\/or long connections.\n#\tif ( c$start_time > network_time()-10secs && ssn_regex in data )\n#\t\tcheck_ssns(c, data);\n#\t}\n\n# This is used if the signature based technique is in use\nfunction validate_ssn_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way. Should return F if this is\n\t# an http\/smtp session and handle the relevant *_data events.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_ssns(state$conn, data);\n\t}","old_contents":"\n@load notice\n\nmodule SSN;\n\nexport {\n\t# You must redef this variable with a normalized list of SSNs.\n\t# If you would like or require trivial obfuscation, you can set \n\t# the use_md5_hashed_ssns variable to T and put md5 hashed SSNs\n\t# into the list.\n\t# Example for redefining this variable... (huge sets are handled easily)\n\t# redef SSN::SSN_list = {\"264439985\", \"351669087\"};\n\tconst SSN_list: set[string] &redef;\n\n\t# As commented above, set this to T if you are using hashed SSNs in your \n\t# SSN_list variable.\n\tconst use_md5_hashed_ssns = F;\n\n\tconst ssn_log = open_log_file(\"ssn-exposure\") &raw_output &redef;\n\n\tredef enum Notice += {\n\t SSN_Exposure,\n\t SSN_MassExposure,\n\t};\n\n\t# The threshold of SSNs that you want to qualify as a mass disclosure.\n\t# This allows you to only alarm on more significant disclosures \n\t# (instead of people sending their own SSN).\n\t# NOT CURRENTLY WORKING!\n\tconst mass_exposure_num = 5;\n\n\t# Uncomment the following line if you'd like to use the signature based \n\t# technique in this script.\n\t#const use_ssn_sigs = T;\n}\n\n# This variable is for tracking the valid SSNs detected per-connection.\n# This should catch SSN leakage over email.\nglobal ssn_conn_tracker: table[conn_id] of set[string] &create_expire=5mins &default=function(id:conn_id):string_set { return set(); };\n\n# This variable tracks the valid SSNs detected per-service.\n# The idea is that this would catch SSN leakage through an SQL injection attack.\nglobal ssn_serv_tracker: table[addr, port] of set[string] &create_expire=5mins &default=function(a:addr, p:port):string_set { return set(); };\n\n@ifdef (use_ssn_sigs)\n@load signatures\nredef signature_files += \"ssn.sig\";\nredef signature_actions += { [\"ssn-match\"] = SIG_IGNORE };\n@else \n# Conn is needed because of a small dependency between smtp.bro and conn.bro\n@load conn\n@load smtp\n@load http-reply\n@endif\n\n#redef notice_action_filters += { [SSN::SSN_Exposure] = ignore_notice };\n\nconst ssn_regex = \/[^0-9\\\/]\\0?[0-6](\\0?[0-9]){2}\\0?[ \\-]?(\\0?[0-9]){2}\\0?[ \\-]?(\\0?[0-9]){4}(\\0?[[:blank:]\\r\\n<\\\"\\'])\/;\n\n# This function is used for validating and notifying about SSNs in a string.\nfunction check_ssns(c: connection, data: string): bool\n\t{\n\tlocal ssnps = find_all(data, ssn_regex);\n\t\n\tfor ( ssnp in ssnps )\n\t\t{\n\t\t# Make sure the number has either 2 hyphens, 2 spaces, or no separators.\n\t\tif ( \/[0-9]{3}-[0-9]{2}-[0-9]{4}\/ in ssnp ||\n\t\t \/[0-9]{3} [0-9]{2} [0-9]{4}\/ in ssnp ||\n\t\t \/[0-9]{9}\/ in ssnp )\n\t\t\t{\n\t\t\t# Remove all non-numerics\n\t\t\tlocal clean_ssnp = gsub(ssnp, \/[^0-9]\/, \"\");\n\t\t\t# Strip off any leading chars\n\t\t\tlocal ssn = sub_bytes(clean_ssnp, byte_len(clean_ssnp)-8, 9);\n\t\t\t\n\t\t\t#print fmt(\"Checking on -%s-\", ssn);\n\t\t\tlocal hash_ssn: string;\n\t\t\tif ( use_md5_hashed_ssns )\n\t\t\t\thash_ssn = md5_hash(ssn);\n\t\t\telse\n\t\t\t\thash_ssn = ssn;\n\t\t\t\t\n\t\t\tif ( hash_ssn in SSN_list )\n\t\t\t\t{\n\t\t\t\tlocal id = c$id;\n\t\t\t\t#print fmt(\" %s - Found it! (%s)\", ssn, md5_hash(ssn));\n\t\t\t\tadd ssn_conn_tracker[id][ssn];\n\t\t\t\tif ( |ssn_conn_tracker[id]| >= mass_exposure_num )\n\t\t\t\t\t{\n\t\t\t\t\tNOTICE([$note=SSN_MassExposure,\n\t\t\t\t\t $conn=c,\n\t\t\t\t\t $msg=fmt(\"More than %i SSNs disclosed in one connection.\", mass_exposure_num)]);\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tNOTICE([$note=SSN_Exposure,\n\t\t\t\t\t $conn=c,\n\t\t\t\t\t $msg=fmt(\"Contents of disclosed ssn session: %s\", data),\n\t\t\t\t\t $sub=hash_ssn]);\n\t\t\t\t\t}\n\t\t\t\n\t\t\t\tprint ssn_log, cat_sep(\"\\t\", \"\\\\N\", network_time(),\n\t\t\t\t id$orig_h, fmt(\"%d\", id$orig_p), \n\t\t\t\t id$resp_h, fmt(\"%d\", id$resp_p), \n\t\t\t\t ssn, data);\n\t\t\t\treturn T;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn F;\n\t}\n\n# This is used if the mime event parsing technique is used.\n# This seems to be the better technique if HTTP and SMTP are where\n# the SSN leakage problems are in your environment (especially if you \n# are able to use DPD).\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\t# Only looking at outbound SMTP.\n\tif ( is_orig && is_local_addr(c$id$orig_h) && \n\t c$start_time > network_time()-10secs && ssn_regex in data )\n\t\tcheck_ssns(c, data);\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\t# We're looking for outbound POST data and outbound HTTP data contents.\n\tif ( ((is_local_addr(c$id$resp_h) && !is_orig) || (is_local_addr(c$id$orig_h) && is_orig)) &&\n\t c$start_time > network_time()-10secs && ssn_regex in data )\n\t\tcheck_ssns(c, data);\n\t}\n\t\n# This event is broken in Robin's branch currently\n#event mime_all_data(c: connection, length: count, data: string)\n#\t{\n#\t# Only check the regex for connections younger than 10 seconds.\n#\t# This helps avoid load during large and\/or long connections.\n#\tif ( c$start_time > network_time()-10secs && ssn_regex in data )\n#\t\tcheck_ssns(c, data);\n#\t}\n\n# This is used if the signature based technique is in use\nfunction validate_ssn_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way. Should return F if this is\n\t# an http\/smtp session and handle the relevant *_data events.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_ssns(state$conn, data);\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"6d2b8f97cedc05d78dc64baa16ec13ae0786c7d3","subject":"README for using Bro on top of pf_ring","message":"README for using Bro on top of pf_ring\n","repos":"opencTM\/PF_RING,ntop\/PF_RING,opencTM\/PF_RING,ntop\/PF_RING,opencTM\/PF_RING,ntop\/PF_RING,opencTM\/PF_RING,ntop\/PF_RING,ntop\/PF_RING,ntop\/PF_RING,ntop\/PF_RING","old_file":"doc\/README.bro","new_file":"doc\/README.bro","new_contents":"Using PF_RING with Bro\n----------------------\n\nIn order to use Bro on top of pf_ring support please follow this guide.\n\n1. Install the \"pfring\" package (and optionally \"pfring-drivers-zc-dkms\"\nif you want to use ZC drivers) from http:\/\/packages.ntop.org as explained\nin README.apt_rpm_packages\n\n2. Download Bro from https:\/\/www.bro.org\/download\/\n\nwget https:\/\/www.bro.org\/downloads\/release\/bro-X.X.X.tar.gz\ntar xvzf bro-*.tar.gz\n\n3. Configure and install Bro\n\n.\/configure --with-pcap=\/usr\/local\/lib\nmake\nmake install\n\n4. Make sure Bro is correctly linked to pf_ring-aware libpcap:\n\nldd \/usr\/local\/bro\/bin\/bro | grep pcap\n libpcap.so.1 => \/usr\/local\/lib\/libpcap.so.1 (0x00007fa371e33000)\n\n\n5. Configure the node configuration file (node.cfg) with:\n lb_method=pf_ring \n lb_procs=\n pin_cpus=\n\nExample:\n\n[worker-1]\ntype=worker\nhost=10.10.10.1\ninterface=eth1\nlb_method=pf_ring\nlb_procs=8\npin_cpus=0,1,2,3,4,5,6,7\n\nIf you installed the ZC drivers, you can configure the number of RSS queues,\nas explained in README.apt_rpm_packages (or running \"ethtool -L eth1 combined \"),\nto the same number of processes in lb_procs, and use zc:ethX as interface name.\n\nExample:\n\t\t\n[worker-1]\ntype=worker\nhost=10.10.10.1\ninterface=zc:eth1\nlb_method=pf_ring\nlb_procs=8\npin_cpus=0,1,2,3,4,5,6,7\n\t\t\nAnother option for distributing the load using ZC is using zero-copy software \ndistribution with zbalance_ipc. This configuration requires RSS set to single \nqueue.\nRun zbalance_ipc *before* running bro with:\nzbalance_ipc -i zc:eth1 -c 99 -n 8 -m 1 -g 8\nWhere:\n-c 99 is the cluster ID\n-n 8 is the number of queues\n-g 9 is core affinity for zbalance_ipc\nYou should use as interface name zc: as in the example below.\n\nExample:\n\n[worker-1]\ntype=worker\nhost=10.10.10.1\ninterface=zc:99\nlb_method=pf_ring\nlb_procs=8\npin_cpus=0,1,2,3,4,5,6,7\n\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'doc\/README.bro' did not match any file(s) known to git\n","license":"lgpl-2.1","lang":"Bro"} {"commit":"074287d256d52f991615563c9cca49b073115f31","subject":"Tabbed headers works again.","message":"Tabbed headers works again.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"logging-ext.bro","new_file":"logging-ext.bro","new_contents":"module LOG;\n\nexport {\n\t# The record type to store logging information.\n\ttype log_info: record {\n\t\tdh: Directions_and_Hosts &default=All;\n\t\tsplit: bool &default=F;\n\t\traw_output: bool &default=F;\n\t\theader: string &default=\"\";\n\t\tcombined_log: file &optional;\n\t\tsplit1_log: file &optional;\n\t\tsplit2_log: file &optional;\n\t};\n\t\n\t# Where the data for knowing how to log is stored.\n\tconst logs: table[string] of log_info &redef;\n\n\t# Utility functions\n\tglobal get_file_by_addr: function(a: string, ip: addr, force_log: bool): file;\n\tglobal get_file_by_id: function(a: string, id: conn_id, force_log: bool): file;\n\tglobal open_log_files: function(a: string);\n\tglobal create_logs: function(a: string, d: Directions_and_Hosts, split: bool, raw: bool);\n\tglobal define_header: function(a: string, h: string);\n\tglobal buffer: function(a: string, value: bool);\n\t\n\t# This is dumb, but it helps avoid needing to duplicate code on the\n\t# printing side.\n\tconst null_file: file = open_log_file(\"null\");\n}\n\nfunction get_file_by_addr(a: string, ip: addr, force_log: bool): file\n\t{\n\tlocal i = logs[a];\n\tif ( !force_log && !addr_matches_hosts(ip, i$dh) )\n\t\treturn LOG::null_file;\n\n\tif ( i$split )\n\t\t{\n\t\tif ( is_local_addr(ip) )\n\t\t\treturn i$split1_log;\n\t\telse\n\t\t\treturn i$split2_log;\n\t\t}\n\telse\n\t\t{\n\t\treturn i$combined_log;\n\t\t}\n\t}\n\t\nfunction get_file_by_id(a: string, id: conn_id, force_log: bool): file\n\t{\n\tlocal i = logs[a];\n\tif ( !force_log && !id_matches_directions(id, i$dh) )\n\t\treturn LOG::null_file;\n\n\tif ( i$split )\n\t\t{\n\t\tif ( is_local_addr(id$resp_h) )\n\t\t\treturn i$split1_log;\n\t\telse\n\t\t\treturn i$split2_log;\n\t\t}\n\telse\n\t\t{\n\t\treturn i$combined_log;\n\t\t}\n\t}\n\n\nfunction buffer(a: string, value: bool)\n\t{\n\tlocal i = logs[a];\n\t\n\tif ( i$split )\n\t\t{\n\t\tset_buf(i$split1_log, value);\n\t\tset_buf(i$split2_log, value);\n\t\t}\n\telse\n\t\t{\n\t\tset_buf(i$combined_log, value);\n\t\t}\n\t}\n\nfunction open_log_files(a: string)\n\t{\n\tlocal i = logs[a];\n\t\n\tif ( i$split )\n\t\t{\n\t\t# Find if this log is determined by HOSTS or DIRECTIONS\n\t\tif ( i$dh in DIRECTIONS ) \n\t\t\t{\n\t\t\ti$split1_log = open_log_file(cat(a,\"-inbound\"));\n\t\t\ti$split2_log = open_log_file(cat(a,\"-outbound\"));\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ti$split1_log = open_log_file(cat(a,\"-localhosts\"));\n\t\t\ti$split2_log = open_log_file(cat(a,\"-remotehosts\"));\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\ti$combined_log = open_log_file(a);\n\t\t}\n\t}\n\nfunction create_logs(a: string, d: Directions_and_Hosts, split: bool, raw: bool)\n\t{\n\tlogs[a] = [$dh=d, $split=split, $raw_output=raw];\n\t}\n\t\nfunction define_header(a: string, h: string)\n\t{\n\tlocal i = logs[a];\n\ti$header = h;\n\t}\n\t\nevent file_opened(f: file) &priority=10\n\t{\n\tlocal filename = get_file_name(f);\n\t# TODO: make this not depend on the file extension being .log\n\tlocal log_type = gsub(filename, \/(-(((in|out)bound)|(local|remote)hosts))?\\.log$\/, \"\");\n\tif ( log_type in logs )\n\t\t{\n\t\tlocal i = logs[log_type];\n\t\tif ( i$raw_output )\n\t\t\tenable_raw_output(f);\n\t\tif ( !is_remote_event() && i$header != \"\" )\n\t\t\tprint f, i$header;\n\t\t}\n\telse\n\t\t{\n\t\t# TODO: This needs to be handled.\n\t\t}\n\t}\n\n# This is a hack. The null file is used as \/dev\/null by all\n# scripts using the logging framework. The file needs to be\n# closed so that nothing is ever written to it.\n# TODO: change this when a better method for not printing\n# is created.\nevent bro_init()\n\t{\n\tclose(null_file);\n\t}\n\n# Open the appropriate log files.\nevent bro_init() &priority=-10\n\t{\n\tfor ( lt in logs )\n\t\topen_log_files(lt);\n\t}\n","old_contents":"module LOG;\n\nexport {\n\t# The record type to store logging information.\n\ttype log_info: record {\n\t\tdh: Directions_and_Hosts &default=All;\n\t\tsplit: bool &default=F;\n\t\traw_output: bool &default=F;\n\t\theader: string &default=\"\";\n\t\tcombined_log: file &optional;\n\t\tsplit1_log: file &optional;\n\t\tsplit2_log: file &optional;\n\t};\n\t\n\t# Where the data for knowing how to log is stored.\n\tconst logs: table[string] of log_info &redef;\n\n\t# Utility functions\n\tglobal get_file_by_addr: function(a: string, ip: addr, force_log: bool): file;\n\tglobal get_file_by_id: function(a: string, id: conn_id, force_log: bool): file;\n\tglobal open_log_files: function(a: string);\n\tglobal create_logs: function(a: string, d: Directions_and_Hosts, split: bool, raw: bool);\n\tglobal define_header: function(a: string, h: string);\n\tglobal buffer: function(a: string, value: bool);\n\t\n\t# This is dumb, but it helps avoid needing to duplicate code on the\n\t# printing side.\n\tconst null_file: file = open_log_file(\"null\");\n}\n\nfunction get_file_by_addr(a: string, ip: addr, force_log: bool): file\n\t{\n\tlocal i = logs[a];\n\tif ( !force_log && !addr_matches_hosts(ip, i$dh) )\n\t\treturn LOG::null_file;\n\n\tif ( i$split )\n\t\t{\n\t\tif ( is_local_addr(ip) )\n\t\t\treturn i$split1_log;\n\t\telse\n\t\t\treturn i$split2_log;\n\t\t}\n\telse\n\t\t{\n\t\treturn i$combined_log;\n\t\t}\n\t}\n\t\nfunction get_file_by_id(a: string, id: conn_id, force_log: bool): file\n\t{\n\tlocal i = logs[a];\n\tif ( !force_log && !id_matches_directions(id, i$dh) )\n\t\treturn LOG::null_file;\n\n\tif ( i$split )\n\t\t{\n\t\tif ( is_local_addr(id$resp_h) )\n\t\t\treturn i$split1_log;\n\t\telse\n\t\t\treturn i$split2_log;\n\t\t}\n\telse\n\t\t{\n\t\treturn i$combined_log;\n\t\t}\n\t}\n\n\nfunction buffer(a: string, value: bool)\n\t{\n\tlocal i = logs[a];\n\t\n\tif ( i$split )\n\t\t{\n\t\tset_buf(i$split1_log, value);\n\t\tset_buf(i$split2_log, value);\n\t\t}\n\telse\n\t\t{\n\t\tset_buf(i$combined_log, value);\n\t\t}\n\t}\n\nfunction open_log_files(a: string)\n\t{\n\tlocal i = logs[a];\n\t\n\tif ( i$split )\n\t\t{\n\t\t# Find if this log is determined by HOSTS or DIRECTIONS\n\t\tif ( i$dh in DIRECTIONS ) \n\t\t\t{\n\t\t\ti$split1_log = open_log_file(cat(a,\"-inbound\"));\n\t\t\ti$split2_log = open_log_file(cat(a,\"-outbound\"));\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ti$split1_log = open_log_file(cat(a,\"-localhosts\"));\n\t\t\ti$split2_log = open_log_file(cat(a,\"-remotehosts\"));\n\t\t\t}\n\t\tif ( i$raw_output )\n\t\t\t{\n\t\t\tenable_raw_output(i$split1_log);\n\t\t\tenable_raw_output(i$split2_log);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\ti$combined_log = open_log_file(a);\n\t\tif ( i$raw_output )\n\t\t\t{\n\t\t\tenable_raw_output(i$combined_log);\n\t\t\t}\n\t\t}\n\t}\n\nfunction create_logs(a: string, d: Directions_and_Hosts, split: bool, raw: bool)\n\t{\n\tlogs[a] = [$dh=d, $split=split, $raw_output=raw];\n\t}\n\t\nfunction define_header(a: string, h: string)\n\t{\n\tlocal i = logs[a];\n\ti$header = h;\n\t}\n\t\nevent file_opened(f: file) &priority=10\n\t{\n\tlocal filename = get_file_name(f);\n\t# TODO: make this not depend on the file extension being .log\n\tlocal log_type = gsub(filename, \/(-(((in|out)bound)|(local|remote)hosts))?\\.log$\/, \"\");\n\tif ( log_type in logs )\n\t\t{\n\t\tlocal i = logs[log_type];\n\t\tif ( !is_remote_event() && i$header != \"\" )\n\t\t\tprint f, i$header;\n\t\t}\n\telse\n\t\t{\n\t\t# TODO: This needs to be handled.\n\t\t}\n\t}\n\n# This is a hack. The null file is used as \/dev\/null by all\n# scripts using the logging framework. The file needs to be\n# closed so that nothing is ever written to it.\n# TODO: change this when a better method for not printing\n# is created.\nevent bro_init()\n\t{\n\tclose(null_file);\n\t}\n\n# Open the appropriate log files.\nevent bro_init() &priority=-10\n\t{\n\tfor ( lt in logs )\n\t\topen_log_files(lt);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"2c249a60dfff315278f6fe941e7682d98f4467df","subject":"Update detect-rfd.bro","message":"Update detect-rfd.bro\n\nUpdated pattern to be more lenient","repos":"theflakes\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,CrowdStrike\/cs-bro,albertzaharovits\/cs-bro","old_file":"bro-scripts\/rfd\/detect-rfd.bro","new_file":"bro-scripts\/rfd\/detect-rfd.bro","new_contents":"# Detect reflected file download attacks as described in \n# http:\/\/packetstorm.foofus.com\/papers\/presentations\/eu-14-Hafif-Reflected-File-Download-A-New-Web-Attack-Vector.pdf\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Reflected_File_Download\n };\n\n redef enum HTTP::Tags += {\n RFD\n };\n}\n\nconst rfd_content_type: set[string] = {\n \"application\/json\",\n \"application\/x-javascript\",\n \"application\/javascript\",\n \"application\/notexist\",\n \"text\/json\",\n \"text\/x-javascript\",\n \"text\/plain\",\n \"text\/notexist\",\n \"application\/xml\",\n \"text\/xml\",\n \"text\/html\"\n} &redef;\n\nconst rfd_pattern = \/\\\"\\|\\|\/ |\n \/\\\"\\<\\<\/ |\n \/\\\"\\>\\>\/ |\n \/[^?]*\\.bat(\\;|$)\/ |\n \/[^?]*\\.cmd(\\;|$)\/ |\n \/[:alnum:]*?[Ss][Ee][Tt][Uu][Pp][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/[:alnum:]*?[Ii][nn][Ss][Tt][Aa][Ll][Ll][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/[:alnum:]*?[Uu][Pp][Dd][Aa][Tt][Ee][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/[:alnum:]*?[Uu][Nn][In][Ss][Tt][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ &redef;\n\n\n# Perform a pattern match for reflected file downloads.\n# If found, add HTTP tag and generate a notice.\nfunction rfd_do_notice(c: connection)\n{\nif ( rfd_pattern in c$http$uri )\n {\n add c$http$tags[RFD];\n NOTICE([$note=Reflected_File_Download,\n $msg=\"A reflected file download was attempted\",\n $sub=c$http$uri,\n $id=c$id,\n $identifier=cat(c$id$orig_h,c$id$resp_h,c$http$uri)]);\n }\n}\n\n# Check for reflected file downloads in HTTP transactions that have a \n# CONTENT-TYPE header. Valid RFD content types are identified anywhere\n# in the CONTENT-TYPE header value.\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nif ( name == \"CONTENT-TYPE\" )\n for ( rct in rfd_content_type )\n if ( rct in value )\n rfd_do_notice(c);\n}\n\n# Check for reflected file downloads in HTTP transactions that do not have a \n# CONTENT-TYPE header.\nevent http_all_headers(c: connection, is_orig: bool, hlist: mime_header_list)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nlocal headers: set[string];\n\nfor ( h in hlist )\n {\n local name = hlist[h]$name;\n add headers[name];\n }\n\nif ( \"CONTENT-TYPE\" !in headers ) \n rfd_do_notice(c);\nelse return;\n}\n","old_contents":"# Detect reflected file download attacks as described in \n# http:\/\/packetstorm.foofus.com\/papers\/presentations\/eu-14-Hafif-Reflected-File-Download-A-New-Web-Attack-Vector.pdf\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Reflected_File_Download\n };\n\n redef enum HTTP::Tags += {\n RFD\n };\n}\n\nconst rfd_content_type: set[string] = {\n \"application\/json\",\n \"application\/x-javascript\",\n \"application\/javascript\",\n \"application\/notexist\",\n \"text\/json\",\n \"text\/x-javascript\",\n \"text\/plain\",\n \"text\/notexist\",\n \"application\/xml\",\n \"text\/xml\",\n \"text\/html\"\n} &redef;\n\nconst rfd_pattern = \/\\\"\\|\\|\/ |\n \/\\\"\\<\\<\/ |\n \/\\\"\\>\\>\/ |\n \/\\;\\\/[^?]*\\.bat(\\;|$)\/ |\n \/\\;\\\/[^?]*\\.cmd(\\;|$)\/ |\n \/\\;\\\/[:alnum:]*?[Ss][Ee][Tt][Uu][Pp][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/\\;\\\/[:alnum:]*?[Ii][nn][Ss][Tt][Aa][Ll][Ll][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/\\;\\\/[:alnum:]*?[Uu][Pp][Dd][Aa][Tt][Ee][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/\\;\\\/[:alnum:]*?[Uu][Nn][In][Ss][Tt][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ &redef;\n\n\n# Perform a pattern match for reflected file downloads.\n# If found, add HTTP tag and generate a notice.\nfunction rfd_do_notice(c: connection)\n{\nif ( rfd_pattern in c$http$uri )\n {\n add c$http$tags[RFD];\n NOTICE([$note=Reflected_File_Download,\n $msg=\"A reflected file download was attempted\",\n $sub=c$http$uri,\n $id=c$id,\n $identifier=cat(c$id$orig_h,c$id$resp_h,c$http$uri)]);\n }\n}\n\n# Check for reflected file downloads in HTTP transactions that have a \n# CONTENT-TYPE header. Valid RFD content types are identified anywhere\n# in the CONTENT-TYPE header value.\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nif ( name == \"CONTENT-TYPE\" )\n for ( rct in rfd_content_type )\n if ( rct in value )\n rfd_do_notice(c);\n}\n\n# Check for reflected file downloads in HTTP transactions that do not have a \n# CONTENT-TYPE header.\nevent http_all_headers(c: connection, is_orig: bool, hlist: mime_header_list)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nlocal headers: set[string];\n\nfor ( h in hlist )\n {\n local name = hlist[h]$name;\n add headers[name];\n }\n\nif ( \"CONTENT-TYPE\" !in headers ) \n rfd_do_notice(c);\nelse return;\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"d7791988bc30f3f60fc74fbefb9f02a5173e9be2","subject":"Re-add util loading","message":"Re-add util loading\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_master.bro","new_file":"scripts_master\/bro_master.bro","new_contents":"@load .\/beemaster_events\n@load .\/beemaster_log\n@load .\/beemaster_util\n@load .\/log\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\n # Subscribe to acu alerts\n Broker::subscribe_to_events_multi(\"beemaster\/acu\/alert\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioAccessInfo = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_ACCESS_LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioDownloadCompleteInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_COMPLETE_LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioDownloadOfferInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_OFFER_LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioFtpInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_FTP_LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioMysqlCommandInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_MYSQL_COMMAND_LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioLoginInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_LOGIN_LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioSmbBindInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_SMB_BIND_LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioSmbRequestInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_SMB_REQUEST_LOG, rec);\n}\n\nevent Beemaster::dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioBlackholeInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_BLACKHOLE_LOG, rec);\n}\n\nevent Beemaster::portscan_meta_alert(timestamp: time, attack: string, ips: vector of string) {\n local rec: Beemaster::PortscanAlertInfo = [$ts=timestamp, $attack=attack, $ips=ips];\n Log::write(Beemaster::PORTSCAN_ALERT_LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n Beemaster::log(msg);\n # Add new client to balance\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n Beemaster::log(msg);\n # Remove disconnected client from balance\n remove_from_balance(peer_name);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n Beemaster::log(msg);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: Beemaster::BalanceInfo = [$connector=connector, $slave=slave];\n Log::write(Beemaster::BALANCE_LOG, rec);\n}\n","old_contents":"@load .\/beemaster_events\n@load .\/beemaster_log\n@load .\/beemaster_logwriter\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\n # Subscribe to acu alerts\n Broker::subscribe_to_events_multi(\"beemaster\/acu\/alert\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioAccessInfo = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_ACCESS_LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioDownloadCompleteInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_COMPLETE_LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioDownloadOfferInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_OFFER_LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioFtpInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_FTP_LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioMysqlCommandInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_MYSQL_COMMAND_LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioLoginInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_LOGIN_LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioSmbBindInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_SMB_BIND_LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioSmbRequestInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_SMB_REQUEST_LOG, rec);\n}\n\nevent Beemaster::dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioBlackholeInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_BLACKHOLE_LOG, rec);\n}\n\nevent Beemaster::portscan_meta_alert(timestamp: time, attack: string, ips: vector of string) {\n local rec: Beemaster::PortscanAlertInfo = [$ts=timestamp, $attack=attack, $ips=ips];\n Log::write(Beemaster::PORTSCAN_ALERT_LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n Beemaster::log(msg);\n # Add new client to balance\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n Beemaster::log(msg);\n # Remove disconnected client from balance\n remove_from_balance(peer_name);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n Beemaster::log(msg);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: Beemaster::BalanceInfo = [$connector=connector, $slave=slave];\n Log::write(Beemaster::BALANCE_LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"cd4079d2baf6aa422eb5ff19a49e3eded51e9b74","subject":"Create __load__.bro","message":"Create __load__.bro","repos":"jatkins-sfdc\/ja3,salesforce\/ja3","old_file":"bro\/__load__.bro","new_file":"bro\/__load__.bro","new_contents":"@load .\/ja3.bro\n@load .\/intel_ja3.bro\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro\/__load__.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"79e8e75beb17a21d62da2786339690cb29c7f77c","subject":"removed duplicate def. thx git merge","message":"removed duplicate def. thx git merge\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_master.bro","new_file":"scripts_master\/bro_master.bro","new_contents":"@load .\/beemaster_events\n@load .\/beemaster_log\n@load .\/beemaster_util\n\n@load .\/log\n\nredef exit_only_after_terminate = T;\n\n# Broker setup\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal log_balance: function(connector: string, slave: string);\nglobal mhr_lookup: function(hash: string) : string;\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\n # Subscribe to lattice events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/lattice\");\n\n # Subscribe to acu alerts\n Broker::subscribe_to_events_multi(\"beemaster\/acu\/alert\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count,\n remote_hostname: string, remote_ip: addr, remote_port: count, transport: string,\n protocol: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioAccessInfo = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_ACCESS_LOG, rec);\n}\n\nevent Beemaster::dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string,\n length: count, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioBlackholeInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_BLACKHOLE_LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, md5hash: string, filelocation: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n local detection_rate: string;\n local rec: Beemaster::DioDownloadCompleteInfo;\n local hash_domain = fmt(\"%s.malware.hash.cymru.com\", md5hash);\n\n when ( local MHR_result = lookup_hostname_txt(hash_domain) ) {\n # Data is returned as \" \"\n local MHR_answer = split_string1(MHR_result, \/ \/);\n if ( |MHR_answer| == 2 ) {\n Beemaster::log(\"MHR lookup returned \" + MHR_answer[0] + \" \" + MHR_answer[1]);\n detection_rate = MHR_answer[1];\n\n rec = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $detection_rate=detection_rate, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_COMPLETE_LOG, rec);\n }\n else {\n Beemaster::log(\"MHR lookup for \" + md5hash + \" did not return any results\");\n detection_rate = \"NO_DATA\";\n\n rec = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $detection_rate=detection_rate, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_COMPLETE_LOG, rec);\n }\n }\n timeout 1sec {\n Beemaster::log(\"ERROR: Unable to query \" + hash_domain + \" within 1s, timeout\");\n detection_rate = \"TIMEOUT\";\n\n rec = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $detection_rate=detection_rate, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_COMPLETE_LOG, rec);\n }\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string,\n origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioDownloadOfferInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_OFFER_LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n command: string, arguments: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioFtpInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_FTP_LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string,\n origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioMysqlCommandInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_MYSQL_COMMAND_LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n username: string, password: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioLoginInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_LOGIN_LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n transfersyntax: string, uuid: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioSmbBindInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_SMB_BIND_LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n opnum: count, uuid: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioSmbRequestInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_SMB_REQUEST_LOG, rec);\n}\n\nevent Beemaster::acu_meta_alert(timestamp: time, attack: string) {\n Beemaster::log(\"Got acu_meta_alert!\");\n local rec: Beemaster::AcuAlertInfo = [$ts=timestamp, $attack=attack];\n Log::write(Beemaster::ACU_ALERT_LOG, rec);\n}\n\nevent Beemaster::portscan_meta_alert(timestamp: time, attack: string, ips: vector of string) {\n local rec: Beemaster::PortscanAlertInfo = [$ts=timestamp, $attack=attack, $ips=ips];\n Log::write(Beemaster::PORTSCAN_ALERT_LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n Beemaster::log(msg);\n # Add new client to balance\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n Beemaster::log(msg);\n # Remove disconnected client from balance\n remove_from_balance(peer_name);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n Beemaster::log(msg);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: Beemaster::BalanceInfo = [$connector=connector, $slave=slave];\n Log::write(Beemaster::BALANCE_LOG, rec);\n}\n","old_contents":"@load .\/beemaster_events\n@load .\/beemaster_log\n@load .\/beemaster_util\n\n@load .\/log\n\nredef exit_only_after_terminate = T;\n\n# Broker setup\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal log_balance: function(connector: string, slave: string);\nglobal mhr_lookup: function(hash: string) : string;\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\nglobal log_balance: function(connector: string, slave: string);\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\n # Subscribe to lattice events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/lattice\");\n\n # Subscribe to acu alerts\n Broker::subscribe_to_events_multi(\"beemaster\/acu\/alert\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count,\n remote_hostname: string, remote_ip: addr, remote_port: count, transport: string,\n protocol: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioAccessInfo = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_ACCESS_LOG, rec);\n}\n\nevent Beemaster::dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string,\n length: count, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioBlackholeInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_BLACKHOLE_LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n url: string, md5hash: string, filelocation: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n local detection_rate: string;\n local rec: Beemaster::DioDownloadCompleteInfo;\n local hash_domain = fmt(\"%s.malware.hash.cymru.com\", md5hash);\n\n when ( local MHR_result = lookup_hostname_txt(hash_domain) ) {\n # Data is returned as \" \"\n local MHR_answer = split_string1(MHR_result, \/ \/);\n if ( |MHR_answer| == 2 ) {\n Beemaster::log(\"MHR lookup returned \" + MHR_answer[0] + \" \" + MHR_answer[1]);\n detection_rate = MHR_answer[1];\n\n rec = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $detection_rate=detection_rate, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_COMPLETE_LOG, rec);\n }\n else {\n Beemaster::log(\"MHR lookup for \" + md5hash + \" did not return any results\");\n detection_rate = \"NO_DATA\";\n\n rec = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $detection_rate=detection_rate, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_COMPLETE_LOG, rec);\n }\n }\n timeout 1sec {\n Beemaster::log(\"ERROR: Unable to query \" + hash_domain + \" within 1s, timeout\");\n detection_rate = \"TIMEOUT\";\n\n rec = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $detection_rate=detection_rate, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_COMPLETE_LOG, rec);\n }\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string,\n origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioDownloadOfferInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_DOWNLOAD_OFFER_LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n command: string, arguments: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioFtpInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_FTP_LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string,\n origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioMysqlCommandInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_MYSQL_COMMAND_LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n username: string, password: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioLoginInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_LOGIN_LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n transfersyntax: string, uuid: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioSmbBindInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_SMB_BIND_LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count,\n remote_ip: addr, remote_port: count, transport: string, protocol: string,\n opnum: count, uuid: string, origin: string, connector_id: string)\n{\n local lport: port = count_to_port(local_port, Beemaster::string_to_proto(transport));\n local rport: port = count_to_port(remote_port, Beemaster::string_to_proto(transport));\n\n local rec: Beemaster::DioSmbRequestInfo = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Beemaster::DIO_SMB_REQUEST_LOG, rec);\n}\n\nevent Beemaster::acu_meta_alert(timestamp: time, attack: string) {\n Beemaster::log(\"Got acu_meta_alert!\");\n local rec: Beemaster::AcuAlertInfo = [$ts=timestamp, $attack=attack];\n Log::write(Beemaster::ACU_ALERT_LOG, rec);\n}\n\nevent Beemaster::portscan_meta_alert(timestamp: time, attack: string, ips: vector of string) {\n local rec: Beemaster::PortscanAlertInfo = [$ts=timestamp, $attack=attack, $ips=ips];\n Log::write(Beemaster::PORTSCAN_ALERT_LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n Beemaster::log(msg);\n # Add new client to balance\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n Beemaster::log(msg);\n # Remove disconnected client from balance\n remove_from_balance(peer_name);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n Beemaster::log(msg);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: Beemaster::BalanceInfo = [$connector=connector, $slave=slave];\n Log::write(Beemaster::BALANCE_LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"90586a1aa29ecd98ff9115c18dd4ae575ad898aa","subject":"add missing header fields","message":"add missing header fields\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"logging.ssh-ext.bro","new_file":"logging.ssh-ext.bro","new_contents":"@load global-ext\n@load ssh-ext\n\nmodule SSH;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Which SSH logins to record.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssh-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"ssh-ext\", cat_sep(\"\\t\", \"\", \n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"status\", \"direction\",\n\t \"country\", \"region\",\n\t \"client\", \"server\", \"resp_size\"));\n\t\n\t}\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info)\n\t{\n\tlocal log = LOG::choose(\"ssh-ext\", id$resp_h);\n\n\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t si$start_time,\n\t id$orig_h, fmt(\"%d\", id$orig_p),\n\t id$resp_h, fmt(\"%d\", id$resp_p),\n\t si$status, si$direction, \n\t si$location$country_code, si$location$region,\n\t si$client, si$server,\n\t si$resp_size);\n\t}","old_contents":"@load global-ext\n@load ssh-ext\n\nmodule SSH;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Which SSH logins to record.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssh-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"ssh-ext\", cat_sep(\"\\t\", \"\", \n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"country\", \"region\",\n\t \"client\", \"server\", \"resp_size\"));\n\t\n\t}\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info)\n\t{\n\tlocal log = LOG::choose(\"ssh-ext\", id$resp_h);\n\n\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t si$start_time,\n\t id$orig_h, fmt(\"%d\", id$orig_p),\n\t id$resp_h, fmt(\"%d\", id$resp_p),\n\t si$status, si$direction, \n\t si$location$country_code, si$location$region,\n\t si$client, si$server,\n\t si$resp_size);\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"c7dd9e2e2f471d9da2df0d618376baec7574b38c","subject":"Added Kafka plugin config.","message":"Added Kafka plugin config.\n","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Configure Kafka output\n# Bro Kafka Output (plugin must be loaded!)\n@load Kafka\/KafkaWriter\/logs-to-kafka\nredef KafkaLogger::topic_name = \"bro_raw\";\nredef KafkaLogger::sensor_name = ROCK::sensor_id;\n\n","old_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"88bc5f97ec516edee6651eaec6a10dc4beaaf95f","subject":"Updates kafka config to mainline plugin","message":"Updates kafka config to mainline plugin\n\nDepends on the following to be merged in:\r\n\r\nbro-plugin: kafka - Patch to set default to send all logs with option to whitelist or blacklist\r\nhttps:\/\/bro-tracker.atlassian.net\/browse\/BIT-1745\r\n\r\nbro-plugin: kafka - Patch to configure JSON timestamp\r\nhttps:\/\/bro-tracker.atlassian.net\/browse\/BIT-1745","repos":"mocyber\/rock-scripts","old_file":"plugins\/kafka.bro","new_file":"plugins\/kafka.bro","new_contents":"\n## Setup Kafka output\n@load Bro\/Kafka\/logs-to-kafka\n\nredef Kafka::topic_name = \"bro_raw\";\nredef Kafka::json_timestamps = JSON::TS_ISO8601;\nredef Kafka::tag_json = T;\n\n## Setup event extension to include sensor and probe name\ntype Extension: record {\n ## The name of the system that wrote this log. This\n ## is defined in the const so that\n ## a system running lots of processes can give the\n ## same value for any process that writes a log.\n system: string &log;\n ## The name of the process that wrote the log. In\n ## clusters, this will typically be the name of the\n ## worker that wrote the log.\n proc: string &log;\n};\n\nfunction add_log_extension(path: string): Extension\n{\n return Extension($system = ROCK::sensor_id,\n $proc = peer_description);\n}\n\nredef Log::default_ext_func = add_log_extension;\nredef Log::default_ext_prefix = \"@\";\nredef Log::default_scope_sep = \"_\";\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'plugins\/kafka.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"02ee0caf81fefda82ea8f94499e6c7d12fa12161","subject":"Delete remote.bro","message":"Delete remote.bro","repos":"trakons\/sshd_stunnel","old_file":"remote.bro","new_file":"remote.bro","new_contents":"","old_contents":"# @TEST-SERIALIZE: comm\n#\n# @TEST-EXEC: btest-bg-run sender bro -b --pseudo-realtime %INPUT ..\/sender.bro\n# @TEST-EXEC: sleep 1\n# @TEST-EXEC: btest-bg-run receiver bro -b --pseudo-realtime %INPUT ..\/receiver.bro\n# @TEST-EXEC: sleep 1\n# @TEST-EXEC: btest-bg-wait 15\n# @TEST-EXEC: btest-diff sender\/test.log\n# @TEST-EXEC: btest-diff sender\/test.failure.log\n# @TEST-EXEC: btest-diff sender\/test.success.log\n# @TEST-EXEC: ( cd sender && for i in *.log; do cat $i | $SCRIPTS\/diff-remove-timestamps >c.$i; done )\n# @TEST-EXEC: ( cd receiver && for i in *.log; do cat $i | $SCRIPTS\/diff-remove-timestamps >c.$i; done )\n# @TEST-EXEC: cmp receiver\/c.test.log sender\/c.test.log\n# @TEST-EXEC: cmp receiver\/c.test.failure.log sender\/c.test.failure.log\n# @TEST-EXEC: cmp receiver\/c.test.success.log sender\/c.test.success.log\n\n# This is the common part loaded by both sender and receiver.\nmodule Test;\n\nexport {\n\t# Create a new ID for our log stream\n\tredef enum Log::ID += { LOG };\n\n\t# Define a record with all the columns the log file can have.\n\t# (I'm using a subset of fields from ssh-ext for demonstration.)\n\ttype Log: record {\n\t\tt: time;\n\t\tid: conn_id; # Will be rolled out into individual columns.\n\t\tstatus: string &optional;\n\t\tcountry: string &default=\"unknown\";\n\t} &log;\n}\n\nevent bro_init()\n{\n\tLog::create_stream(Test::LOG, [$columns=Log]);\n\tLog::add_filter(Test::LOG, [$name=\"f1\", $path=\"test.success\", $pred=function(rec: Log): bool { return rec$status == \"success\"; }]);\n}\n\n#####\n\n@TEST-START-FILE sender.bro\n\n@load frameworks\/communication\/listen\n\nmodule Test;\n\nfunction fail(rec: Log): bool\n\t{\n\treturn rec$status != \"success\";\n\t}\n\nevent remote_connection_handshake_done(p: event_peer)\n\t{\n\tLog::add_filter(Test::LOG, [$name=\"f2\", $path=\"test.failure\", $pred=fail]);\n\n\tlocal cid = [$orig_h=1.2.3.4, $orig_p=1234\/tcp, $resp_h=2.3.4.5, $resp_p=80\/tcp];\n\n\tlocal r: Log = [$t=network_time(), $id=cid, $status=\"success\"];\n\n\t# Log something.\n\tLog::write(Test::LOG, r);\n\tLog::write(Test::LOG, [$t=network_time(), $id=cid, $status=\"failure\", $country=\"US\"]);\n\tLog::write(Test::LOG, [$t=network_time(), $id=cid, $status=\"failure\", $country=\"UK\"]);\n\tLog::write(Test::LOG, [$t=network_time(), $id=cid, $status=\"success\", $country=\"BR\"]);\n\tLog::write(Test::LOG, [$t=network_time(), $id=cid, $status=\"failure\", $country=\"MX\"]);\n\tdisconnect(p);\n\t}\n\nevent remote_connection_closed(p: event_peer)\n\t{\n\tterminate();\n\t}\n\n@TEST-END-FILE\n\n@TEST-START-FILE receiver.bro\n\n#####\n\n@load base\/frameworks\/communication\n\nredef Communication::nodes += {\n [\"foo\"] = [$host = 127.0.0.1, $connect=T, $request_logs=T]\n};\n\nevent remote_connection_closed(p: event_peer)\n\t{\n\tterminate();\n\t}\n\n@TEST-END-FILE\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"7b947beead5b7b5b99da259bf31d9382902a207d","subject":"use real hostname for connector:","message":"use real hostname for connector:\n\nit appears, that repeering by peername is not possible on remote\nmachines. Thus, the hostname + port has to be used. In order to make\nthis possible, all bro slaves will use their unique hostnames as\nendpoint-suffixes.\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_slave\/dionaea_receiver.bro","new_file":"scripts_slave\/dionaea_receiver.bro","new_contents":"@load .\/bro_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro-slave-\" + gethostname(); # make sure this is unique (for docker-compose, it is!)\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string);\n#global log_dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\n#global log_dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string);\nglobal log_bro: function(msg: string);\nglobal published_events: set[string] = { \"dionaea_access\", \"dionaea_mysql\" };\n\n\nevent bro_init() {\n log_bro(\"dionaea_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n \n # Listening\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n \n # Forwarding\n Broker::connect(\"bro-master\", broker_port, 1sec);\n Broker::register_broker_events(\"bro\/forwarder\/dionaea\", published_events);\n\n # Try unsolicited option, which should prevent topic issues\n Broker::auto_event(\"bro\/forwarder\/dionaea\", dionaea_access, [$unsolicited=T]);\n Broker::auto_event(\"bro\/forwarder\/dionaea\", dionaea_mysql, [$unsolicited=T]);\n log_bro(\"dionaea_receiver.bro: bro_init() done\");\n}\n\nevent bro_done() {\n log_bro(\"dionaea_receiver.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n log_bro(\"Dionaea access event received!\");\n\n # forward:\n event dionaea_access(timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n log_bro(\"Dionaea mysql event received!\");\n\n # forward:\n event dionaea_mysql(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n log_bro(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address; \n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n log_bro(msg);\n}\n\nfunction log_bro(msg: string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n","old_contents":"@load .\/bro_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = unique_id(\"bro-slave-\");\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string);\n#global log_dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\n#global log_dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string);\nglobal log_bro: function(msg: string);\nglobal published_events: set[string] = { \"dionaea_access\", \"dionaea_mysql\" };\n\n\nevent bro_init() {\n log_bro(\"dionaea_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n \n # Listening\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n \n # Forwarding\n Broker::connect(\"bro-master\", broker_port, 1sec);\n Broker::register_broker_events(\"bro\/forwarder\/dionaea\", published_events);\n\n # Try unsolicited option, which should prevent topic issues\n Broker::auto_event(\"bro\/forwarder\/dionaea\", dionaea_access, [$unsolicited=T]);\n Broker::auto_event(\"bro\/forwarder\/dionaea\", dionaea_mysql, [$unsolicited=T]);\n log_bro(\"dionaea_receiver.bro: bro_init() done\");\n}\n\nevent bro_done() {\n log_bro(\"dionaea_receiver.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n log_bro(\"Dionaea access event received!\");\n\n # forward:\n event dionaea_access(timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n log_bro(\"Dionaea mysql event received!\");\n\n # forward:\n event dionaea_mysql(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n log_bro(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address; \n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n log_bro(msg);\n}\n\nfunction log_bro(msg: string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"5fa229cc6e0bc88b214ae081c2fc3f54ec6008bd","subject":"Remove prints from logging-events as they have no use","message":"Remove prints from logging-events as they have no use\n\nTODO: Other prints should be changed to Logs to be useful\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dionaea_receiver.bro","new_file":"custom_scripts\/dionaea_receiver.bro","new_contents":"@load .\/dio_json_log.bro\n@load .\/dio_ftp_log.bro\n@load .\/dio_mysql_log.bro\n@load .\/dio_download_complete_log.bro\n@load .\/dio_download_offer_log.bro\n@load .\/dio_smb_bind_log.bro\n@load .\/dio_smb_request_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, connector_id: string); \nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $connector_id=connector_id];\n\n Log::write(Dio_mysql::LOG, rec);\n}\n\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","old_contents":"@load .\/dio_json_log.bro\n@load .\/dio_ftp_log.bro\n@load .\/dio_mysql_log.bro\n@load .\/dio_download_complete_log.bro\n@load .\/dio_download_offer_log.bro\n@load .\/dio_smb_bind_log.bro\n@load .\/dio_smb_request_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, connector_id: string); \nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, protocol=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, args, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $connector_id=connector_id];\n\n Log::write(Dio_mysql::LOG, rec);\n}\n\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_download_complete: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, protocol=%s, url=%s, md5hash=%s, filelocation=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, md5hash, filelocation, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_download_offer: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, protocol=%s, url=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_smb_request: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, protocol=%s, opnum=%d, uuid=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, opnum, uuid, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_smb_bind: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, protocol=%s, transfersyntax=%s, uuid=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, transfersyntax, uuid, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"26505e7ea9b05e61fd7fc428822b3c5f5ba33d87","subject":"watched_countries is defined under the SSH module","message":"watched_countries is defined under the SSH module\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext.bro","new_file":"ssh-ext.bro","new_contents":"@load global-ext\n@load ssh\n@load notice\n\t\nmodule SSH;\n\nexport {\n\tconst ssh_ext_log = open_log_file(\"ssh-ext\") &raw_output;\n\t\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\ttype ssh_versions: record {\n\t\tclient: string &default=\"\";\n\t\tserver: string &default=\"\";\n\t};\n\t\n\t# Only monitor SSH connections for up to 15 minutes\n\tglobal active_ssh_conns: table[conn_id] of ssh_versions &create_expire=15mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in SSH::watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\t\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal versions = active_ssh_conns[c$id];\n\tlocal status = \"failure\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $sub=location$country_code]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 20000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\t\t\n\tif ( (log_geodata_on_failure && status == \"failure\") ||\n\t status == \"success\" )\n\t\t{\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\t}\n\t\t\n\tprint ssh_ext_log, cat_sep(\"\\t\", \"\\\\N\", c$start_time,\n\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\tstatus, direction, \n\t\t\t\tlocation$country_code, location$region,\n\t\t\t\tversions$client, versions$server,\n\t\t\t\tc$resp$size);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +2mins { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_versions;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +2mins { ssh_watcher(c) }; \n\t\t}\n\t}\n","old_contents":"@load global-ext\n@load ssh\n@load notice\n\t\nmodule SSH;\n\nexport {\n\tconst ssh_ext_log = open_log_file(\"ssh-ext\") &raw_output;\n\t\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\ttype ssh_versions: record {\n\t\tclient: string &default=\"\";\n\t\tserver: string &default=\"\";\n\t};\n\t\n\t# Only monitor SSH connections for up to 15 minutes\n\tglobal active_ssh_conns: table[conn_id] of ssh_versions &create_expire=15mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\t\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal versions = active_ssh_conns[c$id];\n\tlocal status = \"failure\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $sub=location$country_code]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 20000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\t\t\n\tif ( (log_geodata_on_failure && status == \"failure\") ||\n\t status == \"success\" )\n\t\t{\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\t}\n\t\t\n\tprint ssh_ext_log, cat_sep(\"\\t\", \"\\\\N\", c$start_time,\n\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\tstatus, direction, \n\t\t\t\tlocation$country_code, location$region,\n\t\t\t\tversions$client, versions$server,\n\t\t\t\tc$resp$size);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +2mins { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_versions;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +2mins { ssh_watcher(c) }; \n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"cb7ca4acfc0e1a18060c9b562b761ab1326e3397","subject":"Renamed a variable","message":"Renamed a variable\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst log = open_log_file(\"ssl-known-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tadd c$service[\"SSL\"];\n\t\n\tif ( !ip_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\t\t}\n\t}\n\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst log = open_log_file(\"ssl-known-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst log_hosts: Hosts = LocalHosts &redef;\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tadd c$service[\"SSL\"];\n\t\n\tif ( !ip_matches_hosts(c$id$resp_h, log_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\t\t}\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"c0124c813b5a69c1880d19b950f872b562139831","subject":"remove relict","message":"remove relict\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_slave\/bro_slave.bro","new_file":"scripts_slave\/bro_slave.bro","new_contents":"@load .\/slave_log.bro\n\nredef exit_only_after_terminate = T;\n\n# the ports and IPs that are externally routable for a master and this slave\nconst slave_broker_port: string = getenv(\"SLAVE_PUBLIC_PORT\") &redef;\nconst slave_broker_ip: string = getenv(\"SLAVE_PUBLIC_IP\") &redef;\nconst master_broker_port: port = to_port(cat(getenv(\"MASTER_PUBLIC_PORT\"), \"\/tcp\")) &redef;\nconst master_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\n\nredef Broker::endpoint_name = cat(\"bro-slave-\", slave_broker_ip, \":\", slave_broker_port);\n\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string);\nglobal dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal log_conn: event(rec: Conn::Info);\n\nglobal log_bro: function(msg: string);\nglobal published_events: set[string] = { \"dionaea_access\", \"dionaea_ftp\", \"dionaea_mysql_command\", \"dionaea_mysql_login\", \"dionaea_download_complete\", \"dionaea_download_offer\", \"dionaea_smb_request\", \"dionaea_smb_bind\", \"log_conn\" };\n\n\nevent bro_init() {\n log_bro(\"bro_slave.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n \n # Listening\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n \n # Forwarding\n Broker::connect(master_broker_ip, master_broker_port, 1sec);\n Broker::register_broker_events(\"honeypot\/dionaea\", published_events);\n\n log_bro(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n log_bro(\"bro_slave.bro: bro_done()\");\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n log_bro(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n log_bro(msg);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address; \n log_bro(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n log_bro(msg);\n}\n\n# forwarding when some local connection is beeing logged. Throws an explicit beemaster event to forward.\nevent Conn::log_conn(rec: Conn::Info) {\n event log_conn(rec);\n}\n\nfunction log_bro(msg: string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n","old_contents":"@load .\/slave_log.bro\n\nredef exit_only_after_terminate = T;\n\n# the ports and IPs that are externally routable for a master and this slave\nconst slave_broker_port: string = getenv(\"SLAVE_PUBLIC_PORT\") &redef;\nconst slave_broker_ip: string = getenv(\"SLAVE_PUBLIC_IP\") &redef;\nconst master_broker_port: port = to_port(cat(getenv(\"MASTER_PUBLIC_PORT\"), \"\/tcp\")) &redef;\nconst master_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\n\nredef Broker::endpoint_name = cat(\"bro-slave-\", slave_broker_ip, \":\", slave_broker_port);\n\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string);\nglobal dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal log_conn: event(rec: Conn::Info);\n\nglobal log_bro: function(msg: string);\nglobal published_events: set[string] = { \"dionaea_access\", \"dionaea_ftp\", \"dionaea_mysql_command\", \"dionaea_mysql_login\", \"dionaea_download_complete\", \"dionaea_download_offer\", \"dionaea_smb_request\", \"dionaea_smb_bind\", \"log_conn\" };\n\n\nevent bro_init() {\n log_bro(\"bro_slave.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n \n # Listening\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n \n # Forwarding\n Broker::connect(master_broker_ip, master_broker_port, 1sec);\n Broker::register_broker_events(\"honeypot\/dionaea\", published_events);\n\n # Try unsolicited option, which should prevent topic issues\n Broker::auto_event(\"honeypot\/dionaea\", dionaea_access);\n log_bro(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n log_bro(\"bro_slave.bro: bro_done()\");\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n log_bro(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n log_bro(msg);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address; \n log_bro(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n log_bro(msg);\n}\n\n# forwarding when some local connection is beeing logged. Throws an explicit beemaster event to forward.\nevent Conn::log_conn(rec: Conn::Info) {\n event log_conn(rec);\n}\n\nfunction log_bro(msg: string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"2dc24f25e7dd15e36d2d283d807dea5023e87871","subject":"Fix file path for extracted files","message":"Fix file path for extracted files","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nmodule ROCK;\n\nexport {\n const sensor_id = gethostname() &redef;\n}\n\n#=== Bro built-ins ===================================\n\n# Enable VLAN Logging\n@load policy\/protocols\/conn\/vlan-logging\n\n# Log MAC addresses\n@load policy\/protocols\/conn\/mac-logging\n\n# Log (All) Client and Server HTTP Headers\n@load policy\/protocols\/http\/header-names\n\n#== ROCK specific scripts ============================\n# Add empty Intel framework database\n@load .\/frameworks\/intel\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/zeek\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n\n# Log all orig and resp cert hashes in ssl log\n@load .\/protocols\/ssl\/ssl-add-cert-hash\n\n# Enable pop3 logging\n@load .\/protocols\/pop3\n\n# Notice on all recently created certs\n# @load .\/protocols\/ssl\/new-certs\n\n# Generate log of all unique DNS queries with answers\n# @load .\/protocols\/dns\/known_domains\n\n# Generate log of all URLs seen in an SMTP body\n# @load .\/protocols\/smtp\/smtp-url\n\n# Generate log of local systems using unencrypted protocols\n# @load .\/frameworks\/compliance\/detect-insecure-protos\n\n#== 3rd Party Scripts =================================\n# Add Salesforce's JA3 SSL fingerprinting\n@load .\/misc\/ja3\n\n# Add Salesforce's HASSH SSH fingerprinting\n@load .\/misc\/hassh\n\n### Sensor specific scripts ######################\n\n# Configure AF_PACKET, if in use\n@load .\/plugins\/afpacket\n","old_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nmodule ROCK;\n\nexport {\n const sensor_id = gethostname() &redef;\n}\n\n#=== Bro built-ins ===================================\n\n# Enable VLAN Logging\n@load policy\/protocols\/conn\/vlan-logging\n\n# Log MAC addresses\n@load policy\/protocols\/conn\/mac-logging\n\n# Log (All) Client and Server HTTP Headers\n@load policy\/protocols\/http\/header-names\n\n#== ROCK specific scripts ============================\n# Add empty Intel framework database\n@load .\/frameworks\/intel\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n\n# Log all orig and resp cert hashes in ssl log\n@load .\/protocols\/ssl\/ssl-add-cert-hash\n\n# Enable pop3 logging\n@load .\/protocols\/pop3\n\n# Notice on all recently created certs\n# @load .\/protocols\/ssl\/new-certs\n\n# Generate log of all unique DNS queries with answers\n# @load .\/protocols\/dns\/known_domains\n\n# Generate log of all URLs seen in an SMTP body\n# @load .\/protocols\/smtp\/smtp-url\n\n# Generate log of local systems using unencrypted protocols\n# @load .\/frameworks\/compliance\/detect-insecure-protos\n\n#== 3rd Party Scripts =================================\n# Add Salesforce's JA3 SSL fingerprinting\n@load .\/misc\/ja3\n\n# Add Salesforce's HASSH SSH fingerprinting\n@load .\/misc\/hassh\n\n### Sensor specific scripts ######################\n\n# Configure AF_PACKET, if in use\n@load .\/plugins\/afpacket\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"2d83ca68c241f586934dbce634b6b2c872514632","subject":"Fixed a small problem with cc extraction.","message":"Fixed a small problem with cc extraction.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\tlocal redacted_cc = gsub(ccp, \/[0-9]\/, redaction_char);\n\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, ccp);\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_redacted_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","old_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tlocal cc_match = \"\";\n\t\t\tlocal redacted_cc = gsub(ccp, \/[0-9]\/, redaction_char);\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tcc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, cc_match);\n\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : cc_match),\n\t\t\t $data=(redact_log ? redacted_data : data)];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"54638fb28d760758b1156503bf37710474771432","subject":"Create ja3s.bro","message":"Create ja3s.bro\n\nFirst iteration of JA3S, JA3 for the Server Hello packet.","repos":"salesforce\/ja3","old_file":"bro\/ja3s.bro","new_file":"bro\/ja3s.bro","new_contents":"# This Bro script appends JA3S (JA3 Server) to ssl.log\n# Version 1.0 (August 2018)\n# This builds a fingerprint for the SSL Server Hello packet based on SSL\/TLS version, cipher picked, and extensions used. \n# Designed to be used in conjunction with JA3 to fingerprint SSL communication between clients and servers.\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) Jeff Atkinson (jatkinson@salesforce.com)\n# Copyright (c) 2018, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n#\n\n\n\nmodule JA3_Server;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype JA3Sstorage: record {\n server_version: count &default=0 &log;\n server_cipher: count &default=0 &log;\n server_extensions: string &default=\"\" &log;\n};\n\nredef record connection += {\n ja3sfp: JA3Sstorage &optional;\n};\n\nredef record SSL::Info += {\n ja3s: string &optional &log;\n# LOG FIELD VALUES #\n# ja3s_version: string &optional &log;\n# ja3s_cipher: string &optional &log;\n# ja3s_extensions: string &optional &log;\n};\n\n\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3_Server::LOG,[$columns=JA3Sstorage, $path=\"ja3sfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$ja3sfp )\n c$ja3sfp=JA3Sstorage();\n if ( is_orig == F ) { \n if ( c$ja3sfp$server_extensions == \"\" ) {\n c$ja3sfp$server_extensions = cat(code);\n }\n else {\n c$ja3sfp$server_extensions = string_cat(c$ja3sfp$server_extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_server_hello(c: connection, version: count, possible_ts: time, server_random: string, session_id: string, cipher: count, comp_method: count) &priority=1\n{\n if ( !c?$ja3sfp )\n c$ja3sfp=JA3Sstorage();\n c$ja3sfp$server_version = version;\n c$ja3sfp$server_cipher = cipher;\n local sep2 = \",\";\n local ja3s_string = string_cat(cat(c$ja3sfp$server_version),sep2,cat(c$ja3sfp$server_cipher),sep2,c$ja3sfp$server_extensions);\n local ja3sfp_1 = md5_hash(ja3s_string);\n c$ssl$ja3s = ja3sfp_1;\n\n# LOG FIELD VALUES #\n#c$ssl$ja3s_version = cat(c$ja3sfp$server_version);\n#c$ssl$ja3s_cipher = cat(c$ja3sfp$server_cipher);\n#c$ssl$ja3s_extensions = c$ja3sfp$server_extensions;\n#\n# FOR DEBUGGING #\n#print \"JA3S: \"+ja3sfp_1+\" Fingerprint String: \"+ja3s_string;\n\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro\/ja3s.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"74580ef34169af43fb067e41f4dcec993f1639c0","subject":"Added another analyzer for identifying file types of http transfers.","message":"Added another analyzer for identifying file types of http transfers.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-identified-files.bro","new_file":"http-identified-files.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\nmodule HTTP;\n\n\nexport {\n\tconst http_magic_log = open_log_file(\"http-identified-files\") &raw_output &redef;\n\n\t# Base the libmagic analysis on at least this many bytes.\n\tconst magic_content_limit = 1024 &redef;\n\t\n\tconst watched_mime_types: set[string] = { \n\t\t\"application\/x-dosexec\", # Windows and DOS executables\n\t\t\"application\/x-executable\", # *NIX executable binary\n\t} &redef; \n\t\n\tconst watched_descriptions =\n\t\t\/PHP script text\/ &redef;\n\t\n\t# URLs included here are not logged and notices are not thrown.\n\t# Take care when defining regexes to not be overly broad.\n\tconst ignored_urls = \/^http:\\\/\\\/www\\.download\\.windowsupdate\\.com\\\/\/ &redef;\n\t\n\tredef enum Notice += {\n\t\t# This notice is thrown when the file extension doesn't match the file contents\n\t\tHTTP_IncorrectFileType, \n\t};\n\t\n\t# Create regexes that *should* in be in the urls for specifics mime types.\n\t# Notices are thrown if the pattern doesn't match the url for the file type.\n\tconst mime_types_extensions: table[string] of pattern = {\n\t\t[\"application\/x-dosexec\"] = \/\\.([eE][xX][eE]|[dD][lL][lL])\/,\n\t} &redef;\n}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( is_orig ) # We are only watching for server responses\n\t\treturn;\n\t\n\tlocal s = lookup_http_request_stream(c);\n\tlocal msg = get_http_message(s, is_orig);\n\t\n@ifndef\t( content_truncation_limit )\n\t# This is only done if http-body.bro is not loaded.\n\tmsg$data_length = msg$data_length + length;\n@endif\n\t\n\t# For the time being, we'll just use the data from the first packet.\n\t# Don't continue until we have enough data\n\t#if ( msg$data_length < magic_content_limit )\n\t#\treturn;\n\t\n\t# Right now, only try this for the first chunk of data\n\tif ( msg$data_length > length )\n\t\treturn;\n\t\n\tlocal abstract = sub_bytes(data, 1, magic_content_limit);\n\tlocal magic_mime = identify_data(abstract, T);\n\tlocal magic_descr = identify_data(abstract, F);\n\n\tif ( (magic_mime in watched_mime_types ||\n\t watched_descriptions in magic_descr) &&\n\t s$first_pending_request in s$requests )\n\t\t{\n\t\tlocal r = s$requests[s$first_pending_request];\n\t\tlocal host = (s$next_request$host==\"\") ? fmt(\"%s\", c$id$resp_h) : s$next_request$host;\n\t\tlocal url = fmt(\"http:\/\/%s%s\", host, r$URI);\n\t\t\n\t\tevent file_transferred(c, abstract, magic_descr, magic_mime);\n\t\t\n\t\tif ( ignored_urls in url )\n\t\t\treturn;\n\t\t\n\t\tlocal file_type: string = \"\";\n\t\tif ( magic_mime in watched_mime_types )\n\t\t\tfile_type = magic_mime;\n\t\telse\n\t\t\tfile_type = magic_descr;\n\t\t\n\t\tprint http_magic_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), s$id, c$id$orig_h, fmt(\"%d\", c$id$orig_p), c$id$resp_h, fmt(\"%d\", c$id$resp_p), file_type, r$method, url);\n\t\t\n\t\tif ( (magic_mime in mime_types_extensions && mime_types_extensions[magic_mime] !in url) ||\n\t\t (magic_descr in mime_types_extensions && mime_types_extensions[magic_descr] !in url) )\n\t\t\t{\n\t\t\tlocal message = fmt(\"%s %s %s\", file_type, r$method, url);\n\t\t\tNOTICE([$note=HTTP_IncorrectFileType, \n\t\t\t $msg=message, \n\t\t\t $conn=c, \n\t\t\t $method=r$method, \n\t\t\t $URL=url]);\n\t\t\t}\n\t\t}\n\t}\n\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'http-identified-files.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"5b5b367306f0a18f356c88a836a95f17e7ebabb0","subject":"stats get written once per worker.. need to fix","message":"stats get written once per worker.. need to fix\n\nfor now, just don't synchronize\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"metrics.http-ext.bro","new_file":"metrics.http-ext.bro","new_contents":"#output something like this\n#http_metrics total=343243 inbound=102313 outbound=3423432 exe_download=23\n\n@load global-ext\n@load http-ext\n\nexport {\n global http_metrics: table[string] of count &default=0; #&synchronized;\n global http_metrics_interval = +60sec;\n const http_metrics_log = open_log_file(\"http-ext-metrics\");\n}\n\nevent http_write_stats()\n {\n if (http_metrics[\"total\"]!=0)\n {\n print http_metrics_log, fmt(\"http_metrics time=%.6f total=%d inbound=%d outbound=%d video_download=%d youtube_watches=%d\",\n network_time(),\n http_metrics[\"total\"],\n http_metrics[\"inbound\"],\n http_metrics[\"outbound\"],\n http_metrics[\"video_download\"],\n http_metrics[\"youtube_watches\"]\n );\n clear_table(http_metrics);\n }\n schedule http_metrics_interval { http_write_stats() };\n }\n\nevent bro_init()\n {\n set_buf(http_metrics_log, F);\n schedule http_metrics_interval { http_write_stats() };\n }\n\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=-10\n {\n ++http_metrics[\"total\"];\n if(is_local_addr(id$orig_h))\n ++http_metrics[\"outbound\"];\n else\n ++http_metrics[\"inbound\"];\n\n if (\/\\.(avi|flv|mp4|mpg)\/ in si$uri)\n ++http_metrics[\"video_download\"];\n if (\/watch\\?v=\/ in si$uri && \/youtube\/ in si$host)\n ++http_metrics[\"youtube_watches\"];\n\n }\n","old_contents":"#output something like this\n#http_metrics total=343243 inbound=102313 outbound=3423432 exe_download=23\n\n@load global-ext\n@load http-ext\n\nexport {\n global http_metrics: table[string] of count &default=0 &synchronized;\n global http_metrics_interval = +60sec;\n const http_metrics_log = open_log_file(\"http-ext-metrics\");\n}\n\nevent http_write_stats()\n {\n if (http_metrics[\"total\"]!=0)\n {\n print http_metrics_log, fmt(\"http_metrics time=%.6f total=%d inbound=%d outbound=%d video_download=%d youtube_watches=%d\",\n network_time(),\n http_metrics[\"total\"],\n http_metrics[\"inbound\"],\n http_metrics[\"outbound\"],\n http_metrics[\"video_download\"],\n http_metrics[\"youtube_watches\"]\n );\n clear_table(http_metrics);\n }\n schedule http_metrics_interval { http_write_stats() };\n }\n\nevent bro_init()\n {\n set_buf(http_metrics_log, F);\n schedule http_metrics_interval { http_write_stats() };\n }\n\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=-10\n {\n ++http_metrics[\"total\"];\n if(is_local_addr(id$orig_h))\n ++http_metrics[\"outbound\"];\n else\n ++http_metrics[\"inbound\"];\n\n if (\/\\.(avi|flv|mp4|mpg)\/ in si$uri)\n ++http_metrics[\"video_download\"];\n if (\/watch\\?v=\/ in si$uri && \/youtube\/ in si$host)\n ++http_metrics[\"youtube_watches\"];\n\n }\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1518f765ac872f8b9cfbd0277af2efdda43c0a59","subject":"Create __load__.bro","message":"Create __load__.bro","repos":"unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,CrowdStrike\/cs-bro,albertzaharovits\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/intel-extensions\/__load__.bro","new_file":"bro-scripts\/intel-extensions\/__load__.bro","new_contents":"@load .\/main\n@load .\/seen\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/intel-extensions\/__load__.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"12df2497b397c10e611cabe36fdd832164b33087","subject":"check for presence of mime type first","message":"check for presence of mime type first\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-mime-metrics.bro","new_file":"http-mime-metrics.bro","new_contents":"@load base\/frameworks\/metrics\n\nredef enum Metrics::ID += {\n HTTP_MIME_METRICS,\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_MIME_METRICS,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n}\n\nevent HTTP::log_http(rec: HTTP::Info)\n{\n if(Site::is_local_addr(rec$id$resp_h) && rec?$mime_type) {\n Metrics::add_data(HTTP_MIME_METRICS, [$str=rec$mime_type], rec$response_body_len);\n }\n}\n","old_contents":"@load base\/frameworks\/metrics\n\nredef enum Metrics::ID += {\n HTTP_MIME_METRICS,\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_MIME_METRICS,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n}\n\nevent HTTP::log_http(rec: HTTP::Info)\n{\n if(Site::is_local_addr(rec$id$resp_h)) {\n Metrics::add_data(HTTP_MIME_METRICS, [$str=rec$mime_type], rec$response_body_len);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"2756a960b697f1d536859638e1760ed37bd14b46","subject":"don't block the same address more than once at the same time","message":"don't block the same address more than once at the same time\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ipblocker.bro","new_file":"ipblocker.bro","new_contents":"function notice_exec_ipblocker(n: notice_info, a: NoticeAction): NoticeAction\n{\n local cmd = fmt(\"lckdo \/tmp\/bro_ipblocker_%s \/usr\/local\/bin\/bro_ipblocker_block\", n$id$orig_h);\n execute_with_notice(cmd, n);\n return NOTICE_ALARM_ALWAYS;\n}\n\n","old_contents":"function notice_exec_ipblocker(n: notice_info, a: NoticeAction): NoticeAction\n{\n execute_with_notice(\"\/usr\/local\/bin\/bro_ipblocker_block\", n);\n return NOTICE_ALARM_ALWAYS;\n}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"cdcbd72a2930aba93d0f42a33f890e5cc4af6534","subject":"Fix from Vern.","message":"Fix from Vern.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"88ea5024948ae30cfe6ea66c6ad2cf24da5d7cc0","subject":"Fixed an issue with logging of user-agent headers. Thanks Justin. Also, *actually* fixed the indentation issue from last commit.","message":"Fixed an issue with logging of user-agent headers. Thanks Justin.\nAlso, *actually* fixed the indentation issue from last commit.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext.bro","new_file":"http-ext.bro","new_contents":"@load global-ext\n@load http-request\n@load http-entity\n\ntype http_ext_session_info: record {\n\tstart_time: time;\n\tmethod: string &default=\"\";\n\thost: string &default=\"\";\n\turi: string &default=\"\";\n\turl: string &default=\"\";\n\treferrer: string &default=\"\";\n\tuser_agent: string &default=\"\";\n\tproxied_for: string &default=\"\";\n\n\tforce_log: bool &default=F; # This will force the request to be logged (if doing any logging)\n\tforce_log_client_body: bool &default=F; # This will force the client body to be logged.\n\tforce_log_reasons: set[string]; # Reasons why the forced logging happened.\n\t\n\t# This is internal state tracking.\n\tfull: bool &default=F;\n\tnew_user_agent: bool &default=F;\n};\n\nfunction default_http_ext_session_info(): http_ext_session_info\n\t{\n\tlocal x: http_ext_session_info;\n\tlocal tmp: set[string] = set();\n\tx$start_time=network_time();\n\tx$force_log_reasons=tmp;\n\treturn x;\n\t}\n\ntype http_ext_activity_count: record {\n\tsql_injections: track_count;\n\tsql_injection_probes: track_count;\n\tsuspicious_posts: track_count;\n};\n\nfunction default_http_ext_activity_count(a:addr):http_ext_activity_count \n\t{\n\tlocal x: http_ext_activity_count; \n\treturn x; \n\t}\n\n# Define the generic http_ext events that can be handled from other scripts\nglobal http_ext: event(id: conn_id, si: http_ext_session_info);\n\nmodule HTTP;\n\n# Uncomment the following lines if you have these data sets available and would\n# like to use them.\n#@load malware_com_br_block_list-data\n#@load zeus-data\n#@load malwaredomainlist-data\n\nexport {\n\tredef enum Notice += { \n\t\tHTTP_Suspicious,\n\t\tHTTP_SQL_Injection_Attack,\n\t\tHTTP_SQL_Injection_Heavy_Probing,\n\n\t\tHTTP_Malware_com_br_Block_List,\n\t\tHTTP_Zeus_Communication,\n\t\tHTTP_MalwareDomainList_Communication,\n\t};\n\n\t# This is the regular expression that is used to match URI based SQL injections\n\tconst sql_injection_regex = \n\t\t \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[iI][nN][sS][eE][rR][tT])[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([oO][rR]|[aA][nN][dD])([[:blank:]]|\\\/\\*.*?\\*\\\/)+['\"]?[^a-zA-Z&]+?=\/\n\t\t| \/[\\?&][^[:blank:]]+?=[\\-0-9%]*([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/)*(\\-|\\+|\\|\\|)([[:blank:]]|\\\/\\*.*?\\*\\\/)*([0-9]|\\(?[cC][oO][nN][vV][eE][rR][tT]|[cC][aA][sS][tT])\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/|;)*([oO][rR]|[aA][nN][dD]|[hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[rR][eE][gG][eE][xX][pP]|[iI][nN][sS][eE][rR][tT]|\\()[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]]+?=[^\\.]*?([cC][hH][aA][rR]|[aA][sS][cC][iI][iI]|[sS][uU][bB][sS][tT][rR][iI][nN][gG]|[tT][rR][uU][nN][cC][aA][tT][eE]|[vV][eE][rR][sS][iI][oO][nN]|[lL][eE][nN][gG][tT][hH])\\(\/ &redef;\n\n\t# SQL injection probes are considered to be:\n\t# 1. A single single-quote at the end of a URL with no other single-quotes.\n\t# 2. URLs with one single quote at the end of a normal GET value.\n\tconst sql_injection_probe_regex =\n\t\t \/^[^\\']+\\'$\/\n\t\t| \/^[^\\']+\\'&[^\\']*$\/ &redef;\n\n\t# Define which hosts user-agents you'd like to track.\n\tconst track_user_agents_for = LocalHosts &redef;\n\n\t# If there is something creating large number of strange user-agent,\n\t# you can filter those out with this pattern.\n\tconst ignored_user_agents = \/DONT_MATCH_ANYTHING\/ &redef;\n\n\t# HTTP post data contents that appear suspicious.\n\t# This is usually spammy forum postings and the like.\n\tconst suspicious_http_posts = \n\t\t\/[vV][iI][aA][gG][rR][aA]\/ | \n\t\t\/[tT][rR][aA][mM][aA][dD][oO][lL]\/ |\n\t\t\/[cC][iI][aA][lL][iI][sS]\/ | \n\t\t\/[sS][oO][mM][aA]\/ | \n\t\t\/[hH][yY][dD][rR][oO][cC][oO][dD][oO][nN][eE]\/ |\n\t\t\/[cC][aA][nN][aA][dD][iI][aA][nN].{0,15}[pP][hH][aA][rR][mM][aA][cC][yY]\/ |\n\t\t\/[rR][iI][nN][gG].?[tT][oO][nN][eE]\/ |\n\t\t\/[pP][eE][nN][iI][sS]\/ |\n\t\t\/[oO][nN][lL][iI][nN][eE].?[cC][aA][sS][iI][nN][oO]\/ |\n\t\t\/[rR][eE][mM][oO][rR][tT][gG][aA][gG][eE][sS]\/ |\n\t\t# more than 4 bbcode style links in a POST is deemed suspicious\n\t\t\/(url=http:.*){4}\/ | \n\t\t# more that 4 html links is also suspicious\n\t\t\/(a.href(=|%3[dD]).*){4}\/ &redef;\n\t\t\n\tconst http_forwarded_headers = {\n\t\t\"HTTP_FORWARDED\",\n\t\t\"FORWARDED\",\n\t\t\"HTTP_X_FORWARDED_FOR\",\n\t\t\"X_FORWARDED_FOR\",\n\t\t\"HTTP_X_FORWARDED_FROM\",\n\t\t\"X_FORWARDED_FROM\",\n\t\t\"HTTP_CLIENT_IP\",\n\t\t\"CLIENT_IP\",\n\t\t\"HTTP_FROM\",\n\t\t\"FROM\",\n\t\t\"HTTP_VIA\",\n\t\t\"VIA\",\n\t\t\"HTTP_XROXY_CONNECTION\",\n\t\t\"XROXY_CONNECTION\",\n\t\t\"HTTP_PROXY_CONNECTION\",\n\t\t\"PROXY_CONNECTION\",\n\t} &redef;\n\n\tglobal conn_info: table[conn_id] of http_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\n\tglobal activity_counters: table[addr] of http_ext_activity_count \n\t\t&create_expire=1day \n\t\t&synchronized\n\t\t&default=default_http_ext_activity_count\n\t\t&redef;\n\n\t# You can inspect this during runtime from other modules to see what\n\t# user-agents a host has used.\n\tglobal known_user_agents: table[addr] of set[string] \n\t\t&create_expire=3hrs\n\t\t&synchronized\n\t\t&default=addr_empty_string_set\n\t\t&redef;\n}\n\n# This is called from signatures (theoretically)\nfunction log_post(state: signature_state, data: string): bool\n\t{\n\t# Log the post data when it becomes available.\n\tif ( state$conn$id in conn_info )\n\t\t{\n\t\tconn_info[state$conn$id]$force_log_client_body = T;\n\t\tadd conn_info[state$conn$id]$force_log_reasons[fmt(\"matched_signature_%s\",state$id)];\n\t\t}\n\t\n\t# We'll always allow the signature to fire\n\treturn T;\n\t}\n\t\nevent http_request(c: connection, method: string, original_URI: string,\n\t unescaped_URI: string, version: string)\n\t{\n\tif ( c$id !in conn_info )\n\t\t{\n\t\tlocal x = default_http_ext_session_info();\n\t\tconn_info[c$id] = x;\n\t\t}\n\t\n\tlocal sess_ext = conn_info[c$id];\n\tsess_ext$method = method;\n\tsess_ext$uri = unescaped_URI;\n\t}\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &priority=5\n\t{\n\tif ( !is_orig )\n\t\treturn; \n\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t\treturn;\n\t\n\tlocal sess_ext = conn_info[id];\n\tsess_ext$url = fmt(\"http:\/\/%s%s\", sess_ext$host, sess_ext$uri);\n\n\t# Detect and log SQL injection attempts in their own log file\n\tif ( sql_injection_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection\"];\n\t\t\n\t\t++(activity_counters[id$orig_h]$sql_injections$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[id$orig_h]$sql_injections) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Attack,\n\t\t\t $msg=fmt(\"SQL injection attack (n=%d): %s -> %s\",\n\t\t\t activity_counters[id$orig_h]$sql_injections$n,\n\t\t\t numeric_id_string(id), sess_ext$url),\n\t\t\t $conn=c,\n\t\t\t $n=activity_counters[id$orig_h]$sql_injections$n]);\n\t\t\t}\n\t\t}\n\tif ( sql_injection_probe_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection_probe\"];\n\t\t++(activity_counters[id$orig_h]$sql_injection_probes$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[c$id$orig_h]$sql_injection_probes) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Heavy_Probing, \n\t\t\t $msg=fmt(\"Heavy probing from %s\", id$orig_h), \n\t\t\t $n=activity_counters[c$id$orig_h]$sql_injection_probes$n, \n\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\n@ifdef ( MalwareComBr_BlockList )\n\tif ( MalwareComBr_BlockList in sess_ext$url )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malware_com_br\"];\n\t\tlocal malware_com_br_msg = fmt(\"%s %s %s\", sess_ext$method, sess_ext$url, sess_ext$referrer);\n\t\tNOTICE([$note=HTTP_Malware_com_br_Block_List, $msg=malware_com_br_msg, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( ZeusDomains )\n\tif ( sess_ext$host in ZeusDomains )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"zeustracker\"];\n\t\tlocal zeus_msg = fmt(\"%s communicated with likely Zeus controller at %s\", c$id$orig_h, sess_ext$host);\n\t\tNOTICE([$note=HTTP_Zeus_Communication, $msg=zeus_msg, $sub=sess_ext$url, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( MalwareDomainList )\n\tif ( sess_ext$url in MalwareDomainList )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malwaredomainlist\"];\n\t\tlocal mdl_msg = fmt(\"%s communicated with malwaredomainlist.com URL at %s\", c$id$orig_h, sess_ext$url);\n\t\tNOTICE([$note=HTTP_MalwareDomainList_Communication, $msg=mdl_msg, $sub=MalwareDomainList[sess_ext$url], $conn=c]);\n\t\t}\n@endif\n\n\tevent http_ext(id, sess_ext);\n\t\n\t# No data from the reply is supported yet, so it's ok to delete here.\n\tdelete conn_info[c$id];\n\t}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in conn_info )\n\t\tconn_info[c$id] = default_http_ext_session_info();\n\n\tlocal ci = conn_info[c$id];\n\n\tif ( name == \"REFERER\" )\n\t\tci$referrer = value;\n\t\t\n\telse if ( name == \"HOST\" )\n\t\tci$host = value;\n\n\telse if ( name == \"USER-AGENT\" )\n\t\t{\n\t\tci$user_agent = value;\n\t\t\n\t\tif ( ignored_user_agents in value ) \n\t\t\treturn;\n\t\t\t\n\t\tif ( addr_matches_hosts(c$id$orig_h, track_user_agents_for) &&\n\t\t\t value !in known_user_agents[c$id$orig_h] )\n\t\t\t{\n\t\t\tif ( c$id$orig_h !in known_user_agents )\n\t\t\t\tknown_user_agents[c$id$orig_h] = set();\n\t\t\tadd known_user_agents[c$id$orig_h][value];\n\t\t\tci$new_user_agent = T;\n\t\t\t}\n\t\t}\n\n\telse if ( name in http_forwarded_headers )\n\t\t{\n\t\tif ( ci$proxied_for == \"\" )\n\t\t\tci$proxied_for = fmt(\"(%s::%s)\", name, value);\n\t\telse\n\t\t\tci$proxied_for = fmt(\"%s, (%s::%s)\", ci$proxied_for, name, value);\n\t\t}\n\t}\n","old_contents":"@load global-ext\n@load http-request\n@load http-entity\n\ntype http_ext_session_info: record {\n\tstart_time: time;\n\tmethod: string &default=\"\";\n\thost: string &default=\"\";\n\turi: string &default=\"\";\n\turl: string &default=\"\";\n\treferrer: string &default=\"\";\n\tuser_agent: string &default=\"\";\n\tproxied_for: string &default=\"\";\n\n\tforce_log: bool &default=F; # This will force the request to be logged (if doing any logging)\n\tforce_log_client_body: bool &default=F; # This will force the client body to be logged.\n\tforce_log_reasons: set[string]; # Reasons why the forced logging happened.\n\t\n\t# This is internal state tracking.\n\tfull: bool &default=F;\n\tnew_user_agent: bool &default=F;\n};\n\nfunction default_http_ext_session_info(): http_ext_session_info\n\t{\n\tlocal x: http_ext_session_info;\n\tlocal tmp: set[string] = set();\n\tx$start_time=network_time();\n\tx$force_log_reasons=tmp;\n\treturn x;\n\t}\n\ntype http_ext_activity_count: record {\n\tsql_injections: track_count;\n\tsql_injection_probes: track_count;\n\tsuspicious_posts: track_count;\n};\n\nfunction default_http_ext_activity_count(a:addr):http_ext_activity_count \n\t{\n\tlocal x: http_ext_activity_count; \n\treturn x; \n\t}\n\n# Define the generic http_ext events that can be handled from other scripts\nglobal http_ext: event(id: conn_id, si: http_ext_session_info);\n\nmodule HTTP;\n\n# Uncomment the following lines if you have these data sets available and would\n# like to use them.\n#@load malware_com_br_block_list-data\n#@load zeus-data\n#@load malwaredomainlist-data\n\nexport {\n\tredef enum Notice += { \n\t\tHTTP_Suspicious,\n\t\tHTTP_SQL_Injection_Attack,\n\t\tHTTP_SQL_Injection_Heavy_Probing,\n\n\t\tHTTP_Malware_com_br_Block_List,\n\t\tHTTP_Zeus_Communication,\n\t\tHTTP_MalwareDomainList_Communication,\n\t};\n\n\t# This is the regular expression that is used to match URI based SQL injections\n\tconst sql_injection_regex = \n\t\t \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[iI][nN][sS][eE][rR][tT])[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([oO][rR]|[aA][nN][dD])([[:blank:]]|\\\/\\*.*?\\*\\\/)+['\"]?[^a-zA-Z&]+?=\/\n\t\t| \/[\\?&][^[:blank:]]+?=[\\-0-9%]*([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/)*(\\-|\\+|\\|\\|)([[:blank:]]|\\\/\\*.*?\\*\\\/)*([0-9]|\\(?[cC][oO][nN][vV][eE][rR][tT]|[cC][aA][sS][tT])\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/|;)*([oO][rR]|[aA][nN][dD]|[hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[rR][eE][gG][eE][xX][pP]|[iI][nN][sS][eE][rR][tT]|\\()[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]]+?=[^\\.]*?([cC][hH][aA][rR]|[aA][sS][cC][iI][iI]|[sS][uU][bB][sS][tT][rR][iI][nN][gG]|[tT][rR][uU][nN][cC][aA][tT][eE]|[vV][eE][rR][sS][iI][oO][nN]|[lL][eE][nN][gG][tT][hH])\\(\/ &redef;\n\n\t# SQL injection probes are considered to be:\n\t# 1. A single single-quote at the end of a URL with no other single-quotes.\n\t# 2. URLs with one single quote at the end of a normal GET value.\n\tconst sql_injection_probe_regex =\n\t\t \/^[^\\']+\\'$\/\n\t\t| \/^[^\\']+\\'&[^\\']*$\/ &redef;\n\n\t# Define which hosts user-agents you'd like to track.\n\tconst track_user_agents_for = LocalHosts &redef;\n\n\t# If there is something creating large number of strange user-agent,\n\t# you can filter those out with this pattern.\n\tconst ignored_user_agents = \/DONT_MATCH_ANYTHING\/ &redef;\n\n\t# HTTP post data contents that appear suspicious.\n\t# This is usually spammy forum postings and the like.\n\tconst suspicious_http_posts = \n\t\t\/[vV][iI][aA][gG][rR][aA]\/ | \n\t\t\/[tT][rR][aA][mM][aA][dD][oO][lL]\/ |\n\t\t\/[cC][iI][aA][lL][iI][sS]\/ | \n\t\t\/[sS][oO][mM][aA]\/ | \n\t\t\/[hH][yY][dD][rR][oO][cC][oO][dD][oO][nN][eE]\/ |\n\t\t\/[cC][aA][nN][aA][dD][iI][aA][nN].{0,15}[pP][hH][aA][rR][mM][aA][cC][yY]\/ |\n\t\t\/[rR][iI][nN][gG].?[tT][oO][nN][eE]\/ |\n\t\t\/[pP][eE][nN][iI][sS]\/ |\n\t\t\/[oO][nN][lL][iI][nN][eE].?[cC][aA][sS][iI][nN][oO]\/ |\n\t\t\/[rR][eE][mM][oO][rR][tT][gG][aA][gG][eE][sS]\/ |\n\t\t# more than 4 bbcode style links in a POST is deemed suspicious\n\t\t\/(url=http:.*){4}\/ | \n\t\t# more that 4 html links is also suspicious\n\t\t\/(a.href(=|%3[dD]).*){4}\/ &redef;\n\t\t\n\t\tconst http_forwarded_headers = {\n\t\t\t\"HTTP_FORWARDED\",\n\t\t\t\"FORWARDED\",\n\t\t\t\"HTTP_X_FORWARDED_FOR\",\n\t\t\t\"X_FORWARDED_FOR\",\n\t\t\t\"HTTP_X_FORWARDED_FROM\",\n\t\t\t\"X_FORWARDED_FROM\",\n\t\t\t\"HTTP_CLIENT_IP\",\n\t\t\t\"CLIENT_IP\",\n\t\t\t\"HTTP_FROM\",\n\t\t\t\"FROM\",\n\t\t\t\"HTTP_VIA\",\n\t\t\t\"VIA\",\n\t\t\t\"HTTP_XROXY_CONNECTION\",\n\t\t\t\"XROXY_CONNECTION\",\n\t\t\t\"HTTP_PROXY_CONNECTION\",\n\t\t\t\"PROXY_CONNECTION\",\n\t\t} &redef;\n\n\tglobal conn_info: table[conn_id] of http_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\n\tglobal activity_counters: table[addr] of http_ext_activity_count \n\t\t&create_expire=1day \n\t\t&synchronized\n\t\t&default=default_http_ext_activity_count\n\t\t&redef;\n\n\t# You can inspect this during runtime from other modules to see what\n\t# user-agents a host has used.\n\tglobal known_user_agents: table[addr] of set[string] \n\t\t&create_expire=3hrs\n\t\t&synchronized\n\t\t&default=addr_empty_string_set\n\t\t&redef;\n}\n\n# This is called from signatures (theoretically)\nfunction log_post(state: signature_state, data: string): bool\n\t{\n\t# Log the post data when it becomes available.\n\tif ( state$conn$id in conn_info )\n\t\t{\n\t\tconn_info[state$conn$id]$force_log_client_body = T;\n\t\tadd conn_info[state$conn$id]$force_log_reasons[fmt(\"matched_signature_%s\",state$id)];\n\t\t}\n\t\n\t# We'll always allow the signature to fire\n\treturn T;\n\t}\n\t\nevent http_request(c: connection, method: string, original_URI: string,\n\t unescaped_URI: string, version: string)\n\t{\n\tif ( c$id !in conn_info )\n\t\t{\n\t\tlocal x = default_http_ext_session_info();\n\t\tconn_info[c$id] = x;\n\t\t}\n\t\n\tlocal sess_ext = conn_info[c$id];\n\tsess_ext$method = method;\n\tsess_ext$uri = unescaped_URI;\n\t}\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &priority=5\n\t{\n\tif ( !is_orig )\n\t\treturn; \n\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t\treturn;\n\t\n\tlocal sess_ext = conn_info[id];\n\tsess_ext$url = fmt(\"http:\/\/%s%s\", sess_ext$host, sess_ext$uri);\n\n\t# Detect and log SQL injection attempts in their own log file\n\tif ( sql_injection_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection\"];\n\t\t\n\t\t++(activity_counters[id$orig_h]$sql_injections$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[id$orig_h]$sql_injections) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Attack,\n\t\t\t $msg=fmt(\"SQL injection attack (n=%d): %s -> %s\",\n\t\t\t activity_counters[id$orig_h]$sql_injections$n,\n\t\t\t numeric_id_string(id), sess_ext$url),\n\t\t\t $conn=c,\n\t\t\t $n=activity_counters[id$orig_h]$sql_injections$n]);\n\t\t\t}\n\t\t}\n\tif ( sql_injection_probe_regex in sess_ext$uri )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tadd sess_ext$force_log_reasons[\"sql_injection_probe\"];\n\t\t++(activity_counters[id$orig_h]$sql_injection_probes$n);\n\t\t\n\t\tif ( default_check_threshold(activity_counters[c$id$orig_h]$sql_injection_probes) )\n\t\t\t{\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Heavy_Probing, \n\t\t\t $msg=fmt(\"Heavy probing from %s\", id$orig_h), \n\t\t\t $n=activity_counters[c$id$orig_h]$sql_injection_probes$n, \n\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\n@ifdef ( MalwareComBr_BlockList )\n\tif ( MalwareComBr_BlockList in sess_ext$url )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malware_com_br\"];\n\t\tlocal malware_com_br_msg = fmt(\"%s %s %s\", sess_ext$method, sess_ext$url, sess_ext$referrer);\n\t\tNOTICE([$note=HTTP_Malware_com_br_Block_List, $msg=malware_com_br_msg, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( ZeusDomains )\n\tif ( sess_ext$host in ZeusDomains )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"zeustracker\"];\n\t\tlocal zeus_msg = fmt(\"%s communicated with likely Zeus controller at %s\", c$id$orig_h, sess_ext$host);\n\t\tNOTICE([$note=HTTP_Zeus_Communication, $msg=zeus_msg, $sub=sess_ext$url, $conn=c]);\n\t\t}\n@endif\n\n@ifdef ( MalwareDomainList )\n\tif ( sess_ext$url in MalwareDomainList )\n\t\t{\n\t\tsess_ext$force_log=T;\n\t\tsess_ext$force_log_client_body=T;\n\t\tadd sess_ext$force_log_reasons[\"malwaredomainlist\"];\n\t\tlocal mdl_msg = fmt(\"%s communicated with malwaredomainlist.com URL at %s\", c$id$orig_h, sess_ext$url);\n\t\tNOTICE([$note=HTTP_MalwareDomainList_Communication, $msg=mdl_msg, $sub=MalwareDomainList[sess_ext$url], $conn=c]);\n\t\t}\n@endif\n\n\tevent http_ext(id, sess_ext);\n\t\n\t# No data from the reply is supported yet, so it's ok to delete here.\n\tdelete conn_info[c$id];\n\t}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in conn_info )\n\t\tconn_info[c$id] = default_http_ext_session_info();\n\n\tlocal ci = conn_info[c$id];\n\n\tif ( name == \"REFERER\" )\n\t\tci$referrer = value;\n\t\t\n\telse if ( name == \"HOST\" )\n\t\tci$host = value;\n\n\telse if ( name == \"USER-AGENT\" )\n\t\t{\n\t\tci$user_agent = value;\n\t\t\n\t\tif ( ignored_user_agents in value ) \n\t\t\treturn;\n\t\t\t\n\t\tif ( addr_matches_hosts(c$id$orig_h, track_user_agents_for) ||\n\t\t\t value in known_user_agents[c$id$orig_h] )\n\t\t\t{\n\t\t\tif ( c$id$orig_h !in known_user_agents )\n\t\t\t\t{\n\t\t\t\tknown_user_agents[c$id$orig_h] = set();\n\t\t\t\tci$new_user_agent = T;\n\t\t\t\t}\n\t\t\tadd known_user_agents[c$id$orig_h][value];\n\t\t\t}\n\t\t}\n\n\telse if ( name in http_forwarded_headers )\n\t\t{\n\t\tif ( ci$proxied_for == \"\" )\n\t\t\tci$proxied_for = fmt(\"(%s::%s)\", name, value);\n\t\telse\n\t\t\tci$proxied_for = fmt(\"%s, (%s::%s)\", ci$proxied_for, name, value);\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"db6123795803be25651bfca091ba2ac7c47273c8","subject":"Add Bro script to ingest events.","message":"Add Bro script to ingest events.\n\nThe script simply sends all events to VAST.\n","repos":"pmos69\/vast,vast-io\/vast,mavam\/vast,vast-io\/vast,vast-io\/vast,vast-io\/vast,vast-io\/vast,mavam\/vast,pmos69\/vast,pmos69\/vast,pmos69\/vast,mavam\/vast,mavam\/vast","old_file":"test\/bro\/ingest.bro","new_file":"test\/bro\/ingest.bro","new_contents":"@load base\/frameworks\/communication\n\nCommunication::nodes[\"vast\"] = [$host = 127.0.0.1,\n $p = 42000\/tcp,\n $events = \/^.*$\/,\n #$retry=10secs,\n $connect=T];\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'test\/bro\/ingest.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"7c13d10966d8f1aa3fde9fb9fe1ff04ddaeb3165","subject":"Revert \"Removes kafka from main config\"","message":"Revert \"Removes kafka from main config\"\n","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Configure Kafka output\n# Bro Kafka Output (plugin must be loaded!)\n@load Kafka\/KafkaWriter\/logs-to-kafka\nredef KafkaLogger::topic_name = \"bro_raw\";\nredef KafkaLogger::sensor_name = ROCK::sensor_id;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n# Add worker information to conn log\n@load .\/misc\/conn-add-worker\n\n","old_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n# Add worker information to conn log\n@load .\/misc\/conn-add-worker\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"dae039b7c6e526128c9b36647e0663b8e65c66b5","subject":"Added logging extension transform.","message":"Added logging extension transform.\n","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n","old_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n# Add worker information to conn log\n@load .\/misc\/conn-add-worker\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"05fa730d3eafa469269ce231f38b357c56828086","subject":"remove RDP namespace, it isn't needed and was breaking signatures","message":"remove RDP namespace, it isn't needed and was breaking signatures\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"rdp.bro","new_file":"rdp.bro","new_contents":"# $Id$\n@load notice\nglobal rdp_connection: event(c: connection);\n\n@load signatures\nredef signature_files += \"rdp.sig\";\nredef signature_actions += { [\"dpd_rdp\"] = SIG_IGNORE };\n\n\nglobal rdp_ports = {\n\t3389\/tcp\n};\nredef capture_filters += { [\"rdp\"] = \"tcp and port 3389\"};\n\nevent signature_match(state: signature_state, msg: string, data: string)\n{\n if (state$id == \"dpd_rdp\"){\n\t\tadd state$conn$service[\"RDP\"];\n event rdp_connection(state$conn);\n }\n}\n","old_contents":"# $Id$\n@load notice\nglobal rdp_connection: event(c: connection);\n\nmodule RDP;\n\n@load signatures\nredef signature_files += \"rdp.sig\";\nredef signature_actions += { [\"dpd_rdp\"] = SIG_IGNORE };\n\n\nglobal rdp_ports = {\n\t3389\/tcp\n};\nredef capture_filters += { [\"rdp\"] = \"tcp and port 3389\"};\n\nevent signature_match(state: signature_state, msg: string, data: string)\n{\n if (state$id == \"dpd_rdp\"){\n\t\tadd state$conn$service[\"RDP\"];\n event rdp_connection(state$conn);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"29726d1dc08ffbbaf25a6cbc58201623941e6167","subject":"notice action filters for sending email to a subnet administrator","message":"notice action filters for sending email to a subnet administrator\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"subnet-admins.bro","new_file":"subnet-admins.bro","new_contents":"@load my-notice-action-filter\nglobal subnet_admins: table[subnet] of string &redef;\n\nfunction notice_email_subnet_admins(n: notice_info, a: NoticeAction): NoticeAction\n{\n local id = n$conn$id;\n local host = is_local_addr(id$orig_h) ? id$orig_h : id$resp_h;\n local admin = \"\";\n\n if(host !in subnet_admins)\n admin = mail_dest;\n else\n admin = subnet_admins[host];\n email_notice_to(n, admin);\n event notice_alarm(n, NOTICE_EMAIL);\n return NOTICE_FILE;\n}\n\nfunction notice_email_subnet_admins_then_tally(n: notice_info, a: NoticeAction): NoticeAction\n{\n a = notice_email_then_tally(n, a);\n if(a == NOTICE_EMAIL){\n a = notice_email_subnet_admins(n, a);\n }\n return a;\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'subnet-admins.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"2d61aae397bc967733ec2a9b610130140bf5bfdc","subject":"alert on more things","message":"alert on more things\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-block-exe-hosts.bro","new_file":"http-ext-block-exe-hosts.bro","new_contents":"@load http-ext\n@load ipblocker\n\nmodule HTTP;\n\nexport {\n redef enum Notice += {\n HTTP_IncorrectFileTypeBadHost\n };\n\n const bad_exec_domains = \n \/co\\.cc\/\n | \/cz\\.cc\/\n &redef;\n\n const bad_exec_urls = \n \/php.adv=\/\n | \/http:\\\/\\\/[0-9]{1,3}\\.[0-9]{1,3}.*\\\/index\\.php\\?[^=]+=[^=]+$\/ #try to match http:\/\/1.2.3.4\/index.php?foo=bar\n &redef;\n\n const bad_user_agents = \n \/Java\\\/1\/\n &redef;\n\n}\n\nredef notice_action_filters += {\n [HTTP_IncorrectFileTypeBadHost] = notice_exec_ipblocker_dest,\n};\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h))\n return;\n if(! (\"identified-files\" in si$tags && si$mime_type == \"application\/x-dosexec\"))\n return;\n\n if( (bad_exec_domains in si$host || bad_exec_urls in si$url)\n ||(\/\\.exe\/ !in si$url && bad_user_agents in si$user_agent)) {\n NOTICE([$note=HTTP_IncorrectFileTypeBadHost,\n $id=id,\n $msg=fmt(\"EXE Downloaded from bad host %s %s %s\", id$orig_h, id$resp_h, si$url),\n $sub=\"http-ext\"\n ]);\n }\n}\n","old_contents":"@load http-ext\n@load ipblocker\n\nmodule HTTP;\n\nexport {\n redef enum Notice += {\n HTTP_IncorrectFileTypeBadHost\n };\n}\n\nredef notice_action_filters += {\n [HTTP_IncorrectFileTypeBadHost] = notice_exec_ipblocker_dest,\n};\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h))\n return;\n if(! (\"identified-files\" in si$tags && si$mime_type == \"application\/x-dosexec\"))\n return;\n\n if(\/co.cc\/ in si$host) {\n NOTICE([$note=HTTP_IncorrectFileTypeBadHost,\n $id=id,\n $msg=fmt(\"EXE Downloaded from bad host %s %s %s\", id$orig_h, id$resp_h, si$url),\n $sub=\"http-ext\"\n ]);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"887c933ff115b044eb27f022159c8e28bbaa1c36","subject":"Fix case typo for hassh","message":"Fix case typo for hassh\n\nFixes #22","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nmodule ROCK;\n\nexport {\n const sensor_id = gethostname() &redef;\n}\n\n#=== Bro built-ins ===================================\n\n# Enable VLAN Logging\n@load policy\/protocols\/conn\/vlan-logging\n\n# Log MAC addresses\n@load policy\/protocols\/conn\/mac-logging\n\n# Log (All) Client and Server HTTP Headers\n@load policy\/protocols\/http\/header-names\n\n#== ROCK specific scripts ============================\n# Add empty Intel framework database\n@load .\/frameworks\/intel\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n\n# Log all orig and resp cert hashes in ssl log\n@load .\/protocols\/ssl\/ssl-add-cert-hash\n\n# Enable pop3 logging\n@load .\/protocols\/pop3\n\n# Notice on all recently created certs\n# @load .\/protocols\/ssl\/new-certs\n\n# Generate log of all unique DNS queries with answers\n# @load .\/protocols\/dns\/known_domains\n\n# Generate log of all URLs seen in an SMTP body\n# @load .\/protocols\/smtp\/smtp-url\n\n# Generate log of local systems using unencrypted protocols\n# @load .\/frameworks\/compliance\/detect-insecure-protos\n\n#== 3rd Party Scripts =================================\n# Add Salesforce's JA3 SSL fingerprinting\n@load .\/misc\/ja3\n\n# Add Salesforce's HASSH SSH fingerprinting\n@load .\/misc\/hassh\n\n### Sensor specific scripts ######################\n\n# Configure AF_PACKET, if in use\n@load .\/plugins\/afpacket\n","old_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nmodule ROCK;\n\nexport {\n const sensor_id = gethostname() &redef;\n}\n\n#=== Bro built-ins ===================================\n\n# Enable VLAN Logging\n@load policy\/protocols\/conn\/vlan-logging\n\n# Log MAC addresses\n@load policy\/protocols\/conn\/mac-logging\n\n# Log (All) Client and Server HTTP Headers\n@load policy\/protocols\/http\/header-names\n\n#== ROCK specific scripts ============================\n# Add empty Intel framework database\n@load .\/frameworks\/intel\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n\n# Log all orig and resp cert hashes in ssl log\n@load .\/protocols\/ssl\/ssl-add-cert-hash\n\n# Enable pop3 logging\n@load .\/protocols\/pop3\n\n# Notice on all recently created certs\n# @load .\/protocols\/ssl\/new-certs\n\n# Generate log of all unique DNS queries with answers\n# @load .\/protocols\/dns\/known_domains\n\n# Generate log of all URLs seen in an SMTP body\n# @load .\/protocols\/smtp\/smtp-url\n\n# Generate log of local systems using unencrypted protocols\n# @load .\/frameworks\/compliance\/detect-insecure-protos\n\n#== 3rd Party Scripts =================================\n# Add Salesforce's JA3 SSL fingerprinting\n@load .\/misc\/ja3\n\n# Add Salesforce's HASSH SSH fingerprinting\n@load .\/misc\/HASSH\n\n### Sensor specific scripts ######################\n\n# Configure AF_PACKET, if in use\n@load .\/plugins\/afpacket\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"30398b04dcb66962a600da6615c04f77f7db9e28","subject":"Update detect-rogue-dns.bro","message":"Update detect-rogue-dns.bro\n\nUpdated year","repos":"theflakes\/cs-bro,kingtuna\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/dynamic\/detect-rogue-dns.bro","new_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/dynamic\/detect-rogue-dns.bro","new_contents":"# Detects a Hurricane Panda tactic of using Hurricane Electric to resolve commonly accessed websites\n# Alerts when a domain in the Alexa top 500 is resolved via Hurricane Electric and\/or when a host connects to an IP in the DNS response\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n}\n\n# File generated by scrape-alexa.py\nconst alexa_file = \".\/alexa_domains.txt\" &redef;\n# Table to store list of domains in file above\nglobal alexa_table: set[string];\n# Record for domains in file above\ntype alexa_idx: record {\n alexa: string;\n};\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\n# Pulls data from scrape-alexa.py output (alexa_file)\nevent bro_init()\n{\nInput::add_table([$source=alexa_file,\n $name=\"alexa_domains\",\n $idx=alexa_idx,\n $destination=alexa_table,\n $mode=Input::REREAD]);\n}\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n \n # Clean the sub-message\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"# Detects a Hurricane Panda tactic of using Hurricane Electric to resolve commonly accessed websites\n# Alerts when a domain in the Alexa top 500 is resolved via Hurricane Electric and\/or when a host connects to an IP in the DNS response\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n}\n\n# File generated by scrape-alexa.py\nconst alexa_file = \".\/alexa_domains.txt\" &redef;\n# Table to store list of domains in file above\nglobal alexa_table: set[string];\n# Record for domains in file above\ntype alexa_idx: record {\n alexa: string;\n};\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\n# Pulls data from scrape-alexa.py output (alexa_file)\nevent bro_init()\n{\nInput::add_table([$source=alexa_file,\n $name=\"alexa_domains\",\n $idx=alexa_idx,\n $destination=alexa_table,\n $mode=Input::REREAD]);\n}\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n \n # Clean the sub-message\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"d4ef0cea3291e247e425a6989113c49dceefe276","subject":"removing a print out","message":"removing a print out\n\n\nFormer-commit-id: c5c329659507683fca545726be63726edfe8953d","repos":"djtotten\/workbench,SuperCowPowers\/workbench,SuperCowPowers\/workbench,djtotten\/workbench,SuperCowPowers\/workbench,djtotten\/workbench","old_file":"server\/workers\/bro\/file_extensions\/extract_files.bro","new_file":"server\/workers\/bro\/file_extensions\/extract_files.bro","new_contents":"##! Extract exe, pdf, jar and cab files.\n\nglobal ext_map: table[string] of string = {\n [\"application\/x-dosexec\"] = \"exe\",\n [\"application\/pdf\"] = \"pdf\",\n [\"application\/zip\"] = \"zip\",\n [\"application\/jar\"] = \"jar\",\n [\"application\/vnd.ms-cab-compressed\"] = \"cab\",\n [\"text\/plain\"] = \"txt\",\n [\"image\/gif\"] = \"gif\",\n [\"image\/jpeg\"] = \"jpg\",\n [\"image\/png\"] = \"png\",\n [\"text\/html\"] = \"html\",\n [\"application\/vnd.ms-fontobject\"] = \"ms_font\",\n [\"application\/x-shockwave-flash\"] = \"swf\"\n} &default =\"unknown\";\n\nevent file_new(f: fa_file)\n {\n local ext = ext_map[f$mime_type];\n if (ext != \"txt\" && ext != \"html\" && ext != \"ms_font\" && ext != \"jpg\" && ext != \"gif\" && ext != \"png\")\n {\n local fname = fmt(\"%s-%s.%s\", f$source, f$id, ext);\n Files::add_analyzer(f, Files::ANALYZER_EXTRACT, [$extract_filename=fname]);\n }\n }","old_contents":"##! Extract exe, pdf, jar and cab files.\n\nglobal ext_map: table[string] of string = {\n [\"application\/x-dosexec\"] = \"exe\",\n [\"application\/pdf\"] = \"pdf\",\n [\"application\/zip\"] = \"zip\",\n [\"application\/jar\"] = \"jar\",\n [\"application\/vnd.ms-cab-compressed\"] = \"cab\",\n [\"text\/plain\"] = \"txt\",\n [\"image\/gif\"] = \"gif\",\n [\"image\/jpeg\"] = \"jpg\",\n [\"image\/png\"] = \"png\",\n [\"text\/html\"] = \"html\",\n [\"application\/vnd.ms-fontobject\"] = \"ms_font\",\n [\"application\/x-shockwave-flash\"] = \"swf\"\n} &default =\"unknown\";\n\nevent file_new(f: fa_file)\n {\n local ext = ext_map[f$mime_type];\n print f$mime_type, ext;\n if (ext != \"txt\" && ext != \"html\" && ext != \"ms_font\" && ext != \"jpg\" && ext != \"gif\" && ext != \"png\")\n {\n local fname = fmt(\"%s-%s.%s\", f$source, f$id, ext);\n Files::add_analyzer(f, Files::ANALYZER_EXTRACT, [$extract_filename=fname]);\n }\n }","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"a6a2cf56491ea705ce41561ef2e06573cbd0f214","subject":"watched_countries is defined under the SSH module","message":"watched_countries is defined under the SSH module\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext.bro","new_file":"ssh-ext.bro","new_contents":"@load global-ext\n@load ssh\n@load notice\n\t\nmodule SSH;\n\nexport {\n\tconst ssh_ext_log = open_log_file(\"ssh-ext\") &raw_output;\n\t\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\ttype ssh_versions: record {\n\t\tclient: string &default=\"\";\n\t\tserver: string &default=\"\";\n\t};\n\t\n\t# Only monitor SSH connections for up to 15 minutes\n\tglobal active_ssh_conns: table[conn_id] of ssh_versions &create_expire=15mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in SSH::watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\t\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal versions = active_ssh_conns[c$id];\n\tlocal status = \"failure\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $sub=location$country_code]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 20000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\t\t\n\tif ( (log_geodata_on_failure && status == \"failure\") ||\n\t status == \"success\" )\n\t\t{\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\t}\n\t\t\n\tprint ssh_ext_log, cat_sep(\"\\t\", \"\\\\N\", c$start_time,\n\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\tstatus, direction, \n\t\t\t\tlocation$country_code, location$region,\n\t\t\t\tversions$client, versions$server,\n\t\t\t\tc$resp$size);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +2mins { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_versions;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +2mins { ssh_watcher(c) }; \n\t\t}\n\t}\n","old_contents":"@load global-ext\n@load ssh\n@load notice\n\t\nmodule SSH;\n\nexport {\n\tconst ssh_ext_log = open_log_file(\"ssh-ext\") &raw_output;\n\t\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\ttype ssh_versions: record {\n\t\tclient: string &default=\"\";\n\t\tserver: string &default=\"\";\n\t};\n\t\n\t# Only monitor SSH connections for up to 15 minutes\n\tglobal active_ssh_conns: table[conn_id] of ssh_versions &create_expire=15mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\t\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal versions = active_ssh_conns[c$id];\n\tlocal status = \"failure\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $sub=location$country_code]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 20000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\t\t\n\tif ( (log_geodata_on_failure && status == \"failure\") ||\n\t status == \"success\" )\n\t\t{\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\t}\n\t\t\n\tprint ssh_ext_log, cat_sep(\"\\t\", \"\\\\N\", c$start_time,\n\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\tstatus, direction, \n\t\t\t\tlocation$country_code, location$region,\n\t\t\t\tversions$client, versions$server,\n\t\t\t\tc$resp$size);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +2mins { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_versions;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +2mins { ssh_watcher(c) }; \n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"65c467e8564b8588c5a25c1c7325b754385120b3","subject":"Bro module to extract HTTP Headers","message":"Bro module to extract HTTP Headers\n","repos":"Soinull\/assimilate,Soinull\/assimilate","old_file":"http-headers.bro","new_file":"http-headers.bro","new_contents":"module HTTP;\n\n# Original version credit to Mike Sconzo modified from https:\/\/github.com\/ClickSecurity\/data_hacking\/blob\/master\/browser_fingerprinting\/bro_scripts\/http-headers.bro\n# Modified to also keep track of the Bro session ID for easy cross reference of suspicious entries with other Bro logs\n\nexport {\n type header_info_record: record\n {\n ## Header name and value.\n name: string;\n value: string;\n };\n\n redef record Info += { header_info_vector: vector of header_info_record &optional; };\n}\n\n\nmodule HTTPHeaders;\n\nexport\n{\n redef enum Log::ID += { LOG };\n\n type Info: record\n {\n ts: time &log;\n uid: string &log;\n origin: string &log;\n identifier: string &log;\n header_events_kv: string &log;\n # header_events_json: string &log;\n };\n\n type header_info_record_type: record\n {\n ## Header name and value.\n name: string;\n value: string;\n };\n\n ## A type alias for a vector of header_info_records.\n type header_info_vector_type: vector of header_info_record_type;\n\n}\n\nredef record connection += {\n header_info_vector: header_info_vector_type &optional;\n};\n\nevent bro_init()\n{\n Log::create_stream(HTTPHeaders::LOG, [$columns=Info]);\n}\n\n# These events just init the vector, the whole http object gets wiped w\/each request\/reply\nevent http_request(c: connection, method: string, original_URI: string, unescaped_URI: string, version: string)\n {\n c$http$header_info_vector = vector();\n }\n\nevent http_reply(c: connection, version: string, code: count, reason: string)\n {\n c$http$header_info_vector = vector();\n }\n\nfunction sanitize_string(s: string): string\n{\n local sanitized: string;\n local escape_chars: string;\n # escape_chars = \"\\\\\\\/\\b\\f\\n\\r\\t\\\"\\:\\,\";\n escape_chars = \"\\\"\";\n\n sanitized = s;\n sanitized = to_string_literal(s);\n sanitized = subst_string(sanitized, \"\\\\x\", \"\\\\u00\"); # Replacing any hex escapes\n # sanitized = string_escape(sanitized, escape_chars);\n\n return sanitized;\n}\n\nfunction vector_to_kv_string(info_vector: header_info_vector_type): string\n{\n local kv_string: string;\n local key: string;\n local value: string;\n\n kv_string = \"\";\n for ( i in info_vector )\n {\n key = sanitize_string(info_vector[i]$name);\n value = sanitize_string(info_vector[i]$value);\n\n # Stubbing out Cookie for now\n if (key == \"COOKIE\") { value = \"-COOKIE-\"; }\n\n kv_string += \"\\\"\" + key + \"\\\"\" + \":\" + \"\\\"\" + value + \"\\\",\";\n }\n\n # Remove the last comma\n return cut_tail(kv_string, 1);\n}\n\nfunction vector_to_json_string(info_vector: header_info_vector_type): string\n{\n local json_string: string;\n local key: string;\n local value: string;\n\n json_string = \"[\";\n for ( i in info_vector )\n {\n key = sanitize_string(info_vector[i]$name);\n value = sanitize_string(info_vector[i]$value);\n\n # Stubbing out Cookie for now\n if (key == \"COOKIE\") { value = \"-COOKIE-\"; }\n\n json_string += \"{\\\"\" + key + \"\\\"\" + \":\" + \"\\\"\" + value + \"\\\"},\";\n }\n\n # Remove the last comma and add the closing bracket\n return cut_tail(json_string, 1) + \"]\";\n}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\n local header_record: HTTP::header_info_record;\n local vector_size: int;\n\n if ( ! c?$http || ! c$http?$header_info_vector )\n return;\n\n # Add this http header info to the vector\n header_record$name = name;\n header_record$value = value;\n\n # Get current size of vector and add the record to the end\n c$http$header_info_vector[|c$http$header_info_vector|] = header_record;\n}\n\nevent http_all_headers(c: connection, is_orig: bool, hlist: mime_header_list)\n{\n local my_log: Info;\n local origin: string;\n local identifier: string;\n # local event_json_string: string;\n local event_kv_string: string;\n\n # Is the header from a client request or server response\n if ( is_orig )\n origin = \"client\";\n else\n origin = \"server\";\n\n # If we don't have a header_info_vector than punt\n if ( ! c?$http || ! c$http?$header_info_vector )\n return;\n\n print c$http$header_info_vector;\n\n # At this point our c$header_info_vector should contain all the\n # name\/value pairs associated with the header, so will turn the\n # vector into a JSON string and add it to our log file.\n # event_json_string = vector_to_json_string(c$http$header_info_vector);\n event_kv_string = vector_to_kv_string(c$http$header_info_vector);\n\n # Okay now set the user agent field\n identifier = \"NOTPRESENT\";\n for ( i in hlist )\n {\n if ( origin == \"client\" )\n if ( hlist[i]$name == \"USER-AGENT\" ){identifier = hlist[i]$value;}\n if ( origin == \"server\" )\n if ( hlist[i]$name == \"SERVER\" ){identifier = hlist[i]$value;}\n }\n\n # Now add all the info and the event list to the log\n my_log = [$ts=c$start_time,\n $uid=c$uid,\n $origin=fmt(\"%s\", origin),\n $identifier=fmt(\"%s\", identifier),\n $header_events_kv=fmt(\"%s\", event_kv_string)];\n\n # $header_events_kv=fmt(\"%s\", event_kv_string),\n # $header_events_json=fmt(\"%s\", event_json_string)];\n\n Log::write(HTTPHeaders::LOG, my_log);\n}\n","old_contents":"module HTTP;\n\n# Original version credit to Mike Sconzo modified from https:\/\/github.com\/ClickSecurity\/data_hacking\/blob\/master\/browser_fingerprinting\/bro_scripts\/http-headers.bro\n\nexport {\n type header_info_record: record\n {\n ## Header name and value.\n name: string;\n value: string;\n };\n\n redef record Info += { header_info_vector: vector of header_info_record &optional; };\n}\n\n\nmodule HTTPHeaders;\n\nexport\n{\n redef enum Log::ID += { LOG };\n\n type Info: record\n {\n ts: time &log;\n uid: string &log;\n origin: string &log;\n identifier: string &log;\n header_events_kv: string &log;\n # header_events_json: string &log;\n };\n\n type header_info_record_type: record\n {\n ## Header name and value.\n name: string;\n value: string;\n };\n\n ## A type alias for a vector of header_info_records.\n type header_info_vector_type: vector of header_info_record_type;\n\n}\n\nredef record connection += {\n header_info_vector: header_info_vector_type &optional;\n};\n\nevent bro_init()\n{\n Log::create_stream(HTTPHeaders::LOG, [$columns=Info]);\n}\n\n# These events just init the vector, the whole http object gets wiped w\/each request\/reply\nevent http_request(c: connection, method: string, original_URI: string, unescaped_URI: string, version: string)\n {\n c$http$header_info_vector = vector();\n }\n\nevent http_reply(c: connection, version: string, code: count, reason: string)\n {\n c$http$header_info_vector = vector();\n }\n\nfunction sanitize_string(s: string): string\n{\n local sanitized: string;\n local escape_chars: string;\n # escape_chars = \"\\\\\\\/\\b\\f\\n\\r\\t\\\"\\:\\,\";\n escape_chars = \"\\\"\";\n\n sanitized = s;\n sanitized = to_string_literal(s);\n sanitized = subst_string(sanitized, \"\\\\x\", \"\\\\u00\"); # Replacing any hex escapes\n # sanitized = string_escape(sanitized, escape_chars);\n\n return sanitized;\n}\n\nfunction vector_to_kv_string(info_vector: header_info_vector_type): string\n{\n local kv_string: string;\n local key: string;\n local value: string;\n\n kv_string = \"\";\n for ( i in info_vector )\n {\n key = sanitize_string(info_vector[i]$name);\n value = sanitize_string(info_vector[i]$value);\n\n # Stubbing out Cookie for now\n if (key == \"COOKIE\") { value = \"-COOKIE-\"; }\n\n kv_string += \"\\\"\" + key + \"\\\"\" + \":\" + \"\\\"\" + value + \"\\\",\";\n }\n\n # Remove the last comma\n return cut_tail(kv_string, 1);\n}\n\nfunction vector_to_json_string(info_vector: header_info_vector_type): string\n{\n local json_string: string;\n local key: string;\n local value: string;\n\n json_string = \"[\";\n for ( i in info_vector )\n {\n key = sanitize_string(info_vector[i]$name);\n value = sanitize_string(info_vector[i]$value);\n\n # Stubbing out Cookie for now\n if (key == \"COOKIE\") { value = \"-COOKIE-\"; }\n\n json_string += \"{\\\"\" + key + \"\\\"\" + \":\" + \"\\\"\" + value + \"\\\"},\";\n }\n\n # Remove the last comma and add the closing bracket\n return cut_tail(json_string, 1) + \"]\";\n}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\n local header_record: HTTP::header_info_record;\n local vector_size: int;\n\n if ( ! c?$http || ! c$http?$header_info_vector )\n return;\n\n # Add this http header info to the vector\n header_record$name = name;\n header_record$value = value;\n\n # Get current size of vector and add the record to the end\n c$http$header_info_vector[|c$http$header_info_vector|] = header_record;\n}\n\nevent http_all_headers(c: connection, is_orig: bool, hlist: mime_header_list)\n{\n local my_log: Info;\n local origin: string;\n local identifier: string;\n # local event_json_string: string;\n local event_kv_string: string;\n\n # Is the header from a client request or server response\n if ( is_orig )\n origin = \"client\";\n else\n origin = \"server\";\n\n # If we don't have a header_info_vector than punt\n if ( ! c?$http || ! c$http?$header_info_vector )\n return;\n\n print c$http$header_info_vector;\n\n # At this point our c$header_info_vector should contain all the\n # name\/value pairs associated with the header, so will turn the\n # vector into a JSON string and add it to our log file.\n # event_json_string = vector_to_json_string(c$http$header_info_vector);\n event_kv_string = vector_to_kv_string(c$http$header_info_vector);\n\n # Okay now set the user agent field\n identifier = \"NOTPRESENT\";\n for ( i in hlist )\n {\n if ( origin == \"client\" )\n if ( hlist[i]$name == \"USER-AGENT\" ){identifier = hlist[i]$value;}\n if ( origin == \"server\" )\n if ( hlist[i]$name == \"SERVER\" ){identifier = hlist[i]$value;}\n }\n\n # Now add all the info and the event list to the log\n my_log = [$ts=c$start_time,\n $uid=c$uid,\n $origin=fmt(\"%s\", origin),\n $identifier=fmt(\"%s\", identifier),\n $header_events_kv=fmt(\"%s\", event_kv_string)];\n\n # $header_events_kv=fmt(\"%s\", event_kv_string),\n # $header_events_json=fmt(\"%s\", event_json_string)];\n\n Log::write(HTTPHeaders::LOG, my_log);\n}\n","returncode":0,"stderr":"","license":"apache-2.0","lang":"Bro"} {"commit":"b56900c7bb436a5257080e988a6055577ff4174d","subject":"Adding the SMTP rejected connections counting.","message":"Adding the SMTP rejected connections counting.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n recipients: string;\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id];\n local blarg: set[conn_id];\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg, $recipients=\"\"];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n if( foo$recipients == \"\" )\n {\n foo$recipients = session$recipients;\n } else if (session$recipients != \"\") {\n foo$recipients = cat(foo$recipients, \",\", session$recipients);\n }\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"%s is rejecting a high percentage of mail\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent mailto: %s\", foo$total, percent, foo$recipients), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif","old_contents":"","returncode":1,"stderr":"error: pathspec 'smtp-ext-count-rejects.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"4d590ccb1490fc5bf967f1c0f10083b2ff25758e","subject":"updating the scan_cmd to also include the python keyword--this addresses edge cases where the shell wasn't handling the shebang properly","message":"updating the scan_cmd to also include the python keyword--this addresses edge cases where the shell wasn't handling the shebang properly\n","repos":"mocyber\/rock-scripts","old_file":"frameworks\/files\/extract2fsf.bro","new_file":"frameworks\/files\/extract2fsf.bro","new_contents":"# knifehands\n# take extracted files and submit to FSF\n \nevent file_state_remove(f: fa_file)\n {\n if ( f$info?$extracted )\n {\n # invoke the FSF-CLIENT and add the source metadata of ROCK01 (sensorID), we're suppressing the returned report\n # becuase we don't need that\n local script_path = cat(@DIR, \"\/fsf-client\/fsf_client.py\");\n\t local scan_cmd = fmt(\"python %s --suppress-report --archive none --source %s %s%s\", script_path, ROCK::sensor_id, FileExtract::prefix, f$info$extracted);\n system(scan_cmd);\n }\n}\n","old_contents":"# knifehands\n# take extracted files and submit to FSF\n \nevent file_state_remove(f: fa_file)\n {\n if ( f$info?$extracted )\n {\n # invoke the FSF-CLIENT and add the source metadata of ROCK01 (sensorID), we're suppressing the returned report\n # becuase we don't need that\n local script_path = cat(@DIR, \"\/fsf-client\/fsf_client.py\");\n local scan_cmd = fmt(\"%s --suppress-report --archive none --source %s %s\/%s\", script_path, ROCK::sensor_id, FileExtract::prefix, f$info$extracted);\n system(scan_cmd);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"d3946942659d0c2f06df3c74560555b6c73ad956","subject":"include auxiliary information in the ssh notices for client version and country code","message":"include auxiliary information in the ssh notices for client version and country code\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext.bro","new_file":"ssh-ext.bro","new_contents":"@load global-ext\n@load ssh\n@load notice\n\ntype ssh_ext_session_info: record {\n\tstart_time: time;\n\tclient: string &default=\"\";\n\tserver: string &default=\"\";\n\tlocation: geo_location;\n\tstatus: string &default=\"\";\n\tdirection: string &default=\"\";\n\tresp_size: count &default=0;\n};\n\n# Define the generic ssh-ext event that can be handled from other scripts\nglobal ssh_ext: event(id: conn_id, si: ssh_ext_session_info);\n\nmodule SSH;\n\nexport {\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of track_count \n\t\t&default=default_track_count\n\t\t&write_expire=guessing_timeout;\n\t\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\t# The list of active SSH connections and the associated session info.\n\tglobal active_ssh_conns: table[conn_id] of ssh_ext_session_info &read_expire=2mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$aux[\"country\"] in SSH::watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a successful ssh login happens from a strange client version\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && \/lib\/ in n$aux[\"client\"]); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\n\tlocal ssh_conn = active_ssh_conns[c$id];\n\tlocal status = \"failure\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\t\tif ( log_geodata_on_failure )\n\t\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\n\t\tif ( c$id$orig_h !in password_rejections )\n\t\t\tpassword_rejections[c$id$orig_h] = default_track_count(c$id$orig_h);\n\t\t\t\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\t++password_rejections[c$id$orig_h]$n;\n\n\t\tif ( default_check_threshold(password_rejections[c$id$orig_h]) )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]$n),\n\t\t\t $aux=table([\"client\"]=ssh_conn$client, [\"country\"]=location$country_code),\n\t\t\t $n=password_rejections[c$id$orig_h]$n]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\n\t\tif ( password_rejections[c$id$orig_h]$n > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h]$n,\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $aux=table([\"client\"]=ssh_conn$client, [\"country\"]=location$country_code),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]$n)]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $aux=table([\"client\"]=ssh_conn$client, [\"country\"]=location$country_code)]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $aux=table([\"client\"]=ssh_conn$client, [\"country\"]=location$country_code),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 200000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\n\tssh_conn$start_time = c$start_time;\n\tssh_conn$location = location;\n\tssh_conn$status = status;\n\tssh_conn$direction = direction;\n\tssh_conn$resp_size = c$resp$size;\n\t\n\tevent ssh_ext(c$id, ssh_conn);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +15secs { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_ext_session_info;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +15secs { ssh_watcher(c) }; \n\t\t}\n\t}\n","old_contents":"@load global-ext\n@load ssh\n@load notice\n\ntype ssh_ext_session_info: record {\n\tstart_time: time;\n\tclient: string &default=\"\";\n\tserver: string &default=\"\";\n\tlocation: geo_location;\n\tstatus: string &default=\"\";\n\tdirection: string &default=\"\";\n\tresp_size: count &default=0;\n};\n\n# Define the generic ssh-ext event that can be handled from other scripts\nglobal ssh_ext: event(id: conn_id, si: ssh_ext_session_info);\n\nmodule SSH;\n\nexport {\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of track_count \n\t\t&default=default_track_count\n\t\t&write_expire=guessing_timeout;\n\t\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\t# The list of active SSH connections and the associated session info.\n\tglobal active_ssh_conns: table[conn_id] of ssh_ext_session_info &read_expire=2mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in SSH::watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\n\tlocal ssh_conn = active_ssh_conns[c$id];\n\tlocal status = \"failure\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\t\tif ( log_geodata_on_failure )\n\t\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\n\t\tif ( c$id$orig_h !in password_rejections )\n\t\t\tpassword_rejections[c$id$orig_h] = default_track_count(c$id$orig_h);\n\t\t\t\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\t++password_rejections[c$id$orig_h]$n;\n\n\t\tif ( default_check_threshold(password_rejections[c$id$orig_h]) )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]$n),\n\t\t\t $n=password_rejections[c$id$orig_h]$n]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\n\t\tif ( password_rejections[c$id$orig_h]$n > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h]$n,\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]$n)]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $sub=location$country_code]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 200000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\n\tssh_conn$start_time = c$start_time;\n\tssh_conn$location = location;\n\tssh_conn$status = status;\n\tssh_conn$direction = direction;\n\tssh_conn$resp_size = c$resp$size;\n\t\n\tevent ssh_ext(c$id, ssh_conn);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +15secs { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_ext_session_info;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +15secs { ssh_watcher(c) }; \n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"2beb15255faf8d4ee6ad18e2d033eb959445095b","subject":"add load.php to regex","message":"add load.php to regex\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-block-exe-hosts.bro","new_file":"http-ext-block-exe-hosts.bro","new_contents":"@load http-ext\n@load ipblocker\n\nmodule HTTP;\n\nexport {\n redef enum Notice += {\n HTTP_IncorrectFileTypeBadHost\n };\n\n const bad_exec_domains = \n \/co\\.cc\/\n | \/cx\\.cc\/\n | \/cz\\.cc\/\n &redef;\n\n const bad_exec_urls = \n \/php.adv=\/\n | \/http:\\\/\\\/[0-9]{1,3}\\.[0-9]{1,3}.*\\\/index\\.php\\?[^=]+=[^=]+$\/ #try to match http:\/\/1.2.3.4\/index.php?foo=bar\n | \/load.php\/\n &redef;\n\n const bad_user_agents = \n \/Java\\\/1\/\n &redef;\n\n}\n\nredef notice_action_filters += {\n [HTTP_IncorrectFileTypeBadHost] = notice_exec_ipblocker_dest,\n};\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h))\n return;\n if(! (\"identified-files\" in si$tags && si$mime_type == \"application\/x-dosexec\"))\n return;\n\n if( (bad_exec_domains in si$host || bad_exec_urls in si$url)\n ||(\/\\.exe\/ !in si$url && bad_user_agents in si$user_agent)) {\n NOTICE([$note=HTTP_IncorrectFileTypeBadHost,\n $id=id,\n $msg=fmt(\"EXE Downloaded from bad host %s %s %s\", id$orig_h, id$resp_h, si$url),\n $sub=\"http-ext\"\n ]);\n }\n}\n","old_contents":"@load http-ext\n@load ipblocker\n\nmodule HTTP;\n\nexport {\n redef enum Notice += {\n HTTP_IncorrectFileTypeBadHost\n };\n\n const bad_exec_domains = \n \/co\\.cc\/\n | \/cx\\.cc\/\n | \/cz\\.cc\/\n &redef;\n\n const bad_exec_urls = \n \/php.adv=\/\n | \/http:\\\/\\\/[0-9]{1,3}\\.[0-9]{1,3}.*\\\/index\\.php\\?[^=]+=[^=]+$\/ #try to match http:\/\/1.2.3.4\/index.php?foo=bar\n &redef;\n\n const bad_user_agents = \n \/Java\\\/1\/\n &redef;\n\n}\n\nredef notice_action_filters += {\n [HTTP_IncorrectFileTypeBadHost] = notice_exec_ipblocker_dest,\n};\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h))\n return;\n if(! (\"identified-files\" in si$tags && si$mime_type == \"application\/x-dosexec\"))\n return;\n\n if( (bad_exec_domains in si$host || bad_exec_urls in si$url)\n ||(\/\\.exe\/ !in si$url && bad_user_agents in si$user_agent)) {\n NOTICE([$note=HTTP_IncorrectFileTypeBadHost,\n $id=id,\n $msg=fmt(\"EXE Downloaded from bad host %s %s %s\", id$orig_h, id$resp_h, si$url),\n $sub=\"http-ext\"\n ]);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"083ecdfcf5adddbd60a5e7e9b0083b620e8c39f0","subject":"maintain a list of known external sites","message":"maintain a list of known external sites\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-external-names.bro","new_file":"http-ext-external-names.bro","new_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)example\\.com($|:)\/ &redef;\n\n # in site policy, redef HTTP::ignore_external_addr += {1.2.3.4};\n # redef HTTP::ignore_external_host += {\"www.foo.com\"};\n\n\n global ignore_external_addr: set[addr] &redef;\n global ignore_external_host: set[string] &redef;\n\n #maybe this should be two tables for mapping addr -> string and string -> addr?\n global external_names: set[addr, string] &create_expire=1day &synchronized &persistent;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(id$resp_h in ignore_external_addr || si$host in ignore_external_host)\n return;\n\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n\n if([id$resp_h, si$host] !in external_names)\n add external_names[id$resp_h, si$host];\n }\n}\n","old_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)example\\.com($|:)\/ &redef;\n\n # in site policy, redef HTTP::ignore_external_addr += {1.2.3.4};\n # redef HTTP::ignore_external_host += {\"www.foo.com\"};\n\n\n global ignore_external_addr: set[addr] &redef;\n global ignore_external_host: set[string] &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(id$resp_h in ignore_external_addr || si$host in ignore_external_host)\n return;\n\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"7de1d5e1d7b7c22d74c05afb6025c413b2d48805","subject":"apparently I do need a priority","message":"apparently I do need a priority\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-external-names.bro","new_file":"http-ext-external-names.bro","new_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)albany\\.edu($|:)\/ &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","old_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)albany\\.edu($|:)\/ &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info)\n{\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"812bad146f5ba98aefcba2f050e65ed6bcc57840","subject":"WIP: start rebalance feature","message":"WIP: start rebalance feature\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_receiver.bro","new_file":"scripts_master\/bro_receiver.bro","new_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n log_bro(\"Bro Master log access event!\");\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n log_bro(\"Bro Master log mysql event!\");\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n local inc: string = \"Incoming connection extablished \" + peer_name;\n log_bro(inc);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local inc: string = \"Incoming connection broken for \" + peer_name;\n log_bro(inc);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Registering new slave \" + peer_name);\n slaves[peer_name] = 0;\n local total_slaves = |slaves|;\n local total_connectors = 0;\n local slave_table = vector of string;\n local i = 0;\n for (slave in slaves) {\n total_connectors += slaves[slave];\n slave_table[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_table = vector of string;\n while (i < total_connectors) {\n connector_table[i] = Broker::vector_lookup(keys$result, i);\n }\n\n print \"Starting add slave to balance:\";\n print \"total_slaves\", total_slaves, \"total_connectors\", total_connectors;\n while (total_slaves > 0) {\n local balance_amount = balance_amount = total_connectors; \n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n total_connectors -= balance_amount;\n print \"total_slaves\", total_slaves, \"total_connectors\", total_connectors;\n # TODO: set balanceamount as value for one slave\n # TODO: set for all those connectors that one slave\n }\n\n }\n timeout 100msec {\n print \"aww\"; \n }\n \n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Registering new connector \" + peer_name);\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n local size = |slaves|;\n\n if (size <= 0) {\n log_bro(\"No slaves are registered, cannot register connector \" + peer_name);\n print \"should return\";\n return;\n }\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n if (best_slave != \"\") {\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not register connector \", peer_name;\n log_bro(\"Could not register connector \" + peer_name);\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Unregistering old slave \" + peer_name);\n delete slaves[peer_name];\n # TODO rebalance\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n }\n Broker::erase(connectors, Broker::data(peer_name));\n print \"Unregistered old connector\", peer_name, \"leaving slave table\", slaves;\n log_bro(\"Unregistered old connector \" + peer_name);\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}","old_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n log_bro(\"Bro Master log access event!\");\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n log_bro(\"Bro Master log mysql event!\");\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n local inc: string = \"Incoming connection extablished \" + peer_name;\n log_bro(inc);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local inc: string = \"Incoming connection broken for \" + peer_name;\n log_bro(inc);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Registering new slave \" + peer_name);\n slaves[peer_name] = 0;\n # TODO realance clients to this new slave\n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Registering new connector \" + peer_name);\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n local size = |slaves|;\n\n if (size <= 0) {\n log_bro(\"No slaves are registered, cannot register connector \" + peer_name);\n print \"should return\";\n return;\n }\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n \n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n if (best_slave != \"\") {\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not register connector \", peer_name;\n log_bro(\"Could not register connector \" + peer_name);\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Unregistering old slave \" + peer_name);\n delete slaves[peer_name];\n # TODO rebalance\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n }\n Broker::erase(connectors, Broker::data(peer_name));\n print \"Unregistered old connector\", peer_name, \"leaving slave table\", slaves;\n log_bro(\"Unregistered old connector \" + peer_name);\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"2c393110d041c328a82c58b4d48273b0410631ee","subject":"include the subject in the SMTP_PossiblePWPhishReply notice","message":"include the subject in the SMTP_PossiblePWPhishReply notice\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-phish-passwords.bro","new_file":"smtp-ext-phish-passwords.bro","new_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &create_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s - %s\", si$mailfrom, to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n if(++(phishing_counter[si$mailfrom]) > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","old_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &create_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s\", si$mailfrom, to),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n if(++(phishing_counter[si$mailfrom]) > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"7c3899f6db72e5390d68fcc43c2acdc289dac538","subject":"Update detect-rogue-dns.bro","message":"Update detect-rogue-dns.bro\n\nMoved alexa_file to export","repos":"CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,theflakes\/cs-bro,kingtuna\/cs-bro","old_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/dynamic\/detect-rogue-dns.bro","new_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/dynamic\/detect-rogue-dns.bro","new_contents":"# Detects a Hurricane Panda tactic of using Hurricane Electric to resolve commonly accessed websites\n# Alerts when a domain in the Alexa top 500 is resolved via Hurricane Electric and\/or when a host connects to an IP in the DNS response\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n \n # File generated by scrape-alexa.py\n const alexa_file = \".\/alexa_domains.txt\" &redef;\n}\n\n# Table to store list of domains in file above\nglobal alexa_table: set[string];\n# Record for domains in file above\ntype alexa_idx: record {\n alexa: string;\n};\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\n# Pulls data from scrape-alexa.py output (alexa_file)\nevent bro_init()\n{\nInput::add_table([$source=alexa_file,\n $name=\"alexa_domains\",\n $idx=alexa_idx,\n $destination=alexa_table,\n $mode=Input::REREAD]);\n}\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n \n # Clean the sub-message\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"# Detects a Hurricane Panda tactic of using Hurricane Electric to resolve commonly accessed websites\n# Alerts when a domain in the Alexa top 500 is resolved via Hurricane Electric and\/or when a host connects to an IP in the DNS response\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n}\n\n# File generated by scrape-alexa.py\nconst alexa_file = \".\/alexa_domains.txt\" &redef;\n# Table to store list of domains in file above\nglobal alexa_table: set[string];\n# Record for domains in file above\ntype alexa_idx: record {\n alexa: string;\n};\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\n# Pulls data from scrape-alexa.py output (alexa_file)\nevent bro_init()\n{\nInput::add_table([$source=alexa_file,\n $name=\"alexa_domains\",\n $idx=alexa_idx,\n $destination=alexa_table,\n $mode=Input::REREAD]);\n}\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n \n # Clean the sub-message\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"ec7e4dc627026fc92640eb6373873b039d769726","subject":"Create detect-rfd.bro","message":"Create detect-rfd.bro","repos":"CrowdStrike\/cs-bro,theflakes\/cs-bro,albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro","old_file":"bro-scripts\/rfd\/detect-rfd.bro","new_file":"bro-scripts\/rfd\/detect-rfd.bro","new_contents":"# Detect reflected file download attacks as described in \n# http:\/\/packetstorm.foofus.com\/papers\/presentations\/eu-14-Hafif-Reflected-File-Download-A-New-Web-Attack-Vector.pdf\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Reflected_File_Download\n };\n\n redef enum HTTP::Tags += {\n RFD\n };\n}\n\nconst rfd_content_type: set[string] = {\n \"application\/json\",\n \"application\/x-javascript\",\n \"application\/javascript\",\n \"application\/notexist\",\n \"text\/json\",\n \"text\/x-javascript\",\n \"text\/plain\",\n \"text\/notexist\",\n \"application\/xml\",\n \"text\/xml\",\n \"text\/html\"\n} &redef;\n\nconst rfd_pattern = \/\\\"\\|\\|\/ |\n \/\\\"\\<\\<\/ |\n \/\\\"\\>\\>\/ |\n \/[^?]*\\.bat(\\;|$)\/ |\n \/[^?]*\\.cmd(\\;|$)\/ |\n \/[^?]*[Ss][Ee][Tt][Uu][Pp][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/[^?]*[Ii][nn][Ss][Tt][Aa][Ll][Ll][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/[^?]*[Uu][Pp][Dd][Aa][Tt][Ee][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/[^?]*[Uu][Nn][In][Ss][Tt][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ &redef;\n\n\n# Perform a pattern match for reflected file downloads.\n# If found, add HTTP tag and generate a notice.\nfunction rfd_do_notice(c: connection)\n{\nif ( rfd_pattern in c$http$uri )\n {\n add c$http$tags[RFD];\n NOTICE([$note=Reflected_File_Download,\n $msg=\"A reflected file download was attempted\",\n $sub=c$http$uri,\n $id=c$id,\n $identifier=cat(c$id$orig_h,c$id$resp_h,c$http$uri)]);\n }\n}\n\n# Check for reflected file downloads in HTTP transactions that have a \n# CONTENT-TYPE header. Valid RFD content types are identified anywhere\n# in the CONTENT-TYPE header value.\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nif ( name == \"CONTENT-TYPE\" )\n for ( rct in rfd_content_type )\n if ( rct in value )\n rfd_do_notice(c);\n}\n\n# Check for reflected file downloads in HTTP transactions that do not have a \n# CONTENT-TYPE header.\nevent http_all_headers(c: connection, is_orig: bool, hlist: mime_header_list)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nlocal headers: set[string];\n\nfor ( h in hlist )\n {\n local name = hlist[h]$name;\n add headers[name];\n }\n\nif ( \"CONTENT-TYPE\" !in headers ) \n rfd_do_notice(c);\nelse return;\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/rfd\/detect-rfd.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"91d8b1c62c77f3dd6c15e45a42d727ffade2af6b","subject":"fixed log path","message":"fixed log path\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/acu_result.bro","new_file":"scripts_master\/acu_result.bro","new_contents":"module Acu_result;\n\nexport{\n redef enum Log::ID += { LOG };\n redef LogAscii::empty_field = \"EMPTY\";\n \n type Info: record {\n ts: time &log;\n attack: string &log;\n };\n}\n\nevent bro_init() &priority=5 {\n Log::create_stream(Acu_result::LOG, [$columns=Info, $path=\"acu_result\"]);\n}\n","old_contents":"module Acu_result;\n\nexport{\n redef enum Log::ID += { LOG };\n redef LogAscii::empty_field = \"EMPTY\";\n \n type Info: record {\n ts: time &log;\n attack: string &log;\n };\n}\n\nevent bro_init() &priority=5 {\n Log::create_stream(Acu_result::LOG, [$columns=Info, $path=\"master\"]);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"1b7022f70a2fa9f0a55023f27c741c0d7e82f6c4","subject":"Mostly just style and naming changes here.","message":"Mostly just style and naming changes here.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For the SMTP_StrangeRejectBehavior notice to work, you must define a \n# local_mail table listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n\trejects: count;\n\ttotal: count;\n};\n\nexport {\n\t# The idea for this is that if a host makes more than spam_threshold \n\t# smtp connections per hour of which at least spam_percent of those are\n\t# rejected and the host is not a known mail sending host, then it's likely \n\t# sending spam or viruses.\n\t#\n\tconst spam_threshold = 300 &redef;\n\tconst spam_percent = 30 &redef;\n\t\n\t# These are smtp status codes that are considered \"rejected\".\n\tconst smtp_reject_codes: set[count] = {\n\t\t501, # Bad sender address syntax\n\t\t550, # Requested action not taken: mailbox unavailable\n\t\t551, # User not local; please try \n\t\t553, # Requested action not taken: mailbox name not allowed\n\t\t554, # Transaction failed\n\t};\n\t\n\tredef enum Notice += {\n\t\tSMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n\t\tSMTP_PossibleInternalSpam, # Internal host seems to be spamming\n\t\tSMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n\t};\n\t\n\t# This variable keeps track of the number of rejected and accepted \n\t# RCPT TO's a host is doing and receiving per hour.\n\tglobal reject_counter: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tif ( c$id$orig_h !in reject_counter ) \n\t\treject_counter[c$id$orig_h] = [$rejects=0, $total=0];\n\t\n\t# Set the smtp_counter to the local var \"foo\"\n\tlocal foo = reject_counter[c$id$orig_h];\n\t\n\tif ( code in smtp_reject_codes)\n\t\t++foo$rejects;\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in cmd )\n\t\t++foo$total;\n\t\n\tlocal host = c$id$orig_h;\n\tif ( foo$total >= spam_threshold ) \n\t\t{\n\t\tlocal percent = (foo$rejects*100) \/ foo$total;\n\t\tif ( percent >= spam_percent ) \n\t\t\t{\n@ifdef ( local_mail )\n\t\t\tif ( host in local_mail )\n\t\t\t\tNOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n\t\t\telse \n@endif\n\t\t\tif ( is_local_addr(host) ) \n\t\t\t\tNOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n\t\t\telse \n\t\t\t\tNOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n\t\t\t}\n\t\t}\n\t}","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes)\n ++foo$rejects;\n\n if ( \/^([hH]|[eE]){2}[lL][oO]\/ in cmd )\n ++foo$total;\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"18f1547fc9f6fb9f06ab4185734436a70989b4bf","subject":"Fix performance and behavior issues.","message":"Fix performance and behavior issues.\n\nThe connpolling timeout wasn't being set correctly to end polling\nfor connections that lived long enough to go beyond the defined \"long\"\nintervals.\n\nThere was a state tracking table for the currently watched offset that\nwasn't being cleaned up. This was fixed by becoming a field in the\nconnection.\n","repos":"corelight\/bro-long-connections","old_file":"scripts\/main.bro","new_file":"scripts\/main.bro","new_contents":"@load base\/protocols\/conn\n@load base\/utils\/time\n\n\n# This is probably not so great to reach into the Conn namespace..\nmodule Conn;\n\nexport {\nfunction set_conn_log_data_hack(c: connection)\n\t{\n\tConn::set_conn(c, T);\n\t}\n}\n\n# Now onto the actual code for this script...\n\nmodule LongConnection;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += {\n\t\t## Notice for when a long connection is found.\n\t\t## The `sub` field in the notice represents the number\n\t\t## of seconds the connection has currently been alive.\n\t\tLongConnection::found\n\t};\n\n\t## Aliasing vector of interval values as\n\t## \"Durations\"\n\ttype Durations: vector of interval;\n\n\t## The default duration that you are locally \n\t## considering a connection to be \"long\". \n\tconst default_durations = Durations(10min, 30min, 1hr, 12hr, 24hrs, 3days) &redef;\n\n\t## These are special cases for particular hosts or subnets\n\t## that you may want to watch for longer or shorter\n\t## durations than the default.\n\tconst special_cases: table[subnet] of Durations = {} &redef;\n}\n\nredef record connection += {\n\t## Offset of the currently watched connection duration by the long-connections script.\n\tlong_conn_offset: count &default=0;\n};\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(LOG, [$columns=Conn::Info, $path=\"conn_long\"]);\n\t}\n\nfunction get_durations(c: connection): Durations\n\t{\n\tlocal check_it: Durations;\n\tif ( c$id$orig_h in special_cases )\n\t\tcheck_it = special_cases[c$id$orig_h];\n\telse if ( c$id$resp_h in special_cases )\n\t\tcheck_it = special_cases[c$id$resp_h];\n\telse\n\t\tcheck_it = default_durations;\n\n\treturn check_it;\n\t}\n\nfunction long_callback(c: connection, cnt: count): interval\n\t{\n\tlocal check_it = get_durations(c);\n\n\tif ( c$long_conn_offset < |check_it| && c$duration >= check_it[c$long_conn_offset] )\n\t\t{\n\t\tConn::set_conn_log_data_hack(c);\n\t\tLog::write(LongConnection::LOG, c$conn);\n\n\t\tlocal message = fmt(\"%s -> %s:%s remained alive for longer than %s\", \n\t\t c$id$orig_h, c$id$resp_h, c$id$resp_p, duration_to_mins_secs(c$duration));\n\t\tNOTICE([$note=LongConnection::found,\n\t\t $msg=message,\n\t\t $sub=fmt(\"%.2f\", c$duration),\n\t\t $conn=c]);\n\t\t\n\t\t++c$long_conn_offset;\n\t\t}\n\n\t# Keep watching if there are potentially more thresholds.\n\tif ( c$long_conn_offset < |check_it| )\n\t\treturn check_it[c$long_conn_offset];\n\telse\n\t\treturn -1sec;\n\t}\n\nevent connection_established(c: connection)\n\t{\n\tlocal check = get_durations(c);\n\tif ( |check| > 0 )\n\t\t{\n\t\tConnPolling::watch(c, long_callback, 1, check[0]);\n\t\t}\n\t}\n","old_contents":"@load base\/protocols\/conn\n@load base\/utils\/time\n\n\n# This is probably not so great to reach into the Conn namespace..\nmodule Conn;\n\nexport {\nfunction set_conn_log_data_hack(c: connection)\n\t{\n\tConn::set_conn(c, T);\n\t}\n}\n\n# Now onto the actual code for this script...\n\nmodule LongConnection;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += {\n\t\t## Notice for when a long connection is found.\n\t\t## The `sub` field in the notice represents the number\n\t\t## of seconds the connection has currently been alive.\n\t\tLongConnection::found\n\t};\n\n\t## Aliasing vector of interval values as\n\t## \"Durations\"\n\ttype Durations: vector of interval;\n\n\t## The default duration that you are locally \n\t## considering a connection to be \"long\". \n\tconst default_durations = Durations(10min, 30min, 1hr, 12hr, 24hrs, 3days) &redef;\n\n\t## These are special cases for particular hosts or subnets\n\t## that you may want to watch for longer or shorter\n\t## durations than the default.\n\tconst special_cases: table[subnet] of Durations = {} &redef;\n}\n\n# The yield value on this is the current offset into the\n# Durations value.\nglobal tracking_conns: table[string] of count &default=0;\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(LOG, [$columns=Conn::Info, $path=\"conn_long\"]);\n\t}\n\nfunction get_durations(c: connection): Durations\n\t{\n\tlocal check_it: Durations;\n\tif ( c$id$orig_h in special_cases )\n\t\tcheck_it = special_cases[c$id$orig_h];\n\telse if ( c$id$resp_h in special_cases )\n\t\tcheck_it = special_cases[c$id$resp_h];\n\telse\n\t\tcheck_it = default_durations;\n\n\treturn check_it;\n\t}\n\nfunction long_callback(c: connection, cnt: count): interval\n\t{\n\tlocal check_it = get_durations(c);\n\tlocal offset = tracking_conns[c$uid];\n\n\tif ( offset < |check_it| && c$duration >= check_it[offset] )\n\t\t{\n\t\tConn::set_conn_log_data_hack(c);\n\t\tLog::write(LongConnection::LOG, c$conn);\n\n\t\tlocal message = fmt(\"%s -> %s:%s remained alive for longer than %s\", \n\t\t c$id$orig_h, c$id$resp_h, c$id$resp_p, duration_to_mins_secs(c$duration));\n\t\tNOTICE([$note=LongConnection::found,\n\t\t $msg=message,\n\t\t $sub=fmt(\"%.2f\", c$duration),\n\t\t $conn=c]);\n\t\t\n\t\t++tracking_conns[c$uid];\n\t\t# We're only bumping the local offset value\n\t\t# here so we can use it below and don't need\n\t\t# to do the hash table lookup again.\n\t\t++offset;\n\t\t}\n\n\t# Keep watching if there are potentially more thresholds.\n\tif ( offset < |check_it| )\n\t\treturn check_it[offset];\n\telse\n\t\treturn 0secs;\n\t}\n\nevent connection_established(c: connection)\n\t{\n\tlocal check = get_durations(c);\n\tif ( |check| > 0 )\n\t\t{\n\t\tConnPolling::watch(c, long_callback, 1, check[0]);\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"30f03ff97cb49c8f0f2b27b001efaea53067ae61","subject":"global-ext needed to load site for some things to work.","message":"global-ext needed to load site for some things to work.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"global-ext.bro","new_file":"global-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load site\n@load functions-ext\n\nconst private_address_space: set[subnet] = {10.0.0.0\/8, 192.168.0.0\/16, 127.0.0.0\/8, 172.16.0.0\/12};","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load functions-ext\n\nconst private_address_space: set[subnet] = {10.0.0.0\/8, 192.168.0.0\/16, 127.0.0.0\/8, 172.16.0.0\/12};","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1939a8ac80fd3d28a8dc282639f0a5c3675b914a","subject":"Update rock.bro","message":"Update rock.bro\n\nlogging http headers allows for a few things:\r\n- domain fronting detection\r\n- http evasion sort of things with double headers.\r\n- greater visibility into potential software\/programs\r\n- additional indicator possibilites\r\n- additional hunting possibilities looking for abnormal\/rare headers","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nmodule ROCK;\n\nexport {\n const sensor_id = gethostname() &redef;\n}\n\n#=== Bro built-ins ===================================\n\n# Collect on SMB protocol\n@load policy\/protocols\/smb\n\n# Enable VLAN Logging\n@load policy\/protocols\/conn\/vlan-logging\n\n# Log MAC addresses\n@load policy\/protocols\/conn\/mac-logging\n\n# Log (All) Client and Server HTTP Headers\n@load policy\/protocols\/http\/header-names.bro\n\n#== ROCK specific scripts ============================\n# Add empty Intel framework database\n@load .\/frameworks\/intel\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n\n#== 3rd Party Scripts =================================\n# Add Salesforce's JA3 SSL fingerprinting\n@load .\/misc\/ja3\n\n### Sensor specific scripts ######################\n\n# Configure AF_PACKET, if in use\n@load .\/plugins\/afpacket\n","old_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nmodule ROCK;\n\nexport {\n const sensor_id = gethostname() &redef;\n}\n\n#=== Bro built-ins ===================================\n\n# Collect on SMB protocol\n@load policy\/protocols\/smb\n\n# Enable VLAN Logging\n@load policy\/protocols\/conn\/vlan-logging\n\n# Log MAC addresses\n@load policy\/protocols\/conn\/mac-logging\n\n#== ROCK specific scripts ============================\n# Add empty Intel framework database\n@load .\/frameworks\/intel\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n\n#== 3rd Party Scripts =================================\n# Add Salesforce's JA3 SSL fingerprinting\n@load .\/misc\/ja3\n\n### Sensor specific scripts ######################\n\n# Configure AF_PACKET, if in use\n@load .\/plugins\/afpacket\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"081837054a4e767ed3daef21af70fee9ccbcc1bc","subject":"Oops. ssl-ext only logs localhosts by default now.","message":"Oops. ssl-ext only logs localhosts by default now.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-ext.bro","new_file":"ssl-ext.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t\n\t# Which SSH logins to record.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts, NoHosts\n\tconst logging = LocalHosts &redef;\n\t\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssl-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"ssl-ext\", cat_sep(\"\\t\", \"\\\\N\",\n\t \"ts\",\n\t \"host\", \"port\",\n\t \"cert_subject\"));\n\t}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tif ( is_server )\n\t\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logging) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\t\n\t\tlocal log = LOG::get_file_by_addr(\"ssl-ext\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(),\n\t\t c$id$resp_h, port_to_count(c$id$resp_p), \n\t\t cert$subject);\n\t\t}\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t\n\t# Which SSH logins to record.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts, NoHosts\n\tconst logging = AllHosts &redef;\n\t\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssl-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"ssl-ext\", cat_sep(\"\\t\", \"\\\\N\",\n\t \"ts\",\n\t \"host\", \"port\",\n\t \"cert_subject\"));\n\t}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tif ( is_server )\n\t\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logging) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\t\n\t\tlocal log = LOG::get_file_by_addr(\"ssl-ext\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(),\n\t\t c$id$resp_h, port_to_count(c$id$resp_p), \n\t\t cert$subject);\n\t\t}\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"c8852607370686bbcf2b2c42c0b41093a9d94d6e","subject":"Create __load__.bro","message":"Create __load__.bro","repos":"CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,albertzaharovits\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/tor\/policy\/__load__.bro","new_file":"bro-scripts\/tor\/policy\/__load__.bro","new_contents":"@load .\/add-tor\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/tor\/policy\/__load__.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"66d187ecc72b5f8d93f30215ff96ba889fb25bb8","subject":"load global-ext from ssh-ext-logging","message":"load global-ext from ssh-ext-logging\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext-logging.bro","new_file":"ssh-ext-logging.bro","new_contents":"@load global-ext\n@load ssh-ext\n\nmodule SSH;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Which SSH logins to record.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssh-ext\", logging, split_log_file, T);\n\t}\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info)\n\t{\n\tlocal log = LOG::choose(\"ssh-ext\", id$resp_h);\n\n\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t si$start_time,\n\t id$orig_h, fmt(\"%d\", id$orig_p),\n\t id$resp_h, fmt(\"%d\", id$resp_p),\n\t si$status, si$direction, \n\t si$location$country_code, si$location$region,\n\t si$client, si$server,\n\t si$resp_size);\n\t}","old_contents":"@load ssh-ext\n\nmodule SSH;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Which SSH logins to record.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssh-ext\", logging, split_log_file, T);\n\t}\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info)\n\t{\n\tlocal log = LOG::choose(\"ssh-ext\", id$resp_h);\n\n\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t si$start_time,\n\t id$orig_h, fmt(\"%d\", id$orig_p),\n\t id$resp_h, fmt(\"%d\", id$resp_p),\n\t si$status, si$direction, \n\t si$location$country_code, si$location$region,\n\t si$client, si$server,\n\t si$resp_size);\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"4c0297163389a4e808f7fe1e7d043e47bb0596e1","subject":"fix logged hosts configuration","message":"fix logged hosts configuration\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", All, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !resp_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logging = Outbound &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", logging, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !orig_matches_direction(c$id$resp_h, logging) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"74311f0451cc0e14d666f6f62ae468f55fd70de9","subject":"Listen on localhost only.","message":"Listen on localhost only.\n","repos":"mavam\/vast,vast-io\/vast,vast-io\/vast,vast-io\/vast,pmos69\/vast,pmos69\/vast,vast-io\/vast,mavam\/vast,mavam\/vast,pmos69\/vast,vast-io\/vast,pmos69\/vast,mavam\/vast","old_file":"test\/bro\/ingest.bro","new_file":"test\/bro\/ingest.bro","new_contents":"@load base\/frameworks\/communication\n\nCommunication::nodes[\"vast\"] = [$host = 127.0.0.1,\n $p = 42000\/tcp,\n $events = \/^.*$\/,\n #$retry=10secs,\n $connect=T];\n","old_contents":"@load base\/frameworks\/communication\n\nCommunication::nodes[\"vast\"] = [$host = 192.150.187.38,\n $p = 42000\/tcp,\n $events = \/^.*$\/,\n #$retry=10secs,\n $connect=T];\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f226a4ce195465083f3ff5cb706f9b21d55467e3","subject":"add more opendns servers","message":"add more opendns servers\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"log-external-dns.bro","new_file":"log-external-dns.bro","new_contents":"module DNS;\n\nexport {\n redef record Info += {\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n 208.67.220.220\/32, #opendns\n } &redef;\n\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n if(!rec$RD)\n return F;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return F;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return F;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n return T;\n\n } ]);\n}\n","old_contents":"module DNS;\n\nexport {\n redef record Info += {\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n } &redef;\n\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n if(!rec$RD)\n return F;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return F;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return F;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n return T;\n\n } ]);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"25f08042939537e9775fcd0792fe74f2acc00df0","subject":"Further restriction to not allow hyphens on either side of candidate SSN.","message":"Further restriction to not allow hyphens on either side of candidate SSN.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\tlocal redacted_cc = gsub(ccp, \/[0-9]\/, redaction_char);\n\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, ccp);\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_redacted_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","old_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\tlocal redacted_cc = gsub(ccp, \/[0-9]\/, redaction_char);\n\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, ccp);\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_redacted_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"137ffcd27a13d9adb46b0571f0eb5eb2248044c1","subject":"Fix an occasional crash and remove a print statement.","message":"Fix an occasional crash and remove a print statement.\n\n - There was a stray print.\n - Removed a case of modifying a vector while\n iterating over it by taking a copy. A user was\n seeing rare crashes.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){2,3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\t## Configure this to `F` if you'd like to stop enforcing that\n\t## credit cards use an internal digit separator.\n\tconst use_cc_separators = T &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = F;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal found_cnt = 0;\n\n\tlocal ccps = find_all(data, cc_regex);\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\n\t\tif ( (!use_cc_separators || cc_separators in ccp) && luhn_check(ccp) )\n\t\t\t{\n\t\t\t++found_cnt;\n\n\t\t\t# we've got a match\n\t\t\tlocal cc_parts = split_string_all(data, cc_regex);\n\t\t\t# take a copy to avoid modifying the vector while iterating.\n\t\t\tfor ( i in copy(ccp_parts) )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 1 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = cc_parts[i];\n\t\t\t\t\tcc_parts[i] = gsub(cc_parts[i], \/[0-9]\/, \"X\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tlocal redacted_data = join_string_vec(cc_parts, \"\");\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tlocal cc_location = strstr(data, ccp);\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? gsub(ccp, \/[0-9]\/, \"X\") : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\t}\n\t\t\n\t\t}\n\tif ( found_cnt > 0 )\n\t\t{\n\t\tNOTICE([$note=CreditCardExposure::Found,\n\t\t $conn=c,\n\t\t $msg=fmt(\"Found at least %d credit card number%s\", found_cnt, found_cnt > 1 ? \"s\" : \"\"),\n\t\t $sub=trimmed_redacted_data,\n\t\t $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n\t\treturn T;\n\t\t}\n\telse\n\t\t{\n\t\treturn F;\n\t\t}\n\t}\n\n# This is used if the signature based technique is in use\n#function validate_credit_card_match(state: signature_state, data: string): bool\n#\t{\n#\t# TODO: Don't handle HTTP data this way.\n#\tif ( \/^GET\/ in data )\n#\t\treturn F;\n#\n#\treturn check_cards(state$conn, data);\n#\t}\n\nevent CreditCardExposure::stream_data(f: fa_file, data: string)\n\t{\n\tlocal c: connection;\n\tfor ( id in f$conns )\n\t\t{\n\t\tc = f$conns[id];\n\t\tbreak;\n\t\t}\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent file_new(f: fa_file)\n\t{\n\tif ( f$source == \"HTTP\" || f$source == \"SMTP\" )\n\t\t{\n\t\tFiles::add_analyzer(f, Files::ANALYZER_DATA_EVENT, \n\t\t [$stream_event=CreditCardExposure::stream_data]);\n\t\t}\n\t}\n","old_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){2,3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\t## Configure this to `F` if you'd like to stop enforcing that\n\t## credit cards use an internal digit separator.\n\tconst use_cc_separators = T &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = F;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal found_cnt = 0;\n\n\tlocal ccps = find_all(data, cc_regex);\n\tprint ccps;\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\n\t\tif ( (!use_cc_separators || cc_separators in ccp) && luhn_check(ccp) )\n\t\t\t{\n\t\t\t++found_cnt;\n\n\t\t\t# we've got a match\n\t\t\tlocal cc_parts = split_string_all(data, cc_regex);\n\t\t\tfor ( i in cc_parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 1 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = cc_parts[i];\n\t\t\t\t\tcc_parts[i] = gsub(cc_parts[i], \/[0-9]\/, \"X\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tlocal redacted_data = join_string_vec(cc_parts, \"\");\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tlocal cc_location = strstr(data, ccp);\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? gsub(ccp, \/[0-9]\/, \"X\") : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\t}\n\t\t\n\t\t}\n\tif ( found_cnt > 0 )\n\t\t{\n\t\tNOTICE([$note=CreditCardExposure::Found,\n\t\t $conn=c,\n\t\t $msg=fmt(\"Found at least %d credit card number%s\", found_cnt, found_cnt > 1 ? \"s\" : \"\"),\n\t\t $sub=trimmed_redacted_data,\n\t\t $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n\t\treturn T;\n\t\t}\n\telse\n\t\t{\n\t\treturn F;\n\t\t}\n\t}\n\n# This is used if the signature based technique is in use\n#function validate_credit_card_match(state: signature_state, data: string): bool\n#\t{\n#\t# TODO: Don't handle HTTP data this way.\n#\tif ( \/^GET\/ in data )\n#\t\treturn F;\n#\n#\treturn check_cards(state$conn, data);\n#\t}\n\nevent CreditCardExposure::stream_data(f: fa_file, data: string)\n\t{\n\tlocal c: connection;\n\tfor ( id in f$conns )\n\t\t{\n\t\tc = f$conns[id];\n\t\tbreak;\n\t\t}\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent file_new(f: fa_file)\n\t{\n\tif ( f$source == \"HTTP\" || f$source == \"SMTP\" )\n\t\t{\n\t\tFiles::add_analyzer(f, Files::ANALYZER_DATA_EVENT, \n\t\t [$stream_event=CreditCardExposure::stream_data]);\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"7d73c9e88fbec86c03152d838fa25e74a2f781ab","subject":"don't bother to keep track of recipients","message":"don't bother to keep track of recipients\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"","old_contents":"","returncode":0,"stderr":"unknown","license":"bsd-3-clause","lang":"Bro"} {"commit":"7711538f27fc87f3e4916d8efa926286bf712ef8","subject":"Create smtp-subject.bro","message":"Create smtp-subject.bro","repos":"unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,kingtuna\/cs-bro,CrowdStrike\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/intel-extensions\/seen\/smtp-subject.bro","new_file":"bro-scripts\/intel-extensions\/seen\/smtp-subject.bro","new_contents":"# Intel framework support for SMTP subjects \n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/smtp\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) \n{\nif ( c$smtp?$subject )\n Intel::seen([$indicator=c$smtp$subject,\n $indicator_type=Intel::EMAIL_SUBJECT,\n $conn=c,\n $where=SMTP::IN_SUBJECT]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/intel-extensions\/seen\/smtp-subject.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"f460be2432db8240d1793050ea23f68b992a0a53","subject":"Added spamcop.","message":"Added spamcop.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"30b7e59281039c3a84f1f1e126fea9fafe69bab3","subject":"update to use new function name","message":"update to use new function name\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-ext.bro","new_file":"ssl-ext.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", All, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", All, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !resp_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"6d5823550728db6cb3cac6c7ab082608f42793c6","subject":"Create __load__.bro","message":"Create __load__.bro","repos":"CrowdStrike\/cs-bro","old_file":"bro-scripts\/extensions\/dns\/__load__.bro","new_file":"bro-scripts\/extensions\/dns\/__load__.bro","new_contents":"@load .\/expand-query\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/extensions\/dns\/__load__.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"33290680dfc27957209bf3ff548933d159c5005b","subject":"connection hostnames logging","message":"connection hostnames logging\n\nadd a script that adds the hostnames to conn objects and creates a\nconn_hostnames log. Should possible be two scripts :)\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"conn-hostnames.bro","new_file":"conn-hostnames.bro","new_contents":"@load base\/protocols\/conn\n@load base\/protocols\/http\n@load base\/protocols\/ssl\n@load base\/utils\/site\n\nmodule Conn;\n\nevent connection_established(c: connection)\n{\n Conn::set_conn(c, F);\n}\n\nredef record Conn::Info += {\n resp_hostname: string &optional &log;\n};\n\nevent http_header (c: connection, is_orig: bool, name: string, value: string)\n{\n if(name == \"HOST\") {\n c$conn$resp_hostname = value;\n print \"set hostname\", value;\n flush_all();\n }\n}\n\nevent ssl_established(c: connection)\n{\n if(c?$ssl && c$ssl?$server_name) {\n c$conn$resp_hostname = c$ssl$server_name;\n print \"set hostname\", c$ssl$server_name;\n flush_all();\n }\n}\n\nevent bro_init()\n{\n Log::add_filter(Conn::LOG, [$name = \"conn-hostnames\",\n $path = \"conn_hostnames\",\n $pred(rec: Conn::Info) = {\n return (rec?$resp_hostname);\n }]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'conn-hostnames.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"234aaf6df5ea3f9738e2412c40bc0f1f2c1946fa","subject":"fix load.bro with new filenames","message":"fix load.bro with new filenames\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/__load__.bro","new_file":"scripts_master\/__load__.bro","new_contents":"@load .\/master_log.bro\n@load .\/bro_master.bro\n@load .\/dio_access.bro\n@load .\/dio_download_complete.bro\n@load .\/dio_download_offer.bro\n@load .\/dio_ftp.bro\n@load .\/dio_mysql_command.bro\n@load .\/dio_mysql_login.bro\n@load .\/dio_smb_bind.bro\n@load .\/dio_smb_request.bro","old_contents":"@load .\/master_log.bro\n@load .\/bro_master.bro\n@load .\/dio_access.bro\n@load .\/dio_download_complete.bro\n@load .\/dio_download_offer.bro\n@load .\/dio_ftp.bro\n@load .\/dio_mysql.bro\n@load .\/dio_smb_bind.bro\n@load .\/dio_smb_request.bro","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"a60d75eca87f66f83f6d9e7a47d602aef120d10d","subject":"Added the known-services script.","message":"Added the known-services script.\n\nThis script will currently log all discovered TCP services that are allowing a full handshake. You can optionally choose to log remote hosts, local hosts or all hosts services.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"known-services.bro","new_file":"known-services.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load global-ext\n\nmodule KnownServices;\n\nexport {\n\tconst services_log = open_log_file(\"known-services\") &raw_output &redef;\n\n\tglobal established_conns: set[addr, port] &create_expire=1day &redef;\n\tglobal known_services: set[addr, port] &create_expire=1day &synchronized &persistent;\n\t\n\t# The hosts whose services should be logged.\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n}\n\nevent connection_established(c: connection)\n\t{\n\tlocal id = c$id;\n\tif ( [id$resp_h, id$resp_p] !in established_conns && \n\t ip_matches_hosts(id$resp_h, logged_hosts) )\n\t\tadd established_conns[id$resp_h, id$resp_p];\n\t}\n\t\nevent known_services_done(c: connection)\n\t{\n\tlocal id = c$id;\n\tif ( [id$resp_h, id$resp_p] !in known_services &&\n\t [id$resp_h, id$resp_p] in established_conns &&\n\t \"ftp-data\" !in c$service )\n\t\t{\n\t\tadd known_services[id$resp_h, id$resp_p];\n\t\tprint services_log, cat_sep(\"\\t\", \"\\\\N\", id$resp_h, fmt(\"%d\", id$resp_p), fmt_str_set(c$service, \/\\-\/));\n\t\t}\n\t}\n\t\nevent connection_state_remove(c: connection)\n\t{\n\tevent known_services_done(c);\n\t}","old_contents":"","returncode":1,"stderr":"error: pathspec 'known-services.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"b52cc6219f8963c4593e9ef75c9ea2f653eb025f","subject":"Added the Sophos blacklist.","message":"Added the Sophos blacklist.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"fbef814996718b07e0cb3293630218b63846fb76","subject":"Small tweaks to try avoiding a problem.","message":"Small tweaks to try avoiding a problem.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal cc_parts = split_all(data, cc_regex);\n\t\t\tfor ( i in cc_parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = cc_parts[i];\n\t\t\t\t\tcc_parts[i] = gsub(cc_parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tlocal redacted_data = join_string_array(\"\", cc_parts);\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tlocal cc_location = strstr(data, ccp);\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_redacted_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? gsub(ccp, \/[0-9]\/, redaction_char) : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","old_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\tlocal redacted_cc = gsub(ccp, \/[0-9]\/, redaction_char);\n\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, ccp);\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_redacted_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1214d881d9d0ae6e286f0bf4960136f6df0ffbd0","subject":"Small fix leftover from debugging.","message":"Small fix leftover from debugging.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\tlocal session = smtp_sessions[id];\n\n\tif ( id !in conn_info || \n\t\t !session$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\n# This is a locally defined event. Handle it with a priority greater than\n# negative 5 if you want to dig into the conn_info record before it's deleted.\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(id);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\tlocal session = smtp_sessions[id];\n\n\tif ( id !in conn_info || \n\t\t !session$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\n# This is a locally defined event. Handle it with a priority greater than\n# negative 5 if you want to dig into the conn_info record before it's deleted.\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s). Subject: %s\", loc$country_code, ip, conn_log$subject),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(id);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"e1ed4809d370e35433f90110fd87ef8e52ed6794","subject":"New script for watching for correct headers and order of those headers. This is very much in testing, do not run in production!","message":"New script for watching for correct headers and order of those headers. This is very much in testing, do not run in production!\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"testing\/http-watch-header-order.bro","new_file":"testing\/http-watch-header-order.bro","new_contents":"@load http\n@load http-request\n@load http-ext\n\nmodule HTTP;\n\ntype browser_header_info: record {\n\tname: string &default=\"\";\n\tuser_agent_regex: pattern;\n\trequired_headers: vector of string;\n\theaders: vector of string;\n\trev_headers: table[string] of int;\n};\n\nexport {\n\t# Domains where header order is frequently messed up for various reasons.\n\tconst ignore_header_order_at = \/\\.facebook\\.com$\/ | \n\t \/\\.fbcdn\\.net$\/ |\n\t \/\\.apmebf\\.com$\/ |\n\t \/\\.qq\\.com$\/ |\n\t \/\\.yahoo\\.com$\/ |\n\t \/\\.mozilla\\.com$\/ |\n\t \/\\.google\\.com$\/ &redef;\n\t\n\t# This is a set of local proxies (proxies frequently rewrite headers)\n\tconst local_http_proxies: set[addr] &redef;\n}\n\nconst BROWSER_HEADERS: table[string] of browser_header_info = {\n\t[\"IE6\"] = record($name = \"IE6\",\n\t $user_agent_regex = \/Mozilla\\\/.*compatible; MSIE 6\/ |\n\t #\/^iTunes\\\/.*Windows\/ | \/^Microsoft-CryptoAPI\\\/\/ |\n\t \/Windows-Update-Agent\/,\n\t $required_headers = vector(\"ACCEPT\", \"USER-AGENT\", \"CONNECTION\"),\n\t $headers = vector(\"ACCEPT\", \"REFERER\", \"ACCEPT-LANGUAGE\", \"ACCEPT-ENCODING\", \"USER-AGENT\", \"CONNECTION\"),\n\t $rev_headers = table([\"\"]=0)),\n\n\t[\"IE7\"] = record($name = \"IE7\",\n\t $user_agent_regex = \/Mozilla\\\/.*compatible; MSIE 7\/,\n\t $required_headers = vector(\"ACCEPT\", \"UA-CPU\", \"USER-AGENT\", \"CONNECTION\"),\n\t $headers = vector(\"ACCEPT\", \"REFERER\", \"ACCEPT-LANGUAGE\", \"UA-CPU\", \"ACCEPT-ENCODING\", \"ACCEPT-CHARSET\", \"IF-MODIFIED-SINCE\", \"IF-NONE-MATCH\", \"USER-AGENT\", \"CONNECTION\", \"KEEP-ALIVE\"),\n\t $rev_headers = table([\"\"]=0)),\n\t\n\t[\"IE8\"] = record($name = \"IE8\",\n\t $user_agent_regex = \/Mozilla\\\/.*MSIE 8\/ |\n\t \/Mozilla\\\/.*compatible; MSIE 7.*Trident\\\/4\\.0\/,\n\t $required_headers = vector(\"ACCEPT\", \"USER-AGENT\", \"UA-CPU\", \"HOST\", \"CONNECTION\"),\n\t $headers = vector(\"ACCEPT\", \"REFERER\", \"ACCEPT-LANGUAGE\", \"USER-AGENT\", \"UA-CPU\", \"ACCEPT-ENCODING\", \"HOST\", \"CONNECTION\", \"COOKIE\"),\n\t $rev_headers = table([\"\"]=0)),\n\n\t[\"MSOffice\"] = record($name = \"MSOffice\",\n\t $user_agent_regex = \/MSOffice\/,\n\t $required_headers = vector(\"ACCEPT\", \"USER-AGENT\", \"UA-CPU\", \"CONNECTION\"),\n\t $headers = vector(\"ACCEPT\", \"REFERER\", \"ACCEPT-LANGUAGE\", \"USER-AGENT\", \"UA-CPU\", \"ACCEPT-ENCODING\", \"CONNECTION\", \"COOKIE\"),\n\t $rev_headers = table([\"\"]=0)),\n\n\t[\"FIREFOX\"] = record($name = \"FIREFOX\",\n\t $user_agent_regex = \/Gecko\\\/.*(Firefox|Thunderbird|Netscape)\\\/\/ |\n\t \/^mozbar [0-9\\.]* xpi\/,\n\t $required_headers = vector(\"USER-AGENT\", \"ACCEPT\", \"ACCEPT-LANGUAGE\", \"ACCEPT-CHARSET\", \"CONNECTION\"),\n\t $headers = vector(\"HOST\", \"USER-AGENT\", \"ACCEPT\", \"ACCEPT-LANGUAGE\", \"ACCEPT-ENCODING\", \"ACCEPT-CHARSET\", \"CONTENT-TYPE\", \"REFERER\", \"CONTENT-LENGTH\", \"COOKIE\", \"RANGE\", \"CONNECTION\"),\n\t $rev_headers = table([\"\"]=0)),\n\n\t[\"WEBKIT_OSX_<=312\"] = record($name=\"WEBKIT_OSX_<=312\",\n\t $user_agent_regex = \/(PPC|Intel) Mac OS X;.*Safari\\\/\/,\n\t $required_headers = vector(\"HOST\", \"CONNECTION\", \"USER-AGENT\", \"ACCEPT\", \"ACCEPT-LANGUAGE\"),\n\t $headers = vector(\"HOST\", \"CONNECTION\", \"REFERER\", \"USER-AGENT\", \"IF-MODIFIED-SINCE\", \"ACCEPT\", \"ACCEPT-ENCODING\", \"ACCEPT-LANGUAGE\", \"COOKIE\"),\n\t $rev_headers = table([\"\"]=0)),\n\n\t[\"WEBKIT_OSX_PPC\"] = record($name = \"WEBKIT_OSX_PPC\",\n\t $user_agent_regex = \/PPC Mac OS X.*AppleWebKit\\\/.*(Safari\\\/)?\/,\n\t $required_headers = vector(\"HOST\", \"CONNECTION\", \"USER-AGENT\", \"ACCEPT\", \"ACCEPT-LANGUAGE\"),\n\t $headers = vector(\"HOST\", \"CONNECTION\", \"REFERER\", \"USER-AGENT\", \"ACCEPT\", \"ACCEPT-ENCODING\", \"ACCEPT-LANGUAGE\"),\n\t $rev_headers = table([\"\"]=0)),\n\n\t# ACCEPT was removed as a header because it is put in two different locations at different times.\n\t[\"WEBKIT_OSX_10.4\"] = record($name = \"WEBKIT_OSX_10.4\",\n\t $user_agent_regex = \/^AppleSyndication\/ |\n\t \/Mac OS X.*AppleWebKit\\\/.*(Safari\\\/)?\/,\n\t $required_headers = vector(\"ACCEPT-LANGUAGE\", \"ACCEPT-ENCODING\", \"USER-AGENT\", \"CONNECTION\"),\n\t $headers = vector(\"ACCEPT-LANGUAGE\", \"ACCEPT-ENCODING\", \"COOKIE\", \"REFERER\", \"USER-AGENT\", \"CONNECTION\"),\n\t $rev_headers = table([\"\"]=0)),\n\t\n\t[\"WEBKIT_OSX_10.5\"] = record($name = \"WEBKIT_OSX_10.5\",\n\t $user_agent_regex = \/^Apple-PubSub\/ |\n\t \/CFNetwork\\\/.*Darwin\\\/\/ |\n\t \/(Windows|Mac OS X|iPhone OS).*AppleWebKit\\\/.*(Safari\\\/)?\/,\n\t $required_headers = vector(\"USER-AGENT\", \"ACCEPT\", \"ACCEPT-LANGUAGE\", \"CONNECTION\"),\n\t $headers = vector(\"USER-AGENT\", \"REFERER\", \"ACCEPT\", \"ACCEPT-LANGUAGE\", \"COOKIE\", \"CONNECTION\"),\n\t $rev_headers = table([\"\"]=0)),\n\t\n\t[\"CHROME_<4.0\"] = record($name = \"CHROME_<4.0\",\n\t $user_agent_regex = \/Chrome\\\/.*Safari\\\/\/,\n\t $required_headers = vector(\"USER-AGENT\", \"ACCEPT-LANGUAGE\", \"ACCEPT-CHARSET\", \"HOST\", \"CONNECTION\"),\n\t $headers = vector(\"USER-AGENT\", \"REFERER\", \"CONTENT-LENGTH\", \"CONTENT-TYPE\", \"ACCEPT\", \"RANGE\", \"COOKIE\", \"ACCEPT-LANGUAGE\", \"ACCEPT-CHARSET\", \"HOST\", \"CONNECTION\"),\n\t $rev_headers = table([\"\"]=0)),\n\t\n\t[\"CHROME_>=4.0\"] = record($name = \"CHROME_>=4.0\",\n\t $user_agent_regex = \/Chrome\\\/.*Safari\\\/\/,\n\t $required_headers = vector(\"HOST\", \"CONNECTION\", \"USER-AGENT\", \"ACCEPT\", \"ACCEPT-ENCODING\", \"ACCEPT-LANGUAGE\", \"ACCEPT-CHARSET\"),\n\t $headers = vector(\"HOST\", \"CONNECTION\", \"USER-AGENT\", \"REFERER\", \"CONTENT-LENGTH\", \"CONTENT-TYPE\", \"ACCEPT\", \"RANGE\", \"ACCEPT-ENCODING\", \"COOKIE\", \"ACCEPT-LANGUAGE\", \"ACCEPT-CHARSET\"),\n\t $rev_headers = table([\"\"]=0)),\n\t\n\t[\"FLASH\"] = record($name = \"FLASH\",\n\t $user_agent_regex = \/blah... nothing matches\/,\n\t $required_headers = vector(\"ACCEPT\", \"ACCEPT-LANGUAGE\", \"REFERER\", \"X-FLASH-VERSION\", \"ACCEPT-ENCODING\", \"USER-AGENT\", \"COOKIE\", \"CONNECTION\"),\n\t $headers = vector(\"ACCEPT\", \"ACCEPT-LANGUAGE\", \"REFERER\", \"X-FLASH-VERSION\", \"ACCEPT-ENCODING\", \"USER-AGENT\", \"COOKIE\", \"CONNECTION\", \"HOST\"),\n\t $rev_headers = table([\"\"]=0)),\n};\n\n# Generate all of the reverse header tables.\nevent bro_init()\n\t{\n\tfor ( browser_name in BROWSER_HEADERS )\n\t\t{\n\t\tlocal browser = BROWSER_HEADERS[browser_name];\n\t\tdelete browser$rev_headers[\"\"];\n\t\tfor ( i in browser$headers )\n\t\t\t{\n\t\t\tbrowser$rev_headers[browser$headers[i]] = i;\n\t\t\t}\n\t\t}\n\t}\n\n\nconst ordered_headers: set[string] = {\n\t\"HOST\",\n\t\"USER-AGENT\",\n\t\"ACCEPT\",\n\t\"ACCEPT-LANGUAGE\",\n\t\"ACCEPT-ENCODING\",\n\t\"ACCEPT-CHARSET\",\n\t\"KEEP-ALIVE\",\n\t\"CONNECTION\",\n\t\"CONTENT-TYPE\",\n\t\"REFERER\",\n\t\"CONTENT-LENGTH\",\n\t\"COOKIE\", \n\t\"RANGE\",\n\t\"UA-CPU\",\n\t\"X-FLASH-VERSION\",\n};\n\ntype header_tracker: record {\n\tua_identified: set[string];\n\tidentified: set[string];\n\tbroken: set[string];\n\tpossibles: table[string] of count;\n};\n\nglobal tracking_headers: table[conn_id] of header_tracker &read_expire=30secs;\nglobal recently_examined: set[addr] &create_expire=30secs &redef;\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n\t{\n\tif ( !is_orig || \n\t name !in ordered_headers ) \n\t\treturn;\n\t\n\tif ( !is_local_addr(c$id$orig_h) || \n\t #c$id$orig_h in recently_examined || \n\t c$id$orig_h in local_http_proxies ) \n\t\treturn;\n\t\n\tlocal header = name;\n\tif ( c$id !in tracking_headers )\n\t\t{\n\t\ttracking_headers[c$id] = [$ua_identified=set(\"\"),\n\t\t $identified=set(\"\"),\n\t\t $broken=set(\"\"),\n\t\t $possibles=table([\"IE6\"]=0, [\"IE7\"]=0, [\"IE8\"]=0, [\"MSOffice\"]=0, [\"FIREFOX\"]=0, [\"WEBKIT_OSX_PPC\"]=0, [\"WEBKIT_OSX_10.4\"]=0, [\"WEBKIT_OSX_10.5\"]=0, [\"CHROME_<4.0\"]=0, [\"CHROME_>=4.0\"]=0, [\"FLASH\"]=0)];\n\t\t# FIXME: this is a hack because set(\"\") above needed an empty element for some reason.\n\t\tdelete tracking_headers[c$id]$identified[\"\"];\n\t\tdelete tracking_headers[c$id]$ua_identified[\"\"];\n\t\tdelete tracking_headers[c$id]$broken[\"\"];\n\t\t}\n\t\t\n\tlocal ht = tracking_headers[c$id];\n\t\n\t#print fmt(\"CHECKING HEADER: %s\", header);\n\tfor ( browser_name in BROWSER_HEADERS )\n\t\t{\n\t\tif ( header == \"USER-AGENT\" )\n\t\t\t{\n\t\t\tif ( BROWSER_HEADERS[browser_name]$user_agent_regex in value )\n\t\t\t\tadd ht$ua_identified[browser_name];\n\t\t\t}\n\t\t\n\t\tif ( browser_name !in ht$identified )\n\t\t\t{\n\t\t\tlocal browser = BROWSER_HEADERS[browser_name];\n\t\t\t\n\t\t\tif ( browser_name in ht$possibles && \n\t\t\t\t header in browser$rev_headers )\n\t\t\t\t{\n\t\t\t\tlocal possible_browser = ht$possibles[browser_name]; # count\n\t\t\t\tlocal browser_rev_headers = browser$rev_headers; # table[string] of int\n\t\t\t\tlocal h_position = browser_rev_headers[header]; # count\n\t\t\t\tlocal req_headers = browser$required_headers; # vector of string\n\t\t\t\tlocal next_required_header = req_headers[possible_browser+1]; # string\n\t\t\t\tlocal current_header_val = req_headers[h_position]; # string\n\t\t\t\t#print fmt(\"for browser: %s :: checking header: %s :: req position: %d :: next required: %s :: len of req headers: %d\", browser_name, header, ht$possibles[browser_name], req_headers[ht$possibles[browser_name]+1], |req_headers|);\n\t\t\t\t\n\t\t\t\tif ( next_required_header == header )\n\t\t\t\t\t{\n\t\t\t\t\t++ht$possibles[browser_name];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\telse if ( possible_browser == 0 || possible_browser == |req_headers| ||\n\t\t\t\t (browser_rev_headers[req_headers[possible_browser]] < h_position &&\n\t\t\t\t h_position < browser_rev_headers[next_required_header]) )\n\t\t\t\t\t{\n\t\t\t\t\t#print fmt(\"%s is an optional header for %s (but it is in the correct position).\", header, browser_name);\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tdelete ht$possibles[browser_name];\n\t\t\t\t\t}\n\n\t\t\t\t# Have we found a browser yet?\n\t\t\t\tif ( browser_name in ht$possibles && \n\t\t\t\t\t ht$possibles[browser_name] == |req_headers| )\n\t\t\t\t\t{\n\t\t\t\t\tadd ht$identified[browser_name];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=-10\n\t{\n\tif ( id in tracking_headers && \n\t id$orig_h !in local_http_proxies &&\n\t si$proxied_for == \"\" )\n\t\t{\n\t\tadd recently_examined[id$orig_h];\n\t\t\t\n\t\tif ( ignore_header_order_at in si$host )\n\t\t\t{\n\t\t\t#print \"we're going to ignore this entire request.\";\n\t\t\treturn;\n\t\t\t}\n\t\t\n\t\tlocal is_matched = F;\n\t\t#if ( |tracking_headers[id]$identified| > 0 )\n\t\t#\t{\n \t\t#\tis_matched = F;\n\t\t#\tfor ( b in tracking_headers[id]$identified )\n\t\t#\t\t{\n\t\t#\t\tif ( BROWSER_HEADERS[b]$user_agent_regex in si$user_agent )\n\t\t#\t\t\t{\n\t\t#\t\t\tis_matched = T;\n\t\t#\t\t\t}\n\t\t#\t\t}\n\t\t#\tif ( !is_matched )\n\t\t#\t\t{\n\t\t#\t\t#print fmt(\"Headers look like %s, but User-Agent doesn't match.\", fmt_str_set(tracking_headers[id]$identified, \/blah\/));\n\t\t#\t\tprint cat_sep(\"\\t\", \"\\\\N\",\n\t\t#\t\t si$start_time,\n\t\t#\t\t id$orig_h, port_to_count(id$orig_p),\n\t\t#\t\t id$resp_h, port_to_count(id$resp_p),\n\t\t#\t\t fmt_str_set(si$force_log_reasons, \/DONTMATCH\/),\n\t\t#\t\t si$method, si$url, si$referrer,\n\t\t#\t\t si$user_agent, si$proxied_for);\n\t\t#\t\t}\n\t\t#\t}\n\t\t\n\t\t# Do this in case the User-Agent is known, but the headers don't match it.\n\t\tis_matched=F;\n\t\tfor ( b in tracking_headers[id]$ua_identified )\n\t\t\t{\n\t\t\tif ( b in tracking_headers[id]$identified )\n\t\t\t\t{\n\t\t\t\tis_matched=T;\n\t\t\t\t}\n\t\t\t}\n\t\tif ( |tracking_headers[id]$ua_identified| > 0 && !is_matched )\n\t\t\t{\n\t\t\tprint fmt(\"User-Agent looks like %s, but headers look like %s.\", fmt_str_set(tracking_headers[id]$ua_identified, \/blah\/), fmt_str_set(tracking_headers[id]$identified, \/blah\/));\n\t\t\tprint cat_sep(\" :: \", \"\\\\N\",\n\t\t\t si$start_time,\n\t\t\t id$orig_h, port_to_count(id$orig_p),\n\t\t\t id$resp_h, port_to_count(id$resp_p),\n\t\t\t fmt_str_set(si$force_log_reasons, \/DONTMATCH\/),\n\t\t\t si$method, si$url, si$referrer,\n\t\t\t si$user_agent, si$proxied_for);\n\t\t\t\n\t\t\t}\n\t\t}\n\tdelete tracking_headers[id];\n\t}\n\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'testing\/http-watch-header-order.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"c84069e5ecba1912786b1b5bf9f5bea452440f74","subject":"Fixed an issue with the smtp_ext event. It has finally been tested.","message":"Fixed an issue with the smtp_ext event. It has finally been tested.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"@load smtp\n@load global-ext\n\ntype smtp_ext_session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, cl: smtp_ext_session_info);\n\nfunction default_smtp_ext_session_info(): smtp_ext_session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of smtp_ext_session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\t\t\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_smtp_ext_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_smtp_ext_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, cl: session_info);\n\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\t\t\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"fb3a6266feaa1e45c4032489b3b4dc917d68f90e","subject":"update to use new logging framework","message":"update to use new logging framework\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logging = Outbound &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", logging, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !orig_matches_direction(c$id$resp_h, logging) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\tconst log = open_log_file(\"ssl-known-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !resp_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"38e27b680d39643792ac9d6b79edc0e627535215","subject":"bug fix: bro file extraction, add: bro owasp beginnings","message":"bug fix: bro file extraction, add: bro owasp beginnings\n\n\nFormer-commit-id: 97415935f543cbe81ebae23c2bf2c7a0d449e1a0","repos":"SuperCowPowers\/workbench,djtotten\/workbench,SuperCowPowers\/workbench,djtotten\/workbench,SuperCowPowers\/workbench,djtotten\/workbench","old_file":"server\/workers\/bro\/file_extensions\/extract_files.bro","new_file":"server\/workers\/bro\/file_extensions\/extract_files.bro","new_contents":"##! Extract exe, pdf, jar and cab files.\n\nglobal ext_map: table[string] of string = {\n [\"application\/x-dosexec\"] = \"exe\",\n [\"application\/pdf\"] = \"pdf\",\n [\"application\/zip\"] = \"zip\",\n [\"application\/jar\"] = \"jar\",\n [\"application\/vnd.ms-cab-compressed\"] = \"cab\",\n [\"text\/plain\"] = \"txt\",\n [\"image\/gif\"] = \"gif\",\n [\"image\/jpeg\"] = \"jpg\",\n [\"image\/png\"] = \"png\",\n [\"text\/html\"] = \"html\",\n [\"application\/vnd.ms-fontobject\"] = \"ms_font\",\n [\"application\/x-shockwave-flash\"] = \"swf\"\n} &default =\"unknown\";\n\nevent file_new(f: fa_file)\n {\n if (!f?$mime_type) return;\n local ext = ext_map[f$mime_type];\n if (ext != \"txt\" && ext != \"html\" && ext != \"ms_font\" && ext != \"jpg\" && ext != \"gif\" && ext != \"png\")\n {\n local fname = fmt(\"%s-%s.%s\", f$source, f$id, ext);\n Files::add_analyzer(f, Files::ANALYZER_EXTRACT, [$extract_filename=fname]);\n }\n }\n","old_contents":"##! Extract exe, pdf, jar and cab files.\n\nglobal ext_map: table[string] of string = {\n [\"application\/x-dosexec\"] = \"exe\",\n [\"application\/pdf\"] = \"pdf\",\n [\"application\/zip\"] = \"zip\",\n [\"application\/jar\"] = \"jar\",\n [\"application\/vnd.ms-cab-compressed\"] = \"cab\",\n [\"text\/plain\"] = \"txt\",\n [\"image\/gif\"] = \"gif\",\n [\"image\/jpeg\"] = \"jpg\",\n [\"image\/png\"] = \"png\",\n [\"text\/html\"] = \"html\",\n [\"application\/vnd.ms-fontobject\"] = \"ms_font\",\n [\"application\/x-shockwave-flash\"] = \"swf\"\n} &default =\"unknown\";\n\nevent file_new(f: fa_file)\n {\n local ext = ext_map[f$mime_type];\n if (ext != \"txt\" && ext != \"html\" && ext != \"ms_font\" && ext != \"jpg\" && ext != \"gif\" && ext != \"png\")\n {\n local fname = fmt(\"%s-%s.%s\", f$source, f$id, ext);\n Files::add_analyzer(f, Files::ANALYZER_EXTRACT, [$extract_filename=fname]);\n }\n }","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"3bd3e8f8085a2c60a43e5c30c06a8a9bbddabe4f","subject":"Removed a comment","message":"Removed a comment\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\tlocal session = smtp_sessions[id];\n\n\tif ( id !in conn_info || \n\t\t !session$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\tlocal session = smtp_sessions[id];\n\n\tif ( id !in conn_info || \n\t\t !session$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\n# This is a locally defined event. Handle it with a priority greater than\n# negative 5 if you want to dig into the conn_info record before it's deleted.\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"21b4e333e47142fe4c9eeca7df635b4c2fc04e11","subject":"don't bother to keep track of recipients","message":"don't bother to keep track of recipients\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id];\n local blarg: set[conn_id];\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"%s is rejecting a high percentage of mail\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n recipients: string;\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id];\n local blarg: set[conn_id];\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg, $recipients=\"\"];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n if( foo$recipients == \"\" )\n {\n foo$recipients = session$recipients;\n } else if (session$recipients != \"\") {\n foo$recipients = cat(foo$recipients, \",\", session$recipients);\n }\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"%s is rejecting a high percentage of mail\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent mailto: %s\", foo$total, percent, foo$recipients), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"6dfc0c2de376a25fccdc3b7c1132b2c67ec41b8c","subject":"fix regex","message":"fix regex\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-external-names.bro","new_file":"http-ext-external-names.bro","new_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)albany\\.edu($|:)\/ &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=10\n{\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","old_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)albany\\.edu$\/ &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=10\n{\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"7688f9c5951e02f49965fdcf00bba23c9aa70177","subject":"Small fix to is_valid_ip function","message":"Small fix to is_valid_ip function\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"functions-ext.bro","new_file":"functions-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\nfunction numeric_id_string(id: conn_id): string\n\t{\n\treturn fmt(\"%s:%d > %s:%d\",\n\t id$orig_h, id$orig_p,\n\t id$resp_h, id$resp_p);\n\t}\n\nfunction fmt_str_set(input: string_set, strip: pattern): string\n\t{\n\tlocal output = \"{\";\n\tlocal tmp = \"\";\n\tlocal len = length(input);\n\tlocal i = 1;\n\t\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", gsub(item, strip, \"\"));\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s, \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s}\", output);\n\t}\n\n# Regular expressions for matching IP addresses in strings.\nconst ipv4_addr_regex = \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/;\nconst ipv6_8hex_regex = \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/;\nconst ipv6_compressed_hex_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/;\nconst ipv6_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\nconst ipv6_compressed_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\n\n# These are only commented out until this bug is fixed:\n# http:\/\/www.bro-ids.org\/wiki\/index.php\/Known_Issues#Bug_with_OR-ing_together_pattern_variables\n#const ipv6_addr_regex = ipv6_8hex_regex |\n# ipv6_compressed_hex_regex |\n# ipv6_hex4dec_regex |\n# ipv6_compressed_hex4dec_regex;\n#const ip_addr_regex = ipv4_addr_regex | ipv6_addr_regex;\n\nconst ipv6_addr_regex = \n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nconst ip_addr_regex = \n \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/ |\n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nfunction is_valid_ip(ip_str: string): bool\n\t{\n\tif ( ip_str == ipv4_addr_regex )\n\t\t{\n\t\tlocal octets = split(ip_str, \/\\.\/);\n\t\tif ( |octets| != 4 )\n\t\t\treturn F;\n\t\t\n\t\tlocal num=0;\n\t\tfor ( i in octets )\n\t\t\t{\n\t\t\tnum = to_count(octets[i]);\n\t\t\tif ( num < 0 || 255 < num )\n\t\t\t\treturn F;\n\t\t\t}\n\t\treturn T;\n\t\t}\n\telse if ( ip_str == ipv6_addr_regex )\n\t\t{\n\t\t# TODO: make this work correctly.\n\t\treturn T;\n\t\t}\n\treturn F;\n\t}\n\n# This output a string_array of ip addresses extracted from a string.\n# given: \"this is 1.1.1.1 a test 2.2.2.2 string with ip addresses 3.3.3.3\"\n# outputs: { [1] = 1.1.1.1, [2] = 2.2.2.2, [3] = 3.3.3.3 }\nfunction find_ip_addresses(input: string): string_array\n\t{\n\tlocal parts = split_all(input, ip_addr_regex);\n\tlocal output: string_array;\n\t\n\tfor ( i in parts )\n\t\t{\n\t\tif ( i % 2 == 0 && is_valid_ip(parts[i]) )\n\t\t\toutput[i\/2] = parts[i];\n\t\t}\n\treturn output;\n\t}\n\n\t\n# Some enums for deciding what and when to log.\ntype Direction: enum { Inbound, Outbound, BiDirectional };\ntype Hosts: enum { LocalHosts, RemoteHosts, AllHosts };\n\nfunction orig_h_matches_direction(ip: addr, d: Direction): bool\n\t{\n\treturn ( (d == Outbound && is_local_addr(ip)) ||\n\t (d == Inbound && !is_local_addr(ip)) ||\n\t d == BiDirectional );\n\t}\nfunction conn_matches_direction(id: conn_id, d: Direction): bool\n\t{\n\treturn orig_h_matches_direction(id$orig_h, d);\n\t}\nfunction addr_matches_hosts(ip: addr, d: Hosts): bool\n\t{\n\treturn ( (d == LocalHosts && is_local_addr(ip)) ||\n\t (d == RemoteHosts && !is_local_addr(ip)) ||\n\t d == AllHosts );\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\nfunction numeric_id_string(id: conn_id): string\n\t{\n\treturn fmt(\"%s:%d > %s:%d\",\n\t id$orig_h, id$orig_p,\n\t id$resp_h, id$resp_p);\n\t}\n\nfunction fmt_str_set(input: string_set, strip: pattern): string\n\t{\n\tlocal output = \"{\";\n\tlocal tmp = \"\";\n\tlocal len = length(input);\n\tlocal i = 1;\n\t\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", gsub(item, strip, \"\"));\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s, \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s}\", output);\n\t}\n\n# Regular expressions for matching IP addresses in strings.\nconst ipv4_addr_regex = \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/;\nconst ipv6_8hex_regex = \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/;\nconst ipv6_compressed_hex_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/;\nconst ipv6_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\nconst ipv6_compressed_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\n\n# These are only commented out until this bug is fixed:\n# http:\/\/www.bro-ids.org\/wiki\/index.php\/Known_Issues#Bug_with_OR-ing_together_pattern_variables\n#const ipv6_addr_regex = ipv6_8hex_regex |\n# ipv6_compressed_hex_regex |\n# ipv6_hex4dec_regex |\n# ipv6_compressed_hex4dec_regex;\n#const ip_addr_regex = ipv4_addr_regex | ipv6_addr_regex;\n\nconst ipv6_addr_regex = \n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nconst ip_addr_regex = \n \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/ |\n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nfunction is_valid_ip(ip_str: string): bool\n\t{\n\tif ( ip_str == ipv4_addr_regex )\n\t\t{\n\t\tlocal octets = split(ip_str, \/\\.\/);\n\t\tif ( |octets| > 4 )\n\t\t\treturn F;\n\t\t\n\t\tlocal num=0;\n\t\tfor ( i in octets )\n\t\t\t{\n\t\t\tnum = to_count(octets[i]);\n\t\t\tif ( num < 0 || 255 < num )\n\t\t\t\treturn F;\n\t\t\t}\n\t\treturn T;\n\t\t}\n\telse if ( ip_str == ipv6_addr_regex )\n\t\t{\n\t\t# TODO: make this work correctly.\n\t\treturn T;\n\t\t}\n\treturn F;\n\t}\n\n# This output a string_array of ip addresses extracted from a string.\n# given: \"this is 1.1.1.1 a test 2.2.2.2 string with ip addresses 3.3.3.3\"\n# outputs: { [1] = 1.1.1.1, [2] = 2.2.2.2, [3] = 3.3.3.3 }\nfunction find_ip_addresses(input: string): string_array\n\t{\n\tlocal parts = split_all(input, ip_addr_regex);\n\tlocal output: string_array;\n\t\n\tfor ( i in parts )\n\t\t{\n\t\tif ( i % 2 == 0 && is_valid_ip(parts[i]) )\n\t\t\toutput[i\/2] = parts[i];\n\t\t}\n\treturn output;\n\t}\n\n\t\n# Some enums for deciding what and when to log.\ntype Direction: enum { Inbound, Outbound, BiDirectional };\ntype Hosts: enum { LocalHosts, RemoteHosts, AllHosts };\n\nfunction orig_h_matches_direction(ip: addr, d: Direction): bool\n\t{\n\treturn ( (d == Outbound && is_local_addr(ip)) ||\n\t (d == Inbound && !is_local_addr(ip)) ||\n\t d == BiDirectional );\n\t}\nfunction conn_matches_direction(id: conn_id, d: Direction): bool\n\t{\n\treturn orig_h_matches_direction(id$orig_h, d);\n\t}\nfunction addr_matches_hosts(ip: addr, d: Hosts): bool\n\t{\n\treturn ( (d == LocalHosts && is_local_addr(ip)) ||\n\t (d == RemoteHosts && !is_local_addr(ip)) ||\n\t d == AllHosts );\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"97c9a4a88b1994b08e3d82897a0caf1e9c14aca8","subject":"terminate connection from bro 1.5","message":"terminate connection from bro 1.5\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"terminate-connection.bro","new_file":"terminate-connection.bro","new_contents":"# $Id$\n\n@load site\n@load notice\n\n# Ugly: we need the following from conn.bro, but we can't soundly load\n# it because it in turn loads us.\nglobal full_id_string: function(c: connection): string;\n\nmodule TerminateConnection;\n\nexport {\n\tredef enum Notice += {\n\t\tTerminatingConnection,\t# connection will be terminated\n\t\tTerminatingConnectionIgnored,\t# connection terminated disabled\n\t};\n\n\t# Whether we're allowed (and\/or are capable) to terminate connections\n\t# using \"rst\".\n\tconst activate_terminate_connection = F &redef;\n\n\t# Terminate the given connection.\n\tglobal terminate_connection: function(c: connection);\n\n}\n\nfunction terminate_connection(c: connection)\n\t{\n\tlocal id = c$id;\n\n\tif ( activate_terminate_connection )\n\t\t{\n\t\tlocal local_init = is_local_addr(id$orig_h);\n\n\t\tlocal term_cmd = fmt(\"rst %s -n 32 -d 20 %s %d %d %s %d %d\",\n\t\t\t\t\tlocal_init ? \"-R\" : \"\",\n\t\t\t\t\tid$orig_h, id$orig_p, get_orig_seq(id),\n\t\t\t\t\tid$resp_h, id$resp_p, get_resp_seq(id));\n\n\t\tif ( reading_live_traffic() )\n\t\t\tsystem(term_cmd);\n\t\telse\n\t\t\tNOTICE([$note=TerminatingConnection, $conn=c,\n\t\t\t\t$msg=term_cmd, $sub=\"first termination command\"]);\n\n\t\tterm_cmd = fmt(\"rst %s -r 2 -n 4 -s 512 -d 20 %s %d %d %s %d %d\",\n\t\t\t\tlocal_init ? \"-R\" : \"\",\n\t\t\t\tid$orig_h, id$orig_p, get_orig_seq(id),\n\t\t\t\tid$resp_h, id$resp_p, get_resp_seq(id));\n\n\t\tif ( reading_live_traffic() )\n\t\t\tsystem(term_cmd);\n\t\telse\n\t\t\tNOTICE([$note=TerminatingConnection, $conn=c,\n\t\t\t\t$msg=term_cmd, $sub=\"second termination command\"]);\n\n\t\tNOTICE([$note=TerminatingConnection, $conn=c,\n\t\t\t$msg=fmt(\"terminating %s\", full_id_string(c))]);\n\t\t}\n\n\telse\n\t\tNOTICE([$note=TerminatingConnectionIgnored, $conn=c,\n\t\t\t$msg=fmt(\"ignoring request to terminate %s\",\n\t\t\t\t\tfull_id_string(c))]);\n\t}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'terminate-connection.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"1ed8e883650e9e80b3308fe3a4d604196a26e876","subject":"Synchronizing the software table now.","message":"Synchronizing the software table now.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"software-ext.bro","new_file":"software-ext.bro","new_contents":"@load global-ext\n@load weird\n\nmodule Software;\n\nexport {\n\t# The hosts whose software should be logged.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts, NoHosts\n\tconst logging = LocalHosts &redef;\n\n\t# In case you are interested in more than logging just local assets\n\t# you can split the log file.\n\tconst split_log_file = F &redef;\n\n\t# Some software can be installed twice on the same server\n\t# with different major numbers.\n\tconst identify_by_major: set[string] = {\n\t\t\"PHP\",\n\t\t\"WebSTAR\",\n\t} &redef;\n\t\n\tredef enum Notice += { \n\t\tSoftware_Version_Change,\n\t};\n\t\n\t# Some software is more interesting when the version changes. This is\n\t# a set of all software that should raise a notice when a different version\n\t# is seen.\n\tconst interesting_version_changes: set[string] = {\n\t\t\"SSH\"\n\t} &redef;\n\t\n\t# Raise this event from other scripts when software is discovered.\n\t# This event is actually defined internally in Bro.\n\t#global software_version_found: event(c: connection, host: addr, s: software, descr: string);\t\n\n\t# Index is the name of the software.\n\ttype software_set: table[string] of software;\n\t# The set of software associated with an address.\n\tglobal host_software: table[addr] of software_set &create_expire=1day &synchronized;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"software-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"software-ext\", cat_sep(\"\\t\", \"\\\\N\", \n\t \"ts\", \"host\", \n\t \"software\", \"version\"));\n\t}\n\n# Compare two versions.\n# Returns -1 for v1 < v2, 0 for v1 == v2, 1 for v1 > v2.\n# If the numerical version numbers match, the addl string\n# is compared lexicographically.\nfunction software_cmp_version(v1: software_version, v2: software_version): int\n\t{\n\tif ( v1$major < v2$major )\n\t\treturn -1;\n\tif ( v1$major > v2$major )\n\t\treturn 1;\n\n\tif ( v1$minor < v2$minor )\n\t\treturn -1;\n\tif ( v1$minor > v2$minor )\n\t\treturn 1;\n\n\tif ( v1$minor2 < v2$minor2 )\n\t\treturn -1;\n\tif ( v1$minor2 > v2$minor2 )\n\t\treturn 1;\n\n\treturn strcmp(v1$addl, v2$addl);\n\t}\n\t\nfunction software_endpoint_name(c: connection, host: addr): string\n\t{\n\treturn fmt(\"%s %s\", host, (host == c$id$orig_h ? \"client\" : \"server\"));\n\t}\n\n# Convert a version into a string \"a.b.c-x\".\nfunction software_fmt_version(v: software_version): string\n\t{\n\treturn fmt(\"%s%s%s%s\",\n\t v$major >= 0 ? fmt(\"%d\", v$major) : \"\",\n\t v$minor >= 0 ? fmt(\".%d\", v$minor) : \"\",\n\t v$minor2 >= 0 ? fmt(\".%d\", v$minor2) : \"\",\n\t v$addl != \"\" ? fmt(\"-%s\", v$addl) : \"\");\n\t}\n\n# Convert a software into a string \"name a.b.cx\".\nfunction software_fmt(s: software): string\n\t{\n\treturn fmt(\"%s %s\", s$name, software_fmt_version(s$version));\n\t}\n\t\nevent software_new(c: connection, host: addr, s: software, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\t{\n\t\tlocal log = LOG::get_file_by_addr(\"software-ext\", host, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), host,\n\t\t s$name, software_fmt_version(s$version), descr);\n\t\t}\n\t}\n\n# Insert a mapping into the table\n# Overides old entries for the same software and generates events if needed.\nevent software_register(c: connection, host: addr, s: software, descr: string)\n\t{\n\t# Host already known?\n\tif ( host !in host_software )\n\t\thost_software[host] = table();\n\n\t# If a software can be installed more than once on a host\n\t# (with a different major version), we identify it by \"-\"\n\tif ( s$name in identify_by_major && s$version$major >= 0 )\n\t\ts$name = fmt(\"%s-%d\", s$name, s$version$major);\n\n\tlocal hs = host_software[host];\n\t# Software already registered for this host?\n\tif ( s$name in hs )\n\t\t{\n\t\tlocal old = hs[s$name];\n\t\t\n\t\t# Is it a potentially interesting version change \n\t\t# and is it a different version?\n\t\tif ( s$name in interesting_version_changes &&\n\t\t software_cmp_version(old$version, s$version) != 0 )\n\t\t\t{\n\t\t\tlocal msg = fmt(\"%.6f %s switched from %s to %s (%s)\",\n\t\t\t\t\tnetwork_time(), software_endpoint_name(c, host),\n\t\t\t\t\tsoftware_fmt_version(old$version),\n\t\t\t\t\tsoftware_fmt(s), descr);\n\t\t\tNOTICE([$note=Software_Version_Change,\n\t\t\t $msg=msg, $sub=software_fmt(s), $conn=c]);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tevent software_new(c, host, s, descr);\n\t\t}\n\n\ths[s$name] = s;\n\t}\n\nevent software_version_found(c: connection, host: addr, s: software,\n\t\t\t\tdescr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\tevent software_register(c, host, s, descr);\n\t}\n\n\n########################################\n# Below are internally defined events. #\n########################################\n\t\nevent software_version_found(c: connection, host: addr, s: software, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\tevent software_register(c, host, s, descr);\n\t}\n\nevent software_parse_error(c: connection, host: addr, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\t{\n\t\t# Here we need a little hack, since software_file is\n\t\t# not always there.\n\t\tlocal msg = fmt(\"%.6f %s: can't parse '%s'\", network_time(),\n\t\t\t\tsoftware_endpoint_name(c, host), descr);\n\n\t\tprint Weird::weird_file, msg;\n\t\t}\n\t}\n\n# I'm not going to handle this at the moment. It doesn't seem terribly useful.\n#event software_unparsed_version_found(c: connection, host: addr, str: string)\n#\t{\n#\tif ( addr_matches_hosts(host, logging) )\n#\t\t{\n#\t\tprint Weird::weird_file, fmt(\"%.6f %s: [%s]\", network_time(),\n#\t\t\t\tsoftware_endpoint_name(c, host), str);\n#\t\t}\n#\t}\n","old_contents":"@load global-ext\n@load weird\n\nmodule Software;\n\nexport {\n\t# The hosts whose software should be logged.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts, NoHosts\n\tconst logging = LocalHosts &redef;\n\n\t# In case you are interested in more than logging just local assets\n\t# you can split the log file.\n\tconst split_log_file = F &redef;\n\n\t# Some software can be installed twice on the same server\n\t# with different major numbers.\n\tconst identify_by_major: set[string] = {\n\t\t\"PHP\",\n\t\t\"WebSTAR\",\n\t} &redef;\n\t\n\tredef enum Notice += { \n\t\tSoftware_Version_Change,\n\t};\n\t\n\t# Some software is more interesting when the version changes. This is\n\t# a set of all software that should raise a notice when a different version\n\t# is seen.\n\tconst interesting_version_changes: set[string] = {\n\t\t\"SSH\"\n\t} &redef;\n\t\n\t# Raise this event from other scripts when software is discovered.\n\t# This event is actually defined internally in Bro.\n\t#global software_version_found: event(c: connection, host: addr, s: software, descr: string);\t\n\n\t# Index is the name of the software.\n\ttype software_set: table[string] of software;\n\t# The set of software associated with an address.\n\tglobal host_software: table[addr] of software_set &create_expire=1day;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"software-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"software-ext\", cat_sep(\"\\t\", \"\\\\N\", \n\t \"ts\", \"host\", \n\t \"software\", \"version\"));\n\t}\n\n# Compare two versions.\n# Returns -1 for v1 < v2, 0 for v1 == v2, 1 for v1 > v2.\n# If the numerical version numbers match, the addl string\n# is compared lexicographically.\nfunction software_cmp_version(v1: software_version, v2: software_version): int\n\t{\n\tif ( v1$major < v2$major )\n\t\treturn -1;\n\tif ( v1$major > v2$major )\n\t\treturn 1;\n\n\tif ( v1$minor < v2$minor )\n\t\treturn -1;\n\tif ( v1$minor > v2$minor )\n\t\treturn 1;\n\n\tif ( v1$minor2 < v2$minor2 )\n\t\treturn -1;\n\tif ( v1$minor2 > v2$minor2 )\n\t\treturn 1;\n\n\treturn strcmp(v1$addl, v2$addl);\n\t}\n\t\nfunction software_endpoint_name(c: connection, host: addr): string\n\t{\n\treturn fmt(\"%s %s\", host, (host == c$id$orig_h ? \"client\" : \"server\"));\n\t}\n\n# Convert a version into a string \"a.b.c-x\".\nfunction software_fmt_version(v: software_version): string\n\t{\n\treturn fmt(\"%s%s%s%s\",\n\t v$major >= 0 ? fmt(\"%d\", v$major) : \"\",\n\t v$minor >= 0 ? fmt(\".%d\", v$minor) : \"\",\n\t v$minor2 >= 0 ? fmt(\".%d\", v$minor2) : \"\",\n\t v$addl != \"\" ? fmt(\"-%s\", v$addl) : \"\");\n\t}\n\n# Convert a software into a string \"name a.b.cx\".\nfunction software_fmt(s: software): string\n\t{\n\treturn fmt(\"%s %s\", s$name, software_fmt_version(s$version));\n\t}\n\t\nevent software_new(c: connection, host: addr, s: software, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\t{\n\t\tlocal log = LOG::get_file_by_addr(\"software-ext\", host, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), host,\n\t\t s$name, software_fmt_version(s$version), descr);\n\t\t}\n\t}\n\n# Insert a mapping into the table\n# Overides old entries for the same software and generates events if needed.\nevent software_register(c: connection, host: addr, s: software, descr: string)\n\t{\n\t# Host already known?\n\tif ( host !in host_software )\n\t\thost_software[host] = table();\n\n\t# If a software can be installed more than once on a host\n\t# (with a different major version), we identify it by \"-\"\n\tif ( s$name in identify_by_major && s$version$major >= 0 )\n\t\ts$name = fmt(\"%s-%d\", s$name, s$version$major);\n\n\tlocal hs = host_software[host];\n\t# Software already registered for this host?\n\tif ( s$name in hs )\n\t\t{\n\t\tlocal old = hs[s$name];\n\t\t\n\t\t# Is it a potentially interesting version change \n\t\t# and is it a different version?\n\t\tif ( s$name in interesting_version_changes &&\n\t\t software_cmp_version(old$version, s$version) != 0 )\n\t\t\t{\n\t\t\tlocal msg = fmt(\"%.6f %s switched from %s to %s (%s)\",\n\t\t\t\t\tnetwork_time(), software_endpoint_name(c, host),\n\t\t\t\t\tsoftware_fmt_version(old$version),\n\t\t\t\t\tsoftware_fmt(s), descr);\n\t\t\tNOTICE([$note=Software_Version_Change,\n\t\t\t $msg=msg, $sub=software_fmt(s), $conn=c]);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tevent software_new(c, host, s, descr);\n\t\t}\n\n\ths[s$name] = s;\n\t}\n\nevent software_version_found(c: connection, host: addr, s: software,\n\t\t\t\tdescr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\tevent software_register(c, host, s, descr);\n\t}\n\n\n########################################\n# Below are internally defined events. #\n########################################\n\t\nevent software_version_found(c: connection, host: addr, s: software, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\tevent software_register(c, host, s, descr);\n\t}\n\nevent software_parse_error(c: connection, host: addr, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\t{\n\t\t# Here we need a little hack, since software_file is\n\t\t# not always there.\n\t\tlocal msg = fmt(\"%.6f %s: can't parse '%s'\", network_time(),\n\t\t\t\tsoftware_endpoint_name(c, host), descr);\n\n\t\tprint Weird::weird_file, msg;\n\t\t}\n\t}\n\n# I'm not going to handle this at the moment. It doesn't seem terribly useful.\n#event software_unparsed_version_found(c: connection, host: addr, str: string)\n#\t{\n#\tif ( addr_matches_hosts(host, logging) )\n#\t\t{\n#\t\tprint Weird::weird_file, fmt(\"%.6f %s: [%s]\", network_time(),\n#\t\t\t\tsoftware_endpoint_name(c, host), str);\n#\t\t}\n#\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"b70c1cc61ef059e3bac8626cddafba696ff0a165","subject":"Remove obsolete load directive","message":"Remove obsolete load directive\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/auto_event.bro","new_file":"custom_scripts\/auto_event.bro","new_contents":"# Configuration\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\n# Simple test event\nglobal remote: event(peer: string, number: int);\n# Dionaea sample events\nglobal dionaea_connection_new: event(timestamp: time, id: count, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string);\nglobal dionaea_connection: event(name: string, timestamp: time, id: count, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string); \n\nevent bro_init() {\n print \"auto_event.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"remote\/event\/\");\n print \"auto_event.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"auto_event.bro: bro_done()\";\n}\n\nevent dionaea_connection(name: string, timestamp: time, id: count, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string) {\n # This doesnt work yet. We want to concat port and transport(=protocol) values to match broker port format (1337\/tcp).\n #local lport = to_port(string_cat(somethingsomething);\n #local rport = to_port(rport_str);\n local lport: port = 1337\/tcp;\n local rport: port = 1337\/tcp;\n print fmt(\"dionaea_connection: name=%s, timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s\", name, timestamp, id, local_ip, local_port, remote_ip, remote_port, transport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport];\n\n Log::write(Dio::LOG, rec);\n}\nevent remote(peer: string, number: int) {\n print fmt(\"remote_event: peer=%s, number=%d\", peer, number);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n","old_contents":"# Configuration\n@load .\/share\/bro\/base\/misc\/dio-log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\n# Simple test event\nglobal remote: event(peer: string, number: int);\n# Dionaea sample events\nglobal dionaea_connection_new: event(timestamp: time, id: count, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string);\nglobal dionaea_connection: event(name: string, timestamp: time, id: count, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string); \n# global dionaea_connection: event(name: string, timestamp: time, protocol: string, local_ip: string, transport: string, remote_ip: string);\nevent bro_init() {\n print \"auto_event.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"remote\/event\/\");\n print \"auto_event.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"auto_event.bro: bro_done()\";\n}\n\nevent dionaea_connection(name: string, timestamp: time, id: count, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string) {\n # This doesnt work yet. We want to concat port and transport(=protocol) values to match broker port format (1337\/tcp).\n #local lport = to_port(string_cat(somethingsomething);\n #local rport = to_port(rport_str);\n local lport: port = 1337\/tcp;\n local rport: port = 1337\/tcp;\n print fmt(\"dionaea_connection: name=%s, timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s\", name, timestamp, id, local_ip, local_port, remote_ip, remote_port, transport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport];\n Log::write(Dio::LOG, rec);\n}\nevent remote(peer: string, number: int) {\n print fmt(\"remote_event: peer=%s, number=%d\", peer, number);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"917b3116d4c02a7e8f135c414d9699a61fb32853","subject":"Oops, I was in the middle of some changes in ftp-ext. Backing them out.","message":"Oops, I was in the middle of some changes in ftp-ext. Backing them out.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ftp-ext.bro","new_file":"ftp-ext.bro","new_contents":"@load global-ext\n@load ftp\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_log = open_log_file(\"ftp-ext\") &raw_output;\n\t\n\ttype ftp_ext_session_info: record {\n\t\tlast_url: string &default=\"\";\n\t\tpassword: string &default=\"\";\n\t};\n\t\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &write_expire=1min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal blah: ftp_ext_session_info;\n\treturn blah;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\t\n\tlocal sess = ftp_sessions[c$id];\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\t# If an anonymous user logged in, record what they used as a password.\n\t\tlocal userpass = ( sess$user in guest_ids ) ?\n\t\t\t\t\t\t\tfmt(\"%s:%s\", sess$user, sess_ext$password) :\n\t\t\t\t\t\t\tsess$user;\n\t\t\n\t\t# If the start directory is unknown, record it as .\/\n\t\tlocal pathfile = sub(absolute_path(sess, arg), \/\/, \"\/.\");\n\t\t\n\t\tsess_ext$last_url = fmt(\"ftp:\/\/%s@%s%s\", userpass, c$id$resp_h, pathfile);\n\t\tprint cat_sep(\"\\t\", \"\\\\N\",\n\t\t\t\t\t\tsess$request_t,\n\t\t\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\t\t\tcommand, sess_ext$last_url);\n\t\t}\n\t}\n\t\n#event ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n#\t{\n#\t#TODO: include reply in logged message\n#\tlocal reply = \"\";\n#\tif ( code in ftp_replies )\n#\t\t reply = ftp_replies[code];\n#\t\t\n#\tprint code;\n#\tprint reply;\n#\t}\n#\t\n#event file_transferred(c: connection, prefix: string, descr: string, mime_type: string)\n#\t{\n#\tprint descr;\n#\t}\n\n","old_contents":"@load global-ext\n@load ftp\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_log = open_log_file(\"ftp-ext\") &raw_output;\n\t\n\ttype ftp_ext_session_info: record {\n\t\tlast_url: string &default=\"\";\n\t\tpassword: string &default=\"\";\n\t};\n\t\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &write_expire=1min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal blah: ftp_ext_session_info;\n\treturn blah;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\t\n\tlocal sess = ftp_sessions[c$id];\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\t# If an anonymous user logged in, record what they used as a password.\n\t\tlocal userpass = ( sess$user in guest_ids ) ?\n\t\t\t\t\t\t\tfmt(\"%s:%s\", sess$user, sess_ext$password) :\n\t\t\t\t\t\t\tsess$user;\n\t\t\n\t\t# If the start directory is unknown, record it as .\/\n\t\tlocal pathfile = sub(absolute_path(sess, arg), \/\/, \"\/.\");\n\t\t\n\t\tsess_ext$last_url = fmt(\"ftp:\/\/%s@%s%s\", userpass, c$id$resp_h, pathfile);\n\t\tprint cat_sep(\"\\t\", \"\\\\N\",\n\t\t\t\t\t\tsess$request_t,\n\t\t\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\t\t\tcommand, sess_ext$last_url);\n\t\t}\n\t}\n\t\nevent ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n\t{\n\t#TODO: include reply in logged message\n\tlocal reply = \"\";\n\tif ( code in ftp_replies )\n\t\t reply = ftp_replies[code];\n\t\t\n\tprint code;\n\tprint reply;\n\t}\n\t\nevent file_transferred(c: connection, prefix: string, descr: string, mime_type: string)\n\t{\n\tprint descr;\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"fe1b4cbf1fbaa94472b95b843eb3190bc6827311","subject":"Create detect-rogue-dns.bro","message":"Create detect-rogue-dns.bro","repos":"albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,theflakes\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/static\/detect-rogue-dns.bro","new_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/static\/detect-rogue-dns.bro","new_contents":"# Detects a Hurricane Panda tactic of using Hurricane Electric to resolve commonly accessed websites\n# Alerts when a domain in the Alexa top 500 is resolved via Hurricane Electric and\/or when a host connects to an IP in the DNS response\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n}\n\n# Current as of 01\/20\/2015\n# alexa.com\/topsites\nconst alexa_table: set[string] = {\n google.com,\n facebook.com,\n youtube.com,\n yahoo.com,\n baidu.com,\n amazon.com,\n wikipedia.org,\n twitter.com,\n taobao.com,\n qq.com,\n google.co.in,\n live.com,\n sina.com.cn,\n weibo.com,\n linkedin.com,\n yahoo.co.jp,\n tmall.com,\n blogspot.com,\n ebay.com,\n hao123.com,\n google.co.jp,\n google.de,\n yandex.ru,\n bing.com,\n sohu.com,\n vk.com,\n instagram.com,\n tumblr.com,\n reddit.com,\n google.co.uk,\n pinterest.com,\n amazon.co.jp,\n wordpress.com,\n msn.com,\n imgur.com,\n google.fr,\n adcash.com,\n google.com.br,\n ask.com,\n paypal.com,\n imdb.com,\n aliexpress.com,\n xvideos.com,\n alibaba.com,\n apple.com,\n fc2.com,\n microsoft.com,\n mail.ru,\n t.co,\n google.it,\n 360.cn,\n google.ru,\n amazon.de,\n google.es,\n kickass.so,\n netflix.com,\n 163.com,\n go.com,\n xinhuanet.com,\n gmw.cn,\n onclickads.net,\n google.com.hk,\n craigslist.org,\n stackoverflow.com,\n xhamster.com,\n people.com.cn,\n google.ca,\n amazon.co.uk,\n naver.com,\n soso.com,\n amazon.cn,\n googleadservices.com,\n pornhub.com,\n bbc.co.uk,\n google.com.tr,\n cnn.com,\n diply.com,\n rakuten.co.jp,\n espn.go.com,\n ebay.de,\n nicovideo.jp,\n dailymotion.com,\n google.com.mx,\n adobe.com,\n cntv.cn,\n flipkart.com,\n google.pl,\n youku.com,\n google.com.au,\n alipay.com,\n ok.ru,\n blogger.com,\n huffingtonpost.com,\n dropbox.com,\n chinadaily.com.cn,\n googleusercontent.com,\n wikia.com,\n nytimes.com,\n google.co.kr,\n ebay.co.uk,\n dailymail.co.uk,\n china.com,\n livedoor.com,\n github.com,\n indiatimes.com,\n pixnet.net,\n jd.com,\n tudou.com,\n sogou.com,\n outbrain.com,\n uol.com.br,\n buzzfeed.com,\n gmail.com,\n xnxx.com,\n google.com.tw,\n blogspot.in,\n amazon.in,\n booking.com,\n google.com.eg,\n chase.com,\n ameblo.jp,\n cnet.com,\n redtube.com,\n pconline.com.cn,\n directrev.com,\n flickr.com,\n amazon.fr,\n douban.com,\n about.com,\n yelp.com,\n wordpress.org,\n dmm.co.jp,\n ettoday.net,\n walmart.com,\n globo.com,\n bankofamerica.com,\n youporn.com,\n bp.blogspot.com,\n youradexchange.com,\n vimeo.com,\n google.com.pk,\n coccoc.com,\n google.nl,\n etsy.com,\n snapdeal.com,\n naver.jp,\n deviantart.com,\n godaddy.com,\n bbc.com,\n daum.net,\n amazonaws.com,\n themeforest.net,\n bestbuy.com,\n aol.com,\n theguardian.com,\n weather.com,\n zol.com.cn,\n google.com.ar,\n adf.ly,\n amazon.it,\n livejasmin.com,\n life.com.tw,\n salesforce.com,\n google.com.sa,\n twitch.tv,\n forbes.com,\n bycontext.com,\n livejournal.com,\n soundcloud.com,\n loading-delivery1.com,\n wikihow.com,\n slideshare.net,\n wellsfargo.com,\n google.gr,\n stackexchange.com,\n jabong.com,\n google.co.id,\n google.co.za,\n leboncoin.fr,\n blogfa.com,\n feedly.com,\n indeed.com,\n ikea.com,\n quora.com,\n ups.com,\n xcar.com.cn,\n espncricinfo.com,\n target.com,\n china.com.cn,\n ziddu.com,\n theadgateway.com,\n allegro.pl,\n businessinsider.com,\n popads.net,\n w3schools.com,\n pixiv.net,\n mozilla.org,\n onet.pl,\n reference.com,\n google.com.ua,\n torrentz.eu,\n 9gag.com,\n mediafire.com,\n files.wordpress.com,\n tubecup.com,\n archive.org,\n wikimedia.org,\n likes.com,\n mailchimp.com,\n tripadvisor.com,\n amazon.es,\n theladbible.com,\n goo.ne.jp,\n usps.com,\n foxnews.com,\n steampowered.com,\n ifeng.com,\n sourceforge.net,\n google.be,\n ndtv.com,\n badoo.com,\n google.co.th,\n zillow.com,\n mystart.com,\n web.de,\n google.com.vn,\n slickdeals.net,\n washingtonpost.com,\n kakaku.com,\n huanqiu.com,\n tianya.cn,\n google.ro,\n skype.com,\n dmm.com,\n ask.fm,\n comcast.net,\n telegraph.co.uk,\n americanexpress.com,\n gmx.net,\n google.com.my,\n secureserver.net,\n bet365.com,\n avg.com,\n mama.cn,\n ign.com,\n force.com,\n akamaihd.net,\n orange.fr,\n gfycat.com,\n steamcommunity.com,\n ppomppu.co.kr,\n gameforge.com,\n answers.com,\n media.tumblr.com,\n google.cn,\n softonic.com,\n google.se,\n newegg.com,\n google.com.co,\n mashable.com,\n reimageplus.com,\n doorblog.jp,\n goodreads.com,\n google.com.ng,\n rediff.com,\n ilividnewtab.com,\n groupon.com,\n stumbleupon.com,\n icicibank.com,\n google.com.sg,\n doublepimp.com,\n google.at,\n wp.pl,\n b5m.com,\n tube8.com,\n rutracker.org,\n chinatimes.com,\n fedex.com,\n abs-cbnnews.com,\n engadget.com,\n zhihu.com,\n caijing.com.cn,\n smzdm.com,\n bild.de,\n pchome.net,\n hdfcbank.com,\n quikr.com,\n rambler.ru,\n amazon.ca,\n google.pt,\n mercadolivre.com.br,\n spiegel.de,\n nfl.com,\n bleacherreport.com,\n t-online.de,\n xuite.net,\n webssearches.com,\n taboola.com,\n weebly.com,\n gizmodo.com,\n hurriyet.com.tr,\n pandora.com,\n shutterstock.com,\n wsj.com,\n gome.com.cn,\n avito.ru,\n what-character-are-you.com,\n homedepot.com,\n seznam.cz,\n youth.cn,\n pclady.com.cn,\n iqiyi.com,\n nih.gov,\n usatoday.com,\n vice.com,\n lifehacker.com,\n webmd.com,\n wix.com,\n hulu.com,\n ebay.in,\n samsung.com,\n hp.com,\n hootsuite.com,\n google.dz,\n extratorrent.cc,\n accuweather.com,\n addthis.com,\n firstmediahub.com,\n speedtest.net,\n kompas.com,\n google.ch,\n ameba.jp,\n macys.com,\n gsmarena.com,\n liveinternet.ru,\n milliyet.com.tr,\n photobucket.com,\n fiverr.com,\n hupu.com,\n 39.net,\n dell.com,\n youm7.com,\n adsrvmedia.net,\n wow.com,\n 4shared.com,\n microsoftonline.com,\n github.io,\n bilibili.com,\n varzesh3.com,\n retailmenot.com,\n myntra.com,\n mobile01.com,\n google.com.pe,\n google.com.bd,\n udn.com,\n capitalone.com,\n tistory.com,\n spotify.com,\n evernote.com,\n theverge.com,\n babytree.com,\n liputan6.com,\n xda-developers.com,\n att.com,\n omiga-plus.com,\n google.com.ph,\n nba.com,\n techcrunch.com,\n wordreference.com,\n google.no,\n battle.net,\n office.com,\n uploaded.net,\n reuters.com,\n libero.it,\n in.com,\n rt.com,\n disqus.com,\n google.co.hu,\n ebay.com.au,\n rbc.ru,\n google.cz,\n time.com,\n goal.com,\n google.ae,\n hstpnetwork.com,\n moz.com,\n intoday.in,\n rottentomatoes.com,\n aili.com,\n goodgamestudios.com,\n lady8844.com,\n onlinesbi.com,\n hudong.com,\n kaskus.co.id,\n twimg.com,\n stylene.net,\n teepr.com,\n zendesk.com,\n google.ie,\n gap.com,\n codecanyon.net,\n yandex.ua,\n verizonwireless.com,\n olx.in,\n okcupid.com,\n bloomberg.com,\n nordstrom.com,\n google.co.il,\n justdial.com,\n intuit.com,\n googleapis.com,\n trackingclick.net,\n ltn.com.tw,\n sahibinden.com,\n 2ch.net,\n free.fr,\n so.com,\n ebay.it,\n thefreedictionary.com,\n csdn.net,\n 12306.cn,\n meetup.com,\n trello.com,\n fbcdn.net,\n autohome.com.cn,\n cnzz.com,\n kinopoisk.ru,\n dsrlte.com,\n gmarket.co.kr,\n detik.com,\n staticwebdom.com,\n marca.com,\n bhaskar.com,\n chinaz.com,\n naukri.com,\n ganji.com,\n gamefaqs.com,\n kohls.com,\n eksisozluk.com,\n ero-advertising.com,\n agoda.com,\n expedia.com,\n npr.org,\n bitly.com,\n mackeeper.com,\n styletv.com.cn,\n allrecipes.com,\n repubblica.it,\n google.fi,\n exoclick.com,\n kickstarter.com,\n baomihua.com,\n beeg.com,\n sears.com,\n mbtrx.com,\n faithtap.com,\n citibank.com,\n ehow.com,\n cloudfront.net,\n tmz.com,\n blog.jp,\n hostgator.com,\n doubleclick.com,\n media1first.com,\n jmpdirect01.com,\n livedoor.biz,\n slimspots.com,\n abcnews.go.com,\n oracle.com,\n chaturbate.com,\n scribd.com,\n outlook.com,\n eyny.com,\n popcash.net,\n xe.com,\n mega.co.nz,\n ink361.com,\n gawker.com,\n sex.com,\n woot.com,\n xywy.com,\n lemonde.fr,\n asos.com,\n ci123.com,\n zippyshare.com,\n chip.de,\n elpais.com,\n putlocker.is,\n nbcnews.com,\n php.net,\n nyaa.se,\n eastday.com,\n google.az,\n list-manage.com,\n eonline.com,\n foodnetwork.com,\n google.dk,\n independent.co.uk,\n statcounter.com\n} &redef;\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n\n # Clean the sub-message.\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/static\/detect-rogue-dns.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"5dd8e794351d445aeb68890bcc038561f3ac1cfe","subject":"tweak interval, fix calculation","message":"tweak interval, fix calculation\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-size-metrics.bro","new_file":"http-size-metrics.bro","new_contents":"@load base\/frameworks\/metrics\n@load base\/protocols\/http\n@load base\/protocols\/ssl\n@load base\/utils\/site\n\nredef enum Metrics::ID += {\n\tHTTP_REQUEST_SIZE_BY_HOST,\n};\n\nredef record connection += {\n resp_hostname: string &optional;\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_REQUEST_SIZE_BY_HOST,\n [$name=\"all\",\n $break_interval=600secs\n ]);\n\n}\n\n\nevent connection_finished(c: connection)\n{\n if (c?$resp_hostname) {\n local size = c$orig$num_bytes_ip + c$resp$num_bytes_ip;\n Metrics::add_data(HTTP_REQUEST_SIZE_BY_HOST, [$str=c$resp_hostname], size);\n }\n}\n\nevent http_header (c: connection, is_orig: bool, name: string, value: string)\n{\n if(name == \"HOST\") {\n c$resp_hostname = value;\n }\n}\n\nevent ssl_established(c: connection)\n{\n if(c?$ssl && c$ssl?$server_name) {\n c$resp_hostname = c$ssl$server_name;\n }\n}\n\n","old_contents":"@load base\/frameworks\/metrics\n@load base\/protocols\/http\n@load base\/protocols\/ssl\n@load base\/utils\/site\n\nredef enum Metrics::ID += {\n\tHTTP_REQUEST_SIZE_BY_HOST,\n};\n\nredef record connection += {\n resp_hostname: string &optional;\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_REQUEST_SIZE_BY_HOST,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n\n}\n\n\nevent connection_finished(c: connection)\n{\n if (c?$resp_hostname) {\n local size = c$orig$size + c$resp$size;\n Metrics::add_data(HTTP_REQUEST_SIZE_BY_HOST, [$str=c$resp_hostname], size);\n }\n}\n\nevent http_header (c: connection, is_orig: bool, name: string, value: string)\n{\n if(name == \"HOST\") {\n c$resp_hostname = value;\n }\n}\n\nevent ssl_established(c: connection)\n{\n if(c?$ssl && c$ssl?$server_name) {\n c$resp_hostname = c$ssl$server_name;\n }\n}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"31bdf8a8e602b9bc88cf51f3d3bf5bc79996ed04","subject":"fix kafka local.bro #11","message":"fix kafka local.bro #11\n","repos":"blacktop\/docker-bro","old_file":"kafka\/local.bro","new_file":"kafka\/local.bro","new_contents":"##! Local site policy. Customize as appropriate.\n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n\n# Estimate and log capture loss.\n@load misc\/capture-loss\n\n# Enable logging of memory, packet and lag statistics.\n@load misc\/stats\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Detect traceroute being run on the network. This could possibly cause\n# performance trouble when there are a lot of traceroutes on your network.\n# Enable cautiously.\n#@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more\n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when\n# running on live traffic. Enable it cautiously.\n@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets\n# where the name is not part of your local DNS zone and is being hosted\n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n@load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and\n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\n\n# Uncomment the following line to enable logging of connection VLANs. Enabling\n# this adds two VLAN fields to the conn.log file.\n@load policy\/protocols\/conn\/vlan-logging\n\n# Uncomment the following line to enable logging of link-layer addresses. Enabling\n# this adds the link-layer address for each connection endpoint to the conn.log file.\n@load policy\/protocols\/conn\/mac-logging\n\n# Uncomment the following line to enable the SMB analyzer. The analyzer\n# is currently considered a preview and therefore not loaded by default.\n@load policy\/protocols\/smb\n\n# Kafka Plugin\n@load Apache\/Kafka\nredef Kafka::logs_to_send = set(Conn::LOG, HTTP::LOG, SSL::LOG, Files::LOG, DNS::LOG, FTP::LOG, SMTP::LOG, X509::LOG, Notice::LOG);\nredef Kafka::kafka_conf = table(\n [\"metadata.broker.list\"] = \"kafka:9092\"\n);\nredef Kafka::topic_name = \"bro\";\nredef Kafka::max_wait_on_shutdown = 3000;\nredef Kafka::tag_json = T;\n","old_contents":"##! Local site policy. Customize as appropriate.\n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n\n# Estimate and log capture loss.\n@load misc\/capture-loss\n\n# Enable logging of memory, packet and lag statistics.\n@load misc\/stats\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Detect traceroute being run on the network. This could possibly cause\n# performance trouble when there are a lot of traceroutes on your network.\n# Enable cautiously.\n#@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more\n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when\n# running on live traffic. Enable it cautiously.\n@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets\n# where the name is not part of your local DNS zone and is being hosted\n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n@load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and\n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\n\n# Uncomment the following line to enable logging of connection VLANs. Enabling\n# this adds two VLAN fields to the conn.log file.\n@load policy\/protocols\/conn\/vlan-logging\n\n# Uncomment the following line to enable logging of link-layer addresses. Enabling\n# this adds the link-layer address for each connection endpoint to the conn.log file.\n@load policy\/protocols\/conn\/mac-logging\n\n# Uncomment the following line to enable the SMB analyzer. The analyzer\n# is currently considered a preview and therefore not loaded by default.\n@load policy\/protocols\/smb\n\n# Kafka Plugin\n@load packages\/metron-bro-plugin-kafka\/Apache\/Kafka\nredef Kafka::logs_to_send = set(Conn::LOG, HTTP::LOG, SSL::LOG, Files::LOG, DNS::LOG, FTP::LOG, SMTP::LOG, X509::LOG, Notice::LOG);\nredef Kafka::kafka_conf = table(\n [\"metadata.broker.list\"] = \"kafka:9092\"\n);\nredef Kafka::topic_name = \"bro\";\nredef Kafka::max_wait_on_shutdown = 3000;\nredef Kafka::tag_json = T;\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"2f619cb0dee6fbb5d72e4df43c9b0dbcc723f66e","subject":"Create dns-answers.bro","message":"Create dns-answers.bro","repos":"albertzaharovits\/cs-bro,kingtuna\/cs-bro,theflakes\/cs-bro,CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro","old_file":"bro-scripts\/intel-extensions\/seen\/dns-answers.bro","new_file":"bro-scripts\/intel-extensions\/seen\/dns-answers.bro","new_contents":"# Intel framework support for DNS answers \n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/dns\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent dns_end(c: connection, msg: dns_msg)\n{\nif ( c$dns?$answers )\n {\n local ans = c$dns$answers;\n for ( i in ans )\n {\n if ( ans[i] == ip_addr_regex )\n Intel::seen([$host=to_addr(ans[i]),\n $conn=c,\n $where=DNS::IN_RESPONSE]);\n else\n Intel::seen([$indicator=ans[i],\n $indicator_type=Intel::DOMAIN,\n $conn=c,\n $where=DNS::IN_RESPONSE]);\n }\n }\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/intel-extensions\/seen\/dns-answers.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"207e5e40b283485c6b625862d889d970c211ce91","subject":"Don't sort the \"received from\" IP addresses, there seems to be a vector sorting bug currently.","message":"Don't sort the \"received from\" IP addresses, there seems to be a vector sorting bug currently.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"@load global-ext\n@load smtp\n\ntype smtp_ext_session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: addr &default=0.0.0.0;\n\treceived_from_originating_ip: addr &default=0.0.0.0;\n\tfirst_received: string &default=\"\";\n\tsecond_received: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: set[string];\n\tpath: vector of addr;\n\tis_webmail: bool &default=F; # This is not being set yet.\n\tagent: string &default=\"\";\n\t\n\t# These are used during processing and are likely less useful.\n\tcurrent_header: string &default=\"\";\n\tin_received_from_headers: bool &default=F;\n\treceived_finished: bool &default=F;\n};\n\nfunction default_smtp_ext_session_info(): smtp_ext_session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\tlocal tmp3: set[string] = set();\n\tlocal tmp4: vector of addr = vector(0.0.0.0);\n\treturn [$rcptto=tmp, $to=tmp2, $files=tmp3, $path=tmp4];\n\t}\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, si: smtp_ext_session_info);\n\nmodule SMTP;\n\nexport {\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Direction to capture the full \"Received from\" path.\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/b\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/\n\t | \/uceprotect\\.net\\\/\/\n\t | \/hostkarma\\.junkemailfilter\\.com\\\/\/ &redef;\n\t\n\tglobal conn_info: table[conn_id] of smtp_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\t\n}\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\telse if ( |ips| > 0 )\n\t\treturn ips[1];\n\telse\n\t\treturn \"\";\n}\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != 0.0.0.0 )\n\t\t{\n\t\tip = conn_log$x_originating_ip;\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != 0.0.0.0 &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = conn_log$received_from_originating_ip;\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\t\n\t# FIXME: I'm seeing crashes from this. We'll delay and just use the \n\t# last element of the vector for the software event for now.\n\t# reverse the \"received from\" path\n\t#sort(conn_log$path, function(a:addr, b:addr):int { return -1; });\n\t# if the MUA provided a user-agent string, raise the software event.\n\tif ( conn_log$agent != \"\" )\n\t\t{\n\t\tlocal s = default_software_parsing(conn_log$agent);\n\t\tevent software_version_found(c, conn_log$path[|conn_log$path|], s, \"MUA\");\n\t\t}\n\n\t# Throw the event for other scripts to handle\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_smtp_ext_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\n\t\t# Start off the received from headers with this connection\n\t\tconn_info[id]$path[1] = c$id$resp_h;\n\t\tconn_info[id]$path[2] = c$id$orig_h;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_smtp_ext_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\t\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tadd conn_info[id]$files[data];\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$current_header == \"received\" )\n\t\t\tconn_log$first_received += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\telse if ( conn_log$current_header == \"agent\" )\n\t\t\tconn_log$agent += data;\t\t\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\n\telse if ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$second_received = conn_log$first_received;\n\t\tconn_log$first_received = split1(data, \/:[[:blank:]]*\/)[2];\n\t\t# Fill in the second value in case there is only one hop in the message.\n\t\tif ( conn_log$second_received == \"\" )\n\t\t\tconn_log$second_received = conn_log$first_received;\n\t\t\n\t\tconn_log$current_header = \"received\";\n\t\t}\n\t\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tlocal addresses = find_ip_addresses(data);\n\t\tif ( |addresses| > 0 )\n\t\t\tconn_log$x_originating_ip = to_addr(addresses[1]);\n\t\telse\n\t\t\tconn_log$x_originating_ip = to_addr(data);\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\telse if ( \/^[xX]-[mM][aA][iI][lL][eE][rR]:[[:blank:]]*.\/ | \n\t \/^[uU][sS][eE][rR]-[aA][gG][eE][nN][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$agent = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"agent\";\n\t\t}\n\t}\n\t\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header )\n\t\treturn;\n\n\tlocal conn_log = conn_info[id];\n\t\n\t# If we've decided that we're done watching the received headers, we're done.\n\tif ( conn_log$received_finished )\n\t\treturn;\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tconn_log$in_received_from_headers = T;\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tconn_log$in_received_from_headers = F;\n\n\tif ( conn_log$in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\n\t\tlocal ip = to_addr(text_ip);\n\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = ip;\n\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tconn_log$received_finished=T;\n\t\t\t}\n\n\t\tconn_log$path[|conn_log$path|+1] = ip;\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && !conn_log$received_finished ) \n\t\tconn_log$received_finished=T;\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"@load global-ext\n@load smtp\n\ntype smtp_ext_session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: addr &default=0.0.0.0;\n\treceived_from_originating_ip: addr &default=0.0.0.0;\n\tfirst_received: string &default=\"\";\n\tsecond_received: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: set[string];\n\tpath: vector of addr;\n\tis_webmail: bool &default=F; # This is not being set yet.\n\tagent: string &default=\"\";\n\t\n\t# These are used during processing and are likely less useful.\n\tcurrent_header: string &default=\"\";\n\tin_received_from_headers: bool &default=F;\n\treceived_finished: bool &default=F;\n};\n\nfunction default_smtp_ext_session_info(): smtp_ext_session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\tlocal tmp3: set[string] = set();\n\tlocal tmp4: vector of addr = vector(0.0.0.0);\n\treturn [$rcptto=tmp, $to=tmp2, $files=tmp3, $path=tmp4];\n\t}\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, si: smtp_ext_session_info);\n\nmodule SMTP;\n\nexport {\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Direction to capture the full \"Received from\" path.\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/b\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/\n\t | \/uceprotect\\.net\\\/\/\n\t | \/hostkarma\\.junkemailfilter\\.com\\\/\/ &redef;\n\t\n\tglobal conn_info: table[conn_id] of smtp_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\t\n}\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\telse if ( |ips| > 0 )\n\t\treturn ips[1];\n\telse\n\t\treturn \"\";\n}\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != 0.0.0.0 )\n\t\t{\n\t\tip = conn_log$x_originating_ip;\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != 0.0.0.0 &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = conn_log$received_from_originating_ip;\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\t\n\t# reverse the \"received from\" path\n\tsort(conn_log$path, function(a:addr, b:addr):int { return -1; });\n\t# if the MUA provided a user-agent string, raise the software event.\n\tif ( conn_log$agent != \"\" )\n\t\t{\n\t\tlocal s = default_software_parsing(conn_log$agent);\n\t\tevent software_version_found(c, conn_log$path[1], s, \"MUA\");\n\t\t}\n\n\t# Throw the event for other scripts to handle\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_smtp_ext_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\n\t\t# Start off the received from headers with this connection\n\t\tconn_info[id]$path[1] = c$id$resp_h;\n\t\tconn_info[id]$path[2] = c$id$orig_h;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_smtp_ext_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\t\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tadd conn_info[id]$files[data];\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$current_header == \"received\" )\n\t\t\tconn_log$first_received += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\telse if ( conn_log$current_header == \"agent\" )\n\t\t\tconn_log$agent += data;\t\t\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\n\telse if ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$second_received = conn_log$first_received;\n\t\tconn_log$first_received = split1(data, \/:[[:blank:]]*\/)[2];\n\t\t# Fill in the second value in case there is only one hop in the message.\n\t\tif ( conn_log$second_received == \"\" )\n\t\t\tconn_log$second_received = conn_log$first_received;\n\t\t\n\t\tconn_log$current_header = \"received\";\n\t\t}\n\t\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tlocal addresses = find_ip_addresses(data);\n\t\tif ( |addresses| > 0 )\n\t\t\tconn_log$x_originating_ip = to_addr(addresses[1]);\n\t\telse\n\t\t\tconn_log$x_originating_ip = to_addr(data);\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\telse if ( \/^[xX]-[mM][aA][iI][lL][eE][rR]:[[:blank:]]*.\/ | \n\t \/^[uU][sS][eE][rR]-[aA][gG][eE][nN][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$agent = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"agent\";\n\t\t}\n\t}\n\t\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header )\n\t\treturn;\n\n\tlocal conn_log = conn_info[id];\n\t\n\t# If we've decided that we're done watching the received headers, we're done.\n\tif ( conn_log$received_finished )\n\t\treturn;\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tconn_log$in_received_from_headers = T;\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tconn_log$in_received_from_headers = F;\n\n\tif ( conn_log$in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\n\t\tlocal ip = to_addr(text_ip);\n\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = ip;\n\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tconn_log$received_finished=T;\n\t\t\t}\n\n\t\tconn_log$path[|conn_log$path|+1] = ip;\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && !conn_log$received_finished ) \n\t\tconn_log$received_finished=T;\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"9bb304acf366e043f9338b8ef8777ed35d7aadf3","subject":"update to use new logging framework","message":"update to use new logging framework\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logging = All &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", logging, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !resp_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", info$c$id$orig_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\tconst log = open_log_file(\"ssl-known-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !resp_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"9841e6737e53839be5791a7414ef47ead3760314","subject":"Huge changes to smtp-ext (additions, fixes, .and code refactoring)","message":"Huge changes to smtp-ext (additions, fixes, .and code refactoring)\n\nNew notice:\n SMTP_Suspicious_Origination - Thrown when mail appears to originate from\n a network or country where unwanted mail typically originates for your site.\n\nNew data logged:\n x-originating-ip\n files transferred in the email\n\nNew smtp block lists:\n mail-abuse.com\n bbl.barracudacentral.com\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\tlocal session = smtp_sessions[id];\n\n\tif ( id !in conn_info || \n\t\t !session$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\n# This is a locally defined event. Handle it with a priority greater than\n# negative 5 if you want to dig into the conn_info record before it's deleted.\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s). Subject: %s\", loc$country_code, ip, conn_log$subject),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(id);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t};\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=10secs;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal text_ip = \"\";\n\tlocal parts: string_array;\n\tif ( \/\\[.*\\]\/ in header )\n\t\tparts = split(header, \/[\\[\\]]\/);\n\telse if ( \/\\(.*\\)\/ in header )\n\t\tparts = split(header, \/[\\(\\)]\/);\n\n\tif (|parts| > 1)\n\t\t{\n\t\tif ( |parts| > 3 && parts[4] == ip_addr_regex )\n\t\t\ttext_ip = parts[4];\n\t\telse if ( parts[2] == ip_addr_regex )\n\t\t\ttext_ip = parts[2];\n\t\t}\n\treturn text_ip;\n}\n\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\t\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\n\tif ( \/^[^[:blank:]]*?:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tdelete in_received_from_headers[id];\n\tif ( \/^Received:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tadd in_received_from_headers[id];\n\t\n\tlocal session = smtp_sessions[id];\n\t\n\tif ( session$in_header && # headers are currently being analyzed \n\t id in in_received_from_headers && # currently seeing received from headers\n\t id !in smtp_received_finished && # we don't want to stop seeing this message yet\n\t \/[\\[\\(]\/ in data ) # the line might contain an ip address\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n \n\t\t# check for valid-ish ip - some mtas are weird.\n\t\tif ( is_valid_ip(text_ip) )\n\t\t\t{\n\t\t\tlocal ip = to_addr(text_ip);\n\t\t\t\n\t\t\t# I don't care if mail bounces around on localhost\n\t\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\t\n\t\t\tif ( addr_matches_hosts(ip, mail_path_capture) || \n\t\t\t ip in private_address_space )\n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t} \n\t\t\telse \n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t\n\t\t\t\tadd smtp_received_finished[id]; \n\t\t\t\t}\n\t\t\t}\n\t\t} \n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\t{\n\t\tadd smtp_received_finished[id];\n\t\t}\n\t}\n\n\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tif ( id !in conn_info )\n\t\treturn;\n\tlocal conn_log = conn_info[id];\n\t\n\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t conn_log$helo, conn_log$msg_id, conn_log$in_reply_to, \n\t conn_log$mailfrom, fmt_str_set(conn_log$rcptto, \/[\\\"\\'<>]|([[:blank:]].*$)\/),\n\t conn_log$date, conn_log$from, conn_log$reply_to, fmt_str_set(conn_log$to, \/[\\\"\\']\/),\n\t conn_log$last_reply, smtp_forward_paths[id]);\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( code >= 400 && id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal msg_parts = split_all(msg, ip_addr_regex);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |msg_parts| > 2 )\n\t\t\t\ttext_ip = msg_parts[2];\n\t\t\tif ( is_valid_ip(text_ip) && to_addr(text_ip) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note, \n\t\t\t $conn=c, \n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id in smtp_sessions )\n\t\t{\n\t\tif ( id !in conn_info )\n\t\t\tconn_info[id] = default_session_info();\n\t\tlocal conn_log = conn_info[id];\n\t\t\n\t\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\t\tconn_log$helo = arg;\n\t\t\n\t\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\t\n\t\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t\t{\n\t\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t \treturn;\n\n\tlocal conn_log = conn_info[id];\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]\/ in data )\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[dD][aA][tT][eE]:[[:blank:]]\/ in data )\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[fF][rR][oO][mM]:[[:blank:]]\/ in data )\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[tT][oO]:[[:blank:]]\/ in data )\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\n\tif ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"39aee7d701ec526b21386758a2f3de7cb6930d32","subject":"indent 4","message":"indent 4\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_slave\/bro_slave.bro","new_file":"scripts_slave\/bro_slave.bro","new_contents":"@load .\/slave_log.bro\n\nredef exit_only_after_terminate = T;\n\n# the ports and IPs that are externally routable for a master and this slave\nconst slave_broker_port: string = getenv(\"SLAVE_PUBLIC_PORT\") &redef;\nconst slave_broker_ip: string = getenv(\"SLAVE_PUBLIC_IP\") &redef;\nconst master_broker_port: port = to_port(cat(getenv(\"MASTER_PUBLIC_PORT\"), \"\/tcp\")) &redef;\nconst master_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\n\nredef Broker::endpoint_name = cat(\"bro-slave-\", slave_broker_ip, \":\", slave_broker_port);\n\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string);\nglobal dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal log_bro: function(msg: string);\nglobal published_events: set[string] = { \"dionaea_access\", \"dionaea_ftp\", \"dionaea_mysql_command\", \"dionaea_mysql_login\", \"dionaea_download_complete\", \"dionaea_download_offer\", \"dionaea_smb_request\", \"dionaea_smb_bind\" };\n\n\nevent bro_init() {\n log_bro(\"bro_slave.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n \n # Listening\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n \n # Forwarding\n Broker::connect(master_broker_ip, master_broker_port, 1sec);\n Broker::register_broker_events(\"honeypot\/dionaea\", published_events);\n\n # Try unsolicited option, which should prevent topic issues\n Broker::auto_event(\"honeypot\/dionaea\", dionaea_access);\n log_bro(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n log_bro(\"bro_slave.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n event dionaea_access(timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n}\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n\n event dionaea_ftp(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, command, arguments, origin, connector_id);\n}\nevent dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n\n event dionaea_mysql_command(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, args, origin, connector_id);\n}\nevent dionaea_mysql_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n\n event dionaea_mysql_login(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, username, password, origin, connector_id);\n}\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n\n event dionaea_download_complete(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, md5hash, filelocation, origin, connector_id);\n}\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n event dionaea_download_offer(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, origin, connector_id);\n}\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n\n event dionaea_smb_request(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, opnum, uuid, origin, connector_id);\n}\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n\n event dionaea_smb_bind(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, transfersyntax, uuid, origin, connector_id);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n log_bro(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n log_bro(msg);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address; \n log_bro(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n log_bro(msg);\n}\nfunction log_bro(msg: string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n","old_contents":"@load .\/slave_log.bro\n\nredef exit_only_after_terminate = T;\n\n# the ports and IPs that are externally routable for a master and this slave\nconst slave_broker_port: string = getenv(\"SLAVE_PUBLIC_PORT\") &redef;\nconst slave_broker_ip: string = getenv(\"SLAVE_PUBLIC_IP\") &redef;\nconst master_broker_port: port = to_port(cat(getenv(\"MASTER_PUBLIC_PORT\"), \"\/tcp\")) &redef;\nconst master_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\n\nredef Broker::endpoint_name = cat(\"bro-slave-\", slave_broker_ip, \":\", slave_broker_port);\n\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string);\nglobal dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal log_bro: function(msg: string);\nglobal published_events: set[string] = { \"dionaea_access\", \"dionaea_ftp\", \"dionaea_mysql_command\", \"dionaea_mysql_login\", \"dionaea_download_complete\", \"dionaea_download_offer\", \"dionaea_smb_request\", \"dionaea_smb_bind\" };\n\n\nevent bro_init() {\n log_bro(\"bro_slave.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n \n # Listening\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n \n # Forwarding\n Broker::connect(master_broker_ip, master_broker_port, 1sec);\n Broker::register_broker_events(\"honeypot\/dionaea\", published_events);\n\n # Try unsolicited option, which should prevent topic issues\n Broker::auto_event(\"honeypot\/dionaea\", dionaea_access);\n log_bro(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n log_bro(\"bro_slave.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n event dionaea_access(timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n}\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n\n event dionaea_ftp(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, command, arguments, origin, connector_id);\n}\nevent dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n\n event dionaea_mysql_command(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, args, origin, connector_id);\n}\nevent dionaea_mysql_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n\n event dionaea_mysql_login(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, username, password, origin, connector_id);\n}\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n\n event dionaea_download_complete(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, md5hash, filelocation, origin, connector_id);\n}\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n event dionaea_download_offer(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, origin, connector_id);\n}\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n\n event dionaea_smb_request(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, opnum, uuid, origin, connector_id);\n}\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n\n event dionaea_smb_bind(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, transfersyntax, uuid, origin, connector_id);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n log_bro(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address; \n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n log_bro(msg);\n}\n\nfunction log_bro(msg: string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"2952bdd096210d289164f291091ab1386c7fb7c1","subject":"Create ja3.bro","message":"Create ja3.bro","repos":"jatkins-sfdc\/ja3,salesforce\/ja3","old_file":"bro\/ja3.bro","new_file":"bro\/ja3.bro","new_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.2 (March 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n## LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n## LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n## FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","old_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.2 (March 2017)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n## LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n## LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n## FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"97bb6a71f34206b50d344b572bf91e7ab4c3edf3","subject":"Spelling fix","message":"Spelling fix\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext.bro","new_file":"ssh-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n@load functions-ext\n\nmodule SSH;\n\nexport {\n\tconst login_log = open_log_file(\"ssh-logins\") &redef;\n\t\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &write_expire=guessing_timeout+1hr;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# This is a table with orig host as the key, and resp host as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t SSH_Login,\n\t SSH_PasswordGuessing,\n\t SSH_LoginByPasswordGuesser,\n\t};\n} \n\nglobal ssh_conns:set[conn_id];\nglobal ssh_watching:bool = F;\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\nevent check_ssh_connection(c: connection)\n\t{\n\t# make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal message = \"\";\n\tif ( c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tmessage = fmt(\"Failed SSH login %s (saw %d bytes)\",\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\tprint login_log, fmt(\"%.6f %s\", network_time(), message);\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\t\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\t\t\tlocal location = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\t\tmessage = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t\t direction, location$country_code, location$region, location$city,\n\t\t\t location$latitude, location$longitude,\n\t\t\t numeric_id_string(c$id), c$resp$size);\n\t\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\t\tNOTICE([$note=SSH_Login,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=location$country_code]);\n\t\t\tprint login_log, fmt(\"%.6f %s\", network_time(), message);\n\t\t}\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tif ( c$id !in ssh_conns )\n\t\treturn;\n\t\n\tdelete ssh_conns[c$id];\n\tevent check_ssh_connection(c);\n\t}\n\nevent ssh_watcher()\n\t{\n\tfor ( id in ssh_conns )\n\t\t{\n\t\t# don't go any further if this connection is gone already!\n\t\tif ( !connection_exists(id) )\n\t\t\tnext;\n\n\t\tlocal c = lookup_connection(id);\n\t\tevent check_ssh_connection(c);\n\n\t\t# Stop watching this connection, we don't care about it anymore.\n\t\tskip_further_processing(c$id);\n\t\tset_record_packets(c$id, F);\n\t\tdelete ssh_conns[id];\n\t\t}\n\n\tif ( |ssh_conns| > 0 )\n\t\tschedule +2mins { ssh_watcher() };\n\telse\n\t\tssh_watching = F;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tadd ssh_conns[c$id];\n\t\tif (!ssh_watching)\n\t\t\t{\n\t\t\tssh_watching = T;\n\t\t\t# TODO: change this to have a scheduled task per-connection\n\t\t\tschedule +2mins { ssh_watcher() }; \n\t\t\t}\n\t\t}\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n@load functions-ext\n\nmodule SSH;\n\nexport {\n\tconst login_log = open_log_file(\"ssh-logins\") &redef;\n\t\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &write_expire=guessing_timeout+1hr;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful logins\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# This is a table with orig host as the key, and resp host as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t SSH_Login,\n\t SSH_PasswordGuessing,\n\t SSH_LoginByPasswordGuesser,\n\t};\n} \n\nglobal ssh_conns:set[conn_id];\nglobal ssh_watching:bool = F;\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\nevent check_ssh_connection(c: connection)\n\t{\n\t# make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal message = \"\";\n\tif ( c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tmessage = fmt(\"Failed SSH login %s (saw %d bytes)\",\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\tprint login_log, fmt(\"%.6f %s\", network_time(), message);\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\t\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\t\t\tlocal location = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\t\tmessage = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t\t direction, location$country_code, location$region, location$city,\n\t\t\t location$latitude, location$longitude,\n\t\t\t numeric_id_string(c$id), c$resp$size);\n\t\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\t\tNOTICE([$note=SSH_Login,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=location$country_code]);\n\t\t\tprint login_log, fmt(\"%.6f %s\", network_time(), message);\n\t\t}\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tif ( c$id !in ssh_conns )\n\t\treturn;\n\t\n\tdelete ssh_conns[c$id];\n\tevent check_ssh_connection(c);\n\t}\n\nevent ssh_watcher()\n\t{\n\tfor ( id in ssh_conns )\n\t\t{\n\t\t# don't go any further if this connection is gone already!\n\t\tif ( !connection_exists(id) )\n\t\t\tnext;\n\n\t\tlocal c = lookup_connection(id);\n\t\tevent check_ssh_connection(c);\n\n\t\t# Stop watching this connection, we don't care about it anymore.\n\t\tskip_further_processing(c$id);\n\t\tset_record_packets(c$id, F);\n\t\tdelete ssh_conns[id];\n\t\t}\n\n\tif ( |ssh_conns| > 0 )\n\t\tschedule +2mins { ssh_watcher() };\n\telse\n\t\tssh_watching = F;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tadd ssh_conns[c$id];\n\t\tif (!ssh_watching)\n\t\t\t{\n\t\t\tssh_watching = T;\n\t\t\t# TODO: change this to have a scheduled task per-connection\n\t\t\tschedule +2mins { ssh_watcher() }; \n\t\t\t}\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"15880156eed6f036fc87a7a464a59db4737cf380","subject":"Create intel_ja3.bro","message":"Create intel_ja3.bro","repos":"salesforce\/ja3,jatkins-sfdc\/ja3","old_file":"bro\/intel_ja3.bro","new_file":"bro\/intel_ja3.bro","new_contents":"# This Bro script adds JA3 to the Bro Intel Framework as Intel::JA3\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule Intel;\n\nexport {\n redef enum Intel::Type += { Intel::JA3 };\n}\n\nexport {\n redef enum Intel::Where += { SSL::IN_JA3 };\n}\n\nevent ssl_server_hello (c: connection, version: count, possible_ts: time, server_random: string, session_id: string, cipher: count, comp_method: count)\n\t{\n\tIntel::seen([$indicator=c$ssl$ja3, $indicator_type=Intel::JA3, $conn=c, $where=SSL::IN_JA3]);\n\t}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro\/intel_ja3.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"7cf3797943563e7fcc3de6d7d89b4f738fd0b93a","subject":"Add ASN to conn log entries.","message":"Add ASN to conn log entries.\n","repos":"mocyber\/rock-scripts","old_file":"misc\/conn-add-geoip.bro","new_file":"misc\/conn-add-geoip.bro","new_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\n##! Add geo_location for the originator and responder of a connection\n##! to the connection logs.\n\nmodule Conn;\n\nexport\n{\n redef record Conn::Info +=\n {\n orig_location: string &optional &log;\n resp_location: string &optional &log;\n orig_country_code: string &optional &log;\n resp_country_code: string &optional &log;\n orig_asn: count &log &optional;\n resp_asn: count &log &optional;\n };\n}\n\nevent connection_state_remove(c: connection)\n{\n local orig_loc = lookup_location(c$id$orig_h);\n if (orig_loc?$longitude && orig_loc?$latitude)\n c$conn$orig_location= cat(orig_loc$latitude,\",\",orig_loc$longitude);\n local orig_ccode = lookup_location(c$id$orig_h);\n if (orig_ccode?$country_code)\n c$conn$orig_country_code= cat(orig_ccode$country_code);\n c$conn$orig_asn= lookup_asn(c$id$orig_h);\n local resp_loc = lookup_location(c$id$resp_h);\n if (resp_loc?$longitude && resp_loc?$latitude)\n c$conn$resp_location= cat(resp_loc$latitude,\",\",resp_loc$longitude);\n local resp_ccode = lookup_location(c$id$resp_h);\n if (resp_ccode?$country_code)\n c$conn$resp_country_code= cat(resp_ccode$country_code);\n c$conn$resp_asn= lookup_asn(c$id$resp_h);\n}\n\nexport\n{\n redef record Conn::Info +=\n {\n orig_location: string &optional &log;\n resp_location: string &optional &log;\n };\n}\n\nevent connection_state_remove(c: connection)\n{\n local orig_loc = lookup_location(c$id$orig_h);\n if (orig_loc?$longitude && orig_loc?$latitude)\n c$conn$orig_location= cat(orig_loc$latitude,\",\",orig_loc$longitude);\n local resp_loc = lookup_location(c$id$resp_h);\n if (resp_loc?$longitude && resp_loc?$latitude)\n c$conn$resp_location= cat(resp_loc$latitude,\",\",resp_loc$longitude);\n}\n","old_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\n##! Add geo_location for the originator and responder of a connection\n##! to the connection logs.\n\nmodule Conn;\n\nexport\n{\n redef record Conn::Info +=\n {\n orig_location: string &optional &log;\n resp_location: string &optional &log;\n };\n}\n\nevent connection_state_remove(c: connection)\n{\n local orig_loc = lookup_location(c$id$orig_h);\n if (orig_loc?$longitude && orig_loc?$latitude)\n c$conn$orig_location= cat(orig_loc$latitude,\",\",orig_loc$longitude);\n local resp_loc = lookup_location(c$id$resp_h);\n if (resp_loc?$longitude && resp_loc?$latitude)\n c$conn$resp_location= cat(resp_loc$latitude,\",\",resp_loc$longitude);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"0f1c425f1dc55619a7c36819776736e345493854","subject":"add www1 to bad domains","message":"add www1 to bad domains\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-block-exe-hosts.bro","new_file":"http-ext-block-exe-hosts.bro","new_contents":"@load http-ext\n@load ipblocker\n\nmodule HTTP;\n\nexport {\n redef enum Notice += {\n HTTP_IncorrectFileTypeBadHost\n };\n\n const bad_exec_domains = \n \/co\\.cc\/\n | \/cx\\.cc\/\n | \/cz\\.cc\/\n | \/^www1\/\n &redef;\n\n const bad_exec_urls = \n \/php.adv=\/\n | \/http:\\\/\\\/[0-9]{1,3}\\.[0-9]{1,3}.*\\\/index\\.php\\?[^=]+=[^=]+$\/ #try to match http:\/\/1.2.3.4\/index.php?foo=bar\n | \/load.php\/\n &redef;\n\n const bad_user_agents = \n \/Java\\\/1\/\n &redef;\n\n}\n\nredef notice_action_filters += {\n [HTTP_IncorrectFileTypeBadHost] = notice_exec_ipblocker_dest,\n};\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h))\n return;\n if(! (\"identified-files\" in si$tags && si$mime_type == \"application\/x-dosexec\"))\n return;\n\n if( (bad_exec_domains in si$host || bad_exec_urls in si$url)\n ||(\/\\.exe\/ !in si$url && bad_user_agents in si$user_agent)) {\n NOTICE([$note=HTTP_IncorrectFileTypeBadHost,\n $id=id,\n $msg=fmt(\"EXE Downloaded from bad host %s %s %s\", id$orig_h, id$resp_h, si$url),\n $sub=\"http-ext\"\n ]);\n }\n}\n","old_contents":"@load http-ext\n@load ipblocker\n\nmodule HTTP;\n\nexport {\n redef enum Notice += {\n HTTP_IncorrectFileTypeBadHost\n };\n\n const bad_exec_domains = \n \/co\\.cc\/\n | \/cx\\.cc\/\n | \/cz\\.cc\/\n &redef;\n\n const bad_exec_urls = \n \/php.adv=\/\n | \/http:\\\/\\\/[0-9]{1,3}\\.[0-9]{1,3}.*\\\/index\\.php\\?[^=]+=[^=]+$\/ #try to match http:\/\/1.2.3.4\/index.php?foo=bar\n | \/load.php\/\n &redef;\n\n const bad_user_agents = \n \/Java\\\/1\/\n &redef;\n\n}\n\nredef notice_action_filters += {\n [HTTP_IncorrectFileTypeBadHost] = notice_exec_ipblocker_dest,\n};\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h))\n return;\n if(! (\"identified-files\" in si$tags && si$mime_type == \"application\/x-dosexec\"))\n return;\n\n if( (bad_exec_domains in si$host || bad_exec_urls in si$url)\n ||(\/\\.exe\/ !in si$url && bad_user_agents in si$user_agent)) {\n NOTICE([$note=HTTP_IncorrectFileTypeBadHost,\n $id=id,\n $msg=fmt(\"EXE Downloaded from bad host %s %s %s\", id$orig_h, id$resp_h, si$url),\n $sub=\"http-ext\"\n ]);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"7c1437d700863fed7ba32fae4d9180a97d76d0c3","subject":"Remove redundant @load call to itself (#13)","message":"Remove redundant @load call to itself (#13)\n\nCloses #12 ","repos":"mocyber\/rock-scripts","old_file":"plugins\/afpacket.bro","new_file":"plugins\/afpacket.bro","new_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# Workaround for AF_Packet plugin across multiple interfaces\n# See https:\/\/bro-tracker.atlassian.net\/browse\/BIT-1747 for more info\nredef AF_Packet::fanout_id = strcmp(getenv(\"fanout_id\"),\"\") == 0 ? 0 : to_count(getenv(\"fanout_id\"));\n","old_contents":"# Copyright (C) 2016-2018 RockNSM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# Workaround for AF_Packet plugin across multiple interfaces\n# See https:\/\/bro-tracker.atlassian.net\/browse\/BIT-1747 for more info\n@load scripts\/rock\/plugins\/afpacket\nredef AF_Packet::fanout_id = strcmp(getenv(\"fanout_id\"),\"\") == 0 ? 0 : to_count(getenv(\"fanout_id\"));\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"9805babe7ed6bdf64544375fab9c50aeb989a1b1","subject":"Changed kafka topic name to use hyphen","message":"Changed kafka topic name to use hyphen\n\nKafka doesn't like it when you use '.' or '_' in topic names. Swapping out for a '-' instead.","repos":"mocyber\/rock-scripts","old_file":"plugins\/kafka.bro","new_file":"plugins\/kafka.bro","new_contents":"\n## Setup Kafka output\n@load Bro\/Kafka\/logs-to-kafka\n\nredef Kafka::topic_name = \"bro-raw\";\nredef Kafka::json_timestamps = JSON::TS_ISO8601;\nredef Kafka::tag_json = F;\n\n## Setup event extension to include sensor and probe name\ntype Extension: record {\n ## The name of the system that wrote this log. This\n ## is defined in the const so that\n ## a system running lots of processes can give the\n ## same value for any process that writes a log.\n system: string &log;\n ## The name of the process that wrote the log. In\n ## clusters, this will typically be the name of the\n ## worker that wrote the log.\n proc: string &log;\n};\n\nfunction add_log_extension(path: string): Extension\n{\n return Extension($system = ROCK::sensor_id,\n $proc = peer_description);\n}\n\nredef Log::default_ext_func = add_log_extension;\nredef Log::default_ext_prefix = \"@\";\nredef Log::default_scope_sep = \"_\";\n","old_contents":"\n## Setup Kafka output\n@load Bro\/Kafka\/logs-to-kafka\n\nredef Kafka::topic_name = \"bro_raw\";\nredef Kafka::json_timestamps = JSON::TS_ISO8601;\nredef Kafka::tag_json = F;\n\n## Setup event extension to include sensor and probe name\ntype Extension: record {\n ## The name of the system that wrote this log. This\n ## is defined in the const so that\n ## a system running lots of processes can give the\n ## same value for any process that writes a log.\n system: string &log;\n ## The name of the process that wrote the log. In\n ## clusters, this will typically be the name of the\n ## worker that wrote the log.\n proc: string &log;\n};\n\nfunction add_log_extension(path: string): Extension\n{\n return Extension($system = ROCK::sensor_id,\n $proc = peer_description);\n}\n\nredef Log::default_ext_func = add_log_extension;\nredef Log::default_ext_prefix = \"@\";\nredef Log::default_scope_sep = \"_\";\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"8166e1cd97ab958a7005af7c3c3e08c7453143aa","subject":"Updated to run in Bro 2.4","message":"Updated to run in Bro 2.4\n\nNot completely sure this is the best way to setup the $orig and $resp child records of the conn record but it is working.","repos":"theflakes\/cs-bro","old_file":"bro-scripts\/intel-extensions\/seen\/conn-udp-icmp.bro","new_file":"bro-scripts\/intel-extensions\/seen\/conn-udp-icmp.bro","new_contents":"# Support for UDP, ICMP, and non-established TCP connections\n# This will only generate Intel matches when a connection is removed from Bro\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n#\n# Update by: Brian Kellogg 8\/7\/2015\n# - updated to run in Bro 2.4\n\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent Conn::log_conn(rec: Conn::Info)\n{\nif ( rec?$proto && ( rec$proto != tcp || ( rec?$history && rec$proto == tcp && \"h\" !in rec$history ) ) )\n {\n # duration, start_time, addl, and hot are required fields although they are not used by Intel framework\n # for Bro 2.4 we also need to setup $orig and $resp for the connection record being sent to Intel::seen\n # we also need to add the start_time and service for the conn record for Bro 2.4\n local dur: interval;\n local history: string;\n local orig_ep: endpoint;\n local resp_ep: endpoint;\n local start: time;\n local service: set[string];\n local c: connection;\n\n start = rec$ts;\n\n orig_ep = [$size = 0,$state = 0,$flow_label = 0];\n resp_ep = [$size = 0,$state = 0,$flow_label = 0];\n\n if ( rec?$service )\n add service[rec$service];\n else add service[\"\"];\n\n if ( rec?$duration )\n dur = rec$duration;\n else dur = 0secs;\n\n if ( rec?$history )\n history = rec$history;\n else history = \"\";\n\n c = [$id = rec$id,$orig = orig_ep,$resp = resp_ep,$start_time = start,$duration = dur,$service = service,$history = history,$uid = rec$uid];\n\n Intel::seen([$host=c$id$orig_h, $conn=c, $where=Conn::IN_ORIG]);\n Intel::seen([$host=c$id$resp_h, $conn=c, $where=Conn::IN_RESP]);\n }\n}\n","old_contents":"# Support for UDP, ICMP, and non-established TCP connections\n# This will only generate Intel matches when a connection is removed from Bro\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent Conn::log_conn(rec: Conn::Info)\n{\nif ( rec?$proto && ( rec$proto != tcp || ( rec?$history && rec$proto == tcp && \"h\" !in rec$history ) ) ) \n {\n # duration, start_time, addl, and hot are required fields although they are not used by Intel framework\n local dur: interval;\n local history: string;\n\n if ( rec?$duration )\n dur = rec$duration;\n else dur = 0secs;\n\n if ( rec?$history )\n history = rec$history;\n else history = \"\";\n\n local c = [$uid = rec$uid,$id = rec$id,$history = history,$duration = dur,$start_time = 0,$addl = \"\",$hot = 0];\n\n Intel::seen([$host=c$id$orig_h, $conn=c, $where=Conn::IN_ORIG]);\n Intel::seen([$host=c$id$resp_h, $conn=c, $where=Conn::IN_RESP]);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"92e389cef73a4ad05e540d395e4ccaed552ea2c7","subject":"Create alert-correlation.bro","message":"Create alert-correlation.bro","repos":"unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,kingtuna\/cs-bro,CrowdStrike\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/correlation\/alert-correlation.bro","new_file":"bro-scripts\/correlation\/alert-correlation.bro","new_contents":"# Monitors indicator matches and notice activity to correlate malicious activity per host \n# Must be loaded after Intelligence framework\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/frameworks\/intel\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Correlated_Alerts\n };\n}\n\n# Amount of time to watch for indicator \/ notice correlations\nconst alert_correlation_interval = 2min &redef;\n\n# Number of notices to see before alerting on correlations\nconst alert_correlation_notice_threshold = 2.0 &redef;\n\n# Number of indicators to see before alerting on correlations\nconst alert_correlation_indicator_threshold = 2.0 &redef;\n\n# Notices to exclude from correlations\nconst alert_correlation_notice_whitelist: set[string] = {\n \"CrowdStrike::Correlated_Alerts\",\n \"SSL::Invalid_Server_Cert\",\n \"Weird::Activity\",\n } &redef;\n\n# Proxy servers to exclude from correlations\n# Indicators and notices tend to funnel at proxy servers, making them useless for this type of detection\nconst alert_correlation_proxy_whitelist: set[subnet] = {\n } &redef;\n\n# Function to build notices from seen indicators \/ notices.\nfunction alerts_out(t: table[addr] of set[string], idx: addr): interval\n{\nlocal cnt = |t[idx]|;\n\n# Continue if more than one indicator or notice was seen.\nif ( cnt > 1 )\n {\n # Local variable to track indicators seen\n local i = 0;\n # Local variable to track notices seen\n local n = 0;\n # Local variable to store sub-message for alert notice\n local sub_msg = \"\";\n\n # Build the notice sub-message that contains all unique indicators \/ notices seen\n for ( [z] in t[idx] )\n {\n # Split all notices and indicators seen\n local parts = split_all(z,\/`\/);\n # If parts[1] is a notice, increase the notice count\n # Otherwise, parts[1] is an indicator, increase the indicator count\n if ( parts[1] == \"Notice\" )\n ++n;\n else\n ++i;\n\n # Add the notice \/ indicator to the sub-message\n sub_msg += fmt(\"%s: %s, \",parts[1],parts[3]);\n }\n\n# Clean the end of the sub-message\nsub_msg = cut_tail(sub_msg,2);\n\n# If at least one notice and one indicator are seen, generate a meta-notice\nif ( n >= 1 && i >= 1 )\n NOTICE([$note=Correlated_Alerts,\n $src=idx,\n $msg=fmt(\"Host %s was involved with %s unique notices \/ indicators\", idx, cnt),\n $sub=sub_msg,\n $n=cnt,\n $identifier=cat(idx,sub_msg)]);\n\n# If notice threshold is met and no indicators are seen, generate a meta-notice\nif ( n >= alert_correlation_notice_threshold && i == 0 )\n NOTICE([$note=Correlated_Alerts,\n $src=idx,\n $msg=fmt(\"Host %s was involved with %s unique notices\", idx, cnt),\n $sub=sub_msg,\n $n=cnt,\n $identifier=cat(idx,sub_msg)]);\n\n# If indicator threshold is met and no notices are seen, generate a meta-notice\nif ( n == 0 && i >= alert_correlation_indicator_threshold )\n NOTICE([$note=Correlated_Alerts,\n $src=idx,\n $msg=fmt(\"Host %s was involved with %s unique indicators\", idx, cnt),\n $sub=sub_msg,\n $n=cnt,\n $identifier=cat(idx,sub_msg)]);\n }\nreturn 0secs;\n}\n\n# Table where endpoint and indicator \/ notice data is dynamically stored\nglobal alert_correlation_state: table[addr] of set[string] &create_expire=alert_correlation_interval &expire_func=alerts_out;\n\n# Function to add host and indicator data to table above\nfunction add_indicator(a: addr, ind: string)\n{\nif ( a !in alert_correlation_state ) \n alert_correlation_state[a] = set();\nif ( a in alert_correlation_state )\n add alert_correlation_state[a][cat(\"Indicator`\",ind)];\n}\n\n# Function to add host and notice data to table above\nfunction add_notice(a: addr, note: string)\n{\nif ( a !in alert_correlation_state )\n alert_correlation_state[a] = set();\nif ( a in alert_correlation_state )\n add alert_correlation_state[a][cat(\"Notice`\",note)];\n}\n\n# Function to check if hosts should be added to table above\nfunction correlation_is_local(a: addr): bool\n{\nif ( Site::is_local_addr(a) == T && a !in alert_correlation_proxy_whitelist )\n return T;\nelse return F;\n}\n\n# Processing for indicators\nevent Intel::match(s: Intel::Seen, items: set[Intel::Item])\n{\n# If the indicator is file related, extract and save the connection data\nif ( s?$f )\n if ( s$f?$conns && |s$f$conns| == 1 )\n for ( cid in s$f$conns )\n s$conn = s$f$conns[cid];\n\n# Stop processing if connection data does not exist\nif ( ! s?$conn ) return;\n\n# Check if the orginator or responder is in the local network and not a proxy server\nif ( correlation_is_local(s$conn$id$orig_h) == T )\n add_indicator(s$conn$id$orig_h,s$indicator);\nif ( correlation_is_local(s$conn$id$resp_h) == T )\n add_indicator(s$conn$id$resp_h,s$indicator);\n}\n\n# Processing for notices\nhook Notice::policy(n: Notice::Info)\n{\nlocal note = cat(n$note);\n\n# Check if the orignator is in the local network and not a proxy server\nif ( n?$src && note !in alert_correlation_notice_whitelist )\n if ( correlation_is_local(n$src) == T )\n add_notice(n$src,note);\n\n# Check if the responder is in the local network and not a proxy server\nif ( n?$dst && note !in alert_correlation_notice_whitelist )\n if ( correlation_is_local(n$dst) == T )\n add_notice(n$dst,note);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/correlation\/alert-correlation.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"ccc21c0a115d4e9122ebb0e016985e65bee20449","subject":"Update detect-rfd.bro","message":"Update detect-rfd.bro\n\nUpdated pattern, added &redef options","repos":"kingtuna\/cs-bro,albertzaharovits\/cs-bro,CrowdStrike\/cs-bro,theflakes\/cs-bro,unusedPhD\/CrowdStrike_cs-bro","old_file":"bro-scripts\/rfd\/detect-rfd.bro","new_file":"bro-scripts\/rfd\/detect-rfd.bro","new_contents":"# Detect reflected file download attacks as described in \n# http:\/\/packetstorm.foofus.com\/papers\/presentations\/eu-14-Hafif-Reflected-File-Download-A-New-Web-Attack-Vector.pdf\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Reflected_File_Download\n };\n\n redef enum HTTP::Tags += {\n RFD\n };\n}\n\nconst rfd_content_type: set[string] = {\n \"application\/json\",\n \"application\/x-javascript\",\n \"application\/javascript\",\n \"application\/notexist\",\n \"text\/json\",\n \"text\/x-javascript\",\n \"text\/plain\",\n \"text\/notexist\",\n \"application\/xml\",\n \"text\/xml\",\n \"text\/html\"\n} &redef;\n\nconst rfd_pattern = \/\\\"\\|\\|\/ |\n \/\\\"\\<\\<\/ |\n \/\\\"\\>\\>\/ |\n \/\\;\\\/[^?]*\\.bat(\\;|$)\/ |\n \/\\;\\\/[^?]*\\.cmd(\\;|$)\/ |\n \/\\;\\\/[:alnum:]*?[Ss][Ee][Tt][Uu][Pp][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/\\;\\\/[:alnum:]*?[Ii][nn][Ss][Tt][Aa][Ll][Ll][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/\\;\\\/[:alnum:]*?[Uu][Pp][Dd][Aa][Tt][Ee][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/\\;\\\/[:alnum:]*?[Uu][Nn][In][Ss][Tt][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ &redef;\n\n\n# Perform a pattern match for reflected file downloads.\n# If found, add HTTP tag and generate a notice.\nfunction rfd_do_notice(c: connection)\n{\nif ( rfd_pattern in c$http$uri )\n {\n add c$http$tags[RFD];\n NOTICE([$note=Reflected_File_Download,\n $msg=\"A reflected file download was attempted\",\n $sub=c$http$uri,\n $id=c$id,\n $identifier=cat(c$id$orig_h,c$id$resp_h,c$http$uri)]);\n }\n}\n\n# Check for reflected file downloads in HTTP transactions that have a \n# CONTENT-TYPE header. Valid RFD content types are identified anywhere\n# in the CONTENT-TYPE header value.\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nif ( name == \"CONTENT-TYPE\" )\n for ( rct in rfd_content_type )\n if ( rct in value )\n rfd_do_notice(c);\n}\n\n# Check for reflected file downloads in HTTP transactions that do not have a \n# CONTENT-TYPE header.\nevent http_all_headers(c: connection, is_orig: bool, hlist: mime_header_list)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nlocal headers: set[string];\n\nfor ( h in hlist )\n {\n local name = hlist[h]$name;\n add headers[name];\n }\n\nif ( \"CONTENT-TYPE\" !in headers ) \n rfd_do_notice(c);\nelse return;\n}\n","old_contents":"# Detect reflected file download attacks as described in \n# http:\/\/packetstorm.foofus.com\/papers\/presentations\/eu-14-Hafif-Reflected-File-Download-A-New-Web-Attack-Vector.pdf\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Reflected_File_Download\n };\n\n redef enum HTTP::Tags += {\n RFD\n };\n}\n\nconst rfd_content_type: set[string] = {\n \"application\/json\",\n \"application\/x-javascript\",\n \"application\/javascript\",\n \"application\/notexist\",\n \"text\/json\",\n \"text\/x-javascript\",\n \"text\/plain\",\n \"text\/notexist\",\n \"application\/xml\",\n \"text\/xml\",\n \"text\/html\"\n};\n\nconst rfd_pattern = \t\/\\\"\\|\\|\/ |\n \t\t\t\/\\\"\\<\\<\/ |\n \t\t\t\/\\\"\\>\\>\/ |\n \t\t\t\/\\;\\\/([:alnum:]|[:punct])*\\.bat\\;\/ |\n \t\t\t\/\\;\\\/([:alnum:]|[:punct])*\\.cmd\\;\/ |\n \t\t\t\/\\;\\\/[:alnum:]*?[Ss][Ee][Tt][Uu][Pp][:alnum:]*?\\.[:alpha:]{3,4}\\;\/ |\n \t\t\t\/\\;\\\/[:alnum:]*?[Ii][nn][Ss][Tt][Aa][Ll][Ll][:alnum:]*?\\.[:alpha:]{3,4}\\;\/ |\n \t\t\t\/\\;\\\/[:alnum:]*?[Uu][Pp][Dd][Aa][Tt][Ee][:alnum:]*?\\.[:alpha:]{3,4}\\;\/ |\n \t\t\t\/\\;\\\/[:alnum:]*?[Uu][Nn][In][Ss][Tt][:alnum:]*?\\.[:alpha:]{3,4}\\;\/;\n\n\n# Perform a pattern match for reflected file downloads.\n# If found, add HTTP tag and generate a notice.\nfunction rfd_do_notice(c: connection)\n{\nif ( rfd_pattern in c$http$uri )\n {\n add c$http$tags[RFD];\n NOTICE([$note=Reflected_File_Download,\n $msg=\"A reflected file download was attempted\",\n $sub=c$http$uri,\n $id=c$id,\n $identifier=cat(c$id$orig_h,c$id$resp_h,c$http$uri)]);\n }\n}\n\n# Check for reflected file downloads in HTTP transactions that have a \n# CONTENT-TYPE header. Valid RFD content types are identified anywhere\n# in the CONTENT-TYPE header value.\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nif ( name == \"CONTENT-TYPE\" )\n for ( rct in rfd_content_type )\n if ( rct in value )\n rfd_do_notice(c);\n}\n\n# Check for reflected file downloads in HTTP transactions that do not have a \n# CONTENT-TYPE header.\nevent http_all_headers(c: connection, is_orig: bool, hlist: mime_header_list)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nlocal headers: set[string];\n\nfor ( h in hlist )\n {\n local name = hlist[h]$name;\n add headers[name];\n }\n\nif ( \"CONTENT-TYPE\" !in headers ) \n rfd_do_notice(c);\nelse return;\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"dd823bcc15fe9075857b70b14615dcc37e8f271f","subject":"set the sub field to the hostname","message":"set the sub field to the hostname\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"log-external-dns.bro","new_file":"log-external-dns.bro","new_contents":"module DNS;\n\nexport {\n redef record Info += {\n is_external: bool &default=F;\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n 208.67.220.220\/32, #opendns\n } &redef;\n\n redef enum Notice::Type += {\n ## Indicates that a user is using an external DNS server\n EXTERNAL_DNS,\n\n ## Indicates that a user is using an external DNS server in \n ## a foreign country.\n EXTERNAL_FOREIGN_DNS,\n };\n\n redef Notice::type_suppression_intervals += {\n [EXTERNAL_DNS] = 12hr,\n [EXTERNAL_FOREIGN_DNS] = 12hr,\n };\n\n const local_countries: set[string] = {\n \"US\",\n } &redef;\n\n}\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\n local rec = c$dns;\n if(!rec$RD)\n return;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return;\n\n rec$is_external=T;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n\n when (local hostname = lookup_addr(resp_h)) {\n #Doesn't work for the log, but we can use it here :-(\n #rec$resp_h_hostname = hostname;\n\n local note = EXTERNAL_DNS;\n local nmsg = fmt(\"An external DNS server is in use %s(%s)\", resp_h, hostname);\n\n if(rec$cc !in local_countries){\n note = EXTERNAL_FOREIGN_DNS;\n nmsg = fmt(\"An external foreign(%s) DNS server is in use %s(%s).\", rec$cc, resp_h, hostname);\n }\n local ident = fmt(\"%s-%s\", orig_h, resp_h);\n NOTICE([$note=note,\n $msg=nmsg,\n $sub=hostname,\n $identifier=ident,\n $conn=c]);\n \n }\n\n\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n\n return rec$is_external==T;\n return F;\n } ]);\n}\n","old_contents":"module DNS;\n\nexport {\n redef record Info += {\n is_external: bool &default=F;\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n 208.67.220.220\/32, #opendns\n } &redef;\n\n redef enum Notice::Type += {\n ## Indicates that a user is using an external DNS server\n EXTERNAL_DNS,\n\n ## Indicates that a user is using an external DNS server in \n ## a foreign country.\n EXTERNAL_FOREIGN_DNS,\n };\n\n redef Notice::type_suppression_intervals += {\n [EXTERNAL_DNS] = 12hr,\n [EXTERNAL_FOREIGN_DNS] = 12hr,\n };\n\n const local_countries: set[string] = {\n \"US\",\n } &redef;\n\n}\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\n local rec = c$dns;\n if(!rec$RD)\n return;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return;\n\n rec$is_external=T;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n\n when (local hostname = lookup_addr(resp_h)) {\n #Doesn't work for the log, but we can use it here :-(\n #rec$resp_h_hostname = hostname;\n\n local note = EXTERNAL_DNS;\n local nmsg = fmt(\"An external DNS server is in use %s(%s)\", resp_h, hostname);\n\n if(rec$cc !in local_countries){\n note = EXTERNAL_FOREIGN_DNS;\n nmsg = fmt(\"An external foreign(%s) DNS server is in use %s(%s).\", rec$cc, resp_h, hostname);\n }\n local ident = fmt(\"%s-%s\", orig_h, resp_h);\n NOTICE([$note=note,\n $msg=nmsg,\n $sub=fmt(\"%s\", resp_h),\n $identifier=ident,\n $conn=c]);\n \n }\n\n\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n\n return rec$is_external==T;\n return F;\n } ]);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"78daa885355874c1ec5bfae536ff83f5e0263e9f","subject":"have total be the number of connections","message":"have total be the number of connections\n\nthis should maybe be MAIL or RCPT and not HELO\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes)\n ++foo$rejects;\n\n if ( \/^([hH]|[eE]){2}[lL][oO]\/ in cmd )\n ++foo$total;\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes)\n ++foo$rejects;\n\n ++foo$total;\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"0f8900b85177d44730ce612122144de46e5baef0","subject":"New passive dns replication script. Primarily for logging dns replies. Use dns-ext.bro for query logging.","message":"New passive dns replication script. Primarily for logging dns replies. Use dns-ext.bro for query logging.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"dns-passive-replication.bro","new_file":"dns-passive-replication.bro","new_contents":"@load global-ext\n@load dns\n\n# Modify the DNS analyzer to give us Authority and Additional section responses.\nredef dns_skip_all_auth = F;\nredef dns_skip_all_addl = F;\n\nmodule DNS;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Replies to which queries to log.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\n# Turn off the dns.log file.\nredef logging = F;\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"dns-passive-replication\", logging, split_log_file, T);\n\tLOG::define_header(\"dns-passive-replication\",\n\t cat_sep(\"\\t\", \"\", \n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"username\", \"password\",\n\t \"command\", \"url\",\n\t \"reply_code\", \"reply\", \"reply_message\"));\n\t}\n\n\nconst dns_response_sections: table[count] of string = {\n\t[0] = \"QUERY\",\n\t[1] = \"ANS\",\n\t[2] = \"AUTH\",\n\t[3] = \"ADDL\",\n};\n\nfunction print_DNS_RR(c: connection, msg: dns_msg, ans: dns_answer, anno: string)\n\t{\n\tlocal output = cat_sep(\"\\t\", \"\\\\N\",\n\t network_time(),\n\t c$id$orig_h, port_to_count(c$id$orig_p),\n\t c$id$resp_h, port_to_count(c$id$resp_p),\n\t get_port_transport_proto(c$id$resp_p),\n\t ans$query,\n\t msg$AA ? 1 : 0,\n\t fmt(\"%.0f\", interval_to_double(ans$TTL)),\n\t dns_class[ans$qclass],\n\t query_types[ans$qtype],\n\t anno, \n\t dns_response_sections[ans$answer_type]);\n\t\n\tprint dns_pr_log, output;\n\t}\n\n#event dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n#\t{\n#\tprint_query(c, msg, query, qtype, qclass);\n#\t}\n\nevent dns_A_reply(c: connection, msg: dns_msg, ans: dns_answer, a: addr)\n\t{\n\tprint_DNS_RR(c, msg, ans, fmt(\"%s\", a));\n\t}\n\t\nevent dns_TXT_reply(c: connection, msg: dns_msg, ans: dns_answer, str: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, str);\n\t}\n\t\nevent dns_AAAA_reply(c: connection, msg: dns_msg, ans: dns_answer, a: addr, \n astr: string)\n\t{\n\t# TODO: not sure what's in astr\n\tprint_DNS_RR(c, msg, ans, fmt(\"%s\", a));\n\t}\n\nevent dns_MX_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string,\n preference: count)\n\t{\n\t# TODO: maybe deal with preference?\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\t\nevent dns_PTR_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\t\nevent dns_NS_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\t\nevent dns_CNAME_reply(c: connection, msg: dns_msg, ans: dns_answer, name: string)\n\t{\n\tprint_DNS_RR(c, msg, ans, name);\n\t}\n\t\nevent dns_SRV_reply(c: connection, msg: dns_msg, ans: dns_answer)\n\t{\n\t# need to make a function to log this...\n\t}\n\t\nevent dns_SOA_reply(c: connection, msg: dns_msg, ans: dns_answer, soa: dns_soa)\n\t{\n\tprint_DNS_RR(c, msg, ans, soa$mname);\n\t}\n\nevent dns_WKS_reply(c: connection, msg: dns_msg, ans: dns_answer)\n\t{\n\t# need to make a function to log this...\n\t}\n\nevent dns_HINFO_reply(c: connection, msg: dns_msg, ans: dns_answer)\n\t{\n\t# need to make a function to log this...\n\t}\n\n\n\n\t\n#event dns_query_reply(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n#\t{\n#\tprint query;\n#\t}\n\n\t\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'dns-passive-replication.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"d0e8a77558a5e48d2190dab034b95f5a61ca00e7","subject":"initial http metrics policy","message":"initial http metrics policy\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"metrics.http-ext.bro","new_file":"metrics.http-ext.bro","new_contents":"#output something like this\n#http_metrics total=343243 inbound=102313 outbound=3423432 exe_download=23\n\n@load global-ext\n@load http-ext\n\nmodule HTTP;\n\nexport {\n global http_metrics: table[string] of count &default=0;\n global http_metrics_interval = +2sec;\n}\n\nevent write_stats()\n {\n if (http_metrics[\"total\"]!=0)\n {\n print fmt(\"http_metrics time=%.6f total=%d inbound=%d outbound=%d exe_download=%d\",\n network_time(),\n http_metrics[\"total\"],\n http_metrics[\"inbound\"],\n http_metrics[\"outbound\"],\n http_metrics[\"exe_download\"]);\n clear_table(http_metrics);\n }\n schedule http_metrics_interval { write_stats() };\n }\n\nevent bro_init()\n {\n LOG::create_logs(\"http-ext-metrics\", All, F, T);\n schedule http_metrics_interval { write_stats() };\n }\n\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=-10\n {\n ++http_metrics[\"total\"];\n if(is_local_addr(id$orig_h))\n ++http_metrics[\"outbound\"];\n else\n ++http_metrics[\"inbound\"];\n\n if (\/\\.exe\/ in si$uri)\n ++http_metrics[\"exe_download\"];\n }\n\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'metrics.http-ext.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"aaed3b85d5bf52092804e3c2981fbd2779df91dc","subject":"new script to log emails that have the word password in the body","message":"new script to log emails that have the word password in the body\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-phish-passwords.bro","new_file":"smtp-ext-phish-passwords.bro","new_contents":"@load global-ext\n@load smtp-ext\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(\/[pP][aA][sS][sS][wW][oO][rR][dD]\/ in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h))\n return;\n if (id !in smtp_password_conns)\n return;\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'smtp-ext-phish-passwords.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"d4a2cb8ec5b72e2d4cc5b0a76c09c6408c7c0f7d","subject":"initial smtp metrics policy","message":"initial smtp metrics policy\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"metrics.smtp-ext.bro","new_file":"metrics.smtp-ext.bro","new_contents":"#output something like this\n#smtp_metrics time=1261506588.216565 total=54 inbound=49 outbound=5 inbound_err=17 outbound_err=0\n\n@load global-ext\n@load smtp-ext\n\nexport {\n global smtp_metrics: table[string] of count &default=0;\n global smtp_metrics_interval = +2sec;\n}\n\nevent write_stats()\n {\n if (smtp_metrics[\"total\"]!=0)\n {\n print fmt(\"smtp_metrics time=%.6f total=%d inbound=%d outbound=%d inbound_err=%d outbound_err=%d\",\n network_time(),\n smtp_metrics[\"total\"],\n smtp_metrics[\"inbound\"],\n smtp_metrics[\"outbound\"],\n smtp_metrics[\"inbound_err\"],\n smtp_metrics[\"outbound_err\"]);\n clear_table(smtp_metrics);\n }\n schedule smtp_metrics_interval { write_stats() };\n }\n\nevent bro_init()\n {\n LOG::create_logs(\"smtp-ext-metrics\", All, F, T);\n schedule smtp_metrics_interval { write_stats() };\n }\n\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info) &priority=-10\n {\n ++smtp_metrics[\"total\"];\n if(is_local_addr(id$orig_h))\n {\n ++smtp_metrics[\"outbound\"];\n if(si$last_reply!=\"\")\n ++smtp_metrics[\"outbound_err\"];\n }\n else\n {\n ++smtp_metrics[\"inbound\"];\n if(si$last_reply!=\"\")\n ++smtp_metrics[\"inbound_err\"];\n }\n }\n\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'metrics.smtp-ext.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"c661daa3660e4a854cded48106fad3a25a3b172f","subject":"removing trailing whitespace","message":"removing trailing whitespace\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dionaea_receiver.bro","new_file":"custom_scripts\/dionaea_receiver.bro","new_contents":"@load .\/dio_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $connector_id=connector_id];\n\n Log::write(Dio::LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","old_contents":"@load .\/dio_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $connector_id=connector_id];\n\n Log::write(Dio::LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"80461e6f3e87968ef2d06cc6575f6f93cc5843f1","subject":"logging for unregistering","message":"logging for unregistering\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_master.bro","new_file":"scripts_master\/bro_master.bro","new_contents":"@load .\/master_log.bro\n@load .\/balance_log.bro\n@load .\/dio_access.bro\n@load .\/dio_download_complete.bro\n@load .\/dio_download_offer.bro\n@load .\/dio_ftp.bro\n@load .\/dio_mysql_command.bro\n@load .\/dio_mysql_login.bro\n@load .\/dio_smb_bind.bro\n@load .\/dio_smb_request.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\n\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string);\nglobal dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n log_bro(\"bro_master.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n\n Broker::subscribe_to_events(\"honeypot\/dionaea\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_master.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent dionaea_mysql_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_login::LOG, rec);\n}\n\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n log_bro(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n log_bro(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n log_bro(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n log_bro(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n log_bro(\"Unregistered old slave \" + peer_name + \" ...\");\n log_balance(peer_name, \"\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n log_bro(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n log_bro(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n log_bro(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n log_bro(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n log_bro(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: BalanceLog::Info = [$connector=connector, $slave=slave];\n Log::write(BalanceLog::LOG, rec);\n}","old_contents":"@load .\/master_log.bro\n@load .\/balance_log.bro\n@load .\/dio_access.bro\n@load .\/dio_download_complete.bro\n@load .\/dio_download_offer.bro\n@load .\/dio_ftp.bro\n@load .\/dio_mysql_command.bro\n@load .\/dio_mysql_login.bro\n@load .\/dio_smb_bind.bro\n@load .\/dio_smb_request.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\n\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string);\nglobal dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n log_bro(\"bro_master.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n\n Broker::subscribe_to_events(\"honeypot\/dionaea\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_master.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent dionaea_mysql_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_login::LOG, rec);\n}\n\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n log_bro(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n log_bro(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n log_bro(\"Registered new slave \" + peer_name);\n \n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n log_bro(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n log_bro(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n log_bro(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_bro(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n log_bro(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n log_bro(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n log_bro(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: BalanceLog::Info = [$connector=connector, $slave=slave];\n Log::write(BalanceLog::LOG, rec);\n}","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"d584d42960295a2a4733206c7e5b9544ce596d66","subject":"filter was backwards","message":"filter was backwards\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-mime-metrics.bro","new_file":"http-mime-metrics.bro","new_contents":"@load base\/frameworks\/metrics\n\nredef enum Metrics::ID += {\n HTTP_MIME_METRICS,\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_MIME_METRICS,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n}\n\nevent HTTP::log_http(rec: HTTP::Info)\n{\n if(Site::is_local_addr(rec$id$orig_h) && rec?$mime_type) {\n Metrics::add_data(HTTP_MIME_METRICS, [$str=rec$mime_type], rec$response_body_len);\n }\n}\n","old_contents":"@load base\/frameworks\/metrics\n\nredef enum Metrics::ID += {\n HTTP_MIME_METRICS,\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_MIME_METRICS,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n}\n\nevent HTTP::log_http(rec: HTTP::Info)\n{\n if(Site::is_local_addr(rec$id$resp_h) && rec?$mime_type) {\n Metrics::add_data(HTTP_MIME_METRICS, [$str=rec$mime_type], rec$response_body_len);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f7973a4d46aca32c5c0773ecef95c22a96c0d227","subject":"Forgot to move a field into the ssh state record.","message":"Forgot to move a field into the ssh state record.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext.bro","new_file":"ssh-ext.bro","new_contents":"@load global-ext\n@load ssh\n@load notice\n\ntype ssh_ext_session_info: record {\n\tstart_time: time;\n\tclient: string &default=\"\";\n\tserver: string &default=\"\";\n\tlocation: geo_location;\n\tstatus: string &default=\"\";\n\tdirection: string &default=\"\";\n\tresp_size: count &default=0;\n};\n\n# Define the generic ssh-ext event that can be handled from other scripts\nglobal ssh_ext: event(id: conn_id, si: ssh_ext_session_info);\n\nmodule SSH;\n\nexport {\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\t# The list of active SSH connections and the associated session info.\n\tglobal active_ssh_conns: table[conn_id] of ssh_ext_session_info &read_expire=2mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in SSH::watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\t\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal ssh_conn = active_ssh_conns[c$id];\n\tlocal status = \"failure\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $sub=location$country_code]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 200000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\t\t\n\tif ( (log_geodata_on_failure && status == \"failure\") ||\n\t status == \"success\" )\n\t\t{\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\t}\n\t\t\n\tssh_conn$start_time = c$start_time;\n\tssh_conn$location = location;\n\tssh_conn$status = status;\n\tssh_conn$direction = direction;\n\tssh_conn$resp_size = c$resp$size;\n\t\n\tevent ssh_ext(c$id, ssh_conn);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +15secs { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_ext_session_info;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +15secs { ssh_watcher(c) }; \n\t\t}\n\t}\n","old_contents":"@load global-ext\n@load ssh\n@load notice\n\ntype ssh_ext_session_info: record {\n\tstart_time: time;\n\tclient: string &default=\"\";\n\tserver: string &default=\"\";\n\tlocation: geo_location;\n\tstatus: string &default=\"\";\n\tdirection: string &default=\"\";\n\tresp_size: count &default=0;\n};\n\n# Define the generic ssh-ext event that can be handled from other scripts\nglobal ssh_ext: event(id: conn_id, si: ssh_ext_session_info);\n\nmodule SSH;\n\nexport {\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\t# The list of active SSH connections and the associated session info.\n\tglobal active_ssh_conns: table[conn_id] of ssh_ext_session_info &read_expire=2mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in SSH::watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\t\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal ssh_conn = active_ssh_conns[c$id];\n\tlocal status = \"failure\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $sub=location$country_code]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 200000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\t\t\n\tif ( (log_geodata_on_failure && status == \"failure\") ||\n\t status == \"success\" )\n\t\t{\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\t}\n\t\t\n\t\n\tssh_conn$location = location;\n\tssh_conn$status = status;\n\tssh_conn$direction = direction;\n\tssh_conn$resp_size = c$resp$size;\n\t\n\tevent ssh_ext(c$id, ssh_conn);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +15secs { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_ext_session_info;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +15secs { ssh_watcher(c) }; \n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1adb688949a99e70324b71eaf065f05d9cc7b9fc","subject":"Create __load__.bro","message":"Create __load__.bro","repos":"kingtuna\/cs-bro,theflakes\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,CrowdStrike\/cs-bro,albertzaharovits\/cs-bro","old_file":"bro-scripts\/tor\/__load__.bro","new_file":"bro-scripts\/tor\/__load__.bro","new_contents":"@load .\/main\n@load policy\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/tor\/__load__.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"de675731784d0c8551f41e4f8e2e1f1ae54d55e2","subject":"add beemaster logging","message":"add beemaster logging\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_master.bro","new_file":"scripts_master\/bro_master.bro","new_contents":"@load .\/balance_log\n\n@load .\/beemaster_events\n@load .\/beemaster_log\n\n@load .\/dio_access\n@load .\/dio_download_complete\n@load .\/dio_download_offer\n@load .\/dio_ftp\n@load .\/dio_mysql_command\n@load .\/dio_login\n@load .\/dio_smb_bind\n@load .\/dio_smb_request\n@load .\/dio_blackhole.bro\n@load .\/acu_result.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\t\t\n\t\tBroker::subscribe_to_events_multi(\"acu_result\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_login::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_blackhole::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_blackhole::LOG, rec);\n}\nevent Beemaster::test(timestamp: time, attack_type: string) {\n Beemaster::log(\"Got test!\");\n local rec: Acu_result::Info = [$ts=timestamp, $attack=attack_type];\n Log::write(Acu_result::LOG, rec);\n}\nevent Beemaster::acu_result(timestamp: time, attack_type: string) {\n Beemaster::log(\"Got acu_result\");\n local rec: Acu_result::Info = [$ts=timestamp, $attack=attack_type];\n Log::write(Acu_result::LOG, rec);\n}\nevent Beemaster::tcp_event(rec: Beemaster::AlertInfo, discriminant: count) {\n Beemaster::log(\"Got tcp_event!!\");\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n Beemaster::log(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n Beemaster::log(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: BalanceLog::Info = [$connector=connector, $slave=slave];\n Log::write(BalanceLog::LOG, rec);\n}\n","old_contents":"@load .\/balance_log\n\n@load .\/beemaster_events\n@load .\/beemaster_log\n\n@load .\/dio_access\n@load .\/dio_download_complete\n@load .\/dio_download_offer\n@load .\/dio_ftp\n@load .\/dio_mysql_command\n@load .\/dio_login\n@load .\/dio_smb_bind\n@load .\/dio_smb_request\n@load .\/dio_blackhole.bro\n@load .\/acu_result.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\t\t\n\t\tBroker::subscribe_to_events_multi(\"acu_result\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_login::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_blackhole::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_blackhole::LOG, rec);\n}\n\nevent Beemaster::acu_result(timestamp: time, attack_type: string) {\n local rec: Acu_result::Info = [$ts=timestamp, $attack=attack_type];\n Log::write(Acu_result::LOG, rec);\n}\nevent Beemaster::tcp_event(rec: Beemaster::AlertInfo, discriminant: count) {\n Beemaster::log(\"Got tcp_event!!\");\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n Beemaster::log(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n Beemaster::log(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: BalanceLog::Info = [$connector=connector, $slave=slave];\n Log::write(BalanceLog::LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"22f9e9871243348007802ad29a799ab4583d075d","subject":"Create ftp-username.bro","message":"Create ftp-username.bro","repos":"albertzaharovits\/cs-bro,kingtuna\/cs-bro,CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/intel-extensions\/seen\/ftp-username.bro","new_file":"bro-scripts\/intel-extensions\/seen\/ftp-username.bro","new_contents":"# Intel framework support for FTP usernames \n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/ftp\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent ftp_request(c: connection, command: string, arg: string)\n{\nif ( command == \"USER\" )\n Intel::seen([$indicator=arg,\n $indicator_type=Intel::USER_NAME,\n $conn=c,\n $where=FTP::IN_USER_NAME]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/intel-extensions\/seen\/ftp-username.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"57f509e47725021974e3c59ad34bba3eecfe4849","subject":"new policy to detect rogue access points","message":"new policy to detect rogue access points\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"rogue-access-points.bro","new_file":"rogue-access-points.bro","new_contents":"@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nexport {\n\tredef enum Notice::Type += { \n\t\tRogue_Access_Point\n\t};\n\n const mobile_browsers =\n \/i(Phone|Pod|Pad)\/ |\n \/Android\/ &redef;\n\n const wireless_nets: set[subnet] &redef;\n global rogue_access_points : set[addr] &redef;\n}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=2\n{\n if (!is_orig )\n return;\n local ip = c$id$orig_h;\n if (ip in wireless_nets || ip in rogue_access_points)\n return;\n\n if ( name == \"USER-AGENT\" && mobile_browsers in value){\n local message = \"Rogue access point detected\";\n local submessage = value;\n NOTICE([$note=Rogue_Access_Point, $msg=message, $sub=submessage,\n $id=c$id]);\n add rogue_access_points[ip];\n }\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'rogue-access-points.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"d84d37479481a0ffcaae3bbd1f5d5c9d60475003","subject":"changed bro version mention from v2.5.4 to v2.5.5","message":"changed bro version mention from v2.5.4 to v2.5.5","repos":"salesforce\/hassh","old_file":"bro\/hassh.bro","new_file":"bro\/hassh.bro","new_contents":"","old_contents":"","returncode":0,"stderr":"unknown","license":"bsd-3-clause","lang":"Bro"} {"commit":"ff1b8455ee89a7cbe5c1bdfcb6a8523b50cc81c9","subject":"Fixed several problems.","message":"Fixed several problems.\n\n - There was an off-by-error due to vectors now being\n zero based.\n - There is no longer an option to specify the character\n use for redaction.\n - There is a new option to choose whether or not you\n want to pay attention to CC# separators. If\n CreditCardExposure::use_cc_separators is set to F,\n you can match on credit cards that are just a bunch\n of digits.\n - American Express cards now match.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){2,3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\t## Configure this to `F` if you'd like to stop enforcing that\n\t## credit cards use an internal digit separator.\n\tconst use_cc_separators = T &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = F;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal found_cnt = 0;\n\n\tlocal ccps = find_all(data, cc_regex);\n\tprint ccps;\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\n\t\tif ( (!use_cc_separators || cc_separators in ccp) && luhn_check(ccp) )\n\t\t\t{\n\t\t\t++found_cnt;\n\n\t\t\t# we've got a match\n\t\t\tlocal cc_parts = split_string_all(data, cc_regex);\n\t\t\tfor ( i in cc_parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 1 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = cc_parts[i];\n\t\t\t\t\tcc_parts[i] = gsub(cc_parts[i], \/[0-9]\/, \"X\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tlocal redacted_data = join_string_vec(cc_parts, \"\");\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tlocal cc_location = strstr(data, ccp);\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? gsub(ccp, \/[0-9]\/, \"X\") : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\t}\n\t\t\n\t\t}\n\tif ( found_cnt > 0 )\n\t\t{\n\t\tNOTICE([$note=CreditCardExposure::Found,\n\t\t $conn=c,\n\t\t $msg=fmt(\"Found at least %d credit card number%s\", found_cnt, found_cnt > 1 ? \"s\" : \"\"),\n\t\t $sub=trimmed_redacted_data,\n\t\t $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n\t\treturn T;\n\t\t}\n\telse\n\t\t{\n\t\treturn F;\n\t\t}\n\t}\n\n# This is used if the signature based technique is in use\n#function validate_credit_card_match(state: signature_state, data: string): bool\n#\t{\n#\t# TODO: Don't handle HTTP data this way.\n#\tif ( \/^GET\/ in data )\n#\t\treturn F;\n#\n#\treturn check_cards(state$conn, data);\n#\t}\n\nevent CreditCardExposure::stream_data(f: fa_file, data: string)\n\t{\n\tlocal c: connection;\n\tfor ( id in f$conns )\n\t\t{\n\t\tc = f$conns[id];\n\t\tbreak;\n\t\t}\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent file_new(f: fa_file)\n\t{\n\tif ( f$source == \"HTTP\" || f$source == \"SMTP\" )\n\t\t{\n\t\tFiles::add_analyzer(f, Files::ANALYZER_DATA_EVENT, \n\t\t [$stream_event=CreditCardExposure::stream_data]);\n\t\t}\n\t}\n","old_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal cc_parts = split_string_all(data, cc_regex);\n\t\t\tfor ( i in cc_parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = cc_parts[i];\n\t\t\t\t\tcc_parts[i] = gsub(cc_parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tlocal redacted_data = join_string_vec(cc_parts, \"\");\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tlocal cc_location = strstr(data, ccp);\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_redacted_data),\n\t\t\t $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? gsub(ccp, \/[0-9]\/, redaction_char) : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1e0fd0df6746849436aadd7ec131ec5623da25f2","subject":"Switching to compiling in debug mode by default.","message":"Switching to compiling in debug mode by default.\n\nIf optimization is enabled, the code will crash currently for unknown\nreasons ...\n","repos":"FrozenCaribou\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti","old_file":"bro\/scripts\/bro\/hilti\/base\/main.bro","new_file":"bro\/scripts\/bro\/hilti\/base\/main.bro","new_contents":"\nmodule Hilti;\n\nexport {\n\t## Dump debug information about analyzers to stderr (for debugging only). \n\tconst dump_debug = F &redef;\n\n\t## Dump generated HILTI\/BinPAC++ code to stderr (for debugging only).\n\tconst dump_code = F &redef;\n\n\t## Dump generated HILTI\/BinPAC++ code to stderr before finalizing the modules. (for\n\t## debugging only). \n\tconst dump_code_pre_finalize = F &redef;\n\n\t## Dump all HILTI\/BinPAC++ code to stderr (for debugging only).\n\tconst dump_code_all = F &redef;\n\n\t## Disable code verification (for debugging only).\n\tconst no_verify = F &redef;\n\n\t## Generate code for all events no matter if they have a handler\n\t## defined or not.\n\tconst compile_all = F &redef;\n\n\t## Enable debug mode for code generation.\n\tconst debug = T &redef;\n\n\t## Enable optimization for code generation.\n\tconst optimize = F &redef;\n\n\t## Profiling level for code generation.\n\tconst profile = 0 &redef;\n\n\t## Tags for codegen debug output as colon-separated string.\n\tconst cg_debug = \"\" &redef;\n\n\t## Save all generated BinPAC++ modules into \"bro..pac2\"\n\tconst save_pac2 = F &redef;\n\n\t## Save all HILTI modules into \"bro..hlt\"\n\tconst save_hilti = F &redef;\n\n\t## Save final linked LLVM assembly into \"bro.ll\"\n\tconst save_llvm = F &redef;\n\n\t## Use on-disk cache for compiled modules.\n\tconst use_cache = T &redef;\n\n\t## Activate the Bro script compiler.\n\tconst compile_scripts = F &redef;\n}\n\n\n","old_contents":"\nmodule Hilti;\n\nexport {\n\t## Dump debug information about analyzers to stderr (for debugging only). \n\tconst dump_debug = F &redef;\n\n\t## Dump generated HILTI\/BinPAC++ code to stderr (for debugging only).\n\tconst dump_code = F &redef;\n\n\t## Dump generated HILTI\/BinPAC++ code to stderr before finalizing the modules. (for\n\t## debugging only). \n\tconst dump_code_pre_finalize = F &redef;\n\n\t## Dump all HILTI\/BinPAC++ code to stderr (for debugging only).\n\tconst dump_code_all = F &redef;\n\n\t## Disable code verification (for debugging only).\n\tconst no_verify = F &redef;\n\n\t## Generate code for all events no matter if they have a handler\n\t## defined or not.\n\tconst compile_all = F &redef;\n\n\t## Enable debug mode for code generation.\n\tconst debug = F &redef;\n\n\t## Enable optimization for code generation.\n\tconst optimize = T &redef;\n\n\t## Profiling level for code generation.\n\tconst profile = 0 &redef;\n\n\t## Tags for codegen debug output as colon-separated string.\n\tconst cg_debug = \"\" &redef;\n\n\t## Save all generated BinPAC++ modules into \"bro..pac2\"\n\tconst save_pac2 = F &redef;\n\n\t## Save all HILTI modules into \"bro..hlt\"\n\tconst save_hilti = F &redef;\n\n\t## Save final linked LLVM assembly into \"bro.ll\"\n\tconst save_llvm = F &redef;\n\n\t## Use on-disk cache for compiled modules.\n\tconst use_cache = T &redef;\n\n\t## Activate the Bro script compiler.\n\tconst compile_scripts = F &redef;\n}\n\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"dc75022f54f2c9f0fd8e6eb6a43b7b072bdd60f5","subject":"Create singlequerysubscription.bro","message":"Create singlequerysubscription.bro","repos":"sami2316\/osquery,sami2316\/osquery","old_file":"singlequerysubscription.bro","new_file":"singlequerysubscription.bro","new_contents":"\nmodule osquery;\n\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef osquery::endpoint_name = \"Printer\";\n\n\nglobal added_acpi_tables: event(host: string, name: string, size: count, md5: string);\nglobal removed_acpi_tables: event(host: string, name: string,size: count,md5: string);\n###################################################################################\nglobal added_arp_cache: event(host: string, address: string, mac: string, interface: string);\nglobal removed_arp_cache: event(host: string, address: string, mac: string, interface: string);\n###################################################################################\nglobal added_block_devices: event(host: string, name: string,vendor: string, model: string);\nglobal removed_block_devices: event(host: string, name: string,vendor: string, model: string);\n###################################################################################\nglobal added_chrome_extensions: event(host: string, name: string,author: string, path:string);\nglobal removed_chrome_extensions: event(host: string, name: string,author: string, path:string);\n###################################################################################\nglobal added_cpuid: event(host: string, feature: string, value: string);\nglobal removed_cpuid: event(host: string, feature: string, value: string);\n###################################################################################\nglobal added_crontab: event(host: string, hour: count, command: string, path: string);\nglobal removed_crontab: event(host: string, hour: count, command: string, path: string);\n###################################################################################\nglobal added_disk_encryption: event(host: string, name: string, uuid: string, encrypted: count);\nglobal removed_disk_encryption: event(host: string, name: string, uuid: string, encrypted: count);\n###################################################################################\nglobal added_etc_hosts: event(host: string, address: string, hostnames: string);\nglobal removed_etc_hosts: event(host: string, address: string, hostnames: string);\n###################################################################################\nglobal added_etc_protocols: event(host: string, name: string, number: count);\nglobal removed_etc_protocols: event(host: string, name: string, number: count);\n###################################################################################\nglobal added_etc_services: event(host: string, name: string, prt: count, protocol: string);\nglobal removed_etc_services: event(host: string, name: string, prt: count, protocol: string);\n###################################################################################\nglobal added_file_events: event(host: string, target_path: string, action: string, t: count);\nglobal removed_file_events: event(host: string, target_path: string, action: string, t: count);\n###################################################################################\nglobal added_firefox_addons: event(host: string, name: string, source_url: string, location: string);\nglobal removed_firefox_addons: event(host: string, name: string, source_url: string, location: string);\n###################################################################################\nglobal added_groups: event(host: string, gid: count, groupname: string);\nglobal removed_groups: event(host: string, gid: count, groupname: string);\n###################################################################################\nglobal added_hardware_events: event(host: string, action: string, model: string, vendor: string);\nglobal removed_hardware_events: event(host: string, action: string, model: string, vendor: string);\n###################################################################################\nglobal added_interface_address: event(host: string, interface: string, address: string);\nglobal removed_interface_address: event(host: string, interface: string, address: string);\n###################################################################################\nglobal added_interface_details: event(host: string, interface: string, mac: string, mtu: count);\nglobal removed_interface_details: event(host: string, interface: string, mac: string, mtu: count);\n###################################################################################\nglobal added_kernel_info: event(host: string, version: string, path: string, device: string);\nglobal removed_kernel_info: event(host: string, version: string, path: string, device: string);\n###################################################################################\nglobal added_last: event(host: string, username: string, pid: count, h: string);\nglobal removed_last: event(host: string, username: string, pid: count, h: string);\n###################################################################################\nglobal added_listening_ports: event(host: string, pid: count, prt: count, protocol: count);\nglobal removed_listening_ports: event(host: string, pid: count, prt: count, protocol: count);\n###################################################################################\nglobal added_logged_in_users: event(host: string, user: string, h: string, t: count);\nglobal removed_logged_in_users: event(host: string, user: string, h: string, t: count);\n###################################################################################\nglobal added_mounts: event(host: string, device: string, path: string);\nglobal removed_mounts: event(host: string, device: string, path: string);\n###################################################################################\nglobal added_opera_extensions: event(host: string, name: string, description: string, author: string);\nglobal removed_opera_extensions: event(host: string, name: string, description: string, author: string);\n###################################################################################\nglobal added_os_version: event(host: string, name: string, patch: count, build: string);\nglobal removed_os_version: event(host: string, name: string, patch: count, build: string);\n###################################################################################\nglobal added_passwd_changes: event(host: string, target_path: string, action: string);\nglobal removed_passwd_changes: event(host: string, target_path: string, action: string);\n###################################################################################\nglobal added_pci_devices: event(host: string, pci_slot: string, driver: string, vendor: string, model: string);\nglobal removed_pci_devices: event(host: string, pci_slot: string, driver: string, vendor: string, model: string);\n###################################################################################\nglobal added_process_envs: event(host: string, pid: count, key: string, value: string);\nglobal removed_process_envs: event(host: string, pid: count, key: string, value: string);\n###################################################################################\nglobal added_process_memory_map: event(host: string, pid: count, permissions: string, device: string);\nglobal removed_process_memory_map: event(host: string, pid: count, permissions: string, device: string);\n###################################################################################\nglobal added_process_open_files: event(host: string, pid: count, fd: string, path: string);\nglobal removed_process_open_files: event(host: string, pid: count, fd: string, path: string);\n###################################################################################\nglobal added_process_open_sockets: event(host: string, pid: count, socket: count, protocol: count);\nglobal removed_process_open_sockets: event(host: string, pid: count, socket: count, protocol: count);\n###################################################################################\nglobal added_processes: event(host: string, pid: count, name: string, on_disk: string);\nglobal removed_processes: event(host: string, pid: count, name: string, on_disk: string);\n###################################################################################\nglobal added_routes: event(host: string, destination: string, source: string, interface: string);\nglobal removed_routes: event(host: string, destination: string, source: string, interface: string);\n###################################################################################\nglobal added_shell_history: event(host: string, username: string, command: string);\nglobal removed_shell_history: event(host: string, username: string, command: string);\n###################################################################################\nglobal added_smbios_tables: event(host: string, number: count, description: string, size: count);\nglobal removed_smbios_tables: event(host: string, number: count, description: string, size: count);\n###################################################################################\nglobal added_system_controls: event(host: string, name: string, oid: string, subsystem: string);\nglobal removed_system_controls: event(host: string, name: string, oid: string, subsystem: string);\n###################################################################################\nglobal added_uptime: event(host: string, days: count, hours: count);\nglobal removed_uptime: event(host: string, days: count, hours: count);\n###################################################################################\nglobal added_usb_devices: event(host: string, usb_address: count, vendor: string, model: string);\nglobal removed_usb_devices: event(host: string, usb_address: count, vendor: string, model: string);\n###################################################################################\nglobal added_user_groups: event(host: string, uid: count, gid: count);\nglobal removed_user_groups: event(host: string, uid: count, gid: count);\n###################################################################################\nglobal added_users: event(host: string, username: string, uid: count, gid: count);\nglobal removed_users: event(host: string, username: string, uid: count, gid: count);\n###################################################################################\n\nevent bro_init()\n{\n\tosquery::enable();\n\tosquery::subscribe_to_events(\"\/bro\/event\/\");\n\tosquery::connect(\"192.168.1.211\",broker_port, 2sec); \n\t##osquery::connect(\"192.168.1.187\",broker_port, 2sec); \n\t##osquery::connect(\"192.168.1.33\",broker_port, 2sec); \n}\n\nevent BrokerComm::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string)\n{\n\tprint \"BrokerComm::outgoing_connection_establisted\", peer_address, peer_port, peer_name;\n\t\n\tosquery::subscribe(\"osquery::added_acpi_tables\",\"SELECT name,size,md5 FROM acpi_tables\",T);\n\t#osquery::subscribe(\"osquery::removed_acpi_tables\",\"SELECT name,size,md5 FROM acpi_tables\");\n\t#######################################################################################\n\tosquery::subscribe(\"osquery::added_arp_cache\",\"SELECT address,mac,interface FROM arp_cache\");\n\t#osquery::subscribe(\"osquery::removed_arp_cache\",\"SELECT address,mac,interface FROM arp_cache\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_block_devices\",\"SELECT name,vendor,model FROM block_devices\");\n\t#osquery::subscribe(\"osquery::removed_block_devices\",\"SELECT name,vendor,model FROM block_devices\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_chrome_extensions\",\"SELECT name,author,path FROM chrome_extensions\");\n\t#osquery::subscribe(\"osquery::removed_chrome_extensions\",\"SELECT name,author,path FROM chrome_extensions\");\n\t########################################################################################\n\t#osquery::subscribe(\"osquery::added_cpuid\",\"SELECT feature,value FROM cpuid\");\n\t#osquery::subscribe(\"osquery::removed_cpuid\",\"SELECT feature,value FROM cpuid\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_crontab\",\"SELECT hour,command,path FROM crontab\");\n\t#osquery::subscribe(\"osquery::removed_crontab\",\"SELECT hour,command,path FROM crontab\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_disk_encryption\",\"SELECT name,uuid,encrypted FROM disk_encryption\");\n\t#osquery::subscribe(\"osquery::removed_disk_encryption\",\"SELECT name,uuid,encrypted FROM disk_encryption\");\n\t########################################################################################\n\t#osquery::subscribe(\"osquery::added_etc_hosts\",\"SELECT address,hostnames FROM etc_hosts\");\n\t#osquery::subscribe(\"osquery::removed_etc_hosts\",\"SELECT address,hostnames FROM etc_hosts\");\n\t########################################################################################\n\t#osquery::subscribe(\"osquery::added_etc_protocols\",\"SELECT name,number FROM etc_protocols\");\n\t#osquery::subscribe(\"osquery::removed_etc_protocols\",\"SELECT name,number FROM etc_protocols\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_etc_services\",\"SELECT name,port,protocol FROM etc_services\");\n\t#osquery::subscribe(\"osquery::removed_etc_services\",\"SELECT name,port,protocol FROM etc_services\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_file_events\",\"SELECT target_path,action,time FROM file_events\");\n\t#osquery::subscribe(\"osquery::removed_file_events\",\"SELECT target_path,action,time FROM file_events\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_firefox_addons\",\"SELECT name,source_url,location FROM firefox_addons\");\n\t#osquery::subscribe(\"osquery::removed_firefox_addons\",\"SELECT name,source_url,location FROM firefox_addons\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_groups\",\"SELECT gid,groupname FROM groups\");\n\t#osquery::subscribe(\"osquery::removed_groups\",\"SELECT gid,groupname FROM groups\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_hardware_events\",\"SELECT action,model,vendor FROM hardware_events\");\n\t#osquery::subscribe(\"osquery::removed_hardware_events\",\"SELECT action,model,vendor FROM hardware_events\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_interface_address\",\"SELECT interface,address FROM interface_address\");\n\t#osquery::subscribe(\"osquery::removed_interface_address\",\"SELECT interface,address FROM interface_address\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_interface_details\",\"SELECT interface,mac,mtu FROM interface_details\");\n\t#osquery::subscribe(\"osquery::removed_interface_details\",\"SELECT interface,mac,mtu FROM interface_details\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_kernel_info\",\"SELECT version,path,device FROM kernel_info\");\n\t#osquery::subscribe(\"osquery::removed_kernel_info\",\"SELECT version,path,device FROM kernel_info\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_last\",\"SELECT username,pid,host FROM last\");\n\t#osquery::subscribe(\"osquery::removed_last\",\"SELECT username,pid,host FROM last\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_listening_ports\",\"SELECT pid,port,protocol FROM listening_ports\");\n\t#osquery::subscribe(\"osquery::removed_listening_ports\",\"SELECT pid,port,protocol FROM listening_ports\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_logged_in_users\",\"SELECT user,host,time FROM logged_in_users\");\n\t#osquery::subscribe(\"osquery::removed_logged_in_users\",\"SELECT user,host,time FROM logged_in_users\");\n\t########################################################################################\n\t#osquery::subscribe(\"osquery::added_mounts\",\"SELECT device,path FROM mounts\");\n\t#osquery::subscribe(\"osquery::removed_mounts\",\"SELECT device,path FROM mounts\");\n\t########################################################################################\n\t#osquery::subscribe(\"osquery::added_opera_extensions\",\"SELECT name,description,author FROM opera_extensions\");\n\t#osquery::subscribe(\"osquery::removed_opera_extensions\",\"SELECT name,description,author FROM opera_extensions\");\n\t#######################################################################################\n\tosquery::subscribe(\"osquery::added_os_version\",\"SELECT name,patch,build FROM os_version\",T);\n\t#osquery::subscribe(\"osquery::removed_os_version\",\"SELECT name,patch,build FROM os_version\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_passwd_changes\",\"SELECT target_path,action FROM passwd_changes\");\n\t#osquery::subscribe(\"osquery::removed_passwd_changes\",\"SELECT target_path,action FROM passwd_changes\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_pci_devices\",\"SELECT pci_slot,driver,vendor,model FROM pci_devices\");\n\t#osquery::subscribe(\"osquery::removed_pci_devices\",\"SELECT pci_slot,driver,vendor,model FROM pci_devices\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_process_envs\",\"SELECT pid,key,value FROM process_envs\");\n\t#osquery::subscribe(\"osquery::removed_process_envs\",\"SELECT pid,key,value FROM process_envs\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_process_memory_map\",\"SELECT pid,permissions,device FROM process_memory_map\");\n\t#osquery::subscribe(\"osquery::removed_process_memory_map\",\"SELECT pid,permissions,device FROM process_memory_map\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_process_open_files\",\"SELECT pid,fd,path FROM process_open_files\");\n\t#osquery::subscribe(\"osquery::removed_process_open_files\",\"SELECT pid,fd,path FROM process_open_files\");\n\t#######################################################################################\n\tosquery::subscribe(\"osquery::added_process_open_sockets\",\"SELECT pid,socket,protocol FROM process_open_sockets\");\n\t#osquery::subscribe(\"osquery::removed_process_open_sockets\",\"SELECT pid,socket,protocol FROM process_open_sockets\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_processes\",\"SELECT pid,name,on_disk FROM processes\");\n\t#osquery::subscribe(\"osquery::removed_processes\",\"SELECT pid,name,on_disk FROM processes\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_routes\",\"SELECT destination,source,interface FROM routes\");\n\t#osquery::subscribe(\"osquery::removed_routes\",\"SELECT destination,source,interface FROM routes\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_shell_history\",\"SELECT username,command FROM shell_history\");\n\t#osquery::subscribe(\"osquery::removed_shell_history\",\"SELECT username,command FROM shell_history\");\n\t#######################################################################################\n\tosquery::subscribe(\"osquery::added_smbios_tables\",\"SELECT number,description,size FROM smbios_tables\");\n\t#osquery::subscribe(\"osquery::removed_smbios_tables\",\"SELECT number,description,size FROM smbios_tables\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_system_controls\",\"SELECT name,oid,subsystem FROM system_controls\");\n\t#osquery::subscribe(\"osquery::removed_system_controls\",\"SELECT name,oid,subsystem FROM system_controls\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_uptime\",\"SELECT days,hours FROM uptime\",T);\n\t#osquery::subscribe(\"osquery::removed_uptime\",\"SELECT days,hours FROM uptime\");\n\t#######################################################################################\n\t#osquery::subscribe(\"osquery::added_usb_devices\",\"SELECT usb_address,vendor,model FROM usb_devices\",T);\n\t#osquery::subscribe(\"osquery::removed_usb_devices\",\"SELECT usb_address,vendor,model FROM usb_devices\");\n\t########################################################################################\n\t#osquery::subscribe(\"osquery::added_user_groups\",\"SELECT uid,gid FROM user_groups\");\n\t#osquery::subscribe(\"osquery::removed_user_groups\",\"SELECT uid,gid FROM user_groups\");\n\t########################################################################################\n\tosquery::subscribe(\"osquery::added_users\",\"SELECT username,uid,gid FROM users\");\n\t#osquery::subscribe(\"osquery::removed_users\",\"SELECT username,uid,gid FROM users\");\n\t#######################################################################################\n\t\n}\n\n\nevent BrokerComm::incoming_connection_broken(peer_name: string)\n{\n\tprint \"BrokerComm::incoming_connection_broken\", peer_name;\n\tterminate();\n}\n########################### ACPI TABLES ################################################\n\nevent added_acpi_tables(host: string, name: string, size: count, md5: string)\n{\n\tprint \"New acpi_table Entry\";\n\tprint fmt(\"Host = %s Table_name = %s size = %d md5 = %s\",host, name, size, md5);\n}\nevent removed_acpi_tables(host: string, name: string,size: count,md5: string)\n{\n\tprint \"Deleted acpi_table Entry\";\n\tprint fmt(\"Host = %s Table_name = %s size = %d md5 = %s\",host, name, size, md5);\n}\n############################## ARP CACHE ##############################################\nevent added_arp_cache(host: string, address: string, mac: string, interface: string)\n{\n\tprint fmt(\"Host = %s Address = %s mac = %s Interface = %s\",host, address, mac, interface);\n}\nevent removed_arp_cache(host: string, address: string, mac: string, interface: string)\n{\n\tprint fmt(\"Host = %s Address = %s mac = %s Interface = %s\",host, address, mac, interface);\n}\n############################## BLOCK DEVICES ###########################################\nevent added_block_devices(host: string, name: string,vendor: string, model: string)\n{\n\tprint fmt(\"Host = %s Name = %s Vendor = %s Model = %s\",host, name, vendor, model);\n}\nevent removed_block_devices(host: string, name: string,vendor: string, model: string)\n{\n\tprint fmt(\"Host = %s Name = %s Vendor = %s Model = %s\",host, name, vendor, model);\n}\n############################## CHROME EXTENSIONS ##########################################\nevent added_chrome_extensions(host: string, name: string,author: string, path:string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s Author = %s Path = %s\",host, name, author, path);\n}\nevent removed_chrome_extensions(host: string, name: string,author: string, path:string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s Author = %s Path = %s\",host, name, author, path);\n}\n############################# CPUID #####################################################\nevent added_cpuid(host: string, feature: string, value: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Feature = %s Value = %s\",host, feature,value);\n}\nevent removed_cpuid(host: string, feature: string, value: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Feature = %s Value = %s\",host, feature,value);\n}\n############################ CRONTAB ####################################################\nevent added_crontab(host: string, hour: count, command: string, path: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Hour = %d Command = %s Path=%s\",host, hour, command, path);\n}\nevent removed_crontab(host: string, hour: count, command: string,path: string)\n{\n\tprint fmt(\"Host = %s Hour = %d Command = %s Path=%s\",host, hour, command, path);\n}\n########################### DISK ENCRYPTION ###############################################\nevent added_disk_encryption(host: string, name: string, uuid: string, encrypted: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s uuid = %s encrypted=%d\",host, name, uuid, encrypted);\n}\nevent removed_disk_encryption(host: string, name: string, uuid: string, encrypted: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s uuid = %s encrypted=%d\",host, name, uuid, encrypted);\n}\n########################### ETC HOSTS ########################################################\nevent added_etc_hosts(host: string, address: string, hostnames: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Address = %s hostnames = %s \",host, address, hostnames);\n}\nevent removed_etc_hosts(host: string, address: string, hostnames: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Address = %s hostnames = %s \",host, address, hostnames);\n}\n########################### ETC PROTOCOLS #################################################\nevent added_etc_protocols(host: string, name: string, number: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s number = %d \",host, name, number);\n}\nevent removed_etc_protocols(host: string, name: string, number: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s number = %d \",host, name, number);\n}\n########################### ETC SERVICES ##################################################\nevent added_etc_services(host: string, name: string, prt: count, protocol: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s prt = %d Protocol = %s \",host, name, prt, protocol);\n}\nevent removed_etc_services(host: string, name: string, prt: count, protocol: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s prt = %d Protocol = %s \",host, name, prt, protocol);\n}\n########################### FILE EVENTS ####################################################\nevent added_file_events(host: string, target_path: string, action: string, t: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s target_path = %s Action = %s Time = %d\",host, target_path,action,t);\n}\nevent removed_file_events(host: string, target_path: string, action: string, t: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s target_path = %s Action = %s Time = %d\",host, target_path,action,t);\n}\n############################ FIREFOX ADDONS #################################################\nevent added_firefox_addons(host: string, name: string, source_url: string, location: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s source_url = %s Locatoin= %s \",host, name, source_url, location);\n}\nevent removed_firefox_addons(host: string, name: string, source_url: string, location: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s source_url = %s Locatoin= %s \",host, name, source_url, location);\n}\n############################ ADDED GROUPS ###################################################\nevent added_groups(host: string, gid: count, groupname: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s gid = %d groupnumber = %s \",host, gid, groupname);\n}\nevent removed_groups(host: string, gid: count, groupname: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s gid = %d groupnumber = %s \",host, gid, groupname);\n}\n############################ HARDWARE EVENTS ##################################################\nevent added_hardware_events(host: string, action: string, model: string, vendor: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s action = %s model = %s Vendor =%s\",host, action, model,vendor);\n}\nevent removed_hardware_events(host: string, action: string, model: string, vendor: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s action = %s model = %s Vendor =%s\",host, action, model,vendor);\n}\n########################### INTERFACE ADDRESS ##################################################\nevent added_interface_address(host: string, interface: string, address: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Interface = %s Address = %s \",host, interface,address);\n}\nevent removed_interface_address(host: string, interface: string, address: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Interface = %s Address = %s \",host, interface,address);\n}\n############################ INTERFACE DETAILS ##################################################\nevent added_interface_details(host: string, interface: string, mac: string, mtu: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s interface= %s mac = %s Mtu =%d \",host, interface,mac,mtu);\n}\nevent removed_interface_details(host: string, interface: string, mac: string, mtu: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s interface= %s mac = %s Mtu =%d \",host, interface,mac,mtu);\n}\n############################ KERNEL INFO ####################################################\nevent added_kernel_info(host: string, version: string, path: string, device: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s version = %s path = %s Device =%s\",host, version,path,device);\n}\nevent removed_kernel_info(host: string, version: string, path: string, device: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s version = %s path = %s Device =%s\",host, version,path,device);\n}\n############################# LAST ##########################################################\nevent added_last(host: string, username: string, pid: count, h: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s username = %s pid = %d Host=%s\",host, username, pid,h);\n}\nevent removed_last(host: string, username: string, pid: count, h: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s username = %s pid = %d Host=%s\",host, username, pid,h);\n}\n############################# LISTENING PORTS ################################################\nevent added_listening_ports(host: string, pid: count, prt: count, protocol: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s pid = %d prt = %d Protocol =%d \",host, pid,prt,protocol);\n}\nevent removed_listening_ports(host: string, pid: count, prt: count, protocol: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s pid = %d prt = %d Protocol =%d \",host, pid,prt,protocol);\n}\n############################# LOGGED IN USERS #################################################\nevent added_logged_in_users(host: string, user: string, h: string, t: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s User = %s Host = %s Time =%d \",host, user,h,t);\n}\nevent removed_logged_in_users(host: string, user: string, h: string, t: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s User = %s Host = %s Time =%d \",host, user,h,t);\n}\n############################ MOUNTS ##########################################################\nevent added_mounts(host: string, device: string, path: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Device = %s Path = %s \",host, device,path);\n}\nevent removed_mounts(host: string, device: string, path: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Device = %s Path = %s \",host, device,path);\n}\n############################ OPERA EXTENSIONS #################################################\nevent added_opera_extensions(host: string, name: string, description: string, author: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s description = %s Author=%s \",host, name,description,author);\n}\nevent removed_opera_extensions(host: string, name: string, description: string, author: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s description = %s Author=%s \",host, name,description,author);\n}\n############################ OS VERSION ######################################################\nevent added_os_version(host: string, name: string, patch: count, build: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s Patch = %d Build = %s \",host, name, patch,build);\n}\nevent removed_os_version(host: string, name: string, patch: count, build: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s Patch = %d Build = %s \",host, name, patch,build);\n}\n############################ PASSWORD CHANGES ##################################################\nevent added_passwd_changes(host: string, target_path: string, action: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Target_Path = %s Action = %s \",host, target_path,action);\n}\nevent removed_passwd_changes(host: string, target_path: string, action: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Target_Path = %s Action = %s \",host, target_path,action);\n}\n############################ PCI DEVICES #####################################################\nevent added_pci_devices(host: string, pci_slot: string, driver: string, vendor: string, model: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PCI_Slot = %s Driver = %s Vendor =%s Model= %s\",host, pci_slot,driver,vendor,model);\n}\nevent removed_pci_devices(host: string, pci_slot: string, driver: string, vendor: string, model: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PCI_Slot = %s Driver = %s Vendor =%s Model= %s\",host, pci_slot,driver,vendor,model);\n}\n########################### PROCESS EVENTS #####################################################\nevent added_process_envs(host: string, pid: count, key: string, value: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d Key = %s Value = %s \",host, pid,key,value);\n}\nevent removed_process_envs(host: string, pid: count, key: string, value: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d Key = %s Value = %s \",host, pid,key,value);\n}\n########################### PROCESS MOMORY ######################################################\nevent added_process_memory_map(host: string, pid: count, permissions: string, device: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d Permissions = %s Device = %s \",host, pid,permissions,device);\n}\nevent removed_process_memory_map(host: string, pid: count, permissions: string, device: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d Permissions = %s Device = %s \",host, pid,permissions,device);\n}\n########################## PROCESS OPEN FILES ###################################################\nevent added_process_open_files(host: string, pid: count, fd: string, path: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d FD = %s Path = %s\",host, pid,fd,path);\n}\nevent removed_process_open_files(host: string, pid: count, fd: string, path: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d FD = %s Path = %s\",host, pid,fd,path);\n}\n########################## PROCESS OPEN SOCKETS ####################################################\nevent added_process_open_sockets(host: string, pid: count, socket: count, protocol: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d Socket = %d Protocol =%d\",host, pid,socket,protocol);\n}\nevent removed_process_open_sockets(host: string, pid: count, socket: count, protocol: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d Socket = %d Protocol =%d\",host, pid,socket,protocol);\n}\n########################## PROCESSES #########################################################\nevent added_processes(host: string, pid: count, name: string, on_disk: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d Name = %s on_disk = %s\",host, pid,name,on_disk);\n}\nevent removed_processes(host: string, pid: count, name: string, on_disk: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d Name = %s on_disk = %s\",host, pid,name,on_disk);\n}\n########################### ROUTES ########################################################\nevent added_routes(host: string, destination: string, source: string, interface: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Destination = %s Source = %s Interface = %s \",host, destination,source,interface);\n}\nevent removed_routes(host: string, destination: string, source: string, interface: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Destination = %s Source = %s Interface = %s \",host, destination,source,interface);\n}\n########################### SHELL HISTORY ####################################################\nevent added_shell_history(host: string, username: string, command: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s UserNmae = %s Command = %s \",host, username, command);\n}\nevent removed_shell_history(host: string, username: string, command: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s UserNmae = %s Command = %s \",host, username, command);\n}\n############################ SMBIOS TABLES ###################################################\nevent added_smbios_tables(host: string, number: count, description: string, size: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Number = %d Description = %s Size=%d \",host, number, description,size);\n}\nevent removed_smbios_tables(host: string, number: count, description: string, size: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Number = %d Description = %s Size=%d \",host, number, description,size);\n}\n############################# SYSTEM CONTROLS ###################################################\nevent added_system_controls(host: string, name: string, oid: string, subsystem: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s OID = %s Subsystem =%s \",host, name, oid, subsystem);\n}\nevent removed_system_controls(host: string, name: string, oid: string, subsystem: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s OID = %s Subsystem =%s \",host, name, oid, subsystem);\n}\n############################## UPTIME ###################################################\nevent added_uptime(host: string, days: count, hours: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Days = %d Hours = %d \",host, days,hours);\n}\nevent removed_uptime(host: string, days: count, hours: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Days = %d Hours = %d \",host, days,hours);\n}\n############################# USB DEVICES ###################################################\nevent added_usb_devices(host: string, usb_address: count, vendor: string, model: string)\n{\n\tprint \"New Usb Device Added\";\n \tprint fmt(\"Host = %s Usb_address = %d Vendor = %s Model = %s\",host, usb_address, vendor, model);\n}\nevent removed_usb_devices(host: string, usb_address: count, vendor: string, model: string)\n{\n\tprint \"Usb Device Removed\";\n \tprint fmt(\"Host = %s Usb_address = %d Vendor = %s Model = %s\",host, usb_address, vendor, model);\n}\n############################# USER GROUPS ###################################################\nevent added_user_groups(host: string, uid: count, gid: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s UID = %d GID = %d \",host, uid, gid);\n}\nevent removed_user_groups(host: string, uid: count, gid: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s UID = %d GID = %d \",host, uid, gid);\n}\n############################# USERS ######################################################\nevent added_users(host: string, username: string, uid: count, gid: count)\n{\n\tprint \"New User Added\";\n \tprint fmt(\"Host = %s UserName = %s UID = %d GID = %d\",host, username, uid, gid);\n}\nevent removed_users(host: string, username: string, uid: count, gid: count)\n{\n\tprint \"User Removed\";\n \tprint fmt(\"Host = %s UserName = %s UID = %d GID = %d\",host, username, uid, gid);\n}\n\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'singlequerysubscription.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"525fd9ddbaca45aa0dd360f23cea43f72478be1c","subject":"add missing header fields","message":"add missing header fields\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"logging.ssh-ext.bro","new_file":"logging.ssh-ext.bro","new_contents":"@load global-ext\n@load ssh-ext\n\nmodule SSH;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Which SSH logins to record.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssh-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"ssh-ext\", cat_sep(\"\\t\", \"\", \n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"status\", \"direction\",\n\t \"country\", \"region\",\n\t \"client\", \"server\", \"resp_size\"));\n\t\n\t}\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info)\n\t{\n\tlocal log = LOG::choose(\"ssh-ext\", id$resp_h);\n\n\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t si$start_time,\n\t id$orig_h, fmt(\"%d\", id$orig_p),\n\t id$resp_h, fmt(\"%d\", id$resp_p),\n\t si$status, si$direction, \n\t si$location$country_code, si$location$region,\n\t si$client, si$server,\n\t si$resp_size);\n\t}","old_contents":"@load global-ext\n@load ssh-ext\n\nmodule SSH;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t# Which SSH logins to record.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssh-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"ssh-ext\", cat_sep(\"\\t\", \"\", \n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"country\", \"region\",\n\t \"client\", \"server\", \"resp_size\"));\n\t\n\t}\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info)\n\t{\n\tlocal log = LOG::choose(\"ssh-ext\", id$resp_h);\n\n\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t si$start_time,\n\t id$orig_h, fmt(\"%d\", id$orig_p),\n\t id$resp_h, fmt(\"%d\", id$resp_p),\n\t si$status, si$direction, \n\t si$location$country_code, si$location$region,\n\t si$client, si$server,\n\t si$resp_size);\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"fe2431018dfa95d2c85ac87c9d2398ae5a4b93e7","subject":"http mime metrics","message":"http mime metrics\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-mime-metrics.bro","new_file":"http-mime-metrics.bro","new_contents":"@load base\/frameworks\/metrics\n\nredef enum Metrics::ID += {\n HTTP_MIME_METRICS,\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_MIME_METRICS,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n}\n\nevent HTTP::log_http(rec: HTTP::Info)\n{\n if(Site::is_local_addr(rec$id$resp_h)) {\n Metrics::add_data(HTTP_MIME_METRICS, [$str=rec$mime_type], rec$response_body_len);\n }\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'http-mime-metrics.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"1900f8201055c2d35b8fde8b52c059ae40ad0e7b","subject":"remove unneeded file","message":"remove unneeded file\n","repos":"juju4\/ansible-bro-ids,juju4\/ansible-bro-ids,juju4\/ansible-bro-ids","old_file":"ja3.bro","new_file":"ja3.bro","new_contents":"","old_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n# LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"9e8ffdb641b7a9ad95666d47a521f0260c99c166","subject":"Dionaea_MySQL Log hinzugef\u00fcgt.","message":"Dionaea_MySQL Log hinzugef\u00fcgt.\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dionaea_receiver.bro","new_file":"custom_scripts\/dionaea_receiver.bro","new_contents":"@load .\/dio_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string); \nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport];\n\n Log::write(Dio_mysql::LOG, rec);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args];\n\n Log::write(Dio::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","old_contents":"@load .\/dio_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport];\n\n Log::write(Dio::LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"feb6e703522dfa7f16850aef877c6b259b983736","subject":"Adds smtp-url.bro","message":"Adds smtp-url.bro\n\nIncluding this bro script by request, but not activating it by default. Also corrected some deprecated string functions and cleaned up commented out code.","repos":"mocyber\/rock-scripts","old_file":"protocols\/smtp\/smtp-url.bro","new_file":"protocols\/smtp\/smtp-url.bro","new_contents":"##! A script for handling URLs in SMTP traffic. This script does\n##! two things. It logs URLs discovered in SMTP traffic. It\n##! also records them in a bloomfilter and looks for them to be\n##! visited through HTTP requests.\n##!\n##! Authors: Aashish Sharma \n##! Seth Hall \n##! Derek Ditch \n\n\n@load base\/utils\/urls\n\nmodule SMTP_URL;\n\nexport {\n redef enum Log::ID += { Links_LOG };\n\n type Info: record {\n ## When the email was seen.\n ts: time &log;\n ## Unique ID for the connection.\n uid: string &log;\n ## Connection details.\n id: conn_id &log;\n ## Depth of the email into the SMTP exchange.\n trans_depth: count &log;\n ## The host field extracted from the discovered URL.\n host: string &log &optional;\n ## URL that was discovered.\n url: string &log &optional;\n };\n\n redef enum Notice::Type += {\n ## A link discovered in an email appears to have been clicked.\n Link_in_Email_Clicked,\n\n ## An email was seen in email that matched the pattern in\n ## `SMTP_URL::suspicious_urls`\n Suspicious_URL,\n\n ## Certain file extensions in email links can be watched for\n ## with the pattern in `SMTP_URL::suspicious_file_extensions`\n Suspicious_File_Extension,\n\n ## URL with a dotted IP address seen in an email.\n Dotted_URL\n };\n\n const suspicious_file_extensions = \/\\.([rR][aA][rR]|[eE][xX][eE]|[zZ][iI][pP])$\/ &redef;\n const suspicious_urls = \/googledocs?\/ &redef;\n\n const ignore_file_types = \/\\.([gG][iI][fF]|[pP][nN][gG]|[jJ][pP][gG]|[xX][mM][lL]|[jJ][pP][eE]?[gG]|[cC][sS][sS])$\/ &redef;\n\n ## The following\n const ignore_mail_originators: set[subnet] = { } &redef;\n const ignore_mailfroms = \/bro@|alerts|reports\/ &redef;\n const ignore_notification_emails = {\"alerts@example.com\", \"notices@example.com\"} &redef;\n const ignore_site_links = \/http:\\\/\\\/.*\\.example\\.com\\\/|http:\\\/\\\/.*\\.example\\.net\/ &redef;\n}\n\n# The bloomfilter that stores all of the links seen in email.\nglobal mail_links_bf: opaque of bloomfilter;\n\nredef record connection += {\n smtp_url: Info &optional;\n};\n\nevent bro_init() &priority=5\n {\n # initialize the bloomfilter\n mail_links_bf = bloomfilter_basic_init(0.00000001, 10000000, \"SMTP_URL\");\n\n Log::create_stream(Links_LOG, [$columns=Info]);\n }\n\nfunction extract_host(name: string): string\n {\n local split_on_slash = split_string(name, \/\\\/\/);\n return split_on_slash[3];\n }\n\nfunction log_smtp_urls(c: connection, url: string)\n {\n c$smtp_url = Info($ts = c$smtp$ts,\n $uid = c$uid,\n $id = c$id,\n $trans_depth = c$smtp$trans_depth,\n $host = extract_host(url),\n $url = url);\n\n Log::write(SMTP_URL::Links_LOG, c$smtp_url);\n }\n\nevent SMTP_URL::email_data(f: fa_file, data: string)\n {\n # Grab the connection.\n local c: connection;\n for ( cid in f$conns )\n {\n c = f$conns[cid];\n break;\n }\n\n if( c$smtp?$mailfrom && ignore_mailfroms in c$smtp$mailfrom )\n {\n return;\n }\n\n if ( c$smtp?$to )\n {\n for ( to in c$smtp$to )\n {\n if ( to in ignore_notification_emails )\n return;\n }\n }\n\n local mail_info = Files::describe(f);\n local urls = find_all_urls(data);\n for ( link in urls )\n {\n if ( ignore_file_types !in link )\n {\n bloomfilter_add(mail_links_bf, link);\n log_smtp_urls(c, link);\n\n if ( suspicious_file_extensions in link )\n {\n NOTICE([$note = Suspicious_File_Extension,\n $msg = fmt(\"Suspicious file extension embedded in URL %s from %s\", link, c$id$orig_h),\n $sub = mail_info,\n $conn = c]);\n }\n\n if ( suspicious_urls in link )\n {\n NOTICE([$note = Suspicious_URL,\n $msg = fmt(\"Suspicious text embedded in URL %s from %s\", link, c$smtp$uid),\n $sub = mail_info,\n $conn = c]);\n }\n\n if ( \/([[:digit:]]{1,3}\\.){3}[[:digit:]]{1,3}.*\/ in link )\n {\n NOTICE([$note = Dotted_URL,\n $msg = fmt(\"Embedded IP address in URL %s from %s\", link, c$id$orig_h),\n $sub = mail_info,\n $conn = c]);\n }\n\n }\n }\n}\n\nevent file_over_new_connection(f: fa_file, c: connection, is_orig: bool)\n {\n if ( f$source == \"SMTP\" && c?$smtp &&\n c$id$orig_h !in ignore_mail_originators )\n {\n Files::add_analyzer(f, Files::ANALYZER_DATA_EVENT, [$stream_event=SMTP_URL::email_data]);\n }\n }\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &priority=-3\n {\n local str = HTTP::build_url_http(c$http);\n if ( bloomfilter_lookup(SMTP_URL::mail_links_bf, str) > 0 &&\n ignore_file_types !in str &&\n ignore_site_links !in str)\n {\n NOTICE([$note=SMTP_URL::Link_in_Email_Clicked,\n $msg=fmt(\"URL %s \", str),\n $conn=c]);\n }\n }\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'protocols\/smtp\/smtp-url.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"4d649470dc9f9a949ebea590846d730faea667d6","subject":"Missed a header field for the software-ext log.","message":"Missed a header field for the software-ext log.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"software-ext.bro","new_file":"software-ext.bro","new_contents":"@load global-ext\n@load weird\n\nmodule Software;\n\nexport {\n\t# The hosts whose software should be logged.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts, NoHosts\n\tconst logging = LocalHosts &redef;\n\n\t# In case you are interested in more than logging just local assets\n\t# you can split the log file.\n\tconst split_log_file = F &redef;\n\n\t# Some software can be installed twice on the same server\n\t# with different major numbers.\n\tconst identify_by_major: set[string] = {\n\t\t\"PHP\",\n\t\t\"WebSTAR\",\n\t} &redef;\n\t\n\tredef enum Notice += { \n\t\tSoftware_Version_Change,\n\t};\n\t\n\t# Some software is more interesting when the version changes. This is\n\t# a set of all software that should raise a notice when a different version\n\t# is seen.\n\tconst interesting_version_changes: set[string] = {\n\t\t\"SSH\"\n\t} &redef;\n\t\n\t# Raise this event from other scripts when software is discovered.\n\t# This event is actually defined internally in Bro.\n\t#global software_version_found: event(c: connection, host: addr, s: software, descr: string);\t\n\t\n\t# Index is the name of the software.\n\ttype software_set: table[string] of software;\n\t# The set of software associated with an address.\n\tglobal host_software: table[addr] of software_set &create_expire=1day &synchronized;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"software-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"software-ext\", cat_sep(\"\\t\", \"\\\\N\", \n\t \"ts\", \"host\", \n\t \"software\", \"version\",\n\t \"description\"));\n\t}\n\n# Compare two versions.\n# Returns -1 for v1 < v2, 0 for v1 == v2, 1 for v1 > v2.\n# If the numerical version numbers match, the addl string\n# is compared lexicographically.\nfunction software_cmp_version(v1: software_version, v2: software_version): int\n\t{\n\tif ( v1$major < v2$major )\n\t\treturn -1;\n\tif ( v1$major > v2$major )\n\t\treturn 1;\n\n\tif ( v1$minor < v2$minor )\n\t\treturn -1;\n\tif ( v1$minor > v2$minor )\n\t\treturn 1;\n\n\tif ( v1$minor2 < v2$minor2 )\n\t\treturn -1;\n\tif ( v1$minor2 > v2$minor2 )\n\t\treturn 1;\n\n\treturn strcmp(v1$addl, v2$addl);\n\t}\n\t\nfunction software_endpoint_name(c: connection, host: addr): string\n\t{\n\treturn fmt(\"%s %s\", host, (host == c$id$orig_h ? \"client\" : \"server\"));\n\t}\n\n# Convert a version into a string \"a.b.c-x\".\nfunction software_fmt_version(v: software_version): string\n\t{\n\treturn fmt(\"%s%s%s%s\",\n\t v$major >= 0 ? fmt(\"%d\", v$major) : \"\",\n\t v$minor >= 0 ? fmt(\".%d\", v$minor) : \"\",\n\t v$minor2 >= 0 ? fmt(\".%d\", v$minor2) : \"\",\n\t v$addl != \"\" ? fmt(\"-%s\", v$addl) : \"\");\n\t}\n\n# Convert a software into a string \"name a.b.cx\".\nfunction software_fmt(s: software): string\n\t{\n\treturn fmt(\"%s %s\", s$name, software_fmt_version(s$version));\n\t}\n\t\nevent software_new(c: connection, host: addr, s: software, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\t{\n\t\tlocal log = LOG::get_file_by_addr(\"software-ext\", host, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), host,\n\t\t s$name, software_fmt_version(s$version), descr);\n\t\t}\n\t}\n\n# Insert a mapping into the table\n# Overides old entries for the same software and generates events if needed.\nevent software_register(c: connection, host: addr, s: software, descr: string)\n\t{\n\t# Host already known?\n\tif ( host !in host_software )\n\t\thost_software[host] = table();\n\n\t# If a software can be installed more than once on a host\n\t# (with a different major version), we identify it by \"-\"\n\tif ( s$name in identify_by_major && s$version$major >= 0 )\n\t\ts$name = fmt(\"%s-%d\", s$name, s$version$major);\n\n\tlocal hs = host_software[host];\n\t# Software already registered for this host?\n\tif ( s$name in hs )\n\t\t{\n\t\tlocal old = hs[s$name];\n\t\t\n\t\t# Is it a potentially interesting version change \n\t\t# and is it a different version?\n\t\tif ( s$name in interesting_version_changes &&\n\t\t software_cmp_version(old$version, s$version) != 0 )\n\t\t\t{\n\t\t\tlocal msg = fmt(\"%.6f %s switched from %s to %s (%s)\",\n\t\t\t\t\tnetwork_time(), software_endpoint_name(c, host),\n\t\t\t\t\tsoftware_fmt_version(old$version),\n\t\t\t\t\tsoftware_fmt(s), descr);\n\t\t\tNOTICE([$note=Software_Version_Change,\n\t\t\t $msg=msg, $sub=software_fmt(s), $conn=c]);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tevent software_new(c, host, s, descr);\n\t\t}\n\n\ths[s$name] = s;\n\t}\n\nevent software_version_found(c: connection, host: addr, s: software,\n\t\t\t\tdescr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\tevent software_register(c, host, s, descr);\n\t}\n\n\n########################################\n# Below are internally defined events. #\n########################################\n\t\nevent software_version_found(c: connection, host: addr, s: software, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\tevent software_register(c, host, s, descr);\n\t}\n\nevent software_parse_error(c: connection, host: addr, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\t{\n\t\t# Here we need a little hack, since software_file is\n\t\t# not always there.\n\t\tlocal msg = fmt(\"%.6f %s: can't parse '%s'\", network_time(),\n\t\t\t\tsoftware_endpoint_name(c, host), descr);\n\n\t\tprint Weird::weird_file, msg;\n\t\t}\n\t}\n\n# I'm not going to handle this at the moment. It doesn't seem terribly useful.\n#event software_unparsed_version_found(c: connection, host: addr, str: string)\n#\t{\n#\tif ( addr_matches_hosts(host, logging) )\n#\t\t{\n#\t\tprint Weird::weird_file, fmt(\"%.6f %s: [%s]\", network_time(),\n#\t\t\t\tsoftware_endpoint_name(c, host), str);\n#\t\t}\n#\t}\n","old_contents":"@load global-ext\n@load weird\n\nmodule Software;\n\nexport {\n\t# The hosts whose software should be logged.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts, NoHosts\n\tconst logging = LocalHosts &redef;\n\n\t# In case you are interested in more than logging just local assets\n\t# you can split the log file.\n\tconst split_log_file = F &redef;\n\n\t# Some software can be installed twice on the same server\n\t# with different major numbers.\n\tconst identify_by_major: set[string] = {\n\t\t\"PHP\",\n\t\t\"WebSTAR\",\n\t} &redef;\n\t\n\tredef enum Notice += { \n\t\tSoftware_Version_Change,\n\t};\n\t\n\t# Some software is more interesting when the version changes. This is\n\t# a set of all software that should raise a notice when a different version\n\t# is seen.\n\tconst interesting_version_changes: set[string] = {\n\t\t\"SSH\"\n\t} &redef;\n\t\n\t# Raise this event from other scripts when software is discovered.\n\t# This event is actually defined internally in Bro.\n\t#global software_version_found: event(c: connection, host: addr, s: software, descr: string);\t\n\t\n\t# Index is the name of the software.\n\ttype software_set: table[string] of software;\n\t# The set of software associated with an address.\n\tglobal host_software: table[addr] of software_set &create_expire=1day &synchronized;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"software-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"software-ext\", cat_sep(\"\\t\", \"\\\\N\", \n\t \"ts\", \"host\", \n\t \"software\", \"version\"));\n\t}\n\n# Compare two versions.\n# Returns -1 for v1 < v2, 0 for v1 == v2, 1 for v1 > v2.\n# If the numerical version numbers match, the addl string\n# is compared lexicographically.\nfunction software_cmp_version(v1: software_version, v2: software_version): int\n\t{\n\tif ( v1$major < v2$major )\n\t\treturn -1;\n\tif ( v1$major > v2$major )\n\t\treturn 1;\n\n\tif ( v1$minor < v2$minor )\n\t\treturn -1;\n\tif ( v1$minor > v2$minor )\n\t\treturn 1;\n\n\tif ( v1$minor2 < v2$minor2 )\n\t\treturn -1;\n\tif ( v1$minor2 > v2$minor2 )\n\t\treturn 1;\n\n\treturn strcmp(v1$addl, v2$addl);\n\t}\n\t\nfunction software_endpoint_name(c: connection, host: addr): string\n\t{\n\treturn fmt(\"%s %s\", host, (host == c$id$orig_h ? \"client\" : \"server\"));\n\t}\n\n# Convert a version into a string \"a.b.c-x\".\nfunction software_fmt_version(v: software_version): string\n\t{\n\treturn fmt(\"%s%s%s%s\",\n\t v$major >= 0 ? fmt(\"%d\", v$major) : \"\",\n\t v$minor >= 0 ? fmt(\".%d\", v$minor) : \"\",\n\t v$minor2 >= 0 ? fmt(\".%d\", v$minor2) : \"\",\n\t v$addl != \"\" ? fmt(\"-%s\", v$addl) : \"\");\n\t}\n\n# Convert a software into a string \"name a.b.cx\".\nfunction software_fmt(s: software): string\n\t{\n\treturn fmt(\"%s %s\", s$name, software_fmt_version(s$version));\n\t}\n\t\nevent software_new(c: connection, host: addr, s: software, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\t{\n\t\tlocal log = LOG::get_file_by_addr(\"software-ext\", host, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), host,\n\t\t s$name, software_fmt_version(s$version), descr);\n\t\t}\n\t}\n\n# Insert a mapping into the table\n# Overides old entries for the same software and generates events if needed.\nevent software_register(c: connection, host: addr, s: software, descr: string)\n\t{\n\t# Host already known?\n\tif ( host !in host_software )\n\t\thost_software[host] = table();\n\n\t# If a software can be installed more than once on a host\n\t# (with a different major version), we identify it by \"-\"\n\tif ( s$name in identify_by_major && s$version$major >= 0 )\n\t\ts$name = fmt(\"%s-%d\", s$name, s$version$major);\n\n\tlocal hs = host_software[host];\n\t# Software already registered for this host?\n\tif ( s$name in hs )\n\t\t{\n\t\tlocal old = hs[s$name];\n\t\t\n\t\t# Is it a potentially interesting version change \n\t\t# and is it a different version?\n\t\tif ( s$name in interesting_version_changes &&\n\t\t software_cmp_version(old$version, s$version) != 0 )\n\t\t\t{\n\t\t\tlocal msg = fmt(\"%.6f %s switched from %s to %s (%s)\",\n\t\t\t\t\tnetwork_time(), software_endpoint_name(c, host),\n\t\t\t\t\tsoftware_fmt_version(old$version),\n\t\t\t\t\tsoftware_fmt(s), descr);\n\t\t\tNOTICE([$note=Software_Version_Change,\n\t\t\t $msg=msg, $sub=software_fmt(s), $conn=c]);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tevent software_new(c, host, s, descr);\n\t\t}\n\n\ths[s$name] = s;\n\t}\n\nevent software_version_found(c: connection, host: addr, s: software,\n\t\t\t\tdescr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\tevent software_register(c, host, s, descr);\n\t}\n\n\n########################################\n# Below are internally defined events. #\n########################################\n\t\nevent software_version_found(c: connection, host: addr, s: software, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\tevent software_register(c, host, s, descr);\n\t}\n\nevent software_parse_error(c: connection, host: addr, descr: string)\n\t{\n\tif ( addr_matches_hosts(host, logging) )\n\t\t{\n\t\t# Here we need a little hack, since software_file is\n\t\t# not always there.\n\t\tlocal msg = fmt(\"%.6f %s: can't parse '%s'\", network_time(),\n\t\t\t\tsoftware_endpoint_name(c, host), descr);\n\n\t\tprint Weird::weird_file, msg;\n\t\t}\n\t}\n\n# I'm not going to handle this at the moment. It doesn't seem terribly useful.\n#event software_unparsed_version_found(c: connection, host: addr, str: string)\n#\t{\n#\tif ( addr_matches_hosts(host, logging) )\n#\t\t{\n#\t\tprint Weird::weird_file, fmt(\"%.6f %s: [%s]\", network_time(),\n#\t\t\t\tsoftware_endpoint_name(c, host), str);\n#\t\t}\n#\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"0005081b48b403ea63b39f019631eae9d89c8f01","subject":"Create ja3.bro","message":"Create ja3.bro","repos":"jatkins-sfdc\/ja3,salesforce\/ja3","old_file":"bro\/ja3.bro","new_file":"bro\/ja3.bro","new_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.2 (March 2017)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n## LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n## LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n## FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro\/ja3.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"1ef67c342a088ad71dc6912bea2d2f43edbc5d10","subject":"New script for extended SSL analysis.","message":"New script for extended SSL analysis.\n\nSolely used for logging X.509 certificate information at the moment.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-ext.bro","new_file":"ssl-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load global-ext\n@load ssl\n\nmodule KnownCerts;\n\nexport {\n\tconst log = open_log_file(\"known-ssl-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst log_hosts: Hosts = LocalHosts &redef;\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tadd c$service[\"SSL\"];\n\t\n\tif ( !ip_matches_hosts(c$id$resp_h, log_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\t\t}\n\t}\n\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'ssl-ext.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"b112431f5026dda3b3ff452ae019a00fe84660d3","subject":"remove outdated enum type","message":"remove outdated enum type\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-ext.bro","new_file":"ssl-ext.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logged_hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", All, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file_by_id(\"ssl-known-certs\", c$id, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", All, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file_by_id(\"ssl-known-certs\", c$id, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"8ce37d97c69b9422bc21fcb7ade1741a2bb83450","subject":"Blank session_http_info records created on access now. Fix for user-agent logging. It was recording user-agents backwards from what the user configured.","message":"Blank session_http_info records created on access now.\nFix for user-agent logging. It was recording user-agents backwards from what the user configured.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext.bro","new_file":"http-ext.bro","new_contents":"@load global-ext\n@load http-request\n\n# I'm working to remove the dependency on this, but I'm not there yet.\n@load http-reply\n\nmodule HTTP;\n\n# Comment out the next line if you don't have or don't want the malware.com.br\n# dataset included.\n#@load malware_com_br_block_list-data\n\nexport {\n\t# Open the log files\n\tglobal http_ext_log = open_log_file(\"http-ext\") &raw_output &redef;\n\tglobal http_malware_log = open_log_file(\"http-malware\") &raw_output &redef;\n\tglobal http_ua_log = open_log_file(\"http-user-agents\") &raw_output &redef;\n\tglobal http_sql_injections_log = open_log_file(\"http-sql-injections\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\tHTTP_Suspicious,\n\t\tHTTP_Malware_com_br_Block_List,\n\t\tHTTP_SQL_Injection_Attempt,\n\t\tHTTP_SQL_Injection_Heavy_Probing,\n\t};\n\t\n\t# Which webservers to log requests for.\n\t# Note that if you choose All or Remote, it will indiscriminately log \n\t# your user's host HTTP requests.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts\n\tconst log_requests_toward: Hosts = LocalHosts &redef;\n\t\n\t# This is list of subnets containing web servers that you'd like to log their\n\t# traffic regardless of the \"log_requests_toward\" variable.\n\tconst ok_to_log: set[subnet] &redef;\n\t\n\t# Which hosts we care about logging user-agents.\n\t# You probably want to leave this alone becase of high memory use.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts\n\tconst log_user_agents_of: Hosts = LocalHosts &redef;\n\t\n\t# This is the regular expression that is used to match URL based SQL injections\n\tconst sql_injection_regex = \n\t\t \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[iI][nN][sS][eE][rR][tT])[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([oO][rR]|[aA][nN][dD])([[:blank:]]|\\\/\\*.*?\\*\\\/)+['\"]?[^a-zA-Z&]+?=\/\n\t\t| \/[\\?&][^[:blank:]]+?=[\\-0-9%]*([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/)*(\\-|\\+|\\|\\|)([[:blank:]]|\\\/\\*.*?\\*\\\/)*([0-9]|\\(?[cC][oO][nN][vV][eE][rR][tT]|[cC][aA][sS][tT])\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/|;)*([oO][rR]|[aA][nN][dD]|[hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[rR][eE][gG][eE][xX][pP]|[iI][nN][sS][eE][rR][tT]|\\()[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]]+?=[^\\.]*?([cC][hH][aA][rR]|[aA][sS][cC][iI][iI]|[sS][uU][bB][sS][tT][rR][iI][nN][gG]|[tT][rR][uU][nN][cC][aA][tT][eE]|[vV][eE][rR][sS][iI][oO][nN]|[lL][eE][nN][gG][tT][hH])\\(\/;\n\n\t# SQL injection probes are considered to be:\n\t# 1. A single single-quote at the end of a URL with no other single-quotes.\n\t# 2. URLs with one single quote at the end of a normal GET value.\n\tconst sql_injection_probe_regex = \n\t\t \/^[^\\']+\\'$\/ \n\t\t| \/^[^\\']+\\'&[^\\']*$\/;\n\tconst sql_injection_probe_threshold = 5;\n\t\n\t# HTTP post data contents that appear suspicious.\n\t# This is usually spamming forum postings and the like.\n\tconst suspicious_http_posts = \n\t\t\/[vV][iI][aA][gG][rR][aA]\/ | \n\t\t\/[tT][rR][aA][mM][aA][dD][oO][lL]\/ |\n\t\t\/[cC][iI][aA][lL][iI][sS]\/ | \n\t\t\/[sS][oO][mM][aA]\/ | \n\t\t\/[hH][yY][dD][rR][oO][cC][oO][dD][oO][nN][eE]\/ |\n\t\t\/[cC][aA][nN][aA][dD][iI][aA][nN].{0,15}[pP][hH][aA][rR][mM][aA][cC][yY]\/ |\n\t\t\/[rR][iI][nN][gG].?[tT][oO][nN][eE]\/ |\n\t\t\/[pP][eE][nN][iI][sS]\/ | \n\t\t\/[oO][nN][lL][iI][nN][eE].?[cC][aA][sS][iI][nN][oO]\/ |\n\t\t\/[rR][eE][mM][oO][rR][tT][gG][aA][gG][eE][sS]\/ |\n\t\t# more than 4 bbcode style links in a POST is deemed suspicious\n\t\t\/(url=http:.*){4}\/ | \n\t\t# more that 4 html links is also suspicious\n\t\t\/(a.href(=|%3[dD]).*){4}\/ &redef;\n}\n\nglobal sql_injection_probes_from: table[addr] of count &default=0 &create_expire=10mins &synchronized;\n\ntype http_info: record {\n\thost: string &default=\"\";\n\treferer: string &default=\"\";\n\tuser_agent: string &default=\"\";\n\tproxied_for: string &default=\"\";\n};\n\nglobal http_log_post: set[conn_id] &write_expire=15secs;\n\nfunction default_http_session_info(id: conn_id): http_info\n\t{\n\tlocal tmp: http_info;\n\treturn tmp;\n\t}\n\nglobal session_http_info: table[conn_id] of http_info &default=default_http_session_info &write_expire=15secs;\n\n# remember the set of user agents at an ip address for while\nglobal http_remember_user_agents: table[addr] of string_set &synchronized &create_expire=1hr;\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &priority=5\n\t{\n\tif ( !is_orig )\n\t\treturn; \n\t\n\tlocal id = c$id;\n\tlocal s = lookup_http_request_stream(c);\n\tif ( s$first_pending_request !in s$requests )\n\t\treturn;\n\t\n\tlocal msg = get_http_message(s, is_orig);\n\tlocal r = s$requests[s$first_pending_request];\n\tlocal host = session_http_info[c$id]$host;\n\tlocal url = fmt(\"http:\/\/%s%s\", host, r$URI);\n\t\n\tif ( addr_matches_hosts(id$resp_h, log_requests_toward) || \n\t id$resp_h in ok_to_log )\n\t\n\t\tprint http_ext_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t\t id$orig_h, \n\t\t fmt(\"%d\", id$orig_p), \n\t\t id$resp_h, \n\t\t fmt(\"%d\", id$resp_p),\n\t\t r$method, \n\t\t url, \n\t\t session_http_info[c$id]$referer);\n\t\n\tlocal log_sql=F;\n\tlocal direction = \"\";\n\t# Detect and log SQL injection attempts in their own log file\n\tif ( sql_injection_regex in r$URI )\n\t\t{\n\t\tlog_sql=T;\n\t\tdirection = \"outbound\";\n\t\tif ( is_local_addr(id$resp_h) )\n\t\t\tdirection=\"inbound\";\n\t\t}\n\tif ( sql_injection_probe_regex in r$URI )\n\t\t{\n\t\tlog_sql=T;\n\t\tdirection=\"PROBE\";\n\t\tif ( ++sql_injection_probes_from[id$orig_h] >= sql_injection_probe_threshold )\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Heavy_Probing, \n\t\t\t $msg=fmt(\"Heavy probing from %s\", id$orig_h), \n\t\t\t $n=sql_injection_probes_from[id$orig_h], \n\t\t\t $conn=c]);\n\t\t}\n\tif ( log_sql )\n\t\t{\n\t\tprint http_sql_injections_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), \n\t\t id$resp_h, fmt(\"%d\", id$resp_p), \n\t\t direction, r$method, url, \n\t\t session_http_info[c$id]$referer, \n\t\t session_http_info[c$id]$user_agent, \n\t\t session_http_info[c$id]$proxied_for);\n\t\tNOTICE([$note=HTTP_SQL_Injection_Attempt,\n\t\t $msg=fmt(\"SQL Injection request: %s -> %s\", \n\t\t numeric_id_string(id), url),\n\t\t $conn=c]);\n\t\t}\n\t\n@ifdef ( MalwareComBr_BlockList )\n\tif ( MalwareComBr_BlockList in url )\n\t\t{\n\t\tadd http_log_post[id];\n\t\tlocal malware_com_br_msg = fmt(\"%s %s %s\", r$method, url, referrer);\n\t\tNOTICE([$note=HTTP_Malware_com_br_Block_List, $msg=malware_com_br_msg, $conn=c]);\n\t\t}\n@endif\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( is_orig && \n\t (c$id in http_log_post || suspicious_http_posts in data) )\n\t\t{\n\t\tprint http_ext_log, fmt(\"%.6f %s POST data: %s User-Agent: %s Referrer: %s Proxied for: %s\", \n\t\t network_time(), numeric_id_string(c$id), data, \n\t\t session_http_info[c$id]$user_agent, \n\t\t session_http_info[c$id]$referer, \n\t\t session_http_info[c$id]$proxied_for);\n\t\t}\n\t}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in session_http_info )\n\t\t{\n\t\tlocal blah: http_info;\n\t\tsession_http_info[c$id] = blah;\n\t\t}\n\n\tif ( name == \"REFERER\" )\n\t\tsession_http_info[c$id]$referer = value; \n\n\tif ( name == \"USER-AGENT\" )\n\t\t{\n\t\tsession_http_info[c$id]$user_agent = value;\n\t\tif ( addr_matches_hosts(c$id$orig_h, log_user_agents_of) &&\n\t\t (c$id$orig_h !in http_remember_user_agents ||\n\t\t (c$id$orig_h in http_remember_user_agents && \n\t\t value !in http_remember_user_agents[c$id$orig_h]) ) )\n\t\t\t{\n\t\t\tif ( c$id$orig_h !in http_remember_user_agents )\n\t\t\t\thttp_remember_user_agents[c$id$orig_h] = set();\n\t\t\tadd http_remember_user_agents[c$id$orig_h][value];\n\t\t\tprint http_ua_log, fmt(\"%.6f %s %s\", network_time(), c$id$orig_h, value);\n\t\t\t}\n\t\t}\n\n\tif ( name == \"HTTP_FORWARDED\" ||\n\t name == \"FORWARDED\" ||\n\t name == \"HTTP_X_FORWARDED_FOR\" ||\n\t name == \"X_FORWARDED_FOR\" ||\n\t name == \"HTTP_X_FORWARDED_FROM\" ||\n\t name == \"X_FORWARDED_FROM\" ||\n\t name == \"HTTP_CLIENT_IP\" ||\n\t name == \"CLIENT_IP\" ||\n\t name == \"HTTP_FROM\" ||\n\t name == \"FROM\" ||\n\t name == \"HTTP_VIA\" ||\n\t name == \"VIA\" ||\n\t name == \"HTTP_XROXY_CONNECTION\" ||\n\t name == \"XROXY_CONNECTION\" ||\n\t name == \"HTTP_PROXY_CONNECTION\" ||\n\t name == \"PROXY_CONNECTION\")\n\t\t{\n\t\tif ( session_http_info[c$id]$proxied_for == \"\" )\n\t\t\tsession_http_info[c$id]$proxied_for = fmt(\"(%s::%s)\", name, value);\n\t\t}\n\t\t\t\n\t# This is duplicating effort from the http-reply script, but it seems\n\t# worthwhile to do it here because we don't have to do as many function\n\t# calls since this is regularly done in http traffic.\n\tif ( name == \"HOST\" )\n\t\t\tsession_http_info[c$id]$host = value;\n\t}\n","old_contents":"@load global-ext\n@load http-request\n\n# I'm working to remove the dependency on this, but I'm not there yet.\n@load http-reply\n\nmodule HTTP;\n\n# Comment out the next line if you don't have or don't want the malware.com.br\n# dataset included.\n#@load malware_com_br_block_list-data\n\nexport {\n\t# Open the log files\n\tglobal http_ext_log = open_log_file(\"http-ext\") &raw_output &redef;\n\tglobal http_malware_log = open_log_file(\"http-malware\") &raw_output &redef;\n\tglobal http_ua_log = open_log_file(\"http-user-agents\") &raw_output &redef;\n\tglobal http_sql_injections_log = open_log_file(\"http-sql-injections\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\tHTTP_Suspicious,\n\t\tHTTP_Malware_com_br_Block_List,\n\t\tHTTP_SQL_Injection_Attempt,\n\t\tHTTP_SQL_Injection_Heavy_Probing,\n\t};\n\t\n\t# Which webservers to log requests for.\n\t# Note that if you choose All or Remote, it will indiscriminately log \n\t# your user's host HTTP requests.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts\n\tconst log_requests_toward: Hosts = LocalHosts &redef;\n\t\n\t# This is list of subnets containing web servers that you'd like to log their\n\t# traffic regardless of the \"log_requests_toward\" variable.\n\tconst ok_to_log: set[subnet] &redef;\n\t\n\t# Which hosts we care about logging user-agents.\n\t# You probably want to leave this alone becase of high memory use.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts\n\tconst log_user_agents_of: Hosts = LocalHosts &redef;\n\t\n\t# This is the regular expression that is used to match URL based SQL injections\n\tconst sql_injection_regex = \n\t\t \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[iI][nN][sS][eE][rR][tT])[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=[\\-0-9%]+([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]?([[:blank:]]|\\\/\\*.*?\\*\\\/|\\)?;)+([oO][rR]|[aA][nN][dD])([[:blank:]]|\\\/\\*.*?\\*\\\/)+['\"]?[^a-zA-Z&]+?=\/\n\t\t| \/[\\?&][^[:blank:]]+?=[\\-0-9%]*([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/)*(\\-|\\+|\\|\\|)([[:blank:]]|\\\/\\*.*?\\*\\\/)*([0-9]|\\(?[cC][oO][nN][vV][eE][rR][tT]|[cC][aA][sS][tT])\/\n\t\t| \/[\\?&][^[:blank:]\\|]+?=([[:blank:]]|\\\/\\*.*?\\*\\\/)*['\"]([[:blank:]]|\\\/\\*.*?\\*\\\/|;)*([oO][rR]|[aA][nN][dD]|[hH][aA][vV][iI][nN][gG]|[uU][nN][iI][oO][nN]|[eE][xX][eE][cC]|[sS][eE][lL][eE][cC][tT]|[dD][eE][lL][eE][tT][eE]|[dD][rR][oO][pP]|[dD][eE][cC][lL][aA][rR][eE]|[cC][rR][eE][aA][tT][eE]|[rR][eE][gG][eE][xX][pP]|[iI][nN][sS][eE][rR][tT]|\\()[^a-zA-Z&]\/\n\t\t| \/[\\?&][^[:blank:]]+?=[^\\.]*?([cC][hH][aA][rR]|[aA][sS][cC][iI][iI]|[sS][uU][bB][sS][tT][rR][iI][nN][gG]|[tT][rR][uU][nN][cC][aA][tT][eE]|[vV][eE][rR][sS][iI][oO][nN]|[lL][eE][nN][gG][tT][hH])\\(\/;\n\n\t# SQL injection probes are considered to be:\n\t# 1. A single single-quote at the end of a URL with no other single-quotes.\n\t# 2. URLs with one single quote at the end of a normal GET value.\n\tconst sql_injection_probe_regex = \n\t\t \/^[^\\']+\\'$\/ \n\t\t| \/^[^\\']+\\'&[^\\']*$\/;\n\tconst sql_injection_probe_threshold = 5;\n\t\n\t# HTTP post data contents that appear suspicious.\n\t# This is usually spamming forum postings and the like.\n\tconst suspicious_http_posts = \n\t\t\/[vV][iI][aA][gG][rR][aA]\/ | \n\t\t\/[tT][rR][aA][mM][aA][dD][oO][lL]\/ |\n\t\t\/[cC][iI][aA][lL][iI][sS]\/ | \n\t\t\/[sS][oO][mM][aA]\/ | \n\t\t\/[hH][yY][dD][rR][oO][cC][oO][dD][oO][nN][eE]\/ |\n\t\t\/[cC][aA][nN][aA][dD][iI][aA][nN].{0,15}[pP][hH][aA][rR][mM][aA][cC][yY]\/ |\n\t\t\/[rR][iI][nN][gG].?[tT][oO][nN][eE]\/ |\n\t\t\/[pP][eE][nN][iI][sS]\/ | \n\t\t\/[oO][nN][lL][iI][nN][eE].?[cC][aA][sS][iI][nN][oO]\/ |\n\t\t\/[rR][eE][mM][oO][rR][tT][gG][aA][gG][eE][sS]\/ |\n\t\t# more than 4 bbcode style links in a POST is deemed suspicious\n\t\t\/(url=http:.*){4}\/ | \n\t\t# more that 4 html links is also suspicious\n\t\t\/(a.href(=|%3[dD]).*){4}\/ &redef;\n}\n\nglobal sql_injection_probes_from: table[addr] of count &default=0 &create_expire=10mins &synchronized;\n\ntype http_info: record {\n\thost: string &default=\"\";\n\treferer: string &default=\"\";\n\tuser_agent: string &default=\"\";\n\tproxied_for: string &default=\"\";\n};\n\nglobal http_log_post: set[conn_id] &write_expire=15secs;\nglobal session_http_info: table[conn_id] of http_info &write_expire=5secs;\n\n# remember the set of user agents at an ip address for while\nglobal http_remember_user_agents: table[addr] of string_set &synchronized &create_expire=1hr;\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat) &priority=5\n\t{\n\tif ( !is_orig )\n\t\treturn; \n\n\tlocal id = c$id;\n\tlocal s = lookup_http_request_stream(c);\n\tif ( s$first_pending_request !in s$requests )\n\t\treturn;\n\t\t\n\tlocal msg = get_http_message(s, is_orig);\n\tlocal r = s$requests[s$first_pending_request];\n\tlocal host = session_http_info[c$id]$host;\n\tlocal url = fmt(\"http:\/\/%s%s\", host, r$URI);\n\n\tif ( addr_matches_hosts(id$resp_h, log_requests_toward) || \n\t id$resp_h in ok_to_log )\n\n\t\tprint http_ext_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t\t id$orig_h, \n\t\t fmt(\"%d\", id$orig_p), \n\t\t id$resp_h, \n\t\t fmt(\"%d\", id$resp_p),\n\t\t r$method, \n\t\t url, \n\t\t session_http_info[c$id]$referer);\n\n\tlocal log_sql=F;\n\tlocal direction = \"\";\n\t# Detect and log SQL injection attempts in their own log file\n\tif ( sql_injection_regex in r$URI )\n\t\t{\n\t\tlog_sql=T;\n\t\tdirection = \"outbound\";\n\t\tif ( is_local_addr(id$resp_h) )\n\t\t\tdirection=\"inbound\";\n\t\t}\n\tif ( sql_injection_probe_regex in r$URI )\n\t\t{\n\t\tlog_sql=T;\n\t\tdirection=\"PROBE\";\n\t\tif ( ++sql_injection_probes_from[id$orig_h] >= sql_injection_probe_threshold )\n\t\t\tNOTICE([$note=HTTP_SQL_Injection_Heavy_Probing, \n\t\t\t $msg=fmt(\"Heavy probing from %s\", id$orig_h), \n\t\t\t $n=sql_injection_probes_from[id$orig_h], \n\t\t\t $conn=c]);\n\t\t}\n\tif ( log_sql )\n\t\t{\n\t\tprint http_sql_injections_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), \n\t\t id$resp_h, fmt(\"%d\", id$resp_p), \n\t\t direction, r$method, url, \n\t\t session_http_info[c$id]$referer, \n\t\t session_http_info[c$id]$user_agent, \n\t\t session_http_info[c$id]$proxied_for);\n\t\tNOTICE([$note=HTTP_SQL_Injection_Attempt,\n\t\t $msg=fmt(\"SQL Injection request: %s -> %s\", \n\t\t numeric_id_string(id), url),\n\t\t $conn=c]);\n\t\t}\n\t\n@ifdef ( MalwareComBr_BlockList )\n\tif ( MalwareComBr_BlockList in url )\n\t\t{\n\t\tadd http_log_post[id];\n\t\tlocal malware_com_br_msg = fmt(\"%s %s %s\", r$method, url, referrer);\n\t\tNOTICE([$note=HTTP_Malware_com_br_Block_List, $msg=malware_com_br_msg, $conn=c]);\n\t\t}\n@endif\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( is_orig && \n\t (c$id in http_log_post || suspicious_http_posts in data) )\n\t\t{\n\t\tprint http_ext_log, fmt(\"%.6f %s POST data: %s User-Agent: %s Referrer: %s Proxied for: %s\", \n\t\t network_time(), numeric_id_string(c$id), data, \n\t\t session_http_info[c$id]$user_agent, \n\t\t session_http_info[c$id]$referer, \n\t\t session_http_info[c$id]$proxied_for);\n\t\t}\n\t}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in session_http_info )\n\t\t{\n\t\tlocal blah: http_info;\n\t\tsession_http_info[c$id] = blah;\n\t\t}\n\n\tif ( name == \"REFERER\" )\n\t\tsession_http_info[c$id]$referer = value; \n\n\tif ( name == \"USER-AGENT\" )\n\t\t{\n\t\tsession_http_info[c$id]$user_agent = value;\n\t\tif ( addr_matches_hosts(c$id$resp_h, log_user_agents_of) &&\n\t\t (c$id$orig_h !in http_remember_user_agents ||\n\t\t (c$id$orig_h in http_remember_user_agents && \n\t\t value !in http_remember_user_agents[c$id$orig_h]) ) )\n\t\t\t{\n\t\t\tif ( c$id$orig_h !in http_remember_user_agents )\n\t\t\t\thttp_remember_user_agents[c$id$orig_h] = set();\n\t\t\tadd http_remember_user_agents[c$id$orig_h][value];\n\t\t\tprint http_ua_log, fmt(\"%.6f %s %s\", network_time(), c$id$orig_h, value);\n\t\t\t}\n\t\t}\n\n\tif ( name == \"HTTP_FORWARDED\" ||\n\t name == \"FORWARDED\" ||\n\t name == \"HTTP_X_FORWARDED_FOR\" ||\n\t name == \"X_FORWARDED_FOR\" ||\n\t name == \"HTTP_X_FORWARDED_FROM\" ||\n\t name == \"X_FORWARDED_FROM\" ||\n\t name == \"HTTP_CLIENT_IP\" ||\n\t name == \"CLIENT_IP\" ||\n\t name == \"HTTP_FROM\" ||\n\t name == \"FROM\" ||\n\t name == \"HTTP_VIA\" ||\n\t name == \"VIA\" ||\n\t name == \"HTTP_XROXY_CONNECTION\" ||\n\t name == \"XROXY_CONNECTION\" ||\n\t name == \"HTTP_PROXY_CONNECTION\" ||\n\t name == \"PROXY_CONNECTION\")\n\t\t{\n\t\tif ( session_http_info[c$id]$proxied_for == \"\" )\n\t\t\tsession_http_info[c$id]$proxied_for = fmt(\"(%s::%s)\", name, value);\n\t\t}\n\t\t\t\n\t# This is duplicating effort from the http-reply script, but it seems\n\t# worthwhile to do it here because we don't have to do as many function\n\t# calls since this is regularly done in http traffic.\n\tif ( name == \"HOST\" )\n\t\t\tsession_http_info[c$id]$host = value;\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"74dd863335be8a14d12d04f6f921d7a8af9c8926","subject":"bro-scripts: ntp-audit.bro: changed alert msg to match purpose","message":"bro-scripts: ntp-audit.bro: changed alert msg to match purpose\n","repos":"jonschipp\/bro-scripts,unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts,unusedPhD\/jonschipp_bro-scripts","old_file":"ntp-audit.bro","new_file":"ntp-audit.bro","new_contents":"# Written by Jon Schipp\n# Detects when hosts send NTP queries to NTP servers not defined in time_servers.\n# \tTo use:\n# \t\t1. Add script to configuration local.bro: $ echo '@load ntp-audit.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# \t\t2. Copy script to $BROPREFIX\/share\/bro\/site\n# \t\t3. $ broctl check && broctl install && broctl restart\n\n@load base\/frameworks\/notice\n\n# List your NTP servers here\t\nconst time_servers: set[addr] = {\n\t192.168.1.250,\n\t192.168.1.251,\n} &redef;\n\n# List any source addresses that should be excluded\nconst time_exclude: set[addr] = {\n\t192.168.1.250,\n\t192.168.1.251,\n\t192.168.1.1, # Gateway\/NAT \n} &redef;\n\nexport {\n\n redef enum Notice::Type += {\n NTP::Query_Sent_To_Wrong_Server\n };\n}\n\nredef Notice::emailed_types += {\n NTP::Query_Sent_To_Wrong_Server\n};\n\nevent udp_request(u: connection)\n {\n if ( u$id$orig_h !in time_exclude && u$id$resp_h !in time_servers && u$id$resp_p == 123\/udp )\n {\n NOTICE([$note=NTP::Query_Sent_To_Wrong_Server,\n $msg=\"NTP query destined to non-defined NTP servers\", $conn=u,\n $identifier=cat(u$id$orig_h),\n $suppress_for=1day]);\n }\n }\n","old_contents":"# Written by Jon Schipp\n# Detects when hosts send NTP queries to NTP servers not defined in time_servers.\n# \tTo use:\n# \t\t1. Add script to configuration local.bro: $ echo '@load ntp-audit.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# \t\t2. Copy script to $BROPREFIX\/share\/bro\/site\n# \t\t3. $ broctl check && broctl install && broctl restart\n\n@load base\/frameworks\/notice\n\n# List your NTP servers here\t\nconst time_servers: set[addr] = {\n\t192.168.1.250,\n\t192.168.1.251,\n} &redef;\n\n# List any source addresses that should be excluded\nconst time_exclude: set[addr] = {\n\t192.168.1.250,\n\t192.168.1.251,\n\t192.168.1.1, # Gateway\/NAT \n} &redef;\n\nexport {\n\n redef enum Notice::Type += {\n NTP::Query_Sent_To_Wrong_Server\n };\n}\n\nredef Notice::emailed_types += {\n NTP::Query_Sent_To_Wrong_Server\n};\n\nevent udp_request(u: connection)\n {\n if ( u$id$orig_h !in time_exclude && u$id$resp_h !in time_servers && u$id$resp_p == 123\/udp )\n {\n NOTICE([$note=NTP::Query_Sent_To_Wrong_Server,\n $msg=\"NTP query destined to non-TOC NTP servers\", $conn=u,\n $identifier=cat(u$id$orig_h),\n $suppress_for=1day]);\n }\n }\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f49948a866bb89439e7794ba85edb955b28b9029","subject":"don't need to change priority","message":"don't need to change priority\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-external-names.bro","new_file":"http-ext-external-names.bro","new_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)albany\\.edu($|:)\/ &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info)\n{\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","old_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)albany\\.edu($|:)\/ &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=10\n{\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"5b2948f1ca2efd7925909851c61c7d1d76a17ada","subject":"Update detect-shellshock.bro","message":"Update detect-shellshock.bro\n\nAdded contact information.","repos":"CrowdStrike\/cs-bro,albertzaharovits\/cs-bro,kingtuna\/cs-bro,theflakes\/cs-bro,unusedPhD\/CrowdStrike_cs-bro","old_file":"bro-scripts\/shellshock\/detect-shellshock.bro","new_file":"bro-scripts\/shellshock\/detect-shellshock.bro","new_contents":"# Monitors traffic for Shellshock exploit attempts\n# When exploits are seen containing IP addresses and domain values, monitors traffic for 60 minutes watching for endpoints to connect to IP addresses and domains seen in exploit attempts\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n@load base\/protocols\/dhcp\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Shellshock_DHCP,\n Shellshock_HTTP,\n Shellshock_Successful_Conn\n };\n}\n\nconst shellshock_pattern = \/(\\(|%28)(\\)|%29)( |%20)(\\{|%7B)\/ &redef;\n\nconst shellshock_commands = \/wget\/ | \/curl\/;\n\nglobal shellshock_servers: set[addr] &create_expire=60min &synchronized;\nglobal shellshock_hosts: set[string] &create_expire=60min &synchronized;\n\n# function to locate and extract domains seen in shellshock exploit attempts\nfunction find_domain(ss: string)\n{\nlocal parts1 = split_all(ss,\/[[:space:]]\/);\nfor ( p in parts1 )\n if ( \"http\" in parts1[p] )\n {\n local parts2 = split_all(parts1[p],\/\\\/\/);\n local output = parts2[5];\n }\n\nif ( output !in shellshock_hosts )\n add shellshock_hosts[output];\n}\n\n# function to locate and extract IP addresses seen in shellshock exploit attempts\nfunction find_ip(ss: string): bool\n{\nlocal b = F;\nlocal remote_servers = find_ip_addresses(ss);\n\nif ( |remote_servers| > 0 )\n {\n b = T;\n for ( rs in remote_servers )\n {\n local s = to_addr(remote_servers[rs]);\n if ( s !in shellshock_servers )\n add shellshock_servers[s];\n }\n }\n\nreturn b;\n}\n\n# event to identify shellshock HTTP exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3\n{\nif ( ! is_orig ) return;\nif ( shellshock_pattern !in value ) return;\n\n# generate a notice of the HTTP exploit attempt\nNOTICE([$note=Shellshock_HTTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock HTTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in value )\n find_domain(value);\n}\n\n# event to identify shellshock DHCP exploit attempts\nevent dhcp_ack(c: connection, msg: dhcp_msg, mask: addr, router: dhcp_router_list, lease: interval, serv_addr: addr, host_name: string)\n{\nif ( shellshock_pattern !in host_name ) return;\n\n# generate a notice of the DHCP exploit attempt\nNOTICE([$note=Shellshock_DHCP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock DHCP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",host_name),\n $identifier=cat(c$id$orig_h,c$id$resp_h,host_name)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(host_name) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in host_name )\n find_domain(host_name);\n}\n\n# event to identify endpoints connecting to domains seen in shellshock exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=5\n{\nif ( name != \"HOST\" ) return;\nif ( value in shellshock_hosts )\n # generate a notice of HTTP connection to domain seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to a domain seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"Domain: %s\",value),\n $identifier=cat(c$id$orig_h,value)]);\n}\n\n# event to identify endpoints connecting to IP addresses seen in shellshock exploit attempts\nevent connection_state_remove(c: connection)\n{\nif ( c$id$resp_h in shellshock_servers )\n # generate a notice of connection to IP address seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to an IP address seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"IP address: %s\",c$id$resp_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"# Monitors traffic for Shellshock exploit attempts\n# When exploits are seen containing IP addresses and domain values, monitors traffic for 60 minutes watching for endpoints to connect to IP addresses and domains seen in exploit attempts\n# CrowdStrike 2014\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n@load base\/protocols\/dhcp\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Shellshock_DHCP,\n Shellshock_HTTP,\n Shellshock_Successful_Conn\n };\n}\n\nconst shellshock_pattern = \/(\\(|%28)(\\)|%29)( |%20)(\\{|%7B)\/ &redef;\n\nconst shellshock_commands = \/wget\/ | \/curl\/;\n\nglobal shellshock_servers: set[addr] &create_expire=60min &synchronized;\nglobal shellshock_hosts: set[string] &create_expire=60min &synchronized;\n\n# function to locate and extract domains seen in shellshock exploit attempts\nfunction find_domain(ss: string)\n{\nlocal parts1 = split_all(ss,\/[[:space:]]\/);\nfor ( p in parts1 )\n if ( \"http\" in parts1[p] )\n {\n local parts2 = split_all(parts1[p],\/\\\/\/);\n local output = parts2[5];\n }\n\nif ( output !in shellshock_hosts )\n add shellshock_hosts[output];\n}\n\n# function to locate and extract IP addresses seen in shellshock exploit attempts\nfunction find_ip(ss: string): bool\n{\nlocal b = F;\nlocal remote_servers = find_ip_addresses(ss);\n\nif ( |remote_servers| > 0 )\n {\n b = T;\n for ( rs in remote_servers )\n {\n local s = to_addr(remote_servers[rs]);\n if ( s !in shellshock_servers )\n add shellshock_servers[s];\n }\n }\n\nreturn b;\n}\n\n# event to identify shellshock HTTP exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3\n{\nif ( ! is_orig ) return;\nif ( shellshock_pattern !in value ) return;\n\n# generate a notice of the HTTP exploit attempt\nNOTICE([$note=Shellshock_HTTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock HTTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in value )\n find_domain(value);\n}\n\n# event to identify shellshock DHCP exploit attempts\nevent dhcp_ack(c: connection, msg: dhcp_msg, mask: addr, router: dhcp_router_list, lease: interval, serv_addr: addr, host_name: string)\n{\nif ( shellshock_pattern !in host_name ) return;\n\n# generate a notice of the DHCP exploit attempt\nNOTICE([$note=Shellshock_DHCP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock DHCP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",host_name),\n $identifier=cat(c$id$orig_h,c$id$resp_h,host_name)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(host_name) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in host_name )\n find_domain(host_name);\n}\n\n# event to identify endpoints connecting to domains seen in shellshock exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=5\n{\nif ( name != \"HOST\" ) return;\nif ( value in shellshock_hosts )\n # generate a notice of HTTP connection to domain seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to a domain seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"Domain: %s\",value),\n $identifier=cat(c$id$orig_h,value)]);\n}\n\n# event to identify endpoints connecting to IP addresses seen in shellshock exploit attempts\nevent connection_state_remove(c: connection)\n{\nif ( c$id$resp_h in shellshock_servers )\n # generate a notice of connection to IP address seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to an IP address seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"IP address: %s\",c$id$resp_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"f3e07b33f2a5f6a6097bbc2c90753624731e75c1","subject":"Update expand-query.bro","message":"Update expand-query.bro","repos":"CrowdStrike\/cs-bro","old_file":"bro-scripts\/extensions\/dns\/expand-query.bro","new_file":"bro-scripts\/extensions\/dns\/expand-query.bro","new_contents":"# Creates a vector from a DNS query\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n# @jshlbrd\n\n@load base\/protocols\/dns\n@load base\/protocols\/http\n\nmodule DNS;\n\nredef record DNS::Info += {\n\tquery_vec: vector of string &log &optional;\n\tquery_vec_size: count &log &optional;\n};\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\n\tif( c?$dns ) {\n\t\tc$dns$query_vec = HTTP::extract_keys(query,\/\\.\/);\n\t\tc$dns$query_vec_size = |c$dns$query_vec|;\n\t}\n}\n","old_contents":"# Creates a vector from a DNS query\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n# @jshlbrd\n\n@load base\/protocols\/dns\n@load base\/protocols\/http\n\nmodule DNS;\n\nredef record DNS::Info += {\n\tquery_vec: vector of string &log &optional;\n\tquery_vec_size: count &log &optional;\n};\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\nc$dns$query_vec = HTTP::extract_keys(query,\/\\.\/);\nc$dns$query_vec_size = |c$dns$query_vec|;\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"da52b80637f9f44c82365116639496e3eed5fcdf","subject":"commenting out the load conn_asn until we figure out the Geo dependency","message":"commenting out the load conn_asn until we figure out the Geo dependency\n\n\nFormer-commit-id: ee3892e7e106ef391257be567fccea3567f8c80e","repos":"SuperCowPowers\/workbench,SuperCowPowers\/workbench,djtotten\/workbench,djtotten\/workbench,SuperCowPowers\/workbench,djtotten\/workbench","old_file":"server\/workers\/bro\/conn_extensions\/__load__.bro","new_file":"server\/workers\/bro\/conn_extensions\/__load__.bro","new_contents":"##! @load .\/conn_asn\n","old_contents":"@load .\/conn_asn\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"2d341fe05d9220953786992ee67a3b18eee9ac53","subject":"Better detection for MS updates.","message":"Better detection for MS updates.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-identified-files.bro","new_file":"http-ext-identified-files.bro","new_contents":"@load global-ext\n@load http-ext\n\n@load signatures\nredef signature_files += \"http-ext-identified-files.sig\";\n\nmodule HTTP;\n\nexport {\n\tredef enum Notice += {\n\t\t# This notice is thrown when the file extension doesn't \n\t\t# seem to match the file contents.\n\t\tHTTP_IncorrectFileType, \n\t};\n\t\n\t# MIME types that you'd like this script to identify and log.\n\tconst watched_mime_types = \/application\\\/x-dosexec\/\n\t | \/application\\\/x-executable\/ &redef;\n\t\n\t# URLs included here are not logged and notices are not thrown.\n\t# Take care when defining regexes to not be overly broad.\n\tconst ignored_urls = \/^http:\\\/\\\/(au\\.|www\\.)?download\\.windowsupdate\\.com\\\/msdownload\\\/update\/ &redef;\n\t\n\t# Create regexes that *should* in be in the urls for specifics mime types.\n\t# Notices are thrown if the pattern doesn't match the url for the file type.\n\tconst mime_types_extensions: table[string] of pattern = {\n\t\t[\"application\/x-dosexec\"] = \/\\.([eE][xX][eE]|[dD][lL][lL])\/,\n\t} &redef;\n}\n\n# Don't delete the http sessions at the end of the request!\nredef watch_reply=T;\n\n# Make the default signature action ignore anything beginning with \"matchfile\"\nfunction default_signature_action(sig: string): SigAction\n\t{\n\tif ( \/^matchfile-\/ in sig )\n\t\treturn SIG_IGNORE;\n\telse\n\t\treturn SIG_ALARM;\n\t}\nredef signature_actions &default=default_signature_action;\n\n# This script uses the file tagging method to create a separate file.\nevent bro_init()\n\t{\n\t# Add the tag for log file splitting.\n\tLOG::define_tag(\"http-ext\", \"identified-files\");\n\t}\n\nevent signature_match(state: signature_state, msg: string, data: string)\n\t{\n\t# Only signatures matching file types are dealt with here.\n\tif ( \/^matchfile\/ !in state$id ) return;\n\t\n\t# Not much point in any of this if we don't know about the \n\t# HTTP-ness of the connection.\n\tif ( state$conn$id !in conn_info ) return;\n\t\n\tlocal si = conn_info[state$conn$id];\n\t# Set the mime type seen.\n\tsi$mime_type = msg;\n\t\n\tif ( watched_mime_types in msg )\n\t\t{\n\t\t# Add a tag for logging purposes.\n\t\tadd si$tags[\"identified-files\"];\n\t\t}\n\t\t\n\tif ( ignored_urls !in si$url &&\n\t msg in mime_types_extensions && \n\t mime_types_extensions[msg] !in si$url )\n\t\t{\n\t\tlocal message = fmt(\"%s %s %s\", msg, si$method, si$url);\n\t\tNOTICE([$note=HTTP_IncorrectFileType, \n\t\t $msg=message, \n\t\t $conn=state$conn, \n\t\t $method=si$method, \n\t\t $URL=si$url]);\n\t\t}\n\t\n\tevent file_transferred(state$conn, data, \"\", msg);\n\t}\n\n","old_contents":"@load global-ext\n@load http-ext\n\n@load signatures\nredef signature_files += \"http-ext-identified-files.sig\";\n\nmodule HTTP;\n\nexport {\n\tredef enum Notice += {\n\t\t# This notice is thrown when the file extension doesn't \n\t\t# seem to match the file contents.\n\t\tHTTP_IncorrectFileType, \n\t};\n\t\n\t# MIME types that you'd like this script to identify and log.\n\tconst watched_mime_types = \/application\\\/x-dosexec\/\n\t | \/application\\\/x-executable\/ &redef;\n\t\n\t# URLs included here are not logged and notices are not thrown.\n\t# Take care when defining regexes to not be overly broad.\n\tconst ignored_urls = \/^http:\\\/\\\/www\\.download\\.windowsupdate\\.com\\\/\/ &redef;\n\t\n\t# Create regexes that *should* in be in the urls for specifics mime types.\n\t# Notices are thrown if the pattern doesn't match the url for the file type.\n\tconst mime_types_extensions: table[string] of pattern = {\n\t\t[\"application\/x-dosexec\"] = \/\\.([eE][xX][eE]|[dD][lL][lL])\/,\n\t} &redef;\n}\n\n# Don't delete the http sessions at the end of the request!\nredef watch_reply=T;\n\n# Make the default signature action ignore anything beginning with \"matchfile\"\nfunction default_signature_action(sig: string): SigAction\n\t{\n\tif ( \/^matchfile-\/ in sig )\n\t\treturn SIG_IGNORE;\n\telse\n\t\treturn SIG_ALARM;\n\t}\nredef signature_actions &default=default_signature_action;\n\n# This script uses the file tagging method to create a separate file.\nevent bro_init()\n\t{\n\t# Add the tag for log file splitting.\n\tLOG::define_tag(\"http-ext\", \"identified-files\");\n\t}\n\nevent signature_match(state: signature_state, msg: string, data: string)\n\t{\n\t# Only signatures matching file types are dealt with here.\n\tif ( \/^matchfile\/ !in state$id ) return;\n\t\n\t# Not much point in any of this if we don't know about the \n\t# HTTP-ness of the connection.\n\tif ( state$conn$id !in conn_info ) return;\n\t\n\tlocal si = conn_info[state$conn$id];\n\t# Set the mime type seen.\n\tsi$mime_type = msg;\n\t\n\tif ( watched_mime_types in msg )\n\t\t{\n\t\t# Add a tag for logging purposes.\n\t\tadd si$tags[\"identified-files\"];\n\t\t}\n\t\t\n\tif ( ignored_urls !in si$url &&\n\t msg in mime_types_extensions && \n\t mime_types_extensions[msg] !in si$url )\n\t\t{\n\t\tlocal message = fmt(\"%s %s %s\", msg, si$method, si$url);\n\t\tNOTICE([$note=HTTP_IncorrectFileType, \n\t\t $msg=message, \n\t\t $conn=state$conn, \n\t\t $method=si$method, \n\t\t $URL=si$url]);\n\t\t}\n\t\n\tevent file_transferred(state$conn, data, \"\", msg);\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"075b6c068ce6f4723789110aa635a0f69f594860","subject":"set bro control port bind to 127.0.0.1","message":"set bro control port bind to 127.0.0.1\n","repos":"MelvinTo\/firewalla,MelvinTo\/firewalla,firewalla\/firewalla,firewalla\/firewalla,MelvinTo\/firewalla,MelvinTo\/firewalla,firewalla\/firewalla,firewalla\/firewalla,firewalla\/firewalla,MelvinTo\/firewalla","old_file":"etc\/local.bro","new_file":"etc\/local.bro","new_contents":"##! Local site policy. Customize as appropriate. \n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\nredef ignore_checksums = T;\nredef SSL::disable_analyzer_after_detection = F;\n\n#@load site\/sqlite.bro\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n@load tuning\/json-logs\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Log some information about web applications being used by users \n# on your network.\n@load misc\/app-stats\n\n# Detect traceroute being run on the network. \n@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more \n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n@load frameworks\/software\/windows-version-detection\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when \n# running on live traffic. Enable it cautiously.\n#@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets \n# where the name is not part of your local DNS zone and is being hosted \n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n# @load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and \n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\nredef SSL::disable_analyzer_after_detection = F;\nredef Communication::listen_interface = 127.0.0.1;\n\n@load base\/protocols\/dhcp\n","old_contents":"##! Local site policy. Customize as appropriate. \n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\nredef ignore_checksums = T;\nredef SSL::disable_analyzer_after_detection = F;\n\n#@load site\/sqlite.bro\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n@load tuning\/json-logs\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Log some information about web applications being used by users \n# on your network.\n@load misc\/app-stats\n\n# Detect traceroute being run on the network. \n@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more \n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n@load frameworks\/software\/windows-version-detection\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when \n# running on live traffic. Enable it cautiously.\n#@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets \n# where the name is not part of your local DNS zone and is being hosted \n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n# @load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and \n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\nredef SSL::disable_analyzer_after_detection = F;\n\n@load base\/protocols\/dhcp\n","returncode":0,"stderr":"","license":"agpl-3.0","lang":"Bro"} {"commit":"525613a157cc3985edb3181e7baa32af2ab3fc8d","subject":"Create main.bro","message":"Create main.bro","repos":"theflakes\/cs-bro,CrowdStrike\/cs-bro,albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro","old_file":"bro-scripts\/tor\/main.bro","new_file":"bro-scripts\/tor\/main.bro","new_contents":"# Log Tor connections based on IP addresses along with Tor node metadata\n# Based on data collected from torstatus.blutmagie.de\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n# @jshlbrd\n\nmodule Tor;\n\nexport {\n\tredef enum Log::ID += { TOR::LOG };\n\n\ttype Info: record {\n\t## Timestamp for when the event happened.\n\tts: time \t&log;\n\t## Unique ID for the connection.\n\tuid: string &log;\n\t## The connection's 4-tuple of endpoint addresses\/ports.\n\tid: conn_id &log;\n\t## Tor node IP address.\n\ttor_ip: addr &log &optional;\n\t## Tor node router name.\n\trouter_name: string &log &optional;\n\t## Tor node host name.\n\thost_name: string &log &optional;\n\t## Tor node platform \/ version number.\n\tplatform: string &log &optional;\n\t## Tor node country code location.\n\tcountry_code: string &log &optional;\n\t## Tor node bandwidth (in KB\/s).\n\tbandwidth: count\t&log &optional;\n\t## Tor node estimated uptime.\n\tuptime: time\t&log &optional;\n\t## Tor node router port.\n\trouter_port: count\t&log &optional;\n\t## Tor node directory port.\n\tdirectory_port: count\t&log &optional;\n\t## Tor node auth flag.\n\tauth_flag: bool\t&log &optional;\n\t## Tor node exit flag.\n\texit_flag: bool\t&log &optional;\n\t## Tor node fast flag.\n\tfast_flag: bool\t&log &optional;\n\t## Tor node guard flag.\n\tguard_flag: bool\t&log &optional;\n\t## Tor node named flag.\n\tnamed_flag: bool\t&log &optional;\n\t## Tor node stable flag.\n\tstable_flag: bool\t&log &optional;\n\t## Tor node running flag.\n\trunning_flag: bool\t&log &optional;\n\t## Tor node valid flag.\n\tvalid_flag: bool\t&log &optional;\n\t## Tor node v2dir flag.\n\tv2dir_flag: bool\t&log &optional;\n\t## Tor node hibernating flag.\n\thibernating_flag: bool\t&log &optional;\n\t## Tor node bad exit flag.\n\tbad_exit_flag: bool\t&log &optional;\n\t};\n\n\t## Event that can be handled to access the Tor record as it is sent on\n\t## to the logging framework.\n\tglobal log_tor: event(rec: Info);\n}\n\nredef record connection += {\n\ttor: Info &optional;\n};\n\ntype tor_idx: record {\n\ttor_ip:\taddr;\n};\n\ntype tor_table: record {\n\trouter_name: string;\n\tcountry_code: string;\n\tbandwidth: count;\n\tuptime: double;\n\thost_name: string;\n\trouter_port: count;\n\tdirectory_port: string;\n\tauth_flag: count;\n\texit_flag: count;\n\tfast_flag: count;\n\tguard_flag: count;\n\tnamed_flag: count;\n\tstable_flag: count;\n\trunning_flag: count;\n\tvalid_flag: count;\t\n\tv2dir_flag: count;\n\tplatform: string;\n\thibernating_flag: count;\n\tbad_exit_flag: count;\t\n};\n\nglobal torlist: table[addr] of tor_table = table();\n\n# Create the Tor log stream and load the Tor list\nevent bro_init()\n{\nLog::create_stream(TOR::LOG, [$columns=Info, $ev=log_tor]);\nInput::add_table([$source=torlist_location, $name=\"torlist\", $idx=tor_idx, $val=tor_table, $destination=torlist, $mode=Input::REREAD]);\n}\n\n# Function to establish a Tor info record\nfunction set_session(c: connection)\n{\nif ( ! c?$tor )\n\t{\n\tadd c$service[\"tor\"];\n\tc$tor = [$ts=network_time(),$id=c$id,$uid=c$uid];\n\t}\n}\n\n# Function to convert blutmagie Tor flags from count to bool\nfunction convert_flag(flag: count): bool\n{\nif ( flag == 1 )\n\treturn T;\nelse return F;\n}\n\n# Function to set data in the Tor info record\nfunction set_data(c: connection, tor_ip: addr)\n{\nc$tor$tor_ip = tor_ip;\nif ( torlist[tor_ip]?$router_name )\n\tc$tor$router_name = torlist[tor_ip]$router_name;\nif ( torlist[tor_ip]?$host_name )\n\tc$tor$host_name = torlist[tor_ip]$host_name;\nif ( torlist[tor_ip]?$platform )\n\tc$tor$platform = torlist[tor_ip]$platform;\nif ( torlist[tor_ip]?$country_code )\n\tc$tor$country_code = torlist[tor_ip]$country_code;\nif ( torlist[tor_ip]?$bandwidth )\n\tc$tor$bandwidth = torlist[tor_ip]$bandwidth;\n\nif ( torlist[tor_ip]?$uptime )\n\t{\n\t# Uptime is recorded by hour, so we need to convert it to seconds\n\tlocal uptime_hr = torlist[tor_ip]$uptime;\n\tlocal uptime_time = ( uptime_hr * 3600 );\n\tc$tor$uptime = double_to_time(uptime_time);\n\t}\n\nif ( torlist[tor_ip]?$router_port )\n\tc$tor$router_port = torlist[tor_ip]$router_port;\nif ( torlist[tor_ip]?$directory_port )\n\tif ( torlist[tor_ip]$directory_port != \"None\" )\n\t\tc$tor$directory_port = to_count(torlist[tor_ip]$directory_port);\nif ( torlist[tor_ip]?$auth_flag )\n\tc$tor$auth_flag = convert_flag(torlist[tor_ip]$auth_flag);\nif ( torlist[tor_ip]?$exit_flag )\n\tc$tor$exit_flag = convert_flag(torlist[tor_ip]$exit_flag);\nif ( torlist[tor_ip]?$fast_flag )\n\tc$tor$fast_flag = convert_flag(torlist[tor_ip]$fast_flag);\nif ( torlist[tor_ip]?$guard_flag )\n\tc$tor$guard_flag = convert_flag(torlist[tor_ip]$guard_flag);\nif ( torlist[tor_ip]?$named_flag )\n\tc$tor$named_flag = convert_flag(torlist[tor_ip]$named_flag);\nif ( torlist[tor_ip]?$stable_flag )\n\tc$tor$stable_flag = convert_flag(torlist[tor_ip]$stable_flag);\nif ( torlist[tor_ip]?$running_flag )\n\tc$tor$running_flag = convert_flag(torlist[tor_ip]$running_flag);\nif ( torlist[tor_ip]?$valid_flag )\n\tc$tor$valid_flag = convert_flag(torlist[tor_ip]$valid_flag);\nif ( torlist[tor_ip]?$v2dir_flag )\n\tc$tor$v2dir_flag = convert_flag(torlist[tor_ip]$v2dir_flag);\nif ( torlist[tor_ip]?$hibernating_flag )\n\tc$tor$hibernating_flag = convert_flag(torlist[tor_ip]$hibernating_flag);\nif ( torlist[tor_ip]?$bad_exit_flag )\n\tc$tor$bad_exit_flag = convert_flag(torlist[tor_ip]$bad_exit_flag);\n}\n\n# Generate reporter message when the Tor list is updated\nevent Input::end_of_data(name: string, source: string) \n{\nlocal msg = fmt(\"Tor list updated at %s\",network_time());\nLog::write(Reporter::LOG, [$ts=network_time(), $level=Reporter::INFO, $message=msg]);\n}\n\n# Check each new connection for an IP address in the Tor list\nevent new_connection(c: connection )\n{\nif ( c$id$orig_h in torlist ) \n\t{\n\tset_session(c);\n\tset_data(c,c$id$orig_h);\n\t}\nelse if ( c$id$resp_h in torlist )\n\t{\n\tset_session(c);\n\tset_data(c,c$id$resp_h);\n\t}\n}\n\n# Generate the tor.log for each Tor connection \nevent connection_state_remove(c: connection)\n{\nif ( c?$tor )\n\t{\n\tLog::write(TOR::LOG, c$tor);\n\t}\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/tor\/main.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"95c9a5579d7a0899e5b318d35604c8a2dc25b263","subject":"typo \/ signature","message":"typo \/ signature\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dionaea_receiver.bro","new_file":"custom_scripts\/dionaea_receiver.bro","new_contents":"@load .\/dio_incident_log.bro\n@load .\/dio_json_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string);\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_incident::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $connector_id=connector_id];\n\n Log::write(Dio_incident::LOG, rec);\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dst_port, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=src_port, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","old_contents":"@load .\/dio_incident_log.bro\n@load .\/dio_json_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string);\nglobal dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_incident::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $connector_id=connector_id];\n\n Log::write(Dio_incident::LOG, rec);\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dst_port, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=src_port, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"dda47b4369aaa51bcd7fea6975de54553bf87aaf","subject":"Small fixes","message":"Small fixes\n\nNow \"@load\"-ing the http.bro script within http-identified-files.bro so it actually works.\nSmall style fixes.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-identified-files.bro","new_file":"http-identified-files.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n@load http\n\nmodule HTTP;\n\nexport {\n\tconst http_magic_log = open_log_file(\"http-identified-files\") &raw_output &redef;\n\n\t# Base the libmagic analysis on at least this many bytes.\n\tconst magic_content_limit = 1024 &redef;\n\t\n\tconst watched_mime_types: set[string] = { \n\t\t\"application\/x-dosexec\", # Windows and DOS executables\n\t\t\"application\/x-executable\", # *NIX executable binary\n\t} &redef; \n\t\n\tconst watched_descriptions =\n\t\t\/PHP script text\/ &redef;\n\t\n\t# URLs included here are not logged and notices are not thrown.\n\t# Take care when defining regexes to not be overly broad.\n\tconst ignored_urls = \/^http:\\\/\\\/www\\.download\\.windowsupdate\\.com\\\/\/ &redef;\n\t\n\tredef enum Notice += {\n\t\t# This notice is thrown when the file extension doesn't match the file contents\n\t\tHTTP_IncorrectFileType, \n\t};\n\t\n\t# Create regexes that *should* in be in the urls for specifics mime types.\n\t# Notices are thrown if the pattern doesn't match the url for the file type.\n\tconst mime_types_extensions: table[string] of pattern = {\n\t\t[\"application\/x-dosexec\"] = \/\\.([eE][xX][eE]|[dD][lL][lL])\/,\n\t} &redef;\n}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( is_orig ) # We are only watching for server responses\n\t\treturn;\n\t\n\tlocal s = lookup_http_request_stream(c);\n\tlocal msg = get_http_message(s, is_orig);\n\t\n@ifndef\t( content_truncation_limit )\n\t# This is only done if http-body.bro is not loaded.\n\tmsg$data_length = msg$data_length + length;\n@endif\n\t\n\t# For the time being, we'll just use the data from the first packet.\n\t# Don't continue until we have enough data\n\t#if ( msg$data_length < magic_content_limit )\n\t#\treturn;\n\t\n\t# Right now, only try this for the first chunk of data\n\tif ( msg$data_length > length )\n\t\treturn;\n\t\n\tlocal abstract = sub_bytes(data, 1, magic_content_limit);\n\tlocal magic_mime = identify_data(abstract, T);\n\tlocal magic_descr = identify_data(abstract, F);\n\n\tif ( (magic_mime in watched_mime_types ||\n\t watched_descriptions in magic_descr) &&\n\t s$first_pending_request in s$requests )\n\t\t{\n\t\tlocal r = s$requests[s$first_pending_request];\n\t\tlocal host = (s$next_request$host==\"\") ? fmt(\"%s\", c$id$resp_h) : s$next_request$host;\n\t\tlocal url = fmt(\"http:\/\/%s%s\", host, r$URI);\n\t\t\n\t\tevent file_transferred(c, abstract, magic_descr, magic_mime);\n\t\t\n\t\tif ( ignored_urls in url )\n\t\t\treturn;\n\t\t\n\t\tlocal file_type = \"\";\n\t\tif ( magic_mime in watched_mime_types )\n\t\t\tfile_type = magic_mime;\n\t\telse\n\t\t\tfile_type = magic_descr;\n\t\t\n\t\tprint http_magic_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), s$id, \n\t\t c$id$orig_h, fmt(\"%d\", c$id$orig_p), \n\t\t c$id$resp_h, fmt(\"%d\", c$id$resp_p), \n\t\t file_type, r$method, url);\n\t\t\n\t\tif ( (magic_mime in mime_types_extensions && \n\t\t mime_types_extensions[magic_mime] !in url) ||\n\t\t (magic_descr in mime_types_extensions && \n\t\t mime_types_extensions[magic_descr] !in url) )\n\t\t\t{\n\t\t\tlocal message = fmt(\"%s %s %s\", file_type, r$method, url);\n\t\t\tNOTICE([$note=HTTP_IncorrectFileType, \n\t\t\t $msg=message, \n\t\t\t $conn=c, \n\t\t\t $method=r$method, \n\t\t\t $URL=url]);\n\t\t\t}\n\t\t}\n\t}\n\n\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\nmodule HTTP;\n\n\nexport {\n\tconst http_magic_log = open_log_file(\"http-identified-files\") &raw_output &redef;\n\n\t# Base the libmagic analysis on at least this many bytes.\n\tconst magic_content_limit = 1024 &redef;\n\t\n\tconst watched_mime_types: set[string] = { \n\t\t\"application\/x-dosexec\", # Windows and DOS executables\n\t\t\"application\/x-executable\", # *NIX executable binary\n\t} &redef; \n\t\n\tconst watched_descriptions =\n\t\t\/PHP script text\/ &redef;\n\t\n\t# URLs included here are not logged and notices are not thrown.\n\t# Take care when defining regexes to not be overly broad.\n\tconst ignored_urls = \/^http:\\\/\\\/www\\.download\\.windowsupdate\\.com\\\/\/ &redef;\n\t\n\tredef enum Notice += {\n\t\t# This notice is thrown when the file extension doesn't match the file contents\n\t\tHTTP_IncorrectFileType, \n\t};\n\t\n\t# Create regexes that *should* in be in the urls for specifics mime types.\n\t# Notices are thrown if the pattern doesn't match the url for the file type.\n\tconst mime_types_extensions: table[string] of pattern = {\n\t\t[\"application\/x-dosexec\"] = \/\\.([eE][xX][eE]|[dD][lL][lL])\/,\n\t} &redef;\n}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( is_orig ) # We are only watching for server responses\n\t\treturn;\n\t\n\tlocal s = lookup_http_request_stream(c);\n\tlocal msg = get_http_message(s, is_orig);\n\t\n@ifndef\t( content_truncation_limit )\n\t# This is only done if http-body.bro is not loaded.\n\tmsg$data_length = msg$data_length + length;\n@endif\n\t\n\t# For the time being, we'll just use the data from the first packet.\n\t# Don't continue until we have enough data\n\t#if ( msg$data_length < magic_content_limit )\n\t#\treturn;\n\t\n\t# Right now, only try this for the first chunk of data\n\tif ( msg$data_length > length )\n\t\treturn;\n\t\n\tlocal abstract = sub_bytes(data, 1, magic_content_limit);\n\tlocal magic_mime = identify_data(abstract, T);\n\tlocal magic_descr = identify_data(abstract, F);\n\n\tif ( (magic_mime in watched_mime_types ||\n\t watched_descriptions in magic_descr) &&\n\t s$first_pending_request in s$requests )\n\t\t{\n\t\tlocal r = s$requests[s$first_pending_request];\n\t\tlocal host = (s$next_request$host==\"\") ? fmt(\"%s\", c$id$resp_h) : s$next_request$host;\n\t\tlocal url = fmt(\"http:\/\/%s%s\", host, r$URI);\n\t\t\n\t\tevent file_transferred(c, abstract, magic_descr, magic_mime);\n\t\t\n\t\tif ( ignored_urls in url )\n\t\t\treturn;\n\t\t\n\t\tlocal file_type: string = \"\";\n\t\tif ( magic_mime in watched_mime_types )\n\t\t\tfile_type = magic_mime;\n\t\telse\n\t\t\tfile_type = magic_descr;\n\t\t\n\t\tprint http_magic_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), s$id, c$id$orig_h, fmt(\"%d\", c$id$orig_p), c$id$resp_h, fmt(\"%d\", c$id$resp_p), file_type, r$method, url);\n\t\t\n\t\tif ( (magic_mime in mime_types_extensions && mime_types_extensions[magic_mime] !in url) ||\n\t\t (magic_descr in mime_types_extensions && mime_types_extensions[magic_descr] !in url) )\n\t\t\t{\n\t\t\tlocal message = fmt(\"%s %s %s\", file_type, r$method, url);\n\t\t\tNOTICE([$note=HTTP_IncorrectFileType, \n\t\t\t $msg=message, \n\t\t\t $conn=c, \n\t\t\t $method=r$method, \n\t\t\t $URL=url]);\n\t\t\t}\n\t\t}\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"c8b69e7d4d0cbe885c7b534d23ad374bb739fed1","subject":"Create multiplequerysubscription.bro","message":"Create multiplequerysubscription.bro","repos":"sami2316\/osquery,sami2316\/osquery","old_file":"multiplequerysubscription.bro","new_file":"multiplequerysubscription.bro","new_contents":"\nmodule osquery;\n\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef osquery::endpoint_name = \"Printer\";\n\n\nglobal added_acpi_tables: event(host: string, name: string, size: count, md5: string);\nglobal removed_acpi_tables: event(host: string, name: string,size: count,md5: string);\n###################################################################################\nglobal added_arp_cache: event(host: string, address: string, mac: string, interface: string);\nglobal removed_arp_cache: event(host: string, address: string, mac: string, interface: string);\n###################################################################################\nglobal added_block_devices: event(host: string, name: string,vendor: string, model: string);\nglobal removed_block_devices: event(host: string, name: string,vendor: string, model: string);\n###################################################################################\nglobal added_chrome_extensions: event(host: string, name: string,author: string, path:string);\nglobal removed_chrome_extensions: event(host: string, name: string,author: string, path:string);\n###################################################################################\nglobal added_cpuid: event(host: string, feature: string, value: string);\nglobal removed_cpuid: event(host: string, feature: string, value: string);\n###################################################################################\nglobal added_crontab: event(host: string, hour: count, command: string, path: string);\nglobal removed_crontab: event(host: string, hour: count, command: string, path: string);\n###################################################################################\nglobal added_disk_encryption: event(host: string, name: string, uuid: string, encrypted: count);\nglobal removed_disk_encryption: event(host: string, name: string, uuid: string, encrypted: count);\n###################################################################################\nglobal added_etc_hosts: event(host: string, address: string, hostnames: string);\nglobal removed_etc_hosts: event(host: string, address: string, hostnames: string);\n###################################################################################\nglobal added_etc_protocols: event(host: string, name: string, number: count);\nglobal removed_etc_protocols: event(host: string, name: string, number: count);\n###################################################################################\nglobal added_etc_services: event(host: string, name: string, prt: count, protocol: string);\nglobal removed_etc_services: event(host: string, name: string, prt: count, protocol: string);\n###################################################################################\nglobal added_file_events: event(host: string, target_path: string, action: string, t: count);\nglobal removed_file_events: event(host: string, target_path: string, action: string, t: count);\n###################################################################################\nglobal added_firefox_addons: event(host: string, name: string, source_url: string, location: string);\nglobal removed_firefox_addons: event(host: string, name: string, source_url: string, location: string);\n###################################################################################\nglobal added_groups: event(host: string, gid: count, groupname: string);\nglobal removed_groups: event(host: string, gid: count, groupname: string);\n###################################################################################\nglobal added_hardware_events: event(host: string, action: string, model: string, vendor: string);\nglobal removed_hardware_events: event(host: string, action: string, model: string, vendor: string);\n###################################################################################\nglobal added_interface_address: event(host: string, interface: string, address: string);\nglobal removed_interface_address: event(host: string, interface: string, address: string);\n###################################################################################\nglobal added_interface_details: event(host: string, interface: string, mac: string, mtu: count);\nglobal removed_interface_details: event(host: string, interface: string, mac: string, mtu: count);\n###################################################################################\nglobal added_kernel_info: event(host: string, version: string, path: string, device: string);\nglobal removed_kernel_info: event(host: string, version: string, path: string, device: string);\n###################################################################################\nglobal added_last: event(host: string, username: string, pid: count, h: string);\nglobal removed_last: event(host: string, username: string, pid: count, h: string);\n###################################################################################\nglobal added_listening_ports: event(host: string, pid: count, prt: count, protocol: count);\nglobal removed_listening_ports: event(host: string, pid: count, prt: count, protocol: count);\n###################################################################################\nglobal added_logged_in_users: event(host: string, user: string, h: string, t: count);\nglobal removed_logged_in_users: event(host: string, user: string, h: string, t: count);\n###################################################################################\nglobal added_mounts: event(host: string, device: string, path: string);\nglobal removed_mounts: event(host: string, device: string, path: string);\n###################################################################################\nglobal added_opera_extensions: event(host: string, name: string, description: string, author: string);\nglobal removed_opera_extensions: event(host: string, name: string, description: string, author: string);\n###################################################################################\nglobal added_os_version: event(host: string, name: string, patch: count, build: string);\nglobal removed_os_version: event(host: string, name: string, patch: count, build: string);\n###################################################################################\nglobal added_passwd_changes: event(host: string, target_path: string, action: string);\nglobal removed_passwd_changes: event(host: string, target_path: string, action: string);\n###################################################################################\nglobal added_pci_devices: event(host: string, pci_slot: string, driver: string, vendor: string, model: string);\nglobal removed_pci_devices: event(host: string, pci_slot: string, driver: string, vendor: string, model: string);\n###################################################################################\nglobal added_process_envs: event(host: string, pid: count, key: string, value: string);\nglobal removed_process_envs: event(host: string, pid: count, key: string, value: string);\n###################################################################################\nglobal added_process_memory_map: event(host: string, pid: count, permissions: string, device: string);\nglobal removed_process_memory_map: event(host: string, pid: count, permissions: string, device: string);\n###################################################################################\nglobal added_process_open_files: event(host: string, pid: count, fd: string, path: string);\nglobal removed_process_open_files: event(host: string, pid: count, fd: string, path: string);\n###################################################################################\nglobal added_process_open_sockets: event(host: string, pid: count, socket: count, protocol: count);\nglobal removed_process_open_sockets: event(host: string, pid: count, socket: count, protocol: count);\n###################################################################################\nglobal added_processes: event(host: string, pid: count, name: string, path: string, cmdline: string );\nglobal removed_processes: event(host: string, pid: count, name: string, path: string, cmdline : string);\n###################################################################################\nglobal added_routes: event(host: string, destination: string, source: string, interface: string);\nglobal removed_routes: event(host: string, destination: string, source: string, interface: string);\n###################################################################################\nglobal added_shell_history: event(host: string, username: string, command: string);\nglobal removed_shell_history: event(host: string, username: string, command: string);\n###################################################################################\nglobal added_smbios_tables: event(host: string, number: count, description: string, size: count);\nglobal removed_smbios_tables: event(host: string, number: count, description: string, size: count);\n###################################################################################\nglobal added_system_controls: event(host: string, name: string, oid: string, subsystem: string);\nglobal removed_system_controls: event(host: string, name: string, oid: string, subsystem: string);\n###################################################################################\nglobal added_uptime: event(host: string, days: count, hours: count);\nglobal removed_uptime: event(host: string, days: count, hours: count);\n###################################################################################\nglobal added_usb_devices: event(host: string, usb_address: count, vendor: string, model: string);\nglobal removed_usb_devices: event(host: string, usb_address: count, vendor: string, model: string);\n###################################################################################\nglobal added_user_groups: event(host: string, uid: count, gid: count);\nglobal removed_user_groups: event(host: string, uid: count, gid: count);\n###################################################################################\nglobal added_users: event(host: string, username: string, uid: count, gid: count);\nglobal removed_users: event(host: string, username: string, uid: count, gid: count);\n###################################################################################\n\n\nglobal query: table[string] of string;\nglobal gconn: table[string] of string;\n\nevent bro_init()\n{\n\tosquery::enable();\n\tosquery::subscribe_to_events(\"\/bro\/event\/\");\n\t\n\tgconn[\"192.168.1.187\"] = \"9999\";\n\tgconn[\"192.168.1.211\"] = \"9999\";\n\tgconn[\"192.168.1.33\"] = \"9999\";\n\t\n\tosquery::groupconnect(gconn, 2sec);\n\n\tquery[\"osquery::added_acpi_tables\"] = \"SELECT name,size,md5 FROM acpi_tables\";\n\t#query[\"osquery::removed_acpi_tables\"] = \"SELECT name,size,md5 FROM acpi_tables\";\n\t#######################################################################################\n\tquery[\"osquery::added_arp_cache\"] = \"SELECT address,mac,interface FROM arp_cache\";\n\t#query[\"osquery::removed_arp_cache\"]= \"SELECT address,mac,interface FROM arp_cache\";\n\t#######################################################################################\n\t#query[\"osquery::added_block_devices\"] = \"SELECT name,vendor,model FROM block_devices\";\n\t#query[\"osquery::removed_block_devices\"] = \"SELECT name,vendor,model FROM block_devices\";\n\t#######################################################################################\n\tquery[\"osquery::added_chrome_extensions\"] = \"SELECT name,author,path FROM chrome_extensions\";\n\t#query[\"osquery::removed_chrome_extensions\"] = \"SELECT name,author,path FROM chrome_extensions\";\n\t########################################################################################\n\t#query[\"osquery::added_cpuid\"] = \"SELECT feature,value FROM cpuid\";\n\t#query[\"osquery::removed_cpuid\"] = \"SELECT feature,value FROM cpuid\";\n\t#######################################################################################\n\t#query[\"osquery::added_crontab\"] = \"SELECT event,hour,command FROM crontab\";\n\t#query[\"osquery::removed_crontab\"] = \"SELECT event,hour,command FROM crontab\";\n\t#######################################################################################\n\t#query[\"osquery::added_disk_encryption\"] = \"SELECT name,uuid,encrypted FROM disk_encryption\";\n\t#query[\"osquery::removed_disk_encryption\"] = \"SELECT name,uuid,encrypted FROM disk_encryption\";\n\t########################################################################################\n\t#query[\"osquery::added_etc_hosts\"] = \"SELECT address,hostnames FROM etc_hosts\";\n\t#query[\"osquery::removed_etc_hosts\"] = \"SELECT address,hostnames FROM etc_hosts\";\n\t########################################################################################\n\t#query[\"osquery::added_etc_protocols\"] = \"SELECT name,number FROM etc_protocols\";\n\t#query[\"osquery::removed_etc_protocols\"] = \"SELECT name,number FROM etc_protocols\";\n\t#######################################################################################\n\t#query[\"osquery::added_etc_services\"] = \"SELECT name,port,protocol FROM etc_services\";\n\t#query[\"osquery::removed_etc_services\"] = \"SELECT name,port,protocol FROM etc_services\";\n\t#######################################################################################\n\t#query[\"osquery::added_file_events\"] = \"SELECT target_path,action,time FROM file_events\";\n\t#query[\"osquery::removed_file_events\"] = \"SELECT target_path,action,time FROM file_events\";\n\t#######################################################################################\n\t#query[\"osquery::added_firefox_addons\"] = \"SELECT name,source_url,location FROM firefox_addons\";\n\t#query[\"osquery::removed_firefox_addons\"] = \"SELECT name,source_url,location FROM firefox_addons\";\n\t#######################################################################################\n\t#query[\"osquery::added_groups\"] = \"SELECT gid,groupname FROM groups\";\n\t#query[\"osquery::removed_groups\"] = \"SELECT gid,groupname FROM groups\";\n\t#######################################################################################\n\t#query[\"osquery::added_hardware_events\"] = \"SELECT action,model,vendor FROM hardware_events\";\n\t#query[\"osquery::removed_hardware_events\"] = \"SELECT action,model,vendor FROM hardware_events\";\n\t#######################################################################################\n\t#query[\"osquery::added_interface_address\"] = \"SELECT interface,address FROM interface_address\";\n\t#query[\"osquery::removed_interface_address\"] = \"SELECT interface,address FROM interface_address\";\n\t#######################################################################################\n\t#query[\"osquery::added_interface_details\"] = \"SELECT interface,mac,mtu FROM interface_details\";\n\t#query[\"osquery::removed_interface_details\"] = \"SELECT interface,mac,mtu FROM interface_details\";\n\t#######################################################################################\n\t#query[\"osquery::added_kernel_info\"] = \"SELECT version,path,device FROM kernel_info\";\n\t#query[\"osquery::removed_kernel_info\"] = \"SELECT version,path,device FROM kernel_info\";\n\t#######################################################################################\n\t#query[\"osquery::added_last\"] = \"SELECT username,pid,host FROM last\";\n\t#query[\"osquery::removed_last\"] = \"SELECT username,pid,host FROM last\";\n\t#######################################################################################\n\t#query[\"osquery::added_listening_ports\"] = \"SELECT pid,port,protocol FROM listening_ports\";\n\t#query[\"osquery::removed_listening_ports\"] = \"SELECT pid,port,protocol FROM listening_ports\";\n\t#######################################################################################\n\t#query[\"osquery::added_logged_in_users\"] = \"SELECT user,host,time FROM logged_in_users\";\n\t#query[\"osquery::removed_logged_in_users\"] = \"SELECT user,host,time FROM logged_in_users\";\n\t########################################################################################\n\t#query[\"osquery::added_mounts\"] = \"SELECT device,path FROM mounts\";\n\t#query[\"osquery::removed_mounts\"] = \"SELECT device,path FROM mounts\";\n\t########################################################################################\n\t#query[\"osquery::added_opera_extensions\"] = \"SELECT name,description,author FROM opera_extensions\";\n\t#query[\"osquery::removed_opera_extensions\"] = \"SELECT name,description,author FROM opera_extensions\";\n\t#######################################################################################\n\t#query[\"osquery::added_os_version\"] = \"SELECT name,patch,build FROM os_version\";\n\t#query[\"osquery::removed_os_version\"] = \"SELECT name,patch,build FROM os_version\";\n\t#######################################################################################\n\t#query[\"osquery::added_passwd_changes\"] = \"SELECT target_path,action FROM passwd_changes\";\n\t#query[\"osquery::removed_passwd_changes\"] = \"SELECT target_path,action FROM passwd_changes\";\n\t#######################################################################################\n\t#query[\"osquery::added_pci_devices\"] = \"SELECT pci_slot,driver,vendor,model FROM pci_devices\";\n\t#query[\"osquery::removed_pci_devices\"] = \"SELECT pci_slot,driver,vendor,model FROM pci_devices\";\n\t#######################################################################################\n\t#query[\"osquery::added_process_envs\"] = \"SELECT pid,key,value FROM process_envs\";\n\t#query[\"osquery::removed_process_envs\"] = \"SELECT pid,key,value FROM process_envs\";\n\t#######################################################################################\n\t#query[\"osquery::added_process_memory_map\"] = \"SELECT pid,permissions,device FROM process_memory_map\";\n\t#query[\"osquery::removed_process_memory_map\"] = \"SELECT pid,permissions,device FROM process_memory_map\";\n\t#######################################################################################\n\t#query[\"osquery::added_process_open_files\"] = \"SELECT pid,fd,path FROM process_open_files\";\n\t#query[\"osquery::removed_process_open_files\"] = \"SELECT pid,fd,path FROM process_open_files\";\n\t#######################################################################################\n\t#query[\"osquery::added_process_open_sockets\"] = \"SELECT pid,socket,protocol FROM process_open_sockets\";\n\t#query[\"osquery::removed_process_open_sockets\"] = \"SELECT pid,socket,protocol FROM process_open_sockets\";\n\t#######################################################################################\n\t#query[\"osquery::added_processes\"] = \"SELECT pid,name,path,cmdline FROM processes\";\n\t#query[\"osquery::removed_processes\"] = \"SELECT pid,name,path,cmdline FROM processes\";\n\t#######################################################################################\n\t#query[\"osquery::added_routes\"] = \"SELECT destination,source,interface FROM routes\";\n\t#query[\"osquery::removed_routes\"] = \"SELECT destination,source,interface FROM routes\";\n\t#######################################################################################\n\t#query[\"osquery::added_shell_history\"] = \"SELECT username,command FROM shell_history\";\n\t#query[\"osquery::removed_shell_history\"] = \"SELECT username,command FROM shell_history\";\n\t#######################################################################################\n\t#query[\"osquery::added_smbios_tables\"] = \"SELECT number,description,size FROM smbios_tables\";\n\t#query[\"osquery::removed_smbios_tables\"] = \"SELECT number,description,size FROM smbios_tables\";\n\t#######################################################################################\n\t#query[\"osquery::added_system_controls\"] = \"SELECT name,oid,subsystem FROM system_controls\";\n\t#query[\"osquery::removed_system_controls\"] = \"SELECT name,oid,subsystem FROM system_controls\";\n\t#######################################################################################\n\t#query[\"osquery::added_uptime\"] = \"SELECT days,hours FROM uptime\";\n\t#query[\"osquery::removed_uptime\"] = \"SELECT days,hours FROM uptime\";\n\t#######################################################################################\n\t#query[\"osquery::added_usb_devices\"] = \"SELECT usb_address,vendor,model FROM usb_devices\";\n\t#query[\"osquery::removed_usb_devices\"] = \"SELECT usb_address,vendor,model FROM usb_devices\";\n\t########################################################################################\n\t#query[\"osquery::added_user_groups\"] = \"SELECT uid,gid FROM user_groups\";\n\t#query[\"osquery::removed_user_groups\"] = \"SELECT uid,gid FROM user_groups\";\n\t########################################################################################\n\t#query[\"osquery::added_users\"] = \"SELECT username,uid,gid FROM users\";\n\t#query[\"osquery::removed_users\"] = \"SELECT username,uid,gid FROM users\";\n\t#######################################################################################\n}\n\nevent BrokerComm::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string)\n{\n\tprint \"BrokerComm::outgoing_connection_establisted\", peer_address, peer_port, peer_name;\n\t\n\tosquery::groupsubscribe(\"\/bro\/event\/host2\",query);\n\t\n}\n\n\n########################### ACPI TABLES ################################################\n\nevent added_acpi_tables(host: string, name: string, size: count, md5: string)\n{\n\tprint \"New acpi_table Entry\";\n\tprint fmt(\"Host = %s Table_name = %s size = %d md5 = %s\",host, name, size, md5);\n}\nevent removed_acpi_tables(host: string, name: string,size: count,md5: string)\n{\n\tprint \"Deleted acpi_table Entry\";\n\tprint fmt(\"Host = %s Table_name = %s size = %d md5 = %s\",host, name, size, md5);\n}\n############################## ARP CACHE ##############################################\nevent added_arp_cache(host: string, address: string, mac: string, interface: string)\n{\n\tprint \"New arp_table Entry\";\n\tprint fmt(\"Host = %s Address = %s mac = %s Interface = %s\",host, address, mac, interface);\n}\nevent removed_arp_cache(host: string, address: string, mac: string, interface: string)\n{\n\tprint \"Deleted arp_table Entry\";\n\tprint fmt(\"Host = %s Address = %s mac = %s Interface = %s\",host, address, mac, interface);\n}\n############################## BLOCK DEVICES ###########################################\nevent added_block_devices(host: string, name: string,vendor: string, model: string)\n{\n\tprint \"New block_device Entry\";\n\tprint fmt(\"Host = %s Name = %s Vendor = %s Model = %s\",host, name, vendor, model);\n}\nevent removed_block_devices(host: string, name: string,vendor: string, model: string)\n{\n\tprint \"Deleted block_device Entry\";\n\tprint fmt(\"Host = %s Name = %s Vendor = %s Model = %s\",host, name, vendor, model);\n}\n############################## CHROME EXTENSIONS ##########################################\nevent added_chrome_extensions(host: string, name: string,author: string, path:string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s Author = %s Path = %s\",host, name, author, path);\n}\nevent removed_chrome_extensions(host: string, name: string,author: string, path:string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s Author = %s Path = %s\",host, name, author, path);\n}\n############################# CPUID #####################################################\nevent added_cpuid(host: string, feature: string, value: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Feature = %s Value = %s\",host, feature,value);\n}\nevent removed_cpuid(host: string, feature: string, value: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Feature = %s Value = %s\",host, feature,value);\n}\n############################ CRONTAB ####################################################\nevent added_crontab(host: string, hour: count, command: string, path: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Hour = %d Command = %s Path=%s\",host, hour, command, path);\n}\nevent removed_crontab(host: string, hour: count, command: string,path: string)\n{\n\tprint fmt(\"Host = %s Hour = %d Command = %s Path=%s\",host, hour, command, path);\n}\n########################### DISK ENCRYPTION ###############################################\nevent added_disk_encryption(host: string, name: string, uuid: string, encrypted: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s uuid = %s encrypted=%d\",host, name, uuid, encrypted);\n}\nevent removed_disk_encryption(host: string, name: string, uuid: string, encrypted: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s uuid = %s encrypted=%d\",host, name, uuid, encrypted);\n}\n########################### ETC HOSTS ########################################################\nevent added_etc_hosts(host: string, address: string, hostnames: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Address = %s hostnames = %s \",host, address, hostnames);\n}\nevent removed_etc_hosts(host: string, address: string, hostnames: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Address = %s hostnames = %s \",host, address, hostnames);\n}\n########################### ETC PROTOCOLS #################################################\nevent added_etc_protocols(host: string, name: string, number: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s number = %d \",host, name, number);\n}\nevent removed_etc_protocols(host: string, name: string, number: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s number = %d \",host, name, number);\n}\n########################### ETC SERVICES ##################################################\nevent added_etc_services(host: string, name: string, prt: count, protocol: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s prt = %d Protocol = %s \",host, name, prt, protocol);\n}\nevent removed_etc_services(host: string, name: string, prt: count, protocol: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s prt = %d Protocol = %s \",host, name, prt, protocol);\n}\n########################### FILE EVENTS ####################################################\nevent added_file_events(host: string, target_path: string, action: string, t: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s target_path = %s Action = %s Time = %d\",host, target_path,action,t);\n}\nevent removed_file_events(host: string, target_path: string, action: string, t: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s target_path = %s Action = %s Time = %d\",host, target_path,action,t);\n}\n############################ FIREFOX ADDONS #################################################\nevent added_firefox_addons(host: string, name: string, source_url: string, location: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s source_url = %s Locatoin= %s \",host, name, source_url, location);\n}\nevent removed_firefox_addons(host: string, name: string, source_url: string, location: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s source_url = %s Locatoin= %s \",host, name, source_url, location);\n}\n############################ ADDED GROUPS ###################################################\nevent added_groups(host: string, gid: count, groupname: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s gid = %d groupnumber = %s \",host, gid, groupname);\n}\nevent removed_groups(host: string, gid: count, groupname: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s gid = %d groupnumber = %s \",host, gid, groupname);\n}\n############################ HARDWARE EVENTS ##################################################\nevent added_hardware_events(host: string, action: string, model: string, vendor: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s action = %s model = %s Vendor =%s\",host, action, model,vendor);\n}\nevent removed_hardware_events(host: string, action: string, model: string, vendor: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s action = %s model = %s Vendor =%s\",host, action, model,vendor);\n}\n########################### INTERFACE ADDRESS ##################################################\nevent added_interface_address(host: string, interface: string, address: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Interface = %s Address = %s \",host, interface,address);\n}\nevent removed_interface_address(host: string, interface: string, address: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Interface = %s Address = %s \",host, interface,address);\n}\n############################ INTERFACE DETAILS ##################################################\nevent added_interface_details(host: string, interface: string, mac: string, mtu: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s interface= %s mac = %s Mtu =%d \",host, interface,mac,mtu);\n}\nevent removed_interface_details(host: string, interface: string, mac: string, mtu: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s interface= %s mac = %s Mtu =%d \",host, interface,mac,mtu);\n}\n############################ KERNEL INFO ####################################################\nevent added_kernel_info(host: string, version: string, path: string, device: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s version = %s path = %s Device =%s\",host, version,path,device);\n}\nevent removed_kernel_info(host: string, version: string, path: string, device: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s version = %s path = %s Device =%s\",host, version,path,device);\n}\n############################# LAST ##########################################################\nevent added_last(host: string, username: string, pid: count, h: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s username = %s pid = %d Host=%s\",host, username, pid,h);\n}\nevent removed_last(host: string, username: string, pid: count, h: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s username = %s pid = %d Host=%s\",host, username, pid,h);\n}\n############################# LISTENING PORTS ################################################\nevent added_listening_ports(host: string, pid: count, prt: count, protocol: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s pid = %d prt = %d Protocol =%d \",host, pid,prt,protocol);\n}\nevent removed_listening_ports(host: string, pid: count, prt: count, protocol: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s pid = %d prt = %d Protocol =%d \",host, pid,prt,protocol);\n}\n############################# LOGGED IN USERS #################################################\nevent added_logged_in_users(host: string, user: string, h: string, t: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s User = %s Host = %s Time =%d \",host, user,h,t);\n}\nevent removed_logged_in_users(host: string, user: string, h: string, t: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s User = %s Host = %s Time =%d \",host, user,h,t);\n}\n############################ MOUNTS ##########################################################\nevent added_mounts(host: string, device: string, path: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Device = %s Path = %s \",host, device,path);\n}\nevent removed_mounts(host: string, device: string, path: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Device = %s Path = %s \",host, device,path);\n}\n############################ OPERA EXTENSIONS #################################################\nevent added_opera_extensions(host: string, name: string, description: string, author: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s description = %s Author=%s \",host, name,description,author);\n}\nevent removed_opera_extensions(host: string, name: string, description: string, author: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s description = %s Author=%s \",host, name,description,author);\n}\n############################ OS VERSION ######################################################\nevent added_os_version(host: string, name: string, patch: count, build: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s Patch = %d Build = %s \",host, name, patch,build);\n}\nevent removed_os_version(host: string, name: string, patch: count, build: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s Patch = %d Build = %s \",host, name, patch,build);\n}\n############################ PASSWORD CHANGES ##################################################\nevent added_passwd_changes(host: string, target_path: string, action: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Target_Path = %s Action = %s \",host, target_path,action);\n}\nevent removed_passwd_changes(host: string, target_path: string, action: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Target_Path = %s Action = %s \",host, target_path,action);\n}\n############################ PCI DEVICES #####################################################\nevent added_pci_devices(host: string, pci_slot: string, driver: string, vendor: string, model: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PCI_Slot = %s Driver = %s Vendor =%s Model= %s\",host, pci_slot,driver,vendor,model);\n}\nevent removed_pci_devices(host: string, pci_slot: string, driver: string, vendor: string, model: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PCI_Slot = %s Driver = %s Vendor =%s Model= %s\",host, pci_slot,driver,vendor,model);\n}\n########################### PROCESS EVENTS #####################################################\nevent added_process_envs(host: string, pid: count, key: string, value: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d Key = %s Value = %s \",host, pid,key,value);\n}\nevent removed_process_envs(host: string, pid: count, key: string, value: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d Key = %s Value = %s \",host, pid,key,value);\n}\n########################### PROCESS MOMORY ######################################################\nevent added_process_memory_map(host: string, pid: count, permissions: string, device: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d Permissions = %s Device = %s \",host, pid,permissions,device);\n}\nevent removed_process_memory_map(host: string, pid: count, permissions: string, device: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d Permissions = %s Device = %s \",host, pid,permissions,device);\n}\n########################## PROCESS OPEN FILES ###################################################\nevent added_process_open_files(host: string, pid: count, fd: string, path: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d FD = %s Path = %s\",host, pid,fd,path);\n}\nevent removed_process_open_files(host: string, pid: count, fd: string, path: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d FD = %s Path = %s\",host, pid,fd,path);\n}\n########################## PROCESS OPEN SOCKETS ####################################################\nevent added_process_open_sockets(host: string, pid: count, socket: count, protocol: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d Socket = %d Protocol =%d\",host, pid,socket,protocol);\n}\nevent removed_process_open_sockets(host: string, pid: count, socket: count, protocol: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d Socket = %d Protocol =%d\",host, pid,socket,protocol);\n}\n########################## PROCESSES #########################################################\nevent added_processes(host: string, pid: count, name: string, path: string, cmdline: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s PID = %d Name = %s Path = %s cmdline = %s\",host, pid,name,path,cmdline);\n}\nevent removed_processes(host: string, pid: count, name: string, path: string, cmdline: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s PID = %d Name = %s Path = %s cmdline = %s\",host, pid,name,path,cmdline);\n}\n########################### ROUTES ########################################################\nevent added_routes(host: string, destination: string, source: string, interface: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Destination = %s Source = %s Interface = %s \",host, destination,source,interface);\n}\nevent removed_routes(host: string, destination: string, source: string, interface: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Destination = %s Source = %s Interface = %s \",host, destination,source,interface);\n}\n########################### SHELL HISTORY ####################################################\nevent added_shell_history(host: string, username: string, command: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s UserNmae = %s Command = %s \",host, username, command);\n}\nevent removed_shell_history(host: string, username: string, command: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s UserNmae = %s Command = %s \",host, username, command);\n}\n############################ SMBIOS TABLES ###################################################\nevent added_smbios_tables(host: string, number: count, description: string, size: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Number = %d Description = %s Size=%d \",host, number, description,size);\n}\nevent removed_smbios_tables(host: string, number: count, description: string, size: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Number = %d Description = %s Size=%d \",host, number, description,size);\n}\n############################# SYSTEM CONTROLS ###################################################\nevent added_system_controls(host: string, name: string, oid: string, subsystem: string)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Name = %s OID = %s Subsystem =%s \",host, name, oid, subsystem);\n}\nevent removed_system_controls(host: string, name: string, oid: string, subsystem: string)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Name = %s OID = %s Subsystem =%s \",host, name, oid, subsystem);\n}\n############################## UPTIME ###################################################\nevent added_uptime(host: string, days: count, hours: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s Days = %d Hours = %d \",host, days,hours);\n}\nevent removed_uptime(host: string, days: count, hours: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s Days = %d Hours = %d \",host, days,hours);\n}\n############################# USB DEVICES ###################################################\nevent added_usb_devices(host: string, usb_address: count, vendor: string, model: string)\n{\n\tprint \"New Usb Device Added\";\n \tprint fmt(\"Host = %s Usb_address = %d Vendor = %s Model = %s\",host, usb_address, vendor, model);\n}\nevent removed_usb_devices(host: string, usb_address: count, vendor: string, model: string)\n{\n\tprint \"Usb Device Removed\";\n \tprint fmt(\"Host = %s Usb_address = %d Vendor = %s Model = %s\",host, usb_address, vendor, model);\n}\n############################# USER GROUPS ###################################################\nevent added_user_groups(host: string, uid: count, gid: count)\n{\n\tprint fmt(\"New entry added\");\n\tprint fmt(\"Host = %s UID = %d GID = %d \",host, uid, gid);\n}\nevent removed_user_groups(host: string, uid: count, gid: count)\n{\n\tprint fmt(\"Entry Removed\");\n\tprint fmt(\"Host = %s UID = %d GID = %d \",host, uid, gid);\n}\n############################# USERS ######################################################\nevent added_users(host: string, username: string, uid: count, gid: count)\n{\n\tprint \"New User Added\";\n \tprint fmt(\"Host = %s UserName = %s UID = %d GID = %d\",host, username, uid, gid);\n}\nevent removed_users(host: string, username: string, uid: count, gid: count)\n{\n\tprint \"User Removed\";\n \tprint fmt(\"Host = %s UserName = %s UID = %d GID = %d\",host, username, uid, gid);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'multiplequerysubscription.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"48750aa9b67b91bbd24820cb2532c7f2913a8420","subject":"add cx.cc to regex","message":"add cx.cc to regex\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-block-exe-hosts.bro","new_file":"http-ext-block-exe-hosts.bro","new_contents":"@load http-ext\n@load ipblocker\n\nmodule HTTP;\n\nexport {\n redef enum Notice += {\n HTTP_IncorrectFileTypeBadHost\n };\n\n const bad_exec_domains = \n \/co\\.cc\/\n | \/cx\\.cc\/\n | \/cz\\.cc\/\n &redef;\n\n const bad_exec_urls = \n \/php.adv=\/\n | \/http:\\\/\\\/[0-9]{1,3}\\.[0-9]{1,3}.*\\\/index\\.php\\?[^=]+=[^=]+$\/ #try to match http:\/\/1.2.3.4\/index.php?foo=bar\n &redef;\n\n const bad_user_agents = \n \/Java\\\/1\/\n &redef;\n\n}\n\nredef notice_action_filters += {\n [HTTP_IncorrectFileTypeBadHost] = notice_exec_ipblocker_dest,\n};\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h))\n return;\n if(! (\"identified-files\" in si$tags && si$mime_type == \"application\/x-dosexec\"))\n return;\n\n if( (bad_exec_domains in si$host || bad_exec_urls in si$url)\n ||(\/\\.exe\/ !in si$url && bad_user_agents in si$user_agent)) {\n NOTICE([$note=HTTP_IncorrectFileTypeBadHost,\n $id=id,\n $msg=fmt(\"EXE Downloaded from bad host %s %s %s\", id$orig_h, id$resp_h, si$url),\n $sub=\"http-ext\"\n ]);\n }\n}\n","old_contents":"@load http-ext\n@load ipblocker\n\nmodule HTTP;\n\nexport {\n redef enum Notice += {\n HTTP_IncorrectFileTypeBadHost\n };\n\n const bad_exec_domains = \n \/co\\.cc\/\n | \/cz\\.cc\/\n &redef;\n\n const bad_exec_urls = \n \/php.adv=\/\n | \/http:\\\/\\\/[0-9]{1,3}\\.[0-9]{1,3}.*\\\/index\\.php\\?[^=]+=[^=]+$\/ #try to match http:\/\/1.2.3.4\/index.php?foo=bar\n &redef;\n\n const bad_user_agents = \n \/Java\\\/1\/\n &redef;\n\n}\n\nredef notice_action_filters += {\n [HTTP_IncorrectFileTypeBadHost] = notice_exec_ipblocker_dest,\n};\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h))\n return;\n if(! (\"identified-files\" in si$tags && si$mime_type == \"application\/x-dosexec\"))\n return;\n\n if( (bad_exec_domains in si$host || bad_exec_urls in si$url)\n ||(\/\\.exe\/ !in si$url && bad_user_agents in si$user_agent)) {\n NOTICE([$note=HTTP_IncorrectFileTypeBadHost,\n $id=id,\n $msg=fmt(\"EXE Downloaded from bad host %s %s %s\", id$orig_h, id$resp_h, si$url),\n $sub=\"http-ext\"\n ]);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"70bbdb17c66e4b1d750397f905c9687f7f0aeb60","subject":"don't keep track of connections at all","message":"don't keep track of connections at all\n\ndon't even bother keeping track of connections, just count status codes\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes)\n ++foo$rejects;\n\n ++foo$total;\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id] &create_expire=1m;\n local blarg: set[conn_id] &create_expire=1m;\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"0a25c1e24c9b5e6ff7e86c26770d83597ddfed3e","subject":"add back in hack to ignore external hosts","message":"add back in hack to ignore external hosts\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"@load global-ext\n@load smtp\n\ntype smtp_ext_session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tfirst_received: string &default=\"\";\n\tsecond_received: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: set[string];\n\tpath: string &default=\"\";\n\tis_webmail: bool &default=F; # This is not being set yet.\n\tagent: string &default=\"\";\n\t\n\t# These are used during processing and are likely less useful.\n\tcurrent_header: string &default=\"\";\n\tin_received_from_headers: bool &default=F;\n\treceived_finished: bool &default=F;\n};\n\nfunction default_smtp_ext_session_info(): smtp_ext_session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\tlocal tmp3: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2, $files=tmp3];\n\t}\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, si: smtp_ext_session_info);\n\nmodule SMTP;\n\nexport {\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Direction to capture the full \"Received from\" path.\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/b\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/\n\t | \/uceprotect\\.net\\\/\/\n\t | \/hostkarma\\.junkemailfilter\\.com\\\/\/ &redef;\n\t\n\tglobal conn_info: table[conn_id] of smtp_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\t\n}\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\telse if ( |ips| > 0 )\n\t\treturn ips[1];\n\telse\n\t\treturn \"\";\n}\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\t# Throw the event for other scripts to handle\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg && is_local_addr(c$id$orig_h))\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_smtp_ext_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_smtp_ext_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\t\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tadd conn_info[id]$files[data];\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$current_header == \"received\" )\n\t\t\tconn_log$first_received += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\telse if ( conn_log$current_header == \"agent\" )\n\t\t\tconn_log$agent += data;\t\t\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\n\telse if ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$second_received = conn_log$first_received;\n\t\tconn_log$first_received = split1(data, \/:[[:blank:]]*\/)[2];\n\t\t# Fill in the second value in case there is only one hop in the message.\n\t\tif ( conn_log$second_received == \"\" )\n\t\t\tconn_log$second_received = conn_log$first_received;\n\t\t\n\t\tconn_log$current_header = \"received\";\n\t\t}\n\t\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tlocal addresses = find_ip_addresses(data);\n\t\tif ( |addresses| > 0 )\n\t\t\tconn_log$x_originating_ip = addresses[1];\n\t\telse\n\t\t\tconn_log$x_originating_ip = data;\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\telse if ( \/^[xX]-[mM][aA][iI][lL][eE][rR]:[[:blank:]]*.\/ | \n\t \/^[uU][sS][eE][rR]-[aA][gG][eE][nN][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$agent = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"agent\";\n\t\t}\n\t\n\t}\n\t\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header )\n\t\treturn;\n\n\tlocal conn_log = conn_info[id];\n\t\n\t# If we've decided that we're done watching the received headers, we're done.\n\tif ( conn_log$received_finished )\n\t\treturn;\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tconn_log$in_received_from_headers = T;\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tconn_log$in_received_from_headers = F;\n\n\tif ( conn_log$in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\n\t\tlocal ip = to_addr(text_ip);\n\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tconn_log$received_finished=T;\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && !conn_log$received_finished ) \n\t\tconn_log$received_finished=T;\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"@load global-ext\n@load smtp\n\ntype smtp_ext_session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tfirst_received: string &default=\"\";\n\tsecond_received: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: set[string];\n\tpath: string &default=\"\";\n\tis_webmail: bool &default=F; # This is not being set yet.\n\tagent: string &default=\"\";\n\t\n\t# These are used during processing and are likely less useful.\n\tcurrent_header: string &default=\"\";\n\tin_received_from_headers: bool &default=F;\n\treceived_finished: bool &default=F;\n};\n\nfunction default_smtp_ext_session_info(): smtp_ext_session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\tlocal tmp3: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2, $files=tmp3];\n\t}\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, si: smtp_ext_session_info);\n\nmodule SMTP;\n\nexport {\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Direction to capture the full \"Received from\" path.\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/b\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/\n\t | \/uceprotect\\.net\\\/\/\n\t | \/hostkarma\\.junkemailfilter\\.com\\\/\/ &redef;\n\t\n\tglobal conn_info: table[conn_id] of smtp_ext_session_info \n\t\t&read_expire=5mins\n\t\t&redef;\n\t\n}\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\telse if ( |ips| > 0 )\n\t\treturn ips[1];\n\telse\n\t\treturn \"\";\n}\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\t# Throw the event for other scripts to handle\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_smtp_ext_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_smtp_ext_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\t\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tadd conn_info[id]$files[data];\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$current_header == \"received\" )\n\t\t\tconn_log$first_received += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\telse if ( conn_log$current_header == \"agent\" )\n\t\t\tconn_log$agent += data;\t\t\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\n\telse if ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$second_received = conn_log$first_received;\n\t\tconn_log$first_received = split1(data, \/:[[:blank:]]*\/)[2];\n\t\t# Fill in the second value in case there is only one hop in the message.\n\t\tif ( conn_log$second_received == \"\" )\n\t\t\tconn_log$second_received = conn_log$first_received;\n\t\t\n\t\tconn_log$current_header = \"received\";\n\t\t}\n\t\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tlocal addresses = find_ip_addresses(data);\n\t\tif ( |addresses| > 0 )\n\t\t\tconn_log$x_originating_ip = addresses[1];\n\t\telse\n\t\t\tconn_log$x_originating_ip = data;\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\telse if ( \/^[xX]-[mM][aA][iI][lL][eE][rR]:[[:blank:]]*.\/ | \n\t \/^[uU][sS][eE][rR]-[aA][gG][eE][nN][tT]:[[:blank:]]*.\/ in data )\n\t\t{\n\t\tconn_log$agent = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"agent\";\n\t\t}\n\t\n\t}\n\t\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header )\n\t\treturn;\n\n\tlocal conn_log = conn_info[id];\n\t\n\t# If we've decided that we're done watching the received headers, we're done.\n\tif ( conn_log$received_finished )\n\t\treturn;\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tconn_log$in_received_from_headers = T;\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tconn_log$in_received_from_headers = F;\n\n\tif ( conn_log$in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\n\t\tlocal ip = to_addr(text_ip);\n\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tconn_log$received_finished=T;\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && !conn_log$received_finished ) \n\t\tconn_log$received_finished=T;\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"b2a547c6fb8a4f4351917512ebdb6e6170bc7a17","subject":"Add archive formats from upstream.","message":"Add archive formats from upstream.\n","repos":"mocyber\/rock-scripts","old_file":"frameworks\/files\/extraction\/plugins\/extract-archive.bro","new_file":"frameworks\/files\/extraction\/plugins\/extract-archive.bro","new_contents":"@load ..\/__load__.bro\n\nmodule FileExtraction;\n\nconst archive_types: set[string] = { \"application\/x-rar-compressed\",\n\t\t\t\t\t\t\t\t\t\"application\/x-bzip2\",\n\t\t\t\t\t\t\t\t\t\"application\/gzip\",\n\t\t\t\t\t\t\t\t\t\"application\/x-lzma\",\n\t\t\t\t\t\t\t\t\t\"application\/x-lzip\",\n\t\t\t\t\t\t\t\t\t\"application\/x-xz\",\n\t\t\t\t\t\t\t\t\t\"application\/x-lzop\",\n\t\t\t\t\t\t\t\t\t\"application\/x-compress\",\n\t\t\t\t\t\t\t\t\t\"application\/x-7z-compressed\",\n\t\t\t\t\t\t\t\t\t\"application\/x-ace-compressed\",\n\t\t\t\t\t\t\t\t\t\"application\/vnd.ms-cab-compressed\",\n\t\t\t\t\t\t\t\t\t\"application\/x-gtar\",\n\t\t\t\t\t\t\t\t\t\"application\/zip\",\n\t\t\t\t\t\t\t\t };\n\nhook FileExtraction::extract(f: fa_file, meta: fa_metadata) &priority=5\n\t{\n\tif ( meta$mime_type in archive_types )\n\t\tbreak;\n\t}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'frameworks\/files\/extraction\/plugins\/extract-archive.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"9093fb024cbbc5dee34e4c450a04558404222535","subject":"Removes kafka from main config","message":"Removes kafka from main config\n\nMoving this to plugins\/kafka.bro and updating with latest config.","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n# Add worker information to conn log\n@load .\/misc\/conn-add-worker\n\n","old_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Configure Kafka output\n# Bro Kafka Output (plugin must be loaded!)\n@load Kafka\/KafkaWriter\/logs-to-kafka\nredef KafkaLogger::topic_name = \"bro_raw\";\nredef KafkaLogger::sensor_name = ROCK::sensor_id;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n# Add worker information to conn log\n@load .\/misc\/conn-add-worker\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"4d20b272d4dd5fd8e9d1e9a033227f63322fe90a","subject":"Fix a tiny mistake that lead to a script error.","message":"Fix a tiny mistake that lead to a script error.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){2,3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\t## Configure this to `F` if you'd like to stop enforcing that\n\t## credit cards use an internal digit separator.\n\tconst use_cc_separators = T &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = F;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal found_cnt = 0;\n\n\tlocal ccps = find_all(data, cc_regex);\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\n\t\tif ( (!use_cc_separators || cc_separators in ccp) && luhn_check(ccp) )\n\t\t\t{\n\t\t\t++found_cnt;\n\n\t\t\t# we've got a match\n\t\t\tlocal cc_parts = split_string_all(data, cc_regex);\n\t\t\t# take a copy to avoid modifying the vector while iterating.\n\t\t\tfor ( i in copy(cc_parts) )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 1 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = cc_parts[i];\n\t\t\t\t\tcc_parts[i] = gsub(cc_parts[i], \/[0-9]\/, \"X\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tlocal redacted_data = join_string_vec(cc_parts, \"\");\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tlocal cc_location = strstr(data, ccp);\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? gsub(ccp, \/[0-9]\/, \"X\") : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\t}\n\t\t\n\t\t}\n\tif ( found_cnt > 0 )\n\t\t{\n\t\tNOTICE([$note=CreditCardExposure::Found,\n\t\t $conn=c,\n\t\t $msg=fmt(\"Found at least %d credit card number%s\", found_cnt, found_cnt > 1 ? \"s\" : \"\"),\n\t\t $sub=trimmed_redacted_data,\n\t\t $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n\t\treturn T;\n\t\t}\n\telse\n\t\t{\n\t\treturn F;\n\t\t}\n\t}\n\n# This is used if the signature based technique is in use\n#function validate_credit_card_match(state: signature_state, data: string): bool\n#\t{\n#\t# TODO: Don't handle HTTP data this way.\n#\tif ( \/^GET\/ in data )\n#\t\treturn F;\n#\n#\treturn check_cards(state$conn, data);\n#\t}\n\nevent CreditCardExposure::stream_data(f: fa_file, data: string)\n\t{\n\tlocal c: connection;\n\tfor ( id in f$conns )\n\t\t{\n\t\tc = f$conns[id];\n\t\tbreak;\n\t\t}\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent file_new(f: fa_file)\n\t{\n\tif ( f$source == \"HTTP\" || f$source == \"SMTP\" )\n\t\t{\n\t\tFiles::add_analyzer(f, Files::ANALYZER_DATA_EVENT, \n\t\t [$stream_event=CreditCardExposure::stream_data]);\n\t\t}\n\t}\n","old_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){2,3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\t## Configure this to `F` if you'd like to stop enforcing that\n\t## credit cards use an internal digit separator.\n\tconst use_cc_separators = T &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = F;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal found_cnt = 0;\n\n\tlocal ccps = find_all(data, cc_regex);\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\n\t\tif ( (!use_cc_separators || cc_separators in ccp) && luhn_check(ccp) )\n\t\t\t{\n\t\t\t++found_cnt;\n\n\t\t\t# we've got a match\n\t\t\tlocal cc_parts = split_string_all(data, cc_regex);\n\t\t\t# take a copy to avoid modifying the vector while iterating.\n\t\t\tfor ( i in copy(ccp_parts) )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 1 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = cc_parts[i];\n\t\t\t\t\tcc_parts[i] = gsub(cc_parts[i], \/[0-9]\/, \"X\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tlocal redacted_data = join_string_vec(cc_parts, \"\");\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tlocal cc_location = strstr(data, ccp);\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? gsub(ccp, \/[0-9]\/, \"X\") : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\t}\n\t\t\n\t\t}\n\tif ( found_cnt > 0 )\n\t\t{\n\t\tNOTICE([$note=CreditCardExposure::Found,\n\t\t $conn=c,\n\t\t $msg=fmt(\"Found at least %d credit card number%s\", found_cnt, found_cnt > 1 ? \"s\" : \"\"),\n\t\t $sub=trimmed_redacted_data,\n\t\t $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n\t\treturn T;\n\t\t}\n\telse\n\t\t{\n\t\treturn F;\n\t\t}\n\t}\n\n# This is used if the signature based technique is in use\n#function validate_credit_card_match(state: signature_state, data: string): bool\n#\t{\n#\t# TODO: Don't handle HTTP data this way.\n#\tif ( \/^GET\/ in data )\n#\t\treturn F;\n#\n#\treturn check_cards(state$conn, data);\n#\t}\n\nevent CreditCardExposure::stream_data(f: fa_file, data: string)\n\t{\n\tlocal c: connection;\n\tfor ( id in f$conns )\n\t\t{\n\t\tc = f$conns[id];\n\t\tbreak;\n\t\t}\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent file_new(f: fa_file)\n\t{\n\tif ( f$source == \"HTTP\" || f$source == \"SMTP\" )\n\t\t{\n\t\tFiles::add_analyzer(f, Files::ANALYZER_DATA_EVENT, \n\t\t [$stream_event=CreditCardExposure::stream_data]);\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"9280ee4d91b9625ce1f8c741e0b292ff553d6368","subject":"Fixed a problem with the hosts\/directions functions.","message":"Fixed a problem with the hosts\/directions functions.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"functions-ext.bro","new_file":"functions-ext.bro","new_contents":"function numeric_id_string(id: conn_id): string\n\t{\n\treturn fmt(\"%s:%d > %s:%d\",\n\t id$orig_h, id$orig_p,\n\t id$resp_h, id$resp_p);\n\t}\n\nfunction fmt_addr_set(input: addr_set): string\n\t{\n\tlocal output = \"\";\n\tlocal tmp = \"\";\n\tlocal len = length(input);\n\tlocal i = 1;\n\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", item);\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s\", output);\n\t}\n\t\nfunction fmt_str_set(input: string_set, strip: pattern): string\n\t{\n\tlocal len = length(input);\n\tif ( len == 0 )\n\t\treturn \"{}\";\n\t\n\tlocal output = \"{\";\n\tlocal tmp = \"\";\n\tlocal i = 1;\n\t\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", gsub(item, strip, \"\"));\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s, \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s}\", output);\n\t}\n\n# Regular expressions for matching IP addresses in strings.\nconst ipv4_addr_regex = \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/;\nconst ipv6_8hex_regex = \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/;\nconst ipv6_compressed_hex_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/;\nconst ipv6_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\nconst ipv6_compressed_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\n\n# These are only commented out until this bug is fixed:\n# http:\/\/www.bro-ids.org\/wiki\/index.php\/Known_Issues#Bug_with_OR-ing_together_pattern_variables\n#const ipv6_addr_regex = ipv6_8hex_regex |\n# ipv6_compressed_hex_regex |\n# ipv6_hex4dec_regex |\n# ipv6_compressed_hex4dec_regex;\n#const ip_addr_regex = ipv4_addr_regex | ipv6_addr_regex;\n\nconst ipv6_addr_regex = \n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nconst ip_addr_regex = \n \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/ |\n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nfunction is_valid_ip(ip_str: string): bool\n\t{\n\tif ( ip_str == ipv4_addr_regex )\n\t\t{\n\t\tlocal octets = split(ip_str, \/\\.\/);\n\t\tif ( |octets| != 4 )\n\t\t\treturn F;\n\t\t\n\t\tlocal num=0;\n\t\tfor ( i in octets )\n\t\t\t{\n\t\t\tnum = to_count(octets[i]);\n\t\t\tif ( num < 0 || 255 < num )\n\t\t\t\treturn F;\n\t\t\t}\n\t\treturn T;\n\t\t}\n\telse if ( ip_str == ipv6_addr_regex )\n\t\t{\n\t\t# TODO: make this work correctly.\n\t\treturn T;\n\t\t}\n\treturn F;\n\t}\n\n# This output a string_array of ip addresses extracted from a string.\n# given: \"this is 1.1.1.1 a test 2.2.2.2 string with ip addresses 3.3.3.3\"\n# outputs: { [1] = 1.1.1.1, [2] = 2.2.2.2, [3] = 3.3.3.3 }\nfunction find_ip_addresses(input: string): string_array\n\t{\n\tlocal parts = split_all(input, ip_addr_regex);\n\tlocal output: string_array;\n\t\n\tfor ( i in parts )\n\t\t{\n\t\tif ( i % 2 == 0 && is_valid_ip(parts[i]) )\n\t\t\toutput[i\/2] = parts[i];\n\t\t}\n\treturn output;\n\t}\n\n\t\n# Some enums for deciding what and when to log.\ntype Direction: enum { Inbound, Outbound, All, Neither };\ntype Hosts: enum { LocalHosts, RemoteHosts, AllHosts, NoHosts };\n\nfunction orig_matches_direction(ip: addr, d: Direction): bool\n\t{\n\tif ( d == Neither ) return F;\n\n\treturn ( d == All ||\n\t (d == Outbound && is_local_addr(ip)) ||\n\t (d == Inbound && !is_local_addr(ip)) );\n\t}\n\t\nfunction resp_matches_direction(ip: addr, d: Direction): bool\n\t{\n\tif ( d == Neither ) return F;\n\t\n\treturn ( d == All ||\n\t (d == Inbound && is_local_addr(ip)) ||\n\t (d == Outbound && !is_local_addr(ip)) );\n\t}\n\nfunction conn_matches_direction(id: conn_id, d: Direction): bool\n\t{\n\tif ( d == NoHosts ) return F;\n\t\n\treturn orig_matches_direction(id$orig_h, d);\n\t}\n\t\nfunction resp_matches_hosts(ip: addr, d: Hosts): bool\n\t{\n\tif ( d == NoHosts ) return F;\n\t\n\treturn ( d == AllHosts ||\n\t (d == LocalHosts && is_local_addr(ip)) ||\n\t (d == RemoteHosts && !is_local_addr(ip)) );\n\t}\n","old_contents":"function numeric_id_string(id: conn_id): string\n\t{\n\treturn fmt(\"%s:%d > %s:%d\",\n\t id$orig_h, id$orig_p,\n\t id$resp_h, id$resp_p);\n\t}\n\nfunction fmt_addr_set(input: addr_set): string\n\t{\n\tlocal output = \"\";\n\tlocal tmp = \"\";\n\tlocal len = length(input);\n\tlocal i = 1;\n\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", item);\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s\", output);\n\t}\n\t\nfunction fmt_str_set(input: string_set, strip: pattern): string\n\t{\n\tlocal len = length(input);\n\tif ( len == 0 )\n\t\treturn \"{}\";\n\t\n\tlocal output = \"{\";\n\tlocal tmp = \"\";\n\tlocal i = 1;\n\t\n\tfor ( item in input )\n\t\t{\n\t\ttmp = fmt(\"%s\", gsub(item, strip, \"\"));\n\t\tif ( len != i )\n\t\t\ttmp = fmt(\"%s, \", tmp);\n\t\ti = i+1;\n\t\toutput = fmt(\"%s%s\", output, tmp);\n\t\t}\n\treturn fmt(\"%s}\", output);\n\t}\n\n# Regular expressions for matching IP addresses in strings.\nconst ipv4_addr_regex = \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/;\nconst ipv6_8hex_regex = \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/;\nconst ipv6_compressed_hex_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/;\nconst ipv6_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\nconst ipv6_compressed_hex4dec_regex = \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/;\n\n# These are only commented out until this bug is fixed:\n# http:\/\/www.bro-ids.org\/wiki\/index.php\/Known_Issues#Bug_with_OR-ing_together_pattern_variables\n#const ipv6_addr_regex = ipv6_8hex_regex |\n# ipv6_compressed_hex_regex |\n# ipv6_hex4dec_regex |\n# ipv6_compressed_hex4dec_regex;\n#const ip_addr_regex = ipv4_addr_regex | ipv6_addr_regex;\n\nconst ipv6_addr_regex = \n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nconst ip_addr_regex = \n \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/ |\n \/([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\/ |\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)\/ | # IPv6 Compressed Hex\n \/(([0-9A-Fa-f]{1,4}:){6,6})([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/ | # 6Hex4Dec\n \/(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::(([0-9A-Fa-f]{1,4}:)*)([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\/; # CompressedHex4Dec\n\nfunction is_valid_ip(ip_str: string): bool\n\t{\n\tif ( ip_str == ipv4_addr_regex )\n\t\t{\n\t\tlocal octets = split(ip_str, \/\\.\/);\n\t\tif ( |octets| != 4 )\n\t\t\treturn F;\n\t\t\n\t\tlocal num=0;\n\t\tfor ( i in octets )\n\t\t\t{\n\t\t\tnum = to_count(octets[i]);\n\t\t\tif ( num < 0 || 255 < num )\n\t\t\t\treturn F;\n\t\t\t}\n\t\treturn T;\n\t\t}\n\telse if ( ip_str == ipv6_addr_regex )\n\t\t{\n\t\t# TODO: make this work correctly.\n\t\treturn T;\n\t\t}\n\treturn F;\n\t}\n\n# This output a string_array of ip addresses extracted from a string.\n# given: \"this is 1.1.1.1 a test 2.2.2.2 string with ip addresses 3.3.3.3\"\n# outputs: { [1] = 1.1.1.1, [2] = 2.2.2.2, [3] = 3.3.3.3 }\nfunction find_ip_addresses(input: string): string_array\n\t{\n\tlocal parts = split_all(input, ip_addr_regex);\n\tlocal output: string_array;\n\t\n\tfor ( i in parts )\n\t\t{\n\t\tif ( i % 2 == 0 && is_valid_ip(parts[i]) )\n\t\t\toutput[i\/2] = parts[i];\n\t\t}\n\treturn output;\n\t}\n\n\n\t\n# Some enums for deciding what and when to log.\ntype Direction: enum { Inbound, Outbound, All };\ntype Hosts: enum { LocalHosts, RemoteHosts, AllHosts };\n\nfunction orig_matches_direction(ip: addr, d: Direction): bool\n\t{\n\tif ( d == None ) return F;\n\n\treturn ( d == All ||\n\t (d == Outbound && is_local_addr(ip)) ||\n\t (d == Inbound && !is_local_addr(ip)) );\n\t}\n\t\nfunction resp_matches_direction(ip: addr, d: Direction): bool\n\t{\n\tif ( d == None ) return F;\n\t\n\treturn ( d == All ||\n\t (d == Inbound && is_local_addr(ip)) ||\n\t (d == Outbound && !is_local_addr(ip)) );\n\t}\n\nfunction conn_matches_direction(id: conn_id, d: Direction): bool\n\t{\n\tif ( d == None ) return F;\n\t\n\treturn orig_matches_direction(id$orig_h, d);\n\t}\n\t\nfunction resp_matches_hosts(ip: addr, d: Hosts): bool\n\t{\n\tif ( d == None ) return F;\n\t\n\treturn ( d == AllHosts ||\n\t (d == LocalHosts && is_local_addr(ip)) ||\n\t (d == RemoteHosts && !is_local_addr(ip)) );\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"10f73e6bf217f458e2f494fc86c5c6de4d4fe1e8","subject":"load scripts properly","message":"load scripts properly\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/__load__.bro","new_file":"scripts_master\/__load__.bro","new_contents":"@load .\/bro_log.bro\n@load .\/bro_receiver.bro\n@load .\/dio_download_complete_log.bro\n@load .\/dio_download_offer_log.bro\n@load .\/dio_ftp_log.bro\n@load .\/dio_log.bro\n@load .\/dio_mysql_log.bro\n@load .\/dio_smb_bind_log.bro\n@load .\/dio_smb_request_log.bro","old_contents":"@load .\/bro_receiver.bro\n@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"c94a3d7c8b382704dfc53b5bba732b9a774c3a80","subject":"add acu_result.bro","message":"add acu_result.bro\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/acu_result.bro","new_file":"scripts_master\/acu_result.bro","new_contents":"module Acu_result;\n\nexport{\n redef enum Log::ID += { LOG };\n redef LogAscii::empty_field = \"EMPTY\";\n \n type Info: record {\n ts: time &log;\n attack: string &log;\n };\n}\n\nevent bro_init() &priority=5 {\n Log::create_stream(Acu_result::LOG, [$columns=Info, $path=\"acu_result\"]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'scripts_master\/acu_result.bro' did not match any file(s) known to git\n","license":"mit","lang":"Bro"} {"commit":"807a5582184c0c375b030aa304714b32d7111514","subject":"WIP balance connector to ready slave","message":"WIP balance connector to ready slave\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_receiver.bro","new_file":"scripts_master\/bro_receiver.bro","new_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n log_bro(\"Bro Master log access event!\");\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n log_bro(\"Bro Master log mysql event!\");\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n local inc: string = \"Incoming connection extablished \" + peer_name;\n log_bro(inc);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local inc: string = \"Incoming connection broken for \" + peer_name;\n log_bro(inc);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Registering new slave \" + peer_name);\n slaves[peer_name] = 0;\n # TODO balance clients to this new slave\n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Registering new connector \" + peer_name);\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n local size = |slaves|;\n\n print \"size\", size;\n if (size <= 0) {\n log_bro(\"No slaves are registered, cannot register connector \" + peer_name);\n print \"should return\";\n return;\n }\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n print \"slave\", slave, \"count_conn\", count_conn;\n \n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n if (best_slave != \"\") {\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n print \"Registered connector \", peer_name, \" and balanced to \", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not register connector \", peer_name;\n log_bro(\"Could not register connector \" + peer_name);\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Unregistering old slave \" + peer_name);\n delete slaves[peer_name];\n # TODO rebalance\n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Unregistering old connector \" + peer_name);\n Broker::erase(connectors, Broker::data(peer_name));\n # TODO decrement slaves for the connector\n }\n}","old_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: opaque of Broker::Handle;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n slaves = Broker::create_master(\"slaves\");\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n log_bro(\"Bro Master log access event!\");\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n log_bro(\"Bro Master log mysql event!\");\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n local inc: string = \"Incoming connection extablished \" + peer_name;\n log_bro(inc);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local inc: string = \"Incoming connection broken for \" + peer_name;\n log_bro(inc);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Registering new slave \" + peer_name);\n Broker::insert(slaves, Broker::data(peer_name), Broker::data(0));\n # TODO balance clients to this new slave\n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Registering new connector \" + peer_name);\n local min_connectors = 100000;\n local best_slave = \"\";\n when (local keys = Broker::keys(slaves)$result) {\n for (slave in Broker::DataVector(keys)) {\n when (local m = Broker::refine_to_count(Broker::lookup(slaves, Broker::data(slave))$result)) {\n if (m < min_connectors) {\n best_slave = Broker::refine_to_string(Broker::data(slave));\n min_connectors = m;\n }\n }\n timeout 1sec {\n log_bro(\"Query timeout registering connector \" + peer_name);\n }\n }\n }\n timeout 1sec {\n log_bro(\"Transit timeout registering connector \" + peer_name);\n }\n if (best_slave != \"\") {\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n log_bro(\"Could not register connector \" + peer_name);\n }\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Unregistering old slave \" + peer_name);\n Broker::erase(slaves, Broker::data(peer_name));\n # TODO rebalance\n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Unregistering old connector \" + peer_name);\n Broker::erase(connectors, Broker::data(peer_name));\n # TODO decrement slaves for the connector\n }\n}","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"8c010473f4c5e9e5e9f30e85775c98b801e68258","subject":"Updating the version check code","message":"Updating the version check code\n\nPrevious code calls a function which does not seem to work or exist in bro 2.5.","repos":"salesforce\/ja3","old_file":"bro\/ja3.bro","new_file":"bro\/ja3.bro","new_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n# LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\n@if ( Version::number >= 20600 || ( Version::number == 20500 && Version::info$commit >= 944 ) )\nevent ssl_client_hello(c: connection, version: count, record_version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec, comp_methods: index_vec) &priority=1\n@else\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n@endif\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","old_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n# LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\n@if ( Version::at_least(\"2.6\") || ( Version::number == 20500 && Version::info$commit >= 944 ) )\nevent ssl_client_hello(c: connection, version: count, record_version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec, comp_methods: index_vec) &priority=1\n@else\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n@endif\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1fc0532f68da583b189f819ba77a46f99158bd53","subject":"Renamed the log file for the ssl-known-certs analyzer to make it match the script name.","message":"Renamed the log file for the ssl-known-certs analyzer to make it match the script name.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load global-ext\n@load ssl\n\nmodule KnownCerts;\n\nexport {\n\tconst log = open_log_file(\"ssl-known-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst log_hosts: Hosts = LocalHosts &redef;\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tadd c$service[\"SSL\"];\n\t\n\tif ( !ip_matches_hosts(c$id$resp_h, log_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\t\t}\n\t}\n\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load global-ext\n@load ssl\n\nmodule KnownCerts;\n\nexport {\n\tconst log = open_log_file(\"known-ssl-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst log_hosts: Hosts = LocalHosts &redef;\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tadd c$service[\"SSL\"];\n\t\n\tif ( !ip_matches_hosts(c$id$resp_h, log_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\t\t}\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f44bb0d868f6b49d8cf42fcd6157750bf01f1354","subject":"fix erroneous log","message":"fix erroneous log\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_master.bro","new_file":"scripts_master\/bro_master.bro","new_contents":"@load .\/master_log.bro\n@load .\/balance_log.bro\n@load .\/dio_access.bro\n@load .\/dio_download_complete.bro\n@load .\/dio_download_offer.bro\n@load .\/dio_ftp.bro\n@load .\/dio_mysql_command.bro\n@load .\/dio_mysql_login.bro\n@load .\/dio_smb_bind.bro\n@load .\/dio_smb_request.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\n\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string);\nglobal dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n log_bro(\"bro_master.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n\n Broker::subscribe_to_events(\"honeypot\/dionaea\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_master.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent dionaea_mysql_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_login::LOG, rec);\n}\n\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n log_bro(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n log_bro(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n log_bro(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n log_bro(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n log_bro(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n log_bro(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n log_bro(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n log_bro(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n log_bro(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n log_bro(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: BalanceLog::Info = [$connector=connector, $slave=slave];\n Log::write(BalanceLog::LOG, rec);\n}","old_contents":"@load .\/master_log.bro\n@load .\/balance_log.bro\n@load .\/dio_access.bro\n@load .\/dio_download_complete.bro\n@load .\/dio_download_offer.bro\n@load .\/dio_ftp.bro\n@load .\/dio_mysql_command.bro\n@load .\/dio_mysql_login.bro\n@load .\/dio_smb_bind.bro\n@load .\/dio_smb_request.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\n\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string);\nglobal dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n log_bro(\"bro_master.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n\n Broker::subscribe_to_events(\"honeypot\/dionaea\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_master.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent dionaea_mysql_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_login::LOG, rec);\n}\n\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n log_bro(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n log_bro(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n log_bro(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n log_bro(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n log_bro(\"Unregistered old slave \" + peer_name + \" ...\");\n log_balance(peer_name, \"\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n log_bro(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n log_bro(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n log_bro(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n log_bro(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n log_bro(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: BalanceLog::Info = [$connector=connector, $slave=slave];\n Log::write(BalanceLog::LOG, rec);\n}","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"90378df73aa1d7024670c320a566187e8b00ffe5","subject":"Creates plugin configuration for AF_PACKET plugin","message":"Creates plugin configuration for AF_PACKET plugin\n\nNot enabling this by default, but placing here so it can be easily turned on.","repos":"mocyber\/rock-scripts","old_file":"plugins\/afpacket.bro","new_file":"plugins\/afpacket.bro","new_contents":"# Workaround for AF_Packet plugin across multiple interfaces\n# See https:\/\/bro-tracker.atlassian.net\/browse\/BIT-1747 for more info\n@load scripts\/rock\/plugins\/afpacketredef AF_Packet::fanout_id = strcmp(getenv(\"fanout_id\"),\"\") == 0 ? 0 : to_count(getenv(\"fanout_id\"));\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'plugins\/afpacket.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"11d6d590e471c7bbc2139bf6824c5ac8b18641f2","subject":"logs the number of outbound connections per destination country","message":"logs the number of outbound connections per destination country\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"country-metrics.bro","new_file":"country-metrics.bro","new_contents":"@load base\/frameworks\/metrics\n\nredef enum Metrics::ID += {\n COUNTRY_CONNECTIONS\n};\n\nevent bro_init()\n{\n Metrics::add_filter(COUNTRY_CONNECTIONS,\n [$name=\"all\",\n $break_interval=600secs\n ]);\n}\n\nevent connection_established(c: connection)\n{\n if(Site::is_local_addr(c$id$orig_h)){\n local loc = lookup_location(c$id$resp_h);\n if(loc?$country_code) {\n local cc = loc$country_code;\n Metrics::add_data(COUNTRY_CONNECTIONS, [$str=cc], 1);\n }\n }\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'country-metrics.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"ee657121327c6022e468a807e7daefb23bc5aff9","subject":"Update hassh.bro","message":"Update hassh.bro","repos":"salesforce\/hassh","old_file":"bro\/hassh.bro","new_file":"bro\/hassh.bro","new_contents":"# HASSH #\n# SSH Key Initiation Exchange Fingerprinting #\n# #\n# Script Version: v1.0 #\n# Authors: Ben Reardon (breardon@salesforce.com, @benreardon) #\n# : Jeff Atkinson (jatkinson@salesforce.com) #\n# : John Althouse (jalthouse@salesforce.com) #\n# Description: This bro script appends hassh data to ssh.log #\n# by enumerating the SSH_MSG_KEXINIT packets sent #\n# as clear text between the client and server as part # \n# of the negotiation of an SSH connection. #\n# NOTE: bro currently ( <= v2.5.4) has a bug which reverses #\n# the Client\/server flag, the logic in this script reverses #\n# this bug. Therefore once the bro bug is patched, the logic #\n# in this script also needs return to the proper form. #\n# #\n# Copyright (c) 2018, salesforce.com, inc. #\n# All rights reserved. #\n# SPDX-License-Identifier: BSD-3-Clause #\n# For full license text, see the LICENSE file in the repo root or #\n# https:\/\/opensource.org\/licenses\/BSD-3-Clause #\n\n\nmodule SSH;\n\nexport {\n type HASSHStorage: record {\n hasshVersion:string &log &default=\"1.0\"; # ANY change in hassh\/hasshServer composition requires Version update \n hassh: string &log &optional &default=\"\";\n hasshServer: string &log &optional &default=\"\";\n \n # Client variables #\n ckex: string &log &optional &default=\"\";\n cshka: string &log &optional &default=\"\";\n ceacts: string &log &optional &default=\"\";\n cmacts: string &log &optional &default=\"\";\n ccacts: string &log &optional &default=\"\";\n #clcts: string &log &optional &default=\"\"; \n hasshAlgorithms: string &log &optional &default=\"\";\n \n # Server variables #\n skex: string &log &optional &default=\"\";\n sshka: string &log &optional &default=\"\";\n seastc: string &log &optional &default=\"\";\n smastc: string &log &optional &default=\"\";\n scastc: string &log &optional &default=\"\";\n #slstc: string &log &optional &default=\"\";\n hasshServerAlgorithms: string &log &optional &default=\"\";\n };\n}\n\nredef record connection += {\n hassh: HASSHStorage &optional;\n};\n \nredef record SSH::Info += {\n hasshVersion: string &log &optional;\n hassh: string &log &optional;\n hasshServer: string &log &optional;\n \n # ===> Log Client variables <=== #\n # Comment out any fields that are not required to be logged in their raw form to ssh.log\n #ckex: string &log &optional;\n cshka: string &log &optional; \n #ceacts: string &log &optional; \n #cmacts: string &log &optional;\n #ccacts: string &log &optional; \n #clcts: string &log &optional;\n hasshAlgorithms: string &log &optional;\n \n # ===> Log Server variables <=== #\n # Comment out any fields that are not required to be logged in their raw form to ssh.log\n #skex: string &log &optional; \n sshka: string &log &optional; \n #seastc: string &log &optional; \n #smastc: string &log &optional; \n #scastc: string &log &optional; \n #slstc: string &log &optional;\n hasshServerAlgorithms: string &log &optional;\n};\n\n\n# Build Client Application fingerprint #\nfunction get_hassh(c:connection, capabilities: SSH::Capabilities ) {\n c$hassh = HASSHStorage();\n c$hassh$ckex = join_string_vec(capabilities$kex_algorithms,\",\");\n c$hassh$ceacts = join_string_vec(capabilities$encryption_algorithms$client_to_server,\",\");\n c$hassh$cmacts = join_string_vec(capabilities$mac_algorithms$client_to_server,\",\");\n c$hassh$ccacts = join_string_vec(capabilities$compression_algorithms$client_to_server,\",\");\n c$hassh$cshka = join_string_vec(capabilities$server_host_key_algorithms,\",\"); # The Host key algorithm set may be useful information by itself but is not included in the hassh.\n #c$hassh$clcts = join_string_vec(capabilities$languages$client_to_server,\",\"); # The Languages field may be useful information by itself but is not included in the hasshServer.\n c$hassh$hasshAlgorithms = string_cat(c$hassh$ckex,\";\",c$hassh$ceacts,\";\",c$hassh$cmacts,\";\",c$hassh$ccacts); # Contatenate the four selected lists of algorithms (Key,Enc,MAC,Compression) to build the Client hash\n c$hassh$hassh = md5_hash(c$hassh$hasshAlgorithms);\n}\n\n# Build Server Application fingerprint #\nfunction get_hasshServer(c:connection, capabilities: SSH::Capabilities ) {\n c$hassh = HASSHStorage();\n c$hassh$skex = join_string_vec(capabilities$kex_algorithms,\",\");\n c$hassh$seastc = join_string_vec(capabilities$encryption_algorithms$server_to_client,\",\");\n c$hassh$smastc = join_string_vec(capabilities$mac_algorithms$server_to_client,\",\");\n c$hassh$scastc = join_string_vec(capabilities$compression_algorithms$server_to_client,\",\");\n c$hassh$sshka = join_string_vec(capabilities$server_host_key_algorithms,\",\"); # The Host key algorithm set may be useful information by itself but is not included in the hasshServer.\n #c$hassh$slstc = join_string_vec(capabilities$languages$server_to_client,\",\"); # The Languages field may be useful information by itself but is not included in the hasshServer.\n c$hassh$hasshServerAlgorithms = string_cat(c$hassh$skex,\";\",c$hassh$seastc,\";\",c$hassh$smastc,\";\",c$hassh$scastc); # Contatenate the four selected lists of algorithms (Key,Enc,Message,Compression) to build the Server hash\n c$hassh$hasshServer = md5_hash(c$hassh$hasshServerAlgorithms);\n}\n\n# Event #\nevent ssh_capabilities(c: connection, cookie: string, capabilities: SSH::Capabilities) {\n if ( !c?$ssh ) {return;}\n c$hassh = HASSHStorage();\n \n # bro currently has a bug which it reverses the Client\/server flag.\n # The following \"if\" statements reverses this bug. Once the bro bug is patched, \n # this logic must return to the proper form. \n \n if ( capabilities$is_server == T ) {\n get_hassh(c, capabilities);\n c$ssh$hasshVersion = c$hassh$hasshVersion;\n c$ssh$hassh = c$hassh$hassh;\n \n # ===> Log Client variables <=== #\n # Comment out any fields that are not required to be logged in their raw form to ssh.log\n #c$ssh$ckex = c$hassh$ckex;\n c$ssh$cshka = c$hassh$cshka;\n #c$ssh$ceacts = c$hassh$ceacts;\n #c$ssh$cmacts = c$hassh$cmacts;\n #c$ssh$ccacts = c$hassh$ccacts;\n #c$ssh$clcts = c$hassh$clcts;\n c$ssh$hasshAlgorithms = c$hassh$hasshAlgorithms;\n }\n if ( capabilities$is_server == F ) {\n get_hasshServer(c, capabilities);\n c$ssh$hasshVersion = c$hassh$hasshVersion;\n c$ssh$hasshServer = c$hassh$hasshServer;\n \n # ===> Log Server variables <=== #\n # Comment out any fields that are not required to be logged in their raw form to ssh.log\n #c$ssh$skex = c$hassh$skex;\n c$ssh$sshka = c$hassh$sshka;\n #c$ssh$seastc = c$hassh$seastc;\n #c$ssh$smastc = c$hassh$smastc;\n #c$ssh$scastc = c$hassh$scastc;\n #c$ssh$slstc = c$hassh$clcts;\n c$ssh$hasshServerAlgorithms = c$hassh$hasshServerAlgorithms;\n }\n}\n","old_contents":"# HASSH #\n# SSH Key Initiation Exchange Fingerprinting #\n# #\n# Script Version: v1.0 #\n# Authors: Ben Reardon (breardon@salesforce.com, @benreardon) #\n# : Jeff Atkinson (jatkinson@salesforce.com) #\n# : John Althouse (jalthouse@salesforce.com) #\n# Description: This bro script appends hassh data to ssh.log #\n# by enumerating the SSH_MSG_KEXINIT packets sent #\n# as clear text between the client and server as part # \n# of the negotiation of an SSH connection. #\n# NOTE: bro currently ( <= v2.5.4) has a bug which reverses #\n# the Client\/server flag, the logic in this script reverses #\n# this bug. Therefore once the bro bug is patched, the logic #\n# in this script also needs return to the proper form. #\n\n\nmodule SSH;\n\nexport {\n type HASSHStorage: record {\n hasshVersion:string &log &default=\"1.0\"; # ANY change in hassh\/hasshServer composition requires Version update \n hassh: string &log &optional &default=\"\";\n hasshServer: string &log &optional &default=\"\";\n \n # Client variables #\n ckex: string &log &optional &default=\"\";\n cshka: string &log &optional &default=\"\";\n ceacts: string &log &optional &default=\"\";\n cmacts: string &log &optional &default=\"\";\n ccacts: string &log &optional &default=\"\";\n #clcts: string &log &optional &default=\"\"; \n hasshAlgorithms: string &log &optional &default=\"\";\n \n # Server variables #\n skex: string &log &optional &default=\"\";\n sshka: string &log &optional &default=\"\";\n seastc: string &log &optional &default=\"\";\n smastc: string &log &optional &default=\"\";\n scastc: string &log &optional &default=\"\";\n #slstc: string &log &optional &default=\"\";\n hasshServerAlgorithms: string &log &optional &default=\"\";\n };\n}\n\nredef record connection += {\n hassh: HASSHStorage &optional;\n};\n \nredef record SSH::Info += {\n hasshVersion: string &log &optional;\n hassh: string &log &optional;\n hasshServer: string &log &optional;\n \n # ===> Log Client variables <=== #\n # Comment out any fields that are not required to be logged in their raw form to ssh.log\n #ckex: string &log &optional;\n cshka: string &log &optional; \n #ceacts: string &log &optional; \n #cmacts: string &log &optional;\n #ccacts: string &log &optional; \n #clcts: string &log &optional;\n hasshAlgorithms: string &log &optional;\n \n # ===> Log Server variables <=== #\n # Comment out any fields that are not required to be logged in their raw form to ssh.log\n #skex: string &log &optional; \n sshka: string &log &optional; \n #seastc: string &log &optional; \n #smastc: string &log &optional; \n #scastc: string &log &optional; \n #slstc: string &log &optional;\n hasshServerAlgorithms: string &log &optional;\n};\n\n\n# Build Client Application fingerprint #\nfunction get_hassh(c:connection, capabilities: SSH::Capabilities ) {\n c$hassh = HASSHStorage();\n c$hassh$ckex = join_string_vec(capabilities$kex_algorithms,\",\");\n c$hassh$ceacts = join_string_vec(capabilities$encryption_algorithms$client_to_server,\",\");\n c$hassh$cmacts = join_string_vec(capabilities$mac_algorithms$client_to_server,\",\");\n c$hassh$ccacts = join_string_vec(capabilities$compression_algorithms$client_to_server,\",\");\n c$hassh$cshka = join_string_vec(capabilities$server_host_key_algorithms,\",\"); # The Host key algorithm set may be useful information by itself but is not included in the hassh.\n #c$hassh$clcts = join_string_vec(capabilities$languages$client_to_server,\",\"); # The Languages field may be useful information by itself but is not included in the hasshServer.\n c$hassh$hasshAlgorithms = string_cat(c$hassh$ckex,\";\",c$hassh$ceacts,\";\",c$hassh$cmacts,\";\",c$hassh$ccacts); # Contatenate the four selected lists of algorithms (Key,Enc,MAC,Compression) to build the Client hash\n c$hassh$hassh = md5_hash(c$hassh$hasshAlgorithms);\n}\n\n# Build Server Application fingerprint #\nfunction get_hasshServer(c:connection, capabilities: SSH::Capabilities ) {\n c$hassh = HASSHStorage();\n c$hassh$skex = join_string_vec(capabilities$kex_algorithms,\",\");\n c$hassh$seastc = join_string_vec(capabilities$encryption_algorithms$server_to_client,\",\");\n c$hassh$smastc = join_string_vec(capabilities$mac_algorithms$server_to_client,\",\");\n c$hassh$scastc = join_string_vec(capabilities$compression_algorithms$server_to_client,\",\");\n c$hassh$sshka = join_string_vec(capabilities$server_host_key_algorithms,\",\"); # The Host key algorithm set may be useful information by itself but is not included in the hasshServer.\n #c$hassh$slstc = join_string_vec(capabilities$languages$server_to_client,\",\"); # The Languages field may be useful information by itself but is not included in the hasshServer.\n c$hassh$hasshServerAlgorithms = string_cat(c$hassh$skex,\";\",c$hassh$seastc,\";\",c$hassh$smastc,\";\",c$hassh$scastc); # Contatenate the four selected lists of algorithms (Key,Enc,Message,Compression) to build the Server hash\n c$hassh$hasshServer = md5_hash(c$hassh$hasshServerAlgorithms);\n}\n\n# Event #\nevent ssh_capabilities(c: connection, cookie: string, capabilities: SSH::Capabilities) {\n if ( !c?$ssh ) {return;}\n c$hassh = HASSHStorage();\n \n # bro currently has a bug which it reverses the Client\/server flag.\n # The following \"if\" statements reverses this bug. Once the bro bug is patched, \n # this logic must return to the proper form. \n \n if ( capabilities$is_server == T ) {\n get_hassh(c, capabilities);\n c$ssh$hasshVersion = c$hassh$hasshVersion;\n c$ssh$hassh = c$hassh$hassh;\n \n # ===> Log Client variables <=== #\n # Comment out any fields that are not required to be logged in their raw form to ssh.log\n #c$ssh$ckex = c$hassh$ckex;\n c$ssh$cshka = c$hassh$cshka;\n #c$ssh$ceacts = c$hassh$ceacts;\n #c$ssh$cmacts = c$hassh$cmacts;\n #c$ssh$ccacts = c$hassh$ccacts;\n #c$ssh$clcts = c$hassh$clcts;\n c$ssh$hasshAlgorithms = c$hassh$hasshAlgorithms;\n }\n if ( capabilities$is_server == F ) {\n get_hasshServer(c, capabilities);\n c$ssh$hasshVersion = c$hassh$hasshVersion;\n c$ssh$hasshServer = c$hassh$hasshServer;\n \n # ===> Log Server variables <=== #\n # Comment out any fields that are not required to be logged in their raw form to ssh.log\n #c$ssh$skex = c$hassh$skex;\n c$ssh$sshka = c$hassh$sshka;\n #c$ssh$seastc = c$hassh$seastc;\n #c$ssh$smastc = c$hassh$smastc;\n #c$ssh$scastc = c$hassh$scastc;\n #c$ssh$slstc = c$hassh$clcts;\n c$ssh$hasshServerAlgorithms = c$hassh$hasshServerAlgorithms;\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"cd0769cfef15ff92c6dade17d25460475261f749","subject":"change metric name","message":"change metric name\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-size-metrics.bro","new_file":"http-size-metrics.bro","new_contents":"@load base\/frameworks\/metrics\n@load base\/protocols\/http\n@load base\/utils\/site\n\nredef enum Metrics::ID += {\n\tHTTP_REQUEST_SIZE_BY_HOST,\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_REQUEST_SIZE_BY_HOST,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n\n}\n\nevent HTTP::log_http(rec: HTTP::Info)\n{\n\tif ( rec?$host && rec?$response_body_len)\n\t\tMetrics::add_data(HTTP_REQUEST_SIZE_BY_HOST, [$str=rec$host], rec$response_body_len);\n}\n","old_contents":"@load base\/frameworks\/metrics\n@load base\/protocols\/http\n@load base\/utils\/site\n\nredef enum Metrics::ID += {\n\tHTTP_REQUEST_SIZE_BY_HOST_HEADER,\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_REQUEST_SIZE_BY_HOST_HEADER,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n\n}\n\nevent HTTP::log_http(rec: HTTP::Info)\n{\n\tif ( rec?$host && rec?$response_body_len)\n\t\tMetrics::add_data(HTTP_REQUEST_SIZE_BY_HOST_HEADER, [$str=rec$host], rec$response_body_len);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"bd25f7213135034dab86778337eabea5385b3d8b","subject":"Track partial_connections","message":"Track partial_connections\n\nTrack partial connections that were established before zeek started.\n","repos":"corelight\/bro-long-connections","old_file":"scripts\/main.bro","new_file":"scripts\/main.bro","new_contents":"@load base\/protocols\/conn\n@load base\/utils\/time\n\n\n# This is probably not so great to reach into the Conn namespace..\nmodule Conn;\n\nexport {\nfunction set_conn_log_data_hack(c: connection)\n\t{\n\tConn::set_conn(c, T);\n\t}\n}\n\n# Now onto the actual code for this script...\n\nmodule LongConnection;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += {\n\t\t## Notice for when a long connection is found.\n\t\t## The `sub` field in the notice represents the number\n\t\t## of seconds the connection has currently been alive.\n\t\tLongConnection::found\n\t};\n\n\t## Aliasing vector of interval values as\n\t## \"Durations\"\n\ttype Durations: vector of interval;\n\n\t## The default duration that you are locally \n\t## considering a connection to be \"long\". \n\tconst default_durations = Durations(10min, 30min, 1hr, 12hr, 24hrs, 3days) &redef;\n\n\t## These are special cases for particular hosts or subnets\n\t## that you may want to watch for longer or shorter\n\t## durations than the default.\n\tconst special_cases: table[subnet] of Durations = {} &redef;\n}\n\nredef record connection += {\n\t## Offset of the currently watched connection duration by the long-connections script.\n\tlong_conn_offset: count &default=0;\n};\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(LOG, [$columns=Conn::Info, $path=\"conn_long\"]);\n\t}\n\nfunction get_durations(c: connection): Durations\n\t{\n\tlocal check_it: Durations;\n\tif ( c$id$orig_h in special_cases )\n\t\tcheck_it = special_cases[c$id$orig_h];\n\telse if ( c$id$resp_h in special_cases )\n\t\tcheck_it = special_cases[c$id$resp_h];\n\telse\n\t\tcheck_it = default_durations;\n\n\treturn check_it;\n\t}\n\nfunction long_callback(c: connection, cnt: count): interval\n\t{\n\tlocal check_it = get_durations(c);\n\n\tif ( c$long_conn_offset < |check_it| && c$duration >= check_it[c$long_conn_offset] )\n\t\t{\n\t\tConn::set_conn_log_data_hack(c);\n\t\tLog::write(LongConnection::LOG, c$conn);\n\n\t\tlocal message = fmt(\"%s -> %s:%s remained alive for longer than %s\", \n\t\t c$id$orig_h, c$id$resp_h, c$id$resp_p, duration_to_mins_secs(c$duration));\n\t\tNOTICE([$note=LongConnection::found,\n\t\t $msg=message,\n\t\t $sub=fmt(\"%.2f\", c$duration),\n\t\t $conn=c]);\n\t\t\n\t\t++c$long_conn_offset;\n\t\t}\n\n\t# Keep watching if there are potentially more thresholds.\n\tif ( c$long_conn_offset < |check_it| )\n\t\treturn check_it[c$long_conn_offset];\n\telse\n\t\treturn -1sec;\n\t}\n\nevent connection_established(c: connection)\n\t{\n\tlocal check = get_durations(c);\n\tif ( |check| > 0 )\n\t\t{\n\t\tConnPolling::watch(c, long_callback, 1, check[0]);\n\t\t}\n\t}\n\nevent partial_connection(c: connection)\n\t{\n\tlocal check = get_durations(c);\n\tif ( |check| > 0 )\n\t\t{\n\t\tConnPolling::watch(c, long_callback, 1, check[0]);\n\t\t}\n\t}\n","old_contents":"@load base\/protocols\/conn\n@load base\/utils\/time\n\n\n# This is probably not so great to reach into the Conn namespace..\nmodule Conn;\n\nexport {\nfunction set_conn_log_data_hack(c: connection)\n\t{\n\tConn::set_conn(c, T);\n\t}\n}\n\n# Now onto the actual code for this script...\n\nmodule LongConnection;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += {\n\t\t## Notice for when a long connection is found.\n\t\t## The `sub` field in the notice represents the number\n\t\t## of seconds the connection has currently been alive.\n\t\tLongConnection::found\n\t};\n\n\t## Aliasing vector of interval values as\n\t## \"Durations\"\n\ttype Durations: vector of interval;\n\n\t## The default duration that you are locally \n\t## considering a connection to be \"long\". \n\tconst default_durations = Durations(10min, 30min, 1hr, 12hr, 24hrs, 3days) &redef;\n\n\t## These are special cases for particular hosts or subnets\n\t## that you may want to watch for longer or shorter\n\t## durations than the default.\n\tconst special_cases: table[subnet] of Durations = {} &redef;\n}\n\nredef record connection += {\n\t## Offset of the currently watched connection duration by the long-connections script.\n\tlong_conn_offset: count &default=0;\n};\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(LOG, [$columns=Conn::Info, $path=\"conn_long\"]);\n\t}\n\nfunction get_durations(c: connection): Durations\n\t{\n\tlocal check_it: Durations;\n\tif ( c$id$orig_h in special_cases )\n\t\tcheck_it = special_cases[c$id$orig_h];\n\telse if ( c$id$resp_h in special_cases )\n\t\tcheck_it = special_cases[c$id$resp_h];\n\telse\n\t\tcheck_it = default_durations;\n\n\treturn check_it;\n\t}\n\nfunction long_callback(c: connection, cnt: count): interval\n\t{\n\tlocal check_it = get_durations(c);\n\n\tif ( c$long_conn_offset < |check_it| && c$duration >= check_it[c$long_conn_offset] )\n\t\t{\n\t\tConn::set_conn_log_data_hack(c);\n\t\tLog::write(LongConnection::LOG, c$conn);\n\n\t\tlocal message = fmt(\"%s -> %s:%s remained alive for longer than %s\", \n\t\t c$id$orig_h, c$id$resp_h, c$id$resp_p, duration_to_mins_secs(c$duration));\n\t\tNOTICE([$note=LongConnection::found,\n\t\t $msg=message,\n\t\t $sub=fmt(\"%.2f\", c$duration),\n\t\t $conn=c]);\n\t\t\n\t\t++c$long_conn_offset;\n\t\t}\n\n\t# Keep watching if there are potentially more thresholds.\n\tif ( c$long_conn_offset < |check_it| )\n\t\treturn check_it[c$long_conn_offset];\n\telse\n\t\treturn -1sec;\n\t}\n\nevent connection_established(c: connection)\n\t{\n\tlocal check = get_durations(c);\n\tif ( |check| > 0 )\n\t\t{\n\t\tConnPolling::watch(c, long_callback, 1, check[0]);\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"c07b4c9aecc510432600515d7f1db7bca299189f","subject":"Reworked and significantly better script for raising a notice when too many recipients are being rejected over email.","message":"Reworked and significantly better script for raising a notice when too many recipients are being rejected over email.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For the SMTP_StrangeRejectBehavior notice to work, you must define a \n# local_mail table listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n\trejects: count &default=0;\n\ttotal: count &default=0;\n};\n\nexport {\n\t# The idea for this is that if a host makes more than spam_threshold \n\t# smtp connections per hour of which at least spam_percent of those are\n\t# rejected and the host is not a known mail sending host, then it's likely \n\t# sending spam or viruses.\n\t#\n\tconst spam_threshold = 300 &redef;\n\tconst spam_percent = 30 &redef;\n\t\n\t# These are smtp status codes that are considered \"rejected\".\n\tconst bad_address_reject_codes: set[count] = {\n\t\t501, # Bad sender address syntax\n\t\t550, # Requested action not taken: mailbox unavailable\n\t\t551, # User not local; please try \n\t\t553, # Requested action not taken: mailbox name not allowed\n\t};\n\t\n\tredef enum Notice += {\n\t\tSMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n\t\tSMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects\n\t};\n\t\n\t# This variable keeps track of the number of rejected and accepted \n\t# RCPT TO's a host has per hour.\n\tglobal reject_counter: table[addr] of smtp_counter &create_expire=1hr &redef;\n\t\n\t# Reduce the volume of notices raised by filtering out host that have \n\t# already been detected as having too many rejected RCPT TOs.\n\tglobal notified_reject_spammers: set[addr] &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\t# If this is a continued response, it could be something like\n\t# the multiline rejections that gmail gives. We only want to count\n\t# the first rejection in that case.\n\tif ( cont_resp ) return;\n\t\t\n\tif ( c$id$orig_h !in reject_counter )\n\t\t{\n\t\tlocal t: smtp_counter;\n\t\treject_counter[c$id$orig_h] = t;\n\t\t}\n\t# Set the smtp_counter to the local var \"sc\"\n\tlocal sc = reject_counter[c$id$orig_h];\n\t\n\t# Whenever a \"RCPT TO\" is done, we add that to the total.\n\tif ( \/^[rR][cC][pP][tT]\/ in cmd )\n\t\t{\n\t\t++sc$total;\n\t\tif ( code in bad_address_reject_codes )\n\t\t\t++sc$rejects;\n\t\t}\n\t\n\tif ( sc$total >= spam_threshold )\n\t\t{\n\t\tlocal percent = (sc$rejects*100) \/ sc$total;\n\t\tlocal host = c$id$orig_h;\n\t\tif ( percent >= spam_percent && \n\t\t\t host !in notified_reject_spammers )\n\t\t\t{\n\t\t\tlocal notice_type = SMTP_PossibleSpam;\n@ifdef ( local_mail )\n\t\t\tif ( host in local_mail )\n\t\t\t\tnotice_type = SMTP_StrangeRejectBehavior;\n@endif\n\t\t\tNOTICE([$note=notice_type,\n\t\t\t $msg=fmt(\"%s is having a large number of attempted recipients rejected\", host),\n\t\t\t $sub=fmt(\"attempted: %d rejected: %d percent\",\n\t\t\t sc$total, percent),\n\t\t\t $conn=c]);\n\t\t\t\n\t\t\tadd notified_reject_spammers[host];\n\t\t\t}\n\t\t}\n\t}\n","old_contents":"# For the SMTP_StrangeRejectBehavior notice to work, you must define a \n# local_mail table listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n\trejects: count;\n\ttotal: count;\n};\n\nexport {\n\t# The idea for this is that if a host makes more than spam_threshold \n\t# smtp connections per hour of which at least spam_percent of those are\n\t# rejected and the host is not a known mail sending host, then it's likely \n\t# sending spam or viruses.\n\t#\n\tconst spam_threshold = 300 &redef;\n\tconst spam_percent = 30 &redef;\n\t\n\t# These are smtp status codes that are considered \"rejected\".\n\tconst smtp_reject_codes: set[count] = {\n\t\t501, # Bad sender address syntax\n\t\t550, # Requested action not taken: mailbox unavailable\n\t\t551, # User not local; please try \n\t\t553, # Requested action not taken: mailbox name not allowed\n\t\t554, # Transaction failed\n\t};\n\t\n\tredef enum Notice += {\n\t\tSMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n\t\tSMTP_PossibleInternalSpam, # Internal host seems to be spamming\n\t\tSMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n\t};\n\t\n\t# This variable keeps track of the number of rejected and accepted \n\t# RCPT TO's a host is doing and receiving per hour.\n\tglobal reject_counter: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tif ( c$id$orig_h !in reject_counter ) \n\t\treject_counter[c$id$orig_h] = [$rejects=0, $total=0];\n\t\n\t# Set the smtp_counter to the local var \"foo\"\n\tlocal foo = reject_counter[c$id$orig_h];\n\t\n\tif ( code in smtp_reject_codes)\n\t\t++foo$rejects;\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in cmd )\n\t\t++foo$total;\n\t\n\tlocal host = c$id$orig_h;\n\tif ( foo$total >= spam_threshold ) \n\t\t{\n\t\tlocal percent = (foo$rejects*100) \/ foo$total;\n\t\tif ( percent >= spam_percent ) \n\t\t\t{\n@ifdef ( local_mail )\n\t\t\tif ( host in local_mail )\n\t\t\t\tNOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n\t\t\telse \n@endif\n\t\t\tif ( is_local_addr(host) ) \n\t\t\t\tNOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n\t\t\telse \n\t\t\t\tNOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n\t\t\t}\n\t\t}\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"4cbaa2830254b9c6cfffefe31c3cda51e4d15104","subject":"Creates __load__ for proper module loading","message":"Creates __load__ for proper module loading","repos":"mocyber\/rock-scripts","old_file":"protocols\/pop3\/__load__.bro","new_file":"protocols\/pop3\/__load__.bro","new_contents":"@load .\/main.bro\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'protocols\/pop3\/__load__.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"47bb18634cf0e4c07172e1d532e7ca0e639cbff0","subject":"stats get written once per worker.. need to fix","message":"stats get written once per worker.. need to fix\n\nfor now, just don't synchronize\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"metrics.smtp-ext.bro","new_file":"metrics.smtp-ext.bro","new_contents":"#output something like this\n#smtp_metrics time=1261506588.216565 total=54 inbound=49 outbound=5 inbound_err=17 outbound_err=0\n\n@load global-ext\n@load smtp-ext\n\nexport {\n global smtp_metrics: table[string] of count &default=0; #&synchronized;\n global smtp_metrics_interval = +60sec;\n const smtp_metrics_log = open_log_file(\"smtp-ext-metrics\");\n}\n\nevent smtp_write_stats()\n {\n if (smtp_metrics[\"total\"]!=0)\n {\n print smtp_metrics_log, fmt(\"smtp_metrics time=%.6f total=%d inbound=%d outbound=%d inbound_err=%d outbound_err=%d\",\n network_time(),\n smtp_metrics[\"total\"],\n smtp_metrics[\"inbound\"],\n smtp_metrics[\"outbound\"],\n smtp_metrics[\"inbound_err\"],\n smtp_metrics[\"outbound_err\"]);\n clear_table(smtp_metrics);\n }\n schedule smtp_metrics_interval { smtp_write_stats() };\n }\n\nevent bro_init()\n {\n set_buf(smtp_metrics_log, F);\n schedule smtp_metrics_interval { smtp_write_stats() };\n }\n\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info) &priority=-10\n {\n ++smtp_metrics[\"total\"];\n if(is_local_addr(id$orig_h))\n {\n ++smtp_metrics[\"outbound\"];\n if(si$last_reply!=\"\")\n ++smtp_metrics[\"outbound_err\"];\n }\n else\n {\n ++smtp_metrics[\"inbound\"];\n if(si$last_reply!=\"\")\n ++smtp_metrics[\"inbound_err\"];\n }\n }\n\n","old_contents":"#output something like this\n#smtp_metrics time=1261506588.216565 total=54 inbound=49 outbound=5 inbound_err=17 outbound_err=0\n\n@load global-ext\n@load smtp-ext\n\nexport {\n global smtp_metrics: table[string] of count &default=0 &synchronized;\n global smtp_metrics_interval = +60sec;\n const smtp_metrics_log = open_log_file(\"smtp-ext-metrics\");\n}\n\nevent smtp_write_stats()\n {\n if (smtp_metrics[\"total\"]!=0)\n {\n print smtp_metrics_log, fmt(\"smtp_metrics time=%.6f total=%d inbound=%d outbound=%d inbound_err=%d outbound_err=%d\",\n network_time(),\n smtp_metrics[\"total\"],\n smtp_metrics[\"inbound\"],\n smtp_metrics[\"outbound\"],\n smtp_metrics[\"inbound_err\"],\n smtp_metrics[\"outbound_err\"]);\n clear_table(smtp_metrics);\n }\n schedule smtp_metrics_interval { smtp_write_stats() };\n }\n\nevent bro_init()\n {\n set_buf(smtp_metrics_log, F);\n schedule smtp_metrics_interval { smtp_write_stats() };\n }\n\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info) &priority=-10\n {\n ++smtp_metrics[\"total\"];\n if(is_local_addr(id$orig_h))\n {\n ++smtp_metrics[\"outbound\"];\n if(si$last_reply!=\"\")\n ++smtp_metrics[\"outbound_err\"];\n }\n else\n {\n ++smtp_metrics[\"inbound\"];\n if(si$last_reply!=\"\")\n ++smtp_metrics[\"inbound_err\"];\n }\n }\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"71e0d0d7ff32b5761fb7e3c4c78d9bfc2cb1eea9","subject":"Update ja3.bro","message":"Update ja3.bro\n\nFixed issue #20","repos":"salesforce\/ja3","old_file":"bro\/ja3.bro","new_file":"bro\/ja3.bro","new_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n# LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","old_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n# LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"17605d302b9fdf6586b404ad9f532c8314bc2041","subject":"Create __load__.bro","message":"Create __load__.bro","repos":"theflakes\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,kingtuna\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/intel-extensions\/seen\/__load__.bro","new_file":"bro-scripts\/intel-extensions\/seen\/__load__.bro","new_contents":"@load .\/ftp-username\n@load .\/radius-username\n@load .\/smtp-subject\n@load .\/ssl-certificates\n@load .\/conn-udp-icmp\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/intel-extensions\/seen\/__load__.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"0864c0cd66952d5d8ac61d050ce675127d6bf4df","subject":"fix logging selection","message":"fix logging selection\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logging = Outbound &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", logging, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !orig_matches_direction(c$id$resp_h, logging) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", info$c$id$orig_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logging = All &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", logging, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !resp_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", info$c$id$orig_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"65c67ab83f3613d30f4b5363603b0bbaa5e0cf9c","subject":"Disable debug mode.","message":"Disable debug mode.\n","repos":"FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,FrozenCaribou\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti","old_file":"bro\/scripts\/bro\/hilti\/base\/main.bro","new_file":"bro\/scripts\/bro\/hilti\/base\/main.bro","new_contents":"\nmodule Hilti;\n\nexport {\n\t## Dump debug information about analyzers to stderr (for debugging only). \n\tconst dump_debug = F &redef;\n\n\t## Dump generated HILTI\/BinPAC++ code to stderr (for debugging only).\n\tconst dump_code = F &redef;\n\n\t## Dump generated HILTI\/BinPAC++ code to stderr before finalizing the modules. (for\n\t## debugging only). \n\tconst dump_code_pre_finalize = F &redef;\n\n\t## Dump all HILTI\/BinPAC++ code to stderr (for debugging only).\n\tconst dump_code_all = F &redef;\n\n\t## Disable code verification (for debugging only).\n\tconst no_verify = F &redef;\n\n\t## Generate code for all events no matter if they have a handler\n\t## defined or not.\n\tconst compile_all = F &redef;\n\n\t## Enable debug mode for code generation.\n\tconst debug = F &redef;\n\n\t## Enable optimization for code generation.\n\tconst optimize = F &redef;\n\n\t## Profiling level for code generation.\n\tconst profile = 0 &redef;\n\n\t## Tags for codegen debug output as colon-separated string.\n\tconst cg_debug = \"\" &redef;\n\n\t## Save all generated BinPAC++ modules into \"bro..pac2\"\n\tconst save_pac2 = F &redef;\n\n\t## Save all HILTI modules into \"bro..hlt\"\n\tconst save_hilti = F &redef;\n\n\t## Save final linked LLVM assembly into \"bro.ll\"\n\tconst save_llvm = F &redef;\n\n\t## Use on-disk cache for compiled modules.\n\tconst use_cache = T &redef;\n\n\t## Activate the Bro script compiler.\n\tconst compile_scripts = F &redef;\n}\n\n\n","old_contents":"\nmodule Hilti;\n\nexport {\n\t## Dump debug information about analyzers to stderr (for debugging only). \n\tconst dump_debug = F &redef;\n\n\t## Dump generated HILTI\/BinPAC++ code to stderr (for debugging only).\n\tconst dump_code = F &redef;\n\n\t## Dump generated HILTI\/BinPAC++ code to stderr before finalizing the modules. (for\n\t## debugging only). \n\tconst dump_code_pre_finalize = F &redef;\n\n\t## Dump all HILTI\/BinPAC++ code to stderr (for debugging only).\n\tconst dump_code_all = F &redef;\n\n\t## Disable code verification (for debugging only).\n\tconst no_verify = F &redef;\n\n\t## Generate code for all events no matter if they have a handler\n\t## defined or not.\n\tconst compile_all = F &redef;\n\n\t## Enable debug mode for code generation.\n\tconst debug = T &redef;\n\n\t## Enable optimization for code generation.\n\tconst optimize = F &redef;\n\n\t## Profiling level for code generation.\n\tconst profile = 0 &redef;\n\n\t## Tags for codegen debug output as colon-separated string.\n\tconst cg_debug = \"\" &redef;\n\n\t## Save all generated BinPAC++ modules into \"bro..pac2\"\n\tconst save_pac2 = F &redef;\n\n\t## Save all HILTI modules into \"bro..hlt\"\n\tconst save_hilti = F &redef;\n\n\t## Save final linked LLVM assembly into \"bro.ll\"\n\tconst save_llvm = F &redef;\n\n\t## Use on-disk cache for compiled modules.\n\tconst use_cache = T &redef;\n\n\t## Activate the Bro script compiler.\n\tconst compile_scripts = F &redef;\n}\n\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1dd199e21644a395dad6ac7412a6ed6d0c5c6e10","subject":"Fixed an issue where the start directory after login is unknown in ftp-ext","message":"Fixed an issue where the start directory after login is unknown in ftp-ext\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ftp-ext.bro","new_file":"ftp-ext.bro","new_contents":"@load global-ext\n\n@load ftp\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_log = open_log_file(\"ftp-ext\") &raw_output;\n\t\n\ttype ftp_ext_session_info: record {\n\t\turl: string &default=\"\";\n\t\tpassword: string &default=\"\";\n\t\tmimetype: string &default=\"\";\n\t};\n\t\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &write_expire=1min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal blah: ftp_ext_session_info;\n\treturn blah;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\t\n\tlocal sess = ftp_sessions[c$id];\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\tlocal userpass = ( sess$user == \/^(anonymous|ftp)$\/ ) ?\n\t\t\t\t\t\t\tfmt(\"%s:%s\", sess$user, sess_ext$password) :\n\t\t\t\t\t\t\tsess$user;\n\t\tlocal pathfile = sub(absolute_path(sess, arg), \/\/, \"\/.\");\n\t\tsess_ext$url = fmt(\"ftp:\/\/%s@%s%s\", userpass, c$id$resp_h, pathfile);\n\t\tprint ftp_ext_log, cat_sep(\"\\t\", \"\\\\N\",\n\t\t\t\t\t\tsess$request_t,\n\t\t\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\t\t\tcommand, sess_ext$url);\n\t\t}\n\t}\n\t\nevent ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n\t{\n\t#TODO: include reply in logged message\n\tlocal reply = \"\";\n\tif ( code in ftp_replies )\n\t\t reply = ftp_replies[code];\n\t}\n","old_contents":"@load global-ext\n\n@load ftp\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_log = open_log_file(\"ftp-ext\") &raw_output;\n\t\n\ttype ftp_ext_session_info: record {\n\t\turl: string &default=\"\";\n\t\tpassword: string &default=\"\";\n\t\tmimetype: string &default=\"\";\n\t};\n\t\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &write_expire=1min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal blah: ftp_ext_session_info;\n\treturn blah;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\t\n\tlocal sess = ftp_sessions[c$id];\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\tlocal userpass = ( \/^(anonymous|ftp)$\/ in sess$user ) ?\n\t\t\t\t\t\t\tfmt(\"%s:%s\", sess$user, sess_ext$password) :\n\t\t\t\t\t\t\tsess$user;\n\t\tsess_ext$url = fmt(\"ftp:\/\/%s@%s%s\", userpass, c$id$resp_h, absolute_path(sess, arg));\n\t\tprint ftp_ext_log, cat_sep(\"\\t\", \"\\\\N\",\n\t\t\t\t\t\tsess$request_t,\n\t\t\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\t\t\tcommand, sess_ext$url);\n\t\t}\n\t}\n\t\nevent ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n\t{\n\t#TODO: include reply in logged message\n\tlocal reply = \"\";\n\tif ( code in ftp_replies )\n\t\t reply = ftp_replies[code];\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"39194c84a9f8a61340bba28c718f60b99976c4fe","subject":"Forced logging should work with client and server requests now. Bug reported by Justin Azoff.","message":"Forced logging should work with client and server requests now. Bug reported by Justin Azoff.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"logging.http-ext.bro","new_file":"logging.http-ext.bro","new_contents":"@load global-ext\n@load http-ext\n\nmodule HTTP;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = T &redef;\n\t\n\t# Which http transactions to log.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n\t\n\t# This is list of subnets containing web servers that you'd like to log their\n\t# traffic regardless of the \"logging\" variable.\n\t# The string value is a description of the subnet and why it was included.\n\tconst always_log: table[subnet] of string &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"http-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"http-ext\", cat_sep(\"\\t\", \"\\\\N\",\n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"force_log_reasons\",\n\t \"method\", \"url\", \"referrer\",\n\t \"user_agent\", \"proxied_for\"));\n\t\n\t# Set this log to always accept output because the POST logging\n\t# must be specifically enabled per-request anyway.\n\tLOG::create_logs(\"http-client-body\", All, split_log_file, T);\n\tLOG::define_header(\"http-client-body\", cat_sep(\"\\t\", \"\\\\N\",\n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"force_log_reasons\", \"method\",\n\t \"url\", \"user_agent\", \"referrer\",\n\t \"client_body\"));\n\t}\n\nevent http_ext(id: conn_id, si: http_ext_session_info)\n\t{\n\tif ( id$resp_h in always_log )\n\t\t{\n\t\tsi$force_log = T;\n\t\tadd si$force_log_reasons[fmt(\"server_in_logged_subnet_%s\", always_log[id$resp_h])];\n\t\t}\n\t\t\n\tif ( id$orig_h in always_log )\n\t\t{\n\t\tsi$force_log = T;\n\t\tadd si$force_log_reasons[fmt(\"client_in_logged_subnet_%s\", always_log[id$orig_h])];\n\t\t}\n\n\tlocal log = LOG::get_file(\"http-ext\", id$resp_h, si$force_log);\n\tprint log, cat_sep(\"\\t\", \"\\\\N\",\n\t si$start_time,\n\t id$orig_h, port_to_count(id$orig_p),\n\t id$resp_h, port_to_count(id$resp_p),\n\t fmt_str_set(si$force_log_reasons, \/DONTMATCH\/),\n\t si$method, si$url, si$referrer,\n\t si$user_agent, si$proxied_for);\n\t}\n\n# This is coming, I just need to figure out to get get_file to\n# accept either a Hosts enum value or a Directions enum value.\n#event http_ext(id: conn_id, si: http_ext_session_info)\n#\t{\n#\tlocal log = LOG::get_file(\"http-ext-user-agents\", id$orig_h, T);\n#\tprint log, cat_sep(\"\\t\", \"\\\\N\", id$orig_h, si$user_agent);\n#\t}\n\n# This is for logging POST contents during suspicious POSTs.\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in HTTP::conn_info )\n\t\treturn;\n\t\n\tlocal si = HTTP::conn_info[c$id];\n\t\n\t# This shouldn't really be done in the logging script, but it avoids\n\t# needing to handle the http_entity_data event twice.\n\tif ( suspicious_http_posts in data )\n\t\t{\n\t\tsi$force_log_client_body = T;\n\t\tadd si$force_log_reasons[\"suspicious_client_body\"];\n\t\t}\n\n\tif ( si$force_log_client_body )\n\t\t{\n\t\tlocal log = LOG::get_file(\"http-client-body\", c$id$resp_h, T);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\",\n\t\t si$start_time,\n\t\t c$id$orig_h, port_to_count(c$id$orig_p),\n\t\t c$id$resp_h, port_to_count(c$id$resp_p),\n\t\t fmt_str_set(si$force_log_reasons, \/DONTMATCH\/),\n\t\t si$method,\n\t\t si$url,\n\t\t si$user_agent,\n\t\t si$referrer,\n\t\t data);\n\t\t\n\t\t# Stop logging the client body. The log file fills up like crazy \n\t\t# in some cases if we don't stop this. If another chuck of data\n\t\t# is detected as loggable later, it will be reenabled anyway.\n\t\tsi$force_log_client_body=F;\n\t\t}\n\t}\n","old_contents":"@load global-ext\n@load http-ext\n\nmodule HTTP;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = T &redef;\n\t\n\t# Which http transactions to log.\n\t# Choices are: Inbound, Outbound, All\n\tconst logging = All &redef;\n\t\n\t# This is list of subnets containing web servers that you'd like to log their\n\t# traffic regardless of the \"logging\" variable.\n\t# The string value is a description of the subnet and why it was included.\n\tconst always_log: table[subnet] of string &redef;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"http-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"http-ext\", cat_sep(\"\\t\", \"\\\\N\",\n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"force_log_reasons\",\n\t \"method\", \"url\", \"referrer\",\n\t \"user_agent\", \"proxied_for\"));\n\t\n\t# Set this log to always accept output because the POST logging\n\t# must be specifically enabled per-request anyway.\n\tLOG::create_logs(\"http-client-body\", All, split_log_file, T);\n\tLOG::define_header(\"http-client-body\", cat_sep(\"\\t\", \"\\\\N\",\n\t \"ts\",\n\t \"orig_h\", \"orig_p\",\n\t \"resp_h\", \"resp_p\",\n\t \"force_log_reasons\", \"method\",\n\t \"url\", \"user_agent\", \"referrer\",\n\t \"client_body\"));\n\t}\n\nevent http_ext(id: conn_id, si: http_ext_session_info)\n\t{\n\tif ( id$resp_h in always_log || id$orig_h in always_log )\n\t\t{\n\t\tsi$force_log = T;\n\t\tadd si$force_log_reasons[fmt(\"server_in_logged_subnet_%s\", always_log[id$resp_h])];\n\t\t}\n\n\tlocal log = LOG::get_file(\"http-ext\", id$resp_h, si$force_log);\n\tprint log, cat_sep(\"\\t\", \"\\\\N\",\n\t si$start_time,\n\t id$orig_h, port_to_count(id$orig_p),\n\t id$resp_h, port_to_count(id$resp_p),\n\t fmt_str_set(si$force_log_reasons, \/DONTMATCH\/),\n\t si$method, si$url, si$referrer,\n\t si$user_agent, si$proxied_for);\n\t}\n\n# This is coming, I just need to figure out to get get_file to\n# accept either a Hosts enum value or a Directions enum value.\n#event http_ext(id: conn_id, si: http_ext_session_info)\n#\t{\n#\tlocal log = LOG::get_file(\"http-ext-user-agents\", id$orig_h, T);\n#\tprint log, cat_sep(\"\\t\", \"\\\\N\", id$orig_h, si$user_agent);\n#\t}\n\n# This is for logging POST contents during suspicious POSTs.\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( !is_orig ) return;\n\n\tif ( c$id !in HTTP::conn_info )\n\t\treturn;\n\t\n\tlocal si = HTTP::conn_info[c$id];\n\t\n\t# This shouldn't really be done in the logging script, but it avoids\n\t# needing to handle the http_entity_data event twice.\n\tif ( suspicious_http_posts in data )\n\t\t{\n\t\tsi$force_log_client_body = T;\n\t\tadd si$force_log_reasons[\"suspicious_client_body\"];\n\t\t}\n\n\tif ( si$force_log_client_body )\n\t\t{\n\t\tlocal log = LOG::get_file(\"http-client-body\", c$id$resp_h, T);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\",\n\t\t si$start_time,\n\t\t c$id$orig_h, port_to_count(c$id$orig_p),\n\t\t c$id$resp_h, port_to_count(c$id$resp_p),\n\t\t fmt_str_set(si$force_log_reasons, \/DONTMATCH\/),\n\t\t si$method,\n\t\t si$url,\n\t\t si$user_agent,\n\t\t si$referrer,\n\t\t data);\n\t\t\n\t\t# Stop logging the client body. The log file fills up like crazy \n\t\t# in some cases if we don't stop this. If another chuck of data\n\t\t# is detected as loggable later, it will be reenabled anyway.\n\t\tsi$force_log_client_body=F;\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"6ce1dcb80d164b0f843fe69600fe99c0653475dd","subject":"multiple fixes and cleanups","message":"multiple fixes and cleanups\n\n* make the phish keywords redefinable\n* allow from addresses to be ignored\n* log subjects\n* only generate a notice once\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-phish-passwords.bro","new_file":"smtp-ext-phish-passwords.bro","new_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &write_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s\", si$mailfrom, to),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n if(++(phishing_counter[si$mailfrom]) > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","old_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &write_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_threshold = 50;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(\/[pP][aA][sS][sS][wW][oO][rR][dD]\/ in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s\", si$mailfrom, to),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(++(phishing_counter[si$mailfrom]) > phishing_threshold){\n if(si$reply_to != \"\")\n add phishing_reply_tos[si$reply_to];\n else \n add phishing_reply_tos[si$mailfrom];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing\", si$mailfrom, si$reply_to),\n $sub=si$mailfrom\n ]);\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"5d9b7d65fef72aae71782149be90846c41e71269","subject":"Fixed the problem with the header not being printed upon file rotation. Add a function named \"buffer\" to enable and disable the buffering for a log type.","message":"Fixed the problem with the header not being printed upon file rotation.\nAdd a function named \"buffer\" to enable and disable the buffering for a log type.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"logging-ext.bro","new_file":"logging-ext.bro","new_contents":"module LOG;\n\nexport {\n\t# The record type to store logging information.\n\ttype log_info: record {\n\t\tdirection: Direction &default=All;\n\t\tsplit: bool &default=F;\n\t\traw_output: bool &default=F;\n\t\theader: string &default=\"\";\n\t\tlog: file &optional;\n\t\toutbound_log: file &optional;\n\t\tinbound_log: file &optional;\n\t};\n\t\n\t# Where the data for knowing how to log is stored.\n\tconst logs: table[string] of log_info &redef;\n\n\t# Utility functions\n\tglobal choose: function(a: string, server: addr): file;\n\tglobal open_log_files: function(a: string);\n\tglobal create_logs: function(a: string, d: Direction, split: bool, raw: bool);\n\tglobal define_header: function(a: string, h: string);\n\tglobal buffer: function(a: string, setit: bool);\n\t\n\t# This is dumb, but it helps avoid needing to duplicate code on the\n\t# printing side.\n\tconst null_file: file = open_log_file(\"null\");\n}\n\nfunction choose(a: string, server: addr): file\n\t{\n\tlocal i = logs[a];\n\tif ( ! resp_matches_direction(server, i$direction) )\n\t\treturn LOG::null_file;\n\t\t\n\tif ( i$split )\n\t\t{\n\t\tif ( is_local_addr(server) )\n\t\t\treturn i$inbound_log;\n\t\telse\n\t\t\treturn i$outbound_log;\n\t\t}\n\telse\n\t\t{\n\t\treturn i$log;\n\t\t}\n\t}\n\t\nfunction buffer(a: string, setit: bool)\n\t{\n\tlocal i = logs[a];\n\t\n\tif ( i$split )\n\t\t{\n\t\tset_buf(i$inbound_log, setit);\n\t\tset_buf(i$outbound_log, setit);\n\t\t}\n\telse\n\t\t{\n\t\tset_buf(i$log, setit);\n\t\t}\n\t}\n\n# TODO: remove the print and uncomment the file_opened event below\n# when bro has the file_opened event. this is broken until then\n# because file rotation does not reprint the header.\nfunction open_log_files(a: string)\n\t{\n\tlocal i = logs[a];\n\tif ( i$direction == None ) return;\n\t\n\tif ( i$split )\n\t\t{\n\t\ti$inbound_log = open_log_file(cat(a,\"-inbound\"));\n\t\ti$outbound_log = open_log_file(cat(a,\"-outbound\"));\n\t\tif ( i$raw_output )\n\t\t\t{\n\t\t\tenable_raw_output(i$inbound_log);\n\t\t\tenable_raw_output(i$outbound_log);\n\t\t\t}\n\t\tprint i$inbound_log, i$header;\n\t\tprint i$outbound_log, i$header;\n\t\t}\n\telse\n\t\t{\n\t\ti$log = open_log_file(a);\n\t\tif ( i$raw_output )\n\t\t\t{\n\t\t\tenable_raw_output(i$log);\n\t\t\t}\n\t\tprint i$log, i$header;\n\t\t}\n\t}\n\nfunction create_logs(a: string, d: Direction, split: bool, raw: bool)\n\t{\n\tlogs[a] = [$direction=d, $split=split, $raw_output=raw];\n\t}\n\t\nfunction define_header(a: string, h: string)\n\t{\n\tlocal i = logs[a];\n\ti$header = h;\n\t}\n\n#event file_opened(f: file) &priority=10\nevent rotate_interval(f: file) &priority=-1\n\t{\n\tlocal fn = get_file_name(f);\n\t# TODO: make this not depend on the file extension being .log\n\tlocal log_type = gsub(fn, \/(-(in|out)bound)?\\.log$\/, \"\");\n\tprint log_type;\n\tif ( log_type in logs )\n\t\t{\n\t\tlocal i = logs[log_type];\n\t\tif ( i$header != \"\" )\n\t\t\tprint f, i$header;\n\t\t}\n\t}\n\n# This is a hack. The null file is used as \/dev\/null by all\n# scripts using the logging framework. The file needs to be\n# closed so that nothing is ever written to it.\n# TODO: change this when a better method for not printing\n# is created.\nevent bro_init()\n\t{\n\tclose(null_file);\n\t}\n\nevent bro_init() &priority=-10\n\t{\n\tlocal d = set(Inbound,Outbound,All,None);\n\tfor ( lt in logs )\n\t\t{\n\t\t# This doesn't work for some reason.\n\t\t#if ( logs[lt]$direction !in d )\n\t\t#\tprint fmt(\"Invalid direction chosen for %s\", lt);\n\t\t\n\t\t# Open the appropriate log files.\n\t\topen_log_files(lt);\n\t\t}\n\t}\n","old_contents":"module LOG;\n\nexport {\n\t# The record type to store logging information.\n\ttype log_info: record {\n\t\tdirection: Direction &default=All;\n\t\tsplit: bool &default=F;\n\t\traw_output: bool &default=F;\n\t\theader: string &default=\"\";\n\t\tlog: file &optional;\n\t\toutbound_log: file &optional;\n\t\tinbound_log: file &optional;\n\t};\n\t\n\t# Where the data for knowing how to log is stored.\n\tconst logs: table[string] of log_info &redef;\n\n\t# Utility functions\n\tglobal choose: function(a: string, server: addr): file;\n\tglobal open_log_files: function(a: string);\n\tglobal create_logs: function(a: string, d: Direction, split: bool, raw: bool);\n\tglobal define_header: function(a: string, h: string);\n\n\t# This is dumb, but it helps avoid needing to duplicate code on the\n\t# printing side.\n\tconst null_file: file = open_log_file(\"null\");\n}\n\nfunction choose(a: string, server: addr): file\n\t{\n\tlocal i = logs[a];\n\tif ( ! resp_matches_direction(server, i$direction) )\n\t\treturn LOG::null_file;\n\t\t\n\tif ( i$split )\n\t\t{\n\t\tif ( is_local_addr(server) )\n\t\t\treturn i$inbound_log;\n\t\telse\n\t\t\treturn i$outbound_log;\n\t\t}\n\telse\n\t\t{\n\t\treturn i$log;\n\t\t}\n\t}\n\n# TODO: remove the print and uncomment the file_opened event below\n# when bro has the file_opened event. this is broken until then\n# because file rotation does not reprint the header.\nfunction open_log_files(a: string)\n\t{\n\tlocal i = logs[a];\n\tif ( i$direction == None ) return;\n\t\n\tif ( i$split )\n\t\t{\n\t\ti$inbound_log = open_log_file(cat(a,\"-inbound\"));\n\t\ti$outbound_log = open_log_file(cat(a,\"-outbound\"));\n\t\tif ( i$raw_output )\n\t\t\t{\n\t\t\tenable_raw_output(i$inbound_log);\n\t\t\tenable_raw_output(i$outbound_log);\n\t\t\t}\n\t\tprint i$inbound_log, i$header;\n\t\tprint i$outbound_log, i$header;\n\t\t}\n\telse\n\t\t{\n\t\ti$log = open_log_file(a);\n\t\tif ( i$raw_output )\n\t\t\t{\n\t\t\tenable_raw_output(i$log);\n\t\t\t}\n\t\tprint i$log, i$header;\n\t\t}\n\t}\n\nfunction create_logs(a: string, d: Direction, split: bool, raw: bool)\n\t{\n\tlogs[a] = [$direction=d, $split=split, $raw_output=raw];\n\t}\n\t\nfunction define_header(a: string, h: string)\n\t{\n\tlocal i = logs[a];\n\ti$header = h;\n\t}\n\n#event file_opened(f: file) &priority=10\nevent rotate_interval(f: file) &priority=-1\n\t{\n\tlocal fn = get_file_name(f);\n\tlocal log_type = gsub(fn, \/-(in|out)bound\/, \"\");\n\tif ( log_type in logs )\n\t\t{\n\t\tlocal i = logs[log_type];\n\t\tif ( i$header != \"\" )\n\t\t\tprint f, i$header;\n\t\t}\n\t}\n\n# This is a hack. The null file is used as \/dev\/null by all\n# scripts using the logging framework. The file needs to be\n# closed so that nothing is ever written to it.\n# TODO: change this when a better method for not printing\n# is created.\nevent bro_init()\n\t{\n\tclose(null_file);\n\t}\n\nevent bro_init() &priority=-10\n\t{\n\tlocal d = set(Inbound,Outbound,All,None);\n\tfor ( lt in logs )\n\t\t{\n\t\t# This doesn't work for some reason.\n\t\t#if ( logs[lt]$direction !in d )\n\t\t#\tprint fmt(\"Invalid direction chosen for %s\", lt);\n\t\t\n\t\t# Open the appropriate log files.\n\t\topen_log_files(lt);\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"48930ba9e73779b245ef9f0ee8c49f143f003460","subject":"metrics policy that logs the number of active hosts on the network","message":"metrics policy that logs the number of active hosts on the network\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"active-hosts-metrics.bro","new_file":"active-hosts-metrics.bro","new_contents":"module Active;\n@load base\/frameworks\/metrics\n\nredef enum Metrics::ID += {\n ACTIVE_HOSTS,\n};\n\nexport {\n global active_hosts: set[addr] &create_expire=1hr &synchronized &redef;\n const host_tracking = LOCAL_HOSTS &redef;\n}\n\nevent bro_init()\n{\n Metrics::add_filter(ACTIVE_HOSTS,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n}\n\nevent connection_established(c: connection)\n{\n #taken from known-hosts.bro\n #I don't want to count incoming scans or anything, so just count outgoing conns.\n local host = c$id$orig_h;\n if ( host !in active_hosts && \n c$orig$state == TCP_ESTABLISHED &&\n c$resp$state == TCP_ESTABLISHED &&\n addr_matches_host(host, host_tracking) )\n {\n add active_hosts[host];\n Metrics::add_data(ACTIVE_HOSTS, [$str=\"hosts\"], 1);\n }\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'active-hosts-metrics.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"3e8f0db463a21efcc8a238120730008940daab14","subject":"ssl-ext uses the logging framework now.","message":"ssl-ext uses the logging framework now.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-ext.bro","new_file":"ssl-ext.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\t# If set to T, this will split inbound and outbound transactions\n\t# into separate files. F merges everything into a single file.\n\tconst split_log_file = F &redef;\n\t\n\t# Which SSH logins to record.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts, NoHosts\n\tconst logging = AllHosts &redef;\n\t\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"ssl-ext\", logging, split_log_file, T);\n\tLOG::define_header(\"ssl-ext\", cat_sep(\"\\t\", \"\\\\N\",\n\t \"ts\",\n\t \"host\", \"port\",\n\t \"cert_subject\"));\n\t}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tif ( is_server )\n\t\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logging) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\t\n\t\tlocal log = LOG::get_file_by_addr(\"ssl-ext\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(),\n\t\t c$id$resp_h, port_to_count(c$id$resp_p), \n\t\t cert$subject);\n\t\t}\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst log = open_log_file(\"ssl-ext\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst logged_hosts = LocalHosts &redef;\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\t\t}\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"55023726f1af5ab7b963c420d296174d52ac51fe","subject":"Modified name of KnownCerts module to SSL_KnownCerts.","message":"Modified name of KnownCerts module to SSL_KnownCerts.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst log = open_log_file(\"ssl-known-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst log_hosts: Hosts = LocalHosts &redef;\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tadd c$service[\"SSL\"];\n\t\n\tif ( !ip_matches_hosts(c$id$resp_h, log_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\t\t}\n\t}\n\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load global-ext\n@load ssl\n\nmodule KnownCerts;\n\nexport {\n\tconst log = open_log_file(\"ssl-known-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst log_hosts: Hosts = LocalHosts &redef;\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\tadd c$service[\"SSL\"];\n\t\n\tif ( !ip_matches_hosts(c$id$resp_h, log_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\t\t}\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"cc832654bb37b110c01c4baaa2220fdabc06b04f","subject":"subscribe","message":"subscribe\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_master.bro","new_file":"scripts_master\/bro_master.bro","new_contents":"@load .\/balance_log\n\n@load .\/beemaster_events\n@load .\/beemaster_log\n\n@load .\/dio_access\n@load .\/dio_download_complete\n@load .\/dio_download_offer\n@load .\/dio_ftp\n@load .\/dio_mysql_command\n@load .\/dio_login\n@load .\/dio_smb_bind\n@load .\/dio_smb_request\n@load .\/dio_blackhole.bro\n@load .\/acu_result.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\t\t\n\t\tBroker::subscribe_to_events_multi(\"acu_result\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_login::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_blackhole::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_blackhole::LOG, rec);\n}\n\nevent Beemaster::acu_result(timestamp: time, attack_type: string) {\n local rec: Acu_result::Info = [$ts=timestamp, $attack=attack_type];\n Log::write(Acu_result::LOG, rec);\n}\nevent Beemaster::tcp_event(rec: Beemaster::AlertInfo, discriminant: count) {\n Beemaster::log(\"Got tcp_event!!\");\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n Beemaster::log(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n Beemaster::log(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: BalanceLog::Info = [$connector=connector, $slave=slave];\n Log::write(BalanceLog::LOG, rec);\n}\n","old_contents":"@load .\/balance_log\n\n@load .\/beemaster_events\n@load .\/beemaster_log\n\n@load .\/dio_access\n@load .\/dio_download_complete\n@load .\/dio_download_offer\n@load .\/dio_ftp\n@load .\/dio_mysql_command\n@load .\/dio_login\n@load .\/dio_smb_bind\n@load .\/dio_smb_request\n@load .\/dio_blackhole.bro\n@load .\/acu_result.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_login::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_blackhole::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_blackhole::LOG, rec);\n}\n\nevent acu_result(timestamp: time, attack_type: string) {\n local rec: Acu_result::Info = [$ts=timestamp, $attack=attack_type];\n Log::write(Acu_result::LOG, rec);\n}\nevent Beemaster::tcp_event(rec: Beemaster::AlertInfo, discriminant: count) {\n Beemaster::log(\"Got tcp_event!!\");\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n Beemaster::log(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n Beemaster::log(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: BalanceLog::Info = [$connector=connector, $slave=slave];\n Log::write(BalanceLog::LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"06860f0c00838957ebf48cf633635f44cb4099df","subject":"Added the known-hosts script which can track and log \"seen\" local and remote hosts.","message":"Added the known-hosts script which can track and log \"seen\" local and remote hosts.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"known-hosts.bro","new_file":"known-hosts.bro","new_contents":"@load global-ext\n\nmodule KnownHosts;\n\nexport {\n\t# The hosts whose existence should be logged.\n\t# Choices are: LocalHosts, RemoteHosts, AllHosts\n\tconst logging = LocalHosts &redef;\n\t\n\t# In case you are interested in more than logging just local assets\n\t# you can split the log file.\n\tconst split_log_file = F &redef;\n\t\n\t# Maintain the list of known hosts for 24 hours so that the existence\n\t# of each individual address is logged each day.\n\tglobal known_hosts: set[addr] &create_expire=1day &synchronized &persistent;\n}\n\nevent bro_init()\n\t{\n\tLOG::create_logs(\"known-hosts\", logging, split_log_file, T);\n\tLOG::define_header(\"known-hosts\", cat_sep(\"\\t\", \"\", \"host\"));\n\t}\n\nevent connection_established(c: connection)\n\t{\n\tlocal id = c$id;\n\t\n\tlocal log:file;\n\tif ( id$orig_h !in known_hosts && addr_matches_hosts(id$orig_h, logging) )\n\t\t{\n\t\tlog = LOG::get_file_by_addr(\"known-hosts\", id$orig_h, F);\n\t\tadd known_hosts[id$orig_h];\n\t\tprint log, cat_sep(\"\\t\", \"\", id$orig_h);\n\t\t}\n\tif ( id$resp_h !in known_hosts && addr_matches_hosts(id$resp_h, logging) )\n\t\t{\n\t\tlog = LOG::get_file_by_addr(\"known-hosts\", id$resp_h, F);\n\t\tadd known_hosts[id$resp_h];\n\t\tprint log, cat_sep(\"\\t\", \"\", id$resp_h);\n\t\t}\n\t}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'known-hosts.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"82cc5d5fe00c6df042fdccbf1eb7aab420c85b19","subject":"update(untested) for 2.0","message":"update(untested) for 2.0\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ipblocker.bro","new_file":"ipblocker.bro","new_contents":"module Notice;\n\nexport {\n redef enum Action += {\n ## Indicates that the notice should be sent to ipblocker to block\n ACTION_IPBLOCKER\n };\n}\n\nevent notice(n: Notice::Info) &priority=-5\n{\n if (ACTION_IPBLOCKER !in n$actions)\n return;\n local id = n$id;\n \n # The IP to block is whichever one is not the local address.\n if(Site::is_local_addr(id$orig_h))\n local ip = id$resp_h;\n else\n local ip = id$orig_h;\n\n local cmd = fmt(\"\/usr\/local\/bin\/bro_ipblocker_block %s\", ip);\n execute_with_notice(cmd, n);\n}\n","old_contents":"function notice_exec_ipblocker(n: notice_info, a: NoticeAction): NoticeAction\n{\n local cmd = fmt(\"lckdo \/tmp\/bro_ipblocker_%s \/usr\/local\/bin\/bro_ipblocker_block %s\", n$id$orig_h, n$id$orig_h);\n execute_with_notice(cmd, n);\n email_notice_to(n, mail_dest);\n return NOTICE_ALARM_ALWAYS;\n}\n\nfunction notice_exec_ipblocker_dest(n: notice_info, a: NoticeAction): NoticeAction\n{\n local cmd = fmt(\"lckdo \/tmp\/bro_ipblocker_%s \/usr\/local\/bin\/bro_ipblocker_block %s\", n$id$resp_h, n$id$resp_h);\n execute_with_notice(cmd, n);\n email_notice_to(n, mail_dest);\n return NOTICE_ALARM_ALWAYS;\n}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f2e5016c9d30b86a41349b6cbaabe26f7644e58b","subject":"is_local_addr is under Site:: now","message":"is_local_addr is under Site:: now\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"rogue-access-points.bro","new_file":"rogue-access-points.bro","new_contents":"@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nexport {\n\tredef enum Notice::Type += { \n\t\tRogue_Access_Point\n\t};\n\n const mobile_browsers =\n \/i(Phone|Pod|Pad)\/ |\n \/Android\/ &redef;\n\n const wireless_nets: set[subnet] &redef;\n global rogue_access_points : set[addr] &redef;\n}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=2\n{\n if (!is_orig )\n return;\n local ip = c$id$orig_h;\n\n if (!Site::is_local_addr(ip) || ip in wireless_nets || ip in rogue_access_points)\n return;\n\n if ( name == \"USER-AGENT\" && mobile_browsers in value){\n local message = \"Rogue access point detected\";\n local submessage = value;\n NOTICE([$note=Rogue_Access_Point, $msg=message, $sub=submessage,\n $id=c$id]);\n add rogue_access_points[ip];\n }\n}\n","old_contents":"@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nexport {\n\tredef enum Notice::Type += { \n\t\tRogue_Access_Point\n\t};\n\n const mobile_browsers =\n \/i(Phone|Pod|Pad)\/ |\n \/Android\/ &redef;\n\n const wireless_nets: set[subnet] &redef;\n global rogue_access_points : set[addr] &redef;\n}\n\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=2\n{\n if (!is_orig )\n return;\n local ip = c$id$orig_h;\n\n if (!is_local_addr(ip) || ip in wireless_nets || ip in rogue_access_points)\n return;\n\n if ( name == \"USER-AGENT\" && mobile_browsers in value){\n local message = \"Rogue access point detected\";\n local submessage = value;\n NOTICE([$note=Rogue_Access_Point, $msg=message, $sub=submessage,\n $id=c$id]);\n add rogue_access_points[ip];\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"6943efcbdd12b00e9161de614fb51a9372258e59","subject":"MySQL-Log gefixt.","message":"MySQL-Log gefixt.\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dio_mysql_log.bro","new_file":"custom_scripts\/dio_mysql_log.bro","new_contents":"module Dio_mysql;\n\nexport {\n redef enum Log::ID += { LOG };\n \n type Info: record {\n ts: time &log;\n id: string &log;\n local_ip: addr &log;\n local_port: port &log;\n remote_ip: addr &log; \n remote_port: port &log;\n transport: string &log;\n args: string &log;\n connector_id: string &log;\n };\n}\n\nevent bro_init() &priority=5 {\n Log::create_stream(Dio_mysql::LOG, [$columns=Info, $path=\"Dionaea_MySQL\"]); \n}\n","old_contents":"module Dio_mysql;\n\nexport {\n redef enum Log::ID += { LOG };\n \n type Info: record {\n ts: time &log;\n id: string &log;\n local_ip: addr &log;\n local_port: port &log;\n remote_ip: addr &log; \n remote_port: port &log;\n transport: string &log;\n args: string &log;\n };\n}\n\nevent bro_init() &priority=5 {\n Log::create_stream(Dio_mysql::LOG, [$columns=Info, $path=\"Dionaea_MySQL\"]); \n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"f047c2f7b54f5c60d196d71f2fd821e643a6838b","subject":"Fixed a problem with the command being set incorrectly when the ftp_ext event fires.","message":"Fixed a problem with the command being set incorrectly when the ftp_ext event fires.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ftp-ext.bro","new_file":"ftp-ext.bro","new_contents":"@load global-ext\n@load ftp\n\ntype ftp_ext_session_info: record {\n\tusername: string &default=\"\";\n\tpassword: string &default=\"\";\n\trequest_t: time &optional;\n\turl: string &default=\"\";\n\tcommand: string &default=\"\";\n\treply_code: count &default=0;\n\treply_msg: string &default=\"\";\n\t\n\t# This is internal state tracking.\n\tready: bool &default=F;\n};\n\n# Define the generic ftp-ext event that can be handled from other scripts\nglobal ftp_ext: event(id: conn_id, si: ftp_ext_session_info);\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &read_expire=5min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal x: ftp_ext_session_info;\n\treturn x;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\t# Throw the ftp_ext event if the session record is \"ready\".\n\t# This will make sure we get the last reply from the previous command.\n\tif ( sess_ext$ready )\n\t\t{\n\t\t# Copy the sess_ext variable because modifications to it can encounter\n\t\t# race conditions with the event dispatching system.\n\t\tevent ftp_ext(c$id, copy(sess_ext));\n\t\tsess_ext$ready=F;\n\t\t}\n\t\n\t# Update the session's command everytime (after potentially dispatching\n\t# the ftp_ext event).\n\tsess_ext$command = command;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\tlocal sess = ftp_sessions[c$id];\n\t\t\n\t\t# Move the request time into the ext session information\n\t\tsess_ext$request_t = sess$request_t;\n\t\t\n\t\t# If the start directory is unknown, record it as \/.\n\t\tlocal pathfile = sub(absolute_path(sess, arg), \/\/, \"\/.\");\n\t\t\n\t\tsess_ext$url = fmt(\"ftp:\/\/%s%s\", c$id$resp_h, pathfile);\n\t\t}\n\t\t\n\telse if ( command == \"USER\" )\n\t\tsess_ext$username=arg;\n\n\telse if ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t}\n\nevent ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n\t{\n\t# I'm not sure how I'd like to handle multiline responses yet.\n\tif ( cont_resp ) return;\n\t\n\tif ( c$id !in ftp_ext_sessions ) return;\n\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( sess_ext$command == \"RETR\" ||\n\t sess_ext$command == \"STOR\" )\n\t\t{\n\t\tsess_ext$reply_code = code;\n\t\tsess_ext$reply_msg = msg;\n\t\t\n\t\t# We are considering the record \"ready\" once the reply has been recorded.\n\t\tsess_ext$ready = T;\n\t\t}\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tif ( c$id in ftp_ext_sessions )\n\t\t{\n\t\tevent ftp_ext(c$id, ftp_ext_sessions[c$id]);\n\t\tdelete ftp_ext_sessions[c$id];\n\t\t}\n\t}\n\n","old_contents":"@load global-ext\n@load ftp\n\ntype ftp_ext_session_info: record {\n\tusername: string &default=\"\";\n\tpassword: string &default=\"\";\n\trequest_t: time &optional;\n\turl: string &default=\"\";\n\tcommand: string &default=\"\";\n\treply_code: count &default=0;\n\treply_msg: string &default=\"\";\n\t\n\t# This is internal state tracking.\n\tready: bool &default=F;\n};\n\n# Define the generic ftp-ext event that can be handled from other scripts\nglobal ftp_ext: event(id: conn_id, si: ftp_ext_session_info);\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &read_expire=5min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal x: ftp_ext_session_info;\n\treturn x;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\t\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\t# Throw the ftp_ext event if the session record is \"ready\".\n\t# This will make sure we get the last reply from the previous command.\n\tif ( sess_ext$ready )\n\t\t{\n\t\tevent ftp_ext(c$id, sess_ext);\n\t\tsess_ext$ready=F;\n\t\tsess_ext$command=\"\";\n\t\t}\n\t\n\tif ( command == \"USER\" )\n\t\tsess_ext$username=arg;\n\t\n\tif ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\tlocal sess = ftp_sessions[c$id];\n\t\t\n\t\t# Move the request time into the ext session information\n\t\tsess_ext$request_t = sess$request_t;\n\t\t\n\t\t# If the start directory is unknown, record it as \/.\n\t\tlocal pathfile = sub(absolute_path(sess, arg), \/\/, \"\/.\");\n\t\t\n\t\tsess_ext$url = fmt(\"ftp:\/\/%s%s\", c$id$resp_h, pathfile);\n\t\tsess_ext$command = command;\n\t\t}\n\t}\n\nevent ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n\t{\n\t# I'm not sure how I'd like to handle multiline responses yet.\n\tif ( cont_resp ) return;\n\t\n\tif ( c$id !in ftp_ext_sessions ) return;\n\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( sess_ext$command == \"RETR\" ||\n\t sess_ext$command == \"STOR\" )\n\t\t{\n\t\tsess_ext$reply_code = code;\n\t\tsess_ext$reply_msg = msg;\n\t\t\n\t\t# We are considering the record \"ready\" once the reply has been recorded.\n\t\tsess_ext$ready = T;\n\t\t}\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tif ( c$id in ftp_ext_sessions )\n\t\t{\n\t\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\tevent ftp_ext(c$id, sess_ext);\n\t\tdelete ftp_ext_sessions[c$id];\n\t\t}\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"34ba11bd10629e1ca98489a45fb084a5608f3c37","subject":"Fixed bro_slave","message":"Fixed bro_slave\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_slave\/bro_slave.bro","new_file":"scripts_slave\/bro_slave.bro","new_contents":"@load .\/beemaster_events\n@load .\/beemaster_types\n@load .\/beemaster_log\n@load .\/beemaster_util\n\n@load base\/bif\/plugins\/Bro_TCP.events.bif\n@load base\/bif\/plugins\/Bro_UDP.events.bif\n@load base\/protocols\/conn\/main\n\nredef exit_only_after_terminate = T;\n\n# Broker setup\n# the ports and IPs that are externally routable for a master and this slave\nconst slave_broker_port: string = getenv(\"SLAVE_PUBLIC_PORT\") &redef;\nconst slave_broker_ip: string = getenv(\"SLAVE_PUBLIC_IP\") &redef;\nconst master_broker_port: port = to_port(cat(getenv(\"MASTER_PUBLIC_PORT\"), \"\/tcp\")) &redef;\nconst master_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-slave-\", slave_broker_ip, \":\", slave_broker_port);\n\nglobal base_events: set[string] = { \"Beemaster::log_conn\" };\n\nglobal tcp_events: set[string] = { \"Beemaster::tcp_event\" };\n\nglobal lattice_events: set[string] = { \"Beemaster::lattice_event\"};\n\nevent bro_init() {\n Beemaster::log(\"bro_slave.bro: bro_init()\");\n\n # Enable broker and listen for incoming connectors\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Connect to bro-master for load-balancing and relaying events\n Broker::connect(master_broker_ip, master_broker_port, 1sec);\n\n # Publish our local events to forward them to master\/acus\n Broker::register_broker_events(\"beemaster\/bro\/base\", base_events);\n\n # Publish our tcp events\n Broker::register_broker_events(\"beemaster\/bro\/tcp\", tcp_events);\n\n # Publish our lattice_events\n Broker::register_broker_events(\"beemaster\/bro\/lattice\", lattice_events);\n\n Beemaster::log(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n Beemaster::log(\"bro_slave.bro: bro_done()\");\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n Beemaster::log(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n Beemaster::log(msg);\n}\n\n# forwarding when some local connection is beeing logged. Throws an explicit beemaster event to forward.\nevent Conn::log_conn(rec: Conn::Info) {\n event Beemaster::log_conn(rec);\n event Beemaster::lattice_event(Beemaster::conninfo_to_alertinfo(rec), Beemaster::proto_to_string(rec$proto)();\n}\n\nevent connection_SYN_packet(c: connection, pkt: SYN_packet) {\n event Beemaster::tcp_event(Beemaster::connection_to_alertinfo(c), 1);\n}\n","old_contents":"@load .\/beemaster_events\n@load .\/beemaster_types\n@load .\/beemaster_log\n@load .\/beemaster_util\n\n@load base\/bif\/plugins\/Bro_TCP.events.bif\n@load base\/bif\/plugins\/Bro_UDP.events.bif\n@load base\/protocols\/conn\/main\n\nredef exit_only_after_terminate = T;\n\n# Broker setup\n# the ports and IPs that are externally routable for a master and this slave\nconst slave_broker_port: string = getenv(\"SLAVE_PUBLIC_PORT\") &redef;\nconst slave_broker_ip: string = getenv(\"SLAVE_PUBLIC_IP\") &redef;\nconst master_broker_port: port = to_port(cat(getenv(\"MASTER_PUBLIC_PORT\"), \"\/tcp\")) &redef;\nconst master_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-slave-\", slave_broker_ip, \":\", slave_broker_port);\n\nglobal base_events: set[string] = { \"Beemaster::log_conn\" };\n\nglobal tcp_events: set[string] = { \"Beemaster::tcp_event\" };\n\nglobal lattice_events: set[string] = { \"Beemaster::lattice_event\"};\n\nevent bro_init() {\n Beemaster::log(\"bro_slave.bro: bro_init()\");\n\n # Enable broker and listen for incoming connectors\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Connect to bro-master for load-balancing and relaying events\n Broker::connect(master_broker_ip, master_broker_port, 1sec);\n\n # Publish our local events to forward them to master\/acus\n Broker::register_broker_events(\"beemaster\/bro\/base\", base_events);\n\n # Publish our tcp events\n Broker::register_broker_events(\"beemaster\/bro\/tcp\", tcp_events);\n\n # Publish our lattice_events\n Broker::register_broker_events(\"beemaster\/bro\/lattice\", lattice_events);\n\n Beemaster::log(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n Beemaster::log(\"bro_slave.bro: bro_done()\");\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n Beemaster::log(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n Beemaster::log(msg);\n}\n\n# forwarding when some local connection is beeing logged. Throws an explicit beemaster event to forward.\nevent Conn::log_conn(rec: Conn::Info) {\n event Beemaster::log_conn(rec);\n event Beemaster::lattice_event(Beemaster::conninfo_to_alertinfo(c), Beemaster::proto_to_string(rec$proto)();\n}\n\nevent connection_SYN_packet(c: connection, pkt: SYN_packet) {\n event Beemaster::tcp_event(Beemaster::connection_to_alertinfo(c), 1);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"c31e6f59fbb6fb4284e0f075b61e3cda6a203b4b","subject":"Updates default ROCK policy to add the worker name","message":"Updates default ROCK policy to add the worker name\n\nAdds a \"peer_descr\" column to `conn.log` to list the worker name (as specified in node.cfg for broctl)","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Configure Kafka output\n# Bro Kafka Output (plugin must be loaded!)\n@load Kafka\/KafkaWriter\/logs-to-kafka\nredef KafkaLogger::topic_name = \"bro_raw\";\nredef KafkaLogger::sensor_name = ROCK::sensor_id;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n# Add worker information to conn log\n@load .\/misc\/conn-add-worker\n\n","old_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Configure Kafka output\n# Bro Kafka Output (plugin must be loaded!)\n@load Kafka\/KafkaWriter\/logs-to-kafka\nredef KafkaLogger::topic_name = \"bro_raw\";\nredef KafkaLogger::sensor_name = ROCK::sensor_id;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"619f9082cb5e5843cfc0468ec833f73b1c217dbf","subject":"allow the ignoring of certain sites","message":"allow the ignoring of certain sites\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-ext-external-names.bro","new_file":"http-ext-external-names.bro","new_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)example\\.com($|:)\/ &redef;\n\n # in site policy, redef HTTP::ignore_external_addr += {1.2.3.4};\n # redef HTTP::ignore_external_host += {\"www.foo.com\"};\n\n\n global ignore_external_addr: set[addr] &redef;\n global ignore_external_host: set[string] &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(id$resp_h in ignore_external_addr || si$host in ignore_external_host)\n return;\n\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","old_contents":"@load http-ext\n\nmodule HTTP;\n\nexport {\n const local_domains = \/(^|\\.)albany\\.edu($|:)\/ &redef;\n}\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=1\n{\n if(is_local_addr(id$resp_h) && local_domains !in si$host) {\n si$force_log = T;\n add si$force_log_reasons[\"external_name\"];\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"b89bda2a96aaf9ac2f739f7348c1bb5f36057a88","subject":"Fixed problem with logging too many passwords in ftp-ext","message":"Fixed problem with logging too many passwords in ftp-ext\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ftp-ext.bro","new_file":"ftp-ext.bro","new_contents":"@load global-ext\n\n@load ftp\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_log = open_log_file(\"ftp-ext\") &raw_output;\n\t\n\ttype ftp_ext_session_info: record {\n\t\turl: string &default=\"\";\n\t\tpassword: string &default=\"\";\n\t\tmimetype: string &default=\"\";\n\t};\n\t\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &write_expire=1min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal blah: ftp_ext_session_info;\n\treturn blah;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\t\n\tlocal sess = ftp_sessions[c$id];\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\tlocal userpass = ( \/^(anonymous|ftp)$\/ in sess$user ) ?\n\t\t\t\t\t\t\tfmt(\"%s:%s\", sess$user, sess_ext$password) :\n\t\t\t\t\t\t\tsess$user;\n\t\tsess_ext$url = fmt(\"ftp:\/\/%s@%s%s\", userpass, c$id$resp_h, absolute_path(sess, arg));\n\t\tprint ftp_ext_log, cat_sep(\"\\t\", \"\\\\N\",\n\t\t\t\t\t\tsess$request_t,\n\t\t\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\t\t\tcommand, sess_ext$url);\n\t\t}\n\t}\n\t\nevent ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n\t{\n\t#TODO: include reply in logged message\n\tlocal reply = \"\";\n\tif ( code in ftp_replies )\n\t\t reply = ftp_replies[code];\n\t}\n","old_contents":"@load global-ext\n\n@load ftp\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_log = open_log_file(\"ftp-ext\") &raw_output;\n\t\n\ttype ftp_ext_session_info: record {\n\t\turl: string &default=\"\";\n\t\tpassword: string &default=\"\";\n\t\tmimetype: string &default=\"\";\n\t};\n\t\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &write_expire=1min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal blah: ftp_ext_session_info;\n\treturn blah;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\t\n\tlocal sess = ftp_sessions[c$id];\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\tlocal userpass = (sess$anonymous_login) ? \n\t\t\t\t\t\t\tfmt(\"%s:%s\", sess$user, sess_ext$password) :\n\t\t\t\t\t\t\tsess$user;\n\t\tsess_ext$url = fmt(\"ftp:\/\/%s@%s%s\", userpass, c$id$resp_h, absolute_path(sess, arg));\n\t\tprint ftp_ext_log, cat_sep(\"\\t\", \"\\\\N\",\n\t\t\t\t\t\tsess$request_t,\n\t\t\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\t\t\tcommand, sess_ext$url);\n\t\t}\n\t}\n\t\nevent ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n\t{\n\t#TODO: include reply in logged message\n\tlocal reply = \"\";\n\tif ( code in ftp_replies )\n\t\t reply = ftp_replies[code];\n\t}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"635d9dcae708940b95387dafdb836723399354db","subject":"Fixed a small issue with the request time in the ftp logs.","message":"Fixed a small issue with the request time in the ftp logs.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ftp-ext.bro","new_file":"ftp-ext.bro","new_contents":"@load global-ext\n@load ftp\n\ntype ftp_ext_session_info: record {\n\tusername: string &default=\"\";\n\tpassword: string &default=\"\";\n\trequest_t: time;\n\turl: string &default=\"\";\n\tcommand: string &default=\"\";\n\treply_code: count &default=0;\n\treply_msg: string &default=\"\";\n\t\n\t# This is internal state tracking.\n\tready: bool &default=F;\n};\n\n# Define the generic ftp-ext event that can be handled from other scripts\nglobal ftp_ext: event(id: conn_id, si: ftp_ext_session_info);\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &read_expire=5min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal x: ftp_ext_session_info;\n\tx$request_t=network_time();\n\treturn x;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\t# Throw the ftp_ext event if the session record is \"ready\".\n\t# This will make sure we get the last reply from the previous command.\n\tif ( sess_ext$ready )\n\t\t{\n\t\t# Copy the sess_ext variable because modifications to it can encounter\n\t\t# race conditions with the event dispatching system.\n\t\tevent ftp_ext(c$id, copy(sess_ext));\n\t\tsess_ext$ready=F;\n\t\t}\n\t\n\t# Update the session's command everytime (after potentially dispatching\n\t# the ftp_ext event).\n\tsess_ext$command = command;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\tlocal sess = ftp_sessions[c$id];\n\t\t\n\t\t# Move the request time into the ext session information\n\t\tsess_ext$request_t = sess$request_t;\n\t\t\n\t\t# If the start directory is unknown, record it as \/.\n\t\tlocal pathfile = sub(absolute_path(sess, arg), \/\/, \"\/.\");\n\t\t\n\t\tsess_ext$url = fmt(\"ftp:\/\/%s%s\", c$id$resp_h, pathfile);\n\t\t}\n\t\t\n\telse if ( command == \"USER\" )\n\t\tsess_ext$username=arg;\n\n\telse if ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t}\n\nevent ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n\t{\n\t# I'm not sure how I'd like to handle multiline responses yet.\n\tif ( cont_resp ) return;\n\t\n\tif ( c$id !in ftp_ext_sessions ) return;\n\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( sess_ext$command == \"RETR\" ||\n\t sess_ext$command == \"STOR\" )\n\t\t{\n\t\tsess_ext$reply_code = code;\n\t\tsess_ext$reply_msg = msg;\n\t\t\n\t\t# We are considering the record \"ready\" once the reply has been recorded.\n\t\tsess_ext$ready = T;\n\t\t}\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tif ( c$id in ftp_ext_sessions )\n\t\t{\n\t\tevent ftp_ext(c$id, ftp_ext_sessions[c$id]);\n\t\tdelete ftp_ext_sessions[c$id];\n\t\t}\n\t}\n\n","old_contents":"@load global-ext\n@load ftp\n\ntype ftp_ext_session_info: record {\n\tusername: string &default=\"\";\n\tpassword: string &default=\"\";\n\trequest_t: time &optional;\n\turl: string &default=\"\";\n\tcommand: string &default=\"\";\n\treply_code: count &default=0;\n\treply_msg: string &default=\"\";\n\t\n\t# This is internal state tracking.\n\tready: bool &default=F;\n};\n\n# Define the generic ftp-ext event that can be handled from other scripts\nglobal ftp_ext: event(id: conn_id, si: ftp_ext_session_info);\n\nmodule FTP;\n\nexport {\n\tglobal ftp_ext_sessions: table[conn_id] of ftp_ext_session_info &read_expire=5min;\n}\n\nfunction new_ftp_ext_session(): ftp_ext_session_info\n\t{\n\tlocal x: ftp_ext_session_info;\n\treturn x;\n\t}\n\nevent ftp_request(c: connection, command: string, arg: string) &priority=10\n\t{\n\tif ( c$id !in ftp_ext_sessions ) \n\t\tftp_ext_sessions[c$id] = new_ftp_ext_session();\n\t\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\t# Throw the ftp_ext event if the session record is \"ready\".\n\t# This will make sure we get the last reply from the previous command.\n\tif ( sess_ext$ready )\n\t\t{\n\t\t# Copy the sess_ext variable because modifications to it can encounter\n\t\t# race conditions with the event dispatching system.\n\t\tevent ftp_ext(c$id, copy(sess_ext));\n\t\tsess_ext$ready=F;\n\t\t}\n\t\n\t# Update the session's command everytime (after potentially dispatching\n\t# the ftp_ext event).\n\tsess_ext$command = command;\n\t\n\tif ( command == \"RETR\" || command == \"STOR\" )\n\t\t{\n\t\tlocal sess = ftp_sessions[c$id];\n\t\t\n\t\t# Move the request time into the ext session information\n\t\tsess_ext$request_t = sess$request_t;\n\t\t\n\t\t# If the start directory is unknown, record it as \/.\n\t\tlocal pathfile = sub(absolute_path(sess, arg), \/\/, \"\/.\");\n\t\t\n\t\tsess_ext$url = fmt(\"ftp:\/\/%s%s\", c$id$resp_h, pathfile);\n\t\t}\n\t\t\n\telse if ( command == \"USER\" )\n\t\tsess_ext$username=arg;\n\n\telse if ( command == \"PASS\" )\n\t\tsess_ext$password=arg;\n\t}\n\nevent ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)\n\t{\n\t# I'm not sure how I'd like to handle multiline responses yet.\n\tif ( cont_resp ) return;\n\t\n\tif ( c$id !in ftp_ext_sessions ) return;\n\n\tlocal sess_ext = ftp_ext_sessions[c$id];\n\t\n\tif ( sess_ext$command == \"RETR\" ||\n\t sess_ext$command == \"STOR\" )\n\t\t{\n\t\tsess_ext$reply_code = code;\n\t\tsess_ext$reply_msg = msg;\n\t\t\n\t\t# We are considering the record \"ready\" once the reply has been recorded.\n\t\tsess_ext$ready = T;\n\t\t}\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tif ( c$id in ftp_ext_sessions )\n\t\t{\n\t\tevent ftp_ext(c$id, ftp_ext_sessions[c$id]);\n\t\tdelete ftp_ext_sessions[c$id];\n\t\t}\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"a3496498c6384dcf600619078f11032ac1b5ea78","subject":"include connection id in phishing notices","message":"include connection id in phishing notices\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-phish-passwords.bro","new_file":"smtp-ext-phish-passwords.bro","new_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &create_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s - %s\", si$mailfrom, to, si$subject),\n $id=id,\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n phishing_counter[si$mailfrom] += |si$rcptto|;\n if(phishing_counter[si$mailfrom] > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $id=id,\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","old_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &create_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s - %s\", si$mailfrom, to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n phishing_counter[si$mailfrom] += |si$rcptto|;\n if(phishing_counter[si$mailfrom] > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"a6f3395f129b1c8c7a05ea46ad7a747099e9d054","subject":"correct the notice msg, the direction in the wording is backwards","message":"correct the notice msg, the direction in the wording is backwards\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id];\n local blarg: set[conn_id];\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id];\n local blarg: set[conn_id];\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"%s is rejecting a high percentage of mail\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"6a478ed0d61c9a15d5609efb49158d0a461dbeed","subject":"Kleinen Fehler korrigiert, Dio_mysql war an der falschen Stelle.","message":"Kleinen Fehler korrigiert, Dio_mysql war an der falschen Stelle.\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dionaea_receiver.bro","new_file":"custom_scripts\/dionaea_receiver.bro","new_contents":"@load .\/dio_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string); \nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport];\n\n Log::write(Dio::LOG, rec);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args];\n\n Log::write(Dio_mysql::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","old_contents":"@load .\/dio_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string); \nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport];\n\n Log::write(Dio_mysql::LOG, rec);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args];\n\n Log::write(Dio::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"06bf369d705eb01717051ee5bdb8414d542bf603","subject":"Rework the ssl logged hosts configuration","message":"Rework the ssl logged hosts configuration\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", All, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !resp_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logging = Outbound &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", logging, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !orig_matches_direction(c$id$resp_h, logging) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"3ae711da1daa2bb6375adad381e475d28589ae71","subject":"slave forward mysql stuff, auto publish everything","message":"slave forward mysql stuff, auto publish everything\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_slave\/bro_slave.bro","new_file":"scripts_slave\/bro_slave.bro","new_contents":"@load .\/slave_log.bro\n\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro-slave-\" + gethostname(); # make sure this is unique (for docker-compose, it is!)\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql_command: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string);\nglobal dionaea_mysql_login: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal log_bro: function(msg: string);\nglobal published_events: set[string] = { \"dionaea_access\", \"dionaea_ftp\", \"dionaea_mysql_command\", \"dionaea_mysql_login\", \"dionaea_download_complete\", \"dionaea_download_offer\", \"dionaea_smb_request\", \"dionaea_smb_bind\" };\n\n\nevent bro_init() {\n log_bro(\"bro_slave.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n \n # Listening\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n \n # Forwarding\n Broker::connect(\"bro-master\", broker_port, 1sec);\n Broker::register_broker_events(\"honeypot\/dionaea\", published_events);\n\n # Try unsolicited option, which should prevent topic issues\n Broker::auto_event(\"honeypot\/dionaea\", dionaea_access);\n log_bro(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n log_bro(\"bro_slave.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n event dionaea_access(timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n}\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n\n event dionaea_ftp(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, command, arguments, origin, connector_id);\n}\nevent dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n\n event dionaea_mysql_command(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, args, origin, connector_id);\n}\nevent dionaea_mysql_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n\n event dionaea_mysql_login(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, username, password, origin, connector_id);\n}\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n\n event dionaea_download_complete(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, md5hash, filelocation, origin, connector_id);\n}\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n event dionaea_download_offer(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, origin, connector_id);\n}\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n\n event dionaea_smb_request(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, opnum, uuid, origin, connector_id);\n}\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n\n event dionaea_smb_bind(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, transfersyntax, uuid, origin, connector_id);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n log_bro(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address; \n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n log_bro(msg);\n}\n\nfunction log_bro(msg: string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n","old_contents":"@load .\/slave_log.bro\n\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro-slave-\" + gethostname(); # make sure this is unique (for docker-compose, it is!)\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_ftp: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, connector_id: string);\nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal log_bro: function(msg: string);\nglobal published_events: set[string] = { \"dionaea_access\", \"dionaea_mysql\" };\n\n\nevent bro_init() {\n log_bro(\"bro_slave.bro: bro_init()\");\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n \n # Listening\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\");\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n \n # Forwarding\n Broker::connect(\"bro-master\", broker_port, 1sec);\n Broker::register_broker_events(\"honeypot\/dionaea\", published_events);\n\n # Try unsolicited option, which should prevent topic issues\n Broker::auto_event(\"honeypot\/dionaea\", dionaea_access);\n log_bro(\"bro_slave.bro: bro_init() done\");\n}\n\nevent bro_done() {\n log_bro(\"bro_slave.bro: bro_done()\");\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n event dionaea_access(timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n}\nevent dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n\n event dionaea_ftp(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, command, arguments, origin, connector_id);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, connector_id: string) {\n\n event dionaea_mysql(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, args, connector_id);\n}\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n\n event dionaea_download_complete(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, md5hash, filelocation, origin, connector_id);\n}\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n event dionaea_download_offer(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, url, origin, connector_id);\n}\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n\n event dionaea_smb_request(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, opnum, uuid, origin, connector_id);\n}\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n\n event dionaea_smb_bind(timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, protocol, transfersyntax, uuid, origin, connector_id);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n log_bro(msg);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address; \n log_bro(msg);\n}\n\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n log_bro(msg);\n}\n\nfunction log_bro(msg: string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"406a5b0d7264b7794690a65e2f6a86effbb37be0","subject":"fix the conn_id reference, n$conn doesn't always exist, but n$id will","message":"fix the conn_id reference, n$conn doesn't always exist, but n$id will\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"subnet-admins.bro","new_file":"subnet-admins.bro","new_contents":"@load my-notice-action-filter\nglobal subnet_admins: table[subnet] of string &redef;\n\nfunction notice_email_subnet_admins(n: notice_info, a: NoticeAction): NoticeAction\n{\n local id = n$id;\n local host = is_local_addr(id$orig_h) ? id$orig_h : id$resp_h;\n local admin = \"\";\n\n if(host !in subnet_admins)\n admin = mail_dest;\n else\n admin = subnet_admins[host];\n email_notice_to(n, admin);\n event notice_alarm(n, NOTICE_EMAIL);\n return NOTICE_FILE;\n}\n\nfunction notice_email_subnet_admins_then_tally(n: notice_info, a: NoticeAction): NoticeAction\n{\n a = notice_email_then_tally(n, a);\n if(a == NOTICE_EMAIL){\n a = notice_email_subnet_admins(n, a);\n }\n return a;\n}\n","old_contents":"@load my-notice-action-filter\nglobal subnet_admins: table[subnet] of string &redef;\n\nfunction notice_email_subnet_admins(n: notice_info, a: NoticeAction): NoticeAction\n{\n local id = n$conn$id;\n local host = is_local_addr(id$orig_h) ? id$orig_h : id$resp_h;\n local admin = \"\";\n\n if(host !in subnet_admins)\n admin = mail_dest;\n else\n admin = subnet_admins[host];\n email_notice_to(n, admin);\n event notice_alarm(n, NOTICE_EMAIL);\n return NOTICE_FILE;\n}\n\nfunction notice_email_subnet_admins_then_tally(n: notice_info, a: NoticeAction): NoticeAction\n{\n a = notice_email_then_tally(n, a);\n if(a == NOTICE_EMAIL){\n a = notice_email_subnet_admins(n, a);\n }\n return a;\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"11bd3495bf4afb90e861a6c3503fe3b6d333350e","subject":"Fixed default bahavior and comment for log redaction.","message":"Fixed default bahavior and comment for log redaction.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/^[3-9]{4}([ -\\.]?\\x00?[0-9]{4}){3}$\/ &redef;\n\n\tconst cc_separators = \/\\.(.*\\.){3}\/ | \n\t \/\\-(.*\\-){3}\/ | \n\t \/[:blank:](.*[:blank:]){3}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tlocal parts = str_split(gsub(val, \/[^0-9]\/, \"\"), vector(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));\n\tfor ( i in parts )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(parts[i]);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tlocal cc_match = \"\";\n\t\t\tlocal redacted_cc = \"\";\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches and save one back for \n\t\t\t\t\t# finding it's location.\n\t\t\t\t\tcc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\tredacted_cc = parts[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, cc_match);\n\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : cc_match),\n\t\t\t $data=(redact_log ? redacted_data : data)];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","old_contents":"\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by defaultIf you want to see the credit card numbers in \n\t## the log, redef this value to T. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = F &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/^[3-9]{4}([ -\\.]?\\x00?[0-9]{4}){3}$\/ &redef;\n\n\tconst cc_separators = \/\\.(.*\\.){3}\/ | \n\t \/\\-(.*\\-){3}\/ | \n\t \/[:blank:](.*[:blank:]){3}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tlocal parts = str_split(gsub(val, \/[^0-9]\/, \"\"), vector(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));\n\tfor ( i in parts )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(parts[i]);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tlocal cc_match = \"\";\n\t\t\tlocal redacted_cc = \"\";\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches and save one back for \n\t\t\t\t\t# finding it's location.\n\t\t\t\t\tcc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\tredacted_cc = parts[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, cc_match);\n\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : cc_match),\n\t\t\t $data=(redact_log ? redacted_data : data)];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"10327c48d83a5aea35a2e8f2a808da53836c3e0a","subject":"Added beemaster::conninfo_to_alertinfo","message":"Added beemaster::conninfo_to_alertinfo\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_shared\/beemaster_types.bro","new_file":"scripts_shared\/beemaster_types.bro","new_contents":"module beemaster;\n\n@load base\/utils\/addrs\n\nexport {\n type AlertInfo: record {\n timestamp: time;\n incident_type: string;\n protocol: string;\n source_ip: string;\n source_port: count;\n destination_ip: string;\n destination_port: count;\n };\n}\n\nfunction conninfo_to_alertinfo(input: Conn::Info) : AlertInfo {\n local conn = input$id;\n return AlertInfo($timestamp = input$ts, $incident_type = \"foo\", $protocol = \"bar\",\n $source_ip = addr_to_uri(conn$orig_h), $source_port = port_to_count(conn$orig_p),\n $destination_ip = addr_to_uri(conn$resp_h), $destination_port = port_to_count(conn$resp_p));\n}\n","old_contents":"module beemaster;\n\nexport {\n type AlertInfo: record {\n timestamp: time;\n incident_type: string;\n protocol: string;\n source_ip: string;\n source_port: port;\n destination_ip: addr;\n destination_port: port;\n };\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"7e53e6b0397f760ad9c6c3e492e19dff975e561e","subject":"log sql injection requests","message":"log sql injection requests\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"log-http-sqli.bro","new_file":"log-http-sqli.bro","new_contents":"event bro_init()\n{\n Log::add_filter(HTTP::LOG, [$name = \"http-sqli\",\n $path = \"http_sqli\",\n $pred(rec: HTTP::Info) = { return HTTP::URI_SQLI in rec$tags ; }\n ]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'log-http-sqli.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"f2594e55277bb036e415c2ffa7a766c745dd30dd","subject":"dio_mysql_log.bro hinzugef\u00fcgt","message":"dio_mysql_log.bro hinzugef\u00fcgt\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dio_mysql_log.bro","new_file":"custom_scripts\/dio_mysql_log.bro","new_contents":"module Dio_mysql;\n\nexport {\n redef enum Log::ID += { LOG };\n \n type Info: record {\n ts: time &log;\n id: string &log;\n local_ip: addr &log;\n local_port: port &log;\n remote_ip: addr &log; \n remote_port: port &log;\n transport: string &log;\n args: string $log;\n };\n}\n\nevent bro_init() &priority=5 {\n Log::create_stream(Dio_mysql::LOG, [$columns=Info, $path=\"Dionaea_MySQL\"]); \n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'custom_scripts\/dio_mysql_log.bro' did not match any file(s) known to git\n","license":"mit","lang":"Bro"} {"commit":"fa7804f9a1351b048ee47d9ff80c7dbd29c21c4c","subject":"terminate connection updated for bro 2.1","message":"terminate connection updated for bro 2.1\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"terminate-connection.bro","new_file":"terminate-connection.bro","new_contents":"module TerminateConnection;\n\nexport {\n\tredef enum Notice::Type += {\n\t\tTerminatingConnection,\t# connection will be terminated\n\t\tTerminatingConnectionIgnored,\t# connection terminated disabled\n\t};\n\n\t# Whether we're allowed (and\/or are capable) to terminate connections\n\t# using \"rst\".\n\tconst activate_terminate_connection = F &redef;\n\n\t# Terminate the given connection.\n\tglobal terminate_connection: function(c: connection);\n\n}\n\nfunction full_id_string(c: connection): string\n {\n local id = c$id;\n return fmt(\"%s:%s -> %s:%s\", id$orig_h, id$orig_p, id$resp_h, id$resp_p);\n }\n\nfunction terminate_connection(c: connection)\n\t{\n\tlocal id = c$id;\n\n\tif ( activate_terminate_connection )\n\t\t{\n\t\tlocal local_init = Site::is_local_addr(id$orig_h);\n\n\t\tlocal term_cmd = fmt(\"rst %s -n 32 -d 20 %s %d %d %s %d %d\",\n\t\t\t\t\tlocal_init ? \"-R\" : \"\",\n\t\t\t\t\tid$orig_h, id$orig_p, get_orig_seq(id),\n\t\t\t\t\tid$resp_h, id$resp_p, get_resp_seq(id));\n\n\t\tif ( reading_live_traffic() )\n\t\t\tsystem(term_cmd);\n\t\telse\n\t\t\tNOTICE([$note=TerminatingConnection, $conn=c,\n\t\t\t\t$msg=term_cmd, $sub=\"first termination command\"]);\n\n\t\tterm_cmd = fmt(\"rst %s -r 2 -n 4 -s 512 -d 20 %s %d %d %s %d %d\",\n\t\t\t\tlocal_init ? \"-R\" : \"\",\n\t\t\t\tid$orig_h, id$orig_p, get_orig_seq(id),\n\t\t\t\tid$resp_h, id$resp_p, get_resp_seq(id));\n\n\t\tif ( reading_live_traffic() )\n\t\t\tsystem(term_cmd);\n\t\telse\n\t\t\tNOTICE([$note=TerminatingConnection, $conn=c,\n\t\t\t\t$msg=term_cmd, $sub=\"second termination command\"]);\n\n\t\tNOTICE([$note=TerminatingConnection, $conn=c,\n\t\t\t$msg=fmt(\"terminating %s\", full_id_string(c))]);\n\t\t}\n\n\telse\n\t\tNOTICE([$note=TerminatingConnectionIgnored, $conn=c,\n\t\t\t$msg=fmt(\"ignoring request to terminate %s\",\n\t\t\t\t\tfull_id_string(c))]);\n\t}\n","old_contents":"# $Id$\n\n@load site\n@load notice\n\n# Ugly: we need the following from conn.bro, but we can't soundly load\n# it because it in turn loads us.\nglobal full_id_string: function(c: connection): string;\n\nmodule TerminateConnection;\n\nexport {\n\tredef enum Notice += {\n\t\tTerminatingConnection,\t# connection will be terminated\n\t\tTerminatingConnectionIgnored,\t# connection terminated disabled\n\t};\n\n\t# Whether we're allowed (and\/or are capable) to terminate connections\n\t# using \"rst\".\n\tconst activate_terminate_connection = F &redef;\n\n\t# Terminate the given connection.\n\tglobal terminate_connection: function(c: connection);\n\n}\n\nfunction terminate_connection(c: connection)\n\t{\n\tlocal id = c$id;\n\n\tif ( activate_terminate_connection )\n\t\t{\n\t\tlocal local_init = is_local_addr(id$orig_h);\n\n\t\tlocal term_cmd = fmt(\"rst %s -n 32 -d 20 %s %d %d %s %d %d\",\n\t\t\t\t\tlocal_init ? \"-R\" : \"\",\n\t\t\t\t\tid$orig_h, id$orig_p, get_orig_seq(id),\n\t\t\t\t\tid$resp_h, id$resp_p, get_resp_seq(id));\n\n\t\tif ( reading_live_traffic() )\n\t\t\tsystem(term_cmd);\n\t\telse\n\t\t\tNOTICE([$note=TerminatingConnection, $conn=c,\n\t\t\t\t$msg=term_cmd, $sub=\"first termination command\"]);\n\n\t\tterm_cmd = fmt(\"rst %s -r 2 -n 4 -s 512 -d 20 %s %d %d %s %d %d\",\n\t\t\t\tlocal_init ? \"-R\" : \"\",\n\t\t\t\tid$orig_h, id$orig_p, get_orig_seq(id),\n\t\t\t\tid$resp_h, id$resp_p, get_resp_seq(id));\n\n\t\tif ( reading_live_traffic() )\n\t\t\tsystem(term_cmd);\n\t\telse\n\t\t\tNOTICE([$note=TerminatingConnection, $conn=c,\n\t\t\t\t$msg=term_cmd, $sub=\"second termination command\"]);\n\n\t\tNOTICE([$note=TerminatingConnection, $conn=c,\n\t\t\t$msg=fmt(\"terminating %s\", full_id_string(c))]);\n\t\t}\n\n\telse\n\t\tNOTICE([$note=TerminatingConnectionIgnored, $conn=c,\n\t\t\t$msg=fmt(\"ignoring request to terminate %s\",\n\t\t\t\t\tfull_id_string(c))]);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"9fab1b594a9e475b327aaa3270c5cd341028e62b","subject":"Modified scripts for flexible log selection. - Added \"include_logs\" and \"exclude_logs\" that allows for default to include all, or if explicitly include logs or exclude logs.","message":"Modified scripts for flexible log selection.\n- Added \"include_logs\" and \"exclude_logs\" that allows for default\n to include all, or if explicitly include logs or exclude logs.\n","repos":"dcode\/KafkaLogger,dcode\/KafkaLogger","old_file":"scripts\/Kafka\/KafkaWriter\/logs-to-kafka.bro","new_file":"scripts\/Kafka\/KafkaWriter\/logs-to-kafka.bro","new_contents":"module KafkaLogger;\n\nexport {\n\t# redefine this in your script to identify the logs\n\t# that should be sent to Kafka. By default, all will be sent.\n\t# for example:\n\t#\n\t# redef KafkaLogger::include_logs = set(HTTP::LOG, Conn::Log, DNS::LOG);\n\t#\n\t# that will send the HTTP, Conn, and DNS logs up to Kafka.\n\t#\n\tconst include_logs: set[Log::ID] &redef;\n\t# redefine this in your script to identify the logs\n\t# that should be excluded from sending to Kafka. By default, all\n\t# will be sent.\n\t# for example:\n\t#\n\t# redef KafkaLogger::include_logs = set(HTTP::LOG, Conn::Log, DNS::LOG);\n\t#\n\t# that will send the HTTP, Conn, and DNS logs up to Kafka.\n\t#\n\tconst exclude_logs: set[Log::ID] &redef;\n\n}\n\nevent bro_init() &priority=-5\n{\n\n\tfor (stream_id in Log::active_streams)\n\t{\n\t if (|include_logs| > 0 && stream_id !in include_logs){\n\t next;\n\t }\n\t\t\tif ( stream_id in exclude_logs ) {\n\t\t\t\t\tnext;\n\t\t\t}\n\t # note: the filter name is different for each log, to cause Bro to instantiate\n\t # a new Writer instance for each log. The bro folks might want me\n\t # to do this with a single writer instance, but the mechanics of\n\t # modifying the field names and adding fields made it quite complicated,\n\t # so I opted to make one log writer per bro log going to Kafka.\n\t # this means there will be multiple connections from bro to the kafka\n\t # server, one per log file.\n\t local streamString = fmt(\"%s\", stream_id);\n\t local pathname = fmt(\"%s\", KafkaLogger::log_names[streamString]);\n\t local filter: Log::Filter = [$name = fmt(\"kafka-%s\",stream_id),\n\t \t\t\t\t\t\t\t $writer = Log::WRITER_KAFKAWRITER,\n\t \t\t\t\t\t\t\t $path = pathname\n\t \t\t\t\t\t\t\t];\n\t Log::add_filter(stream_id, filter);\n\n\t}\n\n}\n","old_contents":"module KafkaLogger;\n\nexport {\n\t# redefine this in your script to identify the logs\n\t# that should be sent up to bro. \n\t# for example: \n\t#\n\t# redef KafkaLogger::logs_to_send = set(HTTP::LOG, Conn::Log, DNS::LOG);\n\t#\n\t# that will send the HTTP, Conn, and DNS logs up to Kafka.\n\t#\n\tconst logs_to_send: set[Log::ID] &redef;\n}\n\nevent bro_init() &priority=-5\n{\n\t\n\tfor (stream_id in Log::active_streams)\n\t{\n\t if (stream_id !in logs_to_send){\n\t next;\n\t }\n\t # note: the filter name is different for each log, to cause Bro to instantiate\n\t # a new Writer instance for each log. The bro folks might want me\n\t # to do this with a single writer instance, but the mechanics of\n\t # modifying the field names and adding fields made it quite complicated,\n\t # so I opted to make one log writer per bro log going to Kafka.\n\t # this means there will be multiple connections from bro to the kafka\n\t # server, one per log file. \n\t local streamString = fmt(\"%s\", stream_id);\n\t local pathname = fmt(\"%s\", KafkaLogger::log_names[streamString]);\n\t local filter: Log::Filter = [$name = fmt(\"kafka-%s\",stream_id),\n\t \t\t\t\t\t\t\t $writer = Log::WRITER_KAFKAWRITER,\n\t \t\t\t\t\t\t\t $path = pathname\n\t \t\t\t\t\t\t\t];\n\t Log::add_filter(stream_id, filter);\n\t\n\t}\n\n}\n\t","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"d926a048b1d272b75feac3f9e701a1f751a46451","subject":"Added some new DNSBLs to the smtp-ext script.","message":"Added some new DNSBLs to the smtp-ext script.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp_ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t};\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# ExternalHosts - only capture the path until an internal host is found.\n\t# InternalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=10secs;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal text_ip = \"\";\n\tlocal parts: string_array;\n\tif ( \/\\[.*\\]\/ in header )\n\t\tparts = split(header, \/[\\[\\]]\/);\n\telse if ( \/\\(.*\\)\/ in header )\n\t\tparts = split(header, \/[\\(\\)]\/);\n\n\tif (|parts| > 1)\n\t\t{\n\t\tif ( |parts| > 3 && parts[4] == ip_addr_regex )\n\t\t\ttext_ip = parts[4];\n\t\telse if ( parts[2] == ip_addr_regex )\n\t\t\ttext_ip = parts[2];\n\t\t}\n\treturn text_ip;\n}\n\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\t\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\n\tif ( \/^[^[:blank:]]*?:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tdelete in_received_from_headers[id];\n\tif ( \/^Received:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tadd in_received_from_headers[id];\n\t\n\tlocal session = smtp_sessions[id];\n\t\n\tif ( session$in_header && # headers are currently being analyzed \n\t id in in_received_from_headers && # currently seeing received from headers\n\t id !in smtp_received_finished && # we don't want to stop seeing this message yet\n\t \/[\\[\\(]\/ in data ) # the line might contain an ip address\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n \n\t\t# check for valid-ish ip - some mtas are weird.\n\t\tif ( is_valid_ip(text_ip) )\n\t\t\t{\n\t\t\tlocal ip = to_addr(text_ip);\n\t\t\t\n\t\t\t# I don't care if mail bounces around on localhost\n\t\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\t\n\t\t\tif ( ip_matches_hosts(ip, mail_path_capture) || \n\t\t\t ip in private_address_space )\n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t} \n\t\t\telse \n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t\n\t\t\t\tadd smtp_received_finished[id]; \n\t\t\t\t}\n\t\t\t}\n\t\t} \n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\t{\n\t\tadd smtp_received_finished[id];\n\t\t}\n\t}\n\n\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tif ( id !in conn_info )\n\t\treturn;\n\tlocal conn_log = conn_info[id];\n\t\n\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t conn_log$helo, conn_log$msg_id, conn_log$in_reply_to, \n\t conn_log$mailfrom, fmt_str_set(conn_log$rcptto, \/[\\\"\\'<>]|([[:blank:]].*$)\/),\n\t conn_log$date, conn_log$from, conn_log$reply_to, fmt_str_set(conn_log$to, \/[\\\"\\']\/),\n\t conn_log$last_reply, smtp_forward_paths[id]);\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( code >= 400 && id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# If a local MTA receives a message from a remote host telling it that it's on a block list, raise a notice.\n\t\tif ( smtp_bl_error_messages in msg && is_local_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\t# TODO: make this work with IPv6\n\t\t\tlocal msg_parts = split_all(msg, \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |msg_parts| > 2 )\n\t\t\t\ttext_ip = msg_parts[2];\n\t\t\tif ( is_valid_ip(text_ip) && to_addr(text_ip) == c$id$orig_h )\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\n\t\t\tNOTICE([$note=note, \n\t\t\t $conn=c, \n\t\t\t $msg=fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h),\n\t\t\t $sub=fmt(\"Remote host said: %s\", msg)]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id in smtp_sessions )\n\t\t{\n\t\tif ( id !in conn_info )\n\t\t\tconn_info[id] = default_session_info();\n\t\tlocal conn_log = conn_info[id];\n\t\t\n\t\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\t\tconn_log$helo = arg;\n\t\t\n\t\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\t\n\t\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t\t{\n\t\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t \treturn;\n\n\tlocal conn_log = conn_info[id];\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]\/ in data )\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[dD][aA][tT][eE]:[[:blank:]]\/ in data )\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[fF][rR][oO][mM]:[[:blank:]]\/ in data )\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[tT][oO]:[[:blank:]]\/ in data )\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\n\tif ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp_ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t};\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# ExternalHosts - only capture the path until an internal host is found.\n\t# InternalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=10secs;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal text_ip = \"\";\n\tlocal parts: string_array;\n\tif ( \/\\[.*\\]\/ in header )\n\t\tparts = split(header, \/[\\[\\]]\/);\n\telse if ( \/\\(.*\\)\/ in header )\n\t\tparts = split(header, \/[\\(\\)]\/);\n\n\tif (|parts| > 1)\n\t\t{\n\t\tif ( |parts| > 3 && parts[4] == ip_addr_regex )\n\t\t\ttext_ip = parts[4];\n\t\telse if ( parts[2] == ip_addr_regex )\n\t\t\ttext_ip = parts[2];\n\t\t}\n\treturn text_ip;\n}\n\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\t\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\n\tif ( \/^[^[:blank:]]*?:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tdelete in_received_from_headers[id];\n\tif ( \/^Received:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tadd in_received_from_headers[id];\n\t\n\tlocal session = smtp_sessions[id];\n\t\n\tif ( session$in_header && # headers are currently being analyzed \n\t id in in_received_from_headers && # currently seeing received from headers\n\t id !in smtp_received_finished && # we don't want to stop seeing this message yet\n\t \/[\\[\\(]\/ in data ) # the line might contain an ip address\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n \n\t\t# check for valid-ish ip - some mtas are weird.\n\t\tif ( is_valid_ip(text_ip) )\n\t\t\t{\n\t\t\tlocal ip = to_addr(text_ip);\n\t\t\t\n\t\t\t# I don't care if mail bounces around on localhost\n\t\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\t\n\t\t\tif ( ip_matches_hosts(ip, mail_path_capture) || \n\t\t\t ip in private_address_space )\n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t} \n\t\t\telse \n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t\n\t\t\t\tadd smtp_received_finished[id]; \n\t\t\t\t}\n\t\t\t}\n\t\t} \n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\t{\n\t\tadd smtp_received_finished[id];\n\t\t}\n\t}\n\n\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tif ( id !in conn_info )\n\t\treturn;\n\tlocal conn_log = conn_info[id];\n\t\n\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t conn_log$helo, conn_log$msg_id, conn_log$in_reply_to, \n\t conn_log$mailfrom, fmt_str_set(conn_log$rcptto, \/[\\\"\\'<>]|([[:blank:]].*$)\/),\n\t conn_log$date, conn_log$from, conn_log$reply_to, fmt_str_set(conn_log$to, \/[\\\"\\']\/),\n\t conn_log$last_reply, smtp_forward_paths[id]);\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( code >= 400 && id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# If a local MTA receives a message from a remote host telling it that it's on a block list, raise a notice.\n\t\tif ( smtp_bl_error_messages in msg && is_local_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\t# TODO: make this work with IPv6\n\t\t\tlocal msg_parts = split_all(msg, \/[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\/);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |msg_parts| > 2 )\n\t\t\t\ttext_ip = msg_parts[2];\n\t\t\tif ( is_valid_ip(text_ip) && to_addr(text_ip) == c$id$orig_h )\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\n\t\t\tNOTICE([$note=note, \n\t\t\t $conn=c, \n\t\t\t $msg=fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h),\n\t\t\t $sub=fmt(\"Remote host said: %s\", msg)]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id in smtp_sessions )\n\t\t{\n\t\tif ( id !in conn_info )\n\t\t\tconn_info[id] = default_session_info();\n\t\tlocal conn_log = conn_info[id];\n\t\t\n\t\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\t\tconn_log$helo = arg;\n\t\t\n\t\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\t\n\t\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t\t{\n\t\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t \treturn;\n\n\tlocal conn_log = conn_info[id];\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]\/ in data )\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[dD][aA][tT][eE]:[[:blank:]]\/ in data )\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[fF][rR][oO][mM]:[[:blank:]]\/ in data )\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[tT][oO]:[[:blank:]]\/ in data )\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\n\tif ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1086b34aab254bab8628f4b97b526c36148d90e4","subject":"Huge changes to smtp-ext (additions, fixes, .and code refactoring)","message":"Huge changes to smtp-ext (additions, fixes, .and code refactoring)\n\nNew notice:\n SMTP_Suspicious_Origination - Thrown when mail appears to originate from\n a network or country where unwanted mail typically originates for your site.\n\nNew data logged:\n x-originating-ip\n files transferred in the email\n\nNew smtp block lists:\n mail-abuse.com\n bbl.barracudacentral.com\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\tlocal session = smtp_sessions[id];\n\n\tif ( id !in conn_info || \n\t\t !session$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\n# This is a locally defined event. Handle it with a priority greater than\n# negative 5 if you want to dig into the conn_info record before it's deleted.\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s). Subject: %s\", loc$country_code, ip, conn_log$subject),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s). Subject: %s\", loc$country_code, ip, conn_log$subject),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject)]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(id);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","old_contents":"# Copyright 2008 Seth Hall \n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that: (1) source code distributions\n# retain the above copyright notice and this paragraph in its entirety, (2)\n# distributions including binary code include the above copyright notice and\n# this paragraph in its entirety in the documentation or other materials\n# provided with the distribution, and (3) all advertising materials mentioning\n# features or use of this software display the following acknowledgement:\n# ``This product includes software developed by the University of California,\n# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of\n# the University nor the names of its contributors may be used to endorse\n# or promote products derived from this software without specific prior\n# written permission.\n# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\n# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\n# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t};\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/www\\.spamhaus\\.org\\\/\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/www\\.sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/www\\.dyndns\\.com\\\/.*spam\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n};\n\t\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=10secs;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal text_ip = \"\";\n\tlocal parts: string_array;\n\tif ( \/\\[.*\\]\/ in header )\n\t\tparts = split(header, \/[\\[\\]]\/);\n\telse if ( \/\\(.*\\)\/ in header )\n\t\tparts = split(header, \/[\\(\\)]\/);\n\n\tif (|parts| > 1)\n\t\t{\n\t\tif ( |parts| > 3 && parts[4] == ip_addr_regex )\n\t\t\ttext_ip = parts[4];\n\t\telse if ( parts[2] == ip_addr_regex )\n\t\t\ttext_ip = parts[2];\n\t\t}\n\treturn text_ip;\n}\n\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\t\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\n\tif ( \/^[^[:blank:]]*?:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tdelete in_received_from_headers[id];\n\tif ( \/^Received:[[:blank:]]\/ in data && id !in smtp_received_finished ) \n\t\tadd in_received_from_headers[id];\n\t\n\tlocal session = smtp_sessions[id];\n\t\n\tif ( session$in_header && # headers are currently being analyzed \n\t id in in_received_from_headers && # currently seeing received from headers\n\t id !in smtp_received_finished && # we don't want to stop seeing this message yet\n\t \/[\\[\\(]\/ in data ) # the line might contain an ip address\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n \n\t\t# check for valid-ish ip - some mtas are weird.\n\t\tif ( is_valid_ip(text_ip) )\n\t\t\t{\n\t\t\tlocal ip = to_addr(text_ip);\n\t\t\t\n\t\t\t# I don't care if mail bounces around on localhost\n\t\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\t\n\t\t\tif ( addr_matches_hosts(ip, mail_path_capture) || \n\t\t\t ip in private_address_space )\n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"%s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t} \n\t\t\telse \n\t\t\t\t{\n\t\t\t\tif (smtp_forward_paths[id] == \"\")\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s :: %s -> %s\", ip, id$orig_h, id$resp_h);\n\t\t\t\telse\n\t\t\t\t\tsmtp_forward_paths[id] = fmt(\"... %s -> %s\", ip, smtp_forward_paths[id]);\n\t\t\t\t\n\t\t\t\tadd smtp_received_finished[id]; \n\t\t\t\t}\n\t\t\t}\n\t\t} \n\telse if ( !session$in_header && id !in smtp_received_finished ) \n\t\t{\n\t\tadd smtp_received_finished[id];\n\t\t}\n\t}\n\n\nfunction end_smtp_extended_logging(id: conn_id)\n\t{\n\tif ( id !in conn_info )\n\t\treturn;\n\tlocal conn_log = conn_info[id];\n\t\n\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", network_time(), \n\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t conn_log$helo, conn_log$msg_id, conn_log$in_reply_to, \n\t conn_log$mailfrom, fmt_str_set(conn_log$rcptto, \/[\\\"\\'<>]|([[:blank:]].*$)\/),\n\t conn_log$date, conn_log$from, conn_log$reply_to, fmt_str_set(conn_log$to, \/[\\\"\\']\/),\n\t conn_log$last_reply, smtp_forward_paths[id]);\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( code >= 400 && id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal msg_parts = split_all(msg, ip_addr_regex);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |msg_parts| > 2 )\n\t\t\t\ttext_ip = msg_parts[2];\n\t\t\tif ( is_valid_ip(text_ip) && to_addr(text_ip) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note, \n\t\t\t $conn=c, \n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id in smtp_sessions )\n\t\t{\n\t\tif ( id !in conn_info )\n\t\t\tconn_info[id] = default_session_info();\n\t\tlocal conn_log = conn_info[id];\n\t\t\n\t\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\t\tconn_log$helo = arg;\n\t\t\n\t\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\t\n\t\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t\t{\n\t\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in conn_info )\n\t \treturn;\n\n\tlocal conn_log = conn_info[id];\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:[[:blank:]]\/ in data )\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[dD][aA][tT][eE]:[[:blank:]]\/ in data )\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\n\tif ( \/^[fF][rR][oO][mM]:[[:blank:]]\/ in data )\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\n\tif ( \/^[tT][oO]:[[:blank:]]\/ in data )\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\n\tif ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:[[:blank:]]\/ in data )\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c$id);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"8694889a2b8b40eea1f429d6eb297289049a19f1","subject":"Added Bro example","message":"Added Bro example","repos":"paladox\/ace,fjakobs\/ace,fjakobs\/ace,fjakobs\/ace,paladox\/ace,mlajtos\/ace,fjakobs\/ace,mlajtos\/ace,paladox\/ace,acanakoglu\/ace,fjakobs\/ace,robottomw\/ace,mlajtos\/ace,mlajtos\/ace,mlajtos\/ace,mlajtos\/ace,fjakobs\/ace,paladox\/ace,fjakobs\/ace,fjakobs\/ace,paladox\/ace,fjakobs\/ace,fjakobs\/ace,paladox\/ace,acanakoglu\/ace,fjakobs\/ace,paladox\/ace,fjakobs\/ace,paladox\/ace,paladox\/ace,robottomw\/ace,mlajtos\/ace,fjakobs\/ace,paladox\/ace,paladox\/ace,mlajtos\/ace,acanakoglu\/ace,paladox\/ace,robottomw\/ace,mlajtos\/ace,mlajtos\/ace,mlajtos\/ace,fjakobs\/ace,paladox\/ace,fjakobs\/ace,mlajtos\/ace,mlajtos\/ace,fjakobs\/ace,paladox\/ace,paladox\/ace,mlajtos\/ace,fjakobs\/ace,ektx\/ace,paladox\/ace,mlajtos\/ace,ektx\/ace,mlajtos\/ace,paladox\/ace,mlajtos\/ace,ektx\/ace,fjakobs\/ace,paladox\/ace,fjakobs\/ace,mlajtos\/ace","old_file":"demo\/kitchen-sink\/docs\/bro.bro","new_file":"demo\/kitchen-sink\/docs\/bro.bro","new_contents":"##! Add countries for the originator and responder of a connection\n##! to the connection logs.\n\nmodule Conn;\n\nexport {\n\tredef record Conn::Info += {\n\t\t## Country code for the originator of the connection based \n\t\t## on a GeoIP lookup.\n\t\torig_cc: string &optional &log;\n\t\t## Country code for the responser of the connection based \n\t\t## on a GeoIP lookup.\n\t\tresp_cc: string &optional &log;\n\t};\n}\n\nevent connection_state_remove(c: connection) \n\t{\n\tlocal orig_loc = lookup_location(c$id$orig_h);\n\tif ( orig_loc?$country_code )\n\t\tc$conn$orig_cc = orig_loc$country_code;\n\n\tlocal resp_loc = lookup_location(c$id$resp_h);\n\tif ( resp_loc?$country_code )\n\t\tc$conn$resp_cc = resp_loc$country_code;\n\t}","old_contents":"TODO add a nice demo!\nTry to keep it short!","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1ac32d69a15feeaba224009abb71a583757f89b1","subject":"rsyslog-invalid-pri.bro: set facility less than 128","message":"rsyslog-invalid-pri.bro: set facility less than 128\n","repos":"unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts,unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts","old_file":"rsyslog-invalid-pri.bro","new_file":"rsyslog-invalid-pri.bro","new_contents":"# Generates a notice and e-mail if syslog messages contain a PRI greater than 191 but less than 1016\n# fac: (23 but less than 127)\n# Vulnerability: http:\/\/www.rsyslog.com\/remote-syslog-pri-vulnerability\/\n#\n# To use:\n# 1. Add script to configuration local.bro: $ echo '@load rsyslog-invalid-pri.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# 2. Copy script to $BROPREFIX\/share\/bro\/site\n# 3. $ broctl check && broctl install && broctl restart\n# Testing: \n# mausezahn -t syslog severity=7,facility=24,host=mausezahn -P \"Invalid PRI message test\" -B 10.1.1.100\n# \n# Facility: Divide the PRI number by 8. \n# 191\/8 = 23\n# \n# Severity: multiply facility by 8 and subtract from PRI\n# 191 - (23 * 8 ) = 7\n# \n# PRI = Facility 23 and Priority (7)\n\n# Possible combinations:\n# for pri in {1..1016}; do FAC=\"$((pri\/8))\"; echo -e -n \"PRI:$pri Fac:$FAC Sev:$((pri - ($FAC * 8 )))\\n\"; done\n\n@load base\/frameworks\/notice\n\nexport {\n redef enum Notice::Type += {\n SYSLOG::Invalid_PRI\n };\n\n # List your NTP servers here \n const syslog_servers: set[addr] = {\n\t10.1.1.100\n } &redef;\n\n}\n\nredef Notice::emailed_types += {\n SYSLOG::Invalid_PRI\n};\n\nevent syslog_message(c: connection, facility: count, severity: count, msg: string)\n {\n\n if ( c$id$resp_h !in syslog_servers )\n return;\n\n\tlocal pri = (facility * 8) + severity;\n\n if (facility > 23 && facility < 128)\n {\n NOTICE([$note=SYSLOG::Invalid_PRI,\n\t\t$msg=fmt(\"Syslog message with invalid PRI of %d\", pri),\n $conn=c,\n $identifier=cat(c$id$orig_h,c$id$resp_h),\n $suppress_for=1day]);\n }\n }\n","old_contents":"# Generates a notice and e-mail if syslog messages contain a PRI greater than 191 but less than 1016\n# fac: (23 but less than 127)\n# Vulnerability: http:\/\/www.rsyslog.com\/remote-syslog-pri-vulnerability\/\n#\n# To use:\n# 1. Add script to configuration local.bro: $ echo '@load rsyslog-invalid-pri.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# 2. Copy script to $BROPREFIX\/share\/bro\/site\n# 3. $ broctl check && broctl install && broctl restart\n# Testing: \n# mausezahn -t syslog severity=7,facility=24,host=mausezahn -P \"Invalid PRI message test\" -B 10.1.1.100\n# \n# Facility: Divide the PRI number by 8. \n# 191\/8 = 23\n# \n# Severity: multiply facility by 8 and subtract from PRI\n# 191 - (23 * 8 ) = 7\n# \n# PRI = Facility 23 and Priority (7)\n\n# Possible combinations:\n# for pri in {1..1016}; do FAC=\"$((pri\/8))\"; echo -e -n \"PRI:$pri Fac:$FAC Sev:$((pri - ($FAC * 8 )))\\n\"; done\n\n@load base\/frameworks\/notice\n\nexport {\n redef enum Notice::Type += {\n SYSLOG::Invalid_PRI\n };\n\n # List your NTP servers here \n const syslog_servers: set[addr] = {\n\t10.1.1.100\n } &redef;\n\n}\n\nredef Notice::emailed_types += {\n SYSLOG::Invalid_PRI\n};\n\nevent syslog_message(c: connection, facility: count, severity: count, msg: string)\n {\n\n if ( c$id$resp_h !in syslog_servers )\n return;\n\n\tlocal pri = (facility * 8) + severity;\n\n if (facility > 23 && facility < 127)\n {\n NOTICE([$note=SYSLOG::Invalid_PRI,\n\t\t$msg=fmt(\"Syslog message with invalid PRI of %d\", pri),\n $conn=c,\n $identifier=cat(c$id$orig_h,c$id$resp_h),\n $suppress_for=1day]);\n }\n }\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"e7aaecfa45d624a5b63d116b4fc6f98ec4e2a9de","subject":"Allow use of tcpdump-like BPF","message":"Allow use of tcpdump-like BPF\n\nAdd the bro config which enables the tcpdump-style filter options, which vortex also supports, to be added to the command-line","repos":"ckane\/brotex","old_file":"local.bro","new_file":"local.bro","new_contents":"@load base\/frameworks\/packet-filter\n@load conn-contents.bro\n","old_contents":"@load conn-contents.bro\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"0be0e2a365ddc813cc5f0172ee1f81603b0aef9f","subject":"correct the notice msg, the direction in the wording is backwards","message":"correct the notice msg, the direction in the wording is backwards\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id];\n local blarg: set[conn_id];\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id];\n local blarg: set[conn_id];\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"%s is rejecting a high percentage of mail\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"3f25df1d559a943e7e83774ed630567a88f84173","subject":"Removed debugging code","message":"Removed debugging code\n","repos":"finarfin\/smbx,finarfin\/smbx","old_file":"scripts\/Custom\/SMB\/main.bro","new_file":"scripts\/Custom\/SMB\/main.bro","new_contents":"@load base\/frameworks\/files\n\nmodule SMBx;\n\nglobal smbports = { 139\/tcp, 445\/tcp };\nredef capture_filters = { [\"smb\"] = \"port 445\" };\n\nredef record connection += {\n\tsmbx: smb2_session &optional;\t\n};\n\nredef record Files::Info += {\n\tpath: string &optional &log;\t\n};\n\nevent bro_init() &priority=5\n{\n Analyzer::register_for_ports(Analyzer::ANALYZER_SMBX, smbports);\n}\n\nevent smb2_pre_file_transfer(c: connection, h: smb2_header, f: smb2_fileinfo)\n{\n\tif (!c?$smbx)\n\t{\n\t\tlocal t : table[string] of smb2_fileinfo &read_expire=5mins;\n\t\tlocal s: smb2_session = smb2_session();\n\t\ts$files = t;\n\t\tc$smbx = s;\n\t}\n\t\n\tc$smbx$files[f$id] = f;\n}\n\nevent file_over_new_connection(f: fa_file, c: connection, is_orig: bool) &priority=5\n{\n\tif (!c?$smbx || f$source != \"SMBX\") \n\t\treturn;\n\t\t\n\tif (f$id !in c$smbx$files) \n\t\treturn;\n\n\tlocal f2 = c$smbx$files[f$id];\n\tf$info$filename = f2$name;\n\tf$info$path = f2$path;\n}\n","old_contents":"@load base\/frameworks\/files\n\nmodule SMBx;\n\nglobal smbports = { 139\/tcp, 445\/tcp };\nredef capture_filters = { [\"smb\"] = \"port 445\" };\n\nredef record connection += {\n\tsmbx: smb2_session &optional;\t\n};\n\nredef record Files::Info += {\n\tpath: string &optional &log;\t\n};\n\nevent bro_init() &priority=5\n{\n Analyzer::register_for_ports(Analyzer::ANALYZER_SMBX, smbports);\n}\n\nevent smb2_pre_file_transfer(c: connection, h: smb2_header, f: smb2_fileinfo)\n{\n\tprint fmt(\"Hi!!\");\n\tif (!c?$smbx)\n\t{\n\t\tlocal t : table[string] of smb2_fileinfo &read_expire=5mins;\n\t\tlocal s: smb2_session = smb2_session();\n\t\ts$files = t;\n\t\tc$smbx = s;\n\t}\n\t\n\tc$smbx$files[f$id] = f;\n}\n\nevent file_over_new_connection(f: fa_file, c: connection, is_orig: bool) &priority=5\n{\n\tprint fmt(\"Here %s %s\", f$source, c?$smbx);\n\tif (!c?$smbx || f$source != \"SMBX\") \n\t\treturn;\n\t\t\n\tprint \"And Here\";\t\t\n\t\n\tif (f$id !in c$smbx$files) \n\t\treturn;\n\n\tprint \"And And Here\";\n\tlocal f2 = c$smbx$files[f$id];\n\tf$info$filename = f2$name;\n\tf$info$path = f2$path;\n}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1a12606363d24da4f2ceda03ae16d4211a8c6030","subject":"refactor","message":"refactor\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"log-external-dns.bro","new_file":"log-external-dns.bro","new_contents":"module DNS;\n\nexport {\n redef record Info += {\n is_external: bool &default=F;\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n 208.67.220.220\/32, #opendns\n } &redef;\n\n redef enum Notice::Type += {\n ## Indicates that a user is using an external DNS server\n EXTERNAL_DNS,\n\n ## Indicates that a user is using an external DNS server in \n ## a foreign country.\n EXTERNAL_FOREIGN_DNS,\n };\n\n redef Notice::type_suppression_intervals += {\n [EXTERNAL_DNS] = 12hr,\n [EXTERNAL_FOREIGN_DNS] = 12hr,\n };\n\n const local_countries: set[string] = {\n \"US\",\n } &redef;\n\n}\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\n local rec = c$dns;\n if(!rec$RD)\n return;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return;\n\n rec$is_external=T;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n\n when (local hostname = lookup_addr(resp_h)) {\n #Doesn't work for the log, but we can use it here :-(\n #rec$resp_h_hostname = hostname;\n\n local note = EXTERNAL_DNS;\n local nmsg = fmt(\"An external DNS server is in use %s(%s)\", resp_h, hostname);\n\n if(rec$cc !in local_countries){\n note = EXTERNAL_FOREIGN_DNS;\n nmsg = fmt(\"An external foreign(%s) DNS server is in use %s(%s).\", rec$cc, resp_h, hostname);\n }\n local ident = fmt(\"%s-%s\", orig_h, resp_h);\n NOTICE([$note=note,\n $msg=nmsg,\n $sub=fmt(\"%s\", resp_h),\n $identifier=ident,\n $conn=c]);\n \n }\n\n\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n\n return rec$is_external==T;\n return F;\n } ]);\n}\n","old_contents":"module DNS;\n\nexport {\n redef record Info += {\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n 208.67.220.220\/32, #opendns\n } &redef;\n\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n if(!rec$RD)\n return F;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return F;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return F;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n return T;\n\n } ]);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"4ce1c93eea633ed7ebab2cf2dfaef7d897dc2028","subject":"Fixed a problem with accurately recording the received headers.","message":"Fixed a problem with accurately recording the received headers.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"@load global-ext\n@load smtp\n\ntype smtp_ext_session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tfirst_received: string &default=\"\";\n\tsecond_received: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: set[string];\n\tpath: string &default=\"\";\n\tis_webmail: bool &default=F; # This is not being set yet.\n\tagent: string &default=\"\";\n\t\n\t# These are used during processing and are likely less useful.\n\tcurrent_header: string &default=\"\";\n\tin_received_from_headers: bool &default=F;\n\treceived_finished: bool &default=F;\n};\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, si: smtp_ext_session_info);\n\nmodule SMTP;\n\nexport {\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Hosts enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\nfunction default_smtp_ext_session_info(): smtp_ext_session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\tlocal tmp3: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2, $files=tmp3];\n\t}\n\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of smtp_ext_session_info &read_expire=4mins;\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\t# Throw the event for other scripts to handle\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_smtp_ext_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_smtp_ext_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tadd conn_info[id]$files[data];\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$current_header == \"received\" )\n\t\t\tconn_log$first_received += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\telse if ( conn_log$current_header == \"agent\" )\n\t\t\tconn_log$agent += data;\t\t\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\n\telse if ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data )\n\t\t{\n\t\tconn_log$second_received = conn_log$first_received;\n\t\tconn_log$first_received = split1(data, \/:[[:blank:]]*\/)[2];\n\t\t# Fill in the second value in case there is only one hop in the message.\n\t\tif ( conn_log$second_received == \"\" )\n\t\t\tconn_log$second_received = conn_log$first_received;\n\t\t\n\t\tconn_log$current_header = \"received\";\n\t\t}\n\t\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\telse if ( \/^[xX]-[mM][aA][iI][lL][eE][rR]:[[:blank:]]\/ | \n\t \/^[uU][sS][eE][rR]-[aA][gG][eE][nN][tT]:[[:blank:]]\/ in data )\n\t\t{\n\t\tconn_log$agent = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"agent\";\n\t\t}\n\t\n\t}\n\t\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header )\n\t\treturn;\n\n\tlocal conn_log = conn_info[id];\n\t\n\t# If we've decided that we're done watching the received headers, we're done.\n\tif ( conn_log$received_finished )\n\t\treturn;\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tconn_log$in_received_from_headers = T;\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tconn_log$in_received_from_headers = F;\n\n\tif ( conn_log$in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\n\t\tlocal ip = to_addr(text_ip);\n\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\n\t\tlocal ellipsis = \"\";\n\t\tif ( !resp_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tconn_log$received_finished=T;\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && !conn_log$received_finished ) \n\t\tconn_log$received_finished=T;\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"@load global-ext\n@load smtp\n\ntype smtp_ext_session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tfirst_received: string &default=\"\";\n\tsecond_received: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: set[string];\n\tpath: string &default=\"\";\n\tis_webmail: bool &default=F; # This is not being set yet.\n\tagent: string &default=\"\";\n\t\n\t# These are used during processing and are likely less useful.\n\tcurrent_header: string &default=\"\";\n\tin_received_from_headers: bool &default=F;\n\treceived_finished: bool &default=F;\n};\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, si: smtp_ext_session_info);\n\nmodule SMTP;\n\nexport {\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Hosts enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\nfunction default_smtp_ext_session_info(): smtp_ext_session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\tlocal tmp3: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2, $files=tmp3];\n\t}\n\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of smtp_ext_session_info &read_expire=4mins;\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\t\n\t# Throw the event for other scripts to handle\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_smtp_ext_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_smtp_ext_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tadd conn_info[id]$files[data];\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\telse if ( conn_log$current_header == \"agent\" )\n\t\t\tconn_log$agent += data;\t\t\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\n\telse if ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data )\n\t\t{\n\t\tconn_log$second_received = conn_log$first_received;\n conn_log$first_received = split1(data, \/:[[:blank:]]*\/)[2];\n conn_log$current_header = \"received\";\n\n\t\t# Fill in the second value in case there is only one hop in the message.\n\t\tif ( conn_log$second_received == \"\" )\n\t\t\t{\n\t\t\tconn_log$second_received = conn_log$first_received;\n\t\t\t}\n\t\t}\n\t\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\telse if ( \/^[xX]-[mM][aA][iI][lL][eE][rR]:[[:blank:]]\/ | \n\t \/^[uU][sS][eE][rR]-[aA][gG][eE][nN][tT]:[[:blank:]]\/ in data )\n\t\t{\n\t\tconn_log$agent = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"agent\";\n\t\t}\n\t\n\t}\n\t\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header )\n\t\treturn;\n\n\tlocal conn_log = conn_info[id];\n\t\n\t# If we've decided that we're done watching the received headers, we're done.\n\tif ( conn_log$received_finished )\n\t\treturn;\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tconn_log$in_received_from_headers = T;\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tconn_log$in_received_from_headers = F;\n\n\tif ( conn_log$in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\n\t\tlocal ip = to_addr(text_ip);\n\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\n\t\tlocal ellipsis = \"\";\n\t\tif ( !resp_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tconn_log$received_finished=T;\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && !conn_log$received_finished ) \n\t\tconn_log$received_finished=T;\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"7125efd1a66ce45632590b3e16ed2dd945a52ba0","subject":"Another bug fix. ssh-ext couldn't ever record geo location.","message":"Another bug fix. ssh-ext couldn't ever record geo location.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext.bro","new_file":"ssh-ext.bro","new_contents":"@load global-ext\n@load ssh\n@load notice\n\t\nmodule SSH;\n\nexport {\n\tconst ssh_ext_log = open_log_file(\"ssh-ext\") &raw_output;\n\t\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\ttype ssh_versions: record {\n\t\tclient: string &default=\"\";\n\t\tserver: string &default=\"\";\n\t};\n\t\n\t# Only monitor SSH connections for up to 15 minutes\n\tglobal active_ssh_conns: table[conn_id] of ssh_versions &create_expire=15mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\t\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal versions = active_ssh_conns[c$id];\n\tlocal status = \"failure\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $sub=location$country_code]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 20000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\t\t\n\tif ( (log_geodata_on_failure && status == \"failure\") ||\n\t status == \"success\" )\n\t\t{\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\t}\n\t\t\n\tprint ssh_ext_log, cat_sep(\"\\t\", \"\\\\N\", c$start_time,\n\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\tstatus, direction, \n\t\t\t\tlocation$country_code, location$region,\n\t\t\t\tversions$client, versions$server,\n\t\t\t\tc$resp$size);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +2mins { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_versions;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +2mins { ssh_watcher(c) }; \n\t\t}\n\t}\n","old_contents":"@load global-ext\n@load ssh\n@load notice\n\t\nmodule SSH;\n\nexport {\n\tconst ssh_ext_log = open_log_file(\"ssh-ext\") &raw_output;\n\t\n\tconst password_guesses_limit = 30 &redef;\n\tconst authentication_data_size = 5500 &redef;\n\tconst guessing_timeout = 30 mins;\n\t\n\t# Keeps count of how many rejections a host has had\n\tglobal password_rejections: table[addr] of count &default=0 &write_expire=guessing_timeout;\n\t# Keeps track of hosts identified as guessing passwords\n\tglobal password_guessers: set[addr] &read_expire=guessing_timeout+1hr;\n\t\n\ttype ssh_versions: record {\n\t\tclient: string &default=\"\";\n\t\tserver: string &default=\"\";\n\t};\n\t\n\t# Only monitor SSH connections for up to 15 minutes\n\tglobal active_ssh_conns: table[conn_id] of ssh_versions &create_expire=15mins;\n\t\n\t# If you want to lookup and log geoip data in the event of a failed login.\n\tconst log_geodata_on_failure = F &redef;\n\t\n\t# The set of countries for which you'd like to throw notices upon successful login\n\t# requires Bro compiled with libGeoIP support\n\tconst watched_countries: set[string] = {\"RO\"} &redef;\n\t\n\t# Strange\/bad host names to originate successful SSH logins\n\tconst strange_hostnames =\n\t\t\t\/^d?ns[0-9]*\\.\/ |\n\t\t\t\/^smtp[0-9]*\\.\/ |\n\t\t\t\/^mail[0-9]*\\.\/ |\n\t\t\t\/^pop[0-9]*\\.\/ |\n\t\t\t\/^imap[0-9]*\\.\/ |\n\t\t\t\/^www[0-9]*\\.\/ |\n\t\t\t\/^ftp[0-9]*\\.\/ &redef;\n\n\t# This is a table with orig subnet as the key, and subnet as the value.\n\tconst ignore_guessers: table[subnet] of subnet &redef;\n\t\n\tredef enum Notice += {\n\t\tSSH_Login,\n\t\tSSH_PasswordGuessing,\n\t\tSSH_LoginByPasswordGuesser,\n\t\tSSH_Login_From_Strange_Hostname,\n\t\tSSH_Bytecount_Inconsistency,\n\t};\n} \n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a successful ssh login happens from or to a watched country\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_Login && n$sub in watched_countries); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a password guesser logs in successfully anywhere\n#\t# To avoid false positives, setting the lower bound for notification to 50 bad password attempts.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_LoginByPasswordGuesser && n$n > 50); },\n#\t $result = NOTICE_EMAIL],\n#\n#\t# Send email if a local host is password guessing.\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SSH::SSH_PasswordGuessing && \n#\t\t is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL], \n#};\n\n# Don't stop processing SSH connections in the default ssh policy script\nredef skip_processing_after_handshake = F;\n\nevent check_ssh_connection(c: connection, done: bool)\n\t{\n\t# If this is no longer a known SSH connection, just return.\n\tif ( c$id !in active_ssh_conns )\n\t\treturn;\n\t\n\t# If this is still a live connection and the byte count has not\n\t# crossed the threshold, just return and let the resheduled check happen later.\n\tif ( !done && c$resp$size < authentication_data_size )\n\t\treturn;\n\n\t# Make sure the server has sent back more than 50 bytes to filter out\n\t# hosts that are just port scanning. Nothing is ever logged if the server\n\t# doesn't send back at least 50 bytes.\n\tif (c$resp$size < 50)\n\t\treturn;\n\t\n\tlocal versions = active_ssh_conns[c$id];\n\tlocal status = \"\";\n\tlocal direction = is_local_addr(c$id$orig_h) ? \"to\" : \"from\";\n\tlocal location: geo_location;\n\t# Need to give these values defaults in bro.init.\n\tlocation$country_code=\"\"; location$region=\"\"; location$city=\"\"; location$latitude=0.0; location$longitude=0.0;\n\tif ( (log_geodata_on_failure && status == \"failure\") ||\n\t status == \"success\" )\n\t\tlocation = (direction == \"to\") ? lookup_location(c$id$resp_h) : lookup_location(c$id$orig_h);\n\t\n\tif ( done && c$resp$size < authentication_data_size ) \n\t\t{\n\t\t# presumed failure\n\t\tstatus = \"failure\";\n\n\t\t# Track the number of rejections\n\t\tif ( !(c$id$orig_h in ignore_guessers &&\n\t\t c$id$resp_h in ignore_guessers[c$id$orig_h]) )\n\t\t\tpassword_rejections[c$id$orig_h] += 1;\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit && \n\t\t c$id$orig_h !in password_guessers )\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_PasswordGuessing,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"SSH password guessing by %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h]),\n\t\t\t $n=password_rejections[c$id$orig_h]]);\n\t\t\t}\n\t\t} \n\t# TODO: This is to work around a quasi-bug in Bro which occasionally \n\t# causes the byte count to be oversized.\n\telse if (c$resp$size < 20000000) \n\t\t{ \n\t\t# presumed successful login\n\t\tstatus = \"success\";\n\n\t\tif ( password_rejections[c$id$orig_h] > password_guesses_limit &&\n\t\t c$id$orig_h !in password_guessers)\n\t\t\t{\n\t\t\tadd password_guessers[c$id$orig_h];\n\t\t\tNOTICE([$note=SSH_LoginByPasswordGuesser,\n\t\t\t $conn=c,\n\t\t\t $n=password_rejections[c$id$orig_h],\n\t\t\t $msg=fmt(\"Successful SSH login by password guesser %s\", c$id$orig_h),\n\t\t\t $sub=fmt(\"%d failed logins\", password_rejections[c$id$orig_h])]);\n\t\t\t}\n\n\t\tlocal message = fmt(\"SSH login %s %s \\\"%s\\\" \\\"%s\\\" %f %f %s (triggered with %d bytes)\",\n\t\t direction, location$country_code, location$region, location$city,\n\t\t location$latitude, location$longitude,\n\t\t numeric_id_string(c$id), c$resp$size);\n\t\t# TODO: rewrite the message once a location variable can be put in notices\n\t\tNOTICE([$note=SSH_Login,\n\t\t $conn=c,\n\t\t $msg=message,\n\t\t $sub=location$country_code]);\n\t\t\n\t\t# Check to see if this login came from a weird hostname (nameserver, mail server, etc.)\n\t\twhen( local hostname = lookup_addr(c$id$orig_h) )\n\t\t\t{\n\t\t\tif ( strange_hostnames in hostname )\n\t\t\t\t{\n\t\t\t\tNOTICE([$note=SSH_Login_From_Strange_Hostname,\n\t\t\t\t $conn=c,\n\t\t\t\t $msg=fmt(\"Strange login from %s\", hostname),\n\t\t\t\t $sub=hostname]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse if (c$resp$size >= 20000000) \n\t\t{\n\t\tNOTICE([$note=SSH_Bytecount_Inconsistency,\n\t\t $conn=c,\n\t\t $msg=\"During byte counting in extended SSH analysis, an overly large value was seen.\",\n\t\t $sub=fmt(\"%d\",c$resp$size)]);\n\t\t}\n\n\tprint ssh_ext_log, cat_sep(\"\\t\", \"\\\\N\", c$start_time,\n\t\t\t\tc$id$orig_h, fmt(\"%d\", c$id$orig_p),\n\t\t\t\tc$id$resp_h, fmt(\"%d\", c$id$resp_p),\n\t\t\t\tstatus, direction, \n\t\t\t\tlocation$country_code, location$region,\n\t\t\t\tversions$client, versions$server,\n\t\t\t\tc$resp$size);\n\n\tdelete active_ssh_conns[c$id];\n\t# Stop watching this connection, we don't care about it anymore.\n\tskip_further_processing(c$id);\n\tset_record_packets(c$id, F);\n\t}\n\nevent connection_state_remove(c: connection)\n\t{\n\tevent check_ssh_connection(c, T);\n\t}\n\nevent ssh_watcher(c: connection)\n\t{\n\tlocal id = c$id;\n\t# don't go any further if this connection is gone already!\n\tif ( !connection_exists(id) )\n\t\t{\n\t\tdelete active_ssh_conns[id];\n\t\treturn;\n\t\t}\n\n\tevent check_ssh_connection(c, F);\n\tif ( c$id in active_ssh_conns )\n\t\tschedule +2mins { ssh_watcher(c) };\n\t}\n\t\nevent ssh_client_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$client = version;\n\t}\n\nevent ssh_server_version(c: connection, version: string)\n\t{\n\tif ( c$id in active_ssh_conns )\n\t\tactive_ssh_conns[c$id]$server = version;\n\t}\n\nevent protocol_confirmation(c: connection, atype: count, aid: count)\n\t{\n\tif ( atype == ANALYZER_SSH )\n\t\t{\n\t\tlocal tmp: ssh_versions;\n\t\tactive_ssh_conns[c$id]=tmp;\n\t\tschedule +2mins { ssh_watcher(c) }; \n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"4c2a05ab3496e13d3dd6e617e0a97206a9ea767e","subject":"Updating the version check code","message":"Updating the version check code\n\nPrevious code calls a function which does not seem to work or exist in bro 2.5.","repos":"salesforce\/ja3","old_file":"bro\/ja3s.bro","new_file":"bro\/ja3s.bro","new_contents":"# This Bro script appends JA3S (JA3 Server) to ssl.log\n# Version 1.0 (August 2018)\n# This builds a fingerprint for the SSL Server Hello packet based on SSL\/TLS version, cipher picked, and extensions used. \n# Designed to be used in conjunction with JA3 to fingerprint SSL communication between clients and servers.\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) Jeff Atkinson (jatkinson@salesforce.com)\n# Copyright (c) 2018, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n#\n\n\n\nmodule JA3_Server;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype JA3Sstorage: record {\n server_version: count &default=0 &log;\n server_cipher: count &default=0 &log;\n server_extensions: string &default=\"\" &log;\n};\n\nredef record connection += {\n ja3sfp: JA3Sstorage &optional;\n};\n\nredef record SSL::Info += {\n ja3s: string &optional &log;\n# LOG FIELD VALUES #\n# ja3s_version: string &optional &log;\n# ja3s_cipher: string &optional &log;\n# ja3s_extensions: string &optional &log;\n};\n\n\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3_Server::LOG,[$columns=JA3Sstorage, $path=\"ja3sfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$ja3sfp )\n c$ja3sfp=JA3Sstorage();\n if ( is_orig == F ) { \n if ( c$ja3sfp$server_extensions == \"\" ) {\n c$ja3sfp$server_extensions = cat(code);\n }\n else {\n c$ja3sfp$server_extensions = string_cat(c$ja3sfp$server_extensions, sep,cat(code));\n }\n }\n}\n\n@if ( ( Version::number >= 20600 ) || ( Version::number == 20500 && Version::info$commit >= 944 ) )\nevent ssl_server_hello(c: connection, version: count, record_version: count, possible_ts: time, server_random: string, session_id: string, cipher: count, comp_method: count) &priority=1\n@else\nevent ssl_server_hello(c: connection, version: count, possible_ts: time, server_random: string, session_id: string, cipher: count, comp_method: count) &priority=1\n@endif\n{\n if ( !c?$ja3sfp )\n c$ja3sfp=JA3Sstorage();\n c$ja3sfp$server_version = version;\n c$ja3sfp$server_cipher = cipher;\n local sep2 = \",\";\n local ja3s_string = string_cat(cat(c$ja3sfp$server_version),sep2,cat(c$ja3sfp$server_cipher),sep2,c$ja3sfp$server_extensions);\n local ja3sfp_1 = md5_hash(ja3s_string);\n c$ssl$ja3s = ja3sfp_1;\n\n# LOG FIELD VALUES #\n#c$ssl$ja3s_version = cat(c$ja3sfp$server_version);\n#c$ssl$ja3s_cipher = cat(c$ja3sfp$server_cipher);\n#c$ssl$ja3s_extensions = c$ja3sfp$server_extensions;\n#\n# FOR DEBUGGING #\n#print \"JA3S: \"+ja3sfp_1+\" Fingerprint String: \"+ja3s_string;\n\n}\n","old_contents":"# This Bro script appends JA3S (JA3 Server) to ssl.log\n# Version 1.0 (August 2018)\n# This builds a fingerprint for the SSL Server Hello packet based on SSL\/TLS version, cipher picked, and extensions used. \n# Designed to be used in conjunction with JA3 to fingerprint SSL communication between clients and servers.\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) Jeff Atkinson (jatkinson@salesforce.com)\n# Copyright (c) 2018, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n#\n\n\n\nmodule JA3_Server;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype JA3Sstorage: record {\n server_version: count &default=0 &log;\n server_cipher: count &default=0 &log;\n server_extensions: string &default=\"\" &log;\n};\n\nredef record connection += {\n ja3sfp: JA3Sstorage &optional;\n};\n\nredef record SSL::Info += {\n ja3s: string &optional &log;\n# LOG FIELD VALUES #\n# ja3s_version: string &optional &log;\n# ja3s_cipher: string &optional &log;\n# ja3s_extensions: string &optional &log;\n};\n\n\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3_Server::LOG,[$columns=JA3Sstorage, $path=\"ja3sfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$ja3sfp )\n c$ja3sfp=JA3Sstorage();\n if ( is_orig == F ) { \n if ( c$ja3sfp$server_extensions == \"\" ) {\n c$ja3sfp$server_extensions = cat(code);\n }\n else {\n c$ja3sfp$server_extensions = string_cat(c$ja3sfp$server_extensions, sep,cat(code));\n }\n }\n}\n\n@if ( Version::at_least(\"2.6\") || ( Version::number == 20500 && Version::info$commit >= 944 ) )\nevent ssl_server_hello(c: connection, version: count, record_version: count, possible_ts: time, server_random: string, session_id: string, cipher: count, comp_method: count) &priority=1\n@else\nevent ssl_server_hello(c: connection, version: count, possible_ts: time, server_random: string, session_id: string, cipher: count, comp_method: count) &priority=1\n@endif\n{\n if ( !c?$ja3sfp )\n c$ja3sfp=JA3Sstorage();\n c$ja3sfp$server_version = version;\n c$ja3sfp$server_cipher = cipher;\n local sep2 = \",\";\n local ja3s_string = string_cat(cat(c$ja3sfp$server_version),sep2,cat(c$ja3sfp$server_cipher),sep2,c$ja3sfp$server_extensions);\n local ja3sfp_1 = md5_hash(ja3s_string);\n c$ssl$ja3s = ja3sfp_1;\n\n# LOG FIELD VALUES #\n#c$ssl$ja3s_version = cat(c$ja3sfp$server_version);\n#c$ssl$ja3s_cipher = cat(c$ja3sfp$server_cipher);\n#c$ssl$ja3s_extensions = c$ja3sfp$server_extensions;\n#\n# FOR DEBUGGING #\n#print \"JA3S: \"+ja3sfp_1+\" Fingerprint String: \"+ja3s_string;\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"1e8237e748e787094e5af2c2b799c8443fe29745","subject":"phishing counter table should be create_expire","message":"phishing counter table should be create_expire\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-phish-passwords.bro","new_file":"smtp-ext-phish-passwords.bro","new_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &create_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s\", si$mailfrom, to),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n if(++(phishing_counter[si$mailfrom]) > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","old_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &write_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s\", si$mailfrom, to),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n if(++(phishing_counter[si$mailfrom]) > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"6498b05170409a0c49676a9f387c46fb5a2c809a","subject":"filter mdns log in bro","message":"filter mdns log in bro\n","repos":"firewalla\/firewalla,firewalla\/firewalla,firewalla\/firewalla,MelvinTo\/firewalla,MelvinTo\/firewalla,firewalla\/firewalla,MelvinTo\/firewalla,MelvinTo\/firewalla,firewalla\/firewalla,MelvinTo\/firewalla","old_file":"etc\/local.bro","new_file":"etc\/local.bro","new_contents":"##! Local site policy. Customize as appropriate. \n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\nredef ignore_checksums = T;\nredef SSL::disable_analyzer_after_detection = F;\n\n#@load site\/sqlite.bro\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n@load tuning\/json-logs\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Log some information about web applications being used by users \n# on your network.\n@load misc\/app-stats\n\n# Detect traceroute being run on the network. \n@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more \n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n@load frameworks\/software\/windows-version-detection\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when \n# running on live traffic. Enable it cautiously.\n#@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets \n# where the name is not part of your local DNS zone and is being hosted \n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n# @load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and \n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\n\n# enable link-layer address information to connection logs\n#@load policy\/protocols\/conn\/mac-logging\n\nredef restrict_filters += [[\"not-mdns\"] = \"not port 5353\"];\n\nredef SSL::disable_analyzer_after_detection = F;\nredef Communication::listen_interface = 127.0.0.1;\n\n@load base\/protocols\/dhcp\n","old_contents":"##! Local site policy. Customize as appropriate. \n##!\n##! This file will not be overwritten when upgrading or reinstalling!\n\nredef ignore_checksums = T;\nredef SSL::disable_analyzer_after_detection = F;\n\n#@load site\/sqlite.bro\n\n# This script logs which scripts were loaded during each run.\n@load misc\/loaded-scripts\n\n# Apply the default tuning scripts for common tuning settings.\n@load tuning\/defaults\n@load tuning\/json-logs\n\n# Load the scan detection script.\n@load misc\/scan\n\n# Log some information about web applications being used by users \n# on your network.\n@load misc\/app-stats\n\n# Detect traceroute being run on the network. \n@load misc\/detect-traceroute\n\n# Generate notices when vulnerable versions of software are discovered.\n# The default is to only monitor software found in the address space defined\n# as \"local\". Refer to the software framework's documentation for more \n# information.\n@load frameworks\/software\/vulnerable\n\n# Detect software changing (e.g. attacker installing hacked SSHD).\n@load frameworks\/software\/version-changes\n@load frameworks\/software\/windows-version-detection\n\n# This adds signatures to detect cleartext forward and reverse windows shells.\n@load-sigs frameworks\/signatures\/detect-windows-shells\n\n# Load all of the scripts that detect software in various protocols.\n@load protocols\/ftp\/software\n@load protocols\/smtp\/software\n@load protocols\/ssh\/software\n@load protocols\/http\/software\n# The detect-webapps script could possibly cause performance trouble when \n# running on live traffic. Enable it cautiously.\n#@load protocols\/http\/detect-webapps\n\n# This script detects DNS results pointing toward your Site::local_nets \n# where the name is not part of your local DNS zone and is being hosted \n# externally. Requires that the Site::local_zones variable is defined.\n@load protocols\/dns\/detect-external-names\n\n# Script to detect various activity in FTP sessions.\n@load protocols\/ftp\/detect\n\n# Scripts that do asset tracking.\n@load protocols\/conn\/known-hosts\n@load protocols\/conn\/known-services\n@load protocols\/ssl\/known-certs\n\n# This script enables SSL\/TLS certificate validation.\n@load protocols\/ssl\/validate-certs\n\n# This script prevents the logging of SSL CA certificates in x509.log\n@load protocols\/ssl\/log-hostcerts-only\n\n# Uncomment the following line to check each SSL certificate hash against the ICSI\n# certificate notary service; see http:\/\/notary.icsi.berkeley.edu .\n# @load protocols\/ssl\/notary\n\n# If you have libGeoIP support built in, do some geographic detections and \n# logging for SSH traffic.\n@load protocols\/ssh\/geo-data\n# Detect hosts doing SSH bruteforce attacks.\n@load protocols\/ssh\/detect-bruteforcing\n# Detect logins using \"interesting\" hostnames.\n@load protocols\/ssh\/interesting-hostnames\n\n# Detect SQL injection attacks.\n@load protocols\/http\/detect-sqli\n\n#### Network File Handling ####\n\n# Enable MD5 and SHA1 hashing for all files.\n@load frameworks\/files\/hash-all-files\n\n# Detect SHA1 sums in Team Cymru's Malware Hash Registry.\n@load frameworks\/files\/detect-MHR\n\n# Uncomment the following line to enable detection of the heartbleed attack. Enabling\n# this might impact performance a bit.\n@load policy\/protocols\/ssl\/heartbleed\n\n# enable link-layer address information to connection logs\n#@load policy\/protocols\/conn\/mac-logging\n\nredef SSL::disable_analyzer_after_detection = F;\nredef Communication::listen_interface = 127.0.0.1;\n\n@load base\/protocols\/dhcp\n","returncode":0,"stderr":"","license":"agpl-3.0","lang":"Bro"} {"commit":"62f60faa5c6ac53ff9b48ec93b2646190a1f5479","subject":"Change bro_init to zeek_init","message":"Change bro_init to zeek_init\n","repos":"corelight\/bro-long-connections","old_file":"scripts\/main.bro","new_file":"scripts\/main.bro","new_contents":"@load base\/protocols\/conn\n@load base\/utils\/time\n\n\n# This is probably not so great to reach into the Conn namespace..\nmodule Conn;\n\nexport {\nfunction set_conn_log_data_hack(c: connection)\n\t{\n\tConn::set_conn(c, T);\n\t}\n}\n\n# Now onto the actual code for this script...\n\nmodule LongConnection;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += {\n\t\t## Notice for when a long connection is found.\n\t\t## The `sub` field in the notice represents the number\n\t\t## of seconds the connection has currently been alive.\n\t\tLongConnection::found\n\t};\n\n\t## Aliasing vector of interval values as\n\t## \"Durations\"\n\ttype Durations: vector of interval;\n\n\t## The default duration that you are locally \n\t## considering a connection to be \"long\". \n\tconst default_durations = Durations(10min, 30min, 1hr, 12hr, 24hrs, 3days) &redef;\n\n\t## These are special cases for particular hosts or subnets\n\t## that you may want to watch for longer or shorter\n\t## durations than the default.\n\tconst special_cases: table[subnet] of Durations = {} &redef;\n}\n\nredef record connection += {\n\t## Offset of the currently watched connection duration by the long-connections script.\n\tlong_conn_offset: count &default=0;\n};\n\nevent zeek_init() &priority=5\n\t{\n\tLog::create_stream(LOG, [$columns=Conn::Info, $path=\"conn_long\"]);\n\t}\n\nfunction get_durations(c: connection): Durations\n\t{\n\tlocal check_it: Durations;\n\tif ( c$id$orig_h in special_cases )\n\t\tcheck_it = special_cases[c$id$orig_h];\n\telse if ( c$id$resp_h in special_cases )\n\t\tcheck_it = special_cases[c$id$resp_h];\n\telse\n\t\tcheck_it = default_durations;\n\n\treturn check_it;\n\t}\n\nfunction long_callback(c: connection, cnt: count): interval\n\t{\n\tlocal check_it = get_durations(c);\n\n\tif ( c$long_conn_offset < |check_it| && c$duration >= check_it[c$long_conn_offset] )\n\t\t{\n\t\tConn::set_conn_log_data_hack(c);\n\t\tLog::write(LongConnection::LOG, c$conn);\n\n\t\tlocal message = fmt(\"%s -> %s:%s remained alive for longer than %s\", \n\t\t c$id$orig_h, c$id$resp_h, c$id$resp_p, duration_to_mins_secs(c$duration));\n\t\tNOTICE([$note=LongConnection::found,\n\t\t $msg=message,\n\t\t $sub=fmt(\"%.2f\", c$duration),\n\t\t $conn=c]);\n\t\t\n\t\t++c$long_conn_offset;\n\t\t}\n\n\t# Keep watching if there are potentially more thresholds.\n\tif ( c$long_conn_offset < |check_it| )\n\t\treturn check_it[c$long_conn_offset];\n\telse\n\t\treturn -1sec;\n\t}\n\nevent connection_established(c: connection)\n\t{\n\tlocal check = get_durations(c);\n\tif ( |check| > 0 )\n\t\t{\n\t\tConnPolling::watch(c, long_callback, 1, check[0]);\n\t\t}\n\t}\n","old_contents":"@load base\/protocols\/conn\n@load base\/utils\/time\n\n\n# This is probably not so great to reach into the Conn namespace..\nmodule Conn;\n\nexport {\nfunction set_conn_log_data_hack(c: connection)\n\t{\n\tConn::set_conn(c, T);\n\t}\n}\n\n# Now onto the actual code for this script...\n\nmodule LongConnection;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += {\n\t\t## Notice for when a long connection is found.\n\t\t## The `sub` field in the notice represents the number\n\t\t## of seconds the connection has currently been alive.\n\t\tLongConnection::found\n\t};\n\n\t## Aliasing vector of interval values as\n\t## \"Durations\"\n\ttype Durations: vector of interval;\n\n\t## The default duration that you are locally \n\t## considering a connection to be \"long\". \n\tconst default_durations = Durations(10min, 30min, 1hr, 12hr, 24hrs, 3days) &redef;\n\n\t## These are special cases for particular hosts or subnets\n\t## that you may want to watch for longer or shorter\n\t## durations than the default.\n\tconst special_cases: table[subnet] of Durations = {} &redef;\n}\n\nredef record connection += {\n\t## Offset of the currently watched connection duration by the long-connections script.\n\tlong_conn_offset: count &default=0;\n};\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(LOG, [$columns=Conn::Info, $path=\"conn_long\"]);\n\t}\n\nfunction get_durations(c: connection): Durations\n\t{\n\tlocal check_it: Durations;\n\tif ( c$id$orig_h in special_cases )\n\t\tcheck_it = special_cases[c$id$orig_h];\n\telse if ( c$id$resp_h in special_cases )\n\t\tcheck_it = special_cases[c$id$resp_h];\n\telse\n\t\tcheck_it = default_durations;\n\n\treturn check_it;\n\t}\n\nfunction long_callback(c: connection, cnt: count): interval\n\t{\n\tlocal check_it = get_durations(c);\n\n\tif ( c$long_conn_offset < |check_it| && c$duration >= check_it[c$long_conn_offset] )\n\t\t{\n\t\tConn::set_conn_log_data_hack(c);\n\t\tLog::write(LongConnection::LOG, c$conn);\n\n\t\tlocal message = fmt(\"%s -> %s:%s remained alive for longer than %s\", \n\t\t c$id$orig_h, c$id$resp_h, c$id$resp_p, duration_to_mins_secs(c$duration));\n\t\tNOTICE([$note=LongConnection::found,\n\t\t $msg=message,\n\t\t $sub=fmt(\"%.2f\", c$duration),\n\t\t $conn=c]);\n\t\t\n\t\t++c$long_conn_offset;\n\t\t}\n\n\t# Keep watching if there are potentially more thresholds.\n\tif ( c$long_conn_offset < |check_it| )\n\t\treturn check_it[c$long_conn_offset];\n\telse\n\t\treturn -1sec;\n\t}\n\nevent connection_established(c: connection)\n\t{\n\tlocal check = get_durations(c);\n\tif ( |check| > 0 )\n\t\t{\n\t\tConnPolling::watch(c, long_callback, 1, check[0]);\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"3402339ed46057bfbd873ee73f5ddf3149d38eca","subject":"Turn off tagged json for now","message":"Turn off tagged json for now","repos":"mocyber\/rock-scripts","old_file":"plugins\/kafka.bro","new_file":"plugins\/kafka.bro","new_contents":"\n## Setup Kafka output\n@load Bro\/Kafka\/logs-to-kafka\n\nredef Kafka::topic_name = \"bro_raw\";\nredef Kafka::json_timestamps = JSON::TS_ISO8601;\nredef Kafka::tag_json = F;\n\n## Setup event extension to include sensor and probe name\ntype Extension: record {\n ## The name of the system that wrote this log. This\n ## is defined in the const so that\n ## a system running lots of processes can give the\n ## same value for any process that writes a log.\n system: string &log;\n ## The name of the process that wrote the log. In\n ## clusters, this will typically be the name of the\n ## worker that wrote the log.\n proc: string &log;\n};\n\nfunction add_log_extension(path: string): Extension\n{\n return Extension($system = ROCK::sensor_id,\n $proc = peer_description);\n}\n\nredef Log::default_ext_func = add_log_extension;\nredef Log::default_ext_prefix = \"@\";\nredef Log::default_scope_sep = \"_\";\n","old_contents":"\n## Setup Kafka output\n@load Bro\/Kafka\/logs-to-kafka\n\nredef Kafka::topic_name = \"bro_raw\";\nredef Kafka::json_timestamps = JSON::TS_ISO8601;\nredef Kafka::tag_json = T;\n\n## Setup event extension to include sensor and probe name\ntype Extension: record {\n ## The name of the system that wrote this log. This\n ## is defined in the const so that\n ## a system running lots of processes can give the\n ## same value for any process that writes a log.\n system: string &log;\n ## The name of the process that wrote the log. In\n ## clusters, this will typically be the name of the\n ## worker that wrote the log.\n proc: string &log;\n};\n\nfunction add_log_extension(path: string): Extension\n{\n return Extension($system = ROCK::sensor_id,\n $proc = peer_description);\n}\n\nredef Log::default_ext_func = add_log_extension;\nredef Log::default_ext_prefix = \"@\";\nredef Log::default_scope_sep = \"_\";\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"ff332258aeece98df94e184a6ab83097f3603da0","subject":"Fixed a bug with the notice generation.","message":"Fixed a bug with the notice generation.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal cc_parts = split_all(data, cc_regex);\n\t\t\tfor ( i in cc_parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = cc_parts[i];\n\t\t\t\t\tcc_parts[i] = gsub(cc_parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tlocal redacted_data = join_string_array(\"\", cc_parts);\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tlocal cc_location = strstr(data, ccp);\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_redacted_data),\n\t\t\t $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? gsub(ccp, \/[0-9]\/, redaction_char) : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","old_contents":"\n@load .\/bin-list\n\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Bank Indentification number information\n\t\tbank: Bank &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9\\-])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9\\-]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal cc_parts = split_all(data, cc_regex);\n\t\t\tfor ( i in cc_parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tlocal cc_match = cc_parts[i];\n\t\t\t\t\tcc_parts[i] = gsub(cc_parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tlocal redacted_data = join_string_array(\"\", cc_parts);\n\n\t\t\t# Trim the data\n\t\t\tlocal begin = 0;\n\t\t\tlocal cc_location = strstr(data, ccp);\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_redacted_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_redacted_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? gsub(ccp, \/[0-9]\/, redaction_char) : ccp),\n\t\t\t $data=(redact_log ? trimmed_redacted_data : sub_bytes(data, begin, byte_count))];\n\n\t\t\tlocal bin_number = to_count(sub_bytes(gsub(ccp, \/[^0-9]\/, \"\"), 1, 6));\n\t\t\tif ( bin_number in bin_list )\n\t\t\t\tlog$bank = bin_list[bin_number];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"2193d000ee5988bb06eea1285f7efabe569dddf6","subject":"The problem of header printing multiple times is showing up again. Hopefully this fixes it.","message":"The problem of header printing multiple times is showing up again. Hopefully this fixes it.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"logging-ext.bro","new_file":"logging-ext.bro","new_contents":"module LOG;\n\nexport {\n\t# The record type to store logging information.\n\ttype log_info: record {\n\t\tdh: Directions_and_Hosts &default=All;\n\t\tsplit: bool &default=F;\n\t\traw_output: bool &default=F;\n\t\theader: string &default=\"\";\n\t\tfiles: table[string] of file;\n\t\ttags: set[string];\n\t};\n\t\n\t# Where the data for knowing how to log is stored.\n\tconst logs: table[string] of log_info &redef;\n\n\t# Utility functions\n\tglobal get_file_by_addr: function(a: string, ip: addr, force_log: bool): file;\n\tglobal get_file_by_id: function(a: string, id: conn_id, force_log: bool): file;\n\tglobal print_log_by_addr: function(a: string, ip: addr, force_log: bool, tags: set[string], line: string): count;\n\tglobal print_log_by_id: function(a: string, id: conn_id, force_log: bool, tags: set[string], line: string): count;\n\tglobal open_log_files: function(a: string, tag: string);\n\tglobal create_logs: function(a: string, d: Directions_and_Hosts, split: bool, raw: bool);\n\tglobal define_header: function(a: string, h: string);\n\tglobal define_tag: function(a: string, tag: string);\n\tglobal buffer: function(a: string, value: bool);\n\t\n\t# This is dumb, but it helps avoid needing to duplicate code on the\n\t# printing side.\n\tconst null_file: file = open_log_file(\"null\");\n}\n\nfunction get_file_by_addr(a: string, ip: addr, force_log: bool): file\n\t{\n\tlocal i = logs[a];\n\tif ( !force_log && !addr_matches_hosts(ip, i$dh) )\n\t\treturn LOG::null_file;\n\n\tif ( i$split && |local_nets| > 0 )\n\t\t{\n\t\tif ( is_local_addr(ip) )\n\t\t\treturn i$files[\"split1-log\"];\n\t\telse\n\t\t\treturn i$files[\"split2-log\"];\n\t\t}\n\telse\n\t\t{\n\t\treturn i$files[\"combined-log\"];\n\t\t}\n\t}\n\t\nfunction get_file_by_id(a: string, id: conn_id, force_log: bool): file\n\t{\n\tlocal i = logs[a];\n\tif ( !force_log && !id_matches_directions(id, i$dh) )\n\t\treturn LOG::null_file;\n\n\tif ( i$split && |local_nets| > 0 )\n\t\t{\n\t\tif ( is_local_addr(id$resp_h) )\n\t\t\treturn i$files[\"split1-log\"];\n\t\telse\n\t\t\treturn i$files[\"split2-log\"];\n\t\t}\n\telse\n\t\t{\n\t\treturn i$files[\"combined-log\"];\n\t\t}\n\t}\n\t\nfunction print_log_by_addr(a: string, ip: addr, force_log: bool, tags: set[string], line: string): count\n\t{\n\tlocal log = get_file_by_addr(a, ip, force_log);\n\tprint log, line;\n\t\n\tlocal lines_printed=0;\n\tif ( get_file_name(log) != \"null.log\" ) ++lines_printed;\n\n\tlocal i = logs[a];\n\tfor ( tag in tags )\n\t\t{\n\t\tlocal prefix = cat(a,\"-\",tag,\"-\"); # http-ext-identified-files\n\t\tif ( prefix in logs )\n\t\t\ti = logs[prefix];\n\t\t\n\t\tif ( i$split && |local_nets| > 0 )\n\t\t\t{\n\t\t\tif ( is_local_addr(ip) )\n\t\t\t\tlog = i$files[\"split1-log\"];\n\t\t\telse\n\t\t\t\tlog = i$files[\"split2-log\"];\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tlog = i$files[\"combined-log\"];\n\t\t\t}\n\t\tprint log, line;\n\t\t++lines_printed;\n\t\t}\n\treturn lines_printed;\n\t}\n\nfunction print_log_by_id(a: string, id: conn_id, force_log: bool, tags: set[string], line: string): count\n\t{\n\tlocal log = get_file_by_id(a, id, force_log);\n\tprint log, line;\n\t\n\tlocal lines_printed=0;\n\tif ( get_file_name(log) != \"null.log\" ) ++lines_printed;\n\t\n\tlocal i = logs[a];\n\tfor ( tag in tags )\n\t\t{\n\t\tlocal prefix = cat(a,\"-\",tag); # http-ext-identified-files\n\t\tif ( prefix in logs )\n\t\t\ti = logs[prefix];\n\t\t\t\n\t\tif ( i$split && |local_nets| > 0 )\n\t\t\t{\n\t\t\tif ( is_local_addr(id$resp_h) )\n\t\t\t\tlog = i$files[\"split1-log\"];\n\t\t\telse\n\t\t\t\tlog = i$files[\"split2-log\"];\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tlog = i$files[\"combined-log\"];\n\t\t\t}\n\t\tprint log, line;\n\t\t++lines_printed;\n\t\t}\n\treturn lines_printed;\n\t}\n\nfunction buffer(a: string, value: bool)\n\t{\n\tlocal i = logs[a];\n\t\n\tfor ( f in i$files )\n\t\t{\n\t\tset_buf(i$files[f], value);\n\t\t}\n\t}\n\nfunction open_log_files(a: string, tag: string)\n\t{\n\tlocal i = logs[a];\n\t\n\tif ( i$split && |local_nets| == 0 )\n\t\tprint fmt(\"WARNING: Output log splitting requested for %s, but no networks defined in local_nets\", a);\n\t\n\tlocal fname=a;\n\tif ( tag != \"\" )\n\t\t{\n\t\tfname = cat(a,\"-\",tag);\n\t\tif ( fname in logs )\n\t\t\ti = logs[fname];\n\t\t}\n\n\tif ( i$split && |local_nets| > 0 )\n\t\t{\n\t\t# Find if this log is determined by HOSTS or DIRECTIONS\n\t\tif ( i$dh in DIRECTIONS ) \n\t\t\t{\n\t\t\ti$files[\"split1-log\"] = open_log_file(cat(fname,\"-inbound\"));\n\t\t\ti$files[\"split2-log\"] = open_log_file(cat(fname,\"-outbound\"));\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ti$files[\"split1-log\"] = open_log_file(cat(fname,\"-localhosts\"));\n\t\t\ti$files[\"split2-log\"] = open_log_file(cat(fname,\"-remotehosts\"));\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\ti$files[\"combined-log\"] = open_log_file(fname);\n\t\t}\n\t}\n\nfunction create_logs(a: string, d: Directions_and_Hosts, split: bool, raw: bool)\n\t{\n\tlocal x: table[string] of file = table();\n\tlocal y: set[string] = set();\n\tlogs[a] = [$dh=d, $split=split, $raw_output=raw, $files=x, $tags=y];\n\t}\n\t\nfunction define_header(a: string, h: string)\n\t{\n\tlocal i = logs[a];\n\ti$header = h;\n\t}\n\t\nfunction define_tag(a: string, tag: string)\n\t{\n\tif ( a !in logs )\n\t\t{\n\t\tprint fmt(\"WARNING: log type '%s' must be defined before adding tag '%s'.\", a, tag);\n\t\treturn;\n\t\t}\n\t# TODO: Validate this is being called during bro_init\n\t\n\tlocal i = logs[a];\n\tlogs[cat(a,\"-\",tag)] = copy(i);\n\tadd i$tags[tag];\n\t}\n\t\nevent file_opened(f: file) &priority=10\n\t{\n\t# Only do any of this for files opened locally.\n\tif ( is_remote_event() ) return;\n\t\n\tlocal filename = get_file_name(f);\n\t# TODO: make this not depend on the file extension being .log\n\tlocal log_type = gsub(filename, \/(-(((in|out)bound)|(local|remote)hosts))?\\.log$\/, \"\");\n\tif ( log_type in logs )\n\t\t{\n\t\tlocal i = logs[log_type];\n\t\tif ( i$raw_output )\n\t\t\tenable_raw_output(f);\n\t\tif ( i$header != \"\" )\n\t\t\tprint f, i$header;\n\t\t}\n\telse\n\t\t{\n\t\t# TODO: This needs to be handled.\n\t\t}\n\t}\n\n# This is a hack. The null file is used as \/dev\/null by all\n# scripts using the logging framework. The file needs to be\n# closed so that nothing is ever written to it.\n# TODO: change this when a better method for not printing\n# is created.\nevent bro_init()\n\t{\n\tclose(null_file);\n\t}\n\n# Open the appropriate log files.\nevent bro_init() &priority=-10\n\t{\n\tfor ( lt in logs )\n\t\t{\n\t\topen_log_files(lt, \"\");\n\t\t# Open up all of the tagged log files if they exist.\n\t\tfor ( tag in logs[lt]$tags )\n\t\t\topen_log_files(lt, tag);\n\t\t}\n\t}\n","old_contents":"module LOG;\n\nexport {\n\t# The record type to store logging information.\n\ttype log_info: record {\n\t\tdh: Directions_and_Hosts &default=All;\n\t\tsplit: bool &default=F;\n\t\traw_output: bool &default=F;\n\t\theader: string &default=\"\";\n\t\tfiles: table[string] of file;\n\t\ttags: set[string];\n\t};\n\t\n\t# Where the data for knowing how to log is stored.\n\tconst logs: table[string] of log_info &redef;\n\n\t# Utility functions\n\tglobal get_file_by_addr: function(a: string, ip: addr, force_log: bool): file;\n\tglobal get_file_by_id: function(a: string, id: conn_id, force_log: bool): file;\n\tglobal print_log_by_addr: function(a: string, ip: addr, force_log: bool, tags: set[string], line: string): count;\n\tglobal print_log_by_id: function(a: string, id: conn_id, force_log: bool, tags: set[string], line: string): count;\n\tglobal open_log_files: function(a: string, tag: string);\n\tglobal create_logs: function(a: string, d: Directions_and_Hosts, split: bool, raw: bool);\n\tglobal define_header: function(a: string, h: string);\n\tglobal define_tag: function(a: string, tag: string);\n\tglobal buffer: function(a: string, value: bool);\n\t\n\t# This is dumb, but it helps avoid needing to duplicate code on the\n\t# printing side.\n\tconst null_file: file = open_log_file(\"null\");\n}\n\nfunction get_file_by_addr(a: string, ip: addr, force_log: bool): file\n\t{\n\tlocal i = logs[a];\n\tif ( !force_log && !addr_matches_hosts(ip, i$dh) )\n\t\treturn LOG::null_file;\n\n\tif ( i$split && |local_nets| > 0 )\n\t\t{\n\t\tif ( is_local_addr(ip) )\n\t\t\treturn i$files[\"split1-log\"];\n\t\telse\n\t\t\treturn i$files[\"split2-log\"];\n\t\t}\n\telse\n\t\t{\n\t\treturn i$files[\"combined-log\"];\n\t\t}\n\t}\n\t\nfunction get_file_by_id(a: string, id: conn_id, force_log: bool): file\n\t{\n\tlocal i = logs[a];\n\tif ( !force_log && !id_matches_directions(id, i$dh) )\n\t\treturn LOG::null_file;\n\n\tif ( i$split && |local_nets| > 0 )\n\t\t{\n\t\tif ( is_local_addr(id$resp_h) )\n\t\t\treturn i$files[\"split1-log\"];\n\t\telse\n\t\t\treturn i$files[\"split2-log\"];\n\t\t}\n\telse\n\t\t{\n\t\treturn i$files[\"combined-log\"];\n\t\t}\n\t}\n\t\nfunction print_log_by_addr(a: string, ip: addr, force_log: bool, tags: set[string], line: string): count\n\t{\n\tlocal log = get_file_by_addr(a, ip, force_log);\n\tprint log, line;\n\t\n\tlocal lines_printed=0;\n\tif ( get_file_name(log) != \"null.log\" ) ++lines_printed;\n\n\tlocal i = logs[a];\n\tfor ( tag in tags )\n\t\t{\n\t\tlocal prefix = cat(a,\"-\",tag,\"-\"); # http-ext-identified-files\n\t\tif ( prefix in logs )\n\t\t\ti = logs[prefix];\n\t\t\n\t\tif ( i$split && |local_nets| > 0 )\n\t\t\t{\n\t\t\tif ( is_local_addr(ip) )\n\t\t\t\tlog = i$files[\"split1-log\"];\n\t\t\telse\n\t\t\t\tlog = i$files[\"split2-log\"];\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tlog = i$files[\"combined-log\"];\n\t\t\t}\n\t\tprint log, line;\n\t\t++lines_printed;\n\t\t}\n\treturn lines_printed;\n\t}\n\nfunction print_log_by_id(a: string, id: conn_id, force_log: bool, tags: set[string], line: string): count\n\t{\n\tlocal log = get_file_by_id(a, id, force_log);\n\tprint log, line;\n\t\n\tlocal lines_printed=0;\n\tif ( get_file_name(log) != \"null.log\" ) ++lines_printed;\n\t\n\tlocal i = logs[a];\n\tfor ( tag in tags )\n\t\t{\n\t\tlocal prefix = cat(a,\"-\",tag); # http-ext-identified-files\n\t\tif ( prefix in logs )\n\t\t\ti = logs[prefix];\n\t\t\t\n\t\tif ( i$split && |local_nets| > 0 )\n\t\t\t{\n\t\t\tif ( is_local_addr(id$resp_h) )\n\t\t\t\tlog = i$files[\"split1-log\"];\n\t\t\telse\n\t\t\t\tlog = i$files[\"split2-log\"];\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tlog = i$files[\"combined-log\"];\n\t\t\t}\n\t\tprint log, line;\n\t\t++lines_printed;\n\t\t}\n\treturn lines_printed;\n\t}\n\nfunction buffer(a: string, value: bool)\n\t{\n\tlocal i = logs[a];\n\t\n\tfor ( f in i$files )\n\t\t{\n\t\tset_buf(i$files[f], value);\n\t\t}\n\t}\n\nfunction open_log_files(a: string, tag: string)\n\t{\n\tlocal i = logs[a];\n\t\n\tif ( i$split && |local_nets| == 0 )\n\t\tprint fmt(\"WARNING: Output log splitting requested for %s, but no networks defined in local_nets\", a);\n\t\n\tlocal fname=a;\n\tif ( tag != \"\" )\n\t\t{\n\t\tfname = cat(a,\"-\",tag);\n\t\tif ( fname in logs )\n\t\t\ti = logs[fname];\n\t\t}\n\n\tif ( i$split && |local_nets| > 0 )\n\t\t{\n\t\t# Find if this log is determined by HOSTS or DIRECTIONS\n\t\tif ( i$dh in DIRECTIONS ) \n\t\t\t{\n\t\t\ti$files[\"split1-log\"] = open_log_file(cat(fname,\"-inbound\"));\n\t\t\ti$files[\"split2-log\"] = open_log_file(cat(fname,\"-outbound\"));\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ti$files[\"split1-log\"] = open_log_file(cat(fname,\"-localhosts\"));\n\t\t\ti$files[\"split2-log\"] = open_log_file(cat(fname,\"-remotehosts\"));\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\ti$files[\"combined-log\"] = open_log_file(fname);\n\t\t}\n\t}\n\nfunction create_logs(a: string, d: Directions_and_Hosts, split: bool, raw: bool)\n\t{\n\tlocal x: table[string] of file = table();\n\tlocal y: set[string] = set();\n\tlogs[a] = [$dh=d, $split=split, $raw_output=raw, $files=x, $tags=y];\n\t}\n\t\nfunction define_header(a: string, h: string)\n\t{\n\tlocal i = logs[a];\n\ti$header = h;\n\t}\n\t\nfunction define_tag(a: string, tag: string)\n\t{\n\tif ( a !in logs )\n\t\t{\n\t\tprint fmt(\"WARNING: log type '%s' must be defined before adding tag '%s'.\", a, tag);\n\t\treturn;\n\t\t}\n\t# TODO: Validate this is being called during bro_init\n\t\n\tlocal i = logs[a];\n\tlogs[cat(a,\"-\",tag)] = copy(i);\n\tadd i$tags[tag];\n\t}\n\t\nevent file_opened(f: file) &priority=10\n\t{\n\tlocal filename = get_file_name(f);\n\t# TODO: make this not depend on the file extension being .log\n\tlocal log_type = gsub(filename, \/(-(((in|out)bound)|(local|remote)hosts))?\\.log$\/, \"\");\n\tif ( log_type in logs )\n\t\t{\n\t\tlocal i = logs[log_type];\n\t\tif ( i$raw_output )\n\t\t\tenable_raw_output(f);\n\t\tif ( !is_remote_event() && i$header != \"\" )\n\t\t\tprint f, i$header;\n\t\t}\n\telse\n\t\t{\n\t\t# TODO: This needs to be handled.\n\t\t}\n\t}\n\n# This is a hack. The null file is used as \/dev\/null by all\n# scripts using the logging framework. The file needs to be\n# closed so that nothing is ever written to it.\n# TODO: change this when a better method for not printing\n# is created.\nevent bro_init()\n\t{\n\tclose(null_file);\n\t}\n\n# Open the appropriate log files.\nevent bro_init() &priority=-10\n\t{\n\tfor ( lt in logs )\n\t\t{\n\t\topen_log_files(lt, \"\");\n\t\t# Open up all of the tagged log files if they exist.\n\t\tfor ( tag in logs[lt]$tags )\n\t\t\topen_log_files(lt, tag);\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"b90332a39125452d0cbd5844fd7ac9d5f858eafd","subject":"datatypes for logging","message":"datatypes for logging\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dio_json_log.bro","new_file":"custom_scripts\/dio_json_log.bro","new_contents":"module Dio_access;\n\nexport {\n redef enum Log::ID += { LOG };\n \n type Info: record {\n ts: time &log;\n dst_ip: addr &log;\n dst_port: port &log;\n src_hostname: string &log;\n src_ip: addr &log;\n src_port: port &log; \n transport: string &log;\n protocol: string &log;\n connector_id: string &log;\n };\n}\n\nevent bro_init() &priority=5 {\n Log::create_stream(Dio_access::LOG, [$columns=Info, $path=\"dionaea_access\"]); \n}\n","old_contents":"module Dio_access;\n\nexport {\n redef enum Log::ID += { LOG };\n \n type Info: record {\n ts: time &log;\n dst_ip: time &log;\n dst_port: string &log;\n src_hostname: addr &log;\n src_ip: port &log;\n src_port: addr &log; \n remote_port: port &log;\n transport: string &log;\n protocol: string &log;\n connector_id: string &log;\n };\n}\n\nevent bro_init() &priority=5 {\n Log::create_stream(Dio_access::LOG, [$columns=Info, $path=\"dionaea_access\"]); \n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"7abd805879e336838e812bf48d114718ec387a83","subject":"count the total number of recipients rather than just one per email","message":"count the total number of recipients rather than just one per email\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-phish-passwords.bro","new_file":"smtp-ext-phish-passwords.bro","new_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &create_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s - %s\", si$mailfrom, to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n phishing_counter[si$mailfrom] += |si$rcptto|;\n if(phishing_counter[si$mailfrom] > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","old_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &create_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s - %s\", si$mailfrom, to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n if(++(phishing_counter[si$mailfrom]) > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"9de957b2e61dda5c570fd790381080ac3f8c923d","subject":"Delete listen-clear.bro","message":"Delete listen-clear.bro","repos":"trakons\/sshd_stunnel","old_file":"listen-clear.bro","new_file":"listen-clear.bro","new_contents":"","old_contents":"# $Id: listen-clear.bro 416 2004-09-17 03:52:28Z vern $\n#\n# Listen for other Bros (non-SSL).\n\n@load remote\n\n# On which port to listen.\nconst listen_port_clear = Remote::default_port_clear &redef;\n\n# On which IP to bind (0.0.0.0 for any interface)\nconst listen_if_clear = 0.0.0.0 &redef;\n\nevent bro_init()\n\t{\n\tlisten(listen_if_clear, listen_port_clear, F);\n\t}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"79d71d5cfc62b4a25b59566b4737b9eb5011aa92","subject":"Adding test for failure to reuse the same event for two on-clauses.","message":"Adding test for failure to reuse the same event for two on-clauses.\n","repos":"FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti","old_file":"bro\/tests\/pac2\/double-event.bro","new_file":"bro\/tests\/pac2\/double-event.bro","new_contents":"#\n# @TEST-EXEC: bro -r ${TRACES}\/ssh-single-conn.trace .\/ssh-cond.evt %INPUT >output\n# @TEST-EXEC: btest-diff output\n#\n# @TEST-KNOWN-FAILURE: The Bro interface can't handle two \"on ..\" clauses\n# raising the same event.\n\nevent ssh::banner(i: int, software: string)\n\t{\n\tprint i, software;\n\t}\n\n# @TEST-START-FILE ssh-cond.evt\n\ngrammar ssh.pac2;\n\nprotocol analyzer pac2::SSH over TCP:\n parse with SSH::Banner,\n port 22\/tcp,\n replaces SSH;\n\non SSH::Banner -> event ssh::banner(1, self.software);\non SSH::Banner -> event ssh::banner(2, self.software);\n\n# @TEST-END-FILE\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro\/tests\/pac2\/double-event.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"142a2186e8c2b0768511e19ae1c82956ebdae898","subject":"Rebalance for new connections:","message":"Rebalance for new connections:\n\nstore registered connectors, regardless of available slaves. Rebalance\nwhenever new slaves come in. Auto-balance (no rebalance required) when\nnew connectors come in.\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_receiver.bro","new_file":"scripts_master\/bro_receiver.bro","new_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n log_bro(\"Incoming connection extablished \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n log_bro(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n print \"Registering new slave \", peer_name;\n log_bro(\"Registering new slave \" + peer_name);\n slaves[peer_name] = 0;\n local total_slaves = |slaves|;\n local slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::vector_lookup(keys$result, i);\n ++i;\n }\n\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = Broker::refine_to_string(connector_vector[total_connectors]);\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n #log_bro(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n log_bro(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n \n }\n if(\/beemaster-connector-\/ in peer_name) {\n print \"Registering new connector \", peer_name;\n log_bro(\"Registering new connector \" + peer_name);\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not register connector\", peer_name;\n log_bro(\"Could not register connector \" + peer_name);\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Unregistering old slave \" + peer_name);\n delete slaves[peer_name];\n # TODO rebalance\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n log_bro(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_bro(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}","old_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n log_bro(\"Bro Master log access event!\");\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n log_bro(\"Bro Master log mysql event!\");\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n local inc: string = \"Incoming connection extablished \" + peer_name;\n log_bro(inc);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local inc: string = \"Incoming connection broken for \" + peer_name;\n log_bro(inc);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Registering new slave \" + peer_name);\n slaves[peer_name] = 0;\n local total_slaves = |slaves|;\n local total_connectors = 0;\n local slave_table = vector of string;\n local i = 0;\n for (slave in slaves) {\n total_connectors += slaves[slave];\n slave_table[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_table = vector of string;\n while (i < total_connectors) {\n connector_table[i] = Broker::vector_lookup(keys$result, i);\n }\n\n print \"Starting add slave to balance:\";\n print \"total_slaves\", total_slaves, \"total_connectors\", total_connectors;\n while (total_slaves > 0) {\n local balance_amount = balance_amount = total_connectors; \n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n total_connectors -= balance_amount;\n print \"total_slaves\", total_slaves, \"total_connectors\", total_connectors;\n # TODO: set balanceamount as value for one slave\n # TODO: set for all those connectors that one slave\n }\n\n }\n timeout 100msec {\n print \"aww\"; \n }\n \n }\n if(\/beemaster-connector-\/ in peer_name) {\n log_bro(\"Registering new connector \" + peer_name);\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n local size = |slaves|;\n\n if (size <= 0) {\n log_bro(\"No slaves are registered, cannot register connector \" + peer_name);\n print \"should return\";\n return;\n }\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n if (best_slave != \"\") {\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not register connector \", peer_name;\n log_bro(\"Could not register connector \" + peer_name);\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n log_bro(\"Unregistering old slave \" + peer_name);\n delete slaves[peer_name];\n # TODO rebalance\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n }\n Broker::erase(connectors, Broker::data(peer_name));\n print \"Unregistered old connector\", peer_name, \"leaving slave table\", slaves;\n log_bro(\"Unregistered old connector \" + peer_name);\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"6a8f49de37ca40583946b472e2365067ede3fc75","subject":"Now counts rejects during the MAIL FROM command. More rewording and slight reworking.","message":"Now counts rejects during the MAIL FROM command.\nMore rewording and slight reworking.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For the SMTP_StrangeRejectBehavior notice to work, you must define a \n# local_mail table listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n\trejects: count &default=0;\n\ttotal: count &default=0;\n};\n\nexport {\n\t# The idea for this is that if a host makes more than reject_threshold \n\t# smtp connections per hour of which at least reject_percent of those are\n\t# rejected and the host is not a known mail sending host, then it's likely \n\t# sending spam or viruses.\n\t#\n\tconst reject_threshold = 100 &redef;\n\tconst reject_percent = 30 &redef;\n\t\n\t# These are smtp status codes that are considered \"rejected\".\n\tconst bad_address_reject_codes: set[count] = {\n\t\t501, # Bad sender address syntax\n\t\t550, # Requested action not taken: mailbox unavailable\n\t\t551, # User not local; please try \n\t\t553, # Requested action not taken: mailbox name not allowed\n\t\t550, # Rejected\n\t};\n\t\n\tredef enum Notice += {\n\t\tSMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n\t\tSMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects\n\t};\n\t\n\t# This variable keeps track of the number of rejected and accepted \n\t# RCPT TO's a host has per hour.\n\tglobal reject_counter: table[addr] of smtp_counter &create_expire=1hr &redef;\n\t\n\t# Reduce the volume of notices raised by filtering out host that have \n\t# already been detected as having too many rejected RCPT TOs.\n\tglobal notified_reject_spammers: set[addr] &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\t# If this is a continued response, it could be something like\n\t# the multiline rejections that gmail gives. We only want to count\n\t# the first rejection in that case.\n\tif ( cont_resp ) return;\n\t\t\n\tif ( c$id$orig_h !in reject_counter )\n\t\t{\n\t\tlocal t: smtp_counter;\n\t\treject_counter[c$id$orig_h] = t;\n\t\t}\n\t# Set the smtp_counter to the local var \"sc\"\n\tlocal sc = reject_counter[c$id$orig_h];\n\t\n\t# Whenever a \"RCPT TO\" is done, we add that to the total.\n\tif ( \/^([rR][cC][pP][tT]|[mM][aA][iI][lL])\/ in cmd )\n\t\t{\n\t\t++sc$total;\n\t\tif ( code in bad_address_reject_codes )\n\t\t\t++sc$rejects;\n\t\n\t\tif ( sc$total >= reject_threshold )\n\t\t\t{\n\t\t\tlocal percent = (sc$rejects*100) \/ sc$total;\n\t\t\tlocal host = c$id$orig_h;\n\t\t\tif ( percent >= reject_percent && \n\t\t\t\t host !in notified_reject_spammers )\n\t\t\t\t{\n\t\t\t\tlocal notice_type = SMTP_PossibleSpam;\n@ifdef ( local_mail )\n\t\t\t\tif ( host in local_mail )\n\t\t\t\t\tnotice_type = SMTP_StrangeRejectBehavior;\n@endif\n\t\t\t\tNOTICE([$note=notice_type,\n\t\t\t\t $msg=fmt(\"%s is having a large number of attempted recipients rejected\", host),\n\t\t\t\t $sub=fmt(\"attempted: %d rejected: %d percent\",\n\t\t\t\t sc$total, percent),\n\t\t\t\t $conn=c]);\n\t\t\t\n\t\t\t\tadd notified_reject_spammers[host];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n","old_contents":"# For the SMTP_StrangeRejectBehavior notice to work, you must define a \n# local_mail table listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n\trejects: count &default=0;\n\ttotal: count &default=0;\n};\n\nexport {\n\t# The idea for this is that if a host makes more than spam_threshold \n\t# smtp connections per hour of which at least spam_percent of those are\n\t# rejected and the host is not a known mail sending host, then it's likely \n\t# sending spam or viruses.\n\t#\n\tconst spam_threshold = 300 &redef;\n\tconst spam_percent = 30 &redef;\n\t\n\t# These are smtp status codes that are considered \"rejected\".\n\tconst bad_address_reject_codes: set[count] = {\n\t\t501, # Bad sender address syntax\n\t\t550, # Requested action not taken: mailbox unavailable\n\t\t551, # User not local; please try \n\t\t553, # Requested action not taken: mailbox name not allowed\n\t};\n\t\n\tredef enum Notice += {\n\t\tSMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n\t\tSMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects\n\t};\n\t\n\t# This variable keeps track of the number of rejected and accepted \n\t# RCPT TO's a host has per hour.\n\tglobal reject_counter: table[addr] of smtp_counter &create_expire=1hr &redef;\n\t\n\t# Reduce the volume of notices raised by filtering out host that have \n\t# already been detected as having too many rejected RCPT TOs.\n\tglobal notified_reject_spammers: set[addr] &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\t# If this is a continued response, it could be something like\n\t# the multiline rejections that gmail gives. We only want to count\n\t# the first rejection in that case.\n\tif ( cont_resp ) return;\n\t\t\n\tif ( c$id$orig_h !in reject_counter )\n\t\t{\n\t\tlocal t: smtp_counter;\n\t\treject_counter[c$id$orig_h] = t;\n\t\t}\n\t# Set the smtp_counter to the local var \"sc\"\n\tlocal sc = reject_counter[c$id$orig_h];\n\t\n\t# Whenever a \"RCPT TO\" is done, we add that to the total.\n\tif ( \/^[rR][cC][pP][tT]\/ in cmd )\n\t\t{\n\t\t++sc$total;\n\t\tif ( code in bad_address_reject_codes )\n\t\t\t++sc$rejects;\n\t\t}\n\t\n\tif ( sc$total >= spam_threshold )\n\t\t{\n\t\tlocal percent = (sc$rejects*100) \/ sc$total;\n\t\tlocal host = c$id$orig_h;\n\t\tif ( percent >= spam_percent && \n\t\t\t host !in notified_reject_spammers )\n\t\t\t{\n\t\t\tlocal notice_type = SMTP_PossibleSpam;\n@ifdef ( local_mail )\n\t\t\tif ( host in local_mail )\n\t\t\t\tnotice_type = SMTP_StrangeRejectBehavior;\n@endif\n\t\t\tNOTICE([$note=notice_type,\n\t\t\t $msg=fmt(\"%s is having a large number of attempted recipients rejected\", host),\n\t\t\t $sub=fmt(\"attempted: %d rejected: %d percent\",\n\t\t\t sc$total, percent),\n\t\t\t $conn=c]);\n\t\t\t\n\t\t\tadd notified_reject_spammers[host];\n\t\t\t}\n\t\t}\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"ac893be4059f2d8b5de7e95067d0935b73c130a0","subject":"only keep track of individual connections for 1 minute.","message":"only keep track of individual connections for 1 minute.\n\nA machine spamming wouldn't have the same connection open for very long.\nEven if it does, if we see more rejects after 1 minute, it doesn't hurt to\ncount them. This would esentially count '1 rejection per connection per\nminute', instead of 'at most 1 rejection per connection'\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id] &create_expire=1m;\n local blarg: set[conn_id] &create_expire=1m;\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n connects: set[conn_id];\n rej_conns: set[conn_id];\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n local bar: set[conn_id];\n local blarg: set[conn_id];\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0, $connects=bar, $rej_conns=blarg];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes &&\n c$id !in foo$rej_conns )\n {\n ++foo$rejects;\n local session = smtp_sessions[c$id];\n add foo$rej_conns[c$id];\n }\n\n if ( c$id !in foo$connects ) \n {\n ++foo$total;\n add foo$connects[c$id];\n }\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"d983bf76c5ea13946c60b19023ec252fd044b7d2","subject":"Fixed path resolution.","message":"Fixed path resolution.\n","repos":"mocyber\/rock-scripts","old_file":"__load__.bro","new_file":"__load__.bro","new_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n","old_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\n\n# Load integration with Snort on ROCK\n@load frameworks\/files\/unified2-integration\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"782be2f06562bfbd73879328d2438235f985445c","subject":"cleanups","message":"cleanups\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"log-external-dns.bro","new_file":"log-external-dns.bro","new_contents":"module DNS;\n\nexport {\n redef record Info += {\n is_external: bool &default=F;\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n 208.67.220.220\/32, #opendns\n } &redef;\n\n redef enum Notice::Type += {\n ## Indicates that a user is using an external DNS server\n EXTERNAL_DNS,\n\n ## Indicates that a user is using an external DNS server in \n ## a foreign country.\n EXTERNAL_FOREIGN_DNS,\n };\n\n redef Notice::type_suppression_intervals += {\n [EXTERNAL_DNS] = 12hr,\n [EXTERNAL_FOREIGN_DNS] = 12hr,\n };\n\n const local_countries: set[string] = {\n \"US\",\n } &redef;\n\n}\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\n local rec = c$dns;\n if(!rec$RD)\n return;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return;\n\n rec$is_external=T;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n\n when (local hostname = lookup_addr(resp_h)) {\n #Doesn't work for the log, but we can use it here :-(\n #rec$resp_h_hostname = hostname;\n\n local note = EXTERNAL_DNS;\n local nmsg = fmt(\"An external DNS server is in use %s(%s)\", resp_h, hostname);\n\n if(rec$cc !in local_countries){\n note = EXTERNAL_FOREIGN_DNS;\n nmsg = fmt(\"An external foreign(%s) DNS server is in use %s(%s).\", rec$cc, resp_h, hostname);\n }\n local ident = fmt(\"%s-%s\", orig_h, resp_h);\n NOTICE([$note=note,\n $msg=nmsg,\n $sub=hostname,\n $identifier=ident,\n $conn=c]);\n }\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n return rec$is_external;\n } ]);\n}\n","old_contents":"module DNS;\n\nexport {\n redef record Info += {\n is_external: bool &default=F;\n ## Country code of external DNS server\n cc: string &log &optional;\n ## hostname of external DNS server\n #resp_h_hostname: string &log &optional;\n };\n\n\n const ignore_external: set[subnet] = {\n 8.8.8.8\/32, #google dns\n 8.8.4.4\/32, #google dns\n 208.67.220.123\/32, #opendns\n 208.67.222.222\/32, #opendns\n 208.67.220.220\/32, #opendns\n } &redef;\n\n redef enum Notice::Type += {\n ## Indicates that a user is using an external DNS server\n EXTERNAL_DNS,\n\n ## Indicates that a user is using an external DNS server in \n ## a foreign country.\n EXTERNAL_FOREIGN_DNS,\n };\n\n redef Notice::type_suppression_intervals += {\n [EXTERNAL_DNS] = 12hr,\n [EXTERNAL_FOREIGN_DNS] = 12hr,\n };\n\n const local_countries: set[string] = {\n \"US\",\n } &redef;\n\n}\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n{\n local rec = c$dns;\n if(!rec$RD)\n return;\n\n local orig_h = rec$id$orig_h;\n local resp_h = rec$id$resp_h;\n\n #is this an outbound query\n if(!Site::is_local_addr(orig_h) || Site::is_local_addr(resp_h))\n return;\n\n if(orig_h in ignore_external || resp_h in ignore_external)\n return;\n\n rec$is_external=T;\n\n local loc = lookup_location(resp_h);\n\n rec$cc = \"\";\n if(loc?$country_code){\n rec$cc = loc$country_code;\n }\n\n when (local hostname = lookup_addr(resp_h)) {\n #Doesn't work for the log, but we can use it here :-(\n #rec$resp_h_hostname = hostname;\n\n local note = EXTERNAL_DNS;\n local nmsg = fmt(\"An external DNS server is in use %s(%s)\", resp_h, hostname);\n\n if(rec$cc !in local_countries){\n note = EXTERNAL_FOREIGN_DNS;\n nmsg = fmt(\"An external foreign(%s) DNS server is in use %s(%s).\", rec$cc, resp_h, hostname);\n }\n local ident = fmt(\"%s-%s\", orig_h, resp_h);\n NOTICE([$note=note,\n $msg=nmsg,\n $sub=hostname,\n $identifier=ident,\n $conn=c]);\n \n }\n\n\n}\n\nevent bro_init()\n{\n Log::add_filter(DNS::LOG, [$name = \"external-dns\",\n $path = \"external_dns\",\n $exclude = set(\"uid\", \"proto\", \"trans_id\",\"qclass\", \"qclass_name\", \"qtype\", \"rcode\",\n \"QR\",\"AA\",\"TC\",\"RD\",\"RA\",\"Z\",\"answers\",\"TTLs\"),\n $pred(rec: DNS::Info) = {\n\n return rec$is_external==T;\n return F;\n } ]);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"4e22cc38e94a0e2b9b62a392d975acd611b7997a","subject":"Removed incident_type and protocol from Beemaster::AlertInfo","message":"Removed incident_type and protocol from Beemaster::AlertInfo\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_shared\/beemaster_types.bro","new_file":"scripts_shared\/beemaster_types.bro","new_contents":"module Beemaster;\n\n@load base\/utils\/addrs\n\nexport {\n type AlertInfo: record {\n timestamp: time;\n source_ip: string;\n source_port: count;\n destination_ip: string;\n destination_port: count;\n };\n}\n\nfunction conninfo_to_alertinfo(input: Conn::Info) : AlertInfo {\n local conn = input$id;\n return AlertInfo($timestamp = input$ts,\n $source_ip = addr_to_uri(conn$orig_h), $source_port = port_to_count(conn$orig_p),\n $destination_ip = addr_to_uri(conn$resp_h), $destination_port = port_to_count(conn$resp_p));\n}\n","old_contents":"module beemaster;\n\n@load base\/utils\/addrs\n\nexport {\n type AlertInfo: record {\n timestamp: time;\n incident_type: string;\n protocol: string;\n source_ip: string;\n source_port: count;\n destination_ip: string;\n destination_port: count;\n };\n}\n\nfunction conninfo_to_alertinfo(input: Conn::Info) : AlertInfo {\n local conn = input$id;\n return AlertInfo($timestamp = input$ts, $incident_type = \"foo\", $protocol = \"bar\",\n $source_ip = addr_to_uri(conn$orig_h), $source_port = port_to_count(conn$orig_p),\n $destination_ip = addr_to_uri(conn$resp_h), $destination_port = port_to_count(conn$resp_p));\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"1564670848e7b6391aa0adef44d1473f42d01372","subject":"name enum convert test fail again.","message":"name enum convert test fail again.\n\n % cat .stderr\n error: identifier or enumerator value in enumerated type definition already exists\n","repos":"FrozenCaribou\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,FrozenCaribou\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti","old_file":"bro\/tests\/pac2\/double-types.bro","new_file":"bro\/tests\/pac2\/double-types.bro","new_contents":"#\n# @TEST-EXEC: bro .\/dtest.evt %INPUT\n#\n# @TEST-KNOWN-FAILURE: enum convert problem. Comment line 16 to toggle error.\n#\n# @TEST-START-FILE dtest.evt\n\ngrammar dtest.pac2;\n\nprotocol analyzer pac2::dtest over UDP:\n parse with dtest::Message,\n port 47808\/udp;\n\non dtest::Message -> event dtest_message(self.func);\n\non dtest::Message -> event dtest_result(self.sub.result);\n\non dtest::Message -> event dtest_result_tuple(dtest::bro_result(self));\n\n# @TEST-END-FILE\n# @TEST-START-FILE dtest.pac2\n\nmodule dtest;\n\nexport type FUNCS = enum {\n A=0, B=1, C=2, D=3, E=4, F=5\n};\n\nexport type RESULT = enum {\n A, B, C, D, E, F\n};\n\nexport type Message = unit {\n func: uint8 &convert=FUNCS($$);\n sub: SubMessage;\n};\n\ntype SubMessage = unit {\n result: uint8 &convert=RESULT($$);\n};\n\ntuple bro_result(entry: Message) {\n\treturn (entry.func, entry.sub.result);\n}\n\n# @TEST-END-FILE\n","old_contents":"#\n# @TEST-EXEC: bro .\/dtest.evt %INPUT\n#\n# @TEST-KNOWN-FAILURE: enum convert problem. Comment line 16 to toggle error.\n\n# @TEST-START-FILE dtest.evt\n\ngrammar dtest.pac2;\n\nprotocol analyzer pac2::dtest over UDP:\n parse with dtest::Message,\n port 47808\/udp;\n\non dtest::Message -> event dtest_message(self.func);\n\non dtest::Message -> event dtest_result (self.sub.result);\n\n# @TEST-END-FILE\n# @TEST-START-FILE dtest.pac2\n\nmodule dtest;\n\ntype FUNCS = enum {\n A, B, C, D, E, F\n};\n\ntype RESULT = enum {\n A, B, C, D, E, F\n};\n\nexport type Message = unit {\n func: uint8 &convert=FUNCS($$);\n sub: SubMessage;\n};\n\ntype SubMessage = unit {\n result: uint8 &convert=RESULT($$);\n};\n\n# @TEST-END-FILE\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"01279e801737ac506f32daf1fa1028525394fc23","subject":"Added server crash polling","message":"Added server crash polling\n\nAdded a SumStats function to more accurately guess if the web server crashed as a result of the MS15-034 vulnerability.","repos":"albertzaharovits\/cs-bro,kingtuna\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,theflakes\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/msb\/detect-ms15-034.bro","new_file":"bro-scripts\/msb\/detect-ms15-034.bro","new_contents":"# Detects MS15-034 vulnerabilities by inspecting inbound HTTP requests and web server responses\n# Any generated notices should have their sub value inspected for the appropriate exploitable RANGE values\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n MS15034_Vulnerability,\n MS15034_Server_Crash\n };\n}\n\n# RANGE values seen in each connection are stored here\nglobal ranges: table[string] of string;\n\n# Potentially crashed servers are stored here and are dropped from the table after 10 seconds of being added\nglobal crash_check: table[addr] of string &create_expire=10secs;\n\nevent bro_init()\n{\n# do a bunch of stuff required by sumstats\nlocal r1: SumStats::Reducer = [$stream=\"http.ms15034.down\", $apply=set(SumStats::SUM)];\nlocal r2: SumStats::Reducer = [$stream=\"http.ms15034.up\", $apply=set(SumStats::SUM)];\nSumStats::create([$name=\"detect-ms15034\",\n $epoch=5secs,\n $reducers=set(r1, r2),\n $epoch_result(ts: time, key: SumStats::Key, result: SumStats::Result) =\n {\n if ( \"http.ms15034.up\" in result && \"http.ms15034.down\" in result \n && result[\"http.ms15034.down\"]$sum > 1 )\n {\n local down = result[\"http.ms15034.down\"];\n local up = result[\"http.ms15034.up\"];\n local total_sum = down$sum + up$sum;\n local down_perc = down$sum \/ total_sum;\n \n if ( down_perc > 90 )\n {\n local sub_msg = fmt(\"Range used: %s\",crash_check[key$host]);\n NOTICE([$note=MS15034_Server_Crash,\n $src=key$host,\n $msg=fmt(\"%s may have crashed due to MS15-034\",cat(key$host)),\n $sub=sub_msg,\n $identifier=cat(key$host)]); \n }\n }\n\n delete crash_check[key$host];\n }\n ]);\n}\n\n# RANGE values are extracted from client HTTP headers if the web server has a private IP address or if the web server is within the local network\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( ! is_orig )\n return;\n\nif ( Site::is_local_addr(c$id$resp_h) == T || Site::is_private_addr(c$id$resp_h) == T ) \n if ( name == \"RANGE\" )\n ranges[c$uid] = value;\n}\n\n# If an HTTP reply is seen for connections in the ranges table, then the web server's response code is checked for a match with the vulnerability\n# A notice is generated that contains the client RANGE request\n# If the server response code isn't 416, then the traffic is ignored\nevent http_reply(c: connection, version: string, code: count, reason: string)\n{\nif ( c$uid in ranges )\n {\n if ( code == 416 )\n {\n local sub_msg = fmt(\"Range used: %s\",ranges[c$uid]);\n NOTICE([$note=MS15034_Vulnerability,\n $conn=c,\n $msg=fmt(\"%s may be vulnerable to MS15-034\",c$id$resp_h),\n $sub=sub_msg,\n $identifier=cat(c$id$resp_h,ranges[c$uid])]);\n\n delete ranges[c$uid];\n }\n\n else if ( code != 416 )\n delete ranges[c$uid];\n }\n}\n\n# If no server response was seen, then poll the web server to see if it has crashed\n# The ranges table is cleaned up as connections are dropped from Bro\nevent connection_state_remove(c: connection)\n{\nif ( c?$http )\n {\n if ( c$id$resp_h in crash_check )\n {\n if ( ! c$http?$status_code )\n {\n SumStats::observe(\"http.ms15034.down\",\n SumStats::Key($host=c$id$resp_h), \n SumStats::Observation($num=1));\n }\n else\n {\n SumStats::observe(\"http.ms15034.up\",\n SumStats::Key($host=c$id$resp_h), \n SumStats::Observation($num=1));\n }\n }\n\n if ( c$uid in ranges )\n {\n if ( ! c$http?$status_code )\n {\n crash_check[c$id$resp_h] = ranges[c$uid];\n delete ranges[c$uid];\n }\n else\n delete ranges[c$uid];\n }\n }\n}\n","old_contents":"# Detects MS15-034 vulnerabilities by inspecting inbound HTTP requests and web server responses\n# Any generated notices should have their sub value inspected for the appropriate exploitable RANGE values\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n MS15034_Vulnerability,\n MS15034_Server_Crash\n };\n}\n\n# RANGE values seen in each connection are stored here\nglobal ranges: table[string] of string;\n\n# RANGE values are extracted from client HTTP headers if the web server has a private IP address or if the web server is within the local network\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( ! is_orig )\n return;\n\nif ( Site::is_local_addr(c$id$resp_h) == T || Site::is_private_addr(c$id$resp_h) == T ) \n if ( name == \"RANGE\" )\n ranges[c$uid] = value;\n}\n\n# If an HTTP reply is seen for connections in the ranges table, then the web server's response code is checked for a match with the vulnerability\n# A notice is generated that contains the client RANGE request\n# If the server response code isn't 416, then the traffic is ignored\nevent http_reply(c: connection, version: string, code: count, reason: string)\n{\nif ( c$uid in ranges )\n {\n if ( code == 416 )\n {\n local sub_msg = fmt(\"Range used: %s\",ranges[c$uid]);\n NOTICE([$note=MS15034_Vulnerability,\n $conn=c,\n $msg=fmt(\"%s may be vulnerable to MS15-034\",c$id$resp_h),\n $sub=sub_msg,\n $identifier=cat(c$id$resp_h,ranges[c$uid])]);\n\n delete ranges[c$uid];\n }\n\n else if ( code != 416 )\n delete ranges[c$uid];\n }\n}\n\n# The ranges table is cleaned up as connections are dropped from Bro\n# If no server response was seen, then assume the web server crashed\nevent connection_state_remove(c: connection)\n{\nif ( c?$http )\n if ( c$uid in ranges )\n {\n if ( ! c$http?$status_code )\n {\n local sub_msg = fmt(\"Range used: %s\",ranges[c$uid]);\n NOTICE([$note=MS15034_Server_Crash,\n $conn=c,\n $msg=fmt(\"%s may have crashed due to MS15-034\",c$id$resp_h),\n $sub=sub_msg,\n $identifier=cat(c$id$resp_h,ranges[c$uid])]);\n\n delete ranges[c$uid];\n }\n else\n delete ranges[c$uid];\n }\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"9c7c8c459314707223be37b24c006b121739e350","subject":"Delete __load__.bro","message":"Delete __load__.bro","repos":"CrowdStrike\/cs-bro,kingtuna\/cs-bro,albertzaharovits\/cs-bro,theflakes\/cs-bro,unusedPhD\/CrowdStrike_cs-bro","old_file":"bro-scripts\/tor\/policy\/__load__.bro","new_file":"bro-scripts\/tor\/policy\/__load__.bro","new_contents":"","old_contents":"@load .\/add-tor\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"779f7160262bf3d99de3514d1c0c8f088ee730d1","subject":"make scanner client versions configurable","message":"make scanner client versions configurable\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssh-ext-block.bro","new_file":"ssh-ext-block.bro","new_contents":"@load global-ext\n@load ssh-ext\n@load subnet-helper\n@load ipblocker\n@load notice\n\nmodule SSH;\n\nexport {\n global ssh_attacked: table[addr] of addr_set &create_expire=30mins &synchronized;# default isn't working &default=function(a:addr):addr_set { print a;return set();};\n global libssh_scanners: set[addr] &create_expire=10mins &synchronized;\n const subnet_threshold = 3 &redef;\n\n redef enum Notice += {\n SSH_Libssh_Scanner,\n };\n const scanner_clients = \n \/libssh\/\n | \/dropbear\/ &redef; \n}\n\nredef notice_action_filters += {\n [SSH_Libssh_Scanner] = notice_exec_ipblocker,\n};\n\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info) &priority=-10\n{\n if(is_local_addr(id$orig_h) ||\n scanner_clients !in si$client ||\n si$status == \"success\")\n return;\n\n local subnets = add_attack(ssh_attacked, id$orig_h, id$resp_h);\n print fmt(\"%s scanned %d subnets\", id$orig_h, subnets);\n \n if(subnets >= subnet_threshold && id$orig_h !in libssh_scanners){\n add libssh_scanners[id$orig_h];\n\n NOTICE([$note=SSH_Libssh_Scanner,\n $id=id,\n $msg=fmt(\"SSH libssh scanning. %s scanned %d subnets\", id$orig_h, subnets),\n $sub=\"ssh-ext\",\n $n=subnets]);\n }\n\n}\n","old_contents":"@load global-ext\n@load ssh-ext\n@load subnet-helper\n@load ipblocker\n@load notice\n\nmodule SSH;\n\nexport {\n global ssh_attacked: table[addr] of addr_set &create_expire=30mins &synchronized;# default isn't working &default=function(a:addr):addr_set { print a;return set();};\n global libssh_scanners: set[addr] &create_expire=10mins &synchronized;\n const subnet_threshold = 3 &redef;\n\n redef enum Notice += {\n SSH_Libssh_Scanner,\n };\n}\n\nredef notice_action_filters += {\n [SSH_Libssh_Scanner] = notice_exec_ipblocker,\n};\n\n\nevent ssh_ext(id: conn_id, si: ssh_ext_session_info) &priority=-10\n{\n if(is_local_addr(id$orig_h) ||\n \/libssh\/ !in si$client ||\n si$status == \"success\")\n return;\n\n local subnets = add_attack(ssh_attacked, id$orig_h, id$resp_h);\n print fmt(\"%s scanned %d subnets\", id$orig_h, subnets);\n \n if(subnets >= subnet_threshold && id$orig_h !in libssh_scanners){\n add libssh_scanners[id$orig_h];\n\n NOTICE([$note=SSH_Libssh_Scanner,\n $id=id,\n $msg=fmt(\"SSH libssh scanning. %s scanned %d subnets\", id$orig_h, subnets),\n $sub=\"ssh-ext\",\n $n=subnets]);\n }\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"fc85e0eca95fff5a1ef2ad9ab5258db9ee5c2f6c","subject":"Fixed the syntax of the smtp_ext event definition.","message":"Fixed the syntax of the smtp_ext event definition.\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext.bro","new_file":"smtp-ext.bro","new_contents":"@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\n# Define the generic smtp-ext event that can be handled from other scripts\nglobal smtp_ext: event(id: conn_id, cl: session_info);\n\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\t\t\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","old_contents":"@load smtp\n@load global-ext\n\nmodule SMTP;\n\nexport {\n\tglobal smtp_ext_log = open_log_file(\"smtp-ext\") &raw_output &redef;\n\n\tredef enum Notice += { \n\t\t# Thrown when a local host receives a reply mentioning an smtp block list\n\t\tSMTP_BL_Error_Message, \n\t\t# Thrown when the local address is seen in the block list error message\n\t\tSMTP_BL_Blocked_Host, \n\t\t# When mail seems to originate from a suspicious location\n\t\tSMTP_Suspicious_Origination,\n\t};\n\t\n\t# Uncomment this next line or define it in your own file to totally \n\t# disable inspection into the smtp received from headers.\n\t# Disabling supressses the suspicious_origination notice when it's \n\t# tracked through the received from headers.\n\tconst smtp_capture_mail_path = 1;\n\t\n\t# Direction to capture the full \"Received from\" path. (from the Direction enum)\n\t# RemoteHosts - only capture the path until an internal host is found.\n\t# LocalHosts - only capture the path until the external host is discovered.\n\t# AllHosts - capture the entire path.\n\tconst mail_path_capture: Hosts = LocalHosts &redef;\n\t\n\t# Places where it's suspicious for mail to originate from.\n\t# this requires all-capital letter, two character country codes (e.x. US)\n\tconst suspicious_origination_countries: set[string] = {} &redef;\n\tconst suspicious_origination_networks: set[subnet] = {} &redef;\n\n\t# This matches content in SMTP error messages that indicate some\n\t# block list doesn't like the connection\/mail.\n\tconst smtp_bl_error_messages = \n\t \/spamhaus\\.org\\\/\/\n\t | \/sophos\\.com\\\/security\\\/\/\n\t | \/spamcop\\.net\\\/bl\/\n\t | \/cbl\\.abuseat\\.org\\\/\/ \n\t | \/sorbs\\.net\\\/\/ \n\t | \/bsn\\.borderware\\.com\\\/\/\n\t | \/mail-abuse\\.com\\\/\/\n\t | \/bbl\\.barracudacentral\\.com\\\/\/\n\t | \/psbl\\.surriel\\.com\\\/\/ \n\t | \/antispam\\.imp\\.ch\\\/\/ \n\t | \/dyndns\\.com\\\/.*spam\/\n\t | \/rbl\\.knology\\.net\\\/\/\n\t | \/intercept\\.datapacket\\.net\\\/\/ &redef;\n}\n\ntype session_info: record {\n\tmsg_id: string &default=\"\";\n\tin_reply_to: string &default=\"\";\n\thelo: string &default=\"\";\n\tmailfrom: string &default=\"\";\n\trcptto: set[string];\n\tdate: string &default=\"\";\n\tfrom: string &default=\"\";\n\tto: set[string];\n\treply_to: string &default=\"\";\n\tsubject: string &default=\"\";\n\tx_originating_ip: string &default=\"\";\n\treceived_from_originating_ip: string &default=\"\";\n\tlast_reply: string &default=\"\"; # last message the server sent to the client\n\tfiles: string &default=\"\";\n\tpath: string &default=\"\";\n\tcurrent_header: string &default=\"\";\n};\n\n# Define the generic smtp-ext event that can be handled from other scripts\nevent smtp_ext(id: conn_id, cl: session_info);\n\nfunction default_session_info(): session_info\n\t{\n\tlocal tmp: set[string] = set();\n\tlocal tmp2: set[string] = set();\n\treturn [$rcptto=tmp, $to=tmp2];\n\t}\n# TODO: setting a default function doesn't seem to be working correctly here.\nglobal conn_info: table[conn_id] of session_info &read_expire=4mins;\n\nglobal in_received_from_headers: set[conn_id] &create_expire = 2min;\nglobal smtp_received_finished: set[conn_id] &create_expire = 2min;\nglobal smtp_forward_paths: table[conn_id] of string &create_expire = 2min &default = \"\";\n\n# Examples for how to handle notices from this script.\n# (define these in a local script)...\n#redef notice_policy += {\n#\t# Send email if a local host is on an SMTP watch list\n#\t[$pred(n: notice_info) = \n#\t\t{ return (n$note == SMTP::SMTP_BL_Blocked_Host && is_local_addr(n$conn$id$orig_h)); },\n#\t $result = NOTICE_EMAIL],\n#};\n\nfunction find_address_in_smtp_header(header: string): string\n{\n\tlocal ips = find_ip_addresses(header);\n\t\t\n\tif ( |ips| > 1 )\n\t\treturn ips[2];\n\tif ( |ips| > 0 )\n\t\treturn ips[1];\n\treturn \"\";\n}\n\n@ifdef( smtp_capture_mail_path )\n# This event handler builds the \"Received From\" path by reading the \n# headers in the mail\nevent smtp_data(c: connection, is_orig: bool, data: string)\n\t{\n\tlocal id = c$id;\n\n\tif ( id !in conn_info ||\n\t\t id !in smtp_sessions ||\n\t\t !smtp_sessions[id]$in_header || \n\t\t id in smtp_received_finished)\n\t\treturn;\n\t\t\n\tlocal conn_log = conn_info[id];\n\n\tif ( \/^[rR][eE][cC][eE][iI][vV][eE][dD]:\/ in data ) \n\t\tadd in_received_from_headers[id];\n\telse if ( \/^[[:blank:]]\/ !in data )\n\t\tdelete in_received_from_headers[id];\n\t\n\tif ( id in in_received_from_headers ) # currently seeing received from headers\n\t\t{\n\t\tlocal text_ip = find_address_in_smtp_header(data);\n\n\t\tif ( text_ip == \"\" )\n\t\t\treturn;\n\t\t\t\n\t\tlocal ip = to_addr(text_ip);\n\t\t\n\t\t# I don't care if mail bounces around on localhost\n\t\tif ( ip == 127.0.0.1 ) return;\n\t\t\n\t\t# This overwrites each time.\n\t\tconn_log$received_from_originating_ip = text_ip;\n\t\t\n\t\tlocal ellipsis = \"\";\n\t\tif ( !addr_matches_hosts(ip, mail_path_capture) && \n\t\t ip !in private_address_space )\n\t\t\t{\n\t\t\tellipsis = \"... \";\n\t\t\tadd smtp_received_finished[id];\n\t\t\t}\n\n\t\tif (conn_log$path == \"\")\n\t\t\tconn_log$path = fmt(\"%s%s -> %s -> %s\", ellipsis, ip, id$orig_h, id$resp_h);\n\t\telse\n\t\t\tconn_log$path = fmt(\"%s%s -> %s\", ellipsis, ip, conn_log$path);\n\t\t}\n\telse if ( !smtp_sessions[id]$in_header && id !in smtp_received_finished ) \n\t\tadd smtp_received_finished[id];\n\t}\n@endif\n\nfunction end_smtp_extended_logging(c: connection)\n\t{\n\tlocal id = c$id;\n\tlocal conn_log = conn_info[id];\n\t\n\tlocal loc: geo_location;\n\tlocal ip: addr;\n\tif ( conn_log$x_originating_ip != \"\" )\n\t\t{\n\t\tip = to_addr(conn_log$x_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t $conn=c]);\n\t\t\t}\n\t\t}\n\t\t\n\tif ( conn_log$received_from_originating_ip != \"\" &&\n\t conn_log$received_from_originating_ip != conn_log$x_originating_ip )\n\t\t{\n\t\tip = to_addr(conn_log$received_from_originating_ip);\n\t\tloc = lookup_location(ip);\n\t\n\t\tif ( loc$country_code in suspicious_origination_countries ||\n\t\t\t ip in suspicious_origination_networks )\n\t\t\t{\n\t\t\tNOTICE([$note=SMTP_Suspicious_Origination,\n\t\t\t\t $msg=fmt(\"An email originated from %s (%s).\", loc$country_code, ip),\n\t\t\t\t $sub=fmt(\"Subject: %s\", conn_log$subject),\n\t\t\t\t\t$conn=c]);\n\t\t\t}\n\t\t}\n\n\tif ( conn_log$mailfrom != \"\" )\n\t\tprint smtp_ext_log, cat_sep(\"\\t\", \"\\\\N\", \n\t\t network_time(), \n\t\t id$orig_h, fmt(\"%d\", id$orig_p), id$resp_h, fmt(\"%d\", id$resp_p),\n\t\t conn_log$helo, \n\t\t conn_log$msg_id, \n\t\t conn_log$in_reply_to, \n\t\t conn_log$mailfrom, \n\t\t fmt_str_set(conn_log$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n\t\t conn_log$date, \n\t\t conn_log$from, \n\t\t conn_log$reply_to, \n\t\t fmt_str_set(conn_log$to, \/[\"']\/),\n\t\t gsub(conn_log$files, \/[\"']\/, \"\"),\n\t\t conn_log$last_reply, \n\t\t conn_log$x_originating_ip,\n\t\t conn_log$path);\n\t\t\n\tevent smtp_ext(id, conn_log);\n\n\tdelete conn_info[id];\n\tdelete smtp_received_finished[id];\n\t}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n msg: string, cont_resp: bool)\n\t{\n\tlocal id = c$id;\n\t# This continually overwrites, but we want the last reply, so this actually works fine.\n\tif ( (code != 421 && code >= 400) && \n\t id in conn_info )\n\t\t{\n\t\tconn_info[id]$last_reply = fmt(\"%d %s\", code, msg);\n\n\t\t# Raise a notice when an SMTP error about a block list is discovered.\n\t\tif ( smtp_bl_error_messages in msg )\n\t\t\t{\n\t\t\tlocal note = SMTP_BL_Error_Message;\n\t\t\tlocal message = fmt(\"%s received an error message mentioning an SMTP block list\", c$id$orig_h);\n\n\t\t\t# Determine if the originator's IP address is in the message.\n\t\t\tlocal ips = find_ip_addresses(msg);\n\t\t\tlocal text_ip = \"\";\n\t\t\tif ( |ips| > 0 && to_addr(ips[1]) == c$id$orig_h )\n\t\t\t\t{\n\t\t\t\tnote = SMTP_BL_Blocked_Host;\n\t\t\t\tmessage = fmt(\"%s is on an SMTP block list\", c$id$orig_h);\n\t\t\t\t}\n\t\t\t\n\t\t\tNOTICE([$note=note,\n\t\t\t $conn=c,\n\t\t\t $msg=message,\n\t\t\t $sub=msg]);\n\t\t\t}\n\t\t}\n\t}\n\nevent smtp_request(c: connection, is_orig: bool, command: string, arg: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\tif ( id !in smtp_sessions )\n\t\treturn;\n\t\t\n\t# In case this is not the first message in a session\n\tif ( ((\/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg) ) &&\n\t id in conn_info )\n\t\t{\n\t\tlocal tmp_helo = conn_info[id]$helo;\n\t\tend_smtp_extended_logging(c);\n\t\tconn_info[id] = default_session_info();\n\t\tconn_info[id]$helo = tmp_helo;\n\t\t}\n\t\t\n\tif ( id !in conn_info ) \n\t\tconn_info[id] = default_session_info();\n\tlocal conn_log = conn_info[id];\n\t\n\tif ( \/^([hH]|[eE]){2}[lL][oO]\/ in command )\n\t\tconn_log$helo = arg;\n\t\n\tif ( \/^[rR][cC][pP][tT]\/ in command && \/^[tT][oO]:\/ in arg )\n\t\tadd conn_log$rcptto[split1(arg, \/:[[:blank:]]*\/)[2]];\n\t\n\tif ( \/^[mM][aA][iI][lL]\/ in command && \/^[fF][rR][oO][mM]:\/ in arg )\n\t\t{\n\t\tlocal partially_done = split1(arg, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$mailfrom = split1(partially_done, \/[[:blank:]]\/)[1];\n\t\t}\n\t}\n\nevent smtp_data(c: connection, is_orig: bool, data: string) &priority=-5\n\t{\n\tlocal id = c$id;\n\t\t\n\tif ( id !in conn_info )\n\treturn; \n \n\tif ( !smtp_sessions[id]$in_header )\n\t\t{\n\t\tif ( \/^[cC][oO][nN][tT][eE][nN][tT]-[dD][iI][sS].*[fF][iI][lL][eE][nN][aA][mM][eE]\/ in data )\n\t\t\t{\n\t\t\tdata = sub(data, \/^.*[fF][iI][lL][eE][nN][aA][mM][eE]=\/, \"\");\n\t\t\tif ( conn_info[id]$files == \"\" )\n\t\t\t\tconn_info[id]$files = data;\n\t\t\telse\n\t\t\t\tconn_info[id]$files += fmt(\", %s\", data);\n\t\t\t}\n\t\treturn;\n\t\t}\n\n\tlocal conn_log = conn_info[id];\t\n\t# This is to fully construct headers that will tend to wrap around.\n\tif ( \/^[[:blank:]]\/ in data )\n\t\t{\n\t\tdata = sub(data, \/^[[:blank:]]\/, \"\");\n\t\tif ( conn_log$current_header == \"message-id\" )\n\t\t\tconn_log$msg_id += data;\n\t\telse if ( conn_log$in_reply_to == \"in-reply-to\" )\n\t\t\tconn_log$in_reply_to += data;\n\t\telse if ( conn_log$current_header == \"subject\" )\n\t\t\tconn_log$subject += data;\n\t\telse if ( conn_log$current_header == \"from\" )\n\t\t\tconn_log$from += data;\n\t\telse if ( conn_log$current_header == \"reply-to\" )\n\t\t\tconn_log$reply_to += data;\n\t\treturn;\n\t\t}\n\tconn_log$current_header = \"\";\n\n\tif ( \/^[mM][eE][sS][sS][aA][gG][eE]-[iI][dD]:\/ in data )\n\t\t{\n\t\tconn_log$msg_id = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"message-id\";\n\t\t}\n\telse if ( \/^[iI][nN]-[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$in_reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"in-reply-to\";\n\t\t}\n\n\telse if ( \/^[dD][aA][tT][eE]:\/ in data )\n\t\t{\n\t\tconn_log$date = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"date\";\n\t\t}\n\n\telse if ( \/^[fF][rR][oO][mM]:\/ in data )\n\t\t{\n\t\tconn_log$from = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"from\";\n\t\t}\n\n\telse if ( \/^[tT][oO]:\/ in data )\n\t\t{\n\t\tadd conn_log$to[split1(data, \/:[[:blank:]]*\/)[2]];\n\t\tconn_log$current_header = \"to\";\n\t\t}\n\n\telse if ( \/^[rR][eE][pP][lL][yY]-[tT][oO]:\/ in data )\n\t\t{\n\t\tconn_log$reply_to = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"reply-to\";\n\t\t}\n\n\telse if ( \/^[sS][uU][bB][jJ][eE][cC][tT]:\/ in data )\n\t\t{\n\t\tconn_log$subject = split1(data, \/:[[:blank:]]*\/)[2];\n\t\tconn_log$current_header = \"subject\";\n\t\t}\n\n\telse if ( \/^[xX]-[oO][rR][iI][gG][iI][nN][aA][tT][iI][nN][gG]-[iI][pP]:\/ in data )\n\t\t{\n\t\tconn_log$x_originating_ip = find_ip_addresses(data)[1];\n\t\tconn_log$current_header = \"x-originating-ip\";\n\t\t}\n\t\n\t}\n\nevent connection_finished(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n\nevent connection_state_remove(c: connection) &priority=5\n\t{\n\tif ( c$id in conn_info )\n\t\tend_smtp_extended_logging(c);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f2b7cd51e2dc64c88e09fb1bf60bc74e652ac64d","subject":"Update main.bro","message":"Update main.bro","repos":"albertzaharovits\/cs-bro,theflakes\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/intel-extensions\/main.bro","new_file":"bro-scripts\/intel-extensions\/main.bro","new_contents":"# Extends functionality of Intel framework in various ways\n# Supports three new indicator types: Email subjects, Usernames, and SSL cert subjects\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n\nmodule Intel;\n\nexport {\n redef enum Intel::Type += {\n \tCERT_SUBJECT,\n EMAIL_SUBJECT\n };\n\n redef enum Intel::Where += {\n \tRADIUS::IN_USER_NAME,\n FTP::IN_USER_NAME,\n SMTP::IN_SUBJECT,\n \tSSL::IN_SERVER_CERT,\n \tSSL::IN_CLIENT_CERT\n };\n}\n","old_contents":"# Extends functionality of Intel framework in various ways\n# Supports three new indicator types: Email subjects, Usernames, and SSL cert subjects\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n\nmodule Intel;\n\nexport {\n redef enum Intel::Type += {\n \tCERT_SUBJECT,\n EMAIL_SUBJECT\n };\n\n redef enum Intel::Where += {\n \tRADIUS::IN_USER_NAME,\n FTP::IN_USER_NAME,\n SMTP::IN_SUBJECT,\n \tSSL::IN_SERVER_CERT,\n \tSSL::IN_CLIENT_CERT\n };\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"fbeea1b791076b37d23a119824b6fdd1e6f2d9c5","subject":"Change acu topic","message":"Change acu topic\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_master.bro","new_file":"scripts_master\/bro_master.bro","new_contents":"@load .\/beemaster_events\n@load .\/beemaster_log\n\n@load .\/balance\n\n@load .\/portscan_alert\n\n@load .\/dio_access\n@load .\/dio_download_complete\n@load .\/dio_download_offer\n@load .\/dio_ftp\n@load .\/dio_mysql_command\n@load .\/dio_login\n@load .\/dio_smb_bind\n@load .\/dio_smb_request\n@load .\/dio_blackhole.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\n # Subscribe to acu alerts\n Broker::subscribe_to_events_multi(\"beemaster\/acu\/alert\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_login::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent Beemaster::dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_blackhole::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_blackhole::LOG, rec);\n}\n\nevent Beemaster::tcp_event(rec: Beemaster::AlertInfo, discriminant: count) {\n Beemaster::log(\"Got tcp_event!!\");\n}\n\nevent Beemaster::portscan_meta_alert(timestamp: time, attack: string, ips: vector of string) {\n Beemaster::log(\"Got portscan_meta_alert!\");\n local rec: Beemaster::PortscanAlertInfo = [$ts=timestamp, $attack=attack, $ips=ips];\n Log::write(Beemaster::PORTSCAN_LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n Beemaster::log(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n Beemaster::log(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: Balance::Info = [$connector=connector, $slave=slave];\n Log::write(Balance::LOG, rec);\n}\n","old_contents":"@load .\/beemaster_events\n@load .\/beemaster_log\n\n@load .\/balance\n\n@load .\/portscan_alert\n\n@load .\/dio_access\n@load .\/dio_download_complete\n@load .\/dio_download_offer\n@load .\/dio_ftp\n@load .\/dio_mysql_command\n@load .\/dio_login\n@load .\/dio_smb_bind\n@load .\/dio_smb_request\n@load .\/dio_blackhole.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\n # Subscribe to acu alerts\n Broker::subscribe_to_events_multi(\"acu\/alert\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_login::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent Beemaster::dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_blackhole::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_blackhole::LOG, rec);\n}\n\nevent Beemaster::tcp_event(rec: Beemaster::AlertInfo, discriminant: count) {\n Beemaster::log(\"Got tcp_event!!\");\n}\n\nevent Beemaster::portscan_meta_alert(timestamp: time, attack: string, ips: vector of string) {\n Beemaster::log(\"Got portscan_meta_alert!\");\n local rec: Beemaster::PortscanAlertInfo = [$ts=timestamp, $attack=attack, $ips=ips];\n Log::write(Beemaster::PORTSCAN_LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n Beemaster::log(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n Beemaster::log(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: Balance::Info = [$connector=connector, $slave=slave];\n Log::write(Balance::LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"9817ffc2f08397836dd4be1b4dd7a015bf263838","subject":"alert if a non local SSL cert is seen","message":"alert if a non local SSL cert is seen\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-known-certs.bro","new_file":"ssl-known-certs.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\tconst log = open_log_file(\"ssl-known-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst log = open_log_file(\"ssl-known-certs\") &raw_output &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n}\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\t\t}\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"5552a35aa7cbeb2fc0830b6aa974aa7266de4545","subject":"add youtube\/video stats","message":"add youtube\/video stats\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"metrics.http-ext.bro","new_file":"metrics.http-ext.bro","new_contents":"#output something like this\n#http_metrics total=343243 inbound=102313 outbound=3423432 exe_download=23\n\n@load global-ext\n@load http-ext\n\nexport {\n global http_metrics: table[string] of count &default=0 &synchronized;\n global http_metrics_interval = +60sec;\n const http_metrics_log = open_log_file(\"http-ext-metrics\");\n}\n\nevent http_write_stats()\n {\n if (http_metrics[\"total\"]!=0)\n {\n print http_metrics_log, fmt(\"http_metrics time=%.6f total=%d inbound=%d outbound=%d video_download=%d youtube_watches=%d\",\n network_time(),\n http_metrics[\"total\"],\n http_metrics[\"inbound\"],\n http_metrics[\"outbound\"],\n http_metrics[\"video_download\"],\n http_metrics[\"youtube_watches\"]\n );\n clear_table(http_metrics);\n }\n schedule http_metrics_interval { http_write_stats() };\n }\n\nevent bro_init()\n {\n set_buf(http_metrics_log, F);\n schedule http_metrics_interval { http_write_stats() };\n }\n\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=-10\n {\n ++http_metrics[\"total\"];\n if(is_local_addr(id$orig_h))\n ++http_metrics[\"outbound\"];\n else\n ++http_metrics[\"inbound\"];\n\n if (\/\\.(avi|flv|mp4|mpg)\/ in si$uri)\n ++http_metrics[\"video_download\"];\n if (\/watch\\?v=\/ in si$uri && \/youtube\/ in si$host)\n ++http_metrics[\"youtube_watches\"];\n\n }\n","old_contents":"#output something like this\n#http_metrics total=343243 inbound=102313 outbound=3423432 exe_download=23\n\n@load global-ext\n@load http-ext\n\nexport {\n global http_metrics: table[string] of count &default=0 &synchronized;\n global http_metrics_interval = +60sec;\n const http_metrics_log = open_log_file(\"http-ext-metrics\");\n}\n\nevent http_write_stats()\n {\n if (http_metrics[\"total\"]!=0)\n {\n print http_metrics_log, fmt(\"http_metrics time=%.6f total=%d inbound=%d outbound=%d exe_download=%d\",\n network_time(),\n http_metrics[\"total\"],\n http_metrics[\"inbound\"],\n http_metrics[\"outbound\"],\n http_metrics[\"exe_download\"]);\n clear_table(http_metrics);\n }\n schedule http_metrics_interval { http_write_stats() };\n }\n\nevent bro_init()\n {\n set_buf(http_metrics_log, F);\n schedule http_metrics_interval { http_write_stats() };\n }\n\n\nevent http_ext(id: conn_id, si: http_ext_session_info) &priority=-10\n {\n ++http_metrics[\"total\"];\n if(is_local_addr(id$orig_h))\n ++http_metrics[\"outbound\"];\n else\n ++http_metrics[\"inbound\"];\n\n if (\/\\.exe$\/ in si$uri)\n ++http_metrics[\"exe_download\"];\n }\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"9c0907d2cf73afd39a9e8b82d0150ac26b7de98d","subject":"Simplified connection logging in bro_master.bro","message":"Simplified connection logging in bro_master.bro\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_master.bro","new_file":"scripts_master\/bro_master.bro","new_contents":"@load .\/beemaster_events\n@load .\/beemaster_log\n\n@load .\/balance\n\n@load .\/portscan_alert\n\n@load .\/dio_access\n@load .\/dio_download_complete\n@load .\/dio_download_offer\n@load .\/dio_ftp\n@load .\/dio_mysql_command\n@load .\/dio_login\n@load .\/dio_smb_bind\n@load .\/dio_smb_request\n@load .\/dio_blackhole.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\n # Subscribe to acu alerts\n Broker::subscribe_to_events_multi(\"beemaster\/acu\/alert\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_login::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent Beemaster::dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_blackhole::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_blackhole::LOG, rec);\n}\n\nevent Beemaster::tcp_event(rec: Beemaster::AlertInfo, discriminant: count) {\n Beemaster::log(\"Got tcp_event!!\");\n}\n\nevent Beemaster::portscan_meta_alert(timestamp: time, attack: string, ips: vector of string) {\n Beemaster::log(\"Got portscan_meta_alert!\");\n local rec: Beemaster::PortscanAlertInfo = [$ts=timestamp, $attack=attack, $ips=ips];\n Log::write(Beemaster::PORTSCAN_LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n local msg: string = \"Incoming_connection_established \" + peer_name;\n Beemaster::log(msg);\n # Add new client to balance\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n local msg: string = \"Incoming_connection_broken \" + peer_name;\n Beemaster::log(msg);\n # Remove disconnected client from balance\n remove_from_balance(peer_name);\n}\nevent Broker::outgoing_connection_established(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection established to: \" + peer_address;\n Beemaster::log(msg);\n}\nevent Broker::outgoing_connection_broken(peer_address: string, peer_port: port, peer_name: string) {\n local msg: string = \"Outgoing connection broken with: \" + peer_address;\n Beemaster::log(msg);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: Balance::Info = [$connector=connector, $slave=slave];\n Log::write(Balance::LOG, rec);\n}\n","old_contents":"@load .\/beemaster_events\n@load .\/beemaster_log\n\n@load .\/balance\n\n@load .\/portscan_alert\n\n@load .\/dio_access\n@load .\/dio_download_complete\n@load .\/dio_download_offer\n@load .\/dio_ftp\n@load .\/dio_mysql_command\n@load .\/dio_login\n@load .\/dio_smb_bind\n@load .\/dio_smb_request\n@load .\/dio_blackhole.bro\n\nredef exit_only_after_terminate = T;\n# the port and IP that are externally routable for this master\nconst public_broker_port: string = getenv(\"MASTER_PUBLIC_PORT\") &redef;\nconst public_broker_ip: string = getenv(\"MASTER_PUBLIC_IP\") &redef;\n\n# the port that is internally used (inside the container) to listen to\nconst broker_port: port = 9999\/tcp &redef;\nredef Broker::endpoint_name = cat(\"bro-master-\", public_broker_ip, \":\", public_broker_port);\n\nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_balance: function(connector: string, slave: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n Beemaster::log(\"bro_master.bro: bro_init()\");\n\n # Enable broker and listen for incoming slaves\/acus\n Broker::enable([$auto_publish=T, $auto_routing=T]);\n Broker::listen(broker_port, \"0.0.0.0\");\n\n # Subscribe to dionaea events for logging\n Broker::subscribe_to_events_multi(\"honeypot\/dionaea\");\n\n # Subscribe to slave events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/base\");\n\n # Subscribe to tcp events for logging\n Broker::subscribe_to_events_multi(\"beemaster\/bro\/tcp\");\n\n # Subscribe to acu alerts\n Broker::subscribe_to_events_multi(\"beemaster\/acu\/alert\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n Beemaster::log(\"bro_master.bro: bro_init() done\");\n}\nevent bro_done() {\n Beemaster::log(\"bro_master.bro: bro_done()\");\n}\n\nevent Beemaster::dionaea_access(timestamp: time, local_ip: addr, local_port: count, remote_hostname: string, remote_ip: addr, remote_port: count, transport: string, protocol: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_access::Info = [$ts=timestamp, $local_ip=local_ip, $local_port=lport, $remote_hostname=remote_hostname, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, md5hash: string, filelocation: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $md5hash=md5hash, $filelocation=filelocation, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent Beemaster::dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent Beemaster::dionaea_ftp(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, command: string, arguments: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_ftp::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $command=command, $arguments=arguments, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_ftp::LOG, rec);\n}\n\nevent Beemaster::dionaea_mysql_command(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, args: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_mysql_command::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $args=args, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_mysql_command::LOG, rec);\n}\n\nevent Beemaster::dionaea_login(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, username: string, password: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_login::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $username=username, $password=password, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_login::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\nevent Beemaster::dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent Beemaster::dionaea_blackhole(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, protocol: string, input: string, length: count, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n local rec: Dio_blackhole::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $protocol=protocol, $input=input, $length=length, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_blackhole::LOG, rec);\n}\n\nevent Beemaster::tcp_event(rec: Beemaster::AlertInfo, discriminant: count) {\n Beemaster::log(\"Got tcp_event!!\");\n}\n\nevent Beemaster::portscan_meta_alert(timestamp: time, attack: string, ips: vector of string) {\n Beemaster::log(\"Got portscan_meta_alert!\");\n local rec: Beemaster::PortscanAlertInfo = [$ts=timestamp, $attack=attack, $ips=ips];\n Log::write(Beemaster::PORTSCAN_LOG, rec);\n}\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n Beemaster::log(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n Beemaster::log(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\n\n# Log slave log_conn events to the master's conn.log\nevent Beemaster::log_conn(rec: Conn::Info) {\n Log::write(Conn::LOG, rec);\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n Beemaster::log(\"Registered new slave \" + peer_name);\n log_balance(\"\", peer_name);\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_balance(peer_name, best_slave);\n Beemaster::log(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n Beemaster::log(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n log_balance(peer_name, \"\");\n }\n\n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n Beemaster::log(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_balance(\"\", connected_slave);\n Beemaster::log(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n Beemaster::log(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n Beemaster::log(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n log_balance(connector, \"\");\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_balance(rebalanced_conn, balanced_to);\n Beemaster::log(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n Beemaster::log(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}\n\nfunction log_balance(connector: string, slave: string) {\n local rec: Balance::Info = [$connector=connector, $slave=slave];\n Log::write(Balance::LOG, rec);\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"e8c1b8a1af8cb7b7dcee7831246f6b2e91a15992","subject":"new script to do http metrics by domain","message":"new script to do http metrics by domain\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"http-size-metrics.bro","new_file":"http-size-metrics.bro","new_contents":"@load base\/frameworks\/metrics\n@load base\/protocols\/http\n@load base\/utils\/site\n\nredef enum Metrics::ID += {\n\tHTTP_REQUEST_SIZE_BY_HOST_HEADER,\n};\n\nevent bro_init()\n{\n Metrics::add_filter(HTTP_REQUEST_SIZE_BY_HOST_HEADER,\n [$name=\"all\",\n $break_interval=3600secs\n ]);\n\n}\n\nevent HTTP::log_http(rec: HTTP::Info)\n{\n\tif ( rec?$host && rec?$response_body_len)\n\t\tMetrics::add_data(HTTP_REQUEST_SIZE_BY_HOST_HEADER, [$str=rec$host], rec$response_body_len);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'http-size-metrics.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"cc9187b8b57b608ba1772ac99a59d67e285ecbc7","subject":"fix reply address extraction","message":"fix reply address extraction\n\nin addition to the reply-to and mail from fields, the\n'from' header will also be used when replying\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-phish-passwords.bro","new_file":"smtp-ext-phish-passwords.bro","new_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &create_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s - %s\", si$mailfrom, to, si$subject),\n $id=id,\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n phishing_counter[si$mailfrom] += |si$rcptto|;\n if(phishing_counter[si$mailfrom] > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else if(si$from != \"\")\n to_add = si$from;\n else\n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $id=id,\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","old_contents":"@load global-ext\n@load smtp-ext\n\nmodule PHISH;\n\nglobal smtp_password_conns: set[conn_id] &read_expire=2mins;\n\n\nexport {\n redef enum Notice += {\n SMTP_PossiblePWPhish,\n SMTP_PossiblePWPhishReply,\n };\n global phishing_counter: table[string] of count &default=0 &create_expire=1hr &synchronized;\n global phishing_reply_tos: set[string] &synchronized &redef;\n global phishing_ignore_froms: set[string] &redef;\n global phishing_threshold = 50;\n\n const phish_keywords =\n \/[pP][aA][sS][sS][wW][oO][rR][dD]\/\n | \/[uU][sS][eE][rR].?[nN][aA][mM][eE]\/\n | \/[nN][eE][tT][iI][dD]\/ &redef;\n}\n\n\nevent bro_init()\n{\n LOG::create_logs(\"password-mail\", All, F, T);\n LOG::define_header(\"password-mail\", cat_sep(\"\\t\", \"\", \n \"ts\",\n \"orig_h\", \"orig_p\",\n \"resp_h\", \"resp_p\",\n \"helo\", \"message-id\", \"in-reply-to\", \n \"mailfrom\", \"rcptto\",\n \"date\", \"from\", \"reply_to\", \"to\", \"subject\",\n \"files\", \"last_reply\", \"x-originating-ip\",\n \"path\", \"is_webmail\", \"agent\"));\n}\n\nevent bro_done()\n{\n print \"Counter\";\n print phishing_counter;\n print \"bad reply-tos\";\n print phishing_reply_tos;\n}\n\nevent smtp_data(c: connection, is_orig: bool, data: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n # look for 'password'\n if(phish_keywords in data)\n add smtp_password_conns[c$id];\n}\n\nevent smtp_ext(id: conn_id, si: smtp_ext_session_info)\n{\n if(is_local_addr(id$orig_h)) {\n for (to in si$rcptto){\n if(to in phishing_reply_tos){\n NOTICE([$note=SMTP_PossiblePWPhishReply,\n $msg=fmt(\"%s replied to %s - %s\", si$mailfrom, to, si$subject),\n $id=id,\n $sub=si$mailfrom\n ]);\n }\n }\n } else {\n if (id !in smtp_password_conns)\n return;\n if(si$mailfrom in phishing_ignore_froms)\n return;\n phishing_counter[si$mailfrom] += |si$rcptto|;\n if(phishing_counter[si$mailfrom] > phishing_threshold){\n local to_add =\"\";\n if(si$reply_to != \"\")\n to_add = si$reply_to;\n else \n to_add = si$mailfrom;\n if(to_add !in phishing_reply_tos){\n add phishing_reply_tos[to_add];\n NOTICE([$note=SMTP_PossiblePWPhish,\n $msg=fmt(\"%s(%s) may be phishing - %s\", si$mailfrom, si$reply_to, si$subject),\n $id=id,\n $sub=si$mailfrom\n ]);\n }\n }\n\n local log = LOG::get_file_by_id(\"password-mail\", id, F);\n print log, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n id$orig_h, port_to_count(id$orig_p), id$resp_h, port_to_count(id$resp_p),\n si$helo,\n si$msg_id,\n si$in_reply_to,\n si$mailfrom,\n fmt_str_set(si$rcptto, \/[\"'<>]|([[:blank:]].*$)\/),\n si$date, \n si$from, \n si$reply_to, \n fmt_str_set(si$to, \/[\"']\/),\n si$subject,\n fmt_str_set(si$files, \/[\"']\/),\n si$last_reply, \n si$x_originating_ip,\n si$path,\n si$is_webmail,\n si$agent);\n }\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"3c2e74f6fa30ff66a33ae83992f43430ce57af93","subject":"Create remote.bro","message":"Create remote.bro","repos":"trakons\/sshd_stunnel","old_file":"remote.bro","new_file":"remote.bro","new_contents":"# @TEST-SERIALIZE: comm\n#\n# @TEST-EXEC: btest-bg-run sender bro -b --pseudo-realtime %INPUT ..\/sender.bro\n# @TEST-EXEC: sleep 1\n# @TEST-EXEC: btest-bg-run receiver bro -b --pseudo-realtime %INPUT ..\/receiver.bro\n# @TEST-EXEC: sleep 1\n# @TEST-EXEC: btest-bg-wait 15\n# @TEST-EXEC: btest-diff sender\/test.log\n# @TEST-EXEC: btest-diff sender\/test.failure.log\n# @TEST-EXEC: btest-diff sender\/test.success.log\n# @TEST-EXEC: ( cd sender && for i in *.log; do cat $i | $SCRIPTS\/diff-remove-timestamps >c.$i; done )\n# @TEST-EXEC: ( cd receiver && for i in *.log; do cat $i | $SCRIPTS\/diff-remove-timestamps >c.$i; done )\n# @TEST-EXEC: cmp receiver\/c.test.log sender\/c.test.log\n# @TEST-EXEC: cmp receiver\/c.test.failure.log sender\/c.test.failure.log\n# @TEST-EXEC: cmp receiver\/c.test.success.log sender\/c.test.success.log\n\n# This is the common part loaded by both sender and receiver.\nmodule Test;\n\nexport {\n\t# Create a new ID for our log stream\n\tredef enum Log::ID += { LOG };\n\n\t# Define a record with all the columns the log file can have.\n\t# (I'm using a subset of fields from ssh-ext for demonstration.)\n\ttype Log: record {\n\t\tt: time;\n\t\tid: conn_id; # Will be rolled out into individual columns.\n\t\tstatus: string &optional;\n\t\tcountry: string &default=\"unknown\";\n\t} &log;\n}\n\nevent bro_init()\n{\n\tLog::create_stream(Test::LOG, [$columns=Log]);\n\tLog::add_filter(Test::LOG, [$name=\"f1\", $path=\"test.success\", $pred=function(rec: Log): bool { return rec$status == \"success\"; }]);\n}\n\n#####\n\n@TEST-START-FILE sender.bro\n\n@load frameworks\/communication\/listen\n\nmodule Test;\n\nfunction fail(rec: Log): bool\n\t{\n\treturn rec$status != \"success\";\n\t}\n\nevent remote_connection_handshake_done(p: event_peer)\n\t{\n\tLog::add_filter(Test::LOG, [$name=\"f2\", $path=\"test.failure\", $pred=fail]);\n\n\tlocal cid = [$orig_h=1.2.3.4, $orig_p=1234\/tcp, $resp_h=2.3.4.5, $resp_p=80\/tcp];\n\n\tlocal r: Log = [$t=network_time(), $id=cid, $status=\"success\"];\n\n\t# Log something.\n\tLog::write(Test::LOG, r);\n\tLog::write(Test::LOG, [$t=network_time(), $id=cid, $status=\"failure\", $country=\"US\"]);\n\tLog::write(Test::LOG, [$t=network_time(), $id=cid, $status=\"failure\", $country=\"UK\"]);\n\tLog::write(Test::LOG, [$t=network_time(), $id=cid, $status=\"success\", $country=\"BR\"]);\n\tLog::write(Test::LOG, [$t=network_time(), $id=cid, $status=\"failure\", $country=\"MX\"]);\n\tdisconnect(p);\n\t}\n\nevent remote_connection_closed(p: event_peer)\n\t{\n\tterminate();\n\t}\n\n@TEST-END-FILE\n\n@TEST-START-FILE receiver.bro\n\n#####\n\n@load base\/frameworks\/communication\n\nredef Communication::nodes += {\n [\"foo\"] = [$host = 127.0.0.1, $connect=T, $request_logs=T]\n};\n\nevent remote_connection_closed(p: event_peer)\n\t{\n\tterminate();\n\t}\n\n@TEST-END-FILE\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'remote.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"45aa24c8c1c62640972e37455dfad62e2126b7a9","subject":"Removed kafka configuration from rock.bro","message":"Removed kafka configuration from rock.bro\n\nNot sure how this snuck in. It should only be included in plugins\/kafka.bro","repos":"mocyber\/rock-scripts","old_file":"rock.bro","new_file":"rock.bro","new_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n","old_contents":"# Copyright (C) 2016, Missouri Cyber Team\n# All Rights Reserved\n# See the file \"LICENSE\" in the main distribution directory for details\n\nmodule ROCK;\n\nexport {\n const sensor_id = \"sensor001-001\" &redef;\n}\n\n# Load integration with Snort on ROCK\n@load .\/frameworks\/files\/unified2-integration\n\n# Load integration with FSF\n@load .\/frameworks\/files\/extract2fsf\n\n# Load file extraction\n@load .\/frameworks\/files\/extraction\nredef FileExtract::prefix = \"\/data\/bro\/logs\/extract_files\/\";\nredef FileExtract::default_limit = 1048576000;\n\n# Configure Kafka output\n# Bro Kafka Output (plugin must be loaded!)\n@load Kafka\/KafkaWriter\/logs-to-kafka\nredef KafkaLogger::topic_name = \"bro_raw\";\nredef KafkaLogger::sensor_name = ROCK::sensor_id;\n\n# Add GeoIP info to conn log\n@load .\/misc\/conn-add-geoip\n\n# Add sensor and log meta information to each log\n@load .\/frameworks\/logging\/extension\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"05b141a409c4515b5e61ffae6e54922eeada4163","subject":"also email notice","message":"also email notice\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ipblocker.bro","new_file":"ipblocker.bro","new_contents":"function notice_exec_ipblocker(n: notice_info, a: NoticeAction): NoticeAction\n{\n local cmd = fmt(\"lckdo \/tmp\/bro_ipblocker_%s \/usr\/local\/bin\/bro_ipblocker_block\", n$id$orig_h);\n execute_with_notice(cmd, n);\n email_notice_to(n, mail_dest);\n return NOTICE_ALARM_ALWAYS;\n}\n\n","old_contents":"function notice_exec_ipblocker(n: notice_info, a: NoticeAction): NoticeAction\n{\n local cmd = fmt(\"lckdo \/tmp\/bro_ipblocker_%s \/usr\/local\/bin\/bro_ipblocker_block\", n$id$orig_h);\n execute_with_notice(cmd, n);\n return NOTICE_ALARM_ALWAYS;\n}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"076d640223cf0393a6f26efaa24994005dcfaefb","subject":"use new api","message":"use new api\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"ssl-ext.bro","new_file":"ssl-ext.bro","new_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", All, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file_by_id(\"ssl-known-certs\", c$id, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","old_contents":"@load global-ext\n@load ssl\n\nmodule SSL_KnownCerts;\n\nexport {\n\tconst local_domains = \/(^|\\.)(osu|ohio-state)\\.edu$\/ |\n\t \/(^|\\.)akamai(tech)?\\.net$\/ &redef;\n\n\t# The list of all detected certs. This prevents over-logging.\n\tglobal certs: set[addr, port, string] &create_expire=1day &synchronized;\n\t\n\t# The hosts that should be logged.\n\tconst split_log_file = F &redef;\n\tconst logged_hosts: Hosts = LocalHosts &redef;\n\n\tredef enum Notice += {\n\t\t# Raised when a non-local name is found in the CN of a SSL cert served\n\t\t# up from a local system.\n\t\tSSLExternalName,\n\t\t};\n}\n\nevent bro_init()\n{\n LOG::create_logs(\"ssl-known-certs\", All, split_log_file, T);\n LOG::define_header(\"ssl-known-certs\", cat_sep(\"\\t\", \"\\\\N\", \"resp_h\", \"resp_p\", \"subject\"));\n}\n\n\nevent ssl_certificate(c: connection, cert: X509, is_server: bool)\n\t{\n\t# The ssl analyzer doesn't do this yet, so let's do it here.\n\t#add c$service[\"SSL\"];\n\tevent protocol_confirmation(c, ANALYZER_SSL, 0);\n\t\n\tif ( !addr_matches_hosts(c$id$resp_h, logged_hosts) )\n\t\treturn;\n\t\n\tlookup_ssl_conn(c, \"ssl_certificate\", T);\n\tlocal conn = ssl_connections[c$id];\n\tif ( [c$id$resp_h, c$id$resp_p, cert$subject] !in certs )\n\t\t{\n\t\tadd certs[c$id$resp_h, c$id$resp_p, cert$subject];\n\t\tlocal log = LOG::get_file(\"ssl-known-certs\", c$id$resp_h, F);\n\t\tprint log, cat_sep(\"\\t\", \"\\\\N\", c$id$resp_h, fmt(\"%d\", c$id$resp_p), cert$subject);\n\n\t if(is_local_addr(c$id$resp_h))\n\t {\n\t local parts = split_all(cert$subject, \/CN=[^\\\/]+\/);\n\t if (|parts| == 3)\n\t {\n\t local cn = parts[2];\n\t if (local_domains !in cn)\n\t {\n\t NOTICE([$note=SSLExternalName,\n\t $msg=fmt(\"SSL Cert for %s returned from an internal host - %s\", cn, c$id$resp_h),\n\t $conn=c]);\n\t }\n\t }\n\t }\n\t }\n\t}\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f1208b661301340b92e88faee919a0b4fdc50771","subject":"have total be the number of connections","message":"have total be the number of connections\n\nthis should maybe be MAIL or RCPT and not HELO\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"smtp-ext-count-rejects.bro","new_file":"smtp-ext-count-rejects.bro","new_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes)\n ++foo$rejects;\n\n if ( \/^([hH]|[eE]){2}[lL][oO]\/ in cmd )\n ++foo$total;\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","old_contents":"# For this script to work, you must define a local_mail table\n# listing all of your known mail sending hosts.\n# i.e. const local_mail: set[subnet] = { 1.2.3.4\/32 };\n\n@ifdef ( local_mail )\n\n@load conn-id\n@load smtp\n\nmodule SMTP;\n\ntype smtp_counter: record {\n rejects: count;\n total: count;\n};\n\nexport {\n # The idea for this is that if a host makes more than spam_threshold \n # smtp connections per hour of which at least spam_percent of those are\n # rejected and the host is not a known mail sending host, then it's likely \n # sending spam or viruses.\n #\n const spam_threshold = 300 &redef;\n const spam_percent = 30 &redef;\n\n # These are smtp status codes that are considered \"rejected\".\n const smtp_reject_codes: set[count] = {\n 501, # Bad sender address syntax\n 550, # Requested action not taken: mailbox unavailable\n 551, # User not local; please try \n 553, # Requested action not taken: mailbox name not allowed\n 554, # Transaction failed\n };\n\n redef enum Notice += {\n SMTP_PossibleSpam, # Host sending mail *to* internal hosts is suspicious\n SMTP_PossibleInternalSpam, # Internal host seems to be spamming\n SMTP_StrangeRejectBehavior, # Local mail server is getting high numbers of rejects \n };\n\n global smtp_status_comparison: table[addr] of smtp_counter &create_expire=1hr &redef;\n}\n\nevent smtp_reply(c: connection, is_orig: bool, code: count, cmd: string,\n\t\t msg: string, cont_resp: bool)\n{\n if ( c$id$orig_h !in smtp_status_comparison ) \n {\n smtp_status_comparison[c$id$orig_h] = [$rejects=0, $total=0];\n }\n\n # Set the smtp_counter to the local var \"foo\"\n local foo = smtp_status_comparison[c$id$orig_h];\n\n if ( code in smtp_reject_codes)\n ++foo$rejects;\n\n ++foo$total;\n\n local host = c$id$orig_h;\n if ( foo$total >= spam_threshold ) {\n local percent = (foo$rejects*100) \/ foo$total;\n if ( percent >= spam_percent ) {\n if ( host in local_mail )\n NOTICE([$note=SMTP_StrangeRejectBehavior, $msg=fmt(\"a high percentage of mail from %s is being rejected\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else if ( is_local_addr(host) ) \n NOTICE([$note=SMTP_PossibleInternalSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n else \n NOTICE([$note=SMTP_PossibleSpam, $msg=fmt(\"%s appears to be spamming\", host), $sub=fmt(\"sent: %d rejected: %d percent\", foo$total, percent), $conn=c]);\n }\n }\n}\n\n@endif\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"eacd793e35c4e7596055ea68f05bac18df779145","subject":"Fixed bugs that totally broke the script.","message":"Fixed bugs that totally broke the script.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/[3-9][0-9]{3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tlocal cc_match = \"\";\n\t\t\tlocal redacted_cc = \"\";\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches and save one back for \n\t\t\t\t\t# finding it's location.\n\t\t\t\t\tcc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\tredacted_cc = parts[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, cc_match);\n\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : cc_match),\n\t\t\t $data=(redact_log ? redacted_data : data)];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","old_contents":"\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/^[3-9]{4}([ -\\.]?\\x00?[0-9]{4}){3}$\/ &redef;\n\n\tconst cc_separators = \/\\.(.*\\.){3}\/ | \n\t \/\\-(.*\\-){3}\/ | \n\t \/[:blank:](.*[:blank:]){3}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tlocal parts = str_split(gsub(val, \/[^0-9]\/, \"\"), vector(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));\n\tfor ( i in parts )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(parts[i]);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tlocal cc_match = \"\";\n\t\t\tlocal redacted_cc = \"\";\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches and save one back for \n\t\t\t\t\t# finding it's location.\n\t\t\t\t\tcc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\tredacted_cc = parts[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, cc_match);\n\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : cc_match),\n\t\t\t $data=(redact_log ? redacted_data : data)];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"98b7de6df21042e0bf25d91f5db171c7cc411483","subject":"fix typo","message":"fix typo\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"rdp.bro","new_file":"rdp.bro","new_contents":"# $Id$\n@load notice\nglobal rdp_connection: event(c: connection);\n\nmodule RDP;\n\n@load signatures\nredef signature_files += \"rdp.sig\";\nredef signature_actions += { [\"dpd_rdp\"] = SIG_IGNORE };\n\n\nglobal rdp_ports = {\n\t3389\/tcp\n};\nredef capture_filters += { [\"rdp\"] = \"tcp and port 3389\"};\n\nevent signature_match(state: signature_state, msg: string, data: string)\n{\n if (state$id == \"dpd_rdp\"){\n\t\tadd state$conn$service[\"RDP\"];\n event rdp_connection(state$conn);\n }\n}\n","old_contents":"# $Id$\n@load notice\nglobal rdp_connection: event(c: connection);\n\nmodule RDP;\n\n@load signatures\nredef signature_files += \"rdp.sig\";\nredef signature_actions += { [\"dpd_rdp\"] = SIG_IGNORE };\n\n\nglobal rdp_ports = {\n\t3389\/tcp\n};\nredef capture_filters += { [\"rfb\"] = \"tcp and port 3389\"};\n\nevent signature_match(state: signature_state, msg: string, data: string)\n{\n if (state$id == \"dpd_rdp\"){\n\t\tadd state$conn$service[\"RDP\"];\n event rdp_connection(state$conn);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"adf097bc195deb6a3e76193dc783dcfd80302665","subject":"Load scripts","message":"Load scripts\n","repos":"finarfin\/smbx,finarfin\/smbx","old_file":"scripts\/init.bro","new_file":"scripts\/init.bro","new_contents":"@load .\/Custom\/SMB\n","old_contents":"","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"ac84b4c3d5d94563fe79fb43d4cfccc751912aa7","subject":"Add default value for enable_software_deduplication","message":"Add default value for enable_software_deduplication\n","repos":"hosom\/bro-napatech,hosom\/bro-napatech","old_file":"scripts\/init.bro","new_file":"scripts\/init.bro","new_contents":"##! Packet source using Napatech\n\nmodule Napatech;\n\nexport {\n ## Should the plugin try to deduplicate packets with the color1\n ## value of the DYN4 packet descriptor?\n const enable_software_deduplication = T &redef;\n ## The size of the software deduplication lru cache\n const dedupe_lru_size = 1024 &redef;\n ## Because applications can share streams, the Host Buffer Allowance\n ## allows an application to consume a portion of the host buffer \n ## before the application stops receiving traffic.\n ## For Bro, you most likely want to set this to 100\n const host_buffer_allowance = 100 &redef;\n}","old_contents":"##! Packet source using Napatech\n\nmodule Napatech;\n\nexport {\n ## The size of the software deduplication lru cache\n const dedupe_lru_size = 1024 &redef;\n ## Because applications can share streams, the Host Buffer Allowance\n ## allows an application to consume a portion of the host buffer \n ## before the application stops receiving traffic.\n ## For Bro, you most likely want to set this to 100\n const host_buffer_allowance = 100 &redef;\n}","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f2c8c0c9734aa16f0621775d8955f1368b83b8b1","subject":"Weiteren Syntaxfehler im Script gefixt.","message":"Weiteren Syntaxfehler im Script gefixt.\n","repos":"UHH-ISS\/beemaster-bro","old_file":"custom_scripts\/dionaea_receiver.bro","new_file":"custom_scripts\/dionaea_receiver.bro","new_contents":"@load .\/dio_incident_log.bro\n@load .\/dio_json_log.bro\n@load .\/dio_mysql_log.bro\n@load .\/dio_download_complete_log.bro\n@load .\/dio_download_offer_log.bro\n@load .\/dio_smb_bind_log.bro\n@load .\/dio_smb_request_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string);\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, md5hash: string, file: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_incident::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $connector_id=connector_id];\n\n Log::write(Dio_incident::LOG, rec);\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n\n Log::write(Dio_mysql::LOG, rec);\n}\n\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, md5hash: string, file: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_download_complete: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, url=%s, md5hash=%s, file=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, url, md5hash, file, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $url=url, $md5hash=md5hash, $file=file, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_download_offer: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, url=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, url, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_smb_request: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, opnum=%d, uuid=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, opnum, uuid, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_smb_bind: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, transfersyntax=%s, uuid=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, transfersyntax, uuid, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","old_contents":"@load .\/dio_incident_log.bro\n@load .\/dio_json_log.bro\n@load .\/dio_mysql_log.bro\n@load .\/dio_download_complete_log.bro\n@load .\/dio_download_offer_log.bro\n@load .\/dio_smb_bind_log.bro\n@load .\/dio_smb_request_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"listener\";\nglobal dionaea_connection: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string);\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal dionaea_download_complete: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, md5hash: string, file: string, origin: string, connector_id: string);\nglobal dionaea_download_offer: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, origin: string, connector_id: string);\nglobal dionaea_smb_request: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, opnum: count, uuid: string, origin: string, connector_id: string);\nglobal dionaea_smb_bind: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, transfersyntax: string, uuid: string, origin: string, connector_id: string);\nglobal get_protocol: function(proto_str: string) : transport_proto;\n\n\nevent bro_init() {\n print \"dionaea_receiver.bro: bro_init()\";\n Broker::enable();\n Broker::listen(broker_port, \"0.0.0.0\");\n Broker::subscribe_to_events(\"honeypot\/dionaea\/\");\n print \"dionaea_receiver.bro: bro_init() done\";\n}\nevent bro_done() {\n print \"dionaea_receiver.bro: bro_done()\";\n}\n\nevent dionaea_connection(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_connection: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_incident::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $connector_id=connector_id];\n\n Log::write(Dio_incident::LOG, rec);\n}\n\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\n\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n\n Log::write(Dio_mysql::LOG, rec);\n}\n\nevent dionaea_download_complete(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, md5hash: string, file: string, origin: string, connector_id: string) { \n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_download_complete: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, url=%s, md5hash=%s, file=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, url, md5hash, file, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_download_complete::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $url=url, $md5hash=md5hash, $file=file, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_complete::LOG, rec);\n}\n\nevent dionaea_download_offer(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, url: string, origin: string, connector_id: string) {\n{\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_download_offer: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, url=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, url, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_download_offer::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $url=url, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_download_offer::LOG, rec);\n}\n\nevent dionaea_smb_request(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, opnum: count, uuid: string, origin: string, connector_id: string) {\n\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_smb_request: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, opnum=%d, uuid=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, opnum, uuid, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_smb_request::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $opnum=opnum, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_request::LOG, rec);\n}\n\nevent dionaea_smb_bind(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, transfersyntax: string, uuid: string, origin: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n\n print fmt(\"dionaea_smb_bind: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, transfersyntax=%s, uuid=%s, origin=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, transfersyntax, uuid, origin, connector_id);\n print fmt(\"converted ports %s %s\", lport, rport);\n local rec: Dio_smb_bind::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $transfersyntax=transfersyntax, $uuid=uuid, $origin=origin, $connector_id=connector_id];\n\n Log::write(Dio_smb_bind::LOG, rec);\n}\n\n\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"-> Broker::incoming_connection_established\", peer_name;\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"-> Broker::incoming_connection_broken\", peer_name;\n}\n\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"cd4262934708d5b5a226a7e9a089c076754e97db","subject":"Update ja3.bro","message":"Update ja3.bro","repos":"salesforce\/ja3","old_file":"bro\/ja3.bro","new_file":"bro\/ja3.bro","new_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n# LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\n@if ( ( Version::number >= 20600 ) || ( Version::number == 20500 && Version::info$commit >= 944 ) )\nevent ssl_client_hello(c: connection, version: count, record_version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec, comp_methods: index_vec) &priority=1\n@else\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n@endif\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","old_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n# LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig == T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\n@if ( Version::number >= 20600 || ( Version::number == 20500 && Version::info$commit >= 944 ) )\nevent ssl_client_hello(c: connection, version: count, record_version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec, comp_methods: index_vec) &priority=1\n@else\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n@endif\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n# LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n# FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"654ba51884fcb4e6ceb0cb499ef2329584bf9a4e","subject":"using the same enum twice in different events results in an error.","message":"using the same enum twice in different events results in an error.\n\nError message:\nidentifier or enumerator value in enumerated type definition already exists\n","repos":"FrozenCaribou\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,rsmmr\/hilti,rsmmr\/hilti,rsmmr\/hilti,FrozenCaribou\/hilti,FrozenCaribou\/hilti","old_file":"bro\/tests\/pac2\/multiple-enum.bro","new_file":"bro\/tests\/pac2\/multiple-enum.bro","new_contents":"#\n# @TEST-EXEC: bro .\/dtest.evt %INPUT\n#\n# @TEST-KNOWN-FAILURE: using the same enum twice in different events results in an error.\n\n# @TEST-START-FILE dtest.evt\n\ngrammar dtest.pac2;\n\nprotocol analyzer pac2::dtest over UDP:\n parse with dtest::Message,\n port 47808\/udp;\n\non dtest::Message if ( self.sswitch == 0 )\n -> event dtest_one(self.result);\n\non dtest::Message if ( self.sswitch == 1 )\n -> event dtest_two(self.result);\n\n# @TEST-END-FILE\n# @TEST-START-FILE dtest.pac2\n\nmodule dtest;\n\ntype RESULT = enum {\n A, B, C, D, E, F\n};\n\nexport type Message = unit {\n sswitch: uint8;\n result: uint8 &convert=RESULT($$);\n};\n\n# @TEST-END-FILE\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro\/tests\/pac2\/multiple-enum.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"1705257c0a959ad1310bd1525ff41f784aca0df1","subject":"fixes","message":"fixes\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"dump_http.bro","new_file":"dump_http.bro","new_contents":"global f: file = open(\"http.txt\");\nevent bro_init()\n{\n enable_raw_output(f);\n}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n{\n print f, \"---------------\\n\";\n print f, fmt(\"%s %s %s %s %s\\n\", c$id$orig_h, c$id$resp_h, c$http$host, c$http$uri, c$http);\n print f, data;\n print f, \"---------------\\n\";\n}\n","old_contents":"global f: file = open(\"http.txt\");\nevent bro_init()\n{\n enable_raw_output(f);\n}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n{\n print f, \"---------------\";\n print f, c$id$orig_h, c$id$resp_h, c$http;\n print f, data;\n print f, \"---------------\";\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"16c0240f5627bca06a4a735cd4683a1fc236445b","subject":"cleanups, new features","message":"cleanups, new features\n\nmake it a propper module\nadd a set of seen user, ips to decrease logging\nlook up the geoip location and dns of the connecting ip\n","repos":"JustinAzoff\/bro_scripts,JustinAzoff\/bro_scripts","old_file":"simple-clear-passwords.bro","new_file":"simple-clear-passwords.bro","new_contents":"redef capture_filters += { [\"pop3\"] = \"port 110\" };\n\nglobal pop3_ports = { 110\/tcp } &redef;\nredef dpd_config += { [ANALYZER_POP3] = [$ports = pop3_ports] };\n\nmodule ClearPasswords;\n\nexport {\n global clear_log_file = open_log_file(\"clear-password-users\") &raw_output;\n global seen_clear_users: set[addr, string] &create_expire=1day &synchronized &persistent;\n}\n\n\n\nevent pop3_request(c: connection, is_orig: bool, command: string, arg: string)\n{\n}\n\nfunction log_clear_pw(c: connection, status: string, user: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n if([c$id$orig_h, user] in seen_clear_users)\n return;\n add seen_clear_users[c$id$orig_h, user];\n\n local loc = lookup_location(c$id$orig_h);\n when( local hostname = lookup_addr(c$id$orig_h) ){\n print clear_log_file, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n c$id$orig_h,\n c$id$resp_h,\n port_to_count(c$id$resp_p),\n hostname,\n loc$country_code,\n loc$region,\n \"success\",\n user);\n }\n\n}\n\nevent pop3_login_success(c: connection, is_orig: bool,\n user: string, password: string)\n{\n log_clear_pw(c, \"success\", user);\n}\n\n\nevent pop3_login_failure(c: connection, is_orig: bool,\n user: string, password: string)\n{\n log_clear_pw(c, \"failure\", user);\n}\n","old_contents":"global clear_log_file = open_log_file(\"clear-password-users\") &raw_output;\n\nredef capture_filters += { [\"pop3\"] = \"port 110\" };\n\nglobal pop3_ports = { 110\/tcp } &redef;\nredef dpd_config += { [ANALYZER_POP3] = [$ports = pop3_ports] };\n\nevent pop3_request(c: connection, is_orig: bool, command: string, arg: string)\n{\n}\n\n\nevent pop3_login_success(c: connection, is_orig: bool,\n user: string, password: string)\n{\n if(is_local_addr(c$id$orig_h))\n return;\n print clear_log_file, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n c$id$orig_h,\n c$id$resp_h,\n port_to_count(c$id$resp_p),\n \"success\",\n user);\n}\n\n\nevent pop3_login_failure(c: connection, is_orig: bool,\n user: string, password: string)\n{\n if(!is_local_addr(c$id$orig_h))\n return;\n print clear_log_file, cat_sep(\"\\t\", \"\\\\N\",\n network_time(),\n c$id$orig_h,\n c$id$resp_h,\n port_to_count(c$id$resp_p),\n \"failure\",\n user);\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"f74814a59f115be2c83c3f246646f7a66e57ff8f","subject":"use correct event for slave:","message":"use correct event for slave:\n\nconnection event does not exist anymore. It seems to be some relic, that\nsomehow made its way back into the master, hence this branch.\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_slave\/dionaea_receiver.bro","new_file":"scripts_slave\/dionaea_receiver.bro","new_contents":"","old_contents":"","returncode":0,"stderr":"unknown","license":"mit","lang":"Bro"} {"commit":"714ad9d708c8a29ea4d700ac371b7ac3ca2e8b26","subject":"beautify some log messages","message":"beautify some log messages\n","repos":"UHH-ISS\/beemaster-bro","old_file":"scripts_master\/bro_receiver.bro","new_file":"scripts_master\/bro_receiver.bro","new_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection established \" + peer_name;\n log_bro(\"Incoming connection established \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n log_bro(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n log_bro(\"Registered new slave \" + peer_name);\n \n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not balance connector\", peer_name, \"because no slaves are ready\";\n log_bro(\"Could not balance connector \" + peer_name + \" because no slaves are ready\");\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n log_bro(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n log_bro(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_bro(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n log_bro(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_bro(\"Rebalanced connector \" + rebalanced_conn + \" to slave \" + balanced_to);\n }\n }\n }\n timeout 100msec {\n log_bro(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}","old_contents":"@load .\/dio_log.bro\n@load .\/bro_log.bro\n@load .\/dio_mysql_log.bro\nconst broker_port: port = 9999\/tcp &redef;\nredef exit_only_after_terminate = T;\nredef Broker::endpoint_name = \"bro_receiver\";\nglobal dionaea_access: event(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string);\nglobal dionaea_mysql: event(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string); \nglobal get_protocol: function(proto_str: string) : transport_proto;\nglobal log_bro: function(msg: string);\nglobal slaves: table[string] of count;\nglobal connectors: opaque of Broker::Handle;\nglobal add_to_balance: function(peer_name: string);\nglobal remove_from_balance: function(peer_name: string);\nglobal rebalance_all: function();\n\nevent bro_init() {\n log_bro(\"bro_receiver.bro: bro_init()\");\n Broker::enable([$auto_publish=T]);\n\n Broker::listen(broker_port, \"0.0.0.0\");\n\n Broker::subscribe_to_events(\"bro\/forwarder\");\n\n ## create a distributed datastore for the connector to link against:\n connectors = Broker::create_master(\"connectors\");\n\n log_bro(\"bro_receiver.bro: bro_init() done\");\n}\nevent bro_done() {\n log_bro(\"bro_receiver.bro: bro_done()\");\n}\nevent dionaea_access(timestamp: time, dst_ip: addr, dst_port: count, src_hostname: string, src_ip: addr, src_port: count, transport: string, protocol: string, connector_id: string) {\n local sport: port = count_to_port(src_port, get_protocol(transport));\n local dport: port = count_to_port(dst_port, get_protocol(transport));\n print fmt(\"dionaea_access: timestamp=%s, dst_ip=%s, dst_port=%s, src_hostname=%s, src_ip=%s, src_port=%s, transport=%s, protocol=%s, connector_id=%s\", timestamp, dst_ip, dst_port, src_hostname, src_ip, src_port, transport, protocol, connector_id);\n local rec: Dio_access::Info = [$ts=timestamp, $dst_ip=dst_ip, $dst_port=dport, $src_hostname=src_hostname, $src_ip=src_ip, $src_port=sport, $transport=transport, $protocol=protocol, $connector_id=connector_id];\n\n Log::write(Dio_access::LOG, rec);\n}\nevent dionaea_mysql(timestamp: time, id: string, local_ip: addr, local_port: count, remote_ip: addr, remote_port: count, transport: string, args: string, connector_id: string) {\n local lport: port = count_to_port(local_port, get_protocol(transport));\n local rport: port = count_to_port(remote_port, get_protocol(transport));\n print fmt(\"dionaea_mysql: timestamp=%s, id=%s, local_ip=%s, local_port=%s, remote_ip=%s, remote_port=%s, transport=%s, args=%s, connector_id=%s\", timestamp, id, local_ip, local_port, remote_ip, remote_port, transport, args, connector_id);\n local rec: Dio_mysql::Info = [$ts=timestamp, $id=id, $local_ip=local_ip, $local_port=lport, $remote_ip=remote_ip, $remote_port=rport, $transport=transport, $args=args, $connector_id=connector_id];\n Log::write(Dio_mysql::LOG, rec);\n}\nevent Broker::incoming_connection_established(peer_name: string) {\n print \"Incoming connection extablished \" + peer_name;\n log_bro(\"Incoming connection extablished \" + peer_name);\n add_to_balance(peer_name);\n}\nevent Broker::incoming_connection_broken(peer_name: string) {\n print \"Incoming connection broken for \" + peer_name;\n log_bro(\"Incoming connection broken for \" + peer_name);\n remove_from_balance(peer_name);\n}\nfunction get_protocol(proto_str: string) : transport_proto {\n # https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-transport_proto\n if (proto_str == \"tcp\") {\n return tcp;\n }\n if (proto_str == \"udp\") {\n return udp;\n }\n if (proto_str == \"icmp\") {\n return icmp;\n }\n return unknown_transport;\n}\n\nfunction log_bro(msg:string) {\n local rec: Brolog::Info = [$msg=msg];\n Log::write(Brolog::LOG, rec);\n}\n\nfunction add_to_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n slaves[peer_name] = 0;\n\n print \"Registered new slave \", peer_name;\n log_bro(\"Registered new slave \" + peer_name);\n \n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n local min_count_conn = 100000;\n local best_slave = \"\";\n\n for(slave in slaves) {\n local count_conn = slaves[slave];\n if (count_conn < min_count_conn) {\n best_slave = slave;\n min_count_conn = count_conn;\n }\n }\n # add the connector, regardless if any slave is ready. Thus, at least a reference is stored, that will get rebalanced once a new slave registers.\n Broker::insert(connectors, Broker::data(peer_name), Broker::data(best_slave));\n if (best_slave != \"\") {\n ++slaves[best_slave];\n print \"Registered connector\", peer_name, \"and balanced to\", best_slave;\n log_bro(\"Registered connector \" + peer_name + \" and balanced to \" + best_slave);\n }\n else {\n print \"Could not register connector\", peer_name;\n log_bro(\"Could not register connector \" + peer_name);\n }\n \n }\n}\n\nfunction remove_from_balance(peer_name: string) {\n if(\/bro-slave-\/ in peer_name) {\n delete slaves[peer_name];\n\n print \"Unregistered old slave \", peer_name;\n log_bro(\"Unregistered old slave \" + peer_name + \" ...\");\n\n rebalance_all();\n }\n if(\/beemaster-connector-\/ in peer_name) {\n when(local cs = Broker::lookup(connectors, Broker::data(peer_name))) {\n local connected_slave = Broker::refine_to_string(cs$result);\n Broker::erase(connectors, Broker::data(peer_name));\n if (connected_slave == \"\") {\n # connector was registered, but no slave was there to handle it. If it now goes away, OK!\n print \"Unregistered old connector\", peer_name, \"no connected slave found\";\n log_bro(\"Unregistered old connector \" + peer_name + \" no connected slave found\");\n return;\n }\n local count_conn = slaves[connected_slave];\n if (count_conn > 0) {\n slaves[connected_slave] = count_conn - 1;\n print \"Unregistered old connector\", peer_name, \"from slave\", connected_slave;\n log_bro(\"Unregistered old connector \" + peer_name + \" from slave \" + connected_slave);\n }\n }\n timeout 100msec {\n print \"Timeout unregistering connector\", peer_name;\n log_bro(\"Timeout unregistering connector \" + peer_name);\n }\n }\n}\n\nfunction rebalance_all() {\n local total_slaves = |slaves|;\n local slave_vector: vector of string;\n slave_vector = vector();\n local i = 0;\n for (slave in slaves) {\n slave_vector[i] = slave;\n ++i;\n }\n i = 0;\n when (local keys = Broker::keys(connectors)) {\n local connector_vector: vector of string;\n connector_vector = vector();\n local total_connectors = Broker::vector_size(keys$result);\n while (i < total_connectors) {\n connector_vector[i] = Broker::refine_to_string(Broker::vector_lookup(keys$result, i));\n ++i;\n }\n if (total_slaves == 0) {\n print \"No registered slaves found, invalidating all connectors\";\n log_bro(\"No registered slaves found, invalidating all connectors\");\n local j = 0;\n while (j < i) {\n local connector = connector_vector[j];\n Broker::insert(connectors, Broker::data(connector), Broker::data(\"\"));\n ++j;\n }\n return; # break out.\n }\n while (total_slaves > 0 && total_connectors > 0) {\n local balance_amount = total_connectors \/ total_slaves;\n if (total_connectors % total_slaves > 0) {\n balance_amount = total_connectors \/ total_slaves + 1;\n }\n --total_slaves;\n local balanced_to = slave_vector[total_slaves];\n slaves[balanced_to] = balance_amount;\n local balance_index = total_connectors - balance_amount; # do this once, do this here!\n while (total_connectors > balance_index) {\n --total_connectors;\n local rebalanced_conn = connector_vector[total_connectors];\n Broker::insert(connectors, Broker::data(rebalanced_conn), Broker::data(balanced_to));\n print \"Rebalanced connector\", rebalanced_conn, \"to slave\", balanced_to;\n log_bro(\"Rebalanced connector \" + rebalanced_conn + \"to slave\" + balanced_to);\n }\n }\n }\n timeout 100msec {\n log_bro(\"ERROR: Unable to query keys in 'connectors-data-store' within 100ms, timeout\");\n }\n}","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"d86fb158f66b890918d379e407fa9e32dfa84e19","subject":"Adds pop3 analyzer","message":"Adds pop3 analyzer","repos":"mocyber\/rock-scripts","old_file":"protocols\/pop3\/main.bro","new_file":"protocols\/pop3\/main.bro","new_contents":"##! Basic POP3 analyzer\n# From here: https:\/\/github.com\/albert-magyar\/bro\/blob\/topic\/pop3\/scripts\/base\/protocols\/pop3\/main.bro\n\n@load base\/utils\/numbers\n@load base\/utils\/files\n\nmodule POP3;\n\nexport {\n redef enum Log::ID += { LOG };\n\n ## Set to true to capture passwords from PASS command\n const default_capture_password = F &redef;\n\n type session_state: enum { AUTHORIZATION, TRANSACTION, UPDATE };\n\n\n ## The most significant deviation in this script from the style of\n ## the HTTP and SMTP analyzers is that this record type is NOT used\n ## as a field of the connection struct. In those analyzers, any use\n ## of c$http\/c$smtp in an event handler was preceded by a call to\n ## set_state that caused that field to hold the appropriate Info\n ## record instance. Since the persistence of the contents of that\n ## field were restricted to local scope, it has been replaced with\n ## local variables that hold the correct element of the pending queue.\n type CommandInfo: record {\n ts: time;\n command: string &optional;\n arg: string &optional;\n status: string ;\n msg: string &optional;\n has_client_activity: bool &default=F;\n };\n\n type Info: record {\n ts: time &log;\n uid: string &log;\n id: conn_id &log;\n current_request: count &default=0;\n current_response: count &default=0;\n successful_commands: count &default=0 &log;\n failed_commands: count &default=0 &log;\n pending: table[count] of CommandInfo;\n username: string &optional &log;\n password: string &optional &log;\n state: session_state &default=AUTHORIZATION;\n };\n\n ## Event that can be handled to access the POP3 record sent to the logging framework.\n global log_pop3: event(rec: Info);\n}\n\n# Add the POP3 state tracking fields to the connection record.\nredef record connection += {\n\tpop3: Info &optional;\n};\n\nconst ports = { 110\/tcp };\nredef likely_server_ports += { ports };\nevent bro_init() &priority=5 {\n Log::create_stream(POP3::LOG, [$columns=Info, $ev=log_pop3]);\n Analyzer::register_for_ports(Analyzer::ANALYZER_POP3, ports);\n}\n\n\nfunction new_pop3_command(c: connection): CommandInfo {\n local tmp: CommandInfo;\n tmp$ts=network_time();\n return tmp;\n}\n\nfunction new_pop3_session(c: connection): Info {\n local tmp: Info;\n tmp$ts=network_time();\n tmp$uid=c$uid;\n tmp$id=c$id;\n return tmp;\n}\n\nfunction select_command(c: connection, is_request: bool): CommandInfo {\n if (!c?$pop3) {\n local s: Info;\n c$pop3 = s;\n }\n local current_command: count;\n current_command = (is_request) ? c$pop3$current_request : c$pop3$current_response;\n if (current_command !in c$pop3$pending) {\n c$pop3$pending[current_command] = new_pop3_command(c);\n }\n return c$pop3$pending[current_command];\n}\n\nevent pop3_request(c: connection, is_orig: bool, command: string, arg: string) &priority=5 {\n if (!c?$pop3)\n c$pop3 = new_pop3_session(c);\n local current_command: CommandInfo;\n current_command = select_command(c, is_orig);\n current_command$has_client_activity = T;\n current_command$command = command;\n current_command$arg = arg;\n ++c$pop3$current_request;\n}\n\nfunction process_command(c: connection, command: CommandInfo) {\n if (command?$command && command$status == \"OK\") {\n ++c$pop3$successful_commands;\n switch(command$command) {\n case \"USER\":\n c$pop3$username = command$arg;\n break;\n case \"PASS\":\n if (default_capture_password)\n c$pop3$password = command$arg;\n c$pop3$state = TRANSACTION;\n break;\n case \"QUIT\":\n c$pop3$state = UPDATE;\n break;\n }\n } else if (command?$command && command$status == \"ERR\") {\n ++c$pop3$failed_commands;\n }\n}\n\nevent pop3_reply(c: connection, is_orig: bool, cmd: string, msg: string) &priority=5 {\n if (!c?$pop3)\n c$pop3 = new_pop3_session(c);\n local current_command: CommandInfo;\n current_command = select_command(c, is_orig);\n current_command$status = cmd;\n current_command$msg = msg;\n process_command(c, current_command);\n if (current_command$has_client_activity)\n ++c$pop3$current_response;\n}\n\nevent connection_state_remove(c: connection) &priority=-5 {\n if (c?$pop3) {\n Log::write(POP3::LOG, c$pop3);\n }\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'protocols\/pop3\/main.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"ff2c9dd03e2c859eeef7cacd842bd1979bb7df98","subject":"Update detect-rogue-dns.bro","message":"Update detect-rogue-dns.bro\n\nUpdated year","repos":"theflakes\/cs-bro,CrowdStrike\/cs-bro,kingtuna\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro","old_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/static\/detect-rogue-dns.bro","new_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/static\/detect-rogue-dns.bro","new_contents":"# Detects a Hurricane Panda tactic of using Hurricane Electric to resolve commonly accessed websites\n# Alerts when a domain in the Alexa top 500 is resolved via Hurricane Electric and\/or when a host connects to an IP in the DNS response\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n}\n\n# Current as of 01\/20\/2015\n# alexa.com\/topsites\nconst alexa_table: set[string] = {\n google.com,\n facebook.com,\n youtube.com,\n yahoo.com,\n baidu.com,\n amazon.com,\n wikipedia.org,\n twitter.com,\n taobao.com,\n qq.com,\n google.co.in,\n live.com,\n sina.com.cn,\n weibo.com,\n linkedin.com,\n yahoo.co.jp,\n tmall.com,\n blogspot.com,\n ebay.com,\n hao123.com,\n google.co.jp,\n google.de,\n yandex.ru,\n bing.com,\n sohu.com,\n vk.com,\n instagram.com,\n tumblr.com,\n reddit.com,\n google.co.uk,\n pinterest.com,\n amazon.co.jp,\n wordpress.com,\n msn.com,\n imgur.com,\n google.fr,\n adcash.com,\n google.com.br,\n ask.com,\n paypal.com,\n imdb.com,\n aliexpress.com,\n xvideos.com,\n alibaba.com,\n apple.com,\n fc2.com,\n microsoft.com,\n mail.ru,\n t.co,\n google.it,\n 360.cn,\n google.ru,\n amazon.de,\n google.es,\n kickass.so,\n netflix.com,\n 163.com,\n go.com,\n xinhuanet.com,\n gmw.cn,\n onclickads.net,\n google.com.hk,\n craigslist.org,\n stackoverflow.com,\n xhamster.com,\n people.com.cn,\n google.ca,\n amazon.co.uk,\n naver.com,\n soso.com,\n amazon.cn,\n googleadservices.com,\n pornhub.com,\n bbc.co.uk,\n google.com.tr,\n cnn.com,\n diply.com,\n rakuten.co.jp,\n espn.go.com,\n ebay.de,\n nicovideo.jp,\n dailymotion.com,\n google.com.mx,\n adobe.com,\n cntv.cn,\n flipkart.com,\n google.pl,\n youku.com,\n google.com.au,\n alipay.com,\n ok.ru,\n blogger.com,\n huffingtonpost.com,\n dropbox.com,\n chinadaily.com.cn,\n googleusercontent.com,\n wikia.com,\n nytimes.com,\n google.co.kr,\n ebay.co.uk,\n dailymail.co.uk,\n china.com,\n livedoor.com,\n github.com,\n indiatimes.com,\n pixnet.net,\n jd.com,\n tudou.com,\n sogou.com,\n outbrain.com,\n uol.com.br,\n buzzfeed.com,\n gmail.com,\n xnxx.com,\n google.com.tw,\n blogspot.in,\n amazon.in,\n booking.com,\n google.com.eg,\n chase.com,\n ameblo.jp,\n cnet.com,\n redtube.com,\n pconline.com.cn,\n directrev.com,\n flickr.com,\n amazon.fr,\n douban.com,\n about.com,\n yelp.com,\n wordpress.org,\n dmm.co.jp,\n ettoday.net,\n walmart.com,\n globo.com,\n bankofamerica.com,\n youporn.com,\n bp.blogspot.com,\n youradexchange.com,\n vimeo.com,\n google.com.pk,\n coccoc.com,\n google.nl,\n etsy.com,\n snapdeal.com,\n naver.jp,\n deviantart.com,\n godaddy.com,\n bbc.com,\n daum.net,\n amazonaws.com,\n themeforest.net,\n bestbuy.com,\n aol.com,\n theguardian.com,\n weather.com,\n zol.com.cn,\n google.com.ar,\n adf.ly,\n amazon.it,\n livejasmin.com,\n life.com.tw,\n salesforce.com,\n google.com.sa,\n twitch.tv,\n forbes.com,\n bycontext.com,\n livejournal.com,\n soundcloud.com,\n loading-delivery1.com,\n wikihow.com,\n slideshare.net,\n wellsfargo.com,\n google.gr,\n stackexchange.com,\n jabong.com,\n google.co.id,\n google.co.za,\n leboncoin.fr,\n blogfa.com,\n feedly.com,\n indeed.com,\n ikea.com,\n quora.com,\n ups.com,\n xcar.com.cn,\n espncricinfo.com,\n target.com,\n china.com.cn,\n ziddu.com,\n theadgateway.com,\n allegro.pl,\n businessinsider.com,\n popads.net,\n w3schools.com,\n pixiv.net,\n mozilla.org,\n onet.pl,\n reference.com,\n google.com.ua,\n torrentz.eu,\n 9gag.com,\n mediafire.com,\n files.wordpress.com,\n tubecup.com,\n archive.org,\n wikimedia.org,\n likes.com,\n mailchimp.com,\n tripadvisor.com,\n amazon.es,\n theladbible.com,\n goo.ne.jp,\n usps.com,\n foxnews.com,\n steampowered.com,\n ifeng.com,\n sourceforge.net,\n google.be,\n ndtv.com,\n badoo.com,\n google.co.th,\n zillow.com,\n mystart.com,\n web.de,\n google.com.vn,\n slickdeals.net,\n washingtonpost.com,\n kakaku.com,\n huanqiu.com,\n tianya.cn,\n google.ro,\n skype.com,\n dmm.com,\n ask.fm,\n comcast.net,\n telegraph.co.uk,\n americanexpress.com,\n gmx.net,\n google.com.my,\n secureserver.net,\n bet365.com,\n avg.com,\n mama.cn,\n ign.com,\n force.com,\n akamaihd.net,\n orange.fr,\n gfycat.com,\n steamcommunity.com,\n ppomppu.co.kr,\n gameforge.com,\n answers.com,\n media.tumblr.com,\n google.cn,\n softonic.com,\n google.se,\n newegg.com,\n google.com.co,\n mashable.com,\n reimageplus.com,\n doorblog.jp,\n goodreads.com,\n google.com.ng,\n rediff.com,\n ilividnewtab.com,\n groupon.com,\n stumbleupon.com,\n icicibank.com,\n google.com.sg,\n doublepimp.com,\n google.at,\n wp.pl,\n b5m.com,\n tube8.com,\n rutracker.org,\n chinatimes.com,\n fedex.com,\n abs-cbnnews.com,\n engadget.com,\n zhihu.com,\n caijing.com.cn,\n smzdm.com,\n bild.de,\n pchome.net,\n hdfcbank.com,\n quikr.com,\n rambler.ru,\n amazon.ca,\n google.pt,\n mercadolivre.com.br,\n spiegel.de,\n nfl.com,\n bleacherreport.com,\n t-online.de,\n xuite.net,\n webssearches.com,\n taboola.com,\n weebly.com,\n gizmodo.com,\n hurriyet.com.tr,\n pandora.com,\n shutterstock.com,\n wsj.com,\n gome.com.cn,\n avito.ru,\n what-character-are-you.com,\n homedepot.com,\n seznam.cz,\n youth.cn,\n pclady.com.cn,\n iqiyi.com,\n nih.gov,\n usatoday.com,\n vice.com,\n lifehacker.com,\n webmd.com,\n wix.com,\n hulu.com,\n ebay.in,\n samsung.com,\n hp.com,\n hootsuite.com,\n google.dz,\n extratorrent.cc,\n accuweather.com,\n addthis.com,\n firstmediahub.com,\n speedtest.net,\n kompas.com,\n google.ch,\n ameba.jp,\n macys.com,\n gsmarena.com,\n liveinternet.ru,\n milliyet.com.tr,\n photobucket.com,\n fiverr.com,\n hupu.com,\n 39.net,\n dell.com,\n youm7.com,\n adsrvmedia.net,\n wow.com,\n 4shared.com,\n microsoftonline.com,\n github.io,\n bilibili.com,\n varzesh3.com,\n retailmenot.com,\n myntra.com,\n mobile01.com,\n google.com.pe,\n google.com.bd,\n udn.com,\n capitalone.com,\n tistory.com,\n spotify.com,\n evernote.com,\n theverge.com,\n babytree.com,\n liputan6.com,\n xda-developers.com,\n att.com,\n omiga-plus.com,\n google.com.ph,\n nba.com,\n techcrunch.com,\n wordreference.com,\n google.no,\n battle.net,\n office.com,\n uploaded.net,\n reuters.com,\n libero.it,\n in.com,\n rt.com,\n disqus.com,\n google.co.hu,\n ebay.com.au,\n rbc.ru,\n google.cz,\n time.com,\n goal.com,\n google.ae,\n hstpnetwork.com,\n moz.com,\n intoday.in,\n rottentomatoes.com,\n aili.com,\n goodgamestudios.com,\n lady8844.com,\n onlinesbi.com,\n hudong.com,\n kaskus.co.id,\n twimg.com,\n stylene.net,\n teepr.com,\n zendesk.com,\n google.ie,\n gap.com,\n codecanyon.net,\n yandex.ua,\n verizonwireless.com,\n olx.in,\n okcupid.com,\n bloomberg.com,\n nordstrom.com,\n google.co.il,\n justdial.com,\n intuit.com,\n googleapis.com,\n trackingclick.net,\n ltn.com.tw,\n sahibinden.com,\n 2ch.net,\n free.fr,\n so.com,\n ebay.it,\n thefreedictionary.com,\n csdn.net,\n 12306.cn,\n meetup.com,\n trello.com,\n fbcdn.net,\n autohome.com.cn,\n cnzz.com,\n kinopoisk.ru,\n dsrlte.com,\n gmarket.co.kr,\n detik.com,\n staticwebdom.com,\n marca.com,\n bhaskar.com,\n chinaz.com,\n naukri.com,\n ganji.com,\n gamefaqs.com,\n kohls.com,\n eksisozluk.com,\n ero-advertising.com,\n agoda.com,\n expedia.com,\n npr.org,\n bitly.com,\n mackeeper.com,\n styletv.com.cn,\n allrecipes.com,\n repubblica.it,\n google.fi,\n exoclick.com,\n kickstarter.com,\n baomihua.com,\n beeg.com,\n sears.com,\n mbtrx.com,\n faithtap.com,\n citibank.com,\n ehow.com,\n cloudfront.net,\n tmz.com,\n blog.jp,\n hostgator.com,\n doubleclick.com,\n media1first.com,\n jmpdirect01.com,\n livedoor.biz,\n slimspots.com,\n abcnews.go.com,\n oracle.com,\n chaturbate.com,\n scribd.com,\n outlook.com,\n eyny.com,\n popcash.net,\n xe.com,\n mega.co.nz,\n ink361.com,\n gawker.com,\n sex.com,\n woot.com,\n xywy.com,\n lemonde.fr,\n asos.com,\n ci123.com,\n zippyshare.com,\n chip.de,\n elpais.com,\n putlocker.is,\n nbcnews.com,\n php.net,\n nyaa.se,\n eastday.com,\n google.az,\n list-manage.com,\n eonline.com,\n foodnetwork.com,\n google.dk,\n independent.co.uk,\n statcounter.com\n} &redef;\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n\n # Clean the sub-message.\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"# Detects a Hurricane Panda tactic of using Hurricane Electric to resolve commonly accessed websites\n# Alerts when a domain in the Alexa top 500 is resolved via Hurricane Electric and\/or when a host connects to an IP in the DNS response\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n}\n\n# Current as of 01\/20\/2015\n# alexa.com\/topsites\nconst alexa_table: set[string] = {\n google.com,\n facebook.com,\n youtube.com,\n yahoo.com,\n baidu.com,\n amazon.com,\n wikipedia.org,\n twitter.com,\n taobao.com,\n qq.com,\n google.co.in,\n live.com,\n sina.com.cn,\n weibo.com,\n linkedin.com,\n yahoo.co.jp,\n tmall.com,\n blogspot.com,\n ebay.com,\n hao123.com,\n google.co.jp,\n google.de,\n yandex.ru,\n bing.com,\n sohu.com,\n vk.com,\n instagram.com,\n tumblr.com,\n reddit.com,\n google.co.uk,\n pinterest.com,\n amazon.co.jp,\n wordpress.com,\n msn.com,\n imgur.com,\n google.fr,\n adcash.com,\n google.com.br,\n ask.com,\n paypal.com,\n imdb.com,\n aliexpress.com,\n xvideos.com,\n alibaba.com,\n apple.com,\n fc2.com,\n microsoft.com,\n mail.ru,\n t.co,\n google.it,\n 360.cn,\n google.ru,\n amazon.de,\n google.es,\n kickass.so,\n netflix.com,\n 163.com,\n go.com,\n xinhuanet.com,\n gmw.cn,\n onclickads.net,\n google.com.hk,\n craigslist.org,\n stackoverflow.com,\n xhamster.com,\n people.com.cn,\n google.ca,\n amazon.co.uk,\n naver.com,\n soso.com,\n amazon.cn,\n googleadservices.com,\n pornhub.com,\n bbc.co.uk,\n google.com.tr,\n cnn.com,\n diply.com,\n rakuten.co.jp,\n espn.go.com,\n ebay.de,\n nicovideo.jp,\n dailymotion.com,\n google.com.mx,\n adobe.com,\n cntv.cn,\n flipkart.com,\n google.pl,\n youku.com,\n google.com.au,\n alipay.com,\n ok.ru,\n blogger.com,\n huffingtonpost.com,\n dropbox.com,\n chinadaily.com.cn,\n googleusercontent.com,\n wikia.com,\n nytimes.com,\n google.co.kr,\n ebay.co.uk,\n dailymail.co.uk,\n china.com,\n livedoor.com,\n github.com,\n indiatimes.com,\n pixnet.net,\n jd.com,\n tudou.com,\n sogou.com,\n outbrain.com,\n uol.com.br,\n buzzfeed.com,\n gmail.com,\n xnxx.com,\n google.com.tw,\n blogspot.in,\n amazon.in,\n booking.com,\n google.com.eg,\n chase.com,\n ameblo.jp,\n cnet.com,\n redtube.com,\n pconline.com.cn,\n directrev.com,\n flickr.com,\n amazon.fr,\n douban.com,\n about.com,\n yelp.com,\n wordpress.org,\n dmm.co.jp,\n ettoday.net,\n walmart.com,\n globo.com,\n bankofamerica.com,\n youporn.com,\n bp.blogspot.com,\n youradexchange.com,\n vimeo.com,\n google.com.pk,\n coccoc.com,\n google.nl,\n etsy.com,\n snapdeal.com,\n naver.jp,\n deviantart.com,\n godaddy.com,\n bbc.com,\n daum.net,\n amazonaws.com,\n themeforest.net,\n bestbuy.com,\n aol.com,\n theguardian.com,\n weather.com,\n zol.com.cn,\n google.com.ar,\n adf.ly,\n amazon.it,\n livejasmin.com,\n life.com.tw,\n salesforce.com,\n google.com.sa,\n twitch.tv,\n forbes.com,\n bycontext.com,\n livejournal.com,\n soundcloud.com,\n loading-delivery1.com,\n wikihow.com,\n slideshare.net,\n wellsfargo.com,\n google.gr,\n stackexchange.com,\n jabong.com,\n google.co.id,\n google.co.za,\n leboncoin.fr,\n blogfa.com,\n feedly.com,\n indeed.com,\n ikea.com,\n quora.com,\n ups.com,\n xcar.com.cn,\n espncricinfo.com,\n target.com,\n china.com.cn,\n ziddu.com,\n theadgateway.com,\n allegro.pl,\n businessinsider.com,\n popads.net,\n w3schools.com,\n pixiv.net,\n mozilla.org,\n onet.pl,\n reference.com,\n google.com.ua,\n torrentz.eu,\n 9gag.com,\n mediafire.com,\n files.wordpress.com,\n tubecup.com,\n archive.org,\n wikimedia.org,\n likes.com,\n mailchimp.com,\n tripadvisor.com,\n amazon.es,\n theladbible.com,\n goo.ne.jp,\n usps.com,\n foxnews.com,\n steampowered.com,\n ifeng.com,\n sourceforge.net,\n google.be,\n ndtv.com,\n badoo.com,\n google.co.th,\n zillow.com,\n mystart.com,\n web.de,\n google.com.vn,\n slickdeals.net,\n washingtonpost.com,\n kakaku.com,\n huanqiu.com,\n tianya.cn,\n google.ro,\n skype.com,\n dmm.com,\n ask.fm,\n comcast.net,\n telegraph.co.uk,\n americanexpress.com,\n gmx.net,\n google.com.my,\n secureserver.net,\n bet365.com,\n avg.com,\n mama.cn,\n ign.com,\n force.com,\n akamaihd.net,\n orange.fr,\n gfycat.com,\n steamcommunity.com,\n ppomppu.co.kr,\n gameforge.com,\n answers.com,\n media.tumblr.com,\n google.cn,\n softonic.com,\n google.se,\n newegg.com,\n google.com.co,\n mashable.com,\n reimageplus.com,\n doorblog.jp,\n goodreads.com,\n google.com.ng,\n rediff.com,\n ilividnewtab.com,\n groupon.com,\n stumbleupon.com,\n icicibank.com,\n google.com.sg,\n doublepimp.com,\n google.at,\n wp.pl,\n b5m.com,\n tube8.com,\n rutracker.org,\n chinatimes.com,\n fedex.com,\n abs-cbnnews.com,\n engadget.com,\n zhihu.com,\n caijing.com.cn,\n smzdm.com,\n bild.de,\n pchome.net,\n hdfcbank.com,\n quikr.com,\n rambler.ru,\n amazon.ca,\n google.pt,\n mercadolivre.com.br,\n spiegel.de,\n nfl.com,\n bleacherreport.com,\n t-online.de,\n xuite.net,\n webssearches.com,\n taboola.com,\n weebly.com,\n gizmodo.com,\n hurriyet.com.tr,\n pandora.com,\n shutterstock.com,\n wsj.com,\n gome.com.cn,\n avito.ru,\n what-character-are-you.com,\n homedepot.com,\n seznam.cz,\n youth.cn,\n pclady.com.cn,\n iqiyi.com,\n nih.gov,\n usatoday.com,\n vice.com,\n lifehacker.com,\n webmd.com,\n wix.com,\n hulu.com,\n ebay.in,\n samsung.com,\n hp.com,\n hootsuite.com,\n google.dz,\n extratorrent.cc,\n accuweather.com,\n addthis.com,\n firstmediahub.com,\n speedtest.net,\n kompas.com,\n google.ch,\n ameba.jp,\n macys.com,\n gsmarena.com,\n liveinternet.ru,\n milliyet.com.tr,\n photobucket.com,\n fiverr.com,\n hupu.com,\n 39.net,\n dell.com,\n youm7.com,\n adsrvmedia.net,\n wow.com,\n 4shared.com,\n microsoftonline.com,\n github.io,\n bilibili.com,\n varzesh3.com,\n retailmenot.com,\n myntra.com,\n mobile01.com,\n google.com.pe,\n google.com.bd,\n udn.com,\n capitalone.com,\n tistory.com,\n spotify.com,\n evernote.com,\n theverge.com,\n babytree.com,\n liputan6.com,\n xda-developers.com,\n att.com,\n omiga-plus.com,\n google.com.ph,\n nba.com,\n techcrunch.com,\n wordreference.com,\n google.no,\n battle.net,\n office.com,\n uploaded.net,\n reuters.com,\n libero.it,\n in.com,\n rt.com,\n disqus.com,\n google.co.hu,\n ebay.com.au,\n rbc.ru,\n google.cz,\n time.com,\n goal.com,\n google.ae,\n hstpnetwork.com,\n moz.com,\n intoday.in,\n rottentomatoes.com,\n aili.com,\n goodgamestudios.com,\n lady8844.com,\n onlinesbi.com,\n hudong.com,\n kaskus.co.id,\n twimg.com,\n stylene.net,\n teepr.com,\n zendesk.com,\n google.ie,\n gap.com,\n codecanyon.net,\n yandex.ua,\n verizonwireless.com,\n olx.in,\n okcupid.com,\n bloomberg.com,\n nordstrom.com,\n google.co.il,\n justdial.com,\n intuit.com,\n googleapis.com,\n trackingclick.net,\n ltn.com.tw,\n sahibinden.com,\n 2ch.net,\n free.fr,\n so.com,\n ebay.it,\n thefreedictionary.com,\n csdn.net,\n 12306.cn,\n meetup.com,\n trello.com,\n fbcdn.net,\n autohome.com.cn,\n cnzz.com,\n kinopoisk.ru,\n dsrlte.com,\n gmarket.co.kr,\n detik.com,\n staticwebdom.com,\n marca.com,\n bhaskar.com,\n chinaz.com,\n naukri.com,\n ganji.com,\n gamefaqs.com,\n kohls.com,\n eksisozluk.com,\n ero-advertising.com,\n agoda.com,\n expedia.com,\n npr.org,\n bitly.com,\n mackeeper.com,\n styletv.com.cn,\n allrecipes.com,\n repubblica.it,\n google.fi,\n exoclick.com,\n kickstarter.com,\n baomihua.com,\n beeg.com,\n sears.com,\n mbtrx.com,\n faithtap.com,\n citibank.com,\n ehow.com,\n cloudfront.net,\n tmz.com,\n blog.jp,\n hostgator.com,\n doubleclick.com,\n media1first.com,\n jmpdirect01.com,\n livedoor.biz,\n slimspots.com,\n abcnews.go.com,\n oracle.com,\n chaturbate.com,\n scribd.com,\n outlook.com,\n eyny.com,\n popcash.net,\n xe.com,\n mega.co.nz,\n ink361.com,\n gawker.com,\n sex.com,\n woot.com,\n xywy.com,\n lemonde.fr,\n asos.com,\n ci123.com,\n zippyshare.com,\n chip.de,\n elpais.com,\n putlocker.is,\n nbcnews.com,\n php.net,\n nyaa.se,\n eastday.com,\n google.az,\n list-manage.com,\n eonline.com,\n foodnetwork.com,\n google.dk,\n independent.co.uk,\n statcounter.com\n} &redef;\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n\n # Clean the sub-message.\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"12828e5effe9c096a5550d9bb97b6375918f38c2","subject":"Detection and false positive improvements.","message":"Detection and false positive improvements.\n","repos":"sethhall\/credit-card-exposure","old_file":"main.bro","new_file":"main.bro","new_contents":"\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/(^|[^0-9])\\x00?[3-9](\\x00?[0-9]){3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}([^0-9]|$)\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\t# Remove non digit characters from the beginning and end of string.\n\t\tccp = sub(ccp, \/^[^0-9]*\/, \"\");\n\t\tccp = sub(ccp, \/[^0-9]*$\/, \"\");\n\t\t# Remove any null bytes.\n\t\tccp = gsub(ccp, \/\\x00\/, \"\");\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tlocal cc_match = \"\";\n\t\t\tlocal redacted_cc = \"\";\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches\n\t\t\t\t\tcc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tredacted_cc = gsub(ccp, \/[0-9]\/, redaction_char);\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, cc_match);\n\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : cc_match),\n\t\t\t $data=(redact_log ? redacted_data : data)];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-20secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","old_contents":"\nmodule CreditCardExposure;\n\nexport {\n\tredef enum Log::ID += { LOG };\n\n\tredef enum Notice::Type += { \n\t\tFound\n\t};\n\n\ttype Info: record {\n\t\t## When the SSN was seen.\n\t\tts: time &log;\n\t\t## Unique ID for the connection.\n\t\tuid: string &log;\n\t\t## Connection details.\n\t\tid: conn_id &log;\n\t\t## Credit card number that was discovered.\n\t\tcc: string &log &optional;\n\t\t## Data that was received when the credit card was discovered.\n\t\tdata: string &log;\n\t};\n\t\n\t## Logs are redacted by default. If you want to see the credit card \n\t## numbers in the log, redef this value to F. \n\t## Notices are automatically and unchangeably redacted.\n\tconst redact_log = T &redef;\n\n\t## The character used for redaction to replace all numbers.\n\tconst redaction_char = \"X\" &redef;\n\n\t## The number of bytes around the discovered credit card number that is used \n\t## as a summary in notices.\n\tconst summary_length = 200 &redef;\n\n\tconst cc_regex = \/[3-9][0-9]{3}([[:blank:]\\-\\.]?\\x00?[0-9]{4}){3}\/ &redef;\n\n\tconst cc_separators = \/\\.([0-9]*\\.){2}\/ | \n\t \/\\-([0-9]*\\-){2}\/ | \n\t \/[:blank:]([0-9]*[:blank:]){2}\/ &redef;\n}\n\nconst luhn_vector = vector(0,2,4,6,8,1,3,5,7,9);\nfunction luhn_check(val: string): bool\n\t{\n\tlocal sum = 0;\n\tlocal odd = T;\n\tfor ( char in gsub(val, \/[^0-9]\/, \"\") )\n\t\t{\n\t\todd = !odd;\n\t\tlocal digit = to_count(char);\n\t\tsum += (odd ? digit : luhn_vector[digit]);\n\t\t}\n\treturn sum % 10 == 0;\n\t}\n\nevent bro_init() &priority=5\n\t{\n\tLog::create_stream(CreditCardExposure::LOG, [$columns=Info]);\n\t}\n\n\nfunction check_cards(c: connection, data: string): bool\n\t{\n\tlocal ccps = find_all(data, cc_regex);\n\n\tfor ( ccp in ccps )\n\t\t{\n\t\tif ( cc_separators in ccp && luhn_check(ccp) )\n\t\t\t{\n\t\t\t# we've got a match\n\t\t\tlocal parts = split_all(data, cc_regex);\n\t\t\tlocal cc_match = \"\";\n\t\t\tlocal redacted_cc = \"\";\n\t\t\tfor ( i in parts )\n\t\t\t\t{\n\t\t\t\tif ( i % 2 == 0 )\n\t\t\t\t\t{\n\t\t\t\t\t# Redact all matches and save one back for \n\t\t\t\t\t# finding it's location.\n\t\t\t\t\tcc_match = parts[i];\n\t\t\t\t\tparts[i] = gsub(parts[i], \/[0-9]\/, redaction_char);\n\t\t\t\t\tredacted_cc = parts[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tlocal redacted_data = join_string_array(\"\", parts);\n\t\t\tlocal cc_location = strstr(data, cc_match);\n\n\t\t\tlocal begin = 0;\n\t\t\tif ( cc_location > (summary_length\/2) )\n\t\t\t\tbegin = cc_location - (summary_length\/2);\n\t\t\t\n\t\t\tlocal byte_count = summary_length;\n\t\t\tif ( begin + summary_length > |redacted_data| )\n\t\t\t\tbyte_count = |redacted_data| - begin;\n\n\t\t\tlocal trimmed_data = sub_bytes(redacted_data, begin, byte_count);\n\n\t\t\tNOTICE([$note=Found,\n\t\t\t $conn=c,\n\t\t\t $msg=fmt(\"Redacted excerpt of disclosed credit card session: %s\", trimmed_data),\n\t\t\t $identity=cat(c$id$orig_h,c$id$resp_h)]);\n\n\t\t\tlocal log: Info = [$ts=network_time(), \n\t\t\t $uid=c$uid, $id=c$id,\n\t\t\t $cc=(redact_log ? redacted_cc : cc_match),\n\t\t\t $data=(redact_log ? redacted_data : data)];\n\n\t\t\tLog::write(CreditCardExposure::LOG, log);\n\t\t\treturn T;\n\t\t\t}\n\t\t}\n\treturn F;\n\t}\n\nevent http_entity_data(c: connection, is_orig: bool, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\nevent mime_segment_data(c: connection, length: count, data: string)\n\t{\n\tif ( c$start_time > network_time()-10secs )\n\t\tcheck_cards(c, data);\n\t}\n\n# This is used if the signature based technique is in use\nfunction validate_credit_card_match(state: signature_state, data: string): bool\n\t{\n\t# TODO: Don't handle HTTP data this way.\n\tif ( \/^GET\/ in data )\n\t\treturn F;\n\n\treturn check_cards(state$conn, data);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"e6cba045dd640764b3741234e58cdbcf2b129b59","subject":"update ja3.bro hash from upstream","message":"update ja3.bro hash from upstream\n","repos":"juju4\/ansible-bro-ids,juju4\/ansible-bro-ids,juju4\/ansible-bro-ids","old_file":"ja3.bro","new_file":"ja3.bro","new_contents":"","old_contents":"","returncode":0,"stderr":"unknown","license":"bsd-2-clause","lang":"Bro"} {"commit":"a27e4a37f702f810d0e6ade0726fecc5f3294476","subject":"Bro: todo","message":"Bro: todo\n","repos":"valery1707\/test-sorm,valery1707\/test-sorm,valery1707\/test-sorm,valery1707\/test-sorm","old_file":"src\/main\/resources\/bro\/amt_init.bro","new_file":"src\/main\/resources\/bro\/amt_init.bro","new_contents":"##! \u0421\u043a\u0440\u0438\u043f\u0442 \u0441 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438: \n##! * \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0432 \u043b\u043e\u0433\u0438\n##! * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414\n##! * \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432\n\n@load base\/protocols\/conn\/main.bro\n\n#https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-fa_file\n@load base\/frameworks\/files\/main.bro\n@load base\/protocols\/ftp\/files.bro\n@load base\/protocols\/http\/entities.bro\n\n#https:\/\/www.bro.org\/sphinx\/scripts\/base\/frameworks\/files\/main.bro.html#type-Files::Info\n@load base\/files\/hash\/main.bro\n@load base\/files\/extract\/main.bro\n\n#https:\/\/www.bro.org\/sphinx\/frameworks\/logging-input-sqlite.html#id6\n#@load frameworks\/files\/hash-all-files\n\nmodule AMT;\n\n# \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0442\u0438\u043a\u0435\u0442 \u0432 conn \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u043b\u043e\u0433\u043e\u0432 \u0433\u0434\u0435 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e\n#--------------------------------------------------#\n#--------------------------------------------------#\n#--------------------------------------------------#\nredef record Conn::Info += {\n\tamt_tasks: set[count] &default=set();\n\tamt_tasks_list: string &default=\"\" &log;\n};\n\nexport {\n\t## \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0435\n\t##\n\t## c: \u041a\u043e\u043d\u043d\u0435\u043a\u0442\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal catch_conn: function(c: connection, taskId: count): bool;\n\n\t## \u0421\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0437\u0430 \u043f\u043e\u0447\u0442\u043e\u0439\n\t##\n\t## s: eMail\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal watch_email: function(s: string, taskId: count);\n\n\t## \u0421\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0437\u0430 \u0442\u0440\u0430\u0444\u0438\u043a\u043e\u043c \u043f\u043e IP\n\t##\n\t## target: IPv4\/IPv6\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal watch_ip_addr: function(target: addr, taskId: count);\n}\n\n#--------------------------------------------------#\n# \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432 - \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439\n#--------------------------------------------------#\n## table[conn$uid] => set[taskId]\nglobal catched_conn_uid: table[string] of set[count] = {};\n#todo Remove?\nglobal catched_conn_id: set[conn_id] = {};\n\n#--------------------------------------------------#\n# \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d\n#--------------------------------------------------#\nfunction is_catched_conn_single(conn_uid: string): bool {\n\treturn conn_uid in catched_conn_uid;\n}\nfunction is_catched_conn_set(conn_uids: set[string]): bool {\n\tfor (uid in conn_uids) {\n\t\tif (uid in catched_conn_uid) {\n\t\t\treturn T;\n\t\t}\n\t}\n\treturn F;\n}\nfunction is_catched_conn_table(conn: table[conn_id] of connection): bool {\n\tfor (id in conn) {\n\t\tif (is_catched_conn_single(conn[id]$uid)) {\n\t\t\treturn T;\n\t\t}\n\t}\n\treturn F;\n}\n\n\n#--------------------------------------------------#\n# \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043b\u043e\u0433\u043e\u0432\n#--------------------------------------------------#\nfunction filter_conn(rec: Conn::Info): bool {\n\tif (rec$uid in catched_conn_uid) {\n\t\tlocal tasks_list = \"\";\n\t\tfor (taskId in catched_conn_uid[rec$uid]) {\n\t\t\ttasks_list = cat(tasks_list, \",\", taskId);\n\t\t}\n\t\trec$amt_tasks_list = tasks_list + \",\";\n\t\treturn T;\n\t}\n\treturn F;\n}\nfunction filter_smtp(rec: SMTP::Info): bool {\n\treturn is_catched_conn_single(rec$uid);\n}\nfunction filter_http(rec: HTTP::Info): bool {\n\treturn is_catched_conn_single(rec$uid);\n}\nfunction filter_files(rec: Files::Info): bool {\n\treturn is_catched_conn_set(rec$conn_uids);\n}\n\n\n#--------------------------------------------------#\n# \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432\n#--------------------------------------------------#\nevent bro_init() {\n\tprint \"AMT::start\";\n\n\t# Conn\n\tlocal filter = Log::get_filter(Conn::LOG, \"default\");\n\tfilter$pred = filter_conn;\n\tLog::add_filter(Conn::LOG, filter);\n\n\t# SMTP\n\tfilter = Log::get_filter(SMTP::LOG, \"default\");\n\tfilter$pred = filter_smtp;\n\tLog::add_filter(SMTP::LOG, filter);\n\n\t# HTTP\n\tfilter = Log::get_filter(HTTP::LOG, \"default\");\n\tfilter$pred = filter_http;\n\tLog::add_filter(HTTP::LOG, filter);\n\n\t# Files\n\tfilter = Log::get_filter(Files::LOG, \"default\");\n\tfilter$pred = filter_files;\n\tLog::add_filter(Files::LOG, filter);\n}\nevent bro_done() {\n\tprint \"AMT::stop\";\n}\n\n\n#--------------------------------------------------#\n# \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438\n#--------------------------------------------------#\nfunction catch_conn(c: connection, taskId: count): bool {\n\tlocal tasks: set[count];\n\tif (c$uid in catched_conn_uid) {\n\t\ttasks = catched_conn_uid[c$uid];\n\t} else {\n\t\ttasks = set();\n\t}\n\tif (taskId in tasks) {\n\t\t# Already catched\n\t\treturn F;\n\t}\n\tadd tasks[taskId];\n\tcatched_conn_uid[c$uid] = tasks;\n\treturn T;\n}\nfunction catch_conn_multi(c: connection, taskIds: set[count]): bool {\n\tlocal tasks: set[count];\n\tif (c$uid in catched_conn_uid) {\n\t\ttasks = catched_conn_uid[c$uid];\n\t} else {\n\t\ttasks = set();\n\t}\n\tlocal catchedNow = F;\n\tfor (task in taskIds) {\n\t\tif (! (task in tasks)) {\n\t\t\tcatchedNow = T;\n\t\t\tadd tasks[task];\n\t\t}\n\t}\n\tif (catchedNow) {\n\t\tcatched_conn_uid[c$uid] = tasks;\n\t}\n\treturn catchedNow;\n}\n\n## table[email] => set[taskId]\nglobal watch_emails: table[string] of set[count] = {};\n## table[email] => pattern\nglobal watch_emails_p: table[string] of pattern = {};\nfunction watch_email(s: string, taskId: count) {\n\tlocal p: pattern = string_to_pattern(s, T);\n\tlocal tasks: set[count] = set();\n\tif (s in watch_emails) {\n\t\ttasks = watch_emails[s];\n\t}\n\tadd tasks[taskId];\n\twatch_emails[s] = tasks;\n\twatch_emails_p[s] = p;\n}\n\n## table[addr] => set[taskId]\nglobal watch_ip_addrs: table[addr] of set[count] = {};\nfunction watch_ip_addr(target: addr, taskId: count) {\n\tlocal tasks: set[count] = set();\n\tif (target in watch_ip_addrs) {\n\t\ttasks = watch_ip_addrs[target];\n\t}\n\tadd tasks[taskId];\n\twatch_ip_addrs[target] = tasks;\n}\n\n\n#--------------------------------------------------#\n#---------- \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 ---------#\n#--------------------------------------------------#\n\n# \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432 \u043f\u043e IP\nevent new_connection(c: connection) {\n\tif (! is_catched_conn_single(c$uid)) {#todo \u041d\u0435 \u0432\u0435\u0440\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u044f\u043c \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u043c\n\t\tif (c$id$orig_h in watch_ip_addrs) {\n\t\t\tcatch_conn_multi(c, watch_ip_addrs[c$id$orig_h]);\n\t\t} else if (c$id$resp_h in watch_ip_addrs) {\n\t\t\tcatch_conn_multi(c, watch_ip_addrs[c$id$resp_h]);\n\t\t}\n\t}\n}\n\n# \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 eMail\nevent mime_one_header(c: connection, h: mime_header_rec) {\n#\tprint fmt(\"mime_one_header(c: {uid: '%s'}, h: {name: '%s', value: '%s'})\", c$uid, h$name, h$value);\n\tif (! is_catched_conn_single(c$uid)) {#todo \u041d\u0435 \u0432\u0435\u0440\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u044f\u043c \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u043c\n\t\tif (h$name == \"FROM\" || h$name == \"TO\") {#todo \u041d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f \"\u041a\u043e\u043f\u0438\u044f\" \u0438 \"\u0421\u043a\u0440\u044b\u0442\u0430\u044f \u043a\u043e\u043f\u0438\u044f\"\n#\t\t\tprint fmt(\"Header: %s=%s\", h$name, h$value);\n\t\t\tfor (p in watch_emails) {\n#\t\t\t\tprint fmt(\"Pattern: %s\", p);\n\t\t\t\tif (watch_emails_p[p] in h$value) {\n\t\t\t\t\tprint fmt(\"Catch Mime: conn$uid=%s, h$name=%s, h$value=%s\", c$uid, h$name, h$value);\n\t\t\t\t\tcatch_conn_multi(c, watch_emails[p]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n# \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u0437 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432\nevent file_new(f: fa_file) {\n\tif (is_catched_conn_table(f$conns)) {\n\t\tFiles::add_analyzer(f, Files::ANALYZER_EXTRACT);\n\t}\n}\n\nevent file_sniff(f: fa_file, meta: fa_metadata) {\n#\tlocal fname = fmt(\"%s-%s.%s\", f$source, f$id, meta$mime_type);\n#\tprint fmt(\"Extracting file %s\", fname);\n#\tlocal mime_type = (meta?$mime_type) ? meta$mime_type : \"NONE\";\n#\tprint fmt(\"Source: %s; ID: %s; Mime: %s\", f$source, f$id, mime_type);\n#\tif (f?$info) {\n#\t\tprint fmt(\" Info! ts: %s; mime: %s; filename: %s; md5: %s\", f$info$ts, f$info?$mime_type ? f$info$mime_type : \"NONE\", f$info?$filename ? f$info$filename : \"???\", f$info?$md5 ? f$info$md5 : \"000\");\n#\t}\n}\n","old_contents":"##! \u0421\u043a\u0440\u0438\u043f\u0442 \u0441 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438: \n##! * \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0432 \u043b\u043e\u0433\u0438\n##! * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414\n##! * \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432\n\n@load base\/protocols\/conn\/main.bro\n\n#https:\/\/www.bro.org\/sphinx\/scripts\/base\/init-bare.bro.html#type-fa_file\n@load base\/frameworks\/files\/main.bro\n@load base\/protocols\/ftp\/files.bro\n@load base\/protocols\/http\/entities.bro\n\n#https:\/\/www.bro.org\/sphinx\/scripts\/base\/frameworks\/files\/main.bro.html#type-Files::Info\n@load base\/files\/hash\/main.bro\n@load base\/files\/extract\/main.bro\n\n#https:\/\/www.bro.org\/sphinx\/frameworks\/logging-input-sqlite.html#id6\n#@load frameworks\/files\/hash-all-files\n\nmodule AMT;\n\n# \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0442\u0438\u043a\u0435\u0442 \u0432 conn \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u043b\u043e\u0433\u043e\u0432 \u0433\u0434\u0435 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e\n#--------------------------------------------------#\n#--------------------------------------------------#\n#--------------------------------------------------#\nredef record Conn::Info += {\n\tamt_tasks: set[count] &default=set();\n\tamt_tasks_list: string &default=\"\" &log;\n};\n\nexport {\n\t## \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0435\n\t##\n\t## c: \u041a\u043e\u043d\u043d\u0435\u043a\u0442\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal catch_conn: function(c: connection, taskId: count): bool;\n\n\t## \u0421\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0437\u0430 \u043f\u043e\u0447\u0442\u043e\u0439\n\t##\n\t## s: eMail\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal watch_email: function(s: string, taskId: count);\n\n\t## \u0421\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0437\u0430 \u0442\u0440\u0430\u0444\u0438\u043a\u043e\u043c \u043f\u043e IP\n\t##\n\t## target: IPv4\/IPv6\n\t## taskId: \u041d\u043e\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f\n\tglobal watch_ip_addr: function(target: addr, taskId: count);\n}\n\n#--------------------------------------------------#\n# \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432 - \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439\n#--------------------------------------------------#\n## table[conn$uid] => set[taskId]\nglobal catched_conn_uid: table[string] of set[count] = {};\n#todo Remove?\nglobal catched_conn_id: set[conn_id] = {};\n\n#--------------------------------------------------#\n# \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d\n#--------------------------------------------------#\nfunction is_catched_conn_single(conn_uid: string): bool {\n\treturn conn_uid in catched_conn_uid;\n}\nfunction is_catched_conn_set(conn_uids: set[string]): bool {\n\tfor (uid in conn_uids) {\n\t\tif (uid in catched_conn_uid) {\n\t\t\treturn T;\n\t\t}\n\t}\n\treturn F;\n}\nfunction is_catched_conn_table(conn: table[conn_id] of connection): bool {\n\tfor (id in conn) {\n\t\tif (is_catched_conn_single(conn[id]$uid)) {\n\t\t\treturn T;\n\t\t}\n\t}\n\treturn F;\n}\n\n\n#--------------------------------------------------#\n# \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043b\u043e\u0433\u043e\u0432\n#--------------------------------------------------#\nfunction filter_conn(rec: Conn::Info): bool {\n\tif (rec$uid in catched_conn_uid) {\n\t\tlocal tasks_list = \"\";\n\t\tfor (taskId in catched_conn_uid[rec$uid]) {\n\t\t\ttasks_list = cat(tasks_list, \",\", taskId);\n\t\t}\n\t\trec$amt_tasks_list = tasks_list + \",\";\n\t\treturn T;\n\t}\n\treturn F;\n}\nfunction filter_smtp(rec: SMTP::Info): bool {\n\treturn is_catched_conn_single(rec$uid);\n}\nfunction filter_http(rec: HTTP::Info): bool {\n\treturn is_catched_conn_single(rec$uid);\n}\nfunction filter_files(rec: Files::Info): bool {\n\treturn is_catched_conn_set(rec$conn_uids);\n}\n\n\n#--------------------------------------------------#\n# \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432\n#--------------------------------------------------#\nevent bro_init() {\n\tprint \"AMT::start\";\n\n\t# Conn\n\tlocal filter = Log::get_filter(Conn::LOG, \"default\");\n\tfilter$pred = filter_conn;\n\tLog::add_filter(Conn::LOG, filter);\n\n\t# SMTP\n\tfilter = Log::get_filter(SMTP::LOG, \"default\");\n\tfilter$pred = filter_smtp;\n\tLog::add_filter(SMTP::LOG, filter);\n\n\t# HTTP\n\tfilter = Log::get_filter(HTTP::LOG, \"default\");\n\tfilter$pred = filter_http;\n\tLog::add_filter(HTTP::LOG, filter);\n\n\t# Files\n\tfilter = Log::get_filter(Files::LOG, \"default\");\n\tfilter$pred = filter_files;\n\tLog::add_filter(Files::LOG, filter);\n}\nevent bro_done() {\n\tprint \"AMT::stop\";\n}\n\n\n#--------------------------------------------------#\n# \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438\n#--------------------------------------------------#\nfunction catch_conn(c: connection, taskId: count): bool {\n\tlocal tasks: set[count];\n\tif (c$uid in catched_conn_uid) {\n\t\ttasks = catched_conn_uid[c$uid];\n\t} else {\n\t\ttasks = set();\n\t}\n\tif (taskId in tasks) {\n\t\t# Already catched\n\t\treturn F;\n\t}\n\tadd tasks[taskId];\n\tcatched_conn_uid[c$uid] = tasks;\n\treturn T;\n}\nfunction catch_conn_multi(c: connection, taskIds: set[count]): bool {\n\tlocal tasks: set[count];\n\tif (c$uid in catched_conn_uid) {\n\t\ttasks = catched_conn_uid[c$uid];\n\t} else {\n\t\ttasks = set();\n\t}\n\tlocal catchedNow = F;\n\tfor (task in taskIds) {\n\t\tif (! (task in tasks)) {\n\t\t\tcatchedNow = T;\n\t\t\tadd tasks[task];\n\t\t}\n\t}\n\tif (catchedNow) {\n\t\tcatched_conn_uid[c$uid] = tasks;\n\t}\n\treturn catchedNow;\n}\n\n## table[email] => set[taskId]\nglobal watch_emails: table[string] of set[count] = {};\n## table[email] => pattern\nglobal watch_emails_p: table[string] of pattern = {};\nfunction watch_email(s: string, taskId: count) {\n\tlocal p: pattern = string_to_pattern(s, T);\n\tlocal tasks: set[count] = set();\n\tif (s in watch_emails) {\n\t\ttasks = watch_emails[s];\n\t}\n\tadd tasks[taskId];\n\twatch_emails[s] = tasks;\n\twatch_emails_p[s] = p;\n}\n\n## table[addr] => set[taskId]\nglobal watch_ip_addrs: table[addr] of set[count] = {};\nfunction watch_ip_addr(target: addr, taskId: count) {\n\tlocal tasks: set[count] = set();\n\tif (target in watch_ip_addrs) {\n\t\ttasks = watch_ip_addrs[target];\n\t}\n\tadd tasks[taskId];\n\twatch_ip_addrs[target] = tasks;\n}\n\n\n#--------------------------------------------------#\n#---------- \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 ---------#\n#--------------------------------------------------#\n\n# \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432 \u043f\u043e IP\nevent new_connection(c: connection) {\n\tif (! is_catched_conn_single(c$uid)) {\n\t\tif (c$id$orig_h in watch_ip_addrs) {\n\t\t\tcatch_conn_multi(c, watch_ip_addrs[c$id$orig_h]);\n\t\t} else if (c$id$resp_h in watch_ip_addrs) {\n\t\t\tcatch_conn_multi(c, watch_ip_addrs[c$id$resp_h]);\n\t\t}\n\t}\n}\n\n# \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 eMail\nevent mime_one_header(c: connection, h: mime_header_rec) {\n#\tprint fmt(\"mime_one_header(c: {uid: '%s'}, h: {name: '%s', value: '%s'})\", c$uid, h$name, h$value);\n\tif (! is_catched_conn_single(c$uid)) {\n\t\tif (h$name == \"FROM\" || h$name == \"TO\") {\n#\t\t\tprint fmt(\"Header: %s=%s\", h$name, h$value);\n\t\t\tfor (p in watch_emails) {\n#\t\t\t\tprint fmt(\"Pattern: %s\", p);\n\t\t\t\tif (watch_emails_p[p] in h$value) {\n\t\t\t\t\tprint fmt(\"Catch Mime: conn$uid=%s, h$name=%s, h$value=%s\", c$uid, h$name, h$value);\n\t\t\t\t\tcatch_conn_multi(c, watch_emails[p]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n# \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u0437 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432\nevent file_new(f: fa_file) {\n\tif (is_catched_conn_table(f$conns)) {\n\t\tFiles::add_analyzer(f, Files::ANALYZER_EXTRACT);\n\t}\n}\n\nevent file_sniff(f: fa_file, meta: fa_metadata) {\n#\tlocal fname = fmt(\"%s-%s.%s\", f$source, f$id, meta$mime_type);\n#\tprint fmt(\"Extracting file %s\", fname);\n#\tlocal mime_type = (meta?$mime_type) ? meta$mime_type : \"NONE\";\n#\tprint fmt(\"Source: %s; ID: %s; Mime: %s\", f$source, f$id, mime_type);\n#\tif (f?$info) {\n#\t\tprint fmt(\" Info! ts: %s; mime: %s; filename: %s; md5: %s\", f$info$ts, f$info?$mime_type ? f$info$mime_type : \"NONE\", f$info?$filename ? f$info$filename : \"???\", f$info?$md5 ? f$info$md5 : \"000\");\n#\t}\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Bro"} {"commit":"486ef65b1bf1b387bb5e1f56994abf0dee75f109","subject":"Check event's source before logging","message":"Check event's source before logging\n","repos":"unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/tor\/main.bro","new_file":"bro-scripts\/tor\/main.bro","new_contents":"# Log Tor connections based on IP addresses along with Tor node metadata\n# Based on data collected from torstatus.blutmagie.de\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n# @jshlbrd\n\nmodule Tor;\n\nexport {\n\tredef enum Log::ID += { TOR::LOG };\n\n\ttype Info: record {\n\t## Timestamp for when the event happened.\n\tts: time \t&log;\n\t## Unique ID for the connection.\n\tuid: string &log;\n\t## The connection's 4-tuple of endpoint addresses\/ports.\n\tid: conn_id &log;\n\t## Tor node IP address.\n\ttor_ip: addr &log &optional;\n\t## Tor node router name.\n\trouter_name: string &log &optional;\n\t## Tor node host name.\n\thost_name: string &log &optional;\n\t## Tor node platform \/ version number.\n\tplatform: string &log &optional;\n\t## Tor node country code location.\n\tcountry_code: string &log &optional;\n\t## Tor node bandwidth (in KB\/s).\n\tbandwidth: count\t&log &optional;\n\t## Tor node estimated uptime.\n\tuptime: time\t&log &optional;\n\t## Tor node router port.\n\trouter_port: count\t&log &optional;\n\t## Tor node directory port.\n\tdirectory_port: count\t&log &optional;\n\t## Tor node auth flag.\n\tauth_flag: bool\t&log &optional;\n\t## Tor node exit flag.\n\texit_flag: bool\t&log &optional;\n\t## Tor node fast flag.\n\tfast_flag: bool\t&log &optional;\n\t## Tor node guard flag.\n\tguard_flag: bool\t&log &optional;\n\t## Tor node named flag.\n\tnamed_flag: bool\t&log &optional;\n\t## Tor node stable flag.\n\tstable_flag: bool\t&log &optional;\n\t## Tor node running flag.\n\trunning_flag: bool\t&log &optional;\n\t## Tor node valid flag.\n\tvalid_flag: bool\t&log &optional;\n\t## Tor node v2dir flag.\n\tv2dir_flag: bool\t&log &optional;\n\t## Tor node hibernating flag.\n\thibernating_flag: bool\t&log &optional;\n\t## Tor node bad exit flag.\n\tbad_exit_flag: bool\t&log &optional;\n\t};\n\n\t## Event that can be handled to access the Tor record as it is sent on\n\t## to the logging framework.\n\tglobal log_tor: event(rec: Info);\n}\n\nredef record connection += {\n\ttor: Info &optional;\n};\n\ntype tor_idx: record {\n\ttor_ip:\taddr;\n};\n\ntype tor_table: record {\n\trouter_name: string;\n\tcountry_code: string;\n\tbandwidth: count;\n\tuptime: double;\n\thost_name: string;\n\trouter_port: count;\n\tdirectory_port: string;\n\tauth_flag: count;\n\texit_flag: count;\n\tfast_flag: count;\n\tguard_flag: count;\n\tnamed_flag: count;\n\tstable_flag: count;\n\trunning_flag: count;\n\tvalid_flag: count;\t\n\tv2dir_flag: count;\n\tplatform: string;\n\thibernating_flag: count;\n\tbad_exit_flag: count;\t\n};\n\nglobal torlist: table[addr] of tor_table = table();\nconst torlist_location = \"bro-tor.txt\";\n\n# Create the Tor log stream and load the Tor list\nevent bro_init()\n{\nLog::create_stream(TOR::LOG, [$columns=Info, $ev=log_tor]);\nInput::add_table([$source=torlist_location, $name=\"torlist\", $idx=tor_idx, $val=tor_table, $destination=torlist, $mode=Input::REREAD]);\n}\n\n# Function to establish a Tor info record\nfunction set_session(c: connection)\n{\nif ( ! c?$tor )\n\t{\n\tadd c$service[\"tor\"];\n\tc$tor = [$ts=network_time(),$id=c$id,$uid=c$uid];\n\t}\n}\n\n# Function to convert blutmagie Tor flags from count to bool\nfunction convert_flag(flag: count): bool\n{\nif ( flag == 1 )\n\treturn T;\nelse return F;\n}\n\n# Function to set data in the Tor info record\nfunction set_data(c: connection, tor_ip: addr)\n{\nc$tor$tor_ip = tor_ip;\nif ( torlist[tor_ip]?$router_name )\n\tc$tor$router_name = torlist[tor_ip]$router_name;\nif ( torlist[tor_ip]?$host_name )\n\tc$tor$host_name = torlist[tor_ip]$host_name;\nif ( torlist[tor_ip]?$platform )\n\tc$tor$platform = torlist[tor_ip]$platform;\nif ( torlist[tor_ip]?$country_code )\n\tc$tor$country_code = torlist[tor_ip]$country_code;\nif ( torlist[tor_ip]?$bandwidth )\n\tc$tor$bandwidth = torlist[tor_ip]$bandwidth;\n\nif ( torlist[tor_ip]?$uptime )\n\t{\n\t# Uptime is recorded by hour, so we need to convert it to seconds\n\tlocal uptime_hr = torlist[tor_ip]$uptime;\n\tlocal uptime_time = ( uptime_hr * 3600 );\n\tc$tor$uptime = double_to_time(uptime_time);\n\t}\n\nif ( torlist[tor_ip]?$router_port )\n\tc$tor$router_port = torlist[tor_ip]$router_port;\nif ( torlist[tor_ip]?$directory_port )\n\tif ( torlist[tor_ip]$directory_port != \"None\" )\n\t\tc$tor$directory_port = to_count(torlist[tor_ip]$directory_port);\nif ( torlist[tor_ip]?$auth_flag )\n\tc$tor$auth_flag = convert_flag(torlist[tor_ip]$auth_flag);\nif ( torlist[tor_ip]?$exit_flag )\n\tc$tor$exit_flag = convert_flag(torlist[tor_ip]$exit_flag);\nif ( torlist[tor_ip]?$fast_flag )\n\tc$tor$fast_flag = convert_flag(torlist[tor_ip]$fast_flag);\nif ( torlist[tor_ip]?$guard_flag )\n\tc$tor$guard_flag = convert_flag(torlist[tor_ip]$guard_flag);\nif ( torlist[tor_ip]?$named_flag )\n\tc$tor$named_flag = convert_flag(torlist[tor_ip]$named_flag);\nif ( torlist[tor_ip]?$stable_flag )\n\tc$tor$stable_flag = convert_flag(torlist[tor_ip]$stable_flag);\nif ( torlist[tor_ip]?$running_flag )\n\tc$tor$running_flag = convert_flag(torlist[tor_ip]$running_flag);\nif ( torlist[tor_ip]?$valid_flag )\n\tc$tor$valid_flag = convert_flag(torlist[tor_ip]$valid_flag);\nif ( torlist[tor_ip]?$v2dir_flag )\n\tc$tor$v2dir_flag = convert_flag(torlist[tor_ip]$v2dir_flag);\nif ( torlist[tor_ip]?$hibernating_flag )\n\tc$tor$hibernating_flag = convert_flag(torlist[tor_ip]$hibernating_flag);\nif ( torlist[tor_ip]?$bad_exit_flag )\n\tc$tor$bad_exit_flag = convert_flag(torlist[tor_ip]$bad_exit_flag);\n}\n\n# Generate reporter message when the Tor list is updated\nevent Input::end_of_data(name: string, source: string) \n{\nif ( strcmp(name, \"torlist\") == 0 )\n\t{\n\tlocal msg = fmt(\"Tor list updated at %s\",network_time());\n\tLog::write(Reporter::LOG, [$ts=network_time(), $level=Reporter::INFO, $message=msg]);\n\t}\n}\n\n# Check each new connection for an IP address in the Tor list\nevent new_connection(c: connection )\n{\nif ( c$id$orig_h in torlist ) \n\t{\n\tset_session(c);\n\tset_data(c,c$id$orig_h);\n\t}\nelse if ( c$id$resp_h in torlist )\n\t{\n\tset_session(c);\n\tset_data(c,c$id$resp_h);\n\t}\n}\n\n# Generate the tor.log for each Tor connection \nevent connection_state_remove(c: connection)\n{\nif ( c?$tor )\n\t{\n\tLog::write(TOR::LOG, c$tor);\n\t}\n}\n","old_contents":"# Log Tor connections based on IP addresses along with Tor node metadata\n# Based on data collected from torstatus.blutmagie.de\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n# @jshlbrd\n\nmodule Tor;\n\nexport {\n\tredef enum Log::ID += { TOR::LOG };\n\n\ttype Info: record {\n\t## Timestamp for when the event happened.\n\tts: time \t&log;\n\t## Unique ID for the connection.\n\tuid: string &log;\n\t## The connection's 4-tuple of endpoint addresses\/ports.\n\tid: conn_id &log;\n\t## Tor node IP address.\n\ttor_ip: addr &log &optional;\n\t## Tor node router name.\n\trouter_name: string &log &optional;\n\t## Tor node host name.\n\thost_name: string &log &optional;\n\t## Tor node platform \/ version number.\n\tplatform: string &log &optional;\n\t## Tor node country code location.\n\tcountry_code: string &log &optional;\n\t## Tor node bandwidth (in KB\/s).\n\tbandwidth: count\t&log &optional;\n\t## Tor node estimated uptime.\n\tuptime: time\t&log &optional;\n\t## Tor node router port.\n\trouter_port: count\t&log &optional;\n\t## Tor node directory port.\n\tdirectory_port: count\t&log &optional;\n\t## Tor node auth flag.\n\tauth_flag: bool\t&log &optional;\n\t## Tor node exit flag.\n\texit_flag: bool\t&log &optional;\n\t## Tor node fast flag.\n\tfast_flag: bool\t&log &optional;\n\t## Tor node guard flag.\n\tguard_flag: bool\t&log &optional;\n\t## Tor node named flag.\n\tnamed_flag: bool\t&log &optional;\n\t## Tor node stable flag.\n\tstable_flag: bool\t&log &optional;\n\t## Tor node running flag.\n\trunning_flag: bool\t&log &optional;\n\t## Tor node valid flag.\n\tvalid_flag: bool\t&log &optional;\n\t## Tor node v2dir flag.\n\tv2dir_flag: bool\t&log &optional;\n\t## Tor node hibernating flag.\n\thibernating_flag: bool\t&log &optional;\n\t## Tor node bad exit flag.\n\tbad_exit_flag: bool\t&log &optional;\n\t};\n\n\t## Event that can be handled to access the Tor record as it is sent on\n\t## to the logging framework.\n\tglobal log_tor: event(rec: Info);\n}\n\nredef record connection += {\n\ttor: Info &optional;\n};\n\ntype tor_idx: record {\n\ttor_ip:\taddr;\n};\n\ntype tor_table: record {\n\trouter_name: string;\n\tcountry_code: string;\n\tbandwidth: count;\n\tuptime: double;\n\thost_name: string;\n\trouter_port: count;\n\tdirectory_port: string;\n\tauth_flag: count;\n\texit_flag: count;\n\tfast_flag: count;\n\tguard_flag: count;\n\tnamed_flag: count;\n\tstable_flag: count;\n\trunning_flag: count;\n\tvalid_flag: count;\t\n\tv2dir_flag: count;\n\tplatform: string;\n\thibernating_flag: count;\n\tbad_exit_flag: count;\t\n};\n\nglobal torlist: table[addr] of tor_table = table();\nconst torlist_location = \"bro-tor.txt\";\n\n# Create the Tor log stream and load the Tor list\nevent bro_init()\n{\nLog::create_stream(TOR::LOG, [$columns=Info, $ev=log_tor]);\nInput::add_table([$source=torlist_location, $name=\"torlist\", $idx=tor_idx, $val=tor_table, $destination=torlist, $mode=Input::REREAD]);\n}\n\n# Function to establish a Tor info record\nfunction set_session(c: connection)\n{\nif ( ! c?$tor )\n\t{\n\tadd c$service[\"tor\"];\n\tc$tor = [$ts=network_time(),$id=c$id,$uid=c$uid];\n\t}\n}\n\n# Function to convert blutmagie Tor flags from count to bool\nfunction convert_flag(flag: count): bool\n{\nif ( flag == 1 )\n\treturn T;\nelse return F;\n}\n\n# Function to set data in the Tor info record\nfunction set_data(c: connection, tor_ip: addr)\n{\nc$tor$tor_ip = tor_ip;\nif ( torlist[tor_ip]?$router_name )\n\tc$tor$router_name = torlist[tor_ip]$router_name;\nif ( torlist[tor_ip]?$host_name )\n\tc$tor$host_name = torlist[tor_ip]$host_name;\nif ( torlist[tor_ip]?$platform )\n\tc$tor$platform = torlist[tor_ip]$platform;\nif ( torlist[tor_ip]?$country_code )\n\tc$tor$country_code = torlist[tor_ip]$country_code;\nif ( torlist[tor_ip]?$bandwidth )\n\tc$tor$bandwidth = torlist[tor_ip]$bandwidth;\n\nif ( torlist[tor_ip]?$uptime )\n\t{\n\t# Uptime is recorded by hour, so we need to convert it to seconds\n\tlocal uptime_hr = torlist[tor_ip]$uptime;\n\tlocal uptime_time = ( uptime_hr * 3600 );\n\tc$tor$uptime = double_to_time(uptime_time);\n\t}\n\nif ( torlist[tor_ip]?$router_port )\n\tc$tor$router_port = torlist[tor_ip]$router_port;\nif ( torlist[tor_ip]?$directory_port )\n\tif ( torlist[tor_ip]$directory_port != \"None\" )\n\t\tc$tor$directory_port = to_count(torlist[tor_ip]$directory_port);\nif ( torlist[tor_ip]?$auth_flag )\n\tc$tor$auth_flag = convert_flag(torlist[tor_ip]$auth_flag);\nif ( torlist[tor_ip]?$exit_flag )\n\tc$tor$exit_flag = convert_flag(torlist[tor_ip]$exit_flag);\nif ( torlist[tor_ip]?$fast_flag )\n\tc$tor$fast_flag = convert_flag(torlist[tor_ip]$fast_flag);\nif ( torlist[tor_ip]?$guard_flag )\n\tc$tor$guard_flag = convert_flag(torlist[tor_ip]$guard_flag);\nif ( torlist[tor_ip]?$named_flag )\n\tc$tor$named_flag = convert_flag(torlist[tor_ip]$named_flag);\nif ( torlist[tor_ip]?$stable_flag )\n\tc$tor$stable_flag = convert_flag(torlist[tor_ip]$stable_flag);\nif ( torlist[tor_ip]?$running_flag )\n\tc$tor$running_flag = convert_flag(torlist[tor_ip]$running_flag);\nif ( torlist[tor_ip]?$valid_flag )\n\tc$tor$valid_flag = convert_flag(torlist[tor_ip]$valid_flag);\nif ( torlist[tor_ip]?$v2dir_flag )\n\tc$tor$v2dir_flag = convert_flag(torlist[tor_ip]$v2dir_flag);\nif ( torlist[tor_ip]?$hibernating_flag )\n\tc$tor$hibernating_flag = convert_flag(torlist[tor_ip]$hibernating_flag);\nif ( torlist[tor_ip]?$bad_exit_flag )\n\tc$tor$bad_exit_flag = convert_flag(torlist[tor_ip]$bad_exit_flag);\n}\n\n# Generate reporter message when the Tor list is updated\nevent Input::end_of_data(name: string, source: string) \n{\nlocal msg = fmt(\"Tor list updated at %s\",network_time());\nLog::write(Reporter::LOG, [$ts=network_time(), $level=Reporter::INFO, $message=msg]);\n}\n\n# Check each new connection for an IP address in the Tor list\nevent new_connection(c: connection )\n{\nif ( c$id$orig_h in torlist ) \n\t{\n\tset_session(c);\n\tset_data(c,c$id$orig_h);\n\t}\nelse if ( c$id$resp_h in torlist )\n\t{\n\tset_session(c);\n\tset_data(c,c$id$resp_h);\n\t}\n}\n\n# Generate the tor.log for each Tor connection \nevent connection_state_remove(c: connection)\n{\nif ( c?$tor )\n\t{\n\tLog::write(TOR::LOG, c$tor);\n\t}\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"16675f325a967b1e6bacd2a033149404d3f86398","subject":"bro-scripts: ntp-audit.bro: check for originator in local networks","message":"bro-scripts: ntp-audit.bro: check for originator in local networks\n","repos":"unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts,jonschipp\/bro-scripts,unusedPhD\/jonschipp_bro-scripts","old_file":"ntp-audit.bro","new_file":"ntp-audit.bro","new_contents":"# Written by Jon Schipp, 01-10-2013\n#\n# Detects when hosts send NTP messages to NTP servers not defined in time_servers.\n# To use:\n# 1. Enable the NTP analyzer:\n#\n# If running Bro 2.1 add lines to local.bro:\n#\n# global ports = set(123\/udp);\n# redef dpd_config += { [ANALYZER_NTP] = [$ports = ports]\n# };\n# \n# If running Bro 2.2 add lines to local.bro:\n#\n# event bro_init()\n# {\n# local ports = set(123\/udp);\n# Analyzer::register_for_ports(Analyzer::ANALYZER_NTP,\n# ports);\n# }\n#\n# 2. Copy ntp-audit.bro script to $BROPREFIX\/share\/bro\/site\n# 3. Place the following line into local.bro and put above code from step 1:\n# @load ntp-audit.bro\n# 4. Run commands to validate the script, install it, and put into production: \n# $ broctl check && broctl install && broctl restart\n#\n# If you would like to receive e-mails when a notice event is generated add to emailed_types in local.bro:\n# e.g.\n# redef Notice::emailed_types += {\n# MyScripts::Query_Sent_To_Wrong_Server,\n# };\n\n\n@load base\/frameworks\/notice\n\n# Use namespace so variables don't conflict with those in other scripts\nmodule MyScripts;\n\n# Export sets and types so that they can be redefined outside of this script\nexport {\n\n redef enum Notice::Type += {\n Query_Sent_To_Wrong_Server\n };\n\n # List your NTP servers here \n const time_servers: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n } &redef;\n\n # List any source addresses that should be excluded\n const time_exclude: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n 192.168.1.1, # Gateway\/NAT\/WAN uses external source for time\n } &redef;\n\n}\n\nevent ntp_message(u: connection, msg: ntp_msg, excess: string)\n {\n\n\t # Exit event handler if originator is not in networks.cfg\n\tif (! Site::is_local_addr(u$id$orig_h) )\n\t\treturn;\n\n if ( u$id$orig_h !in time_exclude && u$id$resp_h !in time_servers )\n {\n NOTICE([$note=Query_Sent_To_Wrong_Server,\n $msg=\"NTP query destined to non-defined NTP servers\", $conn=u,\n $identifier=cat(u$id$orig_h),\n $suppress_for=1day]);\n }\n }\n~ \n","old_contents":"# Written by Jon Schipp, 01-10-2013\n#\n# Detects when hosts send NTP messages to NTP servers not defined in time_servers.\n# To use:\n# 1. Enable the NTP analyzer:\n#\n# If running Bro 2.1 add lines to local.bro:\n#\n# global ports = set(123\/udp);\n# redef dpd_config += { [ANALYZER_NTP] = [$ports = ports]\n# };\n# \n# If running Bro 2.2 add lines to local.bro:\n#\n# event bro_init()\n# {\n# local ports = set(123\/udp);\n# Analyzer::register_for_ports(Analyzer::ANALYZER_NTP,\n# ports);\n# }\n#\n# 2. Copy ntp-audit.bro script to $BROPREFIX\/share\/bro\/site\n# 3. Place the following line into local.bro and put above code from step 1:\n# @load ntp-audit.bro\n# 4. Run commands to validate the script, install it, and put into production: \n# $ broctl check && broctl install && broctl restart\n#\n# If you would like to receive e-mails when a notice event is generated add to emailed_types in local.bro:\n# e.g.\n# redef Notice::emailed_types += {\n# MyScripts::Query_Sent_To_Wrong_Server,\n# };\n\n\n@load base\/frameworks\/notice\n\n# Use namespace so variables don't conflict with those in other scripts\nmodule MyScripts;\n\n# Export sets and types so that they can be redefined outside of this script\nexport {\n\n redef enum Notice::Type += {\n Query_Sent_To_Wrong_Server\n };\n\n # List your NTP servers here \n const time_servers: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n } &redef;\n\n # List any source addresses that should be excluded\n const time_exclude: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n 192.168.1.1, # Gateway\/NAT\/WAN uses external source for time\n } &redef;\n\n}\n\nevent ntp_message(u: connection, msg: ntp_msg, excess: string)\n {\n if ( u$id$orig_h !in time_exclude && u$id$resp_h !in time_servers )\n {\n NOTICE([$note=Query_Sent_To_Wrong_Server,\n $msg=\"NTP query destined to non-defined NTP servers\", $conn=u,\n $identifier=cat(u$id$orig_h),\n $suppress_for=1day]);\n }\n }\n~ \n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"7690d6a1ac2baabb5fa79f4ba5d8fab9548a4d2c","subject":"dns-audit.bro: added new script","message":"dns-audit.bro: added new script\n\nThis script is intended to catch hosts making DNS queries\nto DNS servers other than those defined as local DNS servers.\n\nThis works well on small networks where all queries are intended\nto go through a handful of internal DNS servers.\n","repos":"unusedPhD\/jonschipp_bro-scripts,unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts,jonschipp\/bro-scripts","old_file":"dns-audit.bro","new_file":"dns-audit.bro","new_contents":"# Written by Jon Schipp\n# Detects when hosts send DNS requests to non-local DNS servers.\n# \tTo use:\n# \t\t1. Add script to configuration local.bro: $ echo '@load dns-audit.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# \t\t2. Copy script to $BROPREFIX\/share\/bro\/site\n# \t\t3. $ broctl check && broctl install && broctl restart\n\n@load base\/frameworks\/notice\n\nconst dns_servers: set[addr] = {\n\t192.168.1.2,\n\t192.168.1.3,\n} &redef;\n\nconst dns_ignore: set[addr] = {\n\t192.168.1.255,\n\t224.0.0.252,\n\t224.0.0.251,\n} &redef;\n\nconst dns_port_ignore: set[port] = {\n\t5353\/udp,\n\t137\/udp,\n} &redef;\n\nexport {\n\n redef enum Notice::Type += {\n DNS::Request_Sent_To_Wrong_Server\n };\n}\n\nevent dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)\n {\n\n\t# Exit event handler if originator is not in networks.cfg\n\tif (! Site::is_local_addr(c$id$orig_h) )\n\t\treturn;\n\n\t# Exit event handler if originator is an ignore address\n\tif ( c$id$orig_h in dns_ignore )\n\t\treturn;\n\n\t# Exit event handler if originator is our local dns server\n\tif ( c$id$orig_h in dns_servers )\n\t\treturn;\n\n\t# Exit event handler if port is a ignored DNS port\n\tif ( c$id$resp_p in dns_port_ignore )\n\t\treturn;\n\n if ( c$id$resp_h !in dns_servers )\n {\n NOTICE([$note=DNS::Request_Sent_To_Wrong_Server,\n $msg=\"DNS Request destined to non-local DNS servers\", $conn=c,\n $identifier=cat(c$id$orig_h,c$id$resp_h),\n $suppress_for=1day]);\n }\n }\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'dns-audit.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"6a462b84e9ac4da185a0c5bf2bf2d0f1e2ffc0a6","subject":"Add helper script to set up bro for filecarving, with instructions","message":"Add helper script to set up bro for filecarving, with instructions\n","repos":"unixfreak0037\/mwzoo,unixfreak0037\/mwzoo","old_file":"lib\/bro-helpers\/extract-files.bro","new_file":"lib\/bro-helpers\/extract-files.bro","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/unixfreak0037\/mwzoo.git\/'\n","license":"mit","lang":"Bro"} {"commit":"1e906d4e4e4c78e879d0cebed20ff6859d74463d","subject":"Cleaned formatting in ssdp\/main","message":"Cleaned formatting in ssdp\/main\n","repos":"kingtuna\/cs-bro,CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/ssdp\/main.bro","new_file":"bro-scripts\/ssdp\/main.bro","new_contents":"# A simple parser for SSDP traffic. \n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\nmodule SSDP;\n\nexport {\n redef enum Log::ID += { ssdp::LOG };\n\n type Info: record {\n ## Timestamp for when the event happened.\n ts:\t\t\t\ttime &log;\n ## Unique ID for the connection.\n uid:\t\t\tstring &log;\n ## The connection's 4-tuple of endpoint addresses\/ports.\n id:\t\t\t\tconn_id &log;\n ## Request search target. \n ## This value is derived from search requests.\n request_search_target:\tstring\t&log &optional;\n ## Response search target.\n ## This value is derived from advertisements or responses.\n response_search_target:\tstring\t&log &optional;\n ## Device data.\n ## This value should contain a comma-separated list containing \n ## the OS name, OS version, the string \"UPnP\/1.0,\" product name,\n ## and product version. This is specified by the UPnP vendor.\n server:\t\t\tstring\t&log &optional;\n ## Advertisement UUID of device.\n usn:\t\t\tstring\t&log &optional;\n ## URL for UPnP description of device.\n location:\t\t\tstring\t&log &optional;\n ## Vector of all request header fields.\n request_headers:\t\tvector of string &log &optional;\n ## Vector of all response header fields.\n response_headers:\t\tvector of string &log &optional;\n ## Flag the connection if it contains a request.\n seen_request:\t\tbool\t&log &default=F;\n ## Flag the connection if it contains a response.\n seen_response:\t\tbool\t&log &default=F;\n };\n\n ## Event that can be handled to access the rdp record as it is sent on\n ## to the logging framework.\n global log_ssdp: event(rec: Info);\n}\n\nredef record connection += {\n ssdp: Info &optional;\n};\n\n# Function to parse the SSDP data.\nfunction ssdp_headers(s: string): table[string] of string\n {\n local split_data = split_string_all(s,\/\\x0d\\x0a\/);\n local trimmed_ssdp: table[string] of string;\n\n for ( sd in split_data )\n if ( sd % 2 == 0 )\n {\n local split_ssdp = split_string1(split_data[sd],\/: ?\/);\n\n if ( |split_ssdp| == 2 )\n trimmed_ssdp[split_ssdp[0]] = split_ssdp[1];\n }\n\n return trimmed_ssdp;\n }\n\n# Function to initialize the ssdp record.\nfunction set_session(c: connection)\n {\n if ( ! c?$ssdp )\n {\n c$ssdp = [$ts=network_time(),$id=c$id,$uid=c$uid];\n add c$service[\"ssdp\"];\n }\n }\n\nevent bro_init()&priority=5\n {\n Log::create_stream(ssdp::LOG, [$columns=Info, $ev=log_ssdp]);\n }\n\n# Function to process SSDP requests.\nfunction ssdp::ssdp_request(state: signature_state, data: string): bool\n {\n local c = state$conn;\n set_session(c);\n\n local info = c$ssdp;\n info$seen_request = T;\n\n local ssdp_table = ssdp_headers(data);\n\n if ( ! info?$request_headers )\n info$request_headers = vector();\n\n for ( header in ssdp_table )\n {\n info$request_headers[|info$request_headers|] = header;\n\n if ( header == \/[Ss][Tt]\/ )\n info$request_search_target = ssdp_table[header];\n }\n\n return F;\n }\n\n# Function to process SSDP responses.\nfunction ssdp::ssdp_response(state: signature_state, data: string): bool\n {\n local c = state$conn;\n set_session(c);\n\n local info = c$ssdp;\n info$seen_response = T;\n\n local ssdp_table = ssdp_headers(data);\n\n if ( ! info?$response_headers )\n info$response_headers = vector();\n\n for ( header in ssdp_table )\n {\n info$response_headers[|info$response_headers|] = header;\n\n if ( header == \/([Ss]|[Nn])[Tt]\/ )\n info$response_search_target = ssdp_table[header];\n else if ( header == \/[Ss][Ee][Rr][Vv][Ee][Rr]\/ )\n info$server = ssdp_table[header];\n else if ( header == \/[Uu][Ss][Nn]\/ )\n info$usn = ssdp_table[header];\n else if ( header == \/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn]\/ )\n info$location = ssdp_table[header];\n }\n\n return F;\n }\n\n# Event to write the SSDP log.\nevent connection_state_remove(c: connection) &priority=-5\n {\n if ( c?$ssdp )\n Log::write(ssdp::LOG, c$ssdp);\n }\n","old_contents":"# A simple parser for SSDP traffic. \n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\nmodule SSDP;\n\nexport {\n redef enum Log::ID += { ssdp::LOG };\n\n type Info: record {\n ## Timestamp for when the event happened.\n ts:\t\t\ttime &log;\n ## Unique ID for the connection.\n uid:\t\t\tstring &log;\n ## The connection's 4-tuple of endpoint addresses\/ports.\n id:\t\t\tconn_id &log;\n ## Request search target. \n ## This value is derived from search requests.\n request_search_target:\tstring\t&log &optional;\n ## Response search target.\n ## This value is derived from advertisements or responses.\n response_search_target:\tstring\t&log &optional;\n ## Device data.\n ## This value should contain a comma-separated list containing \n ## the OS name, OS version, the string \"UPnP\/1.0,\" product name,\n ## and product version. This is specified by the UPnP vendor.\n server:\t\t\tstring\t&log &optional;\n ## Advertisement UUID of device.\n usn:\t\t\tstring\t&log &optional;\n ## URL for UPnP description of device.\n location:\t\t\tstring\t&log &optional;\n ## Vector of all request header fields.\n request_headers:\tvector of string &log &optional;\n ## Vector of all response header fields.\n response_headers:\tvector of string &log &optional;\n ## Flag the connection if it contains a request.\n seen_request:\t\tbool\t&log &default=F;\n ## Flag the connection if it contains a response.\n seen_response:\t\tbool\t&log &default=F;\n };\n\n ## Event that can be handled to access the rdp record as it is sent on\n ## to the logging framework.\n global log_ssdp: event(rec: Info);\n}\n\nredef record connection += {\n ssdp: Info &optional;\n};\n\n# Function to parse the SSDP data.\nfunction ssdp_headers(s: string): table[string] of string\n {\n local split_data = split_string_all(s,\/\\x0d\\x0a\/);\n local trimmed_ssdp: table[string] of string;\n\n for ( sd in split_data )\n if ( sd % 2 == 0 )\n {\n local split_ssdp = split_string1(split_data[sd],\/: ?\/);\n\n if ( |split_ssdp| == 2 )\n trimmed_ssdp[split_ssdp[0]] = split_ssdp[1];\n }\n\n return trimmed_ssdp;\n }\n\n# Function to initialize the ssdp record.\nfunction set_session(c: connection)\n {\n if ( ! c?$ssdp )\n {\n c$ssdp = [$ts=network_time(),$id=c$id,$uid=c$uid];\n add c$service[\"ssdp\"];\n }\n }\n\nevent bro_init()&priority=5\n {\n Log::create_stream(ssdp::LOG, [$columns=Info, $ev=log_ssdp]);\n }\n\n# Function to process SSDP requests.\nfunction ssdp::ssdp_request(state: signature_state, data: string): bool\n {\n local c = state$conn;\n set_session(c);\n\n local info = c$ssdp;\n info$seen_request = T;\n\n local ssdp_table = ssdp_headers(data);\n\n if ( ! info?$request_headers )\n info$request_headers = vector();\n\n for ( header in ssdp_table )\n {\n info$request_headers[|info$request_headers|] = header;\n\n if ( header == \/[Ss][Tt]\/ )\n info$request_search_target = ssdp_table[header];\n }\n\n return F;\n }\n\n# Function to process SSDP responses.\nfunction ssdp::ssdp_response(state: signature_state, data: string): bool\n {\n local c = state$conn;\n set_session(c);\n\n local info = c$ssdp;\n info$seen_response = T;\n\n local ssdp_table = ssdp_headers(data);\n\n if ( ! info?$response_headers )\n info$response_headers = vector();\n\n for ( header in ssdp_table )\n {\n info$response_headers[|info$response_headers|] = header;\n\n if ( header == \/([Ss]|[Nn])[Tt]\/ )\n info$response_search_target = ssdp_table[header];\n else if ( header == \/[Ss][Ee][Rr][Vv][Ee][Rr]\/ )\n info$server = ssdp_table[header];\n else if ( header == \/[Uu][Ss][Nn]\/ )\n info$usn = ssdp_table[header];\n else if ( header == \/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn]\/ )\n info$location = ssdp_table[header];\n }\n\n return F;\n }\n\n# Event to write the SSDP log.\nevent connection_state_remove(c: connection) &priority=-5\n {\n if ( c?$ssdp )\n Log::write(ssdp::LOG, c$ssdp);\n }\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"52038e1de5e45d4478db73112f82def8bc1f516d","subject":"added __preload__.bro file and moved types call there","message":"added __preload__.bro file and moved types call there\n","repos":"SoftwareConsultingEmporium\/ldap-analyzer,SoftwareConsultingEmporium\/ldap-analyzer,SoftwareConsultingEmporium\/ldap-analyzer","old_file":"scripts\/__preload__.bro","new_file":"scripts\/__preload__.bro","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/SoftwareConsultingEmporium\/ldap-analyzer.git\/'\n","license":"unlicense","lang":"Bro"} {"commit":"2610d37644811f82ccd77e10053355e79f0ce751","subject":"Update detect-shellshock.bro","message":"Update detect-shellshock.bro\n\nRemoved superfluous &synchronized attributes from tables.","repos":"kingtuna\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,theflakes\/cs-bro,albertzaharovits\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/shellshock\/detect-shellshock.bro","new_file":"bro-scripts\/shellshock\/detect-shellshock.bro","new_contents":"# Monitors traffic for Shellshock exploit attempts\n# When exploits are seen containing IP addresses and domain values, monitors traffic for 60 minutes watching for endpoints to connect to IP addresses and domains seen in exploit attempts\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n@load base\/protocols\/dhcp\n@load base\/protocols\/smtp\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Shellshock_DHCP,\n Shellshock_HTTP,\n Shellshock_SMTP,\n Shellshock_Successful_Conn\n };\n}\n\nconst shellshock_pattern = \/((\\(|%28)(\\)|%29)( |%20)(\\{|%7B)|(\\{|%7B)(\\:|%3A)(\\;|%3B))\/ &redef;\n\nconst shellshock_commands = \/wget\/ | \/curl\/;\n\nglobal shellshock_servers: set[addr] &create_expire=60min;\nglobal shellshock_hosts: set[string] &create_expire=60min;\n\n# function to locate and extract domains seen in shellshock exploit attempts\nfunction find_domain(ss: string)\n{\nlocal parts1 = split_all(ss,\/[[:space:]]\/);\nfor ( p in parts1 )\n if ( \"http\" in parts1[p] )\n {\n local parts2 = split_all(parts1[p],\/\\\/\/);\n local output = parts2[5];\n }\n\nif ( output !in shellshock_hosts )\n add shellshock_hosts[output];\n}\n\n# function to locate and extract IP addresses seen in shellshock exploit attempts\nfunction find_ip(ss: string): bool\n{\nlocal b = F;\nlocal remote_servers = find_ip_addresses(ss);\n\nif ( |remote_servers| > 0 )\n {\n b = T;\n for ( rs in remote_servers )\n {\n local s = to_addr(remote_servers[rs]);\n if ( s !in shellshock_servers )\n add shellshock_servers[s];\n }\n }\n\nreturn b;\n}\n\n# event to identify shellshock HTTP exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3\n{\nif ( ! is_orig ) return;\nif ( shellshock_pattern !in value ) return;\n\n# generate a notice of the HTTP exploit attempt\nNOTICE([$note=Shellshock_HTTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock HTTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in value )\n find_domain(value);\n}\n\n# event to identify shellshock DHCP exploit attempts\nevent dhcp_ack(c: connection, msg: dhcp_msg, mask: addr, router: dhcp_router_list, lease: interval, serv_addr: addr, host_name: string)\n{\nif ( shellshock_pattern !in host_name ) return;\n\n# generate a notice of the DHCP exploit attempt\nNOTICE([$note=Shellshock_DHCP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock DHCP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",host_name),\n $identifier=cat(c$id$orig_h,c$id$resp_h,host_name)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(host_name) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in host_name )\n find_domain(host_name);\n}\n\n# event to identify endpoints connecting to domains seen in shellshock exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=5\n{\nif ( name != \"HOST\" ) return;\nif ( value in shellshock_hosts )\n # generate a notice of HTTP connection to domain seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to a domain seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"Domain: %s\",value),\n $identifier=cat(c$id$orig_h,value)]);\n}\n\n# event to identify shellshock SMTP exploit attempts\nevent mime_one_header(c: connection, h: mime_header_rec)\n{\nif ( ! c?$smtp || ! h?$value ) return;\nif ( shellshock_pattern !in h$value ) return;\n\n# generate a notice of the SMTP exploit attempt\nNOTICE([$note=Shellshock_SMTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock SMTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",h$value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,h$value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(h$value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in h$value )\n find_domain(h$value);\n}\n\n# event to identify endpoints connecting to IP addresses seen in shellshock exploit attempts\nevent connection_state_remove(c: connection)\n{\nif ( c$id$resp_h in shellshock_servers )\n # generate a notice of connection to IP address seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to an IP address seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"IP address: %s\",c$id$resp_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"# Monitors traffic for Shellshock exploit attempts\n# When exploits are seen containing IP addresses and domain values, monitors traffic for 60 minutes watching for endpoints to connect to IP addresses and domains seen in exploit attempts\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n@load base\/protocols\/dhcp\n@load base\/protocols\/smtp\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Shellshock_DHCP,\n Shellshock_HTTP,\n Shellshock_SMTP,\n Shellshock_Successful_Conn\n };\n}\n\nconst shellshock_pattern = \/((\\(|%28)(\\)|%29)( |%20)(\\{|%7B)|(\\{|%7B)(\\:|%3A)(\\;|%3B))\/ &redef;\n\nconst shellshock_commands = \/wget\/ | \/curl\/;\n\nglobal shellshock_servers: set[addr] &create_expire=60min &synchronized;\nglobal shellshock_hosts: set[string] &create_expire=60min &synchronized;\n\n# function to locate and extract domains seen in shellshock exploit attempts\nfunction find_domain(ss: string)\n{\nlocal parts1 = split_all(ss,\/[[:space:]]\/);\nfor ( p in parts1 )\n if ( \"http\" in parts1[p] )\n {\n local parts2 = split_all(parts1[p],\/\\\/\/);\n local output = parts2[5];\n }\n\nif ( output !in shellshock_hosts )\n add shellshock_hosts[output];\n}\n\n# function to locate and extract IP addresses seen in shellshock exploit attempts\nfunction find_ip(ss: string): bool\n{\nlocal b = F;\nlocal remote_servers = find_ip_addresses(ss);\n\nif ( |remote_servers| > 0 )\n {\n b = T;\n for ( rs in remote_servers )\n {\n local s = to_addr(remote_servers[rs]);\n if ( s !in shellshock_servers )\n add shellshock_servers[s];\n }\n }\n\nreturn b;\n}\n\n# event to identify shellshock HTTP exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3\n{\nif ( ! is_orig ) return;\nif ( shellshock_pattern !in value ) return;\n\n# generate a notice of the HTTP exploit attempt\nNOTICE([$note=Shellshock_HTTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock HTTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in value )\n find_domain(value);\n}\n\n# event to identify shellshock DHCP exploit attempts\nevent dhcp_ack(c: connection, msg: dhcp_msg, mask: addr, router: dhcp_router_list, lease: interval, serv_addr: addr, host_name: string)\n{\nif ( shellshock_pattern !in host_name ) return;\n\n# generate a notice of the DHCP exploit attempt\nNOTICE([$note=Shellshock_DHCP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock DHCP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",host_name),\n $identifier=cat(c$id$orig_h,c$id$resp_h,host_name)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(host_name) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in host_name )\n find_domain(host_name);\n}\n\n# event to identify endpoints connecting to domains seen in shellshock exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=5\n{\nif ( name != \"HOST\" ) return;\nif ( value in shellshock_hosts )\n # generate a notice of HTTP connection to domain seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to a domain seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"Domain: %s\",value),\n $identifier=cat(c$id$orig_h,value)]);\n}\n\n# event to identify shellshock SMTP exploit attempts\nevent mime_one_header(c: connection, h: mime_header_rec)\n{\nif ( ! c?$smtp || ! h?$value ) return;\nif ( shellshock_pattern !in h$value ) return;\n\n# generate a notice of the SMTP exploit attempt\nNOTICE([$note=Shellshock_SMTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock SMTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",h$value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,h$value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(h$value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in h$value )\n find_domain(h$value);\n}\n\n# event to identify endpoints connecting to IP addresses seen in shellshock exploit attempts\nevent connection_state_remove(c: connection)\n{\nif ( c$id$resp_h in shellshock_servers )\n # generate a notice of connection to IP address seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to an IP address seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"IP address: %s\",c$id$resp_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"e85479604d622f358c619260b5cd4cea80b03fcb","subject":"Create conn-udp-icmp.bro","message":"Create conn-udp-icmp.bro","repos":"CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,albertzaharovits\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/intel-extensions\/seen\/conn-udp-icmp.bro","new_file":"bro-scripts\/intel-extensions\/seen\/conn-udp-icmp.bro","new_contents":"# Support for UDP, ICMP, and non-established TCP connections\n# This will only generate Intel matches when a connection is removed from Bro\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent Conn::log_conn(rec: Conn::Info)\n{\nif ( rec?$proto && ( rec$proto != tcp || ( rec?$history && rec$proto == tcp && \"h\" !in rec$history ) ) ) \n {\n # duration, start_time, addl, and hot are required fields although they are not used by Intel framework\n local dur: interval;\n local history: string;\n\n if ( rec?$duration )\n dur = rec$duration;\n else dur = 0secs;\n\n if ( rec?$history )\n history = rec$history;\n else history = \"\";\n\n local c = [$uid = rec$uid,$id = rec$id,$history = history,$duration = dur,$start_time = 0,$addl = \"\",$hot = 0];\n\n Intel::seen([$host=c$id$orig_h, $conn=c, $where=Conn::IN_ORIG]);\n Intel::seen([$host=c$id$resp_h, $conn=c, $where=Conn::IN_RESP]);\n }\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/intel-extensions\/seen\/conn-udp-icmp.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"7c06e6aff9c6fc4ef196dc4ca98bb27f34b126ed","subject":"Create detect-mac-iworm.bro","message":"Create detect-mac-iworm.bro","repos":"CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,theflakes\/cs-bro,kingtuna\/cs-bro","old_file":"bro-scripts\/mac-backdoor-iworm\/detect-mac-iworm.bro","new_file":"bro-scripts\/mac-backdoor-iworm\/detect-mac-iworm.bro","new_contents":"# Detects endpoints searching Reddit for values related to the Mac.BackDoor.iWorm malware\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/http\n@load base\/frameworks\/notice\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Mac_BackDoor_iWorm,\n };\n}\n\nevent http_message_done(c: connection, is_orig: bool, stat: http_message_stat)\n{\n# stop processing the event if an endpoint is not searching Reddit\nif ( ! is_orig || ! c$http?$host || ! c$http?$uri ) return;\nif ( c$http$host != \"www.reddit.com\" ) return;\nif ( \"?q=\" !in c$http$uri ) return;\n\n# locate and extract the Reddit search value\nlocal clean_reddit_uri = find_last(c$http$uri,\/\\?q\\=.*\/);\nlocal uri_parts = split_all(clean_reddit_uri,\/&\/);\nlocal extract_reddit_search = split1(uri_parts[1],\/\\?q\\=\/);\n\n# confirm that the search value is 8 bytes of an MD5 hash\nif ( |extract_reddit_search[2]| == 16 && extract_reddit_search[2] == \/^[A-Fa-f0-9]{16}$\/ )\n NOTICE([$note=Mac_BackDoor_iWorm,\n $conn=c,\n $msg=fmt(\"%s connected to a Reddit page that may be related to Mac.BackDoor.iWorm\",c$id$orig_h),\n $sub=c$http$uri,\n $identifier=cat(c$id$orig_h,c$http$uri)]);\n}\n\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/mac-backdoor-iworm\/detect-mac-iworm.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"0b86c613ebb683c35bf4a3c8db6e809037fefa61","subject":"Update main.bro","message":"Update main.bro","repos":"theflakes\/cs-bro,albertzaharovits\/cs-bro,kingtuna\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/intel-extensions\/main.bro","new_file":"bro-scripts\/intel-extensions\/main.bro","new_contents":"# Extends functionality of Intel framework in various ways\n# Supports three new indicator types: Email subjects, Usernames, and SSL cert subjects\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n\nmodule Intel;\n\nexport {\n redef enum Intel::Type += {\n \tCERT_SUBJECT,\n EMAIL_SUBJECT\n };\n\n redef enum Intel::Where += {\n \tRADIUS::IN_USER_NAME,\n FTP::IN_USER_NAME,\n SMTP::IN_SUBJECT,\n \tSSL::IN_SERVER_CERT,\n \tSSL::IN_CLIENT_CERT\n };\n}\n","old_contents":"# Extends functionality of Intel framework in various ways\n# Supports three new indicator types: Email subjects, Usernames, and SSL cert subjects\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n\nmodule Intel;\n\nexport {\n redef enum Intel::Type += {\n \tCERT_SUBJECT,\n EMAIL_SUBJECT\n };\n\n redef enum Intel::Where += {\n \tRADIUS::IN_USER_NAME,\n FTP::IN_USER_NAME,\n SMTP::IN_SUBJECT,\n \tSSL::IN_SERVER_CERT,\n \tSSL::IN_CLIENT_CERT\n };\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"8900fdaf83976db12af8d0989d45365699c1cf41","subject":"rsyslog-invalid-pri.bro: add pri to notice","message":"rsyslog-invalid-pri.bro: add pri to notice\n","repos":"unusedPhD\/jonschipp_bro-scripts,unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts,jonschipp\/bro-scripts","old_file":"rsyslog-invalid-pri.bro","new_file":"rsyslog-invalid-pri.bro","new_contents":"# Generates a notice and e-mail if syslog messages contain a PRI greater than 191 but less than 1016\n# fac: (23 but less than 127)\n# Vulnerability: http:\/\/www.rsyslog.com\/remote-syslog-pri-vulnerability\/\n#\n# To use:\n# 1. Add script to configuration local.bro: $ echo '@load rsyslog-invalid-pri.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# 2. Copy script to $BROPREFIX\/share\/bro\/site\n# 3. $ broctl check && broctl install && broctl restart\n# Testing: \n# mausezahn -t syslog severity=7,facility=24,host=mausezahn -P \"Invalid PRI message test\" -B 10.1.1.100\n# \n# Facility: Divide the PRI number by 8. \n# 191\/8 = 23\n# \n# Severity: multiply facility by 8 and subtract from PRI\n# 191 - (23 * 8 ) = 7\n# \n# PRI = Facility 23 and Priority (7)\n\n# Possible combinations:\n# for pri in {1..1016}; do FAC=\"$((pri\/8))\"; echo -e -n \"PRI:$pri Fac:$FAC Sev:$((pri - ($FAC * 8 )))\\n\"; done\n\n@load base\/frameworks\/notice\n\nexport {\n redef enum Notice::Type += {\n SYSLOG::Invalid_PRI\n };\n\n # List your NTP servers here \n const syslog_servers: set[addr] = {\n\t10.1.1.100\n } &redef;\n\n}\n\nredef Notice::emailed_types += {\n SYSLOG::Invalid_PRI\n};\n\nevent syslog_message(c: connection, facility: count, severity: count, msg: string)\n {\n\n if ( c$id$resp_h !in syslog_servers )\n return;\n\n\tlocal pri = (facility * 8) + severity;\n\n if (facility > 23 && facility < 127)\n {\n NOTICE([$note=SYSLOG::Invalid_PRI,\n\t\t$msg=fmt(\"Syslog message with invalid PRI of %d\", pri),\n $conn=c,\n $identifier=cat(c$id$orig_h,c$id$resp_h),\n $suppress_for=1day]);\n }\n }\n","old_contents":"# Generates a notice and e-mail if syslog messages contain a PRI greater than 191 but less than 1016\n# fac: (23 but less than 127)\n# Vulnerability: http:\/\/www.rsyslog.com\/remote-syslog-pri-vulnerability\/\n#\n# To use:\n# 1. Add script to configuration local.bro: $ echo '@load rsyslog-invalid-pri.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# 2. Copy script to $BROPREFIX\/share\/bro\/site\n# 3. $ broctl check && broctl install && broctl restart\n# Testing: \n# mausezahn -t syslog severity=7,facility=24,host=mausezahn -P \"Invalid PRI message test\" -B 10.1.1.100\n# \n# Facility: Divide the PRI number by 8. \n# 191\/8 = 23\n# \n# Severity: multiply facility by 8 and subtract from PRI\n# 191 - (23 * 8 ) = 7\n# \n# PRI = Facility 23 and Priority (7)\n\n# Possible combinations:\n# for pri in {1..1016}; do FAC=\"$((pri\/8))\"; echo -e -n \"PRI:$pri Fac:$FAC Sev:$((pri - ($FAC * 8 )))\\n\"; done\n\n@load base\/frameworks\/notice\n\nexport {\n redef enum Notice::Type += {\n SYSLOG::Invalid_PRI\n };\n\n # List your NTP servers here \n const syslog_servers: set[addr] = {\n\t10.1.1.100\n } &redef;\n\n}\n\nredef Notice::emailed_types += {\n SYSLOG::Invalid_PRI\n};\n\nevent syslog_message(c: connection, facility: count, severity: count, msg: string)\n {\n\n if ( c$id$resp_h !in syslog_servers )\n return;\n\n if (facility > 23 && facility < 127)\n {\n NOTICE([$note=SYSLOG::Invalid_PRI,\n $msg=fmt(\"Syslog message with invalid PRI from %s to %s\", c$id$orig_h, c$id$resp_h),\n $conn=c,\n $identifier=cat(c$id$orig_h,c$id$resp_h),\n $suppress_for=1day]);\n }\n }\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"ddc9fe8f975b8fcd14317f8a0ea804d4c7ec8724","subject":"Added torlist_location","message":"Added torlist_location","repos":"albertzaharovits\/cs-bro,CrowdStrike\/cs-bro,theflakes\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro","old_file":"bro-scripts\/tor\/main.bro","new_file":"bro-scripts\/tor\/main.bro","new_contents":"# Log Tor connections based on IP addresses along with Tor node metadata\n# Based on data collected from torstatus.blutmagie.de\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n# @jshlbrd\n\nmodule Tor;\n\nexport {\n\tredef enum Log::ID += { TOR::LOG };\n\n\ttype Info: record {\n\t## Timestamp for when the event happened.\n\tts: time \t&log;\n\t## Unique ID for the connection.\n\tuid: string &log;\n\t## The connection's 4-tuple of endpoint addresses\/ports.\n\tid: conn_id &log;\n\t## Tor node IP address.\n\ttor_ip: addr &log &optional;\n\t## Tor node router name.\n\trouter_name: string &log &optional;\n\t## Tor node host name.\n\thost_name: string &log &optional;\n\t## Tor node platform \/ version number.\n\tplatform: string &log &optional;\n\t## Tor node country code location.\n\tcountry_code: string &log &optional;\n\t## Tor node bandwidth (in KB\/s).\n\tbandwidth: count\t&log &optional;\n\t## Tor node estimated uptime.\n\tuptime: time\t&log &optional;\n\t## Tor node router port.\n\trouter_port: count\t&log &optional;\n\t## Tor node directory port.\n\tdirectory_port: count\t&log &optional;\n\t## Tor node auth flag.\n\tauth_flag: bool\t&log &optional;\n\t## Tor node exit flag.\n\texit_flag: bool\t&log &optional;\n\t## Tor node fast flag.\n\tfast_flag: bool\t&log &optional;\n\t## Tor node guard flag.\n\tguard_flag: bool\t&log &optional;\n\t## Tor node named flag.\n\tnamed_flag: bool\t&log &optional;\n\t## Tor node stable flag.\n\tstable_flag: bool\t&log &optional;\n\t## Tor node running flag.\n\trunning_flag: bool\t&log &optional;\n\t## Tor node valid flag.\n\tvalid_flag: bool\t&log &optional;\n\t## Tor node v2dir flag.\n\tv2dir_flag: bool\t&log &optional;\n\t## Tor node hibernating flag.\n\thibernating_flag: bool\t&log &optional;\n\t## Tor node bad exit flag.\n\tbad_exit_flag: bool\t&log &optional;\n\t};\n\n\t## Event that can be handled to access the Tor record as it is sent on\n\t## to the logging framework.\n\tglobal log_tor: event(rec: Info);\n}\n\nredef record connection += {\n\ttor: Info &optional;\n};\n\ntype tor_idx: record {\n\ttor_ip:\taddr;\n};\n\ntype tor_table: record {\n\trouter_name: string;\n\tcountry_code: string;\n\tbandwidth: count;\n\tuptime: double;\n\thost_name: string;\n\trouter_port: count;\n\tdirectory_port: string;\n\tauth_flag: count;\n\texit_flag: count;\n\tfast_flag: count;\n\tguard_flag: count;\n\tnamed_flag: count;\n\tstable_flag: count;\n\trunning_flag: count;\n\tvalid_flag: count;\t\n\tv2dir_flag: count;\n\tplatform: string;\n\thibernating_flag: count;\n\tbad_exit_flag: count;\t\n};\n\nglobal torlist: table[addr] of tor_table = table();\nconst torlist_location = \"bro-tor.txt\";\n\n# Create the Tor log stream and load the Tor list\nevent bro_init()\n{\nLog::create_stream(TOR::LOG, [$columns=Info, $ev=log_tor]);\nInput::add_table([$source=torlist_location, $name=\"torlist\", $idx=tor_idx, $val=tor_table, $destination=torlist, $mode=Input::REREAD]);\n}\n\n# Function to establish a Tor info record\nfunction set_session(c: connection)\n{\nif ( ! c?$tor )\n\t{\n\tadd c$service[\"tor\"];\n\tc$tor = [$ts=network_time(),$id=c$id,$uid=c$uid];\n\t}\n}\n\n# Function to convert blutmagie Tor flags from count to bool\nfunction convert_flag(flag: count): bool\n{\nif ( flag == 1 )\n\treturn T;\nelse return F;\n}\n\n# Function to set data in the Tor info record\nfunction set_data(c: connection, tor_ip: addr)\n{\nc$tor$tor_ip = tor_ip;\nif ( torlist[tor_ip]?$router_name )\n\tc$tor$router_name = torlist[tor_ip]$router_name;\nif ( torlist[tor_ip]?$host_name )\n\tc$tor$host_name = torlist[tor_ip]$host_name;\nif ( torlist[tor_ip]?$platform )\n\tc$tor$platform = torlist[tor_ip]$platform;\nif ( torlist[tor_ip]?$country_code )\n\tc$tor$country_code = torlist[tor_ip]$country_code;\nif ( torlist[tor_ip]?$bandwidth )\n\tc$tor$bandwidth = torlist[tor_ip]$bandwidth;\n\nif ( torlist[tor_ip]?$uptime )\n\t{\n\t# Uptime is recorded by hour, so we need to convert it to seconds\n\tlocal uptime_hr = torlist[tor_ip]$uptime;\n\tlocal uptime_time = ( uptime_hr * 3600 );\n\tc$tor$uptime = double_to_time(uptime_time);\n\t}\n\nif ( torlist[tor_ip]?$router_port )\n\tc$tor$router_port = torlist[tor_ip]$router_port;\nif ( torlist[tor_ip]?$directory_port )\n\tif ( torlist[tor_ip]$directory_port != \"None\" )\n\t\tc$tor$directory_port = to_count(torlist[tor_ip]$directory_port);\nif ( torlist[tor_ip]?$auth_flag )\n\tc$tor$auth_flag = convert_flag(torlist[tor_ip]$auth_flag);\nif ( torlist[tor_ip]?$exit_flag )\n\tc$tor$exit_flag = convert_flag(torlist[tor_ip]$exit_flag);\nif ( torlist[tor_ip]?$fast_flag )\n\tc$tor$fast_flag = convert_flag(torlist[tor_ip]$fast_flag);\nif ( torlist[tor_ip]?$guard_flag )\n\tc$tor$guard_flag = convert_flag(torlist[tor_ip]$guard_flag);\nif ( torlist[tor_ip]?$named_flag )\n\tc$tor$named_flag = convert_flag(torlist[tor_ip]$named_flag);\nif ( torlist[tor_ip]?$stable_flag )\n\tc$tor$stable_flag = convert_flag(torlist[tor_ip]$stable_flag);\nif ( torlist[tor_ip]?$running_flag )\n\tc$tor$running_flag = convert_flag(torlist[tor_ip]$running_flag);\nif ( torlist[tor_ip]?$valid_flag )\n\tc$tor$valid_flag = convert_flag(torlist[tor_ip]$valid_flag);\nif ( torlist[tor_ip]?$v2dir_flag )\n\tc$tor$v2dir_flag = convert_flag(torlist[tor_ip]$v2dir_flag);\nif ( torlist[tor_ip]?$hibernating_flag )\n\tc$tor$hibernating_flag = convert_flag(torlist[tor_ip]$hibernating_flag);\nif ( torlist[tor_ip]?$bad_exit_flag )\n\tc$tor$bad_exit_flag = convert_flag(torlist[tor_ip]$bad_exit_flag);\n}\n\n# Generate reporter message when the Tor list is updated\nevent Input::end_of_data(name: string, source: string) \n{\nlocal msg = fmt(\"Tor list updated at %s\",network_time());\nLog::write(Reporter::LOG, [$ts=network_time(), $level=Reporter::INFO, $message=msg]);\n}\n\n# Check each new connection for an IP address in the Tor list\nevent new_connection(c: connection )\n{\nif ( c$id$orig_h in torlist ) \n\t{\n\tset_session(c);\n\tset_data(c,c$id$orig_h);\n\t}\nelse if ( c$id$resp_h in torlist )\n\t{\n\tset_session(c);\n\tset_data(c,c$id$resp_h);\n\t}\n}\n\n# Generate the tor.log for each Tor connection \nevent connection_state_remove(c: connection)\n{\nif ( c?$tor )\n\t{\n\tLog::write(TOR::LOG, c$tor);\n\t}\n}\n","old_contents":"# Log Tor connections based on IP addresses along with Tor node metadata\n# Based on data collected from torstatus.blutmagie.de\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n# @jshlbrd\n\nmodule Tor;\n\nexport {\n\tredef enum Log::ID += { TOR::LOG };\n\n\ttype Info: record {\n\t## Timestamp for when the event happened.\n\tts: time \t&log;\n\t## Unique ID for the connection.\n\tuid: string &log;\n\t## The connection's 4-tuple of endpoint addresses\/ports.\n\tid: conn_id &log;\n\t## Tor node IP address.\n\ttor_ip: addr &log &optional;\n\t## Tor node router name.\n\trouter_name: string &log &optional;\n\t## Tor node host name.\n\thost_name: string &log &optional;\n\t## Tor node platform \/ version number.\n\tplatform: string &log &optional;\n\t## Tor node country code location.\n\tcountry_code: string &log &optional;\n\t## Tor node bandwidth (in KB\/s).\n\tbandwidth: count\t&log &optional;\n\t## Tor node estimated uptime.\n\tuptime: time\t&log &optional;\n\t## Tor node router port.\n\trouter_port: count\t&log &optional;\n\t## Tor node directory port.\n\tdirectory_port: count\t&log &optional;\n\t## Tor node auth flag.\n\tauth_flag: bool\t&log &optional;\n\t## Tor node exit flag.\n\texit_flag: bool\t&log &optional;\n\t## Tor node fast flag.\n\tfast_flag: bool\t&log &optional;\n\t## Tor node guard flag.\n\tguard_flag: bool\t&log &optional;\n\t## Tor node named flag.\n\tnamed_flag: bool\t&log &optional;\n\t## Tor node stable flag.\n\tstable_flag: bool\t&log &optional;\n\t## Tor node running flag.\n\trunning_flag: bool\t&log &optional;\n\t## Tor node valid flag.\n\tvalid_flag: bool\t&log &optional;\n\t## Tor node v2dir flag.\n\tv2dir_flag: bool\t&log &optional;\n\t## Tor node hibernating flag.\n\thibernating_flag: bool\t&log &optional;\n\t## Tor node bad exit flag.\n\tbad_exit_flag: bool\t&log &optional;\n\t};\n\n\t## Event that can be handled to access the Tor record as it is sent on\n\t## to the logging framework.\n\tglobal log_tor: event(rec: Info);\n}\n\nredef record connection += {\n\ttor: Info &optional;\n};\n\ntype tor_idx: record {\n\ttor_ip:\taddr;\n};\n\ntype tor_table: record {\n\trouter_name: string;\n\tcountry_code: string;\n\tbandwidth: count;\n\tuptime: double;\n\thost_name: string;\n\trouter_port: count;\n\tdirectory_port: string;\n\tauth_flag: count;\n\texit_flag: count;\n\tfast_flag: count;\n\tguard_flag: count;\n\tnamed_flag: count;\n\tstable_flag: count;\n\trunning_flag: count;\n\tvalid_flag: count;\t\n\tv2dir_flag: count;\n\tplatform: string;\n\thibernating_flag: count;\n\tbad_exit_flag: count;\t\n};\n\nglobal torlist: table[addr] of tor_table = table();\n\n# Create the Tor log stream and load the Tor list\nevent bro_init()\n{\nLog::create_stream(TOR::LOG, [$columns=Info, $ev=log_tor]);\nInput::add_table([$source=torlist_location, $name=\"torlist\", $idx=tor_idx, $val=tor_table, $destination=torlist, $mode=Input::REREAD]);\n}\n\n# Function to establish a Tor info record\nfunction set_session(c: connection)\n{\nif ( ! c?$tor )\n\t{\n\tadd c$service[\"tor\"];\n\tc$tor = [$ts=network_time(),$id=c$id,$uid=c$uid];\n\t}\n}\n\n# Function to convert blutmagie Tor flags from count to bool\nfunction convert_flag(flag: count): bool\n{\nif ( flag == 1 )\n\treturn T;\nelse return F;\n}\n\n# Function to set data in the Tor info record\nfunction set_data(c: connection, tor_ip: addr)\n{\nc$tor$tor_ip = tor_ip;\nif ( torlist[tor_ip]?$router_name )\n\tc$tor$router_name = torlist[tor_ip]$router_name;\nif ( torlist[tor_ip]?$host_name )\n\tc$tor$host_name = torlist[tor_ip]$host_name;\nif ( torlist[tor_ip]?$platform )\n\tc$tor$platform = torlist[tor_ip]$platform;\nif ( torlist[tor_ip]?$country_code )\n\tc$tor$country_code = torlist[tor_ip]$country_code;\nif ( torlist[tor_ip]?$bandwidth )\n\tc$tor$bandwidth = torlist[tor_ip]$bandwidth;\n\nif ( torlist[tor_ip]?$uptime )\n\t{\n\t# Uptime is recorded by hour, so we need to convert it to seconds\n\tlocal uptime_hr = torlist[tor_ip]$uptime;\n\tlocal uptime_time = ( uptime_hr * 3600 );\n\tc$tor$uptime = double_to_time(uptime_time);\n\t}\n\nif ( torlist[tor_ip]?$router_port )\n\tc$tor$router_port = torlist[tor_ip]$router_port;\nif ( torlist[tor_ip]?$directory_port )\n\tif ( torlist[tor_ip]$directory_port != \"None\" )\n\t\tc$tor$directory_port = to_count(torlist[tor_ip]$directory_port);\nif ( torlist[tor_ip]?$auth_flag )\n\tc$tor$auth_flag = convert_flag(torlist[tor_ip]$auth_flag);\nif ( torlist[tor_ip]?$exit_flag )\n\tc$tor$exit_flag = convert_flag(torlist[tor_ip]$exit_flag);\nif ( torlist[tor_ip]?$fast_flag )\n\tc$tor$fast_flag = convert_flag(torlist[tor_ip]$fast_flag);\nif ( torlist[tor_ip]?$guard_flag )\n\tc$tor$guard_flag = convert_flag(torlist[tor_ip]$guard_flag);\nif ( torlist[tor_ip]?$named_flag )\n\tc$tor$named_flag = convert_flag(torlist[tor_ip]$named_flag);\nif ( torlist[tor_ip]?$stable_flag )\n\tc$tor$stable_flag = convert_flag(torlist[tor_ip]$stable_flag);\nif ( torlist[tor_ip]?$running_flag )\n\tc$tor$running_flag = convert_flag(torlist[tor_ip]$running_flag);\nif ( torlist[tor_ip]?$valid_flag )\n\tc$tor$valid_flag = convert_flag(torlist[tor_ip]$valid_flag);\nif ( torlist[tor_ip]?$v2dir_flag )\n\tc$tor$v2dir_flag = convert_flag(torlist[tor_ip]$v2dir_flag);\nif ( torlist[tor_ip]?$hibernating_flag )\n\tc$tor$hibernating_flag = convert_flag(torlist[tor_ip]$hibernating_flag);\nif ( torlist[tor_ip]?$bad_exit_flag )\n\tc$tor$bad_exit_flag = convert_flag(torlist[tor_ip]$bad_exit_flag);\n}\n\n# Generate reporter message when the Tor list is updated\nevent Input::end_of_data(name: string, source: string) \n{\nlocal msg = fmt(\"Tor list updated at %s\",network_time());\nLog::write(Reporter::LOG, [$ts=network_time(), $level=Reporter::INFO, $message=msg]);\n}\n\n# Check each new connection for an IP address in the Tor list\nevent new_connection(c: connection )\n{\nif ( c$id$orig_h in torlist ) \n\t{\n\tset_session(c);\n\tset_data(c,c$id$orig_h);\n\t}\nelse if ( c$id$resp_h in torlist )\n\t{\n\tset_session(c);\n\tset_data(c,c$id$resp_h);\n\t}\n}\n\n# Generate the tor.log for each Tor connection \nevent connection_state_remove(c: connection)\n{\nif ( c?$tor )\n\t{\n\tLog::write(TOR::LOG, c$tor);\n\t}\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"989bafd0362aa41672a1ba56b71ed9c02a890db1","subject":"Update __load__.bro","message":"Update __load__.bro\n\nMoved add-tor to bro-scripts\/tor directory","repos":"theflakes\/cs-bro,CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,kingtuna\/cs-bro","old_file":"bro-scripts\/tor\/__load__.bro","new_file":"bro-scripts\/tor\/__load__.bro","new_contents":"@load .\/main\n@load .\/add-tor\n","old_contents":"@load .\/main\n@load policy\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"f593c6b3693f3daeca2b454d7ec55b07d010bf18","subject":"Create add-tor.bro","message":"Create add-tor.bro","repos":"unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,theflakes\/cs-bro,albertzaharovits\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/tor\/add-tor.bro","new_file":"bro-scripts\/tor\/add-tor.bro","new_contents":"module Tor;\n\nexport {\n redef record Conn::Info += {\n found_tor: bool &log &default=F;\n };\n}\n\nevent connection_state_remove (c: connection)\n{\nif ( c?$tor )\n c$conn$found_tor = T;\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/tor\/add-tor.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"0d2e2b08e09548875de3a5a8673a729afd20a860","subject":"Create add-tor.bro","message":"Create add-tor.bro","repos":"theflakes\/cs-bro,albertzaharovits\/cs-bro,kingtuna\/cs-bro,CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro","old_file":"bro-scripts\/tor\/policy\/add-tor.bro","new_file":"bro-scripts\/tor\/policy\/add-tor.bro","new_contents":"module Tor;\n\nexport {\n redef record Conn::Info += {\n found_tor: bool &log &default=F;\n };\n}\n\nevent connection_state_remove (c: connection)\n{\nif ( c?$tor )\n c$conn$found_tor = T;\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/tor\/policy\/add-tor.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"726d5095d739d97edcddd0110546ce97344be0b0","subject":"Update main.bro","message":"Update main.bro","repos":"theflakes\/cs-bro,kingtuna\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,albertzaharovits\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/intel-extensions\/main.bro","new_file":"bro-scripts\/intel-extensions\/main.bro","new_contents":"# Extends functionality of Intel framework in various ways\n# Supports three new indicator types: Email subjects, Usernames, and SSL cert subjects\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n\nmodule Intel;\n\nexport {\n redef enum Intel::Type += {\n CERT_SUBJECT,\n EMAIL_SUBJECT\n };\n\n redef enum Intel::Where += {\n RADIUS::IN_USER_NAME,\n FTP::IN_USER_NAME,\n SMTP::IN_SUBJECT,\n SSL::IN_SERVER_CERT,\n SSL::IN_CLIENT_CERT\n };\n}\n","old_contents":"# Extends functionality of Intel framework in various ways\n# Supports three new indicator types: Email subjects, Usernames, and SSL cert subjects\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n\nmodule Intel;\n\nexport {\n redef enum Intel::Type += {\n \tCERT_SUBJECT,\n EMAIL_SUBJECT\n };\n\n redef enum Intel::Where += {\n \tRADIUS::IN_USER_NAME,\n FTP::IN_USER_NAME,\n SMTP::IN_SUBJECT,\n \tSSL::IN_SERVER_CERT,\n \tSSL::IN_CLIENT_CERT\n };\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"b38c05ecd756f7ea4b3d00afa1d78585f7eddab2","subject":"Create detect-ms15-034.bro","message":"Create detect-ms15-034.bro","repos":"CrowdStrike\/cs-bro,kingtuna\/cs-bro,albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/msb\/detect-ms15-034.bro","new_file":"bro-scripts\/msb\/detect-ms15-034.bro","new_contents":"# Detects MS15-034 vulnerabilities by inspecting inbound HTTP requests and web server responses \n# Any generated notices should have their sub value inspected for the appropriate exploitable RANGE values \n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n MS15034_Vulnerability\n };\n}\n\n# RANGE values seen in each connection are stored here\nglobal ranges: table[string] of string;\n\n# RANGE values are extracted from client HTTP headers if the web server has a private IP address or if the web server is within the local network\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( ! is_orig )\n return;\n\nif ( Site::is_local_addr(c$id$resp_h) == T || Site::is_private_addr(c$id$resp_h) == T ) \n if ( name == \"RANGE\" )\n ranges[c$uid] = value;\n}\n\n# If an HTTP reply is seen for connections in the ranges table, then the web server's response code is checked for a match with the vulnerability\n# A notice is generated that contains the client RANGE request\nevent http_reply(c: connection, version: string, code: count, reason: string)\n{\nif ( c$uid in ranges ) \n {\n if ( code == 416 )\n {\n local sub_msg = fmt(\"Range used: %s\",ranges[c$uid]);\n NOTICE([$note=MS15034_Vulnerability,\n $conn=c,\n $msg=fmt(\"%s may be vulnerable to MS15-034\",c$id$resp_h),\n $sub=sub_msg,\n $identifier=cat(c$id$resp_h,ranges[c$uid])]);\n }\n \n delete ranges[c$uid]; \n }\n}\n\n# The ranges table is cleaned up as connections are dropped from Bro\nevent connection_state_remove(c: connection)\n{\nif ( c?$http )\n if ( c$uid in ranges )\n delete ranges[c$uid];\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/msb\/detect-ms15-034.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"0d11ba71eeb1a6e39caea17fe37df09e2616d3ac","subject":"more bro aliases","message":"more bro aliases\n","repos":"sprax\/dotFiles","old_file":"bash_aliases.bro","new_file":"bash_aliases.bro","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/sprax\/dotFiles.git\/'\n","license":"mit","lang":"Bro"} {"commit":"4aa49b3d653edee2161aecacfb6841fcf4473597","subject":"Create detect-rogue-dns.bro","message":"Create detect-rogue-dns.bro","repos":"CrowdStrike\/cs-bro,kingtuna\/cs-bro,albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/dynamic\/detect-rogue-dns.bro","new_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/dynamic\/detect-rogue-dns.bro","new_contents":"@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n}\n\n# File generated by scrape-alexa.py\nconst alexa_file = \"\" &redef;\n# Table to store list of domains in file above\nglobal alexa_table: set[string];\n# Record for domains in file above\ntype alexa_idx: record {\n alexa: string;\n};\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\n# Pulls data from scrape-alexa.py output (alexa_file)\nevent bro_init()\n{\nInput::add_table([$source=alexa_file,\n $name=\"alexa_domains\",\n $idx=alexa_idx,\n $destination=alexa_table,\n $mode=Input::REREAD]);\n}\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n \n # Clean the sub-message\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/dynamic\/detect-rogue-dns.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"ddc95eb60466a34cdbcaa36f1135cec9d74fc5cb","subject":"Update detect-rogue-dns.bro","message":"Update detect-rogue-dns.bro\n\nAdded comments and location for alexa_file","repos":"albertzaharovits\/cs-bro,CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/dynamic\/detect-rogue-dns.bro","new_file":"bro-scripts\/adversaries\/hurricane-panda\/rogue-dns\/dynamic\/detect-rogue-dns.bro","new_contents":"# Detects a Hurricane Panda tactic of using Hurricane Electric to resolve commonly accessed websites\n# Alerts when a domain in the Alexa top 500 is resolved via Hurricane Electric and\/or when a host connects to an IP in the DNS response\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n}\n\n# File generated by scrape-alexa.py\nconst alexa_file = \".\/alexa_domains.txt\" &redef;\n# Table to store list of domains in file above\nglobal alexa_table: set[string];\n# Record for domains in file above\ntype alexa_idx: record {\n alexa: string;\n};\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\n# Pulls data from scrape-alexa.py output (alexa_file)\nevent bro_init()\n{\nInput::add_table([$source=alexa_file,\n $name=\"alexa_domains\",\n $idx=alexa_idx,\n $destination=alexa_table,\n $mode=Input::REREAD]);\n}\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n \n # Clean the sub-message\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"@load base\/protocols\/dns\n@load base\/frameworks\/notice\n@load base\/frameworks\/input\n\nmodule CrowdStrike::Hurricane_Panda;\n\nexport {\n redef enum Notice::Type += {\n HE_Request,\n HE_Successful_Conn\n };\n}\n\n# File generated by scrape-alexa.py\nconst alexa_file = \"\" &redef;\n# Table to store list of domains in file above\nglobal alexa_table: set[string];\n# Record for domains in file above\ntype alexa_idx: record {\n alexa: string;\n};\n\nconst he_nets: set[subnet] = {\n 216.218.130.2,\n 216.66.1.2,\n 216.66.80.18,\n 216.218.132.2,\n 216.218.131.2\n} &redef;\n\n# Pattern used to identify subdomains\nconst subdomains = \/^d?ns[0-9]*\\.\/ |\n \/^smtp[0-9]*\\.\/ |\n \/^mail[0-9]*\\.\/ |\n \/^pop[0-9]*\\.\/ |\n \/^imap[0-9]*\\.\/ |\n \/^www[0-9]*\\.\/ |\n \/^ftp[0-9]*\\.\/ |\n \/^img[0-9]*\\.\/ |\n \/^images?[0-9]*\\.\/ |\n \/^search[0-9]*\\.\/ |\n \/^nginx[0-9]*\\.\/ &redef;\n\n# Container to store IP address answers from Hurricane Electric queries\n# Each entry expires 5 minutes after the last time it was written\nglobal he_answers: set[addr] &write_expire=5min;\n\n# Pulls data from scrape-alexa.py output (alexa_file)\nevent bro_init()\n{\nInput::add_table([$source=alexa_file,\n $name=\"alexa_domains\",\n $idx=alexa_idx,\n $destination=alexa_table,\n $mode=Input::REREAD]);\n}\n\nevent DNS::log_dns(rec: DNS::Info)\n{\n# Do not process the event if no query exists or if the query is not being resolved by Hurricane Electric\nif ( ! rec?$query ) return;\nif ( rec$id$resp_h !in he_nets ) return;\n\n# If necessary, clean the query so that it can be found in the list of Alexa domains\nlocal query = rec$query;\nif ( subdomains in query )\n query = sub(rec$query,subdomains,\"\");\n\n# Check if the query is in the list of Alexa domains\n# If it is, then this activity is suspicious and should be investigated\nif ( query in alexa_table )\n {\n # Prepare the sub-message for the notice\n # Include the domain queried in the sub-message\n local sub_msg = fmt(\"Query: %s\",query);\n\n # If the query was answered, include the answers in the sub-message\n if ( rec?$answers )\n {\n sub_msg += fmt(\" %s: \", rec$total_answers > 1 ? \"Answers\":\"Answer\");\n\n for ( ans in rec$answers )\n {\n # If an answers value is an IP address, store it for later processing \n if ( is_valid_ip(rec$answers[ans]) == T )\n add he_answers[to_addr(rec$answers[ans])];\n sub_msg += fmt(\"%s, \", rec$answers[ans]);\n }\n \n # Clean the sub-message\n sub_msg = cut_tail(sub_msg,2);\n }\n\n # Generate the notice\n # Includes the connection flow, host intiating the lookup, domain queried, and query answers (if available)\n NOTICE([$note=HE_Request,\n $msg=fmt(\"%s made a suspicious DNS lookup to Hurricane Electric\", rec$id$orig_h),\n $sub=sub_msg,\n $id=rec$id,\n $uid=rec$uid,\n $identifier=cat(rec$id$orig_h,rec$query)]);\n }\n}\n\nevent connection_state_remove(c: connection)\n{\n# Check if a host connected to an IP address seen in an answer from Hurricane Electric\nif ( c$id$resp_h in he_answers )\n NOTICE([$note=HE_Successful_Conn,\n $conn=c,\n $msg=fmt(\"%s connected to a suspicious server resolved by Hurricane Electric\", c$id$orig_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"6deae41f8c21c8c785880916becf3cd5577d7c6d","subject":"Added SMTP support","message":"Added SMTP support\n\nAdded detection for Shellshock exploits over SMTP.","repos":"theflakes\/cs-bro,CrowdStrike\/cs-bro,kingtuna\/cs-bro,albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro","old_file":"bro-scripts\/shellshock\/detect-shellshock.bro","new_file":"bro-scripts\/shellshock\/detect-shellshock.bro","new_contents":"# Monitors traffic for Shellshock exploit attempts\n# When exploits are seen containing IP addresses and domain values, monitors traffic for 60 minutes watching for endpoints to connect to IP addresses and domains seen in exploit attempts\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n@load base\/protocols\/dhcp\n@load base\/protocols\/smtp\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Shellshock_DHCP,\n Shellshock_HTTP,\n Shellshock_SMTP,\n Shellshock_Successful_Conn\n };\n}\n\nconst shellshock_pattern = \/((\\(|%28)(\\)|%29)( |%20)(\\{|%7B)|(\\{|%7B)(\\:|%3A)(\\;|%3B))\/ &redef;\n\nconst shellshock_commands = \/wget\/ | \/curl\/;\n\nglobal shellshock_servers: set[addr] &create_expire=60min &synchronized;\nglobal shellshock_hosts: set[string] &create_expire=60min &synchronized;\n\n# function to locate and extract domains seen in shellshock exploit attempts\nfunction find_domain(ss: string)\n{\nlocal parts1 = split_all(ss,\/[[:space:]]\/);\nfor ( p in parts1 )\n if ( \"http\" in parts1[p] )\n {\n local parts2 = split_all(parts1[p],\/\\\/\/);\n local output = parts2[5];\n }\n\nif ( output !in shellshock_hosts )\n add shellshock_hosts[output];\n}\n\n# function to locate and extract IP addresses seen in shellshock exploit attempts\nfunction find_ip(ss: string): bool\n{\nlocal b = F;\nlocal remote_servers = find_ip_addresses(ss);\n\nif ( |remote_servers| > 0 )\n {\n b = T;\n for ( rs in remote_servers )\n {\n local s = to_addr(remote_servers[rs]);\n if ( s !in shellshock_servers )\n add shellshock_servers[s];\n }\n }\n\nreturn b;\n}\n\n# event to identify shellshock HTTP exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3\n{\nif ( ! is_orig ) return;\nif ( shellshock_pattern !in value ) return;\n\n# generate a notice of the HTTP exploit attempt\nNOTICE([$note=Shellshock_HTTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock HTTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in value )\n find_domain(value);\n}\n\n# event to identify shellshock DHCP exploit attempts\nevent dhcp_ack(c: connection, msg: dhcp_msg, mask: addr, router: dhcp_router_list, lease: interval, serv_addr: addr, host_name: string)\n{\nif ( shellshock_pattern !in host_name ) return;\n\n# generate a notice of the DHCP exploit attempt\nNOTICE([$note=Shellshock_DHCP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock DHCP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",host_name),\n $identifier=cat(c$id$orig_h,c$id$resp_h,host_name)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(host_name) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in host_name )\n find_domain(host_name);\n}\n\n# event to identify endpoints connecting to domains seen in shellshock exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=5\n{\nif ( name != \"HOST\" ) return;\nif ( value in shellshock_hosts )\n # generate a notice of HTTP connection to domain seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to a domain seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"Domain: %s\",value),\n $identifier=cat(c$id$orig_h,value)]);\n}\n\nevent mime_one_header(c: connection, h: mime_header_rec)\n{\nif ( ! c?$smtp || ! h?$value ) return;\nif ( shellshock_pattern !in h$value ) return;\n\nNOTICE([$note=Shellshock_SMTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock SMTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",h$value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,h$value)]);\n\nif ( find_ip(h$value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in h$value )\n find_domain(h$value);\n}\n\n# event to identify endpoints connecting to IP addresses seen in shellshock exploit attempts\nevent connection_state_remove(c: connection)\n{\nif ( c$id$resp_h in shellshock_servers )\n # generate a notice of connection to IP address seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to an IP address seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"IP address: %s\",c$id$resp_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"# Monitors traffic for Shellshock exploit attempts\n# When exploits are seen containing IP addresses and domain values, monitors traffic for 60 minutes watching for endpoints to connect to IP addresses and domains seen in exploit attempts\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n@load base\/protocols\/dhcp\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Shellshock_DHCP,\n Shellshock_HTTP,\n Shellshock_Successful_Conn\n };\n}\n\nconst shellshock_pattern = \/(\\(|%28)(\\)|%29)( |%20)(\\{|%7B)\/ &redef;\n\nconst shellshock_commands = \/wget\/ | \/curl\/;\n\nglobal shellshock_servers: set[addr] &create_expire=60min &synchronized;\nglobal shellshock_hosts: set[string] &create_expire=60min &synchronized;\n\n# function to locate and extract domains seen in shellshock exploit attempts\nfunction find_domain(ss: string)\n{\nlocal parts1 = split_all(ss,\/[[:space:]]\/);\nfor ( p in parts1 )\n if ( \"http\" in parts1[p] )\n {\n local parts2 = split_all(parts1[p],\/\\\/\/);\n local output = parts2[5];\n }\n\nif ( output !in shellshock_hosts )\n add shellshock_hosts[output];\n}\n\n# function to locate and extract IP addresses seen in shellshock exploit attempts\nfunction find_ip(ss: string): bool\n{\nlocal b = F;\nlocal remote_servers = find_ip_addresses(ss);\n\nif ( |remote_servers| > 0 )\n {\n b = T;\n for ( rs in remote_servers )\n {\n local s = to_addr(remote_servers[rs]);\n if ( s !in shellshock_servers )\n add shellshock_servers[s];\n }\n }\n\nreturn b;\n}\n\n# event to identify shellshock HTTP exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3\n{\nif ( ! is_orig ) return;\nif ( shellshock_pattern !in value ) return;\n\n# generate a notice of the HTTP exploit attempt\nNOTICE([$note=Shellshock_HTTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock HTTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in value )\n find_domain(value);\n}\n\n# event to identify shellshock DHCP exploit attempts\nevent dhcp_ack(c: connection, msg: dhcp_msg, mask: addr, router: dhcp_router_list, lease: interval, serv_addr: addr, host_name: string)\n{\nif ( shellshock_pattern !in host_name ) return;\n\n# generate a notice of the DHCP exploit attempt\nNOTICE([$note=Shellshock_DHCP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock DHCP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",host_name),\n $identifier=cat(c$id$orig_h,c$id$resp_h,host_name)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(host_name) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in host_name )\n find_domain(host_name);\n}\n\n# event to identify endpoints connecting to domains seen in shellshock exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=5\n{\nif ( name != \"HOST\" ) return;\nif ( value in shellshock_hosts )\n # generate a notice of HTTP connection to domain seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to a domain seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"Domain: %s\",value),\n $identifier=cat(c$id$orig_h,value)]);\n}\n\n# event to identify endpoints connecting to IP addresses seen in shellshock exploit attempts\nevent connection_state_remove(c: connection)\n{\nif ( c$id$resp_h in shellshock_servers )\n # generate a notice of connection to IP address seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to an IP address seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"IP address: %s\",c$id$resp_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"5bb477b803053fc87e3d51de046d60fb86154c1f","subject":"Update detect-ms15-034.bro","message":"Update detect-ms15-034.bro\n\nAdded a new notice (MS15034_Server_Crash) and extra code to account for web server crashes due to the vulnerability. Thanks to @neu5ron for pointing this out.","repos":"CrowdStrike\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,albertzaharovits\/cs-bro,theflakes\/cs-bro","old_file":"bro-scripts\/msb\/detect-ms15-034.bro","new_file":"bro-scripts\/msb\/detect-ms15-034.bro","new_contents":"# Detects MS15-034 vulnerabilities by inspecting inbound HTTP requests and web server responses\n# Any generated notices should have their sub value inspected for the appropriate exploitable RANGE values\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n MS15034_Vulnerability,\n MS15034_Server_Crash\n };\n}\n\n# RANGE values seen in each connection are stored here\nglobal ranges: table[string] of string;\n\n# RANGE values are extracted from client HTTP headers if the web server has a private IP address or if the web server is within the local network\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( ! is_orig )\n return;\n\nif ( Site::is_local_addr(c$id$resp_h) == T || Site::is_private_addr(c$id$resp_h) == T ) \n if ( name == \"RANGE\" )\n ranges[c$uid] = value;\n}\n\n# If an HTTP reply is seen for connections in the ranges table, then the web server's response code is checked for a match with the vulnerability\n# A notice is generated that contains the client RANGE request\n# If the server response code isn't 416, then the traffic is ignored\nevent http_reply(c: connection, version: string, code: count, reason: string)\n{\nif ( c$uid in ranges )\n {\n if ( code == 416 )\n {\n local sub_msg = fmt(\"Range used: %s\",ranges[c$uid]);\n NOTICE([$note=MS15034_Vulnerability,\n $conn=c,\n $msg=fmt(\"%s may be vulnerable to MS15-034\",c$id$resp_h),\n $sub=sub_msg,\n $identifier=cat(c$id$resp_h,ranges[c$uid])]);\n\n delete ranges[c$uid];\n }\n\n else if ( code != 416 )\n delete ranges[c$uid];\n }\n}\n\n# The ranges table is cleaned up as connections are dropped from Bro\n# If no server response was seen, then assume the web server crashed\nevent connection_state_remove(c: connection)\n{\nif ( c?$http )\n if ( c$uid in ranges )\n {\n if ( ! c$http?$status_code )\n {\n local sub_msg = fmt(\"Range used: %s\",ranges[c$uid]);\n NOTICE([$note=MS15034_Server_Crash,\n $conn=c,\n $msg=fmt(\"%s may have crashed due to MS15-034\",c$id$resp_h),\n $sub=sub_msg,\n $identifier=cat(c$id$resp_h,ranges[c$uid])]);\n\n delete ranges[c$uid];\n }\n else\n delete ranges[c$uid];\n }\n}\n","old_contents":"# Detects MS15-034 vulnerabilities by inspecting inbound HTTP requests and web server responses \n# Any generated notices should have their sub value inspected for the appropriate exploitable RANGE values \n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n MS15034_Vulnerability\n };\n}\n\n# RANGE values seen in each connection are stored here\nglobal ranges: table[string] of string;\n\n# RANGE values are extracted from client HTTP headers if the web server has a private IP address or if the web server is within the local network\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( ! is_orig )\n return;\n\nif ( Site::is_local_addr(c$id$resp_h) == T || Site::is_private_addr(c$id$resp_h) == T ) \n if ( name == \"RANGE\" )\n ranges[c$uid] = value;\n}\n\n# If an HTTP reply is seen for connections in the ranges table, then the web server's response code is checked for a match with the vulnerability\n# A notice is generated that contains the client RANGE request\nevent http_reply(c: connection, version: string, code: count, reason: string)\n{\nif ( c$uid in ranges ) \n {\n if ( code == 416 )\n {\n local sub_msg = fmt(\"Range used: %s\",ranges[c$uid]);\n NOTICE([$note=MS15034_Vulnerability,\n $conn=c,\n $msg=fmt(\"%s may be vulnerable to MS15-034\",c$id$resp_h),\n $sub=sub_msg,\n $identifier=cat(c$id$resp_h,ranges[c$uid])]);\n }\n \n delete ranges[c$uid]; \n }\n}\n\n# The ranges table is cleaned up as connections are dropped from Bro\nevent connection_state_remove(c: connection)\n{\nif ( c?$http )\n if ( c$uid in ranges )\n delete ranges[c$uid];\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"217a8b15a58e755c808fcdc7137dafa8e64fb9c9","subject":"Added a fix for Google's GREASE values","message":"Added a fix for Google's GREASE values\n\nThis update identifies and ignores values as defined in https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01 which is used by Google clients like Chrome. This will allow one to detect Google clients with exceptional accuracy. These lines can be commented out if one is looking for a more un-altered analysis of the Client Hello packet.","repos":"jatkins-sfdc\/ja3,salesforce\/ja3","old_file":"bro\/ja3.bro","new_file":"bro\/ja3.bro","new_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.3 (June 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n## LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\n# Google. https:\/\/tools.ietf.org\/html\/draft-davidben-tls-grease-01\nconst grease: set[int] = {\n 2570,\n 6682,\n 10794,\n 14906,\n 19018,\n 23130,\n 27242,\n 31354,\n 35466,\n 39578,\n 43690,\n 47802,\n 51914,\n 56026,\n 60138,\n 64250\n};\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( code in grease ) {\n next;\n }\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( point_formats[i] in grease ) {\n next;\n }\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( curves[i] in grease ) {\n next;\n }\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( ciphers[i] in grease ) {\n next;\n }\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n## LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n## FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","old_contents":"# This Bro script appends JA3 to ssl.log\n# Version 1.2 (March 2017)\n#\n# Authors: John B. Althouse (jalthouse@salesforce.com) & Jeff Atkinson (jatkinson@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule JA3;\n\nexport {\nredef enum Log::ID += { LOG };\n}\n\ntype TLSFPStorage: record {\n client_version: count &default=0 &log;\n client_ciphers: string &default=\"\" &log;\n extensions: string &default=\"\" &log;\n e_curves: string &default=\"\" &log;\n ec_point_fmt: string &default=\"\" &log;\n};\n\nredef record connection += {\n tlsfp: TLSFPStorage &optional;\n};\n\nredef record SSL::Info += {\n ja3: string &optional &log;\n## LOG FIELD VALUES ##\n# ja3_version: string &optional &log;\n# ja3_ciphers: string &optional &log;\n# ja3_extensions: string &optional &log;\n# ja3_ec: string &optional &log;\n# ja3_ec_fmt: string &optional &log;\n};\n\nconst sep = \"-\";\nevent bro_init() {\n Log::create_stream(JA3::LOG,[$columns=TLSFPStorage, $path=\"tlsfp\"]);\n}\n\nevent ssl_extension(c: connection, is_orig: bool, code: count, val: string)\n{\nif ( ! c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n if ( c$tlsfp$extensions == \"\" ) {\n c$tlsfp$extensions = cat(code);\n }\n else {\n c$tlsfp$extensions = string_cat(c$tlsfp$extensions, sep,cat(code));\n }\n }\n}\n\nevent ssl_extension_ec_point_formats(c: connection, is_orig: bool, point_formats: index_vec)\n{\nif ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in point_formats ) {\n if ( c$tlsfp$ec_point_fmt == \"\" ) {\n c$tlsfp$ec_point_fmt += cat(point_formats[i]);\n }\n else {\n c$tlsfp$ec_point_fmt += string_cat(sep,cat(point_formats[i]));\n }\n }\n }\n}\n\nevent ssl_extension_elliptic_curves(c: connection, is_orig: bool, curves: index_vec)\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n if ( is_orig = T ) {\n for ( i in curves ) {\n if ( c$tlsfp$e_curves == \"\" ) {\n c$tlsfp$e_curves += cat(curves[i]);\n }\n else {\n c$tlsfp$e_curves += string_cat(sep,cat(curves[i]));\n }\n }\n }\n}\n\nevent ssl_client_hello(c: connection, version: count, possible_ts: time, client_random: string, session_id: string, ciphers: index_vec) &priority=1\n{\n if ( !c?$tlsfp )\n c$tlsfp=TLSFPStorage();\n c$tlsfp$client_version = version;\n for ( i in ciphers ) {\n if ( c$tlsfp$client_ciphers == \"\" ) { \n c$tlsfp$client_ciphers += cat(ciphers[i]);\n }\n else {\n c$tlsfp$client_ciphers += string_cat(sep,cat(ciphers[i]));\n }\n }\n local sep2 = \",\";\n local ja3_string = string_cat(cat(c$tlsfp$client_version),sep2,c$tlsfp$client_ciphers,sep2,c$tlsfp$extensions,sep2,c$tlsfp$e_curves,sep2,c$tlsfp$ec_point_fmt);\n local tlsfp_1 = md5_hash(ja3_string);\n c$ssl$ja3 = tlsfp_1;\n\n## LOG FIELD VALUES ##\n#c$ssl$ja3_version = cat(c$tlsfp$client_version);\n#c$ssl$ja3_ciphers = c$tlsfp$client_ciphers;\n#c$ssl$ja3_extensions = c$tlsfp$extensions;\n#c$ssl$ja3_ec = c$tlsfp$e_curves;\n#c$ssl$ja3_ec_fmt = c$tlsfp$ec_point_fmt;\n#\n## FOR DEBUGGING ##\n#print \"JA3: \"+tlsfp_1+\" Fingerprint String: \"+ja3_string;\n\n}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"71ee291bf5bd2418a0716fc81b7d2131f8d17f30","subject":"Add redef statement","message":"Add redef statement\n\nAdded a redef statement for torlist_location.","repos":"unusedPhD\/CrowdStrike_cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/tor\/main.bro","new_file":"bro-scripts\/tor\/main.bro","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/unusedPhD\/CrowdStrike_cs-bro.git\/'\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"5bd20ff22d6a4b3a765da6c4d3d687fb8eca5e6b","subject":"Create __load__.bro","message":"Create __load__.bro","repos":"theflakes\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,CrowdStrike\/cs-bro,kingtuna\/cs-bro,albertzaharovits\/cs-bro","old_file":"bro-scripts\/msb\/__load__.bro","new_file":"bro-scripts\/msb\/__load__.bro","new_contents":"@load .\/detect-ms15-034\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/msb\/__load__.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"592461cbac50f8d31f77794710516ad9c8b19004","subject":"bro-scripts: ipmi.bro: added new script that watches for IPMI traffic","message":"bro-scripts: ipmi.bro: added new script that watches for IPMI traffic\n","repos":"jonschipp\/bro-scripts,jonschipp\/bro-scripts,unusedPhD\/jonschipp_bro-scripts,unusedPhD\/jonschipp_bro-scripts","old_file":"ipmi.bro","new_file":"ipmi.bro","new_contents":"# Written by Jon Schipp\n# Rudimentary detection of IPMI traffic by matching destination port 623\/udp\n# \tTo use:\n# \t\t1. Add script to configuration local.bro: $ echo '@load ipmi.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# \t\t2. Copy script to $BROPREFIX\/share\/bro\/site\n# \t\t3. $ broctl check && broctl install && broctl restart\n\n@load base\/frameworks\/notice\n\nexport {\n redef enum Notice::Type += {\n IPMI::Port_Detected\n };\n}\n\nredef Notice::emailed_types += {\n IPMI::Port_Detected\n};\n\nevent new_connection(c: connection)\n {\n if ( ! Site::is_local_addr(c$id$orig_h) && Site::is_local_addr(c$id$resp_h) && c$id$resp_p == 623\/udp)\n {\n NOTICE([$note=IPMI::Port_Detected, $msg=fmt(\"Host %s sent traffic to UDP port %d.\", c$id$orig_h, c$id$resp_p),\n\t\t$conn=c, $identifier=cat(c$id$orig_h,c$id$resp_p), $suppress_for=1day]);\n }\n }\n\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'ipmi.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"95f9b18a5237837261fb8dfa7d04ff39172b49da","subject":"Fixed for any version of Bro 2.x","message":"Fixed for any version of Bro 2.x\n\nAs identified by @theflakes, this script had some issues if you ran it on Bro 2.4. This change makes the script simpler and should make it compatible with any version of Bro 2.x.","repos":"albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/intel-extensions\/seen\/conn-udp-icmp.bro","new_file":"bro-scripts\/intel-extensions\/seen\/conn-udp-icmp.bro","new_contents":"# Support for UDP, ICMP, and non-established TCP connections\n# This will only generate Intel matches when a connection is removed from Bro\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent connection_state_remove(c: connection)\n{\nif ( c$conn?$proto && ( c$conn$proto != tcp || ( c$conn?$history && c$conn$proto == tcp && \"h\" !in c$conn$history ) ) )\n {\n Intel::seen([$host=c$id$orig_h, $conn=c, $where=Conn::IN_ORIG]);\n Intel::seen([$host=c$id$resp_h, $conn=c, $where=Conn::IN_RESP]);\n }\n}\n","old_contents":"# Support for UDP, ICMP, and non-established TCP connections\n# This will only generate Intel matches when a connection is removed from Bro\n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent Conn::log_conn(rec: Conn::Info)\n{\nif ( rec?$proto && ( rec$proto != tcp || ( rec?$history && rec$proto == tcp && \"h\" !in rec$history ) ) ) \n {\n # duration, start_time, addl, and hot are required fields although they are not used by Intel framework\n local dur: interval;\n local history: string;\n\n if ( rec?$duration )\n dur = rec$duration;\n else dur = 0secs;\n\n if ( rec?$history )\n history = rec$history;\n else history = \"\";\n\n local c = [$uid = rec$uid,$id = rec$id,$history = history,$duration = dur,$start_time = 0,$addl = \"\",$hot = 0];\n\n Intel::seen([$host=c$id$orig_h, $conn=c, $where=Conn::IN_ORIG]);\n Intel::seen([$host=c$id$resp_h, $conn=c, $where=Conn::IN_RESP]);\n }\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"7a49750d166795c04a74a50292e88b0ffebcaf54","subject":"ntp-audit.bro: add ability to exclude subnets","message":"ntp-audit.bro: add ability to exclude subnets\n","repos":"unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts,unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts","old_file":"ntp-audit.bro","new_file":"ntp-audit.bro","new_contents":"# Written by Jon Schipp, 01-10-2013\n#\n# Detects when hosts send NTP messages to NTP servers not defined in time_servers.\n# To use:\n# 1. Enable the NTP analyzer:\n#\n# If running Bro 2.1 add lines to local.bro:\n#\n# global ports = set(123\/udp);\n# redef dpd_config += { [ANALYZER_NTP] = [$ports = ports]\n# };\n# \n# If running Bro 2.2 add lines to local.bro:\n#\n# event bro_init()\n# {\n# local ports = set(123\/udp);\n# Analyzer::register_for_ports(Analyzer::ANALYZER_NTP,\n# ports);\n# }\n#\n# 2. Copy ntp-audit.bro script to $BROPREFIX\/share\/bro\/site\n# 3. Place the following line into local.bro and put above code from step 1:\n# @load ntp-audit.bro\n# 4. Run commands to validate the script, install it, and put into production: \n# $ broctl check && broctl install && broctl restart\n#\n# If you would like to receive e-mails when a notice event is generated add to emailed_types in local.bro:\n# e.g.\n# redef Notice::emailed_types += {\n# MyScripts::Query_Sent_To_Wrong_Server,\n# };\n\n\n@load base\/frameworks\/notice\n\n# Use namespace so variables don't conflict with those in other scripts\nmodule MyScripts;\n\n# Export sets and types so that they can be redefined outside of this script\nexport {\n\n redef enum Notice::Type += {\n Query_Sent_To_Wrong_Server\n };\n\n # List your NTP servers here \n const time_servers: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n } &redef;\n\n\tconst subnet_exclude: set[subnet] = {\n 192.168.2.0\/24, # Exclude mobile network\n } &redef;\n\n # List any source addresses that should be excluded\n const time_exclude: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n 192.168.1.1, # Gateway\/NAT\/WAN uses external source for time\n } &redef;\n\n}\n\nevent ntp_message(u: connection, msg: ntp_msg, excess: string)\n {\n\n\t # Exit event handler if originator is not in networks.cfg\n\tif (! Site::is_local_addr(u$id$orig_h) )\n\t\treturn;\n\n\tif ( u$id$orig_h in subnet_exclude )\n return;\n\n if ( u$id$orig_h !in time_exclude && u$id$resp_h !in time_servers )\n {\n NOTICE([$note=Query_Sent_To_Wrong_Server,\n $msg=\"NTP query destined to non-defined NTP servers\", $conn=u,\n $identifier=cat(u$id$orig_h),\n $suppress_for=1day]);\n }\n }\n~ \n","old_contents":"# Written by Jon Schipp, 01-10-2013\n#\n# Detects when hosts send NTP messages to NTP servers not defined in time_servers.\n# To use:\n# 1. Enable the NTP analyzer:\n#\n# If running Bro 2.1 add lines to local.bro:\n#\n# global ports = set(123\/udp);\n# redef dpd_config += { [ANALYZER_NTP] = [$ports = ports]\n# };\n# \n# If running Bro 2.2 add lines to local.bro:\n#\n# event bro_init()\n# {\n# local ports = set(123\/udp);\n# Analyzer::register_for_ports(Analyzer::ANALYZER_NTP,\n# ports);\n# }\n#\n# 2. Copy ntp-audit.bro script to $BROPREFIX\/share\/bro\/site\n# 3. Place the following line into local.bro and put above code from step 1:\n# @load ntp-audit.bro\n# 4. Run commands to validate the script, install it, and put into production: \n# $ broctl check && broctl install && broctl restart\n#\n# If you would like to receive e-mails when a notice event is generated add to emailed_types in local.bro:\n# e.g.\n# redef Notice::emailed_types += {\n# MyScripts::Query_Sent_To_Wrong_Server,\n# };\n\n\n@load base\/frameworks\/notice\n\n# Use namespace so variables don't conflict with those in other scripts\nmodule MyScripts;\n\n# Export sets and types so that they can be redefined outside of this script\nexport {\n\n redef enum Notice::Type += {\n Query_Sent_To_Wrong_Server\n };\n\n # List your NTP servers here \n const time_servers: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n } &redef;\n\n # List any source addresses that should be excluded\n const time_exclude: set[addr] = {\n 192.168.1.250,\n 192.168.1.251,\n 192.168.1.1, # Gateway\/NAT\/WAN uses external source for time\n } &redef;\n\n}\n\nevent ntp_message(u: connection, msg: ntp_msg, excess: string)\n {\n\n\t # Exit event handler if originator is not in networks.cfg\n\tif (! Site::is_local_addr(u$id$orig_h) )\n\t\treturn;\n\n if ( u$id$orig_h !in time_exclude && u$id$resp_h !in time_servers )\n {\n NOTICE([$note=Query_Sent_To_Wrong_Server,\n $msg=\"NTP query destined to non-defined NTP servers\", $conn=u,\n $identifier=cat(u$id$orig_h),\n $suppress_for=1day]);\n }\n }\n~ \n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"8558e0a7f19d42021976d76e1f9d8d8dfa77011a","subject":"Delete detect-rfd.bro","message":"Delete detect-rfd.bro","repos":"CrowdStrike\/cs-bro,theflakes\/cs-bro,albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro","old_file":"bro-scripts\/rfd\/detect-rfd.bro","new_file":"bro-scripts\/rfd\/detect-rfd.bro","new_contents":"","old_contents":"# Detect reflected file download attacks as described in \n# http:\/\/packetstorm.foofus.com\/papers\/presentations\/eu-14-Hafif-Reflected-File-Download-A-New-Web-Attack-Vector.pdf\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Reflected_File_Download\n };\n\n redef enum HTTP::Tags += {\n RFD\n };\n}\n\nconst rfd_content_type: set[string] = {\n \"application\/json\",\n \"application\/x-javascript\",\n \"application\/javascript\",\n \"application\/notexist\",\n \"text\/json\",\n \"text\/x-javascript\",\n \"text\/plain\",\n \"text\/notexist\",\n \"application\/xml\",\n \"text\/xml\",\n \"text\/html\"\n} &redef;\n\nconst rfd_pattern = \/\\\"\\|\\|\/ |\n \/\\\"\\<\\<\/ |\n \/\\\"\\>\\>\/ |\n \/[^?]*\\.bat(\\;|$)\/ |\n \/[^?]*\\.cmd(\\;|$)\/ |\n \/[:alnum:]*?[Ss][Ee][Tt][Uu][Pp][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/[:alnum:]*?[Ii][nn][Ss][Tt][Aa][Ll][Ll][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/[:alnum:]*?[Uu][Pp][Dd][Aa][Tt][Ee][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ |\n \/[:alnum:]*?[Uu][Nn][In][Ss][Tt][:alnum:]*?\\.[:alpha:]{3,4}(\\;|$)\/ &redef;\n\n\n# Perform a pattern match for reflected file downloads.\n# If found, add HTTP tag and generate a notice.\nfunction rfd_do_notice(c: connection)\n{\nif ( rfd_pattern in c$http$uri )\n {\n add c$http$tags[RFD];\n NOTICE([$note=Reflected_File_Download,\n $msg=\"A reflected file download was attempted\",\n $sub=c$http$uri,\n $id=c$id,\n $identifier=cat(c$id$orig_h,c$id$resp_h,c$http$uri)]);\n }\n}\n\n# Check for reflected file downloads in HTTP transactions that have a \n# CONTENT-TYPE header. Valid RFD content types are identified anywhere\n# in the CONTENT-TYPE header value.\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nif ( name == \"CONTENT-TYPE\" )\n for ( rct in rfd_content_type )\n if ( rct in value )\n rfd_do_notice(c);\n}\n\n# Check for reflected file downloads in HTTP transactions that do not have a \n# CONTENT-TYPE header.\nevent http_all_headers(c: connection, is_orig: bool, hlist: mime_header_list)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nlocal headers: set[string];\n\nfor ( h in hlist )\n {\n local name = hlist[h]$name;\n add headers[name];\n }\n\nif ( \"CONTENT-TYPE\" !in headers ) \n rfd_do_notice(c);\nelse return;\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Bro"} {"commit":"b2cdcf72cc80ae04914e2c5208efb69b3511ea42","subject":"Create detect-rfd.bro","message":"Create detect-rfd.bro","repos":"albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,theflakes\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/rfd\/detect-rfd.bro","new_file":"bro-scripts\/rfd\/detect-rfd.bro","new_contents":"# Detect reflected file download attacks as described in \n# http:\/\/packetstorm.foofus.com\/papers\/presentations\/eu-14-Hafif-Reflected-File-Download-A-New-Web-Attack-Vector.pdf\n# CrowdStrike 2015\n# josh.liburdi@crowdstrike.com\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Reflected_File_Download\n };\n\n redef enum HTTP::Tags += {\n RFD\n };\n}\n\nconst rfd_content_type: set[string] = {\n \"application\/json\",\n \"application\/x-javascript\",\n \"application\/javascript\",\n \"application\/notexist\",\n \"text\/json\",\n \"text\/x-javascript\",\n \"text\/plain\",\n \"text\/notexist\",\n \"application\/xml\",\n \"text\/xml\",\n \"text\/html\"\n};\n\nconst rfd_pattern = \t\/\\\"\\|\\|\/ |\n \t\t\t\/\\\"\\<\\<\/ |\n \t\t\t\/\\\"\\>\\>\/ |\n \t\t\t\/\\;\\\/([:alnum:]|[:punct])*\\.bat\\;\/ |\n \t\t\t\/\\;\\\/([:alnum:]|[:punct])*\\.cmd\\;\/ |\n \t\t\t\/\\;\\\/[:alnum:]*?[Ss][Ee][Tt][Uu][Pp][:alnum:]*?\\.[:alpha:]{3,4}\\;\/ |\n \t\t\t\/\\;\\\/[:alnum:]*?[Ii][nn][Ss][Tt][Aa][Ll][Ll][:alnum:]*?\\.[:alpha:]{3,4}\\;\/ |\n \t\t\t\/\\;\\\/[:alnum:]*?[Uu][Pp][Dd][Aa][Tt][Ee][:alnum:]*?\\.[:alpha:]{3,4}\\;\/ |\n \t\t\t\/\\;\\\/[:alnum:]*?[Uu][Nn][In][Ss][Tt][:alnum:]*?\\.[:alpha:]{3,4}\\;\/;\n\n\n# Perform a pattern match for reflected file downloads.\n# If found, add HTTP tag and generate a notice.\nfunction rfd_do_notice(c: connection)\n{\nif ( rfd_pattern in c$http$uri )\n {\n add c$http$tags[RFD];\n NOTICE([$note=Reflected_File_Download,\n $msg=\"A reflected file download was attempted\",\n $sub=c$http$uri,\n $id=c$id,\n $identifier=cat(c$id$orig_h,c$id$resp_h,c$http$uri)]);\n }\n}\n\n# Check for reflected file downloads in HTTP transactions that have a \n# CONTENT-TYPE header. Valid RFD content types are identified anywhere\n# in the CONTENT-TYPE header value.\nevent http_header(c: connection, is_orig: bool, name: string, value: string)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nif ( name == \"CONTENT-TYPE\" )\n for ( rct in rfd_content_type )\n if ( rct in value )\n rfd_do_notice(c);\n}\n\n# Check for reflected file downloads in HTTP transactions that do not have a \n# CONTENT-TYPE header.\nevent http_all_headers(c: connection, is_orig: bool, hlist: mime_header_list)\n{\nif ( is_orig || ! c$http?$uri || c$http$uri == \"\" ) return;\n\nlocal headers: set[string];\n\nfor ( h in hlist )\n {\n local name = hlist[h]$name;\n add headers[name];\n }\n\nif ( \"CONTENT-TYPE\" !in headers ) \n rfd_do_notice(c);\nelse return;\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/rfd\/detect-rfd.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"b921af7fe860e46976501cd3c94b6f4337de50a5","subject":"Create intel_ja3.bro","message":"Create intel_ja3.bro","repos":"jatkins-sfdc\/ja3,salesforce\/ja3","old_file":"bro\/intel_ja3.bro","new_file":"bro\/intel_ja3.bro","new_contents":"# This Bro script adds JA3 to the Bro Intel Framework as Intel::JA3\n#\n# Author: John B. Althouse (jalthouse@salesforce.com)\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule Intel;\n\nexport {\n redef enum Intel::Type += { Intel::JA3 };\n}\n\nexport {\n redef enum Intel::Where += { SSL::IN_JA3 };\n}\n\nevent ssl_server_hello (c: connection, version: count, possible_ts: time, server_random: string, session_id: string, cipher: count, comp_method: count)\n\t{\n\tIntel::seen([$indicator=c$ssl$ja3, $indicator_type=Intel::JA3, $conn=c, $where=SSL::IN_JA3]);\n\t}\n","old_contents":"# This Bro script adds JA3 to the Bro Intel Framework as Intel::JA3\n#\n# Copyright (c) 2017, salesforce.com, inc.\n# All rights reserved.\n# Licensed under the BSD 3-Clause license. \n# For full license text, see LICENSE.txt file in the repo root or https:\/\/opensource.org\/licenses\/BSD-3-Clause\n\nmodule Intel;\n\nexport {\n redef enum Intel::Type += { Intel::JA3 };\n}\n\nexport {\n redef enum Intel::Where += { SSL::IN_JA3 };\n}\n\nevent ssl_server_hello (c: connection, version: count, possible_ts: time, server_random: string, session_id: string, cipher: count, comp_method: count)\n\t{\n\tIntel::seen([$indicator=c$ssl$ja3, $indicator_type=Intel::JA3, $conn=c, $where=SSL::IN_JA3]);\n\t}\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Bro"} {"commit":"d89920bffde16e0050adb397838c607143bc4179","subject":"Create radius-username.bro","message":"Create radius-username.bro","repos":"albertzaharovits\/cs-bro,theflakes\/cs-bro,CrowdStrike\/cs-bro,kingtuna\/cs-bro,unusedPhD\/CrowdStrike_cs-bro","old_file":"bro-scripts\/intel-extensions\/seen\/radius-username.bro","new_file":"bro-scripts\/intel-extensions\/seen\/radius-username.bro","new_contents":"# Intel framework support for RADIUS usernames \n# CrowdStrike 2014\n# josh.liburdi@crowdstrike.com\n\n@load base\/protocols\/radius\n@load base\/frameworks\/intel\n@load policy\/frameworks\/intel\/seen\/where-locations\n\nevent RADIUS::log_radius(rec: RADIUS::Info)\n{\nif ( rec?$username && rec?$result )\n if ( rec$result == \"success\" )\n Intel::seen([$indicator=rec$username,\n $indicator_type=Intel::USER_NAME,\n $where=RADIUS::IN_USER_NAME]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/intel-extensions\/seen\/radius-username.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"} {"commit":"b513199f24e4e85adf90a2b9dda23e233a5fbe96","subject":"bro-scripts: capinfos.bro: added draft of a capinfos like bro script","message":"bro-scripts: capinfos.bro: added draft of a capinfos like bro script\n","repos":"jonschipp\/bro-scripts,unusedPhD\/jonschipp_bro-scripts,unusedPhD\/jonschipp_bro-scripts,jonschipp\/bro-scripts","old_file":"capinfos.bro","new_file":"capinfos.bro","new_contents":"# Written by Jon Schipp\n# \tTo use:\n#\t\t$ bro -b -r capture.pcap conn-count.bro\n\nglobal connections_seen_counter = 0;\nglobal orig_seen_s: set[addr];\nglobal resp_seen_s: set[addr];\nglobal time_first: time;\nglobal time_last: time;\n\nevent bro_init()\n\t{\n\tprint fmt(\"Bro Version: %s\", bro_version());\n\t}\n\nevent new_connection(c: connection)\n {\n\t\n\tif ( connections_seen_counter == 0 )\n\t\ttime_first = network_time();\n\t\n\ttime_last = network_time();\n\t++connections_seen_counter;\n\tadd orig_seen_s[c$id$orig_h];\n\tadd resp_seen_s[c$id$resp_h];\n }\n\nevent bro_done()\n\t{\n\tprint fmt(\"Start: %DT\", time_first);\n\tprint fmt(\"End: %DT\", time_last);\n\tprint fmt(\" -- Connections Seen: --\");\n\tprint fmt(\"Connections: %d\", connections_seen_counter);\n\tprint fmt(\"Unique Originators: %d\", |orig_seen_s|);\n\tprint fmt(\"Unique Responders: %d\", |resp_seen_s|);\n\tprint fmt(\"Total Unique Hosts: %d\", |orig_seen_s| + |resp_seen_s|);\n\t}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'capinfos.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"f178b397a5bed66c1273b67da461ea34f1a2d3cf","subject":"bro-scripts: ntp-audit.bro: added new Bro script","message":"bro-scripts: ntp-audit.bro: added new Bro script\n","repos":"jonschipp\/bro-scripts,jonschipp\/bro-scripts,unusedPhD\/jonschipp_bro-scripts,unusedPhD\/jonschipp_bro-scripts","old_file":"ntp-audit.bro","new_file":"ntp-audit.bro","new_contents":"# Written by Jon Schipp\n# Detects when hosts send NTP queries to NTP servers not defined in time_servers.\n# \tTo use:\n# \t\t1. Add script to configuration local.bro: $ echo '@load ntp-audit.bro' >> $BROPREFIX\/share\/bro\/site\/local.bro\n# \t\t2. Copy script to $BROPREFIX\/share\/bro\/site\n# \t\t3. $ broctl check && broctl install && broctl restart\n\n@load base\/frameworks\/notice\n\n# List your NTP servers here\t\nconst time_servers: set[addr] = {\n\t192.168.1.250,\n\t192.168.1.251,\n} &redef;\n\n# List any source addresses that should be excluded\nconst time_exclude: set[addr] = {\n\t192.168.1.250,\n\t192.168.1.251,\n\t192.168.1.1, # Gateway\/NAT \n} &redef;\n\nexport {\n\n redef enum Notice::Type += {\n NTP::Query_Sent_To_Wrong_Server\n };\n}\n\nredef Notice::emailed_types += {\n NTP::Query_Sent_To_Wrong_Server\n};\n\nevent udp_request(u: connection)\n {\n if ( u$id$orig_h !in time_exclude && u$id$resp_h !in time_servers && u$id$resp_p == 123\/udp )\n {\n NOTICE([$note=NTP::Query_Sent_To_Wrong_Server,\n $msg=\"NTP query destined to non-TOC NTP servers\", $conn=u,\n $identifier=cat(u$id$orig_h),\n $suppress_for=1day]);\n }\n }\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'ntp-audit.bro' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Bro"} {"commit":"1ace06c4e9b5b52f8de3d645fd874ab2221b6755","subject":"Create detect-shellshock.bro","message":"Create detect-shellshock.bro","repos":"albertzaharovits\/cs-bro,unusedPhD\/CrowdStrike_cs-bro,kingtuna\/cs-bro,theflakes\/cs-bro,CrowdStrike\/cs-bro","old_file":"bro-scripts\/detect-shellshock.bro","new_file":"bro-scripts\/detect-shellshock.bro","new_contents":"# Monitors traffic for Shellshock exploit attempts\n# When exploits are seen containing IP addresses and domain values, monitors traffic for 60 minutes watching for endpoints to connect to IP addresses and domains seen in exploit attempts\n# CrowdStrike 2014\n\n@load base\/frameworks\/notice\n@load base\/protocols\/http\n@load base\/protocols\/dhcp\n\nmodule CrowdStrike;\n\nexport {\n redef enum Notice::Type += {\n Shellshock_DHCP,\n Shellshock_HTTP,\n Shellshock_Successful_Conn\n };\n}\n\nconst shellshock_pattern = \/(\\(|%28)(\\)|%29)( |%20)(\\{|%7B)\/ &redef;\n\nconst shellshock_commands = \/wget\/ | \/curl\/;\n\nglobal shellshock_servers: set[addr] &create_expire=60min &synchronized;\nglobal shellshock_hosts: set[string] &create_expire=60min &synchronized;\n\n# function to locate and extract domains seen in shellshock exploit attempts\nfunction find_domain(ss: string)\n{\nlocal parts1 = split_all(ss,\/[[:space:]]\/);\nfor ( p in parts1 )\n if ( \"http\" in parts1[p] )\n {\n local parts2 = split_all(parts1[p],\/\\\/\/);\n local output = parts2[5];\n }\n\nif ( output !in shellshock_hosts )\n add shellshock_hosts[output];\n}\n\n# function to locate and extract IP addresses seen in shellshock exploit attempts\nfunction find_ip(ss: string): bool\n{\nlocal b = F;\nlocal remote_servers = find_ip_addresses(ss);\n\nif ( |remote_servers| > 0 )\n {\n b = T;\n for ( rs in remote_servers )\n {\n local s = to_addr(remote_servers[rs]);\n if ( s !in shellshock_servers )\n add shellshock_servers[s];\n }\n }\n\nreturn b;\n}\n\n# event to identify shellshock HTTP exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3\n{\nif ( ! is_orig ) return;\nif ( shellshock_pattern !in value ) return;\n\n# generate a notice of the HTTP exploit attempt\nNOTICE([$note=Shellshock_HTTP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock HTTP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",value),\n $identifier=cat(c$id$orig_h,c$id$resp_h,value)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(value) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in value )\n find_domain(value);\n}\n\n# event to identify shellshock DHCP exploit attempts\nevent dhcp_ack(c: connection, msg: dhcp_msg, mask: addr, router: dhcp_router_list, lease: interval, serv_addr: addr, host_name: string)\n{\nif ( shellshock_pattern !in host_name ) return;\n\n# generate a notice of the DHCP exploit attempt\nNOTICE([$note=Shellshock_DHCP,\n $conn=c,\n $msg=fmt(\"Host %s may have attempted a shellshock DHCP exploit against %s\", c$id$orig_h, c$id$resp_h),\n $sub=fmt(\"Command: %s\",host_name),\n $identifier=cat(c$id$orig_h,c$id$resp_h,host_name)]);\n\n# check the exploit attempt for IP addresses\n# if an IP address is found, then do not look for domains\nif ( find_ip(host_name) == T ) return;\n\n# check the exploit attempt for domains\nif ( shellshock_commands in host_name )\n find_domain(host_name);\n}\n\n# event to identify endpoints connecting to domains seen in shellshock exploit attempts\nevent http_header(c: connection, is_orig: bool, name: string, value: string) &priority=5\n{\nif ( name != \"HOST\" ) return;\nif ( value in shellshock_hosts )\n # generate a notice of HTTP connection to domain seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to a domain seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"Domain: %s\",value),\n $identifier=cat(c$id$orig_h,value)]);\n}\n\n# event to identify endpoints connecting to IP addresses seen in shellshock exploit attempts\nevent connection_state_remove(c: connection)\n{\nif ( c$id$resp_h in shellshock_servers )\n # generate a notice of connection to IP address seen in exploit attempts\n NOTICE([$note=Shellshock_Successful_Conn,\n $conn=c,\n $msg=fmt(\"Host %s connected to an IP address seen in a shellshock exploit\", c$id$orig_h),\n $sub=fmt(\"IP address: %s\",c$id$resp_h),\n $identifier=cat(c$id$orig_h,c$id$resp_h)]);\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'bro-scripts\/detect-shellshock.bro' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Bro"}