96 lines
3.1 KiB
Python
96 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test WinRM with Negotiate authentication (instead of Basic)
|
|
"""
|
|
|
|
import os
|
|
from winrm import Session
|
|
|
|
|
|
def test_negotiate_auth():
|
|
host = os.getenv('HOST', '192.168.88.108')
|
|
username = os.getenv('USER_NAME', 'Admin')
|
|
password = os.getenv('PASS', 'P@ssw0rd!')
|
|
|
|
print(f"Testing WinRM with Negotiate authentication to {host}")
|
|
|
|
try:
|
|
# Try with negotiate/ntlm transport
|
|
session = Session(
|
|
f'http://{host}:5985/wsman',
|
|
auth=(username, password),
|
|
transport='ntlm' # Use NTLM instead of plaintext
|
|
)
|
|
|
|
print("✅ Session created with NTLM transport")
|
|
|
|
# Test simple command
|
|
result = session.run_cmd('echo "NTLM test successful"')
|
|
|
|
if result.status_code == 0:
|
|
print(f"✅ Command successful: {result.std_out.decode().strip()}")
|
|
return True
|
|
else:
|
|
print(f"❌ Command failed: {result.std_err.decode()}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ NTLM authentication failed: {e}")
|
|
|
|
# Try with ssl transport (even though we're using HTTP)
|
|
try:
|
|
print("Trying with SSL transport (ignore cert validation)...")
|
|
session = Session(
|
|
f'http://{host}:5985/wsman',
|
|
auth=(username, password),
|
|
transport='ssl',
|
|
server_cert_validation='ignore'
|
|
)
|
|
|
|
print("✅ Session created with SSL transport")
|
|
|
|
result = session.run_cmd('echo "SSL transport test"')
|
|
|
|
if result.status_code == 0:
|
|
print(f"✅ Command successful: {result.std_out.decode().strip()}")
|
|
return True
|
|
else:
|
|
print(f"❌ Command failed: {result.std_err.decode()}")
|
|
return False
|
|
|
|
except Exception as e2:
|
|
print(f"❌ SSL transport also failed: {e2}")
|
|
|
|
# Try with kerberos if available
|
|
try:
|
|
print("Trying with Kerberos transport...")
|
|
session = Session(
|
|
f'http://{host}:5985/wsman',
|
|
auth=(username, password),
|
|
transport='kerberos'
|
|
)
|
|
|
|
print("✅ Session created with Kerberos transport")
|
|
|
|
result = session.run_cmd('echo "Kerberos test"')
|
|
|
|
if result.status_code == 0:
|
|
print(f"✅ Command successful: {result.std_out.decode().strip()}")
|
|
return True
|
|
else:
|
|
print(f"❌ Command failed: {result.std_err.decode()}")
|
|
return False
|
|
|
|
except Exception as e3:
|
|
print(f"❌ Kerberos transport failed: {e3}")
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = test_negotiate_auth()
|
|
if success:
|
|
print("\n🎉 Alternative authentication method works!")
|
|
else:
|
|
print("\n❌ All authentication methods failed")
|
|
print("\nThis suggests the issue is with AllowUnencrypted=false")
|
|
print("We may need to force this setting or use HTTPS instead") |