通过Tor进行SSH隧道

时间:2020-07-24 20:13:02

标签: python mysql ssh paramiko tor

尝试通过TOR代理连接到MySQL数据库。

import paramiko
import MySQLdb

conf = paramiko.SSHConfig()
conf.parse(open('C:\ProgramData\ssh\sshd_config'))
host = conf.lookup('sql-tor')
print (host)

proxy = paramiko.ProxyCommand(host['proxycommand'])

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host["hostname"], username=host["user"], password='test', sock=proxy)

con = MySQLdb.connect(host='127.0.0.1', port=3306, user='user', password='password', connect_timeout=60)
cur = con.cursor()

client.close()

出现此错误:

Exception has occurred: FileNotFoundError
[WinError 2] The system cannot find the file specified
  File "test2.py", line 8, in <module>
    proxy = paramiko.ProxyCommand(host['proxycommand'])

sshd_config:

host *-tor
   CheckHostIP  no
   Compression  yes
   Protocol     2
   ProxyCommand connect -4 -S localhost:9050 $(tor-resolve %h localhost:9050) %p

有什么想法可以在tor上创建ssh隧道吗?还是任何其他变体都可以在不使用隧道的情况下做到这一点?

0 个答案:

没有答案