Lunatik: A Toolkit for Developing Lua Handlers in the Linux Kernel

Project Lunatik develops tools that allow you to use the Lua language to expand the functionality of the Linux kernel and quickly write handler scripts that work at the kernel level. The Lua interpreter is used to execute the code, modified to work at the kernel level. The project code is written in C and distributed by under MIT license.

A special driver is used to load and execute Lua scripts at the kernel level, and a command line utility is offered to control the Lua environment in the kernel from user space. The project also provides a C API to control the loading and execution of Lua scripts from the Linux kernel, which can be used, for example, to execute individual Lua handlers from traditional kernel modules written in C. The Lua API and a set of bindings are provided to access kernel functions from Lua code.

Lua scripts can use a subset of library functions and capabilities, limited due to the specifics of working within the kernel. For example, the code does not support floating point operations and libraries cannot be used io And osand many library functions are not available math. The C API does not support the luaL_Stream, luaL_execresult, luaL_fileresult, luaopen_io, and luaopen_os functions.

Among the capabilities of the command line utility, you can cancel commands for loading, unloading and reloading Lunatik modules in the kernel, displaying the status of loaded modules, viewing a list of scripts running in the kernel, running scripts, creating and stopping Lua runtime environments in the kernel, using the interactive shell REPL (Read –Eval–Print Loop).

The project also provides a set of examples to evaluate the capabilities of Lunatik. For example, scripts are available with the implementation of a character device driver, a network sniffer with the ability to log MAC addresses, a database for storing data in the form of key/value, a server for the ECHO protocol, a keylogger for logging keystrokes, a keyboard blocker (after pressing “↑ ↑ ↓ ↓ ← → ← → LCTRL LALT” the kernel stops processing keystrokes until the sequence is re-entered), drivers for monitoring system calls, routing servicevarious add-ons for the Netfilter and XDP subsystems.

Thanks for reading: