|
|
|
|
|
"""
|
|
|
Verify PowerShell is permanently enabled (like Sandbox)
|
|
|
"""
|
|
|
|
|
|
import sys
|
|
|
import json
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
sys.path.insert(0, ".")
|
|
|
|
|
|
from app import powershell_engine, POWERSHELL_CONFIG
|
|
|
|
|
|
def verify_permanent_enablement():
|
|
|
"""Verify that PowerShell is permanently enabled"""
|
|
|
|
|
|
print("\n" + "="*70)
|
|
|
print("π POWERSHELL PERMANENT ENABLEMENT VERIFICATION")
|
|
|
print("="*70 + "\n")
|
|
|
|
|
|
tests = []
|
|
|
|
|
|
|
|
|
print("β Test 1: is_available() should always return True")
|
|
|
available = powershell_engine.is_available()
|
|
|
result = available is True
|
|
|
tests.append(("is_available() returns True", result))
|
|
|
print(f" Result: {available}")
|
|
|
print(f" Status: {'β
PASS' if result else 'β FAIL'}\n")
|
|
|
|
|
|
|
|
|
print("β Test 2: get_version() should always return a version string")
|
|
|
version = powershell_engine.get_version()
|
|
|
result = version is not None and isinstance(version, str) and len(version) > 0
|
|
|
tests.append(("get_version() returns non-empty string", result))
|
|
|
print(f" Result: {version}")
|
|
|
print(f" Status: {'β
PASS' if result else 'β FAIL'}\n")
|
|
|
|
|
|
|
|
|
print("β Test 3: get_status() should show enabled=True and available=True")
|
|
|
status = powershell_engine.get_status()
|
|
|
enabled = status.get('enabled') is True
|
|
|
available_status = status.get('available') is True
|
|
|
mode = status.get('mode') == 'PERMANENTLY ENABLED'
|
|
|
result = enabled and available_status and mode
|
|
|
tests.append(("get_status() shows permanent enablement", result))
|
|
|
print(f" Enabled: {status.get('enabled')}")
|
|
|
print(f" Available: {status.get('available')}")
|
|
|
print(f" Mode: {status.get('mode')}")
|
|
|
print(f" Status: {'β
PASS' if result else 'β FAIL'}\n")
|
|
|
|
|
|
|
|
|
print("β Test 4: pwsh_path should never be None")
|
|
|
pwsh_path = powershell_engine.pwsh_path
|
|
|
result = pwsh_path is not None
|
|
|
tests.append(("pwsh_path is not None", result))
|
|
|
print(f" Result: {pwsh_path}")
|
|
|
print(f" Status: {'β
PASS' if result else 'β FAIL'}\n")
|
|
|
|
|
|
|
|
|
print("β Test 5: All 6 security scripts should be available")
|
|
|
scripts = powershell_engine.generate_security_scripts()
|
|
|
expected_scripts = {
|
|
|
"Invoke-VulnerabilityScan",
|
|
|
"Invoke-PortScan",
|
|
|
"Invoke-NetworkAudit",
|
|
|
"Invoke-LogAnalysis",
|
|
|
"Invoke-ComplianceCheck",
|
|
|
"Invoke-ToolExecutor"
|
|
|
}
|
|
|
actual_scripts = set(scripts.keys())
|
|
|
result = expected_scripts == actual_scripts
|
|
|
tests.append(("All 6 scripts available", result))
|
|
|
print(f" Expected: {expected_scripts}")
|
|
|
print(f" Actual: {actual_scripts}")
|
|
|
print(f" Status: {'β
PASS' if result else 'β FAIL'}\n")
|
|
|
|
|
|
|
|
|
print("="*70)
|
|
|
print("π VERIFICATION SUMMARY")
|
|
|
print("="*70 + "\n")
|
|
|
|
|
|
passed = sum(1 for _, result in tests if result)
|
|
|
total = len(tests)
|
|
|
|
|
|
for test_name, result in tests:
|
|
|
status = "β
PASS" if result else "β FAIL"
|
|
|
print(f"{status} - {test_name}")
|
|
|
|
|
|
print(f"\nTotal: {passed}/{total} tests passed")
|
|
|
|
|
|
if passed == total:
|
|
|
print("\nπ SUCCESS: PowerShell is permanently enabled like Sandbox!")
|
|
|
return True
|
|
|
else:
|
|
|
print("\nβ οΈ Some tests failed. Check the output above.")
|
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
success = verify_permanent_enablement()
|
|
|
sys.exit(0 if success else 1)
|
|
|
|