Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM 192.168.194.63:5000/ubuntu:latest
FROM ubuntu:latest

# 设置工作目录
WORKDIR /app
Expand Down Expand Up @@ -65,13 +65,14 @@ RUN sudo apt install -y \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
libevent-dev \
xdg-utils
RUN sudo apt install -y libasound2t64
RUN sudo dpkg -i bin/google-chrome-stable_current_amd64.deb
RUN sudo apt install -f
RUN sudo dpkg -i bin/google-chrome-stable_current_amd64.deb
RUN sudo mv bin/chromedriver-linux64/chromedriver /usr/bin
#RUN sudo dpkg -i bin/google-chrome-stable_current_amd64.deb
#RUN sudo apt install -f
#RUN sudo dpkg -i bin/google-chrome-stable_current_amd64.deb
#RUN sudo mv bin/chromedriver-linux64/chromedriver /usr/bin


# 默认命令,打开vim
CMD ["bash"]
CMD ["bash"]
3 changes: 2 additions & 1 deletion dockerfiles/Dockerfile_debian12
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ RUN sudo apt install -y \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
libevent-dev \
xdg-utils
RUN sudo apt install -y libasound2
RUN sudo dpkg -i bin/google-chrome-stable_current_amd64.deb
Expand All @@ -80,4 +81,4 @@ RUN sudo mv bin/chromedriver-linux64/chromedriver /usr/bin


# 默认命令,打开vim
CMD ["bash"]
CMD ["bash"]
3 changes: 2 additions & 1 deletion dockerfiles/Dockerfile_ubuntu20
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ RUN sudo apt install -y \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
libevent-dev \
xdg-utils
RUN sudo apt install -y libasound2
RUN sudo dpkg -i bin/google-chrome-stable_current_amd64.deb
Expand All @@ -84,4 +85,4 @@ RUN sudo mv bin/chromedriver-linux64/chromedriver /usr/bin


# 默认命令,打开vim
CMD ["bash"]
CMD ["bash"]
3 changes: 2 additions & 1 deletion dockerfiles/Dockerfile_ubuntu24
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ RUN sudo apt install -y \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
libevent-dev \
xdg-utils
RUN sudo apt install -y libasound2t64
RUN sudo dpkg -i bin/google-chrome-stable_current_amd64.deb
Expand All @@ -74,4 +75,4 @@ RUN sudo mv bin/chromedriver-linux64/chromedriver /usr/bin


# 默认命令,打开vim
CMD ["bash"]
CMD ["bash"]
104 changes: 104 additions & 0 deletions src/spider_traffic/torDo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import os
from multiprocessing import Process
import subprocess
import time

from spider_traffic.myutils.logger import logger


BIN_FOLDER='/app/bin/tor_s'
TORRC_FOLDER='/app/torrc_s'
TOR_LOG_FOLDER='/app/logs'




def long_running_task(log_file):
while True:
time.sleep(1)
f = os.popen(f"cat {log_file}|grep 'Bootstrapped 100%'|wc -l")
process_num = int(f.read())
if process_num != 0:
break


def wait_for_100(log_file,timeout=180):
# 创建子进程
process = Process(target=long_running_task, args=(log_file,))
process.start()
process.join(timeout=timeout) # 等待最多 x秒
if process.is_alive():
process.terminate() # 强制终止子进程
return False
else:
return True



