-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevilnovnc2cookieeditor.py
executable file
·102 lines (85 loc) · 2.94 KB
/
evilnovnc2cookieeditor.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
#!/usr/bin/env python3
import argparse
import datetime
import json
import sys
from typing import Any, Dict, List
def parse_input(data: str) -> List[Dict[str, Any]]:
if not data.strip():
sys.exit("No input data provided.")
separator = "=" * 62
blocks = data.strip().split(separator)
cookies = []
for block in blocks:
lines = block.strip().split("\n")
if not lines:
continue
cookie: Dict[str, Any] = {}
for line in lines:
if not line.strip():
continue
if ": " in line:
key, value = line.split(": ", 1)
key = key.strip()
value = value.strip()
if key == "Host":
cookie["domain"] = value
elif key == "Cookie name":
cookie["name"] = value
elif key == "Cookie value (decrypted)":
cookie["value"] = value
elif key == "Expires datetime (UTC)":
if value:
try:
dt = datetime.datetime.strptime(
value, "%Y-%m-%d %H:%M:%S.%f"
)
except ValueError:
try:
dt = datetime.datetime.strptime(
value, "%Y-%m-%d %H:%M:%S"
)
except ValueError:
dt = None
if dt:
cookie["expirationDate"] = dt.timestamp()
else:
cookie["session"] = True
else:
continue
domain = cookie.get("domain", "")
cookie["hostOnly"] = not domain.startswith(".")
cookie["path"] = "/"
cookie["secure"] = False
cookie["httpOnly"] = False
cookie["sameSite"] = None
cookie["storeId"] = None
cookie["session"] = cookie.get("session", False)
if "expirationDate" not in cookie:
cookie["session"] = True
cookies.append(cookie)
return cookies
def main():
parser = argparse.ArgumentParser(description="Convert cookie data to JSON format.")
parser.add_argument(
"-i",
"--input",
type=argparse.FileType("r", encoding="utf-8"),
default=sys.stdin,
help="Input file (default: stdin)",
)
parser.add_argument(
"-o",
"--output",
type=argparse.FileType("w", encoding="utf-8"),
default=sys.stdout,
help="Output file (default: stdout)",
)
args = parser.parse_args()
input_data = args.input.read()
if not input_data.strip():
sys.exit("No input data provided.")
cookies = parse_input(input_data)
json.dump(cookies, args.output, ensure_ascii=False, indent=4)
if __name__ == "__main__":
main()