Skip to content
sdkfuyrPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sec-check

Fast, agentless-feel security audit for Ubuntu servers. Each server runs a Python 3 script from cron; if any CRITICAL or HIGH finding appears, a Telegram alert is sent. Quiet otherwise.

Designed for personal/small fleets on Hetzner (or any Ubuntu host).

What it checks

Each run, under a minute on a small server:

  • Patching — pending security updates, kernel/openssl/openssh/libc/sudo prioritised as CRITICAL; reboot-required flag; Ubuntu release EOL; unattended-upgrades installed and enabled; stale apt cache.
  • SSH — PermitRootLogin, PasswordAuthentication, PermitEmptyPasswords, protocol version, sshd actually running. Uses sshd -T so includes drop-in configs.
  • Firewall — ufw / nftables / iptables presence; flags a host with no active firewall as CRITICAL.
  • Listening services — anything bound to 0.0.0.0. Sensitive ports (Postgres, MySQL, Redis, Mongo, Elasticsearch, Docker API, Kibana, etc.) on the public interface are CRITICAL; other unexpected public listeners are HIGH (allowlist via SEC_CHECK_ALLOWED_PORTS).
  • Users & sudo — extra UID 0 accounts, empty password fields, NOPASSWD entries in sudoers.d.
  • File permissions — /etc/shadow, /etc/gshadow, /etc/ssh/sshd_config, /etc/passwd.
  • Brute force signals — failed SSH logins in last 24h grouped by IP; fail2ban active when password auth is enabled.
  • Kernel hardening — randomize_va_space, tcp_syncookies, rp_filter, redirects, source routing.
  • Disk — root and /var/log near-full conditions.
  • Recent admin changes — cron entries and systemd units modified in the last 7 days (worth a manual eyeball).

Severities MEDIUM and LOW are recorded but never alert. See them with --full.

Install

On each Ubuntu server, as root:

curl -sSL https://raw.githubusercontent.com/sdkfuyr/sec-check/main/install.sh | sudo bash

The installer will:

  1. Install missing dependencies (python3, iproute2, procps, ufw).
  2. Drop check.py into /opt/sec-check/.
  3. Prompt for your Telegram bot token and chat ID, send a test message.
  4. Prompt for cron frequency (hourly / 6h / 12h / daily).
  5. Write /etc/cron.d/sec-check and run one dry-run pass.

Re-running the installer is safe — it detects an existing install and lets you update the config, refresh the script only, or do a full reinstall.

Non-interactive install (fleet automation)

Any prompt can be pre-answered via environment variables. Useful when provisioning many servers with Ansible/SaltStack/cloud-init:

Variable Purpose
SEC_CHECK_TG_TOKEN Telegram bot token
SEC_CHECK_TG_CHAT Telegram chat ID
SEC_CHECK_CRON_CHOICE 1=hourly, 2=6h, 3=12h, 4=daily
SEC_CHECK_SKIP_TELEGRAM_TEST 1 to skip the post-config test send
SEC_CHECK_MODE Reinstall choice (1-4) when an existing install is detected
SEC_CHECK_TG_TOKEN="..." \
SEC_CHECK_TG_CHAT="..." \
SEC_CHECK_CRON_CHOICE=2 \
curl -sSL https://raw.githubusercontent.com/sdkfuyr/sec-check/main/install.sh \
  | sudo -E bash

Telegram bot setup

  1. In Telegram, open a chat with @BotFather → /newbot → choose a name and username → copy the API token.
  2. Send any message to your new bot.
  3. Open https://api.telegram.org/bot<TOKEN>/getUpdates in a browser and copy the numeric "chat":{"id":...} value.

The installer prompts for both values.

Files on disk

Path Purpose Mode
/opt/sec-check/check.py Audit script 0750
/etc/sec-check.env Telegram credentials + allowlist 0600
/var/lib/sec-check/state.json Last-alert dedupe state 0600
/etc/cron.d/sec-check Cron entry 0644

Usage

sudo /opt/sec-check/check.py --dry-run        # print findings, do not send
sudo /opt/sec-check/check.py --full           # include MEDIUM/LOW
sudo /opt/sec-check/check.py --test-telegram  # send a test message
sudo /opt/sec-check/check.py --force-alert    # send even if nothing changed
sudo /opt/sec-check/check.py                  # normal cron-mode run

In cron-mode the script alerts only when at least one CRITICAL or HIGH finding exists, and only re-alerts if the finding set changed or 24h have passed since the last alert.

Tuning the allowlist

Edit /etc/sec-check.env:

SEC_CHECK_ALLOWED_PORTS=22,80,443,8080

Public listeners on listed ports stop generating HIGH findings. Sensitive services (databases, message queues, etc.) are still CRITICAL regardless of the allowlist — there's no legitimate reason to expose those.

Uninstall

sudo bash /opt/sec-check/uninstall.sh           # remove everything
sudo bash /opt/sec-check/uninstall.sh --keep-config  # keep /etc/sec-check.env

(Or fetch uninstall.sh from the repo if you no longer have a local copy.)

What it intentionally does NOT do

  • No remote scanning, no SSH from your laptop — each server checks itself.
  • No web/TLS/database deep checks.
  • No Docker container scanning.
  • No Hetzner Cloud API calls (so no API token needed).
  • No remediation. Findings only.

These were all explicitly out of scope for the first version. Adding any of them is a check_* function in check.py.

Testing locally before deploying

A Docker harness lives in test/. See test/README.md.

cd test
./run.sh              # smoke test on clean Ubuntu 22.04
./run.sh --vulnerable # second pass on an intentionally misconfigured image
./run.sh --systemd    # systemd-enabled mode for service-state checks

Local install (without curl)

If you've cloned this repo to the target server:

sudo ./install.sh

The installer detects a local check.py next to itself and copies it directly, skipping the curl download.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages