SHARE
TWEET

tor_hack

DeaD_EyE Nov 10th, 2019 20 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. from zipfile import ZipFile
  3. from contextlib import contextmanager
  4. from io import BytesIO
  5. from pathlib import Path
  6. from tempfile import TemporaryDirectory
  7. from subprocess import Popen, STARTUPINFO, CREATE_NO_WINDOW, DEVNULL
  8. from threading import Thread, Event
  9.  
  10.  
  11. import requests
  12. # pip install requests[socks5]
  13.  
  14.  
  15. @contextmanager
  16. def download_unzip():
  17.     req = requests.get('https://tor.eff.org/dist/torbrowser/9.0.1/tor-win32-0.4.1.6.zip')
  18.     print('Tor heruntergeladen')
  19.     archive = ZipFile(BytesIO(req.content))
  20.     with TemporaryDirectory() as tmp_dir:
  21.         print('Entpacke Tor')
  22.         archive.extractall(tmp_dir)
  23.         yield Path(tmp_dir)
  24.        
  25.  
  26. def run_server(event):
  27.     with download_unzip() as path:
  28.         tor_exe = path / 'Tor/tor.exe'
  29.         sinfo = STARTUPINFO()
  30.         sinfo.dwFlags |= CREATE_NO_WINDOW
  31.         print('Starte Tor')
  32.         proc = Popen([tor_exe], cwd=path, startupinfo=sinfo, stderr=DEVNULL, stdout=DEVNULL)
  33.         while not event.is_set():
  34.             time.sleep(1)
  35.         proc.terminate()
  36.         # Prozess wird beendet
  37.         proc.wait()
  38.         # Wartet bis der Prozess beendet ist
  39.     # Kontextmanager verlassen führt dazu, dass die temporären Dateien
  40.     # gelöscht werden.
  41.  
  42.  
  43. close_event = Event()
  44. tor_thread = Thread(target=run_server, args=[close_event])
  45. tor_thread.start()
  46.  
  47.  
  48. while True:
  49.     try:
  50.         req = requests.get(
  51.             'https://api.ipify.org/',
  52.             proxies={
  53.                 'http': 'socks5://localhost:9050',
  54.                 'https': 'socks5://localhost:9050',
  55.                 }
  56.             )
  57.     except Exception as e:
  58.         print('Not connected to socks5')
  59.         continue
  60.    
  61.     print(req.text)
  62.     close_event.set()
  63.     break
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top