侧边栏壁纸
  • 累计撰写 46 篇文章
  • 累计创建 23 个标签
  • 累计收到 3 条评论

目 录CONTENT

文章目录

在Kali中搭建Tor网络代理

elthon
2021-07-23 / 0 评论 / 0 点赞 / 1434 阅读 / 6867 字

下载了Tor Browser,他本身提供了一个代理服务,地址是127.0.0.1:9150。
通过这个代理,访问 Httpbin,会发现自己的IP在不断变化。证明代理可用。

"""
使用Tor代理服务器更换代理IP
"""

from stem import Signal
from stem.control import Controller
import socket
import socks
import requests

controller = Controller.from_port(port=9151)  # ControlPort默认端口9151
controller.authenticate()
socks.set_default_proxy(socks.SOCKS5,'127.0.0.1',9050)
socket.socket = socks.socksocket


for i in range(1,11):
    response = requests.get('https://httpbin.org/ip')
    print(response.text)
    controller.signal(Signal.NEWNYM)  # 更换IP

但是这种方式是使用了浏览器,想搭建一个Tor网络代理服务,这种方式不合适,必须使用后端进程运行的方式。所以最好的是安装Tor服务了。
这里直接在Kali上面安装,记录配置如下。

安装Tor

sudo -i #切换到root用户
apt install tor
systemctl restart tor
systemctl status tor

可以看到tor已经运行起来了,但是测试发现没有用。
开启tor的日志信息

vi /etc/tor/torrc #我安装的是Tor 0.4.5.9的版本

打开日志记录的注释。
image.png
然后重启tor,这是可以看到tor报错的信息,应该是建立连接的时候被屏蔽了。

Jul 22 21:07:01.000 [warn] 20 connections have failed:
Jul 22 21:07:01.000 [warn]  20 connections died in state handshaking (TLS) with SSL state SSLv3/TLS write client hello in HANDSHAKE
Jul 22 21:07:29.000 [warn] Problem bootstrapping. Stuck at 10% (conn_done): Connected to a relay. (TLS_ERROR; TLS_ERROR; count 21; recommendation warn; host 5889A54CCD68C319F6F8ACEFF81E063E6E84B9BE at 147.135.64.217:443)
Jul 22 21:07:29.000 [warn] 21 connections have failed:
Jul 22 21:07:29.000 [warn]  21 connections died in state handshaking (TLS) with SSL state SSLv3/TLS write client hello in HANDSHAKE
Jul 22 21:08:12.000 [warn] Rejecting SOCKS request for anonymous connection to private address [scrubbed].
Jul 22 21:08:12.000 [notice] Application request when we haven't used client functionality lately. Optimistically trying directory fetches again.
Jul 22 21:08:15.000 [warn] Problem bootstrapping. Stuck at 10% (conn_done): Connected to a relay. (TLS_ERROR; TLS_ERROR; count 22; recommendation warn; host C9DF64AF926E2E584E345D13BCE4A97C231A36BE at 87.118.96.154:9001)
Jul 22 21:08:15.000 [warn] 22 connections have failed:
Jul 22 21:08:15.000 [warn]  22 connections died in state handshaking (TLS) with SSL state SSLv3/TLS write client hello in HANDSHAKE
Jul 22 21:08:16.000 [warn] Problem bootstrapping. Stuck at 10% (conn_done): Connected to a relay. (TLS_ERROR; TLS_ERROR; count 23; recommendation warn; host 81893D8444F0C9100CCD963BD0D62BBC50121D14 at 95.216.118.16:4223)

但是Tor浏览器又可以,只有一个地方了,那就是浏览器用了桥接(网桥)方式进行的连接。那么就需要配置网桥了。Tor浏览器用的是obfs4协议的网桥。必须先安装obfsproxy

安装obfsproxy

apt install obfs4proxy

修改Tor配置文件

vim /etc/tor/torrc

增加如下配置信息

#/etc/tor/torrc

