What Is Lua Scripting?


What Is Lua Scripting? – Prior to this point, working with Wireshark routinely meant using the graphical interface, and just the
occasional mention of its command-line interface, TShark.

The reason we leverage the command line so much is to employ scripting. This chapter is centered around a scripting language, Lua, which you will find uncovers a lot more potential in Wireshark. Lua allows you to perform tasks specific to capturing or analyzing packets, and to extend Wireshark, both at the command line and in the GUI.

What Is Lua Scripting?

Why Lua?

Many software packages seem to support plug-ins of some sort, and with good reason. Tool developers can’t always build functionality for every situation. Extensibility is what separates the tools you use often for a variety of reasons and those that you use only once in a while. Plug-ins and other forms of application extensibility are usually made possible with an application programming interface (API).

An API provides a means for other developers to quickly leverage existing components and produce new functionality. You can use a good API to implement new functionality in a fraction of the time you would need to implement something from scratch or with the aid of regular programming libraries.

What Is Lua Scripting?

Up to only a few years ago, Wireshark users relied on such an API. What was known as the Wireshark API was the only way possible to create and add dissectors to Wireshark. This original plug-in API had to be programmed in C and thus required recompiling. And it was a constant source of security issues, as C is vulnerable to memory corruption when implemented incorrectly. Supporting a scripting language is a more flexible and modern solution, so Wireshark opted for Lua.

Lua is a scripting language in that Lua code is read from a plain text script/source file and then executed by the Lua interpreter—a compiled executable itself—dynamically at runtime. Another word for scripting language is interpreted or managed language.

Because the code is interpreted at runtime, and generally all memory access is managed by the runtime, Lua, in this case, is the interpreter. Being a managed language usually (but not always) means that common security vulnerabilities such as memory corruptions are less common, as developers are not directly responsible for managing memory access themselves (which is usually the cause for buffer overflow vulnerabilities, and so on).

This may be confusing at first if don’t have a computer science or programming background. Ultimately, all you need to understand is that a plain text file you created can be executed immediately by Lua without having to be compiled first, as with other languages, such as C/C++

What Is Lua Scripting?

If you’ve recently used one of the popular interpreted programming languages, such as Python or Perl, you should feel right at home using Lua. It is a language with runtime type checking, and variables do not need to be declared before use, like in many other scripting languages. This section describes some of the features you will use most while developing plug-ins for Wireshark and highlights cases where Lua differs from other programming languages.

To show the basics of Lua, we will show a piece of code for each of the building blocks you would regularly use, such as if statements, loops, functions, and variables. Because we are going to be scripting with Lua in Wireshark, it is imperative that you gain a foundation in the Lua language itself. In the following paragraphs, each element is highlighted to explain the quirks or pitfalls of the language.

Once you have a foundation, we move into Lua and Wireshark specifics. You will use your newfound Lua skills and understanding of the Wireshark Lua API to start programming some simple scripts that demonstrate how to use the command-line TShark, as well as play with GUI elements in the Wireshark application. By the end of this chapter, you will be pulling
files from network captures and writing your own custom dissector to examine a custom protocol.

What Is Lua Scripting?


A variable can be assigned by using the = operator. It does not have to be explicitly defined before use. If you reference a variable by trying to use it in an expression, like printing a variable to the screen, before assigning it a value, it returns the special value nil . Nil is like NULL , or undefined, in other languages. Lua has seven other basic types: Boolean, number, string, userdata, function, thread, and table.

Boolean values are True or False , whereas number is like an integer and floats in other languages combined into one. Both 4 and 4.5 are numbers in Lua. The string type is just what it sounds like; for example, Hello World is an example of a string. The last and probably the most important type is tables. These are incredibly flexible, and from a high-level act like an array/list as a hash/dictionary in other languages. For example, try the following in your Lua shell:

t_table = {11,12,13,14,15,15}
> print(t_table[1])
> print(t_table[2])

Here you see a table that acts as an array. This table is indexed using a number that assigns to the position of the values within the table. Notice that Lua attempts to make computer science majors cringe, as it doesn’t start counting an array by 0, which is common in computing, but instead starts indexing at 1. Also, if you try an out-of-bounds index number, like

Functions and Blocks

Lua does not use brackets to delimit a chunk of code like an if statement or while loop, but instead uses the word then or do to start the block, and end to close it. This might be familiar to you depending on what programming languages you have used. Some chunks, like functions, do not need an explicit statement to open but should still be ended by end . The following shows the creation of a function called testfunction and then the creating of a simple block:

function testfunction(var1)
>> print(var1)
>> end
> testfunction(“foo”)
> do
>> a = 1
>> b = 2
>> end
> print(a)
> print(b)

There Are So Much In This Lua Scripting , Hope You Like This Blog Please Comment Down And For More Blogs Click Here


Related posts

One Thought to “What Is Lua Scripting?”

  1. What Is Lua Scripting? – Automation Marketing Software | AutomateKing

    […] Twitter […]

Leave a Comment