用python验证Tor的麻烦

Sla*_*off 5 sockets authentication proxy tor

可能在这里做一些非常愚蠢的事情,但是我在通过Tor自动进行身份验证时遇到了一些麻烦.

我使用32位ubuntu 12.04与混淆桥.

这应该是所有相关的代码,但请告诉我是否有其他一些在调试此问题时有用:

import socket
import socks
import httplib

def connectTor():
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050, True)
    #9050 is the Tor proxy port
    socket.socket = socks.socksocket

def newIdentity():
    socks.setdefaultproxy() #Disconnect from Tor network

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect(("127.0.0.1", 46594))

s.send("AUTHENTICATE\r\n")

response = s.recv(128)
#128 bytes of data for now, just to see how Tor responds

print response
if response.startswith("250"): #250 is the code for a positive response from Tor
    s.send("SIGNAL NEWNYM\r\n") #Use a new identity
s.close()

connectTor() #Just to make sure we're still connected to Tor
Run Code Online (Sandbox Code Playgroud)

每当我运行这个时,我都会收到以下错误:

515 Authentication failed: Password did not match HashedControlPassword value from configuration. Maybe you tried a plain text password
Run Code Online (Sandbox Code Playgroud)

我尝试使用--hash-password选项并将其粘贴到AUTHENTICATE字符串的位置,但这只会导致脚本挂起.思考?

Dam*_*ian 5

该错误意味着您在torrc中设置HashedControlPassword选项.我会建议选择,CookieAuthentication 1然后使用控制器库,而不是从头开始.

什么你想在这里做(发出NEWNYM)是一个非常,非常普遍的要求(1,2),所以我只是增加了一个FAQ条目它.这是一个使用词干的例子......

from stem import Signal
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
  controller.authenticate()
  controller.signal(Signal.NEWNYM)
Run Code Online (Sandbox Code Playgroud)