# Implementing a new script

**URL:** <https://community.zeek.org/t/implementing-a-new-script/4239>\
**Category:** Zeek\
**Created:** [July 12, 2016, 7:26pm UTC](https://community.zeek.org/t/implementing-a-new-script/4239 "2016-07-12T19:26:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Connor\_Borchgrevink](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@Connor\_Borchgrevink](https://community.zeek.org/u/Connor_Borchgrevink)\
**Post date:** [July 12, 2016, 7:26pm UTC](https://community.zeek.org/t/implementing-a-new-script/4239/1 "2016-07-12T19:26:34Z")

</div>

Howdy all,

I recently began poking around Bro and had my first attempt of writing a script. The purpose of it was to detect whether or not traffic on port 443 used SSL, the moment I implemented the script my CPU usage was at 100% and the same happened to my memory. Without the script enabled, the machine runs fine and bro only uses about 50-60% of the resources. I also tried to turn off every other thing in local.bro but it was the same result. The code is as follows (be warned its pretty rough):

@load base/protocols/ssl  
@load base/frameworks/notice  
@load base/protocols/conn  
@load base/utils/directions-and-hosts

module conn;

export {  
redef enum Notice::Type += {  
Unencrypted\_Traffic  
};

const List\_of\_Hosts = LOCAL\_HOSTS &redef;  
const Encryption = “SSL” &redef;  
}

event new\_connection(c: connection) &priority=3  
{  
if ( ! addr\_matches\_host(c$id$resp\_h, List\_of\_Hosts) )  
return;

local port\_number=c$conn$id$resp\_p;  
local ip\_address=c$conn$id$resp\_h;  
local encrypted=c$conn$service;

if ( port\_number != 443/tcp )  
return;

if ( encrypted != Encryption )  
NOTICE([$note=Unencrypted\_Traffic,  
$msg=fmt(“Unencrypted traffic”),  
$conn=c,  
$identifier=cat(c$id$resp\_h, c$id$resp\_p)  
]);  
}

It is probably something I am not catching in my code or a limited knowledge of bro, but any help is much appreciated.

Thanks

Connor

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [July 13, 2016, 3:25pm UTC](https://community.zeek.org/t/implementing-a-new-script/4239/2 "2016-07-13T15:25:57Z")

</div>

Hi Connor,

This is a nice job at a first script. I'll point out a few issues I noticed with it, but generally I think you got pretty close to what you wanted.  
  
Bro won't have detected the protocol in the connection yet in the new\_connection event. Generally you can assume that no payload has been seen when the new\_connection event is generated which means that we don't yet know if the traffic is encrypted or not. 🙂 You could use the protocol\_violation event to watch for the SSL analyzer to be violated. Port 443/tcp always gets the SSL analyzer attached as a heuristic but it will fail if the traffic is not actually SSL. This might actually be the most straightforward mechanism.  
&nbsp;&nbsp;[https://www.bro.org/sphinx/scripts/base/bif/event.bif.bro.html#id-protocol\_violation](https://www.bro.org/sphinx/scripts/base/bif/event.bif.bro.html#id-protocol_violation)

One other tiny mistake is that you're comparing the c$conn$service field against "SSL" but the value in the service field will be "ssl". You just need to fix your casing.

Nice script!

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:43pm UTC](https://community.zeek.org/t/implementing-a-new-script/4239/3 "2022-05-06T15:43:50Z")

</div>

Closed on May 6, 2022, 3:43pm UTC


