96 lines
3.1 KiB
Python
96 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Check physical auth credentials / env without printing secrets."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
REMOTE = r'''
|
|
import os, sys
|
|
os.chdir("/opt/douyinWEB/backend")
|
|
sys.path.insert(0, ".")
|
|
from app.settings import settings
|
|
from app import session_auth
|
|
print("auth_enabled", settings.auth_enabled)
|
|
print("admin_user", repr(settings.admin_username))
|
|
pw = str(settings.admin_password or "")
|
|
print("admin_pass_len", len(pw), "prefix", pw[:3] if pw else "", "suffix", pw[-2:] if len(pw)>=2 else "")
|
|
print("session_secret_len", len(str(settings.session_secret or "")))
|
|
print("secret_prefix", str(settings.session_secret or "")[:8])
|
|
|
|
# try verify common passwords without printing them
|
|
cands = [
|
|
"Xiao4669805@",
|
|
"Xiao4669805",
|
|
"4669805",
|
|
"Xiao4669805@!",
|
|
os.environ.get("DY_ADMIN_PASSWORD",""),
|
|
]
|
|
# also from systemd
|
|
import subprocess
|
|
out = subprocess.getoutput("systemctl show douyinweb-api -p Environment --no-pager")
|
|
# parse DY_ADMIN_*
|
|
env = {}
|
|
for part in out.replace("Environment=","").split(" "):
|
|
if "=" in part and part.startswith("DY_"):
|
|
k,v = part.split("=",1)
|
|
env[k]=v
|
|
print("systemd_admin_user", env.get("DY_ADMIN_USERNAME"))
|
|
spw = env.get("DY_ADMIN_PASSWORD","")
|
|
print("systemd_pass_len", len(spw), "prefix", spw[:3] if spw else "", "suffix", spw[-2:] if len(spw)>=2 else "")
|
|
print("settings_matches_systemd_user", settings.admin_username == env.get("DY_ADMIN_USERNAME"))
|
|
print("settings_matches_systemd_pass", pw == spw)
|
|
|
|
# How login checks
|
|
import inspect
|
|
from app import main
|
|
# find login handler source quickly
|
|
import app.session_auth as sa
|
|
print("has_verify", hasattr(sa, "verify_password"))
|
|
# probe auth users table?
|
|
try:
|
|
from app import db
|
|
print("db_ok")
|
|
except Exception as e:
|
|
print("db", e)
|
|
|
|
# check PB or local users
|
|
try:
|
|
from app.auth import verify_login
|
|
print("verify_login", verify_login)
|
|
except Exception as e:
|
|
print("no verify_login", e)
|
|
|
|
# try login function used by API
|
|
import urllib.request, json
|
|
for user, password in [("hackrobot", "Xiao4669805@"), ("hackrobot", spw), ("admin", "Xiao4669805@")]:
|
|
if not password: continue
|
|
req=urllib.request.Request("http://127.0.0.1:8014/api/auth/login", data=json.dumps({"username":user,"password":password}).encode(), headers={"Content-Type":"application/json"}, method="POST")
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=10) as r:
|
|
print("login_ok", user, "pass_len", len(password), r.read()[:80])
|
|
except Exception as e:
|
|
code=getattr(e,"code",None)
|
|
body=""
|
|
try: body=e.read()[:80]
|
|
except Exception: pass
|
|
print("login_fail", user, "pass_len", len(password), code, body)
|
|
'''
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_auth_check.py", "w") as f:
|
|
f.write(REMOTE)
|
|
sftp.close()
|
|
_, o, e = c.exec_command(
|
|
"echo '4669805' | sudo -S -p '' /opt/douyinWEB/backend/.venv/bin/python /tmp/_auth_check.py",
|
|
timeout=60,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|