PublishServerDescriptor 0
UseBridges 1
ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy managed
Bridge obfs4 ************ iat-mode=0
Bridge obfs4 ************ iat-mode=0
Bridge obfs4 ************ iat-mode=2
#桥接地址可以去这里领取 https://bridges.torproject.org/ 
#安装了Tor浏览器的话,可以直接从Tor浏览器中复制过来

重启tor

systemctl restart tor
tail -f /var/log/tor/notices.log

查看启动日志

Jul 22 22:07:28.000 [notice] Opened Socks listener connection (ready) on /run/tor/socks
Jul 22 22:07:28.000 [notice] Opening Control listener on /run/tor/control
Jul 22 22:07:28.000 [notice] Opened Control listener connection (ready) on /run/tor/control
Jul 22 22:07:28.000 [notice] Bootstrapped 1% (conn_pt): Connecting to pluggable transport
Jul 22 22:07:28.000 [notice] Bootstrapped 2% (conn_done_pt): Connected to pluggable transport
Jul 22 22:07:29.000 [notice] Bootstrapped 10% (conn_done): Connected to a relay
Jul 22 22:07:29.000 [notice] Bootstrapped 14% (handshake): Handshaking with a relay
Jul 22 22:07:30.000 [notice] Bootstrapped 15% (handshake_done): Handshake with a relay done
Jul 22 22:07:30.000 [notice] Bootstrapped 20% (onehop_create): Establishing an encrypted directory connection
******************** (我隐藏了三个网桥地址)
Jul 22 22:07:32.000 [notice] Bootstrapped 30% (loading_status): Loading networkstatus consensus
Jul 22 22:07:36.000 [notice] I learned some more directory information, but not enough to build a circuit: We have no usable consensus.
Jul 22 22:07:37.000 [notice] Bootstrapped 40% (loading_keys): Loading authority key certs
Jul 22 22:07:37.000 [notice] The current consensus has no exit nodes. Tor can only build internal paths, such as paths to onion services.
Jul 22 22:07:37.000 [notice] Bootstrapped 45% (requesting_descriptors): Asking for relay descriptors
Jul 22 22:07:37.000 [notice] I learned some more directory information, but not enough to build a circuit: We need more microdescriptors: we have 0/6649, and can only build 0% of likely paths. (We have 100% of guards bw, 0% of midpoint bw, and 0% of end bw (no exits in consensus, using mid) = 0% of path bw.)
Jul 22 22:07:38.000 [notice] Bootstrapped 50% (loading_descriptors): Loading relay descriptors
Jul 22 22:07:38.000 [notice] The current consensus contains exit nodes. Tor can build exit and internal paths.
Jul 22 22:07:39.000 [notice] Bootstrapped 56% (loading_descriptors): Loading relay descriptors
Jul 22 22:07:40.000 [notice] Bootstrapped 62% (loading_descriptors): Loading relay descriptors
Jul 22 22:07:46.000 [notice] Bootstrapped 69% (loading_descriptors): Loading relay descriptors
Jul 22 22:07:49.000 [notice] Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
Jul 22 22:07:50.000 [notice] Bootstrapped 76% (ap_conn_pt): Connecting to pluggable transport to build circuits
Jul 22 22:07:50.000 [notice] Bootstrapped 77% (ap_conn_done_pt): Connected to pluggable transport to build circuits
Jul 22 22:07:50.000 [notice] Bootstrapped 85% (ap_conn_done): Connected to a relay to build circuits
Jul 22 22:07:51.000 [notice] Bootstrapped 89% (ap_handshake): Finishing handshake with a relay to build circuits
Jul 22 22:07:51.000 [notice] Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
Jul 22 22:07:51.000 [notice] Bootstrapped 95% (circuit_create): Establishing a Tor circuit
Jul 22 22:07:53.000 [notice] Bootstrapped 100% (done): Done

可以看到没有之前那种错误信息了,这次是100% done。

测试连通性

这里直接用ProxyChain来测试了。
image.png
可以看到,没有问题,获取到了正常的IP地址。

0
Tor

评论区