-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHadesCloak.py
executable file
·260 lines (218 loc) · 10.6 KB
/
HadesCloak.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/env python3
import os
import platform
import subprocess
import getpass
import time
import sys
import hashlib
import secrets
import configparser
from pathlib import Path
DEBUG = True
def debug_print(*args, **kwargs):
if DEBUG:
print("DEBUG:", *args, file=sys.stderr, **kwargs)
def run_command(command, shell=False, sudo=False):
try:
if sudo and os.geteuid() != 0:
command = ['sudo'] + command
debug_print(f"Executing command: {command}")
result = subprocess.run(command, capture_output=True, text=True, shell=shell, check=True)
debug_print(f"Result: {result.stdout.strip()}")
return result.stdout.strip()
except subprocess.CalledProcessError as e:
debug_print(f"Error executing command: {e}")
return None
def check_status():
status = {'microphone': False, 'webcam': False}
system = platform.system()
debug_print(f"Detected operating system: {system}")
if system == 'Darwin': # macOS
webcam_status = run_command(['system_profiler', 'SPCameraDataType'])
status['webcam'] = 'FaceTime' in webcam_status if webcam_status else False
mic_status = run_command(['system_profiler', 'SPAudioDataType'])
status['microphone'] = 'Microphone' in mic_status if mic_status else False
elif system == 'Linux':
webcam_status = run_command(['lsmod | grep uvcvideo'], shell=True)
status['webcam'] = bool(webcam_status)
mic_status = run_command(['arecord', '-l'])
status['microphone'] = 'card' in mic_status if mic_status else False
elif system == 'Windows':
webcam_status = run_command(['powershell', "Get-PnpDevice | Where-Object {$_.Class -eq 'Image'} | Where-Object {$_.Status -eq 'OK'}"])
status['webcam'] = bool(webcam_status)
mic_status = run_command(['powershell', "Get-PnpDevice | Where-Object {$_.Class -eq 'AudioEndpoint'} | Where-Object {$_.Status -eq 'OK'}"])
status['microphone'] = bool(mic_status)
debug_print(f"Device status: {status}")
return status
def set_visibility_macos(visible):
action = "load" if visible else "unload"
debug_print(f"Attempting to {action} devices on macOS")
webcam_command = ['launchctl', action, '-w', '/System/Library/LaunchDaemons/com.apple.webcam.plist']
mic_command = ['launchctl', action, '-w', '/System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist']
run_command(webcam_command, sudo=True)
run_command(mic_command, sudo=True)
def set_visibility_linux(visible):
action = "modprobe" if visible else "rmmod"
debug_print(f"Attempting to {action} devices on Linux")
webcam_command = [action, 'uvcvideo']
mic_command = [action, 'snd_usb_audio']
run_command(webcam_command, sudo=True)
run_command(mic_command, sudo=True)
def set_visibility_windows(visible):
action = "Enable" if visible else "Disable"
debug_print(f"Attempting to {action} devices on Windows")
webcam_command = ['powershell', f"Get-PnpDevice | Where-Object {{$_.Class -eq 'Image'}} | {action}-PnpDevice -Confirm:$false"]
mic_command = ['powershell', f"Get-PnpDevice | Where-Object {{$_.Class -eq 'AudioEndpoint'}} | {action}-PnpDevice -Confirm:$false"]
run_command(webcam_command, sudo=True)
run_command(mic_command, sudo=True)
def set_visibility(visible):
system = platform.system()
if system == 'Darwin':
set_visibility_macos(visible)
elif system == 'Linux':
set_visibility_linux(visible)
elif system == 'Windows':
set_visibility_windows(visible)
else:
debug_print(f"Unsupported operating system: {system}")
return False
time.sleep(5)
new_status = check_status()
debug_print(f"New status after change: {new_status}")
return (new_status['webcam'] == visible) and (new_status['microphone'] == visible)
def print_banner():
banner = """
██╗ ██╗ █████╗ ██████╗ ███████╗███████╗ ██████╗██╗ ██████╗ █████╗ ██╗ ██╗
██║ ██║██╔══██╗██╔══██╗██╔════╝██╔════╝ ██╔════╝██║ ██╔═══██╗██╔══██╗██║ ██╔╝
███████║███████║██║ ██║█████╗ ███████╗ ██║ ██║ ██║ ██║███████║█████╔╝
██╔══██║██╔══██║██║ ██║██╔══╝ ╚════██║ ██║ ██║ ██║ ██║██╔══██║██╔═██╗
██║ ██║██║ ██║██████╔╝███████╗███████║ ╚██████╗███████╗╚██████╔╝██║ ██║██║ ██╗
╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚══════╝ ╚═════╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
"""
print(banner)
def get_user_input(prompt):
while True:
try:
debug_print("Waiting for user input")
user_input = input(prompt).strip().lower()
debug_print(f"User input: '{user_input}'")
if user_input in ['y', 'n', 'r']:
return user_input
elif user_input == '':
print("No input provided. Please enter 'Y', 'N', or 'R'.")
else:
print("Invalid response. Please answer with 'Y', 'N', or 'R' to reset the password.")
except (EOFError, KeyboardInterrupt):
print("\nInput interrupted. Press Ctrl+C again to exit or any other key to continue.")
try:
if input().lower() == '':
continue
else:
print("\nExiting the program.")
sys.exit(0)
except (EOFError, KeyboardInterrupt):
print("\nExiting the program.")
sys.exit(0)
def hash_password(password):
salt = secrets.token_bytes(32)
key = hashlib.pbkdf2_hmac('sha256', password.encode('utf-8'), salt, 100000)
return salt + key
def verify_password(stored_password, provided_password):
salt = stored_password[:32]
key = stored_password[32:]
new_key = hashlib.pbkdf2_hmac('sha256', provided_password.encode('utf-8'), salt, 100000)
return key == new_key
def load_or_create_config():
config = configparser.ConfigParser()
config_file = Path.home() / '.hadescloak.ini'
if config_file.exists():
config.read(config_file)
else:
config['Security'] = {'password': ''}
return config, config_file
def save_config(config, config_file):
with open(config_file, 'w') as f:
config.write(f)
def set_password(config, config_file):
while True:
try:
password = getpass.getpass("Set a password for the Helm of Hades: ")
if len(password) < 4:
print("\nThe password must be at least 4 characters long.")
continue
confirm_password = getpass.getpass("Confirm the password: ")
if password != confirm_password:
print("\nThe passwords do not match. Please try again.")
continue
hashed_password = hash_password(password)
config['Security']['password'] = hashed_password.hex()
save_config(config, config_file)
print("\nPassword set successfully.")
break
except Exception as e:
debug_print(f"Error during password setting: {e}")
print(f"An error occurred: {e}. Please try again.")
def main():
print_banner()
if os.geteuid() != 0:
print("This script needs to be run with root privileges.")
print("Please run again with 'sudo python3 HadesCloak.py'")
sys.exit(1)
config, config_file = load_or_create_config()
while True:
if not config['Security']['password']:
print("No password set. Let's set up a new password.")
set_password(config, config_file)
else:
stored_password = bytes.fromhex(config['Security']['password'])
try:
password = getpass.getpass("Enter the password to invoke the power of the Helm of Hades (or 'R' to reset): ")
if password.lower() == 'r':
print("\nResetting password...")
set_password(config, config_file)
continue
if verify_password(stored_password, password):
break
print("Incorrect password. The power of the Helm of Hades remains inaccessible.")
except (EOFError, KeyboardInterrupt):
print("\nPassword entry interrupted. Exiting the program.")
sys.exit(0)
while True:
status = check_status()
if status['microphone'] or status['webcam']:
current_status = "visible to mortals"
else:
current_status = "hidden in the shadows"
print(f"\nYour current status: {current_status}")
answer = get_user_input("\nDo you wish to invoke the power of the Helm of Hades and conceal yourself? (Y/N/R to reset password): ")
if answer == 'y':
print("Invoking the power of the Helm of Hades...")
success = set_visibility(False)
if success:
print("You are now hidden in the shadows, invisible to the eyes and ears of mortals.")
else:
print("Failed to invoke the power of the Helm. Check the status of your devices and try again.")
elif answer == 'n':
print("Removing the Helm of Hades...")
success = set_visibility(True)
if success:
print("You are now visible to mortals.")
else:
print("Failed to remove the Helm. Check the status of your devices and try again.")
elif answer == 'r':
print("Resetting password...")
set_password(config, config_file)
print("\nPress Enter to continue or Ctrl+C to exit.")
try:
input()
except (EOFError, KeyboardInterrupt):
print("\nExiting the program.")
sys.exit(0)
if __name__ == "__main__":
try:
main()
except Exception as e:
debug_print(f"Unexpected error in main: {e}")
print(f"An unexpected error occurred: {e}")
sys.exit(1)