Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
39 lines
2.9 KiB
Python
39 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Full security audit of production server (read-mostly)."""
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
|
|
|
|
def run(title, cmd, timeout=120):
|
|
print(f"\n===== {title} =====")
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-12000:] if len(out) > 12000 else out)
|
|
return out
|
|
|
|
|
|
run("OS / uptime", "uname -a; cat /etc/os-release | head -6; uptime; who -a | head")
|
|
run("Listening ports", "ss -lntp | head -80")
|
|
run("Firewall status", "command -v ufw >/dev/null && ufw status verbose || echo 'no ufw'; command -v iptables >/dev/null && iptables -L -n | head -40; command -v nft >/dev/null && nft list ruleset 2>/dev/null | head -40")
|
|
run("fail2ban / crowdsec", "systemctl is-active fail2ban 2>/dev/null; systemctl is-active crowdsec 2>/dev/null; dpkg -l | grep -iE 'fail2ban|crowdsec|rkhunter|chkrootkit|clamav|lynis|unattended' || true")
|
|
run("SSH config", "grep -E '^(PermitRootLogin|PasswordAuthentication|PubkeyAuthentication|Port|AllowUsers|MaxAuthTries|PermitEmpty)' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* 2>/dev/null")
|
|
run("Users with shell / sudo", "getent passwd | awk -F: '$7 !~ /(nologin|false)/ {print}'; echo '---'; getent group sudo admin wheel 2>/dev/null; last -n 15")
|
|
run("Cron / timers", "crontab -l 2>/dev/null; ls -la /etc/cron.* /var/spool/cron/crontabs 2>/dev/null | head -40; systemctl list-timers --all | head -25")
|
|
run("Suspicious processes", "ps auxf --sort=-%cpu | head -40; echo '---'; ps aux | grep -iE 'miner|xmr|kdevtmp|kinsing|crypto|pastebin|curl.*\\|.*sh' | grep -v grep || echo none")
|
|
run("Malware HTML inject remnants", r"grep -RIn --binary-files=text -E '0xE75744C53eC0914fE9bE92847019D3d7122B6b77|data:text/javascript;base64|data-seed-prebsc|rpc exhausted|uint8ArrayToHexString' /opt/douyinWEB /etc/caddy /var/www /tmp 2>/dev/null | head -30 || echo clean")
|
|
run("World-writable / tmp scripts", "find /tmp /var/tmp /dev/shm -type f -mtime -14 2>/dev/null | head -40; ls -la /tmp | head -30")
|
|
run("Recent modified web files", "find /opt/douyinWEB/frontend/src /opt/douyinWEB/backend/app /etc/caddy -type f -mtime -7 2>/dev/null | head -40")
|
|
run("Auth log failures", "journalctl -u ssh -n 40 --no-pager 2>/dev/null | tail -40; echo '---'; grep -i 'Failed password\\|Invalid user' /var/log/auth.log 2>/dev/null | tail -20")
|
|
run("Caddy / Next / API health", "systemctl is-active caddy douyinweb-web douyinweb-api; curl -sSI https://dylive.nomadro.com/login | tr -d '\\r' | grep -iE 'HTTP/|content-security|via|x-frame'")
|
|
run("Disk / updates", "df -h | head -15; apt-get -s upgrade 2>/dev/null | grep -E '^Inst |^The following' | head -30 || true")
|
|
|
|
c.close()
|
|
print("\nAUDIT DONE")
|