-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.cfg.proxychains.sh
More file actions
132 lines (111 loc) · 4.42 KB
/
setup.cfg.proxychains.sh
File metadata and controls
132 lines (111 loc) · 4.42 KB
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
#!/bin/bash
# include tools
source "./src/tools.sh" || exit 1
# show help
if [ "${showhelp}" == "yes" ]; then
echo ""
echo "*** ABOUT ***"
echo ""
echo "proxychains configuration update script in userspace"
echo ""
echo "*** USAGE ***"
echo ""
echo ""${0}" <install|update|reinstall>"
echo ""
echo "*** ARGUMENTS(mandatory) ***"
echo ""
echo "<install|update|reinstall>"
echo " >> install >> action to try to copy and update default proxychains configuration"
echo " >> update >> action to try update existing proxychains configuration"
echo " >> reinstall >> action to try to delete actual configuration and do install"
echo ""
echo "*** EXAMPLES ***"
echo ""${0}" install"
echo ""${0}" update"
echo ""${0}" reinstall"
echo ""
exit 0
fi
# handle arguments
cc_action=
argc=$#
argv=("$@")
for (( j=0; j<argc; j++ )); do
if [ "${argv[j]}" = "install" ]; then
if [ "${cc_action}" = "" ]; then
cc_action="install"
echo "INFO >> install enabled"
else
echo "Invalid argument: $j ${argv[j]}"
exit 1
fi
elif [ "${argv[j]}" = "update" ]; then
if [ "${cc_action}" = "" ]; then
cc_action="update"
echo "INFO >> update enabled"
else
echo "Invalid argument: $j ${argv[j]}"
exit 1
fi
elif [ "${argv[j]}" = "reinstall" ]; then
if [ "${cc_action}" = "" ]; then
cc_action="reinstall"
echo "INFO >> reinstall enabled"
else
echo "Invalid argument: $j ${argv[j]}"
exit 1
fi
else
echo "Invalid argument: $j ${argv[j]}"
exit 1
fi
done
# real config paths
cc_cfg_proxychains_root_cfg_path="/etc/proxychains4.conf"
cc_cfg_proxychains_user_dir_path="${HOME}/.proxychains"
cc_cfg_proxychains_user_cfg_path="${cc_cfg_proxychains_user_dir_path}/proxychains.conf"
# create user config dir
tool_realpath cc_cfg_proxychains_user_dir_path "user config dir path"
tool_make_and_check_dir_path cc_cfg_proxychains_user_dir_path "user config dir path"
# real path paths
tool_realpath cc_cfg_proxychains_root_cfg_path "root config path"
tool_realpath cc_cfg_proxychains_user_cfg_path "user config path"
# check root config exist
tool_file_if_notexist_exit ${cc_cfg_proxychains_root_cfg_path}
# if install action, user config file should not exist and will be compied
if [ "${cc_action}" = "install" ]; then
tool_file_if_exist_exit ${cc_cfg_proxychains_user_cfg_path} "user config"
tool_cp ${cc_cfg_proxychains_root_cfg_path} ${cc_cfg_proxychains_user_cfg_path}
# if update action, user config must already exist will be let as it be
elif [ "${cc_action}" = "update" ]; then
tool_file_if_notexist_exit ${cc_cfg_proxychains_user_cfg_path} "user config"
# if reinstall action, user config must already exist and will be removed an new copy created
elif [ "${cc_action}" = "reinstall" ]; then
tool_file_if_notexist_exit ${cc_cfg_proxychains_user_cfg_path} "user config"
rm ${cc_cfg_proxychains_user_cfg_path}
tool_cp ${cc_cfg_proxychains_root_cfg_path} ${cc_cfg_proxychains_user_cfg_path}
else
echo "ERROR >> cc_action >> value >> ${cc_action} >> is invalid"
exit 1
fi
# update user config
# configuration file path
# updating localhost to be accessible
cfg_line="localnet 127\.0\.0\.0\/255\.0\.0\.0"
sed -i \
-e "s/.*${cfg_line}.*/${cfg_line}/g" \
${cc_cfg_proxychains_user_cfg_path}
(test $? != 0) && echo "ERROR >> proxychains config >> ${cc_cfg_proxychains_user_cfg_path} >> localhost enable >> update failed" && exit 1
cat ${cc_cfg_proxychains_user_cfg_path} | grep -e "^${cfg_line}$"
(test $? != 0) && echo "ERROR >> proxychains config >> ${cc_cfg_proxychains_user_cfg_path} >> localhost enable >> check failed" && exit 1
# updating socks4 to socks5
cfg_line_old="socks4.*127.0.0.1 9050"
cfg_line_new="socks5 127.0.0.1 9050"
sed -i \
-e "s/${cfg_line_old}/${cfg_line_new}/g" \
${cc_cfg_proxychains_user_cfg_path}
(test $? != 0) && echo "ERROR >> proxychains config >> ${cc_cfg_proxychains_user_cfg_path} >> socks5 enable >> update failed" && exit 1
cat ${cc_cfg_proxychains_user_cfg_path} | grep -e "^${cfg_line_new}$"
(test $? != 0) && echo "ERROR >> proxychains config >> ${cc_cfg_proxychains_user_cfg_path} >> socks5 enable >> check failed" && exit 1
echo "INFO >> proxychains config >> ${cc_cfg_proxychains_user_cfg_path} >> processing success"
exit 0