-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathba
240 lines (207 loc) · 5.73 KB
/
ba
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
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
setup_ipv6() {
echo "Setup IPv6..."
ip -6 addr flush dev eth0
ip -6 addr flush dev ens33
bash <(curl -s "https://raw.githubusercontent.com/quanglinh0208/3proxy/main/ipv6.sh")
}
setup_ipv6
random() {
tr </dev/urandom -dc A-Za-z0-9 | head -c5
echo
}
array=(1 2 3 4 5 6 7 8 9 0 a b c d e f)
gen64() {
ip64() {
echo "${array[$RANDOM % 16]}${array[$RANDOM % 16]}${array[$RANDOM % 16]}${array[$RANDOM % 16]}"
}
echo "$1:$(ip64):$(ip64):$(ip64):$(ip64)"
}
install_3proxy() {
echo "Installing 3proxy"
URL="https://github.com/z3APA3A/3proxy/archive/refs/tags/0.9.3.tar.gz"
wget -qO- $URL | tar -xz >/dev/null 2>&1
cd 3proxy-0.9.3
make -f Makefile.Linux >/dev/null 2>&1
mkdir -p /usr/local/etc/3proxy/{bin,logs,stat} >/dev/null 2>&1
cp src/3proxy /usr/local/etc/3proxy/bin/ >/dev/null 2>&1
systemctl link /usr/lib/systemd/system/3proxy.service
systemctl daemon-reload
systemctl enable 3proxy
# Increase system limits
echo "* hard nofile 999999" >> /etc/security/limits.conf
echo "* soft nofile 999999" >> /etc/security/limits.conf
echo "fs.file-max = 1000000" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 1024 65000" >> /etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf
echo "net.core.somaxconn = 4096" >> /etc/sysctl.conf
echo "net.core.netdev_max_backlog = 4096" >> /etc/sysctl.conf
echo "net.ipv6.conf.eth0.proxy_ndp=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.proxy_ndp=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.default.forwarding=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf
echo "net.ipv6.ip_nonlocal_bind = 1" >> /etc/sysctl.conf
systemctl stop firewalld
systemctl disable firewalld
sysctl -p
cd $WORKDIR
}
gen_3proxy() {
cat <<EOF
daemon
maxconn 10000
nserver 1.1.1.1
nserver 8.8.4.4
nserver 2001:4860:4860::8888
nserver 2001:4860:4860::8844
nscache 65536
timeouts 1 5 30 60 180 1800 15 60
setgid 65535
setuid 65535
stacksize 6291456
flush
$(awk -F "/" '{print "\n" \
"allow *" $1 "\n" \
"proxy -6 -n -a -p" $4 " -i" $3 " -e"$5"\n" \
"flush\n"}' ${WORKDATA})
EOF
}
gen_proxy_file_for_user() {
cat >proxy.txt <<EOF
$(awk -F "/" '{print $3 ":" $4 }' ${WORKDATA})
EOF
}
gen_data() {
seq $FIRST_PORT $LAST_PORT | while read port; do
echo "//$IP4/$port/$(gen64 $IP6)"
echo "$IP4:$port" >> "$WORKDIR/ipv4.txt"
new_ipv6=$(gen64 $IP6)
echo "$new_ipv6" >> "$WORKDIR/ipv6.txt"
done
}
gen_iptables() {
cat <<EOF
$(awk -F "/" '{print "iptables -I INPUT -p tcp --dport " $4 " -m state --state NEW -j ACCEPT"}' ${WORKDATA})
EOF
}
gen_ifconfig() {
cat <<EOF
$(awk -F "/" '{print "ifconfig eth0 inet6 add " $5 "/64"}' ${WORKDATA})
EOF
}
setup_environment() {
echo "Installing necessary packages"
yum -y install gcc net-tools bsdtar zip make >/dev/null
}
rotate_ipv6() {
echo "Rotating IPv6 addresses..."
IP6=$(curl -6 -s icanhazip.com | cut -f1-4 -d':')
gen_data >$WORKDIR/data.txt
gen_ifconfig >$WORKDIR/boot_ifconfig.sh
bash $WORKDIR/boot_ifconfig.sh
echo "Restarting 3proxy service..."
systemctl restart 3proxy
restart_result=$?
if [ $restart_result -eq 0 ]; then
echo "IPv6 addresses rotated successfully."
echo "[OK]: Thành công"
else
echo "Failed to rotate IPv6 addresses!"
echo "[ERROR]: Thất bại!"
exit 1
fi
}
download_proxy() {
cd $WORKDIR || exit 1
curl -F "file=@proxy.txt" https://transfer.sh
}
echo "working folder = /home/new"
WORKDIR="/home/new"
WORKDATA="${WORKDIR}/data.txt"
mkdir -p $WORKDIR && cd $WORKDIR
IP4=$(curl -4 -s icanhazip.com)
IP6=$(curl -6 -s icanhazip.com | cut -f1-4 -d':')
echo "Internal ip = ${IP4}. External subnet for IPv6 = ${IP6}"
FIRST_PORT=48000
LAST_PORT=50000
setup_environment
install_3proxy
gen_data >$WORKDIR/data.txt
gen_iptables >$WORKDIR/boot_iptables.sh
gen_ifconfig >$WORKDIR/boot_ifconfig.sh
chmod +x $WORKDIR/boot_*.sh /etc/rc.local
gen_3proxy >/usr/local/etc/3proxy/3proxy.cfg
cat >>/etc/rc.local <<EOF
systemctl start NetworkManager.service
ifup eth0
killall 3proxy
service 3proxy start
bash ${WORKDIR}/boot_iptables.sh
bash ${WORKDIR}/boot_ifconfig.sh
ulimit -n 65535
/usr/local/etc/3proxy/bin/3proxy /usr/local/etc/3proxy/3proxy.cfg &
EOF
cat <<EOF >/etc/systemd/system/3proxy.service
[Unit]
Description=3proxy Proxy Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/etc/3proxy/bin/3proxy /usr/local/etc/3proxy/3proxy.cfg
ExecReload=/bin/kill -HUP \$MAINPID
ExecStop=/bin/kill -TERM \$MAINPID
Restart=always
RestartSec=5
LimitNOFILE=1000000
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF >/etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
EOF
chmod +x /etc/rc.local
bash /etc/rc.local
gen_proxy_file_for_user
rm -rf /root/3proxy-0.9.3
echo "Starting Proxy"
echo "So Luong IPv6 Hien Tai:"
ip -6 addr | grep inet6 | wc -l
while true; do
echo "1. Thiết Lập Lại 3proxy"
echo "2. Xoay IPV6"
echo "3. Download proxy"
echo "4. Exit"
echo -n "Enter your choice: "
read choice
case $choice in
1)
install_3proxy
;;
2)
rotate_ipv6
sleep 3600
;;
3)
download_proxy
;;
4)
echo "Exiting..."
exit 0
;;
*)
echo "Invalid choice. Please try again."
;;
esac
done