【问题标题】:Trouble authenticating Tor with python使用 python 对 Tor 进行身份验证时遇到问题
【发布时间】:2013-03-17 09:15:53
【问题描述】:

可能在这里做了一些非常愚蠢的事情,但是我在通过 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

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

515 Authentication failed: Password did not match HashedControlPassword value from configuration. Maybe you tried a plain text password

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

【问题讨论】:

  • 哇,这太糟糕了。
  • 这是一个已知的错误吗? trac.torproject.org/projects/tor/ticket/4817
  • 身份验证必须采用以下格式:AUTHENTICATE (password)\r\n,如AUTHENTICATE 16:7FA1766AE1DC149A603309B1BF8EBBAAA3F44C237898EF82D19908BD92\r\n。你做对了吗?另外,您是否将哈希密码放入torrc
  • 您可以通过以下方式更新您的 Tor 密码:stackoverflow.com/a/33726166/895245

标签: sockets authentication proxy tor


【解决方案1】:

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

您在这里尝试执行的操作(发出 NEWNYM)是一个非常非常常见的请求(12),所以我只是为它添加了一个 FAQ entry。这是一个使用stem的示例...

from stem import Signal
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
  controller.authenticate()
  controller.signal(Signal.NEWNYM)

【讨论】:

  • 这是正确的做法。但是,stem 库对身份验证机制也不是很清楚。
猜你喜欢
  • 1970-01-01
  • 2018-01-27
  • 2021-03-03
  • 2012-08-29
  • 1970-01-01
  • 1970-01-01
  • 2015-11-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多