elesiuta / picosnitch

Monitor Network Traffic Per Executable, Beautifully Visualized
https://elesiuta.github.io/picosnitch/
GNU General Public License v3.0
644 stars 16 forks source link
bandwidth-monitor ebpf intrusion-detection linux monitoring network-analysis network-monitor network-monitoring network-traffic network-visualization networking plotly privacy security

Picosnitch

Installation

AUR for Arch and derivatives

Details - install `picosnitch` [manually](https://wiki.archlinux.org/title/Arch_User_Repository#Installing_and_upgrading_packages) or using your preferred [AUR helper](https://wiki.archlinux.org/title/AUR_helpers)

PPA for Ubuntu and derivatives

Details - `sudo add-apt-repository ppa:elesiuta/picosnitch` - `sudo apt update` - `sudo apt install picosnitch` - optionally install [dash](https://pypi.org/project/dash/) with [pip](https://pip.pypa.io/) or [pipx](https://pypa.github.io/pipx/) - `sudo apt install pipx` - `pipx install dash` - you may require a newer version of [BCC](https://github.com/iovisor/bcc/blob/master/INSTALL.md#ubuntu---binary) ([unofficial PPA](https://launchpad.net/~hadret/+archive/ubuntu/bpfcc)) since the version in the [Ubuntu repos](https://repology.org/project/bcc-bpf/versions) sometimes lags behind its [supported kernel](https://github.com/iovisor/bcc/releases)

OBS for Debian and derivatives

Details - visit the [OBS picosnitch page](https://software.opensuse.org//download.html?project=home%3Aelesiuta&package=picosnitch) and follow the instructions for your distribution - optionally install [dash](https://pypi.org/project/dash/) with [pip](https://pip.pypa.io/) or [pipx](https://pypa.github.io/pipx/) - `sudo apt install pipx` - `pipx install dash` - if you're having issues on bullseye, you may need a newer version of [BCC](https://github.com/iovisor/bcc/blob/master/INSTALL.md#debian---binary)

OBS for openSUSE Tumbleweed and derivatives

Details - `sudo zypper addrepo https://download.opensuse.org/repositories/home:elesiuta/openSUSE_Tumbleweed/home:elesiuta.repo` - `sudo zypper refresh` - `sudo zypper install picosnitch`

Copr for Fedora, Mageia, Mandriva, and derivatives

Details - `sudo dnf copr enable elesiuta/picosnitch` - `sudo dnf install picosnitch` - optionally install [dash](https://pypi.org/project/dash/) with [pip](https://pip.pypa.io/) or [pipx](https://pypa.github.io/pipx/) - `sudo dnf install pipx` - `pipx install dash`

Nixpkgs for Nix

Details - install and enable using the [picosnitch service option](https://search.nixos.org/options?show=services.picosnitch.enable) - add `services.picosnitch.enable = true;` to your Nix configuration file (typically `/etc/nixos/configuration.nix`) - run `sudo nixos-rebuild switch` - workaround for "Failed to compile BPF module" - `systemctl stop picosnitch` - `sudo picosnitch start-no-daemon` then send SIGINT (ctrl + c) - `systemctl start picosnitch`

PyPI for any Linux distribution with Python >= 3.8

Details - install the [BPF Compiler Collection](https://github.com/iovisor/bcc/blob/master/INSTALL.md) python package for your distribution - it should be called `python-bcc` or `python-bpfcc` - install picosnitch using [pip](https://pip.pypa.io/) or [pipx](https://pypa.github.io/pipx/) - `pipx install "picosnitch[full]"` - create a service file for systemd to run picosnitch (recommended) - `picosnitch systemd` - optional dependencies (will install from [PyPI](https://pypi.org/) with `[full]` if not already installed) - for dash: [dash](https://pypi.org/project/dash/), [pandas](https://pypi.org/project/pandas/), and [plotly](https://pypi.org/project/plotly/) - for dash themes: [dash-bootstrap-components](https://pypi.org/project/dash-bootstrap-components/) and [dash-bootstrap-templates](https://pypi.org/project/dash-bootstrap-templates/) - for GeoIP lookups: [geoip2](https://pypi.org/project/geoip2/) - for notifications: `dbus-python`, `python-dbus`, or `python3-dbus` (name depends on your distro and should be installed from their repo) - for sql server: one of [psycopg](https://pypi.org/project/psycopg/), [pymysql](https://pypi.org/project/PyMySQL/), [mariadb](https://pypi.org/project/mariadb/), or [psycopg2](https://pypi.org/project/psycopg2/) (latter two not included with `[full]`) - for VirusTotal: [requests](https://pypi.org/project/requests/)

GitHub for installing from source

Details - clone the repo or download `picosnitch.py` and `setup.py` - install the [BPF Compiler Collection](https://github.com/iovisor/bcc/blob/master/INSTALL.md) python package for your distribution - it should be called `python-bcc` or `python-bpfcc` - install [psutil](https://pypi.org/project/psutil/) - install `python-setuptools` - install picosnitch with `python setup.py install --user` - see other options with `python setup.py [build|install] --help` - you can also run the script `picosnitch.py` directly

Usage

Configuration

{
  "DB retention (days)": 30, # How many days to keep connection logs in snitch.db
  "DB sql log": true, # Write connection logs to snitch.db (SQLite)
  "DB sql server": {}, # Write connection logs to a MariaDB, MySQL, or PostgreSQL server
  "DB text log": false, # Write connection logs to conn.log
  "DB write limit (seconds)": 10, # Minimum time between connection log entries
  # increasing it decreases disk writes by grouping traffic into larger time windows
  # reducing time precision, decreasing database size, and increasing hash latency
  "Dash scroll zoom": true, # Enable scroll zooming on plots
  "Dash theme": "", # Select a theme name from https://bootswatch.com/
  # requires installing https://pypi.org/project/dash-bootstrap-components/
  # and https://pypi.org/project/dash-bootstrap-templates/ with pip or pipx
  "Desktop notifications": true, # Try connecting to dbus to show notifications
  "Every exe (not just conns)": false, # Check every running executable with picosnitch
  # these are treated as "connections" with a port of -1
  # this feature is experimental but should work fairly well, errors should be expected as
  # picosnitch is unable to open file descriptors for some extremely short-lived processes
  # if you just want logs (no hashes) to trace process hierarchy, see execsnoop or forkstat
  "GeoIP lookup": true, # GeoIP lookup of IP addresses in user interface (terminal and web)
  "Log addresses": true, # Log remote addresses for each connection
  "Log commands": true, # Log command line args for each executable
  "Log ignore": [], # List of hashes (str), domains (str), IP subnets (str), or ports (int)
  # will omit connections that match any of these from the connection log
  # domains are in reverse domain name notation and will match all subdomains
  # the process name, executable, and hash will still be recorded in record.json
  "Log ports": true, # Log local and remote ports for each connection
  "Perf ring buffer (pages)": 256, # Power of two number of pages for BPF program
  # only change this if it is giving you errors (e.g. missed events)
  # picosnitch opens a perf buffer for each event type, so this is multiplied by up to 18
  "Set RLIMIT_NOFILE": null, # Set the maximum number of open file descriptors (int)
  # it is used for caching process executables and hashes (typical system default is 1024)
  # this is good enough for most people since caching is based on executable device + inode
  # fanotify is used to detect if a cached executable is modified to trigger a hash update
  "Set st_dev mask": null, # Mask device number for open file descriptors (int)
  # set to 0 to disable verification if it is giving you errors (e.g. FD cache errors)
  # defaults to 0 if a btrfs partition is detected, otherwise 0xffffffff
  "VT API key": "", # API key for VirusTotal, leave blank to disable (str)
  "VT file upload": false, # Upload file if hash not found, only hashes are used by default
  "VT request limit (seconds)": 15 # Number of seconds between requests (free tier quota)
}

Logging

Limitations