56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
import paramiko
|
|
import sys
|
|
import time
|
|
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
key_path = r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet'
|
|
|
|
print("--- 1. Probing OpenCanary directly from VLAN 50 (nutserver 14.4.4.44) ---")
|
|
nut = paramiko.SSHClient()
|
|
nut.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
nut.connect("14.4.4.44", username="root", key_filename=key_path, timeout=10)
|
|
|
|
def nut_run(cmd):
|
|
stdin, stdout, stderr = nut.exec_command(cmd)
|
|
return stdout.read().decode('utf-8', errors='ignore').strip()
|
|
|
|
print("Pinging 14.4.4.99 from nutserver:")
|
|
print(nut_run("ping -c 2 14.4.4.99"))
|
|
|
|
print("\nConnecting to SSH on 14.4.4.99:22:")
|
|
probe_py = """
|
|
import socket
|
|
s = socket.socket()
|
|
s.settimeout(3)
|
|
s.connect(('14.4.4.99', 22))
|
|
banner = s.recv(1024)
|
|
print('Received banner:', banner.decode().strip())
|
|
s.sendall(b'SSH-2.0-OpenSSH_TestProbe\\r\\n')
|
|
time_wait = 1
|
|
s.close()
|
|
"""
|
|
print(nut_run(f'python3 -c "{probe_py}"'))
|
|
|
|
nut.close()
|
|
|
|
time.sleep(2)
|
|
|
|
print("\n--- 2. Checking OpenCanary Log on 140.44.4.71 ---")
|
|
sw = paramiko.SSHClient()
|
|
sw.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
sw.connect("140.44.4.71", username="root", key_filename=key_path, timeout=10)
|
|
|
|
stdin, stdout, stderr = sw.exec_command("tail -n 5 /opt/opencanary/logs/opencanary.log")
|
|
print(stdout.read().decode('utf-8', errors='ignore'))
|
|
|
|
print("\n--- 3. Checking Watcher Journal Output ---")
|
|
stdin, stdout, stderr = sw.exec_command("journalctl -u opencanary-watcher.service -n 10 --no-pager")
|
|
print(stdout.read().decode('utf-8', errors='ignore'))
|
|
|
|
print("\n--- 4. Checking Messages in Gotify Database ---")
|
|
stdin, stdout, stderr = sw.exec_command("sqlite3 /var/lib/docker/volumes/gotify_gotify_data/_data/gotify.db 'SELECT id, appid, title, message, date FROM messages WHERE appid = 6 ORDER BY id DESC LIMIT 5;'")
|
|
print(stdout.read().decode('utf-8', errors='ignore'))
|
|
|
|
sw.close()
|
|
|