I have a fully functional tor hidden service with his v3 url, created with stem and the controller class. The server is redirecting the traffic into a local tcp server running on port 5000 created with socket. But now I want to connect to this hidden service using python. So I tried socks with SOCKS5 proxies, no way of making it work. I also tried the torpy library with the example provided on the offical doc but, again, no way to make it works:
from torpy import TorClient
url = 'myv3torurl.onion'
tor = TorClient()
with tor.create_circuit() as circuit:
print('circuit done')
with circuit.create_stream(('http://' + url, 5000)) as client:
print('sending')
client.send(b'yeah yeah im there')
print(client.recv(1024))
Also tried changing the url adding http:// or https://, or tried to change the port with 80, 9050 or 9051. The torpy logs are always the same and you can find them here.
At this point I do not really know what to try. I just want a tcp connection hosted by the onion website. And by the way, I'm sure it's not a problem of the server because if I try to copy and paste the url on the tor browser it is fully reachable. Thank you for any help.
Noticed that torpy page says it is for v2 services and yours is v3.
Related
I have a python socket.io server, a client-side script (react, socket.io-client) connects to it via ngrok link. At the first time everything worked fine, but at some point I started getting an error:
Access to XMLHttpRequest at 'https://f64f-94-29-126-249.eu.ngrok.io/socket.io/?EIO=4&transport=polling&t=OEJEvFx' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
GET https://f64f-94-29-126-249.eu.ngrok.io/socket.io/?EIO=4&transport=polling&t=OEJEvFx net::ERR_FAILED 200
On the server side i specified cors headers
sio = socketio.Server(cors_allowed_origins=['*'])
I start ngrok with the command:
./ngrok http --host-header=rewrite 5000
Also I tried this:
./ngrok http --host-header='localhost:5000' 5000
And this (on client side):
const socket = io("https://f64f-94-29-126-249.eu.ngrok.io", {transports: ['websocket', 'polling', 'flashsocket']});
And got error:
websocket.js:50 WebSocket connection to 'wss://f64f-94-29-126-249.eu.ngrok.io/socket.io/?EIO=4&transport=websocket' failed:
But none of the internet solutions helped. Then I tried to start the server on my machine and make it online using the same commands and it worked. Then I tried to change the server on which the backend is running, but I got the same error, it turns out that the backend only works on my computer. What could be the problem? Literally a couple of days ago everything worked on the server. Neither the socket.io related code nor the network settings have changed.
I have a python socket listening on my computer's ip address on a specific port. I am using the standard python socket library with something like the following code:
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind(server_address) # Server address is a tuple (HOST, PORT) with host being
# something like 123.456.789.00 and port being 4000
listen_socket.listen()
client_connection, client_address = listen_socket.accept()
request_data = client_connection.recv(1024).decode('utf-8')
print(request_data)
When I use Chrome on my iPhone to connect to the address, the rest of my code runs fine and processes the incoming request by sending an html page. When I use Safari, it loads for a while until it fails and a says "Safari cannot open the page because it could not connect to the server."
Funny enough, if I stay on the page, restart the server, and then reload the page using the refresh button, it connects fine. But trying to access the address through the url address does not work. Refreshing using the refresh button seems to work. Why is Safari having trouble connecting to my Python socket?
Try increasing the backlog count in the listen_socket.listen() call.
I had a similar issue with a python 2 socket server and macOS Safari. Safari would say it could not connect to the server, but Chrome/Firefox/IE/curl all worked without any errors. I changed this:
listen_socket.listen(1)
To this:
listen_socket.listen(5)
Safari then worked without any errors. I am now using 128 instead of 5, not sure what the default is in Python 3.
When set to 1, in the python server I would see Safari connect, but then socket.recv() would never return.
I have a piece of code I am using for testing on http servers. What I did first was to set up my http server in python and type it in my web browser, listening on port8000. However when i delete theindex.htmland stopped thepython` script and hit refresh on my webbrowser, it still shows the same page! I am currently using Firefox developer edition by the way.
link to image
I have tried replacing the index.html with another different website index.html for testing, but it wasnt showing the new website.
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
I expect the web browser to stop showing index.html after closing the python script. Please help to fix my code so that it stops showing the same index.html
welcome to stackoverflow. I think your issue is with the caching! You can try hitting ctrl+f5 on your browser to see if it works.
I want to make an anonymous web request using python 3.
I've tried few suggestions such as: Make requests using Python over Tor
I've managed to get a fake ip using this snippet:
Installation
pip install requests requests[socks]
Basic usage
import requests
def get_tor_session():
session = requests.session()
# Tor uses the 9050 port as the default socks port
session.proxies = {'http': 'socks5://127.0.0.1:9150',
'https': 'socks5://127.0.0.1:9150'}
return session
# Make a request through the Tor connection
# IP visible through Tor
session = get_tor_session()
print(session.get("http://httpbin.org/ip").text)
# Above should print an IP different than your public IP
# Following prints your normal public IP
print(requests.get("http://httpbin.org/ip").text)
But that works only on port 9150 and when the tor web browser works.
I want to make a request without the tor browser, as i want to Dockerize the whole thing.
I've read about Socks5, and as you can see i've installed it, but when i make a request on port 9050 on the same snippet i get:
requests.exceptions.ConnectionError:
SOCKSHTTPConnectionPool(host='httpbin.org', port=80): Max retries
exceeded with url: /ip (Caused by
NewConnectionError(': Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it',))
How can i solve it?
Thanks!
10061 is 'connection refused'
That means there was nothing listening on that port you tried to connect to, no service is up and running (no open port) or firewall on target IP blocks it
you can test that port with telnet
telnet `IP` `PORT`
And also check this port issue on Windows: here
I was also facing this issue, in my case my tor service was not running, actually I was using kalitorify which is a transparent proxy, and whenever I was using this I was not be able to use normal sites such as google search or similar, so to use these sites I was turning off my kalitorify service which also turns off your tor service
So if you're also using that then also check it once
I have an issue with route_url and my setup. On the server I have a paster server which listen on 127.0.0.1 on port 6543 and a nginx server which does reverse proxying from port 80 to port 6543.
I'm also using paste prefix to retrieve the real client IP with this setup in my ini file:
[filter:paste_prefix]
use = egg:PasteDeploy#prefix
[pipeline:main]
pipeline =
paste_prefix
myapp
The server is on a private LAN and I'm trying to connect to the server through a SSH tunnel set up as this:
ssh me#sshgateway -L 8080:nginx_server_ip:80
And I connect to the web page on my client at this url: http://localhost:8080
The main page is displayed correctly but then all links generated with request.route_url are redirecting to localhost/url (without the :8080).
I guess this have something to do either with nginx or paste prefix (or both).
I hope that replacing route_url with route_path will probably solve this problem without fixing the nginx/ini setup issue.
Is there any reason to call route_url instead of route_path, ever ?
route_url is useful in situations like generating a redirect from HTTP to HTTPS, or to a different subdomain. Other than that route_path is probably preferable.