-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.py
More file actions
63 lines (50 loc) · 1.59 KB
/
Copy pathdecrypt.py
File metadata and controls
63 lines (50 loc) · 1.59 KB
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
#!/usr/bin/env python3
import sys
import hashlib
import requests
from cryptography.fernet import Fernet
import getpass
import os
# --- Ask password once ---
password = getpass.getpass("Enter password: ")
hash_pass = hashlib.sha256(password.encode()).hexdigest()
seed_url = "http://localhost/banana/index.php"
url = f"{seed_url}?hash={hash_pass}now"
response = requests.get(url)
if response.status_code != 200 or len(response.text.strip()) != 44:
print("Wrong password or failed to get key.", file=sys.stderr)
sys.exit(1)
key1 = response.text.strip().encode()
fernet = Fernet(key1)
files_to_decrypt = sys.argv[1:]
if not files_to_decrypt:
print("No files specified.", file=sys.stderr)
sys.exit(1)
def should_skip(file_path):
try:
with open(file_path, "r", errors="ignore") as f:
for line in f:
if "GNOENCRYPT" in line:
return True
except:
return False
return False
for file_path in files_to_decrypt:
if should_skip(file_path):
print(f"SKIPPED:{file_path}")
continue
try:
with open(file_path, "rb") as f:
encrypted_data = f.read()
decrypted_data = fernet.decrypt(encrypted_data)
if file_path.endswith(".enc"):
output_file = file_path[:-4]
else:
output_file = f"{file_path}.decrypted"
with open(output_file, "wb") as f:
f.write(decrypted_data)
os.remove(file_path)
print(f"DECRYPTED:{file_path}")
except Exception as e:
print(f"FAILED:{file_path}:{e}", file=sys.stderr)
sys.exit(0)