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>
167 lines
6.0 KiB
Python
167 lines
6.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deep forensics: successful logins from 45.134.95.113 and 45.32.89.58."""
|
|
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=180):
|
|
print(f"\n===== {title} =====")
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-14000:] if len(out) > 14000 else out)
|
|
return out
|
|
|
|
|
|
run(
|
|
"FULL SUCCESS TIMELINE both IPs",
|
|
r"""
|
|
grep -E 'Accepted password for root from (45\.134\.95\.113|45\.32\.89\.58)|session (opened|closed) for user root' /var/log/auth.log /var/log/auth.log.1 2>/dev/null | grep -E '45\.134\.95\.113|45\.32\.89\.58|sshd\[' | head -5
|
|
echo '--- all accepts ---'
|
|
grep -E 'Accepted password for root from (45\.134\.95\.113|45\.32\.89\.58)' /var/log/auth.log /var/log/auth.log.1 2>/dev/null
|
|
echo '--- count by day ---'
|
|
grep -E 'Accepted password for root from (45\.134\.95\.113|45\.32\.89\.58)' /var/log/auth.log /var/log/auth.log.1 2>/dev/null | sed 's/.*T\([0-9-]*\).*/\1/' | cut -dT -f1 | sort | uniq -c
|
|
""",
|
|
)
|
|
|
|
run(
|
|
"SESSION windows around 45.134.95.113",
|
|
r"""
|
|
python3 - <<'PY'
|
|
import re, os
|
|
from collections import defaultdict
|
|
ips={"45.134.95.113","45.32.89.58"}
|
|
files=[p for p in ["/var/log/auth.log","/var/log/auth.log.1"] if os.path.exists(p)]
|
|
# parse: Accepted ... from IP -> pid; session opened/closed by same pid
|
|
events=[]
|
|
for f in files:
|
|
with open(f,errors="replace") as fh:
|
|
for line in fh:
|
|
if "sshd[" not in line: continue
|
|
m=re.search(r"sshd\[(\d+)\]: Accepted password for root from ([0-9.]+)", line)
|
|
if m and m.group(2) in ips:
|
|
ts=line.split()[0] if line[0].isdigit() else line[:32]
|
|
# syslog vs iso
|
|
ts=line.split(" root ")[0] if " root " in line else line[:40]
|
|
events.append(("ACCEPT", m.group(1), m.group(2), line.strip()[:200]))
|
|
m=re.search(r"sshd\[(\d+)\]: pam_unix\(sshd:session\): session opened", line)
|
|
if m:
|
|
events.append(("OPEN", m.group(1), "", line.strip()[:180]))
|
|
m=re.search(r"sshd\[(\d+)\]: pam_unix\(sshd:session\): session closed", line)
|
|
if m:
|
|
events.append(("CLOSE", m.group(1), "", line.strip()[:180]))
|
|
# group by pid after accept from target
|
|
target_pids={}
|
|
for e in events:
|
|
if e[0]=="ACCEPT":
|
|
target_pids[e[1]]=e[2]
|
|
print("TARGET_PIDS", len(target_pids))
|
|
# show accept+close pairs
|
|
for e in events:
|
|
if e[0]=="ACCEPT":
|
|
print(e[3])
|
|
elif e[0] in ("OPEN","CLOSE") and e[1] in target_pids:
|
|
print(" ", e[0], "pid", e[1], "ip", target_pids[e[1]], "=>", e[3][-80:])
|
|
PY
|
|
""",
|
|
)
|
|
|
|
run(
|
|
"last / wtmp for these IPs",
|
|
r"""
|
|
last -a | grep -E '45\.134\.95\.113|45\.32\.89\.58' | head -40
|
|
echo '---'
|
|
last -F | grep -E '45\.134\.95\.113|45\.32\.89\.58' | head -40
|
|
""",
|
|
)
|
|
|
|
run(
|
|
"authorized_keys integrity",
|
|
r"""
|
|
ls -la /root/.ssh/
|
|
echo '---authorized_keys---'
|
|
cat /root/.ssh/authorized_keys 2>/dev/null || echo NONE
|
|
echo '---known_hosts count---'
|
|
wc -l /root/.ssh/known_hosts 2>/dev/null
|
|
echo '---any other users keys---'
|
|
find /home /root -name authorized_keys 2>/dev/null -ls
|
|
getent passwd | awk -F: '$3>=1000 || $1=="root" {print}'
|
|
""",
|
|
)
|
|
|
|
run(
|
|
"bash_history around Aug 9-15",
|
|
r"""
|
|
ls -la /root/.bash_history /root/.zsh_history 2>/dev/null
|
|
echo '--- history mtime and size ---'
|
|
stat /root/.bash_history 2>/dev/null
|
|
echo '--- suspicious cmds in history ---'
|
|
grep -nE 'curl |wget |chmod \+x|base64|nc |ncat |socat|/dev/tcp|python -c|perl -e|crontab|authorized_keys|ssh-keygen|useradd|passwd |iptables|ufw|miner|xmrig|kdevtmp|pastebin|raw.githubusercontent|tmp/.*\.sh|\.ssh/' /root/.bash_history 2>/dev/null | tail -80
|
|
echo '--- last 40 history lines ---'
|
|
tail -40 /root/.bash_history 2>/dev/null
|
|
""",
|
|
)
|
|
|
|
run(
|
|
"cron / systemd persistence",
|
|
r"""
|
|
echo 'ROOT CRONTAB'; crontab -l 2>/dev/null
|
|
echo 'CRON.D'; ls -la /etc/cron.d/; for f in /etc/cron.d/*; do echo "== $f =="; cat "$f"; done
|
|
echo 'CRON DAILY odd'; ls -la /etc/cron.daily/
|
|
echo 'SYSTEMD suspicious timers/services (recent)';
|
|
find /etc/systemd/system /lib/systemd/system -name '*.service' -mtime -30 2>/dev/null | head -40
|
|
ls -lt /etc/systemd/system/*.service 2>/dev/null | head -25
|
|
echo '--- rc.local ---'; cat /etc/rc.local 2>/dev/null || echo none
|
|
echo '--- profile.d ---'; ls -la /etc/profile.d/; ls -la /etc/update-motd.d/ | head
|
|
""",
|
|
)
|
|
|
|
run(
|
|
"new/modified files Aug 9-15 in sensitive paths",
|
|
r"""
|
|
echo 'SSH dir'; find /root/.ssh /etc/ssh -type f -newermt '2026-08-09' ! -newermt '2026-08-16' -ls 2>/dev/null
|
|
echo 'etc passwd/shadow/sudoers changes'
|
|
ls -la --time-style=long-iso /etc/passwd /etc/shadow /etc/group /etc/sudoers /etc/sudoers.d/* 2>/dev/null
|
|
echo 'tmp scripts created those days'
|
|
find /tmp /var/tmp /dev/shm -type f -newermt '2026-08-09' ! -newermt '2026-08-16' 2>/dev/null | head -50
|
|
echo 'root home odd executables'
|
|
find /root -maxdepth 3 -type f \( -name '*.sh' -o -name '*.py' -o -perm -111 \) -newermt '2026-08-09' ! -newermt '2026-08-16' 2>/dev/null | head -40
|
|
""",
|
|
)
|
|
|
|
run(
|
|
"listening reverse-shell-ish + odd processes",
|
|
r"""
|
|
ss -lntp | grep -vE 'sshd|caddy|nginx|docker|next-server|python|uvicorn|node|weed|pocketbase|sing-box|frp|nsq|systemd' || echo 'no extra weird listeners beyond known stack'
|
|
echo '--- procs with deleted binaries ---'
|
|
ls -l /proc/*/exe 2>/dev/null | grep '(deleted)' | head -20 || echo none
|
|
echo '--- network established to odd ---'
|
|
ss -tnp state established | awk 'NR==1 || /:22 |:4444|:5555|:6666|:1337|:31337|:8888|:9999/' | head -30
|
|
""",
|
|
)
|
|
|
|
run(
|
|
"compare with known ops IPs activity same period",
|
|
r"""
|
|
echo 'Accepts Aug 9-15 all IPs:'
|
|
grep 'Accepted password for root' /var/log/auth.log.1 2>/dev/null | grep -E '2026-08-0[9]|2026-08-1[0-5]' | awk '{for(i=1;i<=NF;i++) if($i=="from") print $(i+1)}' | sort | uniq -c | sort -nr
|
|
""",
|
|
)
|
|
|
|
c.close()
|
|
print("\nDEEP FORENSICS DONE")
|