-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgocryptfs-deobfuscate.py
executable file
·68 lines (55 loc) · 1.74 KB
/
gocryptfs-deobfuscate.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
#!/usr/bin/python3
import argparse
import socket
import json
import sys
import re
import os
parser = argparse.ArgumentParser(description="Deobfuscate program output by decrypting filenames")
parser.add_argument('ctlsock', help="Path to the control socket")
args = parser.parse_args()
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(args.ctlsock)
regex = re.compile("(?<!\\w)" +
"([A-Za-z0-9-_]{22,}/|gocryptfs\\.longname\\.[A-Za-z0-9-_]{43}/)*" +
"([A-Za-z0-9-_]{22,}|" +
"gocryptfs\\.longname\\.[A-Za-z0-9-_]{43}(\\.name)?|" +
"gocryptfs\\.(diriv|conf))" +
"(?!\\w)")
def decrypt_path(match):
path = match.group(0)
if path.endswith("gocryptfs.conf"):
path = path[:-14]
suffix = "<gocryptfs.conf>"
elif path.endswith("gocryptfs.diriv"):
path = path[:-15]
suffix = "<gocryptfs.diriv>"
elif path.endswith(".name"):
path = path[:-5]
suffix = "<name>"
else:
suffix = None
if len(path) != 0:
if path.endswith("/"):
path = path[:-1]
sock.sendall(json.dumps({'DecryptPath': path}).encode("utf-8"))
try:
response = json.loads(sock.recv(8192).decode("utf-8"))
except json.JSONDecodeError:
return match.group(0)
if response['ErrNo'] != 0:
return match.group(0)
path = response['Result']
if suffix is not None:
path = os.path.join(path, suffix)
return path
while True:
try:
line = sys.stdin.readline()
except KeyboardInterrupt:
break
if line == "":
break
line = regex.sub(decrypt_path, line)
sys.stdout.write(line)
sock.close()