-
Notifications
You must be signed in to change notification settings - Fork 1
/
bricks
executable file
·333 lines (300 loc) · 10.6 KB
/
bricks
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#!/bin/bash
# BRICKS the Gfwed domains list by @leaskh
listDomain() {
cat $brickFile
}
searchDomain() {
grep "$1" $brickFile
}
addDomain() {
if [ "$1" = '' ]; then
echo 'Domain can not be empty!';
exit 1
fi
echo $1 >> $brickFile
cleanList
}
removeDomain() {
grep -v "$1" $brickFile > $brickFile.temp
mv $brickFile.temp $brickFile
cleanList
}
cleanList() {
sort -u $brickFile -o $brickFile
echo 'Done :)'
}
makePac() {
if [ "$*" = '' ]; then
echo 'Proxy configurations can not be empty!';
exit 1
fi
bricks=''
length=0
opFile=bricks.pac
while read line; do
if [ "$line" != '' ]; then
bricks+="'$line' : 1,"
length=$(( length + 1 ))
fi
done < $brickFile
strPac=$(cat <<EOF
'// BRICKS Pac by @leaskh';
'// https://github.com/leask/bricks';
'// www.leaskh.com, [email protected]';
function FindProxyForURL(url, host) {
var bricks = {
$bricks
'localhost' : 1
};
'// see https://github.com/clowwindy/ChinaDNS/blob/master/chinadns/dnsrelay.py';
var fakeIps = {
'74.125.127.102' : 1,
'74.125.155.102' : 1,
'74.125.39.102' : 1,
'74.125.39.113' : 1,
'209.85.229.138' : 1,
'128.121.126.139' : 1,
'159.106.121.75' : 1,
'169.132.13.103' : 1,
'192.67.198.6' : 1,
'202.106.1.2' : 1,
'202.181.7.85' : 1,
'203.161.230.171' : 1,
'203.98.7.65' : 1,
'207.12.88.98' : 1,
'208.56.31.43' : 1,
'209.145.54.50' : 1,
'209.220.30.174' : 1,
'209.36.73.33' : 1,
'211.94.66.147' : 1,
'213.169.251.35' : 1,
'216.221.188.182' : 1,
'216.234.179.13' : 1,
'243.185.187.39' : 1,
'37.61.54.158' : 1,
'4.36.66.178' : 1,
'46.82.174.68' : 1,
'59.24.3.173' : 1,
'64.33.88.161' : 1,
'64.33.99.47' : 1,
'64.66.163.251' : 1,
'65.104.202.252' : 1,
'65.160.219.113' : 1,
'66.45.252.237' : 1,
'72.14.205.104' : 1,
'72.14.205.99' : 1,
'78.16.49.15' : 1,
'8.7.198.45' : 1,
'93.46.8.89' : 1
};
var safePorts = {
5223 : 1,
3478 : 1,
3479 : 1,
3480 : 1,
3481 : 1,
3482 : 1,
3483 : 1,
3484 : 1,
3485 : 1,
3486 : 1,
3487 : 1,
3488 : 1,
3489 : 1,
3490 : 1,
3491 : 1,
3492 : 1,
3493 : 1,
3494 : 1,
3495 : 1,
3496 : 1,
3497 : 1,
16384 : 1,
16385 : 1,
16386 : 1,
16387 : 1,
16393 : 1,
16394 : 1,
16395 : 1,
16396 : 1,
16397 : 1,
16398 : 1,
16399 : 1,
16400 : 1,
16401 : 1,
16402 : 1
};
var proxy = '$*';
function testDomain(target, domains) {
var hasOwnProperty = Object.hasOwnProperty;
var suffix;
var pos = target.lastIndexOf('.');
pos = target.lastIndexOf('.', pos - 1);
while(true) {
if (pos <= 0) {
if (hasOwnProperty.call(domains, target)) {
return true;
} else {
return false;
}
}
suffix = target.substring(pos + 1);
if (hasOwnProperty.call(domains, suffix)) {
return true;
}
pos = target.lastIndexOf('.', pos - 1);
}
}
if (isPlainHostName(host)
|| host === '127.0.0.1'
|| host === 'localhost') {
return 'DIRECT';
}
if (testDomain(host, bricks)) {
return proxy;
}
if (safePorts[host.split(':')[1]]) {
return 'DIRECT';
}
'// var strIp = dnsResolve(host);';
'// if (!strIp) {';
'// return proxy;';
'// }';
'// if (fakeIps[strIp]) {';
'// return proxy;';
'// }';
return 'DIRECT';
}
EOF
)
echo $strPac > $opFile
echo 'Done :)'
echo "Rules: $length items."
echo "Usage: Use the newly created $opFile as your web browser's automatic"
echo 'PAC(Proxy auto-config) file.'
}
pacServer() {
makePac $*
echo 'PAC is now serving at: 0.0.0.0:8000'
echo 'Check it out with: $ curl http://127.0.0.1:8000/bricks.pac'
python -m SimpleHTTPServer
}
makeSurge() {
proxyKey='Proxy';
proxyValue='custom, 1.2.3.4, 443, rc4-md5, password, http://surge.run/SSEncrypt.module';
if [ "$*" != '' ]; then
proxyValue="$*"
fi
bricks=''
length=0
opFile=bricks_surge.conf
while read line; do
if [ "$line" != '' ]; then
bricks+="DOMAIN-SUFFIX,$line,$proxyKey"$'\n'
length=$(( length + 1 ))
fi
done < $brickFile
strConf=$(cat <<EOF
# BRICKS Surge configuration file by @leaskh';
# Get Info: https://github.com/leask/bricks
# Based on: http://surge.run/config-example/ss-module.conf
[General]
loglevel = notify
bypass-system = true
skip-proxy = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, localhost, *.local
# dns-server = 8.8.8.8, 8.8.4.4
bypass-tun = 0.0.0.0/8, 1.0.0.0/9, 1.160.0.0/11, 1.192.0.0/11, 10.0.0.0/8, 14.0.0.0/11, 14.96.0.0/11, 14.128.0.0/11, 14.192.0.0/11, 27.0.0.0/10, 27.96.0.0/11, 27.128.0.0/9, 36.0.0.0/10, 36.96.0.0/11, 36.128.0.0/9, 39.0.0.0/11, 39.64.0.0/10, 39.128.0.0/10, 42.0.0.0/8, 43.224.0.0/11, 45.64.0.0/10, 47.64.0.0/10, 49.0.0.0/9, 49.128.0.0/11, 49.192.0.0/10, 54.192.0.0/11, 58.0.0.0/9, 58.128.0.0/11, 58.192.0.0/10, 59.32.0.0/11, 59.64.0.0/10, 59.128.0.0/9, 60.0.0.0/10, 60.160.0.0/11, 60.192.0.0/10, 61.0.0.0/10, 61.64.0.0/11, 61.128.0.0/10, 61.224.0.0/11, 100.64.0.0/10, 101.0.0.0/9, 101.128.0.0/11, 101.192.0.0/10, 103.0.0.0/10, 103.192.0.0/10, 106.0.0.0/9, 106.224.0.0/11, 110.0.0.0/7, 112.0.0.0/9, 112.128.0.0/11, 112.192.0.0/10, 113.0.0.0/9, 113.128.0.0/11, 113.192.0.0/10, 114.0.0.0/9, 114.128.0.0/11, 114.192.0.0/10, 115.0.0.0/8, 116.0.0.0/8, 117.0.0.0/9, 117.128.0.0/10, 118.0.0.0/11, 118.64.0.0/10, 118.128.0.0/9, 119.0.0.0/9, 119.128.0.0/10, 119.224.0.0/11, 120.0.0.0/10, 120.64.0.0/11, 120.128.0.0/11, 120.192.0.0/10, 121.0.0.0/9, 121.192.0.0/10, 122.0.0.0/7, 124.0.0.0/8, 125.0.0.0/9, 125.160.0.0/11, 125.192.0.0/10, 127.0.0.0/8, 139.0.0.0/11, 139.128.0.0/9, 140.64.0.0/11, 140.128.0.0/11, 140.192.0.0/10, 144.0.0.0/10, 144.96.0.0/11, 144.224.0.0/11, 150.0.0.0/11, 150.96.0.0/11, 150.128.0.0/11, 150.192.0.0/10, 152.96.0.0/11, 153.0.0.0/10, 153.96.0.0/11, 157.0.0.0/10, 157.96.0.0/11, 157.128.0.0/11, 157.224.0.0/11, 159.224.0.0/11, 161.192.0.0/11, 162.96.0.0/11, 163.0.0.0/10, 163.96.0.0/11, 163.128.0.0/10, 163.192.0.0/11, 166.96.0.0/11, 167.128.0.0/10, 167.192.0.0/11, 168.160.0.0/11, 169.254.0.0/16, 171.0.0.0/9, 171.192.0.0/11, 172.16.0.0/12, 175.0.0.0/9, 175.128.0.0/10, 180.64.0.0/10, 180.128.0.0/9, 182.0.0.0/8, 183.0.0.0/10, 183.64.0.0/11, 183.128.0.0/9, 192.0.0.0/24, 192.0.2.0/24, 192.88.99.0/24, 192.96.0.0/11, 192.160.0.0/11, 198.18.0.0/15, 198.51.100.0/24, 202.0.0.0/9, 202.128.0.0/10, 202.192.0.0/11, 203.0.0.0/9, 203.128.0.0/10, 203.192.0.0/11, 210.0.0.0/10, 210.64.0.0/11, 210.160.0.0/11, 210.192.0.0/11, 211.64.0.0/10, 211.128.0.0/10, 218.0.0.0/9, 218.160.0.0/11, 218.192.0.0/10, 219.64.0.0/11, 219.128.0.0/11, 219.192.0.0/10, 220.96.0.0/11, 220.128.0.0/9, 221.0.0.0/11, 221.96.0.0/11, 221.128.0.0/9, 222.0.0.0/8, 223.0.0.0/11, 223.64.0.0/10, 223.128.0.0/9, 192.168.0.0/16
[Proxy]
Proxy = $proxyValue
[Rule]
DOMAIN-KEYWORD,google,Proxy,force-remote-dns
DOMAIN-KEYWORD,facebook,Proxy,force-remote-dns
DOMAIN-KEYWORD,youtube,Proxy,force-remote-dns
DOMAIN-KEYWORD,twitter,Proxy,force-remote-dns
DOMAIN-KEYWORD,instagram,Proxy,force-remote-dns
DOMAIN-KEYWORD,gmail,Proxy,force-remote-dns
DOMAIN-KEYWORD,blogspot,Proxy
DOMAIN-SUFFIX,twimg.com,Proxy,force-remote-dns
# Remove these lines below if you don't have trouble accessing Apple resources
# Disabled by @Leaskh {
# DOMAIN-SUFFIX,ls.apple.com,DIRECT
# DOMAIN-SUFFIX,lcdn-registration.apple.com,DIRECT
# DOMAIN-SUFFIX,apple.com,Proxy
# DOMAIN-SUFFIX,mzstatic.com,Proxy
# DOMAIN-SUFFIX,itunes.com,Proxy
# DOMAIN-SUFFIX,icloud.com,Proxy
# }
$bricks
// Telegram
IP-CIDR,91.108.56.0/22,Proxy,no-resolve
IP-CIDR,91.108.4.0/22,Proxy,no-resolve
IP-CIDR,109.239.140.0/24,Proxy,no-resolve
IP-CIDR,149.154.160.0/20,Proxy,no-resolve
// LAN
IP-CIDR,192.168.0.0/16,DIRECT
IP-CIDR,10.0.0.0/8,DIRECT
IP-CIDR,172.16.0.0/12,DIRECT
IP-CIDR,127.0.0.0/8,DIRECT
GEOIP,CN,DIRECT
FINAL,Proxy
EOF
)
echo "$strConf" > $opFile
echo 'Done :)'
echo "Rules: $length items."
echo "Usage: Import the newly created $opFile to your Surge app."
}
surgeServer() {
makeSurge $*
echo 'Surge configuration file is now serving at:'
echo 'http://127.0.0.1:8000/bricks_surge.conf'
python -m SimpleHTTPServer
}
showHelp() {
echo ' ____________________________________________ '
echo '| Twitter|________|________|________|__Vimeo_|'
echo '|________|Facebook|________|________|________|'
echo '|________|________|________|________|________|'
echo '|________|________|________|_Google_|________|'
echo '|YouTube_| |________|________|________|'
echo '| |'
echo '| * |'
echo '| |'
echo '| _______ |'
echo '| |_______| |'
echo '|____________________________________________|'
echo ''
echo 'BRICKS is a list for all the domains blocked by the Chinese GFW (Great-Fire-Wall).'
echo ''
echo '- list : List all the domains in BRICKS'
echo '- search : Search for domains in BRICKS'
echo '- add : Add domain into BRICKS'
echo '- remove : Remove domain from BRICKS'
echo '- clean : Sort & uniq domains in BRICKS'
echo '- makpac : Make PAC file with BRICKS'
echo '- pacsrv : Make PAC file and launch HTTP server'
echo '- maksurge : Make Surge configuration file'
echo '- surgesrv : Make Surge conf-file and launch HTTP server'
echo '- help : Show this infos'
}
unknownCommand() {
showHelp
exit 1
}
# BlackBox configurations
brickFile=./gfw.bricks
# Main logic
case "$1" in
'list' ) listDomain ;;
'search' ) searchDomain $2;;
'add' ) addDomain $2;;
'remove' ) removeDomain $2;;
'clean' ) cleanList ;;
'makpac' ) makePac $2;;
'pacsrv' ) pacServer $2;;
'maksurge') makeSurge $2;;
'surgesrv') surgeServer $2;;
'help' ) showHelp ;;
* ) unknownCommand ;;
esac
exit 0