首页
看点啥
插画图片
首页 科技看点 picosnitch:实践指南

picosnitch:实践指南

2026-09-12 0

准备试用picosnitch之前,先别急着安装;这个项目提供的是监视每个可执行文件的网络流量。从日常自动化的使用方式看,输入边界、依赖和失败处理如果不清楚就很难稳定复用是采用前必须回答的问题。我建议用一项范围明确的真实任务完成最小试跑,重点记录配置时间、输出质量、异常信息和维护痕迹,再与现有方案比较。对愿意先做小范围验证并复查原始文档的团队来说,这个仓库值得继续验证;只求即装即用的人则要先看维护成本。

elesiuta/picosnitch 项目截图 1

Picosnitch

picosnitch webui browse and chart past connections

picosnitch tui browse past connections in a terminal

picosnitch top live event feed

More 屏幕截图和 picosnitch 屏幕截图 gallery. 中的简短演示视频

安装

建议安装系统范围的 pipx 安装。它适用于 Python >= 3.12 的每个 Linux 发行版,并且内核足够新,可以运行现代 libbpf CO-RE 程序。

sudo pipx install picosnitch --global
sudo picosnitch systemd
sudo systemctl enable --now picosnitch

用途

配置

配置存储在 /etc/picosnitch/config.toml 中,并在首次运行时使用默认值创建。

[database]
enabled = true                # write connection logs to /var/lib/picosnitch/picosnitch.db (SQLite)
retention_days = 30           # how many days to keep connection logs in the local database
                              # (the remote database is append-only; see [database.remote])
write_limit_seconds = 10      # minimum time between connection log entries
                              # increasing it groups traffic into larger time windows, decreasing
                              # disk writes, time precision, and database size
text_log = false              # also write a CSV connection log to /var/log/picosnitch/conn.log

[database.remote]             # optional: also write connection logs to an external SQL server
                              # used for off-system / tamper-evident logs (see Logging below).
                              # mirrors the local SQLite schema (connections, executables,
                              # domains, addresses).
                              # set `client` to "mariadb", "psycopg", "psycopg2", or "pymysql";
                              # add the rest of the connection parameters as key/value pairs and
                              # optionally `connections_table` to override the default; this lets
                              # multiple hosts share one server with a `connections` table each
                              # while reusing the shared `executables`/`domains`/`addresses`

[data]
owner = "root"                # owner for files in /var/lib/picosnitch, /var/log/picosnitch,
group = "root"                # and /var/cache/picosnitch
mode = "0644"                 # mode applied to those files (directories add execute bits)
                              # config.toml stays root:root 0600 because it can contain credentials

[log]
addresses = true              # log remote addresses for each connection
commands = true               # log command line args for each executable
ports = true                  # log local and remote ports for each connection
ignore_ports = []             # list of ints; matching connections are omitted from the log
ignore_domains = []           # list of strings in reverse-dns notation (matches all subdomains)
ignore_ips = []               # list of IPs/CIDRs (e.g. "192.168.0.0/16")
ignore_sha256 = []            # list of executable sha256 hashes
                              # the process name, executable, and hash are still recorded

[desktop]
user = ""                     # username to send notifications to; defaults to $SUDO_UID
notifications = true          # show desktop notifications via notify-send (libnotify)
geoip_lookup = true           # annotate remote addresses with a country code in the TUI/webui
                              # uses the DB-IP Country Lite CSV cached under /var/cache/picosnitch

[monitoring]
every_exe = false             # check every running executable, not just ones that open sockets
                              # these are treated as "connections" with a port of -1
                              # experimental; expect occasional errors for short-lived processes
                              # if you only want process logs (no hashes), see execsnoop / forkstat
exec_ring_buffer_pages = 256  # power of two pages sizing the exec event ring buffer
                              # network traffic is aggregated in-kernel, it does not use this
                              # only change this if you are seeing missed-event errors
conn_map_max_entries = 65536  # size of the in-kernel per-connection aggregation map
                              # only raise this if you see near-capacity eviction warnings
# rlimit_nofile = 65536       # optional int; raises RLIMIT_NOFILE for the daemon
                              # picosnitch caches one file descriptor per (device, inode);
                              # set this if you see "Too many open files" errors
# st_dev_mask = 0             # optional int; masks the device number reported for opened fds
                              # auto-detected at startup; only set this to override the default
                              # for filesystems that reuse inodes across subvolumes (e.g. btrfs)

[virustotal]
api_key = ""                  # VirusTotal API key, leave blank to disable
file_upload = false           # upload the executable when its hash isn't already known
                              # leave false to only submit hashes
request_limit_seconds = 15    # seconds between requests (free-tier quota)

重新启动 picosnitch 以使任何配置更改生效。

日志记录

Picosnitch 将其磁盘状态划分到 FHS 目录中。所有默认值均采用 systemd 单元(该单元也在首次启动时创建这些单元)。

路径 内容
/etc/picosnitch/config.toml 配置
/var/lib/picosnitch/picosnitch.db SQLite 连接日志(由 picosnitch tuipicosnitch webui 读取)
/var/lib/picosnitch/state.json 已知的可执行文件 + sha256 哈希值,用于决定何时通知
/var/log/picosnitch/exe.log 新可执行通知的历史记录
/var/log/picosnitch/error.log 错误(也作为桌面通知出现)
/var/log/picosnitch/conn.log 可选 CSV 连接日志(通过 [database].text_log = true 启用)
/var/cache/picosnitch/ DB-IP Country Lite 数据库,每月刷新
/run/picosnitch/picosnitch.pid pid 文件(世界可读,由 picosnitch status 使用)
/run/picosnitch/events.sock picosnitch top 消耗的实时事件套接字

[database.remote] 可用于另外将每个连接传送到 MariaDB、MySQL 或 PostgreSQL 服务器。它镜像本地 SQLite 架构(connectionsexecutablesdomainsaddresses);仅 connections 表名可以被覆盖(通过 connections_table),这允许多个主机共享一台服务器,每个服务器都有一个 connections 表,同时重用共享引用表。 Picosnitch 从不更新或删除远程行(不保留,不进行垃圾收集),因此它旨在保留日志 的系统外副本 [;仅授予 CREATE(首次运行)、INSERTSELECT(id 查找),以便受监控主机上的对手无法重写或删除 picosnitch 的系统外日志。

如果现有远程 executables 表缺少 key_hash 列,则守护程序会报告过时的架构并保持不变;备份并重新创建远程表以启用远程日志记录。

conn.log 是一个 CSV,具有以下字段(逗号、换行符、回车符和 NUL 字符从值中删除):entry time, sent bytes, received bytes, event count, executable path, process name, cmdline, sha256, parent executable, parent name, parent cmdline, parent sha256, grandparent executable, grandparent name, grandparent cmdline, grandparent sha256, user id, address family, protocol, local port, remote port, local address, remote address, domain, network namespace

error.log 中的条目通常由异常大量的新进程或连接触发,由在 picosnitch 可以打开文件描述符之前退出的极其短暂的进程触发,或者在对新的可执行文件进行哈希处理时挂起系统。意外的条目值得调查,因为 picosnitch 的设计目的是在进程偏离其正常观察路径时显示错误。

限制

喜欢(0)

上一篇

hospitalrun:实践指南

hospitalrun:实践指南

下一篇

QT-PyQt-PySide-Custom-Widgets:实践指南

QT-PyQt-PySide-Custom-Widgets:实践指南
猜你喜欢