Hi, wenn jemand Interesse hat, ich habe hier ein kleines python script:
import urllib.request
import json
import sys
import hashlib
import base64
import time
# --- KONFIGURATION ---
IP = "WECHSELRICHTER_IP"
TARGET_ID = 33556247
# HINWEIS: Wir verwenden das Passwort MIT Unterstrich, da der letzte korrekte Hash dazu passte.
PASS = "DEIN_PASSWORT"
USER = "pvserver"
MODE = 1 # Anlagebetreiber (Passend zur Browser-Rolle)
print("--- KOSTAL HANDSHAKE SKRIPT V6 (Challenge-Response) ---")
# Wert holen
try:
if len(sys.argv) > 1:
target_value = int(float(sys.argv[1]))
else:
print("Fehler: Kein Wert übergeben")
sys.exit(1)
except ValueError:
print("Fehler: Wert ist keine Zahl")
sys.exit(1)
# --- HELFER ---
headers = {
"User-Agent": "Mozilla/5.0",
"Referer": f"http://{IP}/",
"Content-Type": "application/json",
"Accept": "application/json"
}
# --- SCHRITT 1: SALT/CHALLENGE HOLEN (GET api/login.json) ---
url_pre_login = f"http://{IP}/api/login.json"
session_id = 0
salt = ""
print("1. Hole Challenge (Salt)...")
try:
req = urllib.request.Request(url_pre_login, method='GET', headers=headers)
with urllib.request.urlopen(req, timeout=5) as response:
data = json.loads(response.read().decode())
if "session" in data and "sessionId" in data["session"]:
session_id = data["session"]["sessionId"]
salt = data.get("salt", "")
print(f" -> Session erhalten: {session_id}, Salt: {salt[:8]}...")
else:
print(" -> FEHLER: Keine Session ID/Salt bekommen.")
sys.exit(1)
except Exception as e:
print(f"Verbindungsfehler Pre-Login: {e}")
sys.exit(1)
# --- SCHRITT 2: HASH BERECHNEN & ANMELDEN (POST api/login.json) ---
# Hash = SHA1(Passwort-Text + Salt-Text) -> Base64
try:
raw_pass_salt = PASS.encode('utf-8') + salt.encode('utf-8')
sha1_hash = hashlib.sha1(raw_pass_salt).digest()
pwh_base64 = base64.b64encode(sha1_hash).decode('utf-8')
# print(f" -> Berechneter Hash: {pwh_base64}") # Debug
except Exception as e:
print(f"Hash-Berechnung fehlgeschlagen: {e}")
sys.exit(1)
url_login = f"http://{IP}/api/login.json?sessionId={session_id}"
print(f"2. Sende dynamischen Hash...")
login_payload = {
"mode": MODE,
"userId": USER,
"pwh": pwh_base64
}
try:
json_data = json.dumps(login_payload, separators=(',', ':')).encode('utf-8')
req = urllib.request.Request(url_login, data=json_data, method='POST', headers=headers)
with urllib.request.urlopen(req, timeout=5) as response:
data = json.loads(response.read().decode())
role = data.get("session", {}).get("roleId", 0)
status = data.get("status", {}).get("code", -1)
if status == 0 and role > 0:
print(f" -> ERFOLG! Rolle ist jetzt: {role}")
else:
print(f" -> FEHLER: Login abgelehnt. Status {status}, Rolle {role}")
sys.exit(1)
except Exception as e:
print(f"Login Fehler: {e}")
sys.exit(1)
# --- SCHRITT 3: BEFEHL SENDEN ---
url_send = f"http://{IP}/api/dxs.json?sessionId={session_id}"
print(f"3. Sende Wert {target_value}...")
# Payload ist jetzt clean, nur mit der gültigen Session
payload = {
"dxsEntries": [
{"dxsId": 83888896, "value": 2},
{"dxsId": 33556484, "value": True},
{"dxsId": 33556249, "value": 50},
{"dxsId": TARGET_ID, "value": target_value},
{"dxsId": 33556248, "value": False}
],
"session": {
"sessionId": session_id,
"roleId": role
}
}
try:
json_data = json.dumps(payload, separators=(',', ':')).encode('utf-8')
req = urllib.request.Request(url_send, data=json_data, method='POST', headers=headers)
with urllib.request.urlopen(req, timeout=10) as response:
result = json.loads(response.read().decode())
code = result.get("status", {}).get("code")
if code == 0:
print(f"ERFOLG: {target_value}")
else:
print(f"FEHLER Code: {code}")
sys.exit(1)
except Exception as e:
print(f"Senden Fehler: {e}")
sys.exit(1)