in this next section will review three important components of rose programming language, directives, declarations and types.
The first language component I want to discuss is the directive. Directives and row determine what bro script is to be loaded and executed.
Directives Air used to satisfy script dependencies and constrain script execution to certain conditions or even specific cluster notes.
Declarations on the other hand controlled type invariable definition as well as accessibility based on scope.
I'll describe declarations in scope in more detail in the coming slot.
Row also includes many other types that are common to other programming languages
like strings, imagers, doubles and container types like tables.
Tables in bro are similar to dictionaries and python,
and we'll find many other similarities in these components.
However, Bro Specialization is in network traffic analysis, and this is what sets it apart from other languages.
For that purpose, Bro defines domain specific types like I P's, Sub Nets and Ports.
As we discussed in the previous section, Bro's event based programming model helps translate real world traffic analysis events to events occurring in bro
features and functionality in the language like its domain. Specific types provide programming constructs that make it ideal for describing network communications.
Now let's talk about directives.
The bro scripting language includes what are known as directives.
Directives affect what scripts are loaded and what lines of script code are executed
without directives. Load in particular. Nothing else would happen in bro.
The first directive I want to mention is dirt
their act something like an environment variable in shell scripting. It reflects the current working directory. The script is sitting in
like Durr. File name reflects the name of the script itself. These directives can be very helpful in a variety of ways as they provide information about where the script resides. On the file system
Load is a special directive, and as I mentioned a minute ago, it's critical to making things happen In Bro,
Load specifies a script or module directory. The script interpreters should load and execute
load statements are executed immediately, which is why they're also used to satisfy a script dependencies.
If your script uses a function or variable defined in another module,
you should include an appropriate load statement to make sure that module is loaded and available.
Load cigs is a little different. This directive tells Road read and interpret of file in the format defined by Bro's signature frame, where
this format is similar. In concept of snort rules, however, a signature match results in the execution of an event
and its handlers not necessarily in the generation of an alert.
Finally, the if in end. If directives.
These were special directives that determine what lines of script code will be executed
if allows you to specify a logical test that determines that the lines of code that follow
up to the end if directive should be run.
This is a powerful feature and used extensively to make bro scripts. Cluster aware,
that is, they create blocks of script code that will only be run on specific cluster notes as determined by the supply test.
Now let's talk about declarations.
Declarations were used to create type instances and variables, as well as determined the scope of identifiers and bro script.
Variable declarations can occur before the variable is actually initialized or used
the 1st 2 declarations air used to declare name space and manage what is accessible outside of it from other scripts.
The module declaration keyword specifies the name space for the script.
Every declaration that occurs after it until the next module keyword
belongs to the specified name space.
The export key word is used to define a block of other declarations that are made available to other scripts.
Within the export block, you will often find Global and Const declarations.
The global key word is used to mark variables and user to find types globally accessible.
Constance can be redefined but cannot be modified after their initialized.
They remain constant throughout the lifetime of the bro process.
The type declaration is used to specify user to find types. An important takeaway is that tight Declaration is most commonly used to create records and e numbs
records and Denham's Air used widely and bro scripting in particular by the logging framework
Read off is a declaration that is widely used to tune and tweak Existing bro scripts.
Read F declarations modify a global variable or constant that was declared with the read of attributes.
By making certain variables globally accessible and redefine, Herbal
bro scripts can expose customization options to bro users without requiring that they modify scripts directly.
This is great for turning features on and off, setting options and providing additional metadata to the script.
There are a few other declaration types that I'll only briefly mention here They are functions, events and hooks.
In the previous section, I described the differences between declaration and in vocation as it relates to events, and the same principles apply to both hooks and functions.
We'll discuss this more in a few slots.
Now let's take a look at some of rose and non execute herbal types.
Bro was like many other programming languages for its support of common non excludable types.
Specifically, Bro makes three different America types available. Count Int and double
count and end are very similar. In fact, the only perceptible differences that in't is signed or supports negative and positive values.
Count, on the other hand, can only be positive
both in an account support. The same mathematical operations
double is a special numerical type that is for representing double precision floating point numbers. Doubles can also be positive or negative, and light count and int
can be expressed in Hexi decimal format.
All of the numeric type support a variety of arithmetic operators such as addition, subtraction, multiplication division and Modelo
liked in America types. The string type is another very commonly used type in bro.
Strings are enclosed in double quotes and contain a string of bites that represent text or can be used to represent arbitrary binary data.
Strings can be can captain ated compared, and there are numerous built in functions for transforming and working with strings and useful ways.
String types also support a variety of built in operators such as relational and equality tests,
length operators in sub string extraction.
I've included a link to more information about built in string functions in the resource is section
rose. Regular expression capabilities are implemented by the pattern type
patterns are declared its Constance and that they don't change after their initialized.
They provide an extensive syntax for representing textual data and are used throughout bro for operations that require fast text searching.
Other languages also have a way of representing true or false, typically as a result of a logical test of some kind
and bro, the true or false type is called a bull
bull represents. True as a Capital T and false as a capital. F.
Bro also shares the notion of container types with other programming languages.
Container types are specifically intended for storing data.
Available. Container types include vectors, sets, tables and records
Tables map one set of values the indices to another. The yield
indices can be one of the many not excusable types, with the exception of things like patterns and other containers. The values air yields, on the other hand, have less restrictions.
In fact, a field in a table can be another table, allowing for the representation of very complex, multi dimensional data structures.
Table support indexing with the double bracket operator and membership tests with Ian and not in operators.
Tables Air used throughout Bro and are one of the main mechanisms that make tracking network activity and protocol usage across multiple connections. Possible
sets are similar to tables, but they're indices did not have yield values. In essence, this makes them a list of unique things, and they could be very useful in Bro script for that reason. For example, a second be used to keep a running list of unique your l's
or I P addresses or I P. Import pairings
like tables, set support a variety of attributes that affect how long an element will remain in the container.
We'll discuss attributes a little more in the next segment.
Vectors air similar to a raise or list and other languages there and ordered list of things.
If you want to access an element of the list, you use the double bracket operators to specify the position of the element in the list. The position of the first element is always zero in each into sea increments by one up from there. I've discussed records a few times already. There user defined type that is a collection of values.
Each value has a name and a type, and types can be different.
Records are another foundational component of the language and used extensively for representing an instance of something a connection. For example,
in the prologue segment, we saw a few of the ways records can be constructed after their initialized. A record instances Fields can be accessed using the dollar sign Operator
Infield existence can be tested using the question mark Dollar Sign operator.
The next type category I want to mention are the network types
these air part of what makes bro domain specific, as there used to describe network traffic,
the port type is a representation of the TCP, or UDP. port number.
In the case of ICMP,
the source port is equal to the ICMP message type in the destination port. The ICMP message coat
ports are written as an unsigned manager, followed by a string that designates the transport protocol. TCP UDP or ICMP
Adder in Summit are also special network types that are used to represent I P addresses and sub nets, respectively.
Both I P V four and V six addresses are supported and an adder can be tested for membership in a sub net By using the in operator, this is very useful functionality that will see again in an upcoming example.
Finally, there are two types specifically for describing time.
The first is the time type. This is a positive double that represents the absolute time. The interval type represents the relative time between two consecutive time. Value
Time is critical in network traffic analysis, which is why the time type is used to record the occurrence of each network event written to Abreu Log.
Now let's take a look at some of bro's execute herbal types
of mention. Bro's executed all types several times throughout this course. Each of these types is both declared and invoked these air two distinct operations, and it's useful to have a strong understanding of the difference. Functions and bro is similar to functions and other languages. They are usually given a name,
define some black of code, made up of statements and operators, and optionally return of value. When they're invoked,
functions are invoked using the functions name, followed by any required arguments.
One invoked functions are executed immediately. That is, they're not cute and do not have a priority. You'll see functions used throughout bro to make script code accessible and reusable. This is a very common and useful practice and programming
event. Handlers are similar to functions. However, they do not support return values and they are cute when invoked. As I mentioned in the previous segment, event handlers are cute in an order of priority, which is specified when they're declared event handler. Bodies can also contain the event and scheduled statements which result in the execution of other handlers
or in some cases, the handler there contained it.
This feature could be used to create an event loop where Handler is executed, then scheduled itself to be run again on some interval.
The final excusable type is a hook
hooks or more like a blend of functions and events.
They're excusable blocks of code, with an optional predefined set of arguments.
Ho Cantler's are assigned a priority, which determines their execution order,
but they're executed immediately, not scheduled.
Unique attribute of hook handlers. They can prevent the execution of lower priority handlers by issuing the brakes Statement.
Hooks have a single built in return type, a bull that signifies whether or not all of the handlers ran true or if only some are. None of the handlers ran false.
Now let's just got some of those other statements and operators.
I've mentioned several operators along the way that allowed for testing, interacting with and manipulating bro's built in types.
Now let's review a couple of operators that I haven't mentioned up to this point.
The first are logical operators. That is, they represent the logical and or and not
thes operators are often used in conjunction with an if statement,
you can use combinations of these operators to build out very complex conditions in your bro. Script
assignment operators set one value equal toe another or the addition to or subtraction from one value of another
assignment operators have found everywhere and bro, especially in places where variables are being initialized, where values assigned to record fields.
Membership tests are performed with the inn and not in operators.
You could be used with sets and tables to check for the presence of a value.
Membership test can also be used to check a sub net for the presence of an adder.
This is incredibly useful functionality, and something broke or relies heavily upon
statements and Bro is similar to commands. They instruct the script interpreter to perform some action.
Local declares a local variable inside of an executed will type
ad and elite are used for managing elements in a container.
Print will print the provided argument to standard out, which is very useful for testing and getting to know the language
for a while next and break our all statements that really toe loops.
The four and wild statements are used to create a loop,
and the next and break statements caused the loop to continue to the next generation or exit, respectively, for making a synchronous calls like issuing Olynyk C L. A command and waiting for the output Bro provides the wind statement return is a special statement used to exit from the body of a function *** event.
Return statements used in a function body can yield a value of a predefined type.
The return value of a function is actually the result of the expression to the right of the return statement.
The last two statements I'll mention here are event and schedule. Both are used to execute event handlers.
Event statement cues The matching event handlers for execution in their defined priority
schedule does the same thing except at a specified interval.
You've heard me say when event handlers are executed many times throughout this course. And this is why,
when an event is triggered, generated or executed inside of bro script, it is done with one of these two statements
now in summary review some of the key points discussed and previous slides
In this section, I provided a high level overview of many of the core concepts of Bro's programming language.
First, we discuss directives.
Directives are critical to the execution of Bro script as they determine which scripts get loaded in which lines of code get executed.
All things performed by the script, interpreters start with the load directive.
Next, I described several Bro's declarations, which are used to define Create an Initialized Things in Bro.
You'll use the Global and con Stoeckl orations to create exported variables and Constance
in the Read F Declaration for replacing or modifying variables defined by other scripts.
Declarations like Module on Export are used in conjunction with each other in Crete and manage what variables are accessible outside of a script.
We then discuss some of Bro's types.
In particular, it's non executed all types.
I described types common to many other programming languages, like numeric types, strings and regular expressions.
I also describe the types that make bro domain specific, such as the Port Adder and Sub Net type.
Bro's executed all types provide a way to get things done in the language.
We discussed events extensively throughout this course, and there they are only one of three excusable types, and bro
functions are excusable code blocks that are immediately executed when invoked
and optionally return a value of a predefined type.
Pokes are similar and concept of both events and functions, and are used in cases where neither of these types meet the specific needs of the situation.
Finally, we briefly discussed several of rose operators and statements.
These are foundational components of the language
as they are. What? Tell the script interpreter What to do?
We've seen many examples of operators and statements, and you, so far in the next and final section will revisit, thes and use some customization toe add functionality to our previously defined script.