- Saved searches
- Use saved searches to filter your results more quickly
- License
- torpyorg/torpy
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- requests_tor
- Install
- Dependencies
- Simple usage
- Advanced usage
- Saved searches
- Use saved searches to filter your results more quickly
- License
- RootDev4/Tor-Request
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Pure python Tor client implementation
License
torpyorg/torpy
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
A pure python Tor client implementation of the Tor protocol. Torpy can be used to communicate with clearnet hosts or hidden services through the Tor Network.
- No Stem or official Tor client required
- Support v2 hidden services (v2 specification)
- Support Basic and Stealth authorization protocol
- Provide simple TorHttpAdapter for requests library
- Provide simple urllib tor_opener for making requests without any dependencies
- Provide simple Socks5 proxy
If you find this project interesting, you can send some Bitcoins to address: 16mF9TYaJKkb9eGbZ5jGuJbodTF3mYvcRF
This product is produced independently from the Tor® anonymity software and carries no guarantee from The Tor Project about quality, suitability or anything else.
There are several console utilities to test the client.
A simple HTTP/HTTPS request:
$ torpy_cli --url https://ifconfig.me --header "User-Agent" "curl/7.37.0" Loading cached NetworkStatusDocument from TorCacheDirStorage: .local/share/torpy/network_status Loading cached DirKeyCertificateList from TorCacheDirStorage: .local/share/torpy/dir_key_certificates Connecting to guard node 141.98.136.79:443 (Poseidon; Tor 0.4.3.6). (TorClient) Sending: GET https://ifconfig.me Creating new circuit #80000001 with 141.98.136.79:443 (Poseidon; Tor 0.4.3.6) router. . Building 3 hops circuit. Extending the circuit #80000001 with 109.70.100.23:443 (kren; Tor 0.4.4.5). . Extending the circuit #80000001 with 199.249.230.175:443 (Quintex86; Tor 0.4.4.5). . Stream #4: creating attached to #80000001 circuit. Stream #4: connecting to ('ifconfig.me', 443) Stream #4: connected (remote ip '216.239.36.21') Stream #4: closing (state = Connected). Stream #4: remote disconnected (reason = DONE) Response status: 200 Stream #4: closing (state = Closed). Stream #4: closed already Closing guard connections (TorClient). Destroy circuit #80000001 Closing guard connections (Router descriptor downloader). Destroy circuit #80000002 > 199.249.230.175
Create Socks5 proxy to relay requests via the Tor Network:
$ torpy_socks -p 1050 --hops 3 Loading cached NetworkStatusDocument from TorCacheDirStorage: .local/share/torpy/network_status Connecting to guard node 89.142.75.60:9001 (spongebobness; Tor 0.3.5.8). Creating new circuit #80000001 with 89.142.75.60:9001 (spongebobness; Tor 0.3.5.8) router. Building 3 hops circuit. Extending the circuit #80000001 with 185.248.143.42:9001 (torciusv; Tor 0.3.5.8). Extending the circuit #80000001 with 158.174.122.199:9005 (che1; Tor 0.4.1.6). Start socks proxy at 127.0.0.1:1050 .
Torpy module also has a command-line interface:
$ python3.7 -m torpy --url https://facebookcorewwwi.onion --to-file index.html Loading cached NetworkStatusDocument from TorCacheDirStorage: .local/share/torpy/network_status Connecting to guard node 185.2.31.8:443 (cx10TorServer; Tor 0.4.0.5). Sending: GET https://facebookcorewwwi.onion Creating new circuit #80000001 with 185.2.31.8:443 (cx10TorServer; Tor 0.4.0.5) router. Building 3 hops circuit. Extending the circuit #80000001 with 144.172.71.110:8447 (TonyBamanaboni; Tor 0.4.1.5). Extending the circuit #80000001 with 179.43.134.154:9001 (father; Tor 0.4.0.5). Creating stream #1 attached to #80000001 circuit. Stream #1: connecting to ('facebookcorewwwi.onion', 443) Extending #80000001 circuit for hidden service facebookcorewwwi.onion. Rendezvous established (CellRelayRendezvousEstablished()) Iterate over responsible dirs of the hidden service Iterate over introduction points of the hidden service Create circuit for hsdir Creating new circuit #80000002 with 185.2.31.8:443 (cx10TorServer; Tor 0.4.0.5) router. Building 0 hops circuit. Extending the circuit #80000002 with 132.248.241.5:9001 (toritounam; Tor 0.3.5.8). Creating stream #2 attached to #80000002 circuit. Stream #2: connecting to hsdir Stream #2: closing. Destroy circuit #80000002 Creating new circuit #80000003 with 185.2.31.8:443 (cx10TorServer; Tor 0.4.0.5) router. Building 0 hops circuit. Extending the circuit #80000003 with 88.198.17.248:8443 (bauruine31; Tor 0.4.1.5). Introduced (CellRelayIntroduceAck()) Destroy circuit #80000003 Creating stream #3 attached to #80000001 circuit. Stream #3: connecting to ('www.facebookcorewwwi.onion', 443) Extending #80000001 circuit for hidden service facebookcorewwwi.onion. Response status: 200 Writing to file index.html Stream #1: closing. Stream #3: closing. Closing guard connections. Destroy circuit #80000001
A basic example of how to send some data to a clearnet host or a hidden service:
from torpy import TorClient hostname = 'ifconfig.me' # It's possible use onion hostname here as well with TorClient() as tor: # Choose random guard node and create 3-hops circuit with tor.create_circuit(3) as circuit: # Create tor stream to host with circuit.create_stream((hostname, 80)) as stream: # Now we can communicate with host stream.send(b'GET / HTTP/1.0\r\nHost: %s\r\n\r\n' % hostname.encode()) recv = stream.recv(1024)
TorHttpAdapter is a convenient Tor adapter for the requests library. The following example shows the usage of TorHttpAdapter for multi-threaded HTTP requests:
from multiprocessing.pool import ThreadPool from torpy.http.requests import tor_requests_session with tor_requests_session() as s: # returns requests.Session() object links = ['http://nzxj65x32vh2fkhk.onion', 'http://facebookcorewwwi.onion'] * 2 with ThreadPool(3) as pool: pool.map(s.get, links)
- Just pip3 install torpy
- Or for using TorHttpAdapter with requests library you need install extras: pip3 install torpy[requests]
- Implement v3 hidden services specification
- Refactor Tor cells serialization/deserialization
- More unit tests
- Rewrite the library using asyncio
- Implement onion services
Licensed under the Apache License, Version 2.0
- Official Tor client
- Pycepa
- TorPylle
- TinyTor
- C++ Windows only implementation Mini-tor
- Nice Java implementation Orchid
About
Pure python Tor client implementation
requests_tor
Multithreading requests via TOR with automatic TOR new identity.
Wrapper of the requests and stem libraries. Returns requests.Response object.
Masking as Tor Browser by using its default headers:
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.5", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0",
Install
pip install -U requests_tor
Dependencies
Download and start Tor Browser or install Tor
- In Tor torrc file control port is disabled by default. Needs to uncomment line ControlPort 9051
- If you face an error Authentication failed: unable to read ‘/run/tor/control.authcookie’ ([Errno 13] Permission denied: ‘/run/tor/control.authcookie’) — needs to add your current user to the tor group. ps ax o comm,group | grep tor — command to find tor group (group name will be in the second column, for example debian-tor ). sudo usermod -a -G debian-tor $USER — add your current user to tor group
- Restart Tor ( /etc/init.d/tor restart ) and re-login
Simple usage
Advanced usage
SocksPort 9000 IsolateDestAddr SocksPort 9001 IsolateDestAddr SocksPort 9002 IsolateDestAddr SocksPort 9003 IsolateDestAddr SocksPort 9004 IsolateDestAddr
generate and add in torrc file HashedControlPassword.
HashedControlPassword hashed_password
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Tor proxy support for your python requests.
License
RootDev4/Tor-Request
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Tor proxy support for python requests.
pip install pysocks
pip install requests
OR: pip install -r requirements.txt
# Import TorRequest class from TorRequest import TorRequest # Call TorRequest with path to Tor executable t = TorRequest('/tor.exe') # Windows t = TorRequest('/usr/local/bin/tor') # Mac OS X (default path) t = TorRequest('/usr/sbin/tor') # Linux (default path) # Send optional, comma-separated HTTP headers headers = 'User-Agent': 'Mozilla/5.0'> t = TorRequest('', headers) # Get status (true: connected, false: not connected) t.status() # Get Tor ip address t.ipAddr() # Get requests session object with binded Tor circuit t.session() # Get website content with anonymized request t.get('https://github.com/') # Returns HTML content t.get('https://github.com/', True) # Returns response object (contains HTTP status code, text, . ) # Example: print HTTP status code print(t.get('https://github.com/', True).status_code) # Send anonymized POST request to website (e.g. login credentials) t.post('', 'username': 'foo', 'password': 'bar'>) # Returns HTML content t.post('', 'username': 'foo', 'password': 'bar'>, True) # Returns response object
- Download Tor Browser Bundle from the official website and install it
- Tor executable is placed inside \Browser\TorBrowser\Tor\tor.exe
- If you don’t want to install the whole Tor Browser Bundle, you can also download just the Tor source code
- Install Tor using Homebrew via terminal: brew install tor
- Find installation path: which tor
- By default, installation path is /usr/local/bin/tor
- Install Tor via terminal: apt install tor -y
- Find installation path: which tor
- By default, installation path is /usr/sbin/tor
For both Mac and Linux it’s possible, to use that Tor executable that comes with the Tor Browser Bundle. I still recommend to use the Tor source code installed via terminal (for reason, see Troubleshooting section).
Exception «SyntaxError (unicode error)» thrown
Use forward slashes for path string or mark this string as raw string (e.g. r’C:\Users. \tor.exe’). You can also use double backslashes.
Error message «Missing dependencies for SOCKS support».
(Re-)install PySocks module.
Exception «SOCKSHTTPSConnectionPool» thrown.
This exception gets thrown, if you’re using the Tor executable out of the Tor Browser Bundle in Linux while running the Browser itself. Use the Tor installation under /usr/sbin/tor to avoid this error.
About
Tor proxy support for your python requests.