BitNinja SAM (Standalone Anti-Malware) – Quick User Guide

BitNinja SAM is a standalone Linux malware scanner. It connects to BitNinja Central using its own API key and operates independently of the BitNinja PHP agent.

It supports two scanning modes:

  • Active scan (realtime): Uses eBPF to monitor file operations and immediately scans modified files.

  • Manual scan: Scans all files in a specified directory on demand.

Requirements#

  • systemd-based Linux (Debian/Ubuntu: .deb)

  • Root privileges

  • Outbound HTTPS connectivity to https://api.bitninja.io

  • API key from admin.bitninja.io (Settings / General) or a trusted BitNinja reseller key

Installation and startup#

echo "deb [signed-by=/etc/apt/trusted.gpg.d/bitninja.gpg] http://apt-nightly5.bitninja.io/debian/ bitninja non-free" | sudo tee /etc/apt/sources.list.d/bitninja-sam.list
sudo apt-get install -y bitninja-sam # or: dpkg -i / rpm -Uvh sudo bitninja-sam-setup --license_key=YOUR_API_KEY systemctl status bitninja-sam

After a successful startup, the following entries (among others) should appear in /var/log/bitninja-sam/bitninja-sam.log:

Logged in to BitNinja Central
Command channel connected to https://api.bitninja.io/v2/server/commands
eBPF active scan attached via ...        # only if realtime scanning is available

Active scan (realtime)#

By default, the scanner monitors the following locations:

  • /tmp

  • /home* (including /home2, /home3, etc.)

  • /var/www

  • /var/spool/cron

The list can be extended by modifying the inotify.file_path setting in:

/etc/bitninja-sam/MalwareDetection/config.json

Catch-up scanning#

After a service restart or crash, SAM automatically scans files that have changed since its last run (catch-up scanning).

Exception: If an entire directory has been moved, the timestamps of the files inside it remain unchanged. As a result, catch-up scanning will not detect these files. In this case, run a manual scan.

Manual scan#

While the service is running, write an absolute directory path to the scan.request file:

echo /var/www | sudo tee /var/lib/bitninja-sam/scan.request

Within a few seconds, the service will start the scan and automatically delete the request file.

You can monitor the progress in the log:

  • Local scan started

  • Scan progress ...

Manual scans can also be initiated from BitNinja Central.

Important: Do not run the bitninja-sam -scan command while the service is running, as the two instances will conflict with each other.

Faster scanning#

The default package configuration limits CPU usage to keep the system load low.

To increase the scanning speed, apply the following settings:

{
  "core": {
    "scan_throttle_time_ms": 0,
    "cgroup_cpu_max": 100
  }
}

Add these settings to:

/etc/bitninja-sam/MalwareDetection/config.json

Then restart the service:

sudo systemctl restart bitninja-sam

What the scanner skips#

The scanner excludes the following:

  • Files larger than 10 MiB.

  • Whitelisted file extensions. Extension matching is case-sensitive.

  • Whitelisted paths.

  • Files that have not changed since the previous scan (cache).

Important – Path whitelist behavior:

Whitelist entries are matched as prefixes.

To exclude a directory, make sure the entry ends with a trailing slash.

For example:

/var/www/site/cache/

Without the trailing slash, paths such as /var/www/site/cachex may also be excluded.

Handling detections#

Quarantine#

Detected files are moved to the quarantine directory. A corresponding JSON sidecar file is created alongside each quarantined file. This file contains the information required to restore the original file.

Event logs#

A separate JSON file is created for each detection under:

/var/log/bitninja-sam/events/

The event field can have one of the following values:

  • quarantine

  • validating

  • log-only

External systems can read these files to retrieve scan results.

BitNinja Central#

Incidents are forwarded to BitNinja Central in the background. The quarantine process does not wait for network communication to complete.

Kernel and platform limitations#

Environment

Realtime scanning

Manual scanning and Central

Ubuntu 24.04 (kernel 6.8) and newer, kernel 7.x

Supported

Supported

Ubuntu 22.04, Debian 12

Can make it work by installing the required EBF packages

Supported

Kernels older than 5.8 (e.g. Ubuntu 20.04, kernel 5.4)

Not supported: BPF ring buffer is missing

Supported

arm64

Not supported

–

If realtime scanning cannot be started, the service will continue running. The following message will appear in the log:

Active scan disabled: ....

Additional limitations#

  • Maximum number of monitored prefixes: The kernel supports up to 16 monitored prefixes, each shorter than 64 bytes. If more or longer prefixes are configured, filtering is moved to userspace. This still works but requires additional system resources.

  • Long file paths: Realtime scanning does not support paths longer than 4096 bytes.

  • tmpfs-based /tmp (e.g. Ubuntu 26.04): If the quarantine directory is located on a different filesystem, moving files from /tmp currently fails. In this case, detections are recorded as log-only. The log will contain an invalid cross-device link error.

Useful commands#

# Restart, stop, or check the service status
sudo systemctl restart bitninja-sam
sudo systemctl stop bitninja-sam
sudo systemctl status bitninja-sam

# Follow the service log in real time
sudo tail -f /var/log/bitninja-sam/bitninja-sam.log

# Display the last 50 service log entries
sudo journalctl -u bitninja-sam -n 50

# List detection event files
ls /var/log/bitninja-sam/events/

Important files and directories#

Path

Purpose

/etc/bitninja-sam/config.json

API URL and API key

/etc/bitninja-sam/MalwareDetection/config.json

Scanner settings: whitelist, monitored paths, performance

/var/lib/bitninja-sam/scan.request

Trigger a manual scan

/var/log/bitninja-sam/bitninja-sam.log

Service log

/var/log/bitninja-sam/events/

One JSON file per detection

Uninstallation#

sudo systemctl stop bitninja-sam && sudo dpkg -r bitninja-sam

For RPM-based systems:

sudo systemctl stop bitninja-sam && sudo rpm -e bitninja-sam

Note: Configuration files, license information, and logs are preserved after uninstallation. This allows you to reinstall the package and resume operation using the same API key.