Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mxrch
GitHub Repository: mxrch/GHunt
Path: blob/master/ghunt/objects/base.py
252 views
1
from typing import *
2
from pathlib import Path
3
import json
4
from dateutil.relativedelta import relativedelta
5
from datetime import datetime
6
import base64
7
8
from autoslot import Slots
9
import httpx
10
11
from ghunt.errors import GHuntInvalidSession
12
13
14
# class SmartObj(Slots): # Not Python 3.13 compatible so FUCK it fr fr
15
# pass
16
17
class SmartObj():
18
pass
19
20
class AndroidCreds(SmartObj):
21
def __init__(self) -> None:
22
self.master_token: str = ""
23
self.authorization_tokens: Dict = {}
24
25
class GHuntCreds(SmartObj):
26
"""
27
This object stores all the needed credentials that GHunt uses,
28
such as cookies, OSIDs, keys and tokens.
29
"""
30
31
def __init__(self, creds_path: str = "") -> None:
32
self.cookies: Dict[str, str] = {}
33
self.osids: Dict[str, str] = {}
34
self.android: AndroidCreds = AndroidCreds()
35
36
if not creds_path:
37
cwd_path = Path().home()
38
ghunt_folder = cwd_path / ".malfrats/ghunt"
39
if not ghunt_folder.is_dir():
40
ghunt_folder.mkdir(parents=True, exist_ok=True)
41
creds_path = ghunt_folder / "creds.m"
42
self.creds_path: str = creds_path
43
44
def are_creds_loaded(self) -> bool:
45
return all([self.cookies, self.osids, self.android.master_token])
46
47
def load_creds(self, silent=False) -> None:
48
"""Loads cookies, OSIDs and tokens if they exist"""
49
if Path(self.creds_path).is_file():
50
try:
51
with open(self.creds_path, "r", encoding="utf-8") as f:
52
raw = f.read()
53
data = json.loads(base64.b64decode(raw).decode())
54
55
self.cookies = data["cookies"]
56
self.osids = data["osids"]
57
58
self.android.master_token = data["android"]["master_token"]
59
self.android.authorization_tokens = data["android"]["authorization_tokens"]
60
61
except Exception:
62
raise GHuntInvalidSession("Stored session is corrupted.")
63
else:
64
raise GHuntInvalidSession("No stored session found.")
65
66
if not self.are_creds_loaded():
67
raise GHuntInvalidSession("Stored session is incomplete.")
68
if not silent:
69
print("[+] Stored session loaded !")
70
71
def save_creds(self, silent=False):
72
"""Save cookies, OSIDs and tokens to the specified file."""
73
data = {
74
"cookies": self.cookies,
75
"osids": self.osids,
76
"android": {
77
"master_token": self.android.master_token,
78
"authorization_tokens": self.android.authorization_tokens
79
}
80
}
81
82
with open(self.creds_path, "w", encoding="utf-8") as f:
83
f.write(base64.b64encode(json.dumps(data, indent=2).encode()).decode())
84
85
if not silent:
86
print(f"\n[+] Creds have been saved in {self.creds_path} !")
87
88
### Maps
89
90
class Position(SmartObj):
91
def __init__(self):
92
self.latitude: float = 0.0
93
self.longitude: float = 0.0
94
95
class MapsLocation(SmartObj):
96
def __init__(self):
97
self.id: str = ""
98
self.name: str = ""
99
self.address: str = ""
100
self.position: Position = Position()
101
self.tags: List[str] = []
102
self.types: List[str] = []
103
self.cost_level: int = 0 # 1-4
104
105
class MapsReview(SmartObj):
106
def __init__(self):
107
self.id: str = ""
108
self.comment: str = ""
109
self.rating: int = 0
110
self.location: MapsLocation = MapsLocation()
111
self.date: datetime = None
112
113
class MapsPhoto(SmartObj):
114
def __init__(self):
115
self.id: str = ""
116
self.url: str = ""
117
self.location: MapsLocation = MapsLocation()
118
self.date: datetime = None
119
120
### Drive
121
class DriveExtractedUser(SmartObj):
122
def __init__(self):
123
self.gaia_id: str = ""
124
self.name: str = ""
125
self.email_address: str = ""
126
self.role: str = ""
127
self.is_last_modifying_user: bool = False
128