All Projects → torpyorg → Torpy

torpyorg / Torpy

Licence: apache-2.0
Pure python Tor client implementation

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Torpy

orjail
a more secure way to force programs to exclusively use tor network
Stars: ✭ 136 (+30.77%)
Mutual labels:  tor, tor-network
Multitor
Create multiple TOR instances with a load-balancing.
Stars: ✭ 624 (+500%)
Mutual labels:  tor, tor-network
Toriptables2
Tor Iptables script is an anonymizer that sets up iptables and tor to route all services and traffic including DNS through the Tor network.
Stars: ✭ 287 (+175.96%)
Mutual labels:  tor, tor-network
Tortipi
Tor based Raspberry π hotspot
Stars: ✭ 76 (-26.92%)
Mutual labels:  tor, tor-network
Sybilhunter
Hunting for Sybils and anomalies in archived Tor network data.
Stars: ✭ 35 (-66.35%)
Mutual labels:  tor, tor-network
sbws
Unofficial clone of gitweb.torproject.org. Report issues and open merge requests at: https://gitlab.torproject.org/tpo/network-health/sbws/
Stars: ✭ 15 (-85.58%)
Mutual labels:  tor, tor-network
Exitmap
A fast and modular scanner for Tor exit relays. The canonical repository (including issue tracker) is at https://gitlab.torproject.org/tpo/network-health/exitmap
Stars: ✭ 440 (+323.08%)
Mutual labels:  tor, tor-network
tor-ip-changer
request new identity every X seconds interval using TOR client
Stars: ✭ 233 (+124.04%)
Mutual labels:  tor, tor-network
Scihub Downloader
Sci-Hub PDF downloader through Tor Network (Docker image)
Stars: ✭ 35 (-66.35%)
Mutual labels:  tor, tor-network
Prometheus Tor exporter
Prometheus exporter for the TOR daemon
Stars: ✭ 20 (-80.77%)
Mutual labels:  tor, tor-network
Poopak
POOPAK - TOR Hidden Service Crawler
Stars: ✭ 78 (-25%)
Mutual labels:  tor, tor-network
Onionite
Explore the Tor network
Stars: ✭ 63 (-39.42%)
Mutual labels:  tor, tor-network
onionbox
Send and receive files securely through Tor.
Stars: ✭ 39 (-62.5%)
Mutual labels:  tor, tor-network
Attacks-on-Tor
Thirteen Years of Tor Attacks
Stars: ✭ 170 (+63.46%)
Mutual labels:  tor, tor-network
T0rlib4Android
A minimal android controller library for Tor
Stars: ✭ 25 (-75.96%)
Mutual labels:  tor, tor-network
Torwall
Tallow - Transparent Tor for Windows
Stars: ✭ 346 (+232.69%)
Mutual labels:  tor, tor-network
OnionHarvester
A small TOR Onion Address harvester for checking if the address is available or not.
Stars: ✭ 71 (-31.73%)
Mutual labels:  tor, tor-network
Tor-IP-Addresses
Hourly checked and updated list of IP Addresses of Tor and Tor Exit Nodes
Stars: ✭ 182 (+75%)
Mutual labels:  tor, tor-network
Torbot
Dark Web OSINT Tool
Stars: ✭ 821 (+689.42%)
Mutual labels:  tor, tor-network
Deepweb Scappering
Discover hidden deepweb pages
Stars: ✭ 40 (-61.54%)
Mutual labels:  tor, tor-network

Torpy Python Versions Build Status Build status Coverage Status

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.

Features

  • 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

Donation

If you find this project interesting, you can send some Bitcoins to address: 16mF9TYaJKkb9eGbZ5jGuJbodTF3mYvcRF

Note

This product is produced independently from the Tor® anonymity software and carries no guarantee from The Tor Project about quality, suitability or anything else.

Console examples

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

Usage examples

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)

For more examples see test_integration.py

Installation

  • Just pip3 install torpy
  • Or for using TorHttpAdapter with requests library you need install extras: pip3 install torpy[requests]

Contribute

  • Use It
  • Code review is appreciated
  • Open Issue, send PR

TODO

  • [ ] Implement v3 hidden services specification
  • [ ] Refactor Tor cells serialization/deserialization
  • [ ] More unit tests
  • [ ] Rewrite the library using asyncio
  • [ ] Implement onion services

License

Licensed under the Apache License, Version 2.0

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].