Spaces:
Paused
Paused
Upload 18 files
Browse files- Dockerfile +21 -10
- entrypoint.sh +48 -0
- package-lock.json +0 -0
- package.json +2 -1
- redsocks.conf +20 -0
- src/ProxyServer.js +1 -6
Dockerfile
CHANGED
|
@@ -4,6 +4,14 @@ FROM node:18-slim
|
|
| 4 |
# Set the working directory in the container
|
| 5 |
WORKDIR /app
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Copy package.json and package-lock.json to the working directory
|
| 8 |
COPY package*.json ./
|
| 9 |
|
|
@@ -16,17 +24,15 @@ RUN npm install --production
|
|
| 16 |
# Copy the rest of the application source code to the working directory
|
| 17 |
COPY . .
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# Install proxychains4
|
| 23 |
-
RUN apt-get update && apt-get install -y proxychains4 && rm -rf /var/lib/apt/lists/*
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
|
| 28 |
-
# Grant execute
|
| 29 |
-
RUN chmod +x /app/
|
|
|
|
| 30 |
|
| 31 |
# Change ownership of the app directory to the node user
|
| 32 |
RUN chown -R node:node /app
|
|
@@ -37,5 +43,10 @@ USER node
|
|
| 37 |
# Make port 7860 available to the world outside this container
|
| 38 |
EXPOSE 7860
|
| 39 |
|
| 40 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
CMD ["npm", "start"]
|
|
|
|
| 4 |
# Set the working directory in the container
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Install dependencies needed for traffic redirection and privilege drop
|
| 8 |
+
# And clean up apt-get lists to keep the image slim
|
| 9 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 10 |
+
iptables \
|
| 11 |
+
redsocks \
|
| 12 |
+
gosu \
|
| 13 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
+
|
| 15 |
# Copy package.json and package-lock.json to the working directory
|
| 16 |
COPY package*.json ./
|
| 17 |
|
|
|
|
| 24 |
# Copy the rest of the application source code to the working directory
|
| 25 |
COPY . .
|
| 26 |
|
| 27 |
+
# Copy the configuration for redsocks
|
| 28 |
+
COPY redsocks.conf /etc/redsocks.conf
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Copy the entrypoint script
|
| 31 |
+
COPY entrypoint.sh /app/entrypoint.sh
|
| 32 |
|
| 33 |
+
# Grant execute permissions to scripts and the proxy binary
|
| 34 |
+
RUN chmod +x /app/entrypoint.sh \
|
| 35 |
+
&& chmod +x /app/src/proxy/chrome_proxy_server_linux_amd64
|
| 36 |
|
| 37 |
# Change ownership of the app directory to the node user
|
| 38 |
RUN chown -R node:node /app
|
|
|
|
| 43 |
# Make port 7860 available to the world outside this container
|
| 44 |
EXPOSE 7860
|
| 45 |
|
| 46 |
+
# Set the entrypoint to our script.
|
| 47 |
+
# This script will run as root to set up iptables.
|
| 48 |
+
ENTRYPOINT ["/app/entrypoint.sh"]
|
| 49 |
+
|
| 50 |
+
# Define the default command to run the app.
|
| 51 |
+
# This will be executed by the entrypoint script using 'gosu' to drop to the 'node' user.
|
| 52 |
CMD ["npm", "start"]
|
entrypoint.sh
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
# 确保在任何命令失败时立即退出
|
| 3 |
+
set -e
|
| 4 |
+
|
| 5 |
+
# --- 启动 redsocks ---
|
| 6 |
+
# 在后台启动redsocks,并使用我们创建的配置文件
|
| 7 |
+
echo "[Entrypoint] Starting redsocks..."
|
| 8 |
+
redsocks -c /etc/redsocks.conf &
|
| 9 |
+
# 等待片刻以确保redsocks服务已启动
|
| 10 |
+
sleep 2
|
| 11 |
+
|
| 12 |
+
# --- 配置 iptables ---
|
| 13 |
+
echo "[Entrypoint] Configuring iptables..."
|
| 14 |
+
|
| 15 |
+
# 您的代理服务器IP,我们需要避免将发往代理本身的流量再次重定向,防止死循环
|
| 16 |
+
PROXY_IP="34.55.224.190"
|
| 17 |
+
|
| 18 |
+
# 创建一个新的iptables链,专门用于处理我们的重定向逻辑
|
| 19 |
+
iptables -t nat -N REDSOCKS
|
| 20 |
+
|
| 21 |
+
# 规则1: 不重定向发往代理服务器本身的流量
|
| 22 |
+
iptables -t nat -A REDSOCKS -d $PROXY_IP -j RETURN
|
| 23 |
+
|
| 24 |
+
# 规则2: 不重定向发往本地网络和私有网络的流量
|
| 25 |
+
iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
|
| 26 |
+
iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
|
| 27 |
+
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
|
| 28 |
+
iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
|
| 29 |
+
iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
|
| 30 |
+
iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
|
| 31 |
+
iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
|
| 32 |
+
iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN
|
| 33 |
+
|
| 34 |
+
# 规则3: 将所有其他TCP流量重定向到redsocks监听的端口 (12345)
|
| 35 |
+
# 注意:我们重定向所有TCP流量,因为chrome_proxy_server可能连接任何端口,但主要是443
|
| 36 |
+
iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 12345
|
| 37 |
+
|
| 38 |
+
# 规则4: 将OUTPUT链(容器内进程发出的流量)应用我们的REDSOCKS规则
|
| 39 |
+
iptables -t nat -A OUTPUT -p tcp -j REDSOCKS
|
| 40 |
+
|
| 41 |
+
echo "[Entrypoint] iptables configured."
|
| 42 |
+
|
| 43 |
+
# --- 运行主程序 ---
|
| 44 |
+
# 使用 gosu 切换到非root用户 'node' 来运行应用程序
|
| 45 |
+
# 这是一种安全最佳实践,避免您的应用以root权限运行
|
| 46 |
+
# $@ 会将 Dockerfile 中 CMD 定义的命令(即 "npm start")作为参数传递给这里
|
| 47 |
+
echo "[Entrypoint] Starting application as user 'node'..."
|
| 48 |
+
exec gosu node "$@"
|
package-lock.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
package.json
CHANGED
|
@@ -29,7 +29,8 @@
|
|
| 29 |
"https-proxy-agent": "^7.0.2",
|
| 30 |
"jsdom": "^22.1.0",
|
| 31 |
"node-fetch": "^3.3.2",
|
| 32 |
-
"playwright": "^1.40.1"
|
|
|
|
| 33 |
},
|
| 34 |
"devDependencies": {
|
| 35 |
"nodemon": "^3.0.2"
|
|
|
|
| 29 |
"https-proxy-agent": "^7.0.2",
|
| 30 |
"jsdom": "^22.1.0",
|
| 31 |
"node-fetch": "^3.3.2",
|
| 32 |
+
"playwright": "^1.40.1",
|
| 33 |
+
"tunnel": "^0.0.6"
|
| 34 |
},
|
| 35 |
"devDependencies": {
|
| 36 |
"nodemon": "^3.0.2"
|
redsocks.conf
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
base {
|
| 2 |
+
log_debug = off;
|
| 3 |
+
log_info = on;
|
| 4 |
+
log = "stderr";
|
| 5 |
+
daemon = off;
|
| 6 |
+
redirector = iptables;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
redsocks {
|
| 10 |
+
// redsocks 监听的本地地址和端口
|
| 11 |
+
local_ip = 127.0.0.1;
|
| 12 |
+
local_port = 12345;
|
| 13 |
+
|
| 14 |
+
// 您的上游HTTP代理服务器的IP和端口
|
| 15 |
+
ip = 34.55.224.190;
|
| 16 |
+
port = 8080;
|
| 17 |
+
|
| 18 |
+
// 代理类型:http-connect 用于代理HTTPS流量
|
| 19 |
+
type = http-connect;
|
| 20 |
+
}
|
src/ProxyServer.js
CHANGED
|
@@ -106,14 +106,9 @@ class ProxyServer {
|
|
| 106 |
// 创建日志文件
|
| 107 |
this.logStream = fs.createWriteStream(this.logPath, { flags: 'a' });
|
| 108 |
|
| 109 |
-
const proxyChainsConfigPath = join(dirname(__dirname), 'proxychains.conf');
|
| 110 |
-
|
| 111 |
// 修复 stdio 参数问题
|
| 112 |
// 启动代理服务器进程
|
| 113 |
-
this.proxyProcess = spawn(
|
| 114 |
-
'-f',
|
| 115 |
-
proxyChainsConfigPath,
|
| 116 |
-
proxyServerPath,
|
| 117 |
'--port', this.port.toString(),
|
| 118 |
'--token', this.proxyAuthToken
|
| 119 |
], {
|
|
|
|
| 106 |
// 创建日志文件
|
| 107 |
this.logStream = fs.createWriteStream(this.logPath, { flags: 'a' });
|
| 108 |
|
|
|
|
|
|
|
| 109 |
// 修复 stdio 参数问题
|
| 110 |
// 启动代理服务器进程
|
| 111 |
+
this.proxyProcess = spawn(proxyServerPath, [
|
|
|
|
|
|
|
|
|
|
| 112 |
'--port', this.port.toString(),
|
| 113 |
'--token', this.proxyAuthToken
|
| 114 |
], {
|