# -*- coding: utf-8 -*- import paramiko c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) def run(cmd, timeout=120): _, o, e = c.exec_command(cmd, timeout=timeout) return (o.read().decode("utf-8", "replace") + e.read().decode("utf-8", "replace")).strip() PASSWORD = "Xiao4669805@" USER = "hackrobot" bcrypt_hash = run(f"python3 -c \"import bcrypt; print(bcrypt.hashpw(b'{PASSWORD}', bcrypt.gensalt(rounds=10)).decode())\"") bcrypt_hash = bcrypt_hash.strip().splitlines()[-1] cmds = [ 'docker exec umami-db-1 psql -U umami -d umami -c "\\d user" 2>&1', 'docker exec umami-db-1 psql -U umami -d umami -c "SELECT * FROM \\\"user\\\" LIMIT 1;" 2>&1', f"""docker exec umami-db-1 psql -U umami -d umami -c "UPDATE \\\"user\\\" SET username='{USER}', password='{bcrypt_hash}' WHERE username='admin';" 2>&1""", f"""docker exec umami-db-1 psql -U umami -d umami -c "UPDATE \\\"user\\\" SET username='{USER}', password='{bcrypt_hash}' WHERE username='{USER}';" 2>&1""", 'docker exec umami-db-1 psql -U umami -d umami -c "SELECT username, role FROM \\\"user\\\";" 2>&1', "systemctl start hackrobot-pb; sleep 2; systemctl is-active hackrobot-pb hackrobot-web 2>&1", ] for cmd in cmds: print("===", cmd[:100]) print(run(cmd)) print() c.close()