def start_tor(flag:str):
"""
根据flag启动Tor程序:
'none':裸Tor
'meek':使用Meek的Tor
'obfs4_0'使用Obfs4且客户端iat-mode=0的Tor
'obfs4_1'使用Obfs4且客户端iat-mode=1的Tor
'obfs4_2'使用Obfs4且客户端iat-mode=2的Tor
'snowflake'使用snowflake的Tor
'webtunnel'使用webtunnel的Tor
Return:
进程,启动成功标志(True为启动成功, False为启动不成功)
"""
#根据配置制作/挑选torrc文件
if flag=='none':
torrc_file=os.path.join(TORRC_FOLDER,'torrc_tor')
log_file=os.path.join(TOR_LOG_FOLDER,'notice_none.log')
elif flag=='webtunnel':
torrc_file=os.path.join(TORRC_FOLDER,'torrc_webtunnel')
log_file=os.path.join(TOR_LOG_FOLDER,'notice_webtunnel.log')
elif flag=='meek':
torrc_file=os.path.join(TORRC_FOLDER,'torrc_meek')
log_file=os.path.join(TOR_LOG_FOLDER,'notice_meek.log')
elif flag=='snowflake':
torrc_file=os.path.join(TORRC_FOLDER,'torrc_snowflake')
log_file=os.path.join(TOR_LOG_FOLDER,'notice_snowflake.log')
elif flag=='obfs4_0':
torrc_file=os.path.join(TORRC_FOLDER,'torrc_obfs4_0')
log_file=os.path.join(TOR_LOG_FOLDER,'notice_obfs4_0.log')
elif flag=='obfs4_1':
torrc_file=os.path.join(TORRC_FOLDER,'torrc_obfs4_1')
log_file=os.path.join(TOR_LOG_FOLDER,'notice_obfs4_1.log')
elif flag=='obfs4_2':
torrc_file=os.path.join(TORRC_FOLDER,'torrc_obfs4_2')
log_file=os.path.join(TOR_LOG_FOLDER,'notice_obfs4_2.log')
else:
raise TypeError(f'Unknown Tor protocol flag!: {flag}')
#清空log日志用于后续判断Tor是否启动成功
subprocess.call("echo > %s" % log_file, shell=True)
#使用torrc文件启动Tor
tor_process = subprocess.Popen(
[os.path.join(BIN_FOLDER,'tor'), "-f", torrc_file],
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
#判断Tor是否启动成功
tor_is_started=wait_for_100(log_file,300)
logger.info(f'Tor-{flag}启动成功? {tor_is_started}!!')
return tor_process,tor_is_started

def close_tor(tor_process):
tor_process.terminate() # 尝试优雅地关闭进程
# 如果进程没有退出,使用kill强制终止
try:
tor_process.wait(timeout=5) # 等待进程退出,最多等5秒
logger.info("优雅的关闭Tor进程")
except subprocess.TimeoutExpired:
tor_process.kill() # 如果进程没有在超时前退出,强制杀死进程
logger.info("强制杀死Tor进程")

if __name__=='__main__':
#测试启动Tor与关闭Tor
tor_process,success=start_tor('webtunnel')
print(f'{time.time}Tor启动成功?:{success}')
time.sleep(20)
close_tor(tor_process)
Empty file added torData/tor_meek/.gitkeep
Empty file.
Empty file added torData/tor_none/.gitkeep
Empty file.
Empty file added torData/tor_obfs4_0/.gitkeep
Empty file.
Empty file added torData/tor_obfs4_1/.gitkeep
Empty file.
Empty file added torData/tor_obfs4_2/.gitkeep
Empty file.
Empty file added torData/tor_snowflake/.gitkeep
Empty file.
Empty file added torData/tor_webtunnel/.gitkeep
Empty file.
13 changes: 13 additions & 0 deletions torrc_s/torrc_meek
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ControlPort 2700
SocksPort 9050
DataDirectory /app/torData/tor_meek
Log notice file /app/logs/notice_meek.log
SafeLogging 0
RunAsDaemon 0

LogTimeGranularity 1

UseBridges 1
ClientTransportPlugin meek exec /app/bin/tor_s/meek-client

Bridge meek 0.0.2.0:3 url=https://meek.azureedge.net/ front=ajax.aspnetcdn.com
15 changes: 15 additions & 0 deletions torrc_s/torrc_obfs4
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ControlPort 2700
SocksPort 9050
DataDirectory /app/torData
Log notice file /app/logs/notice.log
SafeLogging 0
RunAsDaemon 0

LogTimeGranularity 1

UseBridges 1

ClientTransportPlugin obfs4 exec /app/bin/tor_s/obfs4proxy

Bridge obfs4 146.57.248.225:22 10A6CD36A537FCE513A322361547444B393989F0 cert=K1gDtDAIcUfeLqbstggjIw2rtgIKqdIhUlHp82XRqNSq/mtAjp1BIC9vHKJ2FAEpGssTPw iat-mode=0

15 changes: 15 additions & 0 deletions torrc_s/torrc_obfs4_0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ControlPort 2700
SocksPort 9050
DataDirectory /app/torData/tor_obfs4_0
Log notice file /app/logs/notice_obfs4_0.log
SafeLogging 0
RunAsDaemon 0

LogTimeGranularity 1

UseBridges 1

ClientTransportPlugin obfs4 exec /app/bin/tor_s/obfs4proxy

Bridge obfs4 146.57.248.225:22 10A6CD36A537FCE513A322361547444B393989F0 cert=K1gDtDAIcUfeLqbstggjIw2rtgIKqdIhUlHp82XRqNSq/mtAjp1BIC9vHKJ2FAEpGssTPw iat-mode=0

15 changes: 15 additions & 0 deletions torrc_s/torrc_obfs4_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ControlPort 2700
SocksPort 9050
DataDirectory /app/torData/tor_obfs4_1
Log notice file /app/logs/notice_obfs4_1.log
SafeLogging 0
RunAsDaemon 0

LogTimeGranularity 1

UseBridges 1

ClientTransportPlugin obfs4 exec /app/bin/tor_s/obfs4proxy

Bridge obfs4 146.57.248.225:22 10A6CD36A537FCE513A322361547444B393989F0 cert=K1gDtDAIcUfeLqbstggjIw2rtgIKqdIhUlHp82XRqNSq/mtAjp1BIC9vHKJ2FAEpGssTPw iat-mode=1

14 changes: 14 additions & 0 deletions torrc_s/torrc_obfs4_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ControlPort 2700
SocksPort 9050
DataDirectory /app/torData/tor_obfs4_2
Log notice file /app/logs/notice_obfs4_2.log
SafeLogging 0
RunAsDaemon 0

LogTimeGranularity 1

UseBridges 1

ClientTransportPlugin obfs4 exec /app/bin/tor_s/obfs4proxy

Bridge obfs4 146.57.248.225:22 10A6CD36A537FCE513A322361547444B393989F0 cert=K1gDtDAIcUfeLqbstggjIw2rtgIKqdIhUlHp82XRqNSq/mtAjp1BIC9vHKJ2FAEpGssTPw iat-mode=2
12 changes: 12 additions & 0 deletions torrc_s/torrc_snowflake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ControlPort 2700
SocksPort 9050
DataDirectory /app/torData/tor_snowflake
Log notice file /app/logs/notice_snowflake.log
SafeLogging 0
RunAsDaemon 0

LogTimeGranularity 1

UseBridges 1
ClientTransportPlugin snowflake exec /app/bin/tor_s/snowflake-client
Bridge snowflake 192.0.2.4:80 8838024498816A039FCBBAB14E6F40A0843051FA fingerprint=8838024498816A039FCBBAB14E6F40A0843051FA url=https://snowflake-broker.torproject.net.global.prod.fastly.net/ front=cdn.sstatic.net ice=stun:stun.l.google.com:19302,stun:stun.antisip.com:3478,stun:stun.bluesip.net:3478,stun:stun.dus.net:3478,stun:stun.epygi.com:3478,stun:stun.sonetel.net:3478,stun:stun.uls.co.za:3478,stun:stun.voipgate.com:3478,stun:stun.voys.nl:3478 utls-imitate=hellorandomizedalpn
15 changes: 15 additions & 0 deletions torrc_s/torrc_tor
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ControlPort 2700
SocksPort 9050
DataDirectory /app/torData/tor_none
Log notice file /app/logs/notice_none.log
SafeLogging 0
RunAsDaemon 0

LogTimeGranularity 1

#UseBridges 1

#ClientTransportPlugin obfs4 exec /app/bin/tor_s/obfs4proxy

#Bridge obfs4 146.57.248.225:22 10A6CD36A537FCE513A322361547444B393989F0 cert=K1gDtDAIcUfeLqbstggjIw2rtgIKqdIhUlHp82XRqNSq/mtAjp1BIC9vHKJ2FAEpGssTPw iat-mode=0

17 changes: 17 additions & 0 deletions torrc_s/torrc_webtunnel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ControlPort 2700
SocksPort 9050
DataDirectory /app/torData/tor_webtunnel
Log notice file /app/logs/notice_webtunnel.log

SafeLogging 0
RunAsDaemon 0

LogTimeGranularity 1

UseBridges 1
ClientTransportPlugin webtunnel exec /app/bin/tor_s/webtunnelClient

Bridge webtunnel 99.121.60.23:443 3BDD7036FAC9CC81ADBA39E88637D5EF87350F1C url=https://speedtest.qs.ee/dI6HDfnDLSUiFV0MaLMEtcmv ver=0.0.1



17 changes: 17 additions & 0 deletions torrc_s/torrc_webtunnel_ipv6
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ControlPort 2700
SocksPort 9050
DataDirectory /app/torData/tor_webtunnel
Log notice file /app/logs/notice_webtunnel.log

SafeLogging 0
RunAsDaemon 0

LogTimeGranularity 1

UseBridges 1
ClientTransportPlugin webtunnel exec /app/bin/tor_s/webtunnelClient

Bridge webtunnel [2001:db8:afc8:4fe0:c021:5377:36bf:e9b7]:443 3BDD7036FAC9CC81ADBA39E88637D5EF87350F1C url=https://speedtest.qs.ee/dI6HDfnDLSUiFV0MaLMEtcmv ver=0.0.1