import os
import subprocess
import sys
import platform
def invalidate_session_cookies(domain):
"""
Invalidates session cookies for a given domain using browser-specific commands.
Handles different operating systems and browser types.
"""
os_name = platform.system()
if os_name == "Windows":
# Example for Chrome on Windows - Requires Chrome to be installed and in PATH
try:
subprocess.run([
"cmd", "/c",
f"powershell -Command \"Get-ItemProperty 'HKCU:\\Software\\Google\\Chrome\\User Data\\Default\\Cookies' | Select-Object -ExpandProperty Data | Where-Object {$_.Host -eq '{domain}'} | ForEach-Object {Remove-Item $_}\"",
], check=True, capture_output=True)
print(f"Successfully invalidated session cookies for {domain} (Chrome on Windows)")
except subprocess.CalledProcessError as e:
print(f"Error invalidating cookies (Chrome on Windows): {e.stderr.decode()}")
print("Ensure Chrome is installed and accessible in your PATH.")
elif os_name == "Darwin": # macOS
# Example for Safari on macOS - Requires Safari to be installed
try:
subprocess.run([
"osascript",
"-e",
f'do shell script "rm -f ~/Library/Caches/com.apple.Safari/Cookies/Main/www.{domain}.cookies"',
], check=True, capture_output=True)
print(f"Successfully invalidated session cookies for {domain} (Safari on macOS)")
except subprocess.CalledProcessError as e:
print(f"Error invalidating cookies (Safari on macOS): {e.stderr.decode()}")
print("Ensure Safari is installed.")
elif os_name == "Linux":
# Example for Firefox on Linux - Requires Firefox to be installed
try:
subprocess.run([
"firefox",
"-profilemanager",
"-a",
"remove",
f"session-store.js$,{domain}",
], check=True, capture_output=True)
print(f"Successfully invalidated session cookies for {domain} (Firefox on Linux)")
except subprocess.CalledProcessError as e:
print(f"Error invalidating cookies (Firefox on Linux): {e.stderr.decode()}")
print("Ensure Firefox is installed and accessible in your PATH.")
else:
print(f"Unsupported operating system: {os_name}")
print("Cannot invalidate session cookies.")
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: python script.py <domain>")
sys.exit(1)
domain_to_invalidate = sys.argv[1]
invalidate_session_cookies(domain_to_invalidate)
Add your comment