{"id":422,"date":"2025-07-03T02:58:28","date_gmt":"2025-07-03T02:58:28","guid":{"rendered":"https:\/\/epbrtcybersecurityportfolio.xyz\/?p=422"},"modified":"2025-07-03T02:58:28","modified_gmt":"2025-07-03T02:58:28","slug":"zeek-script-part-1","status":"publish","type":"post","link":"https:\/\/epbrtcybersecurityportfolio.xyz\/?p=422","title":{"rendered":"Zeek Script Part 1"},"content":{"rendered":"\n<p><strong>Objectives<\/strong><br>This exercise involves creating and running a very basic Zeek script.<\/p>\n\n\n\n<p><strong>Exercise 1<\/strong><br><strong>Description: In this first exercise, we will create the traditional \u201cHello, World!\u201d that is typical of a first attempt at programming in a new language.<\/strong><\/p>\n\n\n\n<p><strong>Using any editor of your choice that is installed on the VM, please create a script that will generate the string \u201cHello, World!\u201d at the console when it is executed with Zeek.<\/strong><\/p>\n\n\n\n<p>Since Zeek is a C-like language, it shares many very familiar syntactical and grammatical similarities. A list of a few similarities is:<\/p>\n\n\n\n<p>\u2022 Functions and events are defined using a type, a name, and a parameter list.<br>\u2022 Parameter lists are contained within parentheses.<br>\u2022 The types of all variables passed as parameters must be defined.<br>\u2022 The end of a statement is delimited with a semicolon <code>;<\/code>.<br>\u2022 Sections of code are all contained within curly-braces <code>{}<\/code>.<\/p>\n\n\n\n<p>The first step is to create a file to put my script into. I am going to name my script first.zeek.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"764\" height=\"52\" src=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/07\/image-24.png\" alt=\"\" class=\"wp-image-425\" srcset=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/07\/image-24.png 764w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/07\/image-24-300x20.png 300w\" sizes=\"auto, (max-width: 764px) 100vw, 764px\" \/><\/figure>\n\n\n\n<p>The next step is to determine which Zeek events will serve my needs. I want an event that will fire every time Zeek starts up.<\/p>\n\n\n\n<p>After searching through the Zeek documentation, I found an event called &#8220;zeek_init()&#8221; that seems to be the correct event. It is triggered every time Zeek starts.<\/p>\n\n\n\n<p>Regarding Module Name, my SEC 503 very strongly recommended that I develop the habit of prefixing all of my scripts with the module keyword and a name (example: module MyFirstScript;)<\/p>\n\n\n\n<p>This statement defines a namespace within which all of my global variables, functions, and events exist. When I do this, other scripts can still access my global variables, functions, and events by prefixing them with the MyFirstScript:: namespace operator, and it protects me from inadvertently overwriting existing variables, events, and functions in the global namespace.<\/p>\n\n\n\n<p>With the event information, I simply need to define my event and instruct Zeek as to what it should do when the event fires. In my case I want Zeek to print out &#8220;Hello, world!&#8221; when Zeek runs.<\/p>\n\n\n\n<p>Putting it all together:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"376\" height=\"145\" src=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/07\/image-25.png\" alt=\"\" class=\"wp-image-432\" srcset=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/07\/image-25.png 376w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/07\/image-25-300x116.png 300w\" sizes=\"auto, (max-width: 376px) 100vw, 376px\" \/><\/figure>\n\n\n\n<p>Let&#8217;s test this script and see if it runs properly:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"531\" height=\"45\" src=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/07\/image-26.png\" alt=\"\" class=\"wp-image-434\" srcset=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/07\/image-26.png 531w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/07\/image-26-300x25.png 300w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/figure>\n\n\n\n<p>It worked!!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ObjectivesThis exercise involves creating and running a very basic Zeek script. Exercise 1Description: In this first exercise, we will create the traditional \u201cHello, World!\u201d that is typical of a first attempt at programming in a new language. Using any editor of your choice that is installed on the VM, please create a script that will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-422","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/posts\/422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=422"}],"version-history":[{"count":5,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/posts\/422\/revisions"}],"predecessor-version":[{"id":436,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/posts\/422\/revisions\/436"}],"wp:attachment":[{"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}