-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathTokIntel.py
More file actions
441 lines (349 loc) · 14.6 KB
/
Copy pathTokIntel.py
File metadata and controls
441 lines (349 loc) · 14.6 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
from apify_client import ApifyClient
import io
import contextlib
import argparse
import json
import time
import os
import random
import string
import sys
import warnings
import logging
# Suprimir TODOS los warnings y logs
warnings.filterwarnings('ignore')
os.environ['PYTHONWARNINGS'] = 'ignore'
# Silenciar logs de todas las librerías
logging.getLogger().setLevel(logging.ERROR)
logging.getLogger("apify_client").setLevel(logging.ERROR)
logging.getLogger("apify").setLevel(logging.ERROR)
logging.getLogger("urllib3").setLevel(logging.ERROR)
logging.getLogger("requests").setLevel(logging.ERROR)
logging.getLogger("asyncio").setLevel(logging.ERROR)
from dotenv import load_dotenv
from datetime import datetime, UTC
from colorama import Fore, init, Style
init(autoreset=True)
RETRIES = 3
TIMEOUT = 30
DELAY = 1
# ==============================
# BANNER
# ==============================
def print_banner():
cyan = Fore.CYAN
magenta = Fore.MAGENTA
white = Fore.WHITE
bright = Style.BRIGHT
banner = f"""
{cyan}████████▀▀▀████
{magenta}████████────▀██
{cyan}████████──█▄──█
{magenta}███▀▀▀██──█████
{cyan}█▀──▄▄██──█████
{magenta}█──█████──█████
{cyan}█▄──▀▀▀──▄█████
{magenta}███▄▄▄▄▄███████
{white}{bright}TokIntel - TikTok OSINT Framework
{white}{bright}by Hack Underway 👁
"""
print(banner)
# ==============================
# SPINNER ANIMADO (SIN THREADS)
# ==============================
def animated_spinner(seconds, message="🔍 Escaneando"):
"""Muestra un spinner animado por X segundos"""
spinner_chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
start_time = time.time()
i = 0
while time.time() - start_time < seconds:
elapsed = int(time.time() - start_time)
spinner = spinner_chars[i % len(spinner_chars)]
sys.stdout.write(f'\r{spinner} {message}... ({elapsed}s)')
sys.stdout.flush()
i += 1
time.sleep(0.1)
sys.stdout.write(f'\r✅ {message} completado ({seconds}s) \n')
sys.stdout.flush()
# ==============================
# API SETUP
# ==============================
def setup_api_key():
print(Fore.YELLOW + "🔑 Initial configuration required\n")
api_key = input("👉 Enter your Apify API Token: ").strip()
with open(".env", "w") as f:
f.write(f"APIFY_TOKEN={api_key}\n")
print(Fore.GREEN + "✅ APIFY_TOKEN saved in .env\n")
return api_key
# ==============================
# ENV
# ==============================
load_dotenv()
API_KEY = os.getenv("APIFY_TOKEN")
# ==============================
# APIFY CLIENT SIN LOGS
# ==============================
class SuppressOutput:
"""Context manager para suprimir completamente stdout y stderr"""
def __enter__(self):
self.devnull = open(os.devnull, 'w')
self.old_stdout = sys.stdout
self.old_stderr = sys.stderr
sys.stdout = self.devnull
sys.stderr = self.devnull
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stdout = self.old_stdout
sys.stderr = self.old_stderr
self.devnull.close()
class TikTokChecker:
def __init__(self, api_key):
self.client = ApifyClient(api_key)
def check(self, username):
"""Ejecuta el scraper completamente en silencio"""
try:
run_input = {
"profiles": [username],
"profileScrapeSections": ["videos"],
"profileSorting": "latest",
"resultsPerPage": 1,
"shouldDownloadVideos": False,
"shouldDownloadCovers": False,
"shouldDownloadAvatars": False
}
# Suprimir TODA la salida durante la ejecución del scraper
with SuppressOutput():
run = self.client.actor(
"clockworks/tiktok-profile-scraper"
).call(
run_input=run_input
)
dataset_id = run.default_dataset_id
items = list(self.client.dataset(dataset_id).iterate_items())
if not items:
return {}
item = items[0]
author = item.get("authorMeta", {})
return {
"tiktok_profile": {
"username": author.get("name"),
"full_name": author.get("nickName"),
"profile_url": author.get("profileUrl"),
"avatar_url": author.get("avatar"),
"additional_info": {
"verified": author.get("verified"),
"signature": author.get("signature"),
"bio_link": author.get("bioLink"),
"private_account": author.get("privateAccount"),
"followers": author.get("fans"),
"following": author.get("following"),
"friends": author.get("friends"),
"likes": author.get("heart"),
"videos": author.get("video"),
"create_time": author.get("createTime")
}
}
}
except Exception as e:
return {"error": str(e)}
# ==============================
# HELPERS
# ==============================
def load_targets(file):
with open(file, "r", encoding="utf-8") as f:
return [line.strip().replace("@", "") for line in f if line.strip()]
def format_date(ts):
try:
return datetime.fromtimestamp(ts, UTC).strftime("%Y-%m-%d")
except:
return "Unknown"
def format_number(num):
"""Formatea números grandes con comas"""
try:
return f"{num:,}"
except:
return str(num)
def extract_info(data):
profile = data.get("tiktok_profile", {})
extra = profile.get("additional_info", {})
return {
"username": profile.get("username"),
"full_name": profile.get("full_name"),
"followers": extra.get("followers"),
"likes": extra.get("likes"),
"private": extra.get("private_account"),
"created": format_date(extra.get("create_time"))
}
def generate_filename(prefix):
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
rand = ''.join(random.choices(string.ascii_lowercase + string.digits, k=6))
return f"{prefix}_{timestamp}_{rand}.json"
def ensure_reports_folder():
if not os.path.exists("reports"):
os.makedirs("reports")
def save_report(data, filename):
path = os.path.join("reports", filename)
with open(path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4, ensure_ascii=False)
return path
def save_txt_report(report, filename):
path = os.path.join("reports", filename)
with open(path, "w", encoding="utf-8") as f:
f.write("TokIntel Report\n")
f.write("=" * 60 + "\n\n")
summary = report["summary"]
f.write(f"Total : {summary['total']}\n")
f.write(f"Hits : {summary['hits']}\n")
f.write(f"Misses : {summary['misses']}\n")
f.write(f"Errors : {summary['errors']}\n\n")
for r in report["results"]:
f.write(f"🎯 Username : {r['target']}\n")
f.write(f"📌 Status : {r['status'].upper()}\n\n")
if r["status"] == "hit" and r["raw"]:
profile = r["raw"]["tiktok_profile"]
extra = profile["additional_info"]
f.write(f"Username : {profile.get('username')}\n")
f.write(f"Name : {profile.get('full_name')}\n")
f.write(f"Profile URL : {profile.get('profile_url')}\n")
f.write(f"Avatar URL : {profile.get('avatar_url')}\n")
f.write(f"Verified : {extra.get('verified')}\n")
f.write(f"Private : {extra.get('private_account')}\n")
f.write(f"Followers : {format_number(extra.get('followers'))}\n")
f.write(f"Following : {format_number(extra.get('following'))}\n")
f.write(f"Friends : {format_number(extra.get('friends'))}\n")
f.write(f"Likes : {format_number(extra.get('likes'))}\n")
f.write(f"Videos : {format_number(extra.get('videos'))}\n")
f.write(f"Created : {format_date(extra.get('create_time'))}\n")
f.write(f"Bio : {extra.get('signature')}\n")
f.write(f"Bio Link : {extra.get('bio_link')}\n")
f.write("\n")
f.write("=" * 60 + "\n\n")
return path
# ==============================
# MAIN
# ==============================
def main():
global API_KEY
print_banner()
parser = argparse.ArgumentParser(description="TikTok OSINT Framework")
parser.add_argument("--user", help="Single TikTok username")
parser.add_argument("--users-file", help="TXT file with usernames")
parser.add_argument("--set-api", action="store_true")
parser.add_argument("--donate", action="store_true", help="Support the project")
parser.add_argument("--show-avatar", action="store_true", help="Show avatar URL in console")
args = parser.parse_args()
if args.donate:
print(Fore.MAGENTA + "\n💖 Support TokIntel\n")
print(Fore.CYAN + "☕ https://buymeacoffee.com/HackUnderway")
print(Fore.WHITE + "🙏 Thank you for supporting the project!\n")
return
if args.set_api:
API_KEY = setup_api_key()
return
if not API_KEY:
API_KEY = setup_api_key()
if args.user:
targets = [args.user.replace("@", "")]
prefix = "user"
elif args.users_file:
targets = load_targets(args.users_file)
prefix = "users"
else:
parser.print_help()
return
print(Fore.CYAN + f"\n[+] Targets: {len(targets)}\n")
checker = TikTokChecker(API_KEY)
results = []
hits = []
misses = []
errors = []
# Escanear cada objetivo
for i, target in enumerate(targets, 1):
print(Fore.WHITE + f"\n📌 [{i}/{len(targets)}] Escaneando: @{target}")
print(Fore.YELLOW + "⏳ Iniciando conexión con Apify...")
# Mostrar mensaje de inicio
sys.stdout.write("🔄 Procesando solicitud...")
sys.stdout.flush()
start_time = time.time()
# Ejecutar scraper (esto toma tiempo real)
data = checker.check(target)
elapsed = time.time() - start_time
# Limpiar línea y mostrar completado
sys.stdout.write(f'\r✅ Escaneo completado en {elapsed:.1f} segundos \n')
sys.stdout.flush()
# Procesar resultados
if "error" in data:
print(Fore.YELLOW + f"⚠️ Error: {data['error']}")
status = "error"
info = None
errors.append(target)
else:
profile = data.get("tiktok_profile")
if profile:
info = extract_info(data)
extra = profile["additional_info"]
# Mostrar resultados completos
print(Fore.GREEN + f"\n{'═' * 60}")
print(Fore.CYAN + f" 📱 Username : @{profile.get('username')}")
print(Fore.CYAN + f" 👤 Name : {profile.get('full_name')}")
print(Fore.CYAN + f" 🔗 Profile URL : {profile.get('profile_url')}")
if args.show_avatar and profile.get('avatar_url'):
# Mostrar avatar completo si se pide
print(Fore.CYAN + f" 🖼️ Avatar URL : {profile.get('avatar_url')}")
print(Fore.CYAN + f" ✓ Verified : {extra.get('verified')}")
print(Fore.CYAN + f" 🔒 Private : {extra.get('private_account')}")
print(Fore.CYAN + f" 👥 Followers : {format_number(extra.get('followers'))}")
print(Fore.CYAN + f" 🔄 Following : {format_number(extra.get('following'))}")
print(Fore.CYAN + f" 👫 Friends : {format_number(extra.get('friends'))}")
print(Fore.CYAN + f" ❤️ Likes : {format_number(extra.get('likes'))}")
print(Fore.CYAN + f" 📹 Videos : {format_number(extra.get('videos'))}")
print(Fore.CYAN + f" 📅 Created : {format_date(extra.get('create_time'))}")
if extra.get('signature'):
print(Fore.CYAN + f" 📝 Bio : {extra.get('signature')}")
if extra.get('bio_link'):
print(Fore.CYAN + f" 🔗 Bio Link : {extra.get('bio_link')}")
print(Fore.GREEN + f"{'═' * 60}\n")
hits.append(target)
status = "hit"
else:
print(Fore.RED + f"\n❌ No se encontró información para @{target}\n")
misses.append(target)
status = "miss"
info = None
results.append({
"target": target,
"status": status,
"info": info,
"raw": data
})
if i < len(targets):
time.sleep(DELAY)
# Guardar reportes
ensure_reports_folder()
report = {
"summary": {
"total": len(results),
"hits": len(hits),
"misses": len(misses),
"errors": len(errors)
},
"results": results
}
json_file = generate_filename(f"report_{prefix}")
json_path = save_report(report, json_file)
txt_path = save_txt_report(report, json_file.replace(".json", ".txt"))
print(Fore.GREEN + "\n✅ Scan Finished\n")
print(Fore.WHITE + f" Targets : {len(results)}")
print(Fore.GREEN + f" Hits : {len(hits)}")
print(Fore.RED + f" Misses : {len(misses)}")
print(Fore.YELLOW + f" Errors : {len(errors)}")
print(Fore.CYAN + "\n📁 Reports")
print(Fore.WHITE + f" JSON : {json_path}")
print(Fore.WHITE + f" TXT : {txt_path}\n")
if not args.show_avatar:
print(Fore.YELLOW + "💡 Tip: Usa --show-avatar para ver la URL completa del avatar en consola\n")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print(Fore.YELLOW + "\n⚠️ Escaneo interrumpido\n")
sys.exit(0)