-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathanon-service.sh
1961 lines (1957 loc) · 63.2 KB
/
anon-service.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
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# ####################################################################
# anon-service.sh
# version 2.4
#
# Transparent proxy through Tor and optionally DNSCrypt with
# Anonymized-DNS feature enabled.
#
# Copyright (C) 2020-2024 Bit4mind
#
# GNU GENERAL PUBLIC LICENSE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# #####################################################################
export root=/home/anon-service
owner=anon-service
version="2.4"
repo=/etc/apt/sources.list.d/tor.list
## DNSCrypt-proxy release
dnscrel="2.1.5"
## If necessary, change the path according to your system
export netman=/etc/NetworkManager/NetworkManager.conf
tor=/etc/tor/torrc
unbound=/etc/unbound/unbound.conf
##
## Interactive menu
##
_menu(){
clear
printf '%s\n' " ▄▄▄ ███▄ █ ▒█████ ███▄ █ "
printf '%s\n' " ▒████▄ ██ ▀█ █▒██▒ ██▒ ██ ▀█ █ "
printf '%s\n' " ▒██ ▀█▄ ▓██ ▀█ ██▒██░ ██▒▓██ ▀█ ██▒ "
printf '%s\n' " ░██▄▄▄▄██▓██▒ ▐▌██▒██ ██░▓██▒ ▐▌██▒ "
printf '%s\n' " ▓█ ▓██▒██░ ▓██░ ████▓▒░▒██░ ▓██░ "
printf '%s\n' " ██████ ▓█████ ██▀███░ ██▒ ░ █▓ ██▓ ▄████▄ ▓█████ "
printf '%s\n' " ▒██ ▒ ▓█ ▀ ▓██ ▒ ██▒▓██░ █▒▓██▒▒██▀ ▀█ ▓█ ▀ "
printf '%s\n' " ░ ▓██▄ ▒███ ▓██ ░▄█ ▒ ▓██ █▒░▒██▒▒▓█ ▄▒███ "
printf '%s\n' " ▒ ██▒▒▓█ ▄ ▒██▀▀█▄ ▒██ █░░░██░▒▓▓▄ ▄██▒▓█ ▄ "
printf '%s\n' " ▒██████▒▒░▒████▒░██▓ ▒██▒ ▒▀█░ ░██░▒ ▓███▀ ░▒████▒"
printf '%s\n' " ░ ░ ░ ░ by bit4mind "
echo "";
printf '%s\n' " 0. Check and download dependencies"
printf '%s\n' " 1. Choose and configure transparent proxy type"
printf '%s\n' " 2. Start/Restart service (restart will change your IP address)"
printf '%s\n' " 3. Execute all tasks above"
printf '%s\n' " 4. Exit this menu"
printf '%s\n' " 5. Display status service"
printf '%s\n' " 6. Enable service to start automatically at boot"
printf '%s\n' " 7. Stop service without removing files and setting"
printf '%s\n' " 8. Exit removing service files and settings from system"
printf '%s\n' " 9. Edit configuration files"
printf '%s\n' " 10. Install this script"
echo -en " 11. View log \033[1;34mChoose:\033[0m ";
read -r task
case "$task" in
0)
_checkX
_download
_menu
;;
1)
_checkX
_configure
_menu
;;
2)
start_service
_menu
;;
3)
_download
_configure
start_service
_menu
;;
4)
if (hash wmctrl) 2>/dev/null; then
wmctrl -c :ACTIVE:
exit 0
else
echo "";
exit 0
fi
;;
5)
checking_service
sleep 7
_menu
;;
6)
permanent_service
exit 0
;;
7)
if [ -f "cpath" ]; then
mv cpath $root/ > /dev/null 2>&1
fi
shutdown_service
_menu
;;
8)
_cleanall
;;
9)
_checkX
_editor
_menu
;;
10)
install_service
sleep 7
_menu
;;
11)
_checkX
_vlog
_menu
;;
*)
echo "";
echo "==> Are you serious?"
sleep 3
_menu
esac
}
##
## Checking dependencies and downloading upgraded services
##
_download(){
if [ -e "menu" ]; then
clear
fi
echo " #######################################################";
echo " # ANON-SERVICE SETUP #";
echo " #######################################################";
if [ -s "$root" ]; then
echo "";
echo "==> Please, firstly remove all files and settings via dedicated option!";
sleep 7
if [ -e "menu" ]; then
_menu
return 1
else
echo "";
exit 1
fi
fi
### Checking for network connection
echo "";
echo "==> Checking for internet connection"
rm conn.txt > /dev/null 2>&1
ping -c1 opendns.com > conn.txt 2>&1
if ( ! grep -q "icmp_seq=1" conn.txt ); then
rm conn.txt > /dev/null 2>&1
echo "==> Please connect to a network!";
sleep 5
if [ -e "menu" ]; then
_menu
return 1
else
echo "";
exit 1
fi
fi
echo "==> Checking dependencies and preparing the system"
rm -rf $root > /dev/null 2>&1
adduser -q --disabled-password --gecos "" $owner > /dev/null 2>&1
usermod -u 888 $owner > /dev/null 2>&1
mv cpath $root > /dev/null 2>&1
mkdir -p $root/temp
chmod -R 777 $root/temp
apt-get update > $root/temp/apt.log
#
if [[ ! -e "menu" ]] || [[ ! -e "$(cat $root/cpath)/temp/menu" ]]; then
apt-get install -y curl wget psmisc nano apt-transport-https unbound net-tools ifupdown > /dev/null
else
apt-get install -y curl wget xterm psmisc wmctrl apt-transport-https net-tools unbound > /dev/null
fi
sleep 1
if [ -e tor_option1 ]; then
install_tor_project
elif [ -e tor_option2 ]; then
rm $repo > /dev/null 2>&1
apt-get update > /dev/null
echo "==> Installing Tor";
apt-get install -y tor > /dev/null 2>&1
elif [ -e tor_option3 ]; then
echo "==> Tor already installed...";
sleep 2
if hash tor 2>/dev/null; then
touch $root/installed
else
echo "==> Sorry! The script cannot recognize your Tor package.";
echo "";
exit 1
fi
else
echo "==> Which version of Tor do you prefer to use?";
echo " ";
echo " 1.Tor Project repository";
echo " 2.Official repository";
echo " 3.I already have tor installed";
echo " "
echo -n " Choose: ";
read -r choose
echo "";
case "$choose" in
1)
install_tor_project
;;
2)
rm $repo > /dev/null 2>&1
apt-get update > /dev/null
echo "==> Installing Tor";
apt-get install -y tor > /dev/null 2>&1
;;
3)
echo "==> OK!";
sleep 2
if hash tor 2>/dev/null; then
touch $root/installed
else
echo "==> Sorry! The script cannot recognize your Tor package.";
sleep 3
_cquit
fi
;;
*)
echo "==> Are you serious?";
sleep 5
_cquit
esac
fi
#
touch $root/temp/arch.txt > /dev/null
uname -a > $root/temp/arch.txt
if ( grep -Fq "x86_64" $root/temp/arch.txt ); then
cd $root/temp/
echo "==> Downloading dnscrypt-proxy";
wget -q https://github.com/DNSCrypt/dnscrypt-proxy/releases/download/$dnscrel/dnscrypt-proxy-linux_x86_64-$dnscrel.tar.gz
else
cd $root/temp/
echo "==> Downloading dnscrypt-proxy";
wget -q https://github.com/DNSCrypt/dnscrypt-proxy/releases/download/$dnscrel/dnscrypt-proxy-linux_i386-$dnscrel.tar.gz
fi
tar -xf dnscrypt-proxy-linux_*.tar.gz
cp linux-*/dnscrypt-proxy $root
cp linux-*/example-dnscrypt-proxy.toml $root/dnscrypt-proxy.toml.bak
cp linux-*/localhost.pem $root
rm -rf $root/temp > /dev/null 2>&1
cd $root
rm *.md > /dev/null 2>&1
rm *.md* > /dev/null 2>&1
echo "==> Downloading public DNS resolvers list";
sleep 1
curl -L -O https://download.dnscrypt.info/dnscrypt-resolvers/v3/public-resolvers.md > /dev/null 2>&1
echo "==> Downloading anonymized DNS relays list";
sleep 1
curl -L -O https://download.dnscrypt.info/dnscrypt-resolvers/v3/relays.md > /dev/null 2>&1
### Backup nm and resolv.conf (if exist)
if [ ! -s "$netman.bak" ]; then
if [ -s "$netman" ]; then
cp $netman $netman.bak
fi
fi
if [ ! -s "/etc/resolv.conf.bak" ]; then
if [ -s "etc/resolv.conf" ]; then
cp etc/resolv.conf etc/resolv.conf.bak > /dev/null 2>&1
fi
fi
cd $(cat $root/cpath)
}
##
## INSTALLING TOR PROJECT
##
install_tor_project(){
touch $root/temp/distribution.txt
### Tor Project supported distro
cd $root/temp/
curl -L -O https://deb.torproject.org/torproject.org/dists > /dev/null 2>&1
cat dists | sed -e 's/\(^.*\/">\)\(.*\)\(\/<\/a>.*$\)/\2/; /^stable/d; /^oldstable/d; /^oldoldstable/d; /^unstable/d; /^testing/d; /^proposed-updates/d; /^tor-/d' | awk '!/</' > distribution.txt
touch $root/temp/os.txt
for target in $(cat $root/temp/distribution.txt); do
if ( grep -Fq "$target" $root/temp/apt.log ); then
echo $target > $root/temp/os.txt
fi
done
os=$(cat $root/temp/os.txt | sed -e 's/^[ \t]*//')
if [[ "$os" == " " ]]; then
echo "";
echo "==> Sorry! The script can't find the correct repository.";
echo "==> Please, re-run the script and choose another option.";
echo "";
exit 1
fi
if curl --head --silent --fail https://deb.torproject.org/torproject.org/dists/$os/main/binary-i386/ > /dev/null 2>&1;
then
echo "==> Enabling $os repository";
sleep 1
rm $repo > /dev/null 2>&1
rm $repo* > /dev/null 2>&1
touch $repo
echo "deb [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $os main" | tee -a $repo > /dev/null
echo "deb-src [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $os main" | tee -a $repo > /dev/null
else
echo "==> Enabling $os repository"
rm $repo > /dev/null 2>&1
rm $repo* > /dev/null 2>&1
touch $repo
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $os main" | tee -a $repo > /dev/null
echo "deb-src [arch=amd64 signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $os main" | tee -a $repo > /dev/null
fi
echo "==> Downloading and importing signing key";
wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor 2>/dev/null | tee /usr/share/keyrings/tor-archive-keyring.gpg >/dev/null 2>&1
sleep 1
### Fixing gnupg ownership
gpgconf --kill dirmngr
chown -R $USER ~/.gnupg > /dev/null 2>&1
cd
echo "==> Checking repository";
apt-get update > $root/temp/apt.log
sleep 1
if ( grep "torproject.org $os Release" $root/temp/apt.log > /dev/null 2>&1 ); then
echo "";
echo "==> Sorry! The script can't find the correct repository.";
echo "==> Please, try to enter the correct codename of your OS.";
echo "";
echo -n "==> Codename (for example: buster): ";
read -r codename
echo "";
rm $repo
touch $repo
echo "deb [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $codename main" | tee -a $repo > /dev/null
echo "deb-src [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $codename main" | tee -a $repo > /dev/null
apt-get update > /dev/null
apt-get install -y tor deb.torproject.org-keyring > /dev/null 2>&1
echo "";
else
echo "==> Installing Tor";
apt-get install -y tor deb.torproject.org-keyring > /dev/null 2>&1
fi
}
##
## CONFIGURING SERVICES
##
_configure(){
if [ -e "menu" ]; then
clear
fi
if [[ -e $root/cpath ]]; then
if [[ -e "$(cat $root/cpath)/temp/menu" ]]; then
clear
fi
fi
echo " #######################################################";
echo " # ANON-SERVICE CONFIGURATION #";
echo " #######################################################";
if [ -f "cpath" ]; then
mv cpath $root/ > /dev/null 2>&1
fi
if [ ! -s "$root/dnscrypt-proxy.toml.bak" ]; then
echo "";
echo "==> Sorry! Your system is not ready to complete this action.";
echo "==> Please, check if you have installed the necessary files.";
sleep 7
if [ -e "menu" ]; then
_menu
return 1
else
echo "";
exit 1
fi
fi
### Disable tor and unbound starting at boot time
systemctl disable unbound > /dev/null 2>&1
systemctl disable tor > /dev/null 2>&1
#####
if [ -e "configure_option1" ]; then
rm $root/stp-service > /dev/null 2>&1
touch $root/stp-service
echo "1" > $root/stp-service
echo "";
elif [ -e "configure_option2" ]; then
rm $root/stp-service > /dev/null 2>&1
touch $root/stp-service
echo "0" > $root/stp-service
_dnscryptconf
elif [ -e "$(cat $root/cpath)/temp/menu" ] || [ -e "$(cat $root/cpath)/temp/configure" ]; then
echo " ";
echo "==> Which type of transparent proxy do you prefer to use?";
echo " ";
echo " 1. Standard transparent proxy";
echo " 2. Trasparent proxy with DNSCrypt";
echo " ";
echo -n " Choose: ";
read -r choose
case "$choose" in
1)
rm $root/stp-service > /dev/null 2>&1
touch $root/stp-service
echo "1" > $root/stp-service
echo "";
;;
2)
rm $root/stp-service > /dev/null 2>&1
touch $root/stp-service
echo "0" > $root/stp-service
echo "";
_dnscryptconf
;;
*)
echo "";
echo "==> Are you serious?"
sleep 5
_cconfig
echo "";
esac
else
echo "";
echo "==> Sorry! Something went wrong...Please, report this issue to the project";
echo "";
exit 1
fi
netiface
echo "==> Configuring Tor";
sleep 1
### Configuring Tor
cp $tor $root/torrc
echo "Log notice file $root/notices.log" >> $root/torrc
echo "VirtualAddrNetworkIPv4 10.192.0.0/10" >> $root/torrc
echo "AutomapHostsOnResolve 1" >> $root/torrc
echo "TransPort 9040 IsolateClientAddr IsolateClientProtocol IsolateDestAddr IsolateDestPort" >> $root/torrc
echo "DNSPort 5353" >> $root/torrc
### Disabling unwanted services and configure Network-Manager (if exists)
echo "==> Configuring system";
echo "";
sleep 1
if [ -s $netman ]; then
rm $root/NetworkManager.conf.temp > /dev/null 2>&1
cp $netman.bak $root/NetworkManager.conf.temp
cd $root
chown $USER:$USER NetworkManager.conf.temp
sed -i 's/^dns=dnsmasq/#&/' NetworkManager.conf.temp
sed -i '/\[main\]/a dns=none' NetworkManager.conf.temp
sed '/dns=none/a rc-manager=unmanaged' NetworkManager.conf.temp > NetworkManager.conf
fi
rm $root/iptables_rules.sh > /dev/null 2>&1
touch $root/iptables_rules.sh
### Configuring basic iptables rules
### Reference: https://trac.torproject.org/projects/tor/wiki/doc/TransparentProxy
echo "#################################################################" > $root/iptables_rules.sh
echo "# IPTABLES RULES #" >> $root/iptables_rules.sh
echo "#################################################################" >> $root/iptables_rules.sh
echo "#!/bin/bash" >> $root/iptables_rules.sh
# Destinations you don't want routed through Tor
echo "_non_tor=\"127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16\"" >> $root/iptables_rules.sh
echo "_user_uid=\"888\" ## Tor is the only process that runs as this user" >> $root/iptables_rules.sh
# Tor's VirtualAddrNetworkIPv4
echo "_virt_addr=\"10.192.0.0/10\"" >> $root/iptables_rules.sh
# Tor's TransPort
echo "_trans_port=\"9040\"" >> $root/iptables_rules.sh
# Other IANA reserved blocks (These are not processed by tor and dropped by default)
echo "_resv_iana=\"0.0.0.0/8 100.64.0.0/10 169.254.0.0/16 192.0.0.0/24 192.0.2.0/24 192.88.99.0/24 198.18.0.0/15 198.51.100.0/24 203.0.113.0/24 224.0.0.0/4 240.0.0.0/4 255.255.255.255/32\"" >> $root/iptables_rules.sh
echo "_iface=\$(cat \$root/netiface.txt)" >> $root/iptables_rules.sh
echo "iptables -F" >> $root/iptables_rules.sh
echo "iptables -t nat -F" >> $root/iptables_rules.sh
echo "iptables -t nat -A OUTPUT -d \$_virt_addr -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j REDIRECT --to-ports \$_trans_port" >> $root/iptables_rules.sh
echo "sleep 1" >> $root/iptables_rules.sh
if ( grep -Fq "1" $root/stp-service ); then
echo "iptables -t nat -A OUTPUT -d 127.0.0.1/32 -p udp -m udp --dport 53 -j REDIRECT --to-ports 5353" >> $root/iptables_rules.sh
else
echo "iptables -t nat -A OUTPUT -d 127.0.0.1/32 -p udp -m udp --dport 53 -j REDIRECT --to-ports 53" >> $root/iptables_rules.sh
fi
echo "iptables -t nat -A OUTPUT -m owner --uid-owner \$_user_uid -j RETURN" >> $root/iptables_rules.sh
echo "sleep 1" >> $root/iptables_rules.sh
echo "iptables -t nat -A OUTPUT -o lo -j RETURN" >> $root/iptables_rules.sh
echo "for _lan in \$_non_tor; do" >> $root/iptables_rules.sh
echo "iptables -t nat -A OUTPUT -d \$_lan -j RETURN" >> $root/iptables_rules.sh
echo "done" >> $root/iptables_rules.sh
echo "sleep 5" >> $root/iptables_rules.sh
echo "for _iana in \$_resv_iana; do" >> $root/iptables_rules.sh
echo "iptables -t nat -A OUTPUT -d \$_iana -j RETURN" >> $root/iptables_rules.sh
echo "done" >> $root/iptables_rules.sh
echo "sleep 7" >> $root/iptables_rules.sh
echo "iptables -t nat -A OUTPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j REDIRECT --to-ports \$_trans_port" >> $root/iptables_rules.sh
echo "## Uncomment the next line to grant yourself ssh access from remote machines before the DROP." >> $root/iptables_rules.sh
echo "#iptables -A INPUT -i \$_iface -p tcp --dport 22 -m state --state NEW -j ACCEPT" >> $root/iptables_rules.sh
echo "iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT" >> $root/iptables_rules.sh
echo "iptables -A INPUT -i lo -j ACCEPT" >> $root/iptables_rules.sh
echo "# Allow INPUT from lan hosts in \$_non_tor" >> $root/iptables_rules.sh
echo "## Uncomment the next 4 lines to enable" >> $root/iptables_rules.sh
echo "#for _lan in \$_non_tor; do" >> $root/iptables_rules.sh
echo "# iptables -A INPUT -s \$_lan -j ACCEPT" >> $root/iptables_rules.sh
echo "#done" >> $root/iptables_rules.sh
echo "#sleep 2" >> $root/iptables_rules.sh
echo "## Uncomment the next line to enable logging" >> $root/iptables_rules.sh
echo "#iptables -A INPUT -j LOG --log-prefix "Dropped INPUT packet: " --log-level 7 --log-uid" >> $root/iptables_rules.sh
echo "iptables -A INPUT -j DROP" >> $root/iptables_rules.sh
echo "iptables -A FORWARD -j DROP" >> $root/iptables_rules.sh
echo "iptables -A OUTPUT -m state --state INVALID -j DROP" >> $root/iptables_rules.sh
echo "iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT" >> $root/iptables_rules.sh
echo "sleep 1" >> $root/iptables_rules.sh
echo "iptables -A OUTPUT -o \$_iface -m owner --uid-owner \$_user_uid -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j ACCEPT" >> $root/iptables_rules.sh
echo "sleep 1" >> $root/iptables_rules.sh
echo "iptables -A OUTPUT -d 127.0.0.1/32 -o lo -j ACCEPT" >> $root/iptables_rules.sh
echo "sleep 1" >> $root/iptables_rules.sh
echo "iptables -A OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport \$_trans_port --tcp-flags FIN,SYN,RST,ACK SYN -j ACCEPT" >> $root/iptables_rules.sh
echo "sleep 1" >> $root/iptables_rules.sh
echo "## Uncomment the next 4 lines to Allow OUTPUT to lan hosts" >> $root/iptables_rules.sh
echo "#for _lan in \$_non_tor; do" >> $root/iptables_rules.sh
echo "#iptables -A INPUT -s \$_lan -j ACCEPT" >> $root/iptables_rules.sh
echo "#done" >> $root/iptables_rules.sh
echo "#sleep 5" >> $root/iptables_rules.sh
echo "## Uncomment the next line to enable logging" >> $root/iptables_rules.sh
echo "#iptables -A OUTPUT -j LOG --log-prefix "Dropped OUTPUT packet: " --log-level 7 --log-uid" >> $root/iptables_rules.sh
echo "iptables -A OUTPUT -j DROP" >> $root/iptables_rules.sh
echo "iptables -P FORWARD DROP" >> $root/iptables_rules.sh
echo "iptables -P INPUT DROP" >> $root/iptables_rules.sh
echo "iptables -P OUTPUT DROP" >> $root/iptables_rules.sh
echo "ip6tables -P INPUT DROP" >> $root/iptables_rules.sh
echo "ip6tables -P FORWARD DROP" >> $root/iptables_rules.sh
echo "ip6tables -P OUTPUT DROP" >> $root/iptables_rules.sh
chmod +x $root/iptables_rules.sh
cd $(cat $root/cpath)
}
##
## CONFIGURING DNSCRYPT
##
_dnscryptconf(){
### Configuring dnscrypt_proxy
rm $root/dnscrypt-proxy.toml > /dev/null 2>&1
cp $root/dnscrypt-proxy.toml.bak $root/dnscrypt-proxy.toml
if [ -e "configure_option2" ]; then
server1="$(cat server1)"
else
clear
echo "==> Opening file contain public resolvers";
sleep 2
if [ -e "configure" ]; then
echo "==> Type "q" to quit";
sleep 3
more $root/public-resolvers.md
else
xterm -ls -xrm 'XTerm*selectToClipboard: true' -T "Resolvers" -e "more $root/public-resolvers.md" &
sleep 1
clear
fi
echo "";
echo "==> Please enter the name of the first resolver to use, only ipv4!";
echo "";
echo -n " First server: ";
read -r server1
fi
if ( ! grep "\<$server1\>" $root/public-resolvers.md > /dev/null ); then
echo "";
echo "==> First server not found! Please retry";
killall xterm > /dev/null 2>&1
sleep 3
echo "";
_dnscryptconf
return 1
fi
if [ -e "configure_option2" ]; then
server2="$(cat server2)"
else
if [ -e "configure" ]; then
clear
echo "==> Type "q" to quit";
sleep 3
more $root/public-resolvers.md
fi
echo "";
echo "==> Please enter the name of the second resolver to use, only ipv4!";
echo "";
echo -n " Second server: ";
read -r server2
if ( ! grep "\<$server2\>" $root/public-resolvers.md > /dev/null ); then
echo "";
echo "==> Second server not found! Please retry";
killall xterm > /dev/null 2>&1
sleep 3
echo "";
_dnscryptconf
return 1
fi
fi
if [ -e "configure_option2" ]; then
relay1="$(cat relay1)"
else
clear
echo "==> Opening file contain relays";
sleep 2
killall xterm > /dev/null 2>&1
sleep 2
echo "";
echo " ***************************************************************************";
echo "==> Carefully choose relays/servers so that they are run by different entities!";
echo " ***************************************************************************";
sleep 2
echo "";
if [ -e "configure" ]; then
echo "==> Type "q" to quit";
sleep 3
more $root/relays.md
else
xterm -ls -xrm 'XTerm*selectToClipboard: true' -T "Relays" -e "more $root/relays.md" &
sleep 1
clear
fi
echo "";
echo "==> Please enter the name of the first realy to use!";
echo "";
echo -n " First relay for the first server: ";
read -r relay1
if ! grep "\<$relay1\>" $root/relays.md > /dev/null; then
echo "";
echo "==> First relay for the first server not found! Please retry";
killall xterm > /dev/null 2>&1
sleep 3
echo "";
_dnscryptconf
return 1
fi
fi
if [ -e "configure_option2" ]; then
relay2="$(cat relay2)"
else
if [ -e "configure" ]; then
clear
echo "==> Type "q" to quit";
sleep 3
more $root/relays.md
fi
echo "";
echo "==> Please enter the name of the second relay to use!";
echo "";
echo -n " Second relay for the first server: ";
read -r relay2
echo "";
if ( ! grep "\<$relay2\>" $root/relays.md > /dev/null ); then
echo "";
echo "==> Second relay for the first server not found! Please retry";
killall xterm > /dev/null 2>&1
sleep 3
echo "";
_dnscryptconf
return 1
fi
fi
if [ -e "configure_option2" ]; then
relay3="$(cat relay3)"
else
if [ -e "configure" ]; then
clear
echo "==> Type "q" to quit";
sleep 3
more $root/relays.md
fi
echo "";
echo "==> Please enter the name of the third resolver to use!";
echo "";
echo -n " First relay for the second server: ";
read -r relay3
if ( ! grep "\<$relay3\>" $root/relays.md > /dev/null; ) then
echo "";
echo "==> First relay for the second server not found! Please retry";
killall xterm > /dev/null 2>&1
sleep 3
echo "";
_dnscryptconf
return 1
fi
fi
if [ -e "configure_option2" ]; then
relay4="$(cat relay4)"
else
if [ -e "configure" ]; then
clear
echo "==> Type "q" to quit";
sleep 3
more $root/relays.md
fi
echo "";
echo "==> Please enter the name of the fourth resolver to use!";
echo "";
echo -n " Second relay for the second server: ";
read -r relay4
if ( ! grep "\<$relay4\>" $root/relays.md > /dev/null ); then
echo "";
echo "==> Second relay for the second server not found! Please retry";
killall xterm > /dev/null 2>&1
sleep 3
echo "";
_dnscryptconf
return 1
fi
clear
echo " #######################################################";
echo " # ANON-SERVICE CONFIGURATION #";
echo " #######################################################";
fi
killall xterm > /dev/null 2>&1
echo "";
echo "==> Configuring DNSCrypt";
sleep 1
sed -i "1iforce_tcp = true" $root/dnscrypt-proxy.toml
sed -i "2iserver_names = ['$server1', '$server2']" $root/dnscrypt-proxy.toml
#sed -i "3iproxy = 'socks5://127.0.0.1:9050'" $root/dnscrypt-proxy.toml
sed -i "s/127.0.0.1:53/127.0.0.1:10000/g; s/9.9.9.9/208.67.222.222/g; s/8.8.8.8/208.67.220.220/g; s/require_dnssec = false/require_dnssec = true/g; s/force_tcp = false/#force_tcp = false/g; s/\[anonymized_dns\]/\[anonymized_dns\]\nroutes = \[\n{ server_name='$server1', via=\[\'$relay1\', \'$relay2\'\] },\n{ server_name=\'$server2\', via=[\'$relay3\', \'$relay4\'] }\n\]/g; s/skip_incompatible = false/skip_incompatible = true/g" $root/dnscrypt-proxy.toml
### Configuring unbound
echo "==> Configuring Unbound";
sleep 1
unbound-anchor > /dev/null 2>&1
sleep 1
echo "server:" > $unbound
echo "tcp-upstream: yes" >> $unbound
echo "domain-insecure: \"onion\"" >> $unbound
echo "private-domain: \"onion\"" >> $unbound
echo "do-not-query-localhost: no" >> $unbound
echo "do-ip6: no " >> $unbound
echo "interface: 127.0.0.1@53" >> $unbound
echo "local-zone: \"onion.\" transparent" >> $unbound
echo "forward-zone:" >> $unbound
echo " name: \"onion\"" >> $unbound
echo " forward-addr: 127.0.0.1@5353" >> $unbound
echo "forward-zone:" >> $unbound
echo " name: \".\"" >> $unbound
echo " forward-addr: 127.0.0.1@10000" >> $unbound
sleep 1
}
##
## Starting services and configuring iptables
##
start_service(){
### Checking for required files
if [ -e "menu" ]; then
clear
fi
if [[ -e $root/cpath ]]; then
if [[ -e "$(cat $root/cpath)/temp/menu" ]]; then
clear
fi
fi
echo " #######################################################";
echo " # ANON-SERVICE STARTER #";
echo " #######################################################";
echo "";
if [ ! -s "$root/stp-service" ]; then
echo "==> Sorry! Your system is not ready to start the service...";
echo "==> Please, check if you have installed the necessary files.";
sleep 7
if [ -e "menu" ]; then
_menu
return 1
else
echo "";
exit 1
fi
fi
if [ -f "cpath" ]; then
mv cpath $root/
fi
if [ -s "/etc/network/if-up.d/anon-service" ]; then
echo "==> Sorry! This menu option is not usable in permanent mode. Use";
echo "==> command-line option or simply restart your connection instead!";
sleep 7
_cquit
fi
rm $root/running > /dev/null 2>&1
### Firewall flush
iptables -F
iptables -t nat -F
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables -P OUTPUT ACCEPT
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
ip6tables -P OUTPUT ACCEPT
ip6tables -P INPUT ACCEPT
ip6tables -P FORWARD ACCEPT
netiface
### Configure Network-Manager
cd $root
if [ -s $netman ]; then
cp NetworkManager.conf $netman
chown root:root $netman
fi
service resolvconf stop > /dev/null 2>&1
service dnsmasq stop > /dev/null 2>&1
service bind stop > /dev/null 2>&1
service systemd-resolved stop > /dev/null 2>&1
killall dnsmasq bind > /dev/null 2>&1
sleep 1
service tor stop > /dev/null 2>&1
service dnscrypt-proxy stop > /dev/null 2>&1
service unbound stop > /dev/null 2>&1
killall unbound tor dnscrypt-proxy > /dev/null 2>&1
echo "==> Forcing nameserver to 127.0.0.1 in resolv.conf";
rm /etc/resolv.conf > /dev/null 2>&1
echo $'inameserver 127.0.0.1\E:x\n' | vi /etc/resolv.conf > /dev/null 2>&1
chattr +i /etc/resolv.conf > /dev/null 2>&1
sleep 1
cat /etc/resolv.conf | sed -e '/^$/d; /^#/d' > $root/dnsread
if [[ $(cat $root/dnsread) != "nameserver 127.0.0.1" ]]; then
echo "";
echo "==> There is a problem with your DNS setting! Fix your /etc/resolv.conf";
echo "==> by setting 127.0.0.1 as nameserver and try again."
_cquit
fi
rm $root/dnsread > /dev/null 2>&1
echo "==> Restarting networking";
service network-manager restart > /dev/null 2>&1
service networking restart > /dev/null 2>&1
sleep 3
### Disable ipv6
ipv6_status=$(cat /proc/sys/net/ipv6/conf/default/disable_ipv6)
if [ "$ipv6_status" == "0" ]; then
echo "==> Disabling IPV6 protocol";
sysctl -w net.ipv6.conf.all.disable_ipv6=1 > /dev/null 2>&1
sysctl -w net.ipv6.conf.default.disable_ipv6=1 > /dev/null 2>&1
fi
sleep 2
chown -R $owner:$owner $root
## Restore original files automatically at shutdown
if ( ! pgrep -f "restoring_orig.sh " ) > /dev/null; then
rm restoring_orig.sh > /dev/null 2>&1
touch restoring_orig.sh
echo "#!/bin/bash" > restoring_orig.sh
echo "restoring_script() {" >> restoring_orig.sh
echo "if [ ! -f /etc/network/if-up.d/anon-service ]; then" >> restoring_orig.sh
echo "cp $netman.bak $netman > /dev/null 2>&1" >> restoring_orig.sh
echo "chattr -i /etc/resolv.conf > /dev/null 2>&1" >> restoring_orig.sh
echo "rm /etc/resolv.conf > /dev/null 2>&1" >> restoring_orig.sh
echo "echo $'inameserver 1.1.1.1\E:x\n' | vi /etc/resolv.conf > /dev/null 2>&1" >> restoring_orig.sh
echo "fi" >> restoring_orig.sh
echo "rm $root/running > /dev/null 2>&1" >> restoring_orig.sh
echo "exit" >> restoring_orig.sh
echo "}" >> restoring_orig.sh
echo "while :" >> restoring_orig.sh
echo "do" >> restoring_orig.sh
echo "trap restoring_script SIGINT SIGTERM" >> restoring_orig.sh
echo "sleep 7" >> restoring_orig.sh
echo "done" >> restoring_orig.sh
chmod +x restoring_orig.sh
if [[ ! -e "menu" ]] || [[ ! -e "$(cat $root/cpath)/temp/menu" ]]; then
nohup ./restoring_orig.sh > /dev/null 2>&1 &
echo "==> Automatic restore started"
sleep 1
else
xterm -e nohup ./restoring_orig.sh
echo "==> Automatic restore started"
sleep 1
fi
fi
echo "==> Starting anon-service";
sleep 1
## Start selected transparent proxy
active_service=$(cat $root/stp-service)
case $active_service in
"0")
nohup ./dnscrypt-proxy > /dev/null 2>&1 &
sleep 1
rm $root/notices.log > /dev/null 2>&1
touch $root/notices.log
chown anon-service:anon-service $root/notices.log
nohup su - $owner -c "tor -f $root/torrc" > /dev/null 2>&1 &
echo "==> Checking connection to Tor";
SECONDS=0
secs=30
while (( SECONDS < secs )); do
if ( grep -Fq "100%" $root/notices.log ); then
break
fi
sleep 1
done
cd $root
./iptables_rules.sh
sleep 2
unbound &
### Checking services
if ( ! pgrep -x "tor" ) > /dev/null; then
echo "==> Sorry! No connection to TOR...Please, report this issue to the project";
sleep 7
shutdown_service
exit 1
fi
if ( ! pgrep -x "dnscrypt-proxy" ) > /dev/null; then
echo "==> Sorry! Dnscrypt-proxy isn't running...Please, report this issue to the project";
sleep 7
shutdown_service
exit 1
fi
if ( ! pgrep -x "unbound" ) > /dev/null; then
echo "==> Sorry! Unbound isn't running...Please, report this issue to the project";
sleep 7
shutdown_service
exit 1
else
echo "==> Service started using Tor and DNSCrypt";
echo "";
touch $root/running
sleep 5
fi
;;
"1")
rm $root/notices.log > /dev/null 2>&1
touch $root/notices.log
chown anon-service:anon-service $root/notices.log
nohup su - $owner -c "tor -f $root/torrc" > /dev/null 2>&1 &
echo "==> Checking connection to Tor";
SECONDS=0
secs=30
while (( SECONDS < secs )); do
if ( grep -Fq "100%" $root/notices.log ); then
break
fi
sleep 1
done
cd $root
./iptables_rules.sh
### Checking services
if ( ! pgrep -x "tor" > /dev/null ); then
echo "==> Sorry! No connection to TOR...Please, report this issue to the project";
echo "";
sleep 7
shutdown_service
exit 1
else
echo "==> Service started using Tor network";
echo "";
touch $root/running
sleep 5
fi
esac
cd $(cat $root/cpath)
}
##
## Edit configuration files
##
_editor(){
if [ -e "menu" ]; then
clear
fi
if [[ -e $root/cpath ]]; then
if [[ -e "$(cat $root/cpath)/temp/menu" ]]; then
clear
fi
fi
echo " #######################################################";
echo " # ANON-SERVICE CUSTOMIZATION #";
echo " #######################################################";
echo "";
if [ -f "cpath" ]; then
mv cpath $root/ > /dev/null 2>&1
fi
if [ ! -s "$root/torrc" ]; then
echo "==> Sorry! Your system is not ready to complete this action.";
echo "==> Please, check if you have installed the necessary files.";
sleep 7
_menu
return 1
else
echo "";
fi
echo "==> What do you want to edit?";
echo " 1.torrc";
echo " 2.iptables rules";
echo " "
echo -n " Choose: ";
read -r answer
echo "";
case "$answer" in
1)
if [[ ! -e "menu" ]] || [[ ! -e "$(cat $root/cpath)/temp/menu" ]]; then
nano $root/torrc
echo "==> Please restart the service to apply changes";
echo "";
exit 0
else
xterm -T "Torrc" -e "nano $root/torrc" > /dev/null 2>&1
echo "==> Please restart the service to apply changes";
sleep 7
_menu