test.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. #!/bin/bash
  2. # ==================================================
  3. GitUser="irwanmohi"
  4. #wget https://github.com/${GitUser}/
  5. # initializing var
  6. export DEBIAN_FRONTEND=noninteractive
  7. MYIP=$(wget -qO- ipinfo.io/ip);
  8. MYIP2="s/xxxxxxxxx/$MYIP/g";
  9. NET=$(ip -o $ANU -4 route show to default | awk '{print $5}');
  10. source /etc/os-release
  11. ver=$VERSION_ID
  12. # certificate ssh & openvpn
  13. # edit bwh, isikan nama domain anda
  14. # detail nama perusahaan
  15. MyScriptName='ReGsUb Script'
  16. country=MY
  17. state=SELANGOR
  18. locality=GOMBAK
  19. organization=AIDAN-TECH
  20. organizationalunit=PLATFORM-TEAM
  21. commonname=vpn.aidan.my
  22. email=irwan@aidan.my
  23. # Install OpenVPN dan Easy-RSA
  24. apt install openvpn easy-rsa unzip -y
  25. apt install openssl iptables iptables-persistent -y
  26. mkdir -p /etc/openvpn/server/easy-rsa/
  27. cd /etc/openvpn/
  28. wget https://raw.githubusercontent.com/Apeachsan91/server/main/vpn.zip
  29. unzip vpn.zip
  30. rm -f vpn.zip
  31. chown -R root:root /etc/openvpn/server/easy-rsa/
  32. cd
  33. mkdir -p /usr/lib/openvpn/
  34. cp /usr/lib/x86_64-linux-gnu/openvpn/plugins/openvpn-plugin-auth-pam.so /usr/lib/openvpn/openvpn-plugin-auth-pam.so
  35. # nano /etc/default/openvpn
  36. sed -i 's/#AUTOSTART="all"/AUTOSTART="all"/g' /etc/default/openvpn
  37. # restart openvpn dan cek status openvpn
  38. systemctl enable --now openvpn-server@server-tcp-1194
  39. systemctl enable --now openvpn-server@server-udp-2200
  40. /etc/init.d/openvpn restart
  41. /etc/init.d/openvpn status
  42. # aktifkan ip4 forwarding
  43. echo 1 > /proc/sys/net/ipv4/ip_forward
  44. sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
  45. cd /etc/stunnel/
  46. openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -sha256 -subj '/CN=127.0.0.1/O=localhost/C=US' -keyout /etc/stunnel/stunnel.pem -out /etc/stunnel/stunnel.pem
  47. sudo touch stunnel.conf
  48. echo "client = no" > /etc/stunnel/stunnel.conf
  49. echo "pid = /var/run/stunnel.pid" >> /etc/stunnel/stunnel.conf
  50. echo "[openvpn2]" >> /etc/stunnel/stunnel.conf
  51. echo "accept = 443" >> /etc/stunnel/stunnel.conf
  52. echo "connect = 127.0.0.1:1194" >> /etc/stunnel/stunnel.conf
  53. echo "cert = /etc/stunnel/stunnel.pem" >> /etc/stunnel/stunnel.conf
  54. sudo sed -i -e 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
  55. iptables -A INPUT -p tcp --dport 443 -j ACCEPT
  56. sudo cp /etc/stunnel/stunnel.pem ~
  57. echo "client = yes\ndebug = 6\n[openvpn]\naccept = 127.0.0.1:1194\nconnect = $IPADDRESS:443\nTIMEOUTclose = 0\nverify = 0\nsni = $1" > /var/www/html/stunnel.conf
  58. # openvpn
  59. mv /etc/openvpn/easy-rsa/vars.example /etc/openvpn/easy-rsa/vars
  60. cp -r /usr/share/easy-rsa/ /etc/openvpn
  61. mkdir /etc/openvpn/easy-rsa/keys
  62. sed -i 's|export KEY_COUNTRY="US"|export KEY_COUNTRY="MY"|' /etc/openvpn/easy-rsa/vars
  63. sed -i 's|export KEY_PROVINCE="CA"|export KEY_PROVINCE="Sel"|' /etc/openvpn/easy-rsa/vars
  64. sed -i 's|export KEY_CITY="SanFrancisco"|export KEY_CITY="Gombak"|' /etc/openvpn/easy-rsa/vars
  65. sed -i 's|export KEY_ORG="Fort-Funston"|export KEY_ORG=Aidab-Tech"|' /etc/openvpn/easy-rsa/vars
  66. sed -i 's|export KEY_EMAIL="me@myhost.mydomain"|export KEY_EMAIL="irwan@aidan.my"|' /etc/openvpn/easy-rsa/vars
  67. sed -i 's|export KEY_OU="MyOrganizationalUnit"|export KEY_OU="Aidan-Tech"|' /etc/openvpn/easy-rsa/vars
  68. sed -i 's|export KEY_NAME="EasyRSA"|export KEY_NAME="IrwanMohi"|' /etc/openvpn/easy-rsa/vars
  69. sed -i 's|export KEY_OU=changeme|export KEY_OU=AidanVPN|' /etc/openvpn/easy-rsa/vars
  70. # just double checking if anything should u want
  71. nano /etc/openvpn/easy-rsa/vars
  72. # generate Diffie hellman parameters
  73. openssl dhparam -out /etc/openvpn/dh2048.pem 2048
  74. # Create PKI
  75. cd /etc/openvpn/easy-rsa
  76. . ./vars
  77. ./clean-all
  78. export EASY_RSA="${EASY_RSA:-.}"
  79. "$EASY_RSA/pkitool" --initca $*
  80. # Create key server
  81. export EASY_RSA="${EASY_RSA:-.}"
  82. "$EASY_RSA/pkitool" --server server
  83. # Setting KEY CN
  84. export EASY_RSA="${EASY_RSA:-.}"
  85. "$EASY_RSA/pkitool" client
  86. # cp /etc/openvpn/easy-rsa/keys/{server.crt,server.key,ca.crt} /etc/openvpn
  87. cd
  88. cp /etc/openvpn/easy-rsa/keys/server.crt /etc/openvpn/server.crt
  89. cp /etc/openvpn/easy-rsa/keys/server.key /etc/openvpn/server.key
  90. cp /etc/openvpn/easy-rsa/keys/ca.crt /etc/openvpn/ca.crt
  91. chmod +x /etc/openvpn/ca.crt
  92. # simple password minimal
  93. wget -O /etc/pam.d/common-password "https://raw.githubusercontent.com/${GitUser}/aws/main/password"
  94. chmod +x /etc/pam.d/common-password
  95. # Get easy-rsa
  96. easy_rsa_url='https://github.com/OpenVPN/easy-rsa/releases/download/v3.0.8/EasyRSA-3.0.8.tgz'
  97. mkdir -p /etc/openvpn/server/easy-rsa/
  98. { wget -qO- "$easy_rsa_url" 2>/dev/null || curl -sL "$easy_rsa_url" ; } | tar xz -C /etc/openvpn/server/easy-rsa/ --strip-components 1
  99. chown -R root:root /etc/openvpn/server/easy-rsa/
  100. cd /etc/openvpn/server/easy-rsa/
  101. # Create the PKI, set up the CA and the server and client certificates
  102. ./easyrsa init-pki
  103. ./easyrsa --batch build-ca nopass
  104. EASYRSA_CERT_EXPIRE=3650 ./easyrsa build-server-full server nopass
  105. EASYRSA_CERT_EXPIRE=3650 ./easyrsa build-client-full "$client" nopass
  106. EASYRSA_CRL_DAYS=3650 ./easyrsa gen-crl
  107. #install OpenVPN
  108. cp -r /usr/share/easy-rsa/ /etc/openvpn
  109. mkdir /etc/openvpn/easy-rsa/keys1
  110. # Creating stunnel certifcate using openssl
  111. openssl req -new -x509 -days 9999 -nodes -subj "/C=MY/ST=SEL/L=Gombak/O=Aidan-Tech/OU=Platform-Team/CN=vpn.aidan.my -out /etc/stunnel/stunnel.pem -keyout /etc/stunnel/stunnel.pem &> /dev/null
  112. ## > /dev/null 2>&1
  113. # Configure Stunnel
  114. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
  115. openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -sha256 -subj '/CN=127.0.0.1/O=localhost/C=MY' -keyout /etc/stunnel/stunnel.pem -out /etc/stunnel/stunnel.pem
  116. cat > /etc/stunnel/stunnel.conf <<-END
  117. # replace bits
  118. sed -i 's|export KEY_COUNTRY="US"|export KEY_COUNTRY="MY"|' /etc/openvpn/easy-rsa/vars
  119. sed -i 's|export KEY_PROVINCE="CA"|export KEY_PROVINCE="Selangor"|' /etc/openvpn/easy-rsa/vars
  120. sed -i 's|export KEY_CITY="SanFrancisco"|export KEY_CITY="Gombak"|' /etc/openvpn/easy-rsa/vars
  121. sed -i 's|export KEY_ORG="Fort-Funston"|export KEY_ORG="Aidan"|' /etc/openvpn/easy-rsa/vars
  122. sed -i 's|export KEY_EMAIL="irwanmohi@gmail.com"|export KEY_FB="vpn.shadow-pipe.tech:99"|' /etc/openvpn/easy-rsa/vars
  123. sed -i 's|export KEY_OU="Aidan"|export KEY_OU="STRICTLY_NO_TORRENT_ALLOWED_IN_THIS_SERVER"|' /etc/openvpn/easy-rsa/vars
  124. sed -i 's|export KEY_NAME="EasyRSA"|export KEY_NAME="Aidan"|' /etc/openvpn/easy-rsa/vars
  125. sed -i 's|export KEY_OU=changeme|export KEY_OU=STRICTLY_NO_TORRENT_ALLOWED_IN_THIS_SERVER|' /etc/openvpn/easy-rsa/vars
  126. #Create Diffie-Helman Pem
  127. openssl dhparam -out /etc/openvpn/dh2048.pem 2048
  128. # Create PKI
  129. cd /etc/openvpn/easy-rsa
  130. cp openssl-1.0.0.cnf openssl.cnf
  131. . ./vars
  132. ./clean-all
  133. export EASY_RSA="${EASY_RSA:-.}"
  134. "$EASY_RSA/pkitool" --initca $*
  135. # create key server
  136. export EASY_RSA="${EASY_RSA:-.}"
  137. "$EASY_RSA/pkitool" --server server
  138. # setting KEY CN
  139. export EASY_RSA="${EASY_RSA:-.}"
  140. "$EASY_RSA/pkitool" client
  141. cd
  142. #cp /etc/openvpn/easy-rsa/keys/{server.crt,server.key} /etc/openvpn
  143. cp /etc/openvpn/easy-rsa/keys/server.crt /etc/openvpn/server.crt
  144. cp /etc/openvpn/easy-rsa/keys/server.key /etc/openvpn/server.key
  145. cp /etc/openvpn/easy-rsa/keys/ca.crt /etc/openvpn/ca.crt
  146. #chmod +x /etc/openvpn/ca.crt #i dont know why making executable
  147. # Setting Server
  148. tar -xzvf /root/plugin.tgz -C /usr/lib/openvpn/
  149. chmod +x /usr/lib/openvpn/*
  150. cat > /etc/openvpn/server.conf <<-END
  151. port 1720
  152. proto tcp
  153. dev tun
  154. ca ca.crt
  155. cert server.crt
  156. key server.key
  157. dh dh2048.pem
  158. verify-client-cert none
  159. username-as-common-name
  160. plugin /usr/lib/openvpn/plugins/openvpn-plugin-auth-pam.so login
  161. server 192.168.10.0 255.255.255.0
  162. ifconfig-pool-persist ipp.txt
  163. push "redirect-gateway def1 bypass-dhcp"
  164. push "dhcp-option DNS 1.1.1.1"
  165. push "dhcp-option DNS 1.0.0.1"
  166. push "route-method exe"
  167. push "route-delay 2"
  168. socket-flags TCP_NODELAY
  169. push "socket-flags TCP_NODELAY"
  170. duplicate-cn
  171. keepalive 10 120
  172. comp-lzo
  173. user nobody
  174. group nogroup
  175. persist-key
  176. persist-tun
  177. status openvpn-status.log
  178. log openvpn.log
  179. verb 3
  180. ncp-disable
  181. cipher none
  182. auth none
  183. management $MYIP 7505
  184. END
  185. systemctl start openvpn@server
  186. #Create OpenVPN Config
  187. mkdir -p /home/panel/html
  188. cat > /home/panel/html/client.ovpn <<-END
  189. # RULES [ NO TORRENT | NO DDOS ]
  190. client
  191. dev tun
  192. proto tcp
  193. remote $MYIP 1194
  194. persist-key
  195. persist-tun
  196. pull
  197. resolv-retry infinite
  198. nobind
  199. user nobody
  200. comp-lzo
  201. remote-cert-tls server
  202. verb 3
  203. mute 2
  204. connect-retry 3
  205. connect-retry-max 8080
  206. keepalive 15 45
  207. mute-replay-warnings
  208. redirect-gateway def1
  209. script-security 2
  210. route-method exe
  211. route-delay 2
  212. auth-user-pass
  213. cipher none
  214. auth none
  215. http-proxy-retry
  216. # If squid is not working try to install Privoxy in your vps
  217. http-proxy $MYIP 8080
  218. http-proxy-option CUSTOM-HEADER ""
  219. http-proxy-option CUSTOM-HEADER "POST https://google.com.my HTTP/1.0"
  220. http-proxy-option CUSTOM-HEADER "Connection: Keep-Alive"
  221. http-proxy-option CUSTOM-HEADER "Proxy-Connection: Keep-Alive"
  222. ## Uncomment below if you like to do auto-login in mobile
  223. #<auth-user-pass>
  224. #your_username
  225. #your_password
  226. #</auth-user-pass>
  227. END
  228. echo '<ca>' >> /home/panel/html/client.ovpn
  229. cat /etc/openvpn/ca.crt >> /home/panel/html/client.ovpn
  230. echo '</ca>' >> /home/panel/html/client.ovpn
  231. cat > /home/panel/html/clientssl.ovpn <<-END
  232. # RULES [ NO TORRENT | NO DDOS ]
  233. client
  234. dev tun
  235. proto tcp
  236. remote 127.0.0.1 1194
  237. route $MYIP 255.255.255.255 net_gateway
  238. persist-key
  239. persist-tun
  240. pull
  241. resolv-retry infinite
  242. nobind
  243. user nobody
  244. comp-lzo
  245. remote-cert-tls server
  246. verb 3
  247. mute 2
  248. connect-retry 5
  249. connect-retry-max 8080
  250. mute-replay-warnings
  251. redirect-gateway def1
  252. script-security 2
  253. auth-user-pass
  254. cipher none
  255. auth none
  256. ## Uncomment below if you like to do auto-login in mobile
  257. #<auth-user-pass>
  258. #your_username
  259. #your_password
  260. #</auth-user-pass>
  261. END
  262. echo '<ca>' >> /home/panel/html/clientssl.ovpn
  263. cat /etc/openvpn/ca.crt >> /home/panel/html/clientssl.ovpn
  264. echo '</ca>' >> /home/panel/html/clientssl.ovpn
  265. cat > /home/panel/html/stunnel.conf <<-END
  266. client = yes
  267. debug = 6
  268. [openvpn]
  269. accept = 127.0.0.1:1194
  270. connect = $MYIP:443
  271. TIMEOUTclose = 0
  272. verify = 0
  273. sni = m.facebook.com
  274. END
  275. # Ubah izin akses
  276. chmod +x /etc/rc.local
  277. # enable rc local
  278. systemctl enable rc-local
  279. systemctl start rc-local.service
  280. # disable ipv6
  281. echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
  282. sed -i '$ i\echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6' /etc/rc.local
  283. # set repo
  284. sh -c 'echo "deb http://download.webmin.com/download/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list'
  285. apt install gnupg gnupg1 gnupg2 -y
  286. wget http://www.webmin.com/jcameron-key.asc
  287. apt-key add jcameron-key.asc
  288. #update
  289. apt update -y
  290. apt upgrade -y
  291. apt dist-upgrade -y
  292. # install wget and curl
  293. apt -y install wget curl
  294. # set time GMT +8 # change your location #
  295. ln -fs /usr/share/zoneinfo/Asia/Kuala_Lumpur /etc/localtime
  296. # set locale
  297. sed -i 's/AcceptEnv/#AcceptEnv/g' /etc/ssh/sshd_config
  298. # install
  299. apt-get --reinstall --fix-missing install -y bzip2 gzip coreutils wget screen rsyslog iftop htop net-tools zip unzip wget net-tools curl nano sed screen gnupg gnupg1 bc apt-transport-https build-essential dirmngr libxml-parser-perl neofetch git
  300. echo "clear" >> .profile
  301. echo "neofetch" >> .profile
  302. echo "echo by Irwan" >> .profile
  303. GitUser="irwanmohi"
  304. #wget https://github.com/${GitUser}/
  305. # install webserver
  306. apt -y install nginx
  307. sslVersion = all
  308. pid = /stunnel.pid
  309. socket = l:TCP_NODELAY=1
  310. socket = r:TCP_NODELAY=1
  311. client = no
  312. [openvpn]
  313. accept = 443
  314. connect = 127.0.0.1:1153
  315. cert = /etc/stunnel/stunnel.pem
  316. [dropbear]
  317. accept = 444
  318. connect = 127.0.0.1:442
  319. cert = /etc/stunnel/stunnel.pem
  320. END
  321. #Setting UFW
  322. ufw allow ssh
  323. ufw allow 1153/tcp
  324. sed -i 's|DEFAULT_INPUT_POLICY="DROP"|DEFAULT_INPUT_POLICY="ACCEPT"|' /etc/default/ufw
  325. sed -i 's|DEFAULT_FORWARD_POLICY="DROP"|DEFAULT_FORWARD_POLICY="ACCEPT"|' /etc/default/ufw
  326. # set ipv4 forward
  327. echo 1 > /proc/sys/net/ipv4/ip_forward
  328. sed -i 's|#net.ipv4.ip_forward=1|net.ipv4.ip_forward=1|' /etc/sysctl.conf
  329. sysctl -w net.ipv4.ip_forward=1