Skip to main content

Suricata Signatures Language Server for the Language Server Protocol

Project description

Suricata Language Server is an implementation of the Language Server Protocol for Suricata signatures. It adds syntax check and hints as well as auto-completion to your preferred editor once it is configured.

https://raw.githubusercontent.com/StamusNetworks/suricata-language-server/main/images/vscode-sample.png

Suricata Language Server requires Python and a Suricata binary.

The code is based on Chris Hansen’s fortran language server and incorporate code from Stamus Networks’ scirius.

Features and architecture

Suricata Language Server currently supports auto-completion and advanced syntax checking. Both features are using the capabilities of the Suricata available on the system. This means that the list of keywords (with documentation information) is coming for Suricata itself and it is the same for the syntax checking. This comes at the cost to have Suricata installed on your system but at the same time, it guarantees a strict checking of signatures with respect to the Suricata version you are running. Pushing signatures to production will not result in bad surprise as the syntax has already been checked by the same engine.

Syntax checking is done when saving the files. A configuration test is started using Suricata. This is providing errors to the diagnostic. Warnings and hints are also provided by using a detection engine analysis done by Suricata. This is returning warnings and hints about the potential issues seen of the signatures.

Installation

You can use pip to install the Suricata language server

pip install suricata-language-server

Run this command with sudo if you want to install it globally.

If you are a Microsoft Windows user and need to install Suricata, you can use the MSI available on Suricata download page. For Python, the installer from Python website available on their Download page is working well.

Manual Installation

After cloning the repository, you need to install first the server by running in the root directory of the project

pip install .

This will add a suricata-language-server command to the system that will be invoked transparently by the editors that are configured to use it. You can use sudo pip install . to install it system wide if needed.

Server options

See suricata-language-server -h for complete and up-to-date help.

  • –suricata-binary: path to the suricata binary used for signatures testing

  • –max-lines: don’t run suricata tests if file is bigger then this limit (auto-completion only)

Editors Configuration

Neovim

https://raw.githubusercontent.com/StamusNetworks/suricata-language-server/main/images/nvim-completion.png

One simple way tis to use nvim-lspconfig and add the following snippet to your configuration

local lspconfig = require 'lspconfig'
local configs = require 'lspconfig.configs'
-- Check if the config is already defined (useful when reloading this file)
if not configs.suricata_language_server then
  configs.suricata_language_server = {
    default_config = {
      cmd = {'suricata-language-server'};
      filetypes = {'suricata', 'hog'};
      root_dir = function(fname)
        return lspconfig.util.find_git_ancestor(fname)
      end;
      single_file_support = true;
      settings = {};
    };
  }
end

If you want to setup a custom suricata binary, you can use the following trick:

local suricata_ls_cmd = {'suricata-language-server', '--suricata-binary=/my/own/suricata'}
require'lspconfig'.suricata_language_server.setup{
  cmd = suricata_ls_cmd,
  on_attach = on_attach,
}

Visual Studio code

Download the Suricata IntelliSense extension published by Stamus Networks from Visual studio Marketplace and install it into your Visual Studio Code instance. You can also direcly install it from Visual Studio Code via the Extensions menu.

Then you can configure it via the settings. Main settings are the path to the Suricata Language Server binary and the path to the Suricata binary.

For the settings on Microsoft Windows, you will need to escape the backslash in the paths you need to enter. With a standard Suricata msi installation and a standard installation of the server with pip the settings look like:

  • Server Path: C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python310\\Scripts\\suricata-language-server.exe

  • Suricata Path: C:\\Program Files\\Suricata\\suricata.exe

The Suricata IntelliSense extension is hosted on its own project on GitHub.

Sublime Text 3

You can use the LSP Package to provide support for LSP to Sublime Text 3.

To activate Suricata Language Server on .rules file, you need to create a new syntax for Suricata file by using the content of Suricata Sublime syntax from justjamesnow

To do so you can click on Tools > Developer > New Syntax then paste the content of the file and modify the text text.suricata to source.suricata. This will provide syntax highlighting as well as a source.suricata Sublime selector that can be used to trigger the Suricata Language Server activation.

To do that, you can setup the Suricata Language Server by following the documentation for the LSP package on client configuration. You will need to open Preferences > Package Settings > LSP > Settings and edit the configuration to add the Suricata Language Server.

The following configuration is known to work

{
  "clients": {
    "suricatals": {
      "enabled": true,
      "command": ["/path/to/suricata-language-server", "--suricata-binary=/path/to/suricata"],
      "selector": "source.suricata",
    },
  },
}

Kate

You can use Suricata Language Server in Kate by activating the LSP Client Plugin.

https://raw.githubusercontent.com/StamusNetworks/suricata-language-server/main/images/kate-sample.png

Once activated, you can go to Settings > Configure Kate > LSP Client then open the User Server Settings tab and add the configuration for the Language Server Protocol

{
  "servers": {
      "suricata": {
          "command": ["/path/to/suricata-language-server", "--suricata-binary=/path/to/suricata"],
          "highlightingModeRegex": "^.*Suricata.*$"
        }
      }
}

The second option giving the path to suricata binary is only necessary if you have a binary in a custom location.

Getting help

You can get help by:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

suricata-language-server-0.5.1.tar.gz (29.6 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page