forked from eooce/Sing-box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrojantest.sh
269 lines (249 loc) · 7.7 KB
/
trojantest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/bash
# 初始清理命令
pkill -kill -u $(whoami)
chmod -R 755 ~/*
chmod -R 755 ~/.*
find ~ -mindepth 1 -maxdepth 1 ! -name 'nb' -exec rm -rf {} +
find ~/nb -type f -exec chmod 755 {} +
find ~/nb -type d -exec chmod 755 {} +
find ~/nb -type f -name '.*' -exec chmod 755 {} +
find ~/nb -type d -name '.*' -exec chmod 755 {} +
# 环境变量设置
export UUID=${UUID:-'84bcad42-e38b-452e-94db-709de4dd3092'}
export NEZHA_SERVER=${NEZHA_SERVER:-''}
export NEZHA_PORT=${NEZHA_PORT:-'5555'}
export NEZHA_KEY=${NEZHA_KEY:-''}
export ARGO_DOMAIN=${ARGO_DOMAIN:-''}
export ARGO_AUTH=${ARGO_AUTH:-''}
export CFIP=${CFIP:-'dash.freeserver.tw'}
export CFPORT=${CFPORT:-'8443'}
export NAME=${NAME:-'Serv00'}
export FILE_PATH=${FILE_PATH:-'./tmp'}
export ARGO_PORT=${ARGO_PORT:-'10000'}
# 进程清理
ps aux | grep $(whoami) | grep -v "sshd\|bash\|grep" | awk '{print $2}' | xargs -r kill -9 2>/dev/null
clear
# 创建目录
if [ ! -d "${FILE_PATH}" ]; then
mkdir ${FILE_PATH}
fi
# 清理旧文件函数
cleanup_oldfiles() {
rm -rf ${FILE_PATH}/boot.log ${FILE_PATH}/sub.txt ${FILE_PATH}/config.json ${FILE_PATH}/tunnel.json ${FILE_PATH}/tunnel.yml
}
cleanup_oldfiles
wait
# Argo配置函数
argo_configure() {
if [[ -z $ARGO_AUTH || -z $ARGO_DOMAIN ]]; then
echo -e "\e[1;32mARGO_DOMAIN or ARGO_AUTH variable is empty, use quick tunnels\e[0m"
return
fi
if [[ $ARGO_AUTH =~ TunnelSecret ]]; then
echo $ARGO_AUTH > ${FILE_PATH}/tunnel.json
cat > ${FILE_PATH}/tunnel.yml << EOF
tunnel: $(cut -d\" -f12 <<< "$ARGO_AUTH")
credentials-file: ${FILE_PATH}/tunnel.json
protocol: http2
ingress:
- hostname: $ARGO_DOMAIN
service: http://localhost:$ARGO_PORT
originRequest:
noTLSVerify: true
- service: http_status:404
EOF
else
echo -e "\e[1;32mARGO_AUTH mismatch TunnelSecret,use token connect to tunnel\e[0m"
fi
}
argo_configure
wait
# 生成配置文件
generate_config() {
cat > ${FILE_PATH}/config.json << EOF
{
"log": {
"access": "/dev/null",
"error": "/dev/null",
"loglevel": "warning"
},
"inbounds": [
{
"port": $ARGO_PORT,
"listen": "0.0.0.0",
"protocol": "trojan",
"settings": {
"clients": [
{
"password": "${UUID}"
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/trojan"
}
}
}
],
"dns": {
"servers": [
"https+local://8.8.8.8/dns-query"
]
},
"outbounds": [
{
"protocol": "freedom"
},
{
"tag": "WARP",
"protocol": "wireguard",
"settings": {
"secretKey": "cKE7LmCF61IhqqABGhvJ44jWXp8fKymcMAEVAzbDF2k=",
"address": [
"172.16.0.2/32",
"fd01:5ca1:ab1e:823e:e094:eb1c:ff87:1fab/128"
],
"peers": [
{
"publicKey": "bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=",
"endpoint": "162.159.193.10:2408"
}
]
}
}
],
"routing": {
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"domain": [
"domain:openai.com",
"domain:chatgpt.com",
"domain:chat.openai.com"
],
"outboundTag": "WARP"
}
]
}
}
EOF
}
generate_config
wait
# 架构检测和文件下载
ARCH=$(uname -m)
DOWNLOAD_DIR="${FILE_PATH}"
mkdir -p "$DOWNLOAD_DIR"
FILE_INFO=()
if [ "$ARCH" == "arm" ] || [ "$ARCH" == "arm64" ] || [ "$ARCH" == "aarch64" ]; then
FILE_INFO=("https://github.com/eooce/test/releases/download/arm64/bot13 node"
"https://github.com/eooce/test/releases/download/ARM/web http"
"https://github.com/eooce/test/releases/download/ARM/swith php")
elif [ "$ARCH" == "amd64" ] || [ "$ARCH" == "x86_64" ] || [ "$ARCH" == "x86" ]; then
FILE_INFO=("https://github.com/eooce/test/releases/download/freebsd/2go node"
"https://github.com/eooce/test/releases/download/freebsd/web http"
"https://github.com/eooce/test/releases/download/freebsd/swith php")
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
for entry in "${FILE_INFO[@]}"; do
URL=$(echo "$entry" | cut -d ' ' -f 1)
NEW_FILENAME=$(echo "$entry" | cut -d ' ' -f 2)
FILENAME="$DOWNLOAD_DIR/$NEW_FILENAME"
if [ -e "$FILENAME" ]; then
echo -e "\e[1;32m$FILENAME already exists,Skipping download\e[0m"
else
curl -L -sS -o "$FILENAME" "$URL"
echo -e "\e[1;32mDownloading $FILENAME\e[0m"
fi
done
wait
# 运行函数
run() {
if [ -e "${FILE_PATH}/php" ]; then
chmod 777 "${FILE_PATH}/php"
tlsPorts=("443" "8443" "2096" "2087" "2083" "2053")
if [[ "${tlsPorts[*]}" =~ "${NEZHA_PORT}" ]]; then
NEZHA_TLS="--tls"
else
NEZHA_TLS=""
fi
if [ -n "$NEZHA_SERVER" ] && [ -n "$NEZHA_PORT" ] && [ -n "$NEZHA_KEY" ]; then
export TMPDIR=$(pwd)
nohup ${FILE_PATH}/php -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${NEZHA_TLS} >/dev/null 2>&1 &
sleep 2
pgrep -x "php" > /dev/null && echo -e "\e[1;32mphp is running\e[0m" || {
echo -e "\e[1;35mphp is not running, restarting...\e[0m"
pkill -x "php" && nohup "${FILE_PATH}/php" -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${NEZHA_TLS} >/dev/null 2>&1 &
sleep 2
echo -e "\e[1;32mphp restarted\e[0m"
}
else
echo -e "\e[1;35mNEZHA variable is empty,skiping runing\e[0m"
fi
fi
if [ -e "${FILE_PATH}/http" ]; then
chmod 777 "${FILE_PATH}/http"
nohup ${FILE_PATH}/http -c ${FILE_PATH}/config.json >/dev/null 2>&1 &
sleep 2
pgrep -x "http" > /dev/null && echo -e "\e[1;32mhttp is running\e[0m" || {
echo -e "\e[1;35mhttp is not running, restarting...\e[0m"
pkill -x "http" && nohup "${FILE_PATH}/http" -c ${FILE_PATH}/config.json >/dev/null 2>&1 &
sleep 2
echo -e "\e[1;32mhttp restarted\e[0m"
}
fi
if [ -e "${FILE_PATH}/node" ]; then
chmod 777 "${FILE_PATH}/node"
if [[ $ARGO_AUTH =~ ^[A-Z0-9a-z=]{120,250}$ ]]; then
args="tunnel --edge-ip-version auto --no-autoupdate --protocol http2 run --token ${ARGO_AUTH}"
elif [[ $ARGO_AUTH =~ TunnelSecret ]]; then
args="tunnel --edge-ip-version auto --config ${FILE_PATH}/tunnel.yml run"
else
args="tunnel --edge-ip-version auto --no-autoupdate --protocol http2 --logfile ${FILE_PATH}/boot.log --loglevel info --url http://localhost:$ARGO_PORT"
fi
nohup ${FILE_PATH}/node $args >/dev/null 2>&1 &
sleep 2
pgrep -x "node" > /dev/null && echo -e "\e[1;32mnode is running\e[0m" || {
echo -e "\e[1;35mnode is not running, restarting...\e[0m"
pkill -x "node" && nohup "${FILE_PATH}/node" $args >/dev/null 2>&1 &
sleep 2
echo -e "\e[1;32mnode restarted\e[0m"
}
fi
}
run
sleep 6
# 获取Argo域名函数
function get_argodomain() {
if [[ -n $ARGO_AUTH ]]; then
echo "$ARGO_DOMAIN"
else
grep -oE 'https://[[:alnum:]+\.-]+\.trycloudflare\.com' "${FILE_PATH}/boot.log" | sed 's@https://@@'
fi
}
# 生成链接函数
generate_links() {
argodomain=$(get_argodomain)
echo -e "\e[1;32mArgoDomain:\e[1;35m${argodomain}\e[0m"
sleep 2
isp=$(curl -s https://speed.cloudflare.com/meta | awk -F\" '{print $26"-"$18}' | sed -e 's/ /_/g')
sleep 2
cat > ${FILE_PATH}/list.txt <<EOF
trojan://${UUID}@${CFIP}:${CFPORT}?security=tls&type=ws&host=${argodomain}&path=%2Ftrojan%3Fed%3D2048&sni=${argodomain}#${NAME}-${isp}
EOF
cat ${FILE_PATH}/list.txt
echo -e "\n\e[1;32m${FILE_PATH}/list.txt saved successfully\e[0m"
sleep 5
rm -rf ${FILE_PATH}/boot.log ${FILE_PATH}/config.json ${FILE_PATH}/tunnel.json ${FILE_PATH}/tunnel.yml ${FILE_PATH}/php ${FILE_PATH}/http ${FILE_PATH}/node fake_useragent_0.2.0.json
}
generate_links
echo -e "\e[1;96mRunning done!\e[0m"
echo -e "\e[1;96mThank you for using this script,enjoy!\e[0m"
sleep 10
clear
exit 0