ssl.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. #!/bin/bash
  2. #25/01/2021 by @Kalix1
  3. clear
  4. clear
  5. SCPdir="/etc/VPS-MX"
  6. SCPfrm="${SCPdir}/herramientas" && [[ ! -d ${SCPfrm} ]] && exit
  7. SCPinst="${SCPdir}/protocolos"&& [[ ! -d ${SCPinst} ]] && exit
  8. declare -A cor=( [0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m" [5]="\e[1;36m" )
  9. mportas () {
  10. unset portas
  11. portas_var=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
  12. while read port; do
  13. var1=$(echo $port | awk '{print $1}') && var2=$(echo $port | awk '{print $9}' | awk -F ":" '{print $2}')
  14. [[ "$(echo -e $portas|grep "$var1 $var2")" ]] || portas+="$var1 $var2\n"
  15. done <<< "$portas_var"
  16. i=1
  17. echo -e "$portas"
  18. }
  19. fun_bar () {
  20. comando="$1"
  21. _=$(
  22. $comando > /dev/null 2>&1
  23. ) & > /dev/null
  24. pid=$!
  25. while [[ -d /proc/$pid ]]; do
  26. echo -ne " \033[1;33m["
  27. for((i=0; i<20; i++)); do
  28. echo -ne "\033[1;31m##"
  29. sleep 0.5
  30. done
  31. echo -ne "\033[1;33m]"
  32. sleep 1s
  33. echo
  34. tput cuu1
  35. tput dl1
  36. done
  37. echo -e " \033[1;33m[\033[1;31m########################################\033[1;33m] - \033[1;32m100%\033[0m"
  38. sleep 1s
  39. }
  40. ssl_stunel () {
  41. [[ $(mportas|grep stunnel4|head -1) ]] && {
  42. echo -e "\033[1;33m $(fun_trans "Deteniendo Stunnel")"
  43. msg -bar
  44. service stunnel4 stop > /dev/null 2>&1
  45. rm -rf /etc/stunnel/stunnel.conf
  46. apt-get purge stunnel4 -y &>/dev/null && echo -e "\e[31m DETENIENDO SERVICIO SSL" | pv -qL10
  47. apt-get purge stunnel4 &>/dev/null
  48. apt-get remove stunnel4 &>/dev/null
  49. rm -rf /etc/stunnel/certificado.zip private.key certificate.crt ca_bundle.crt &>/dev/null
  50. msg -bar
  51. echo -e "\033[1;33m $(fun_trans "Detenido Con Exito!")"
  52. msg -bar
  53. return 0
  54. }
  55. clear
  56. msg -bar
  57. echo -e "\033[1;33m $(fun_trans "Seleccione una puerta de redirección interna.")"
  58. echo -e "\033[1;33m $(fun_trans "Un puerto SSH/DROPBEAR/SQUID/OPENVPN/PYTHON")"
  59. msg -bar
  60. while true; do
  61. echo -ne "\033[1;37m"
  62. read -p " Puerto Local: " redir
  63. echo ""
  64. if [[ ! -z $redir ]]; then
  65. if [[ $(echo $redir|grep [0-9]) ]]; then
  66. [[ $(mportas|grep $redir|head -1) ]] && break || echo -e "\033[1;31m $(fun_trans "Puerto Invalido")"
  67. fi
  68. fi
  69. done
  70. msg -bar
  71. DPORT="$(mportas|grep $redir|awk '{print $2}'|head -1)"
  72. echo -e "\033[1;33m $(fun_trans "Ahora Que Puerto sera SSL")"
  73. msg -bar
  74. while true; do
  75. echo -ne "\033[1;37m"
  76. read -p " Puerto SSL: " SSLPORT
  77. echo ""
  78. [[ $(mportas|grep -w "$SSLPORT") ]] || break
  79. echo -e "\033[1;33m $(fun_trans "Esta puerta está en uso")"
  80. unset SSLPORT
  81. done
  82. msg -bar
  83. echo -e "\033[1;33m $(fun_trans "Instalando SSL")"
  84. msg -bar
  85. fun_bar "apt-get install stunnel4 -y"
  86. apt-get install stunnel4 -y > /dev/null 2>&1
  87. echo -e "client = no\n[SSL]\ncert = /etc/stunnel/stunnel.pem\naccept = ${SSLPORT}\nconnect = 127.0.0.1:${DPORT}" > /etc/stunnel/stunnel.conf
  88. ####Coreccion2.0#####
  89. openssl genrsa -out stunnel.key 2048 > /dev/null 2>&1
  90. (echo "mx" ; echo "mx" ; echo "Speed" ; echo "@conectedmx_bot" ; echo "@conectedmx" ; echo "@lacasitamx" ; echo "@conectedmx_vip" )|openssl req -new -key stunnel.key -x509 -days 1000 -out stunnel.crt > /dev/null 2>&1
  91. cat stunnel.crt stunnel.key > stunnel.pem
  92. mv stunnel.pem /etc/stunnel/
  93. ######-------
  94. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
  95. service stunnel4 restart > /dev/null 2>&1
  96. msg -bar
  97. echo -e "\033[1;33m $(fun_trans "INSTALADO CON EXITO")"
  98. msg -bar
  99. rm -rf /etc/ger-frm/stunnel.crt > /dev/null 2>&1
  100. rm -rf /etc/ger-frm/stunnel.key > /dev/null 2>&1
  101. rm -rf /root/stunnel.crt > /dev/null 2>&1
  102. rm -rf /root/stunnel.key > /dev/null 2>&1
  103. return 0
  104. }
  105. SPR &
  106. ssl_stunel_2 () {
  107. echo -e "\033[1;32m $(fun_trans " AGREGAR MAS PUERTOS SSL")"
  108. msg -bar
  109. echo -e "\033[1;33m $(fun_trans "Seleccione una puerta de redirección interna.")"
  110. echo -e "\033[1;33m $(fun_trans "Un puerto SSH/DROPBEAR/SQUID/OPENVPN/SSL")"
  111. msg -bar
  112. while true; do
  113. echo -ne "\033[1;37m"
  114. read -p " Puerto-Local: " portx
  115. echo ""
  116. if [[ ! -z $portx ]]; then
  117. if [[ $(echo $portx|grep [0-9]) ]]; then
  118. [[ $(mportas|grep $portx|head -1) ]] && break || echo -e "\033[1;31m $(fun_trans "Puerto Invalido")"
  119. fi
  120. fi
  121. done
  122. msg -bar
  123. DPORT="$(mportas|grep $portx|awk '{print $2}'|head -1)"
  124. echo -e "\033[1;33m $(fun_trans "Ahora Que Puerto sera SSL")"
  125. msg -bar
  126. while true; do
  127. echo -ne "\033[1;37m"
  128. read -p " Listen-SSL: " SSLPORT
  129. echo ""
  130. [[ $(mportas|grep -w "$SSLPORT") ]] || break
  131. echo -e "\033[1;33m $(fun_trans "Esta puerta está en uso")"
  132. unset SSLPORT
  133. done
  134. msg -bar
  135. echo -e "\033[1;33m $(fun_trans "Instalando SSL")"
  136. msg -bar
  137. fun_bar "apt-get install stunnel4 -y"
  138. echo -e "client = no\n[SSL+]\ncert = /etc/stunnel/stunnel.pem\naccept = ${SSLPORT}\nconnect = 127.0.0.1:${DPORT}" >> /etc/stunnel/stunnel.conf
  139. ######-------
  140. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
  141. service stunnel4 restart > /dev/null 2>&1
  142. msg -bar
  143. echo -e "${cor[4]} INSTALADO CON EXITO"
  144. msg -bar
  145. rm -rf /etc/ger-frm/stunnel.crt > /dev/null 2>&1
  146. rm -rf /etc/ger-frm/stunnel.key > /dev/null 2>&1
  147. rm -rf /root/stunnel.crt > /dev/null 2>&1
  148. rm -rf /root/stunnel.key > /dev/null 2>&1
  149. return 0
  150. }
  151. sslpython(){
  152. msg -bar
  153. echo -e "\033[1;37mSe Requiere tener el puerto 80 y el 443 libres"
  154. echo -ne " Desea Continuar? [S/N]: "; read seg
  155. [[ $seg = @(n|N) ]] && msg -bar && return
  156. clear
  157. install_python(){
  158. apt-get install python -y &>/dev/null && echo -e "\033[1;97m Activando Python Directo ►80\n" | pv -qL 10
  159. sleep 3
  160. screen -dmS pydic-80 python ${SCPinst}/python.py 80 "VPS-MX" && echo "80 VPS-MX" >> /etc/VPS-MX/PySSL.log
  161. msg -bar
  162. }
  163. install_ssl(){
  164. apt-get install stunnel4 -y &>/dev/null && echo -e "\033[1;97m Activando Servicios SSL ►443\n" | pv -qL 12
  165. apt-get install stunnel4 -y > /dev/null 2>&1
  166. echo -e "client = no\n[SSL]\ncert = /etc/stunnel/stunnel.pem\naccept = 443\nconnect = 127.0.0.1:80" > /etc/stunnel/stunnel.conf
  167. openssl genrsa -out stunnel.key 2048 > /dev/null 2>&1
  168. (echo mx; echo @lacasitamx; echo Full; echo speed; echo internet; echo @conectedmx; echo @conectedmx_bot)|openssl req -new -key stunnel.key -x509 -days 1095 -out stunnel.crt > /dev/null 2>&1
  169. cat stunnel.crt stunnel.key > stunnel.pem
  170. mv stunnel.pem /etc/stunnel/
  171. ######-------
  172. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
  173. service stunnel4 restart > /dev/null 2>&1
  174. rm -rf /root/stunnel.crt > /dev/null 2>&1
  175. rm -rf /root/stunnel.key > /dev/null 2>&1
  176. }
  177. install_python
  178. install_ssl
  179. msg -bar
  180. echo -e "${cor[4]} INSTALACION COMPLETA"
  181. msg -bar
  182. }
  183. unistall(){
  184. clear
  185. msg -bar
  186. msg -ama "DETENIENDO SERVICIOS SSL Y PYTHON"
  187. msg -bar
  188. service stunnel4 stop > /dev/null 2>&1
  189. apt-get purge stunnel4 -y &>/dev/null
  190. apt-get purge stunnel -y &>/dev/null
  191. kill -9 $(ps aux |grep -v grep |grep -w "python.py"|grep dmS|awk '{print $2}') &>/dev/null
  192. rm /etc/VPS-MX/PySSL.log &>/dev/null
  193. rm -rf /etc/stunnel/certificado.zip private.key certificate.crt ca_bundle.crt &>/dev/null
  194. clear
  195. msg -bar
  196. msg -verd "LOS SERVICIOS SE HAN DETENIDO"
  197. msg -bar
  198. }
  199. #
  200. certif(){
  201. msg -bar
  202. msg -tit
  203. echo -e "\e[1;37m ACONTINUACION ES TENER LISTO EL LINK DEL CERTIFICADO.zip\n VERIFICADO EN ZEROSSL, DESCARGALO Y SUBELO\n EN TU GITHUB O DROPBOX"
  204. echo -ne " Desea Continuar? [S/N]: "; read seg
  205. [[ $seg = @(n|N) ]] && msg -bar && return
  206. clear
  207. ####Cerrificado ssl/tls#####
  208. msg -bar
  209. echo -e "\e[1;33m👇 LINK DEL CERTIFICADO.zip 👇 \n \e[0m"
  210. echo -ne "\e[1;36m LINK\e[37m: \e[34m"
  211. #extraer certificado.zip
  212. read linkd
  213. wget -O /etc/stunnel/certificado.zip $linkd &>/dev/null
  214. cd /etc/stunnel/
  215. unzip certificado.zip &>/dev/null
  216. cat private.key certificate.crt ca_bundle.crt > stunnel.pem
  217. rm -rf certificado.zip
  218. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
  219. service stunnel restart > /dev/null 2>&1
  220. service stunnel4 restart &>/dev/null
  221. msg -bar
  222. echo -e "${cor[4]} CERTIFICADO INSTALADO CON EXITO \e[0m"
  223. msg -bar
  224. }
  225. certificadom(){
  226. if [ -f /etc/stunnel/stunnel.conf ]; then
  227. insapa2(){
  228. for pid in $(pgrep python);do
  229. kill $pid
  230. done
  231. for pid in $(pgrep apache2);do
  232. kill $pid
  233. done
  234. service dropbear stop
  235. apt install apache2 -y
  236. echo "Listen 80
  237. <IfModule ssl_module>
  238. Listen 443
  239. </IfModule>
  240. <IfModule mod_gnutls.c>
  241. Listen 443
  242. </IfModule> " > /etc/apache2/ports.conf
  243. service apache2 restart
  244. }
  245. clear
  246. msg -bar
  247. insapa2 &>/dev/null && echo -e " \e[1;33mAGREGANDO RECURSOS " | pv -qL 10
  248. msg -bar
  249. echo -e "\e[1;37m Verificar dominio \e[0m"
  250. msg -bar
  251. read -p " LLAVE: " keyy
  252. msg -bar
  253. read -p " DATOS: " dat2w
  254. mkdir -p /var/www/html/.well-known/pki-validation/
  255. datfr1=$(echo "$dat2w"|awk '{print $1}')
  256. datfr2=$(echo "$dat2w"|awk '{print $2}')
  257. datfr3=$(echo "$dat2w"|awk '{print $3}')
  258. echo -ne "${datfr1}\n${datfr2}\n${datfr3}" >/var/www/html/.well-known/pki-validation/$keyy.txt
  259. msg -bar
  260. echo -e "\e[1;37m VERIFIQUE EN LA PÁGINA ZEROSSL \e[0m"
  261. msg -bar
  262. read -p " ENTER PARA CONTINUAR"
  263. clear
  264. msg -bar
  265. echo -e "\e[1;33m👇 LINK DEL CERTIFICADO 👇 \n \e[0m"
  266. echo -e "\e[1;36m LINK\e[37m: \e[34m"
  267. read link
  268. incertis(){
  269. wget $link -O /etc/stunnel/certificado.zip
  270. cd /etc/stunnel/
  271. unzip certificado.zip
  272. cat private.key certificate.crt ca_bundle.crt > stunnel.pem
  273. service stunnel restart &>/dev/null
  274. service stunnel4 restart &>/dev/null
  275. }
  276. incertis &>/dev/null && echo -e " \e[1;33mEXTRAYENDO CERTIFICADO " | pv -qL 10
  277. msg -bar
  278. echo -e "${cor[4]} CERTIFICADO INSTALADO \e[0m"
  279. msg -bar
  280. for pid in $(pgrep apache2);do
  281. kill $pid
  282. done
  283. apt install apache2 -y &>/dev/null
  284. echo "Listen 81
  285. <IfModule ssl_module>
  286. Listen 443
  287. </IfModule>
  288. <IfModule mod_gnutls.c>
  289. Listen 443
  290. </IfModule> " > /etc/apache2/ports.conf
  291. service apache2 restart &>/dev/null
  292. service dropbear start &>/dev/null
  293. service dropbear restart &>/dev/null
  294. for port in $(cat /etc/VPS-MX/PortPD.log| grep -v "nobody" |cut -d' ' -f1)
  295. do
  296. PIDVRF3="$(ps aux|grep pydic-"$port" |grep -v grep|awk '{print $2}')"
  297. if [[ -z $PIDVRF3 ]]; then
  298. screen -dmS pydic-"$port" python /etc/VPS-MX/protocolos/python.py "$port"
  299. else
  300. for pid in $(echo $PIDVRF3); do
  301. echo ""
  302. done
  303. fi
  304. done
  305. else
  306. msg -bar
  307. echo -e "${cor[3]} SSL/TLS NO INSTALADO \e[0m"
  308. msg -bar
  309. fi
  310. }
  311. certifica2(){
  312. if [ -f /etc/stunnel/stunnel.conf ]; then
  313. insapa2(){
  314. for pid in $(pgrep python);do
  315. kill $pid
  316. done
  317. for pid in $(pgrep apache2);do
  318. kill $pid
  319. done
  320. service dropbear stop
  321. apt install apache2 -y
  322. echo "Listen 80
  323. <IfModule ssl_module>
  324. Listen 443
  325. </IfModule>
  326. <IfModule mod_gnutls.c>
  327. Listen 443
  328. </IfModule> " > /etc/apache2/ports.conf
  329. service apache2 restart
  330. }
  331. clear
  332. msg -bar
  333. insapa2 &>/dev/null && echo -e " \e[1;33mAGREGANDO RECURSOS " | pv -qL 10
  334. msg -bar
  335. echo -e "\e[1;37m Verificar dominio \e[0m"
  336. msg -bar
  337. read -p " LLAVE: " archi
  338. msg -bar
  339. echo -e "\e[1;37m COPIA LOS DATOS DEL ARCHIVO\n\e[1;33m$archi.txt\nLINEA1,LINEA2,LINEA3, SE TE PEDIRA POR PARTES \e[0m"
  340. read -p " LINEA 1: " dat1w
  341. read -p " LINEA 2: " dat2w
  342. read -p " LINEA 3: " dat3w
  343. mkdir -p /var/www/html/.well-known/pki-validation/
  344. dat1=$(echo "$dat1w"|awk '{print $1}')
  345. dat2=$(echo "$dat2w"|awk '{print $1}')
  346. dat3=$(echo "$dat3w"|awk '{print $1}')
  347. echo -ne "${dat1}\n${dat2}\n${dat3}" >/var/www/html/.well-known/pki-validation/$archi.txt
  348. msg -bar
  349. echo -e "\e[1;37m AHORA VERIFIQUE EN LA PÁGINA ZEROSSL \e[0m"
  350. msg -bar
  351. read -p " ENTER PARA CONTINUAR"
  352. clear
  353. msg -bar
  354. echo -e "\e[1;33m👇 LINK DEL CERTIFICADO 👇 \n \e[0m"
  355. echo -e "\e[1;36m LINK\e[37m: \e[34m"
  356. read link
  357. incertis(){
  358. wget $link -O /etc/stunnel/certificado.zip
  359. cd /etc/stunnel/
  360. unzip certificado.zip
  361. cat private.key certificate.crt ca_bundle.crt > stunnel.pem
  362. service stunnel restart &>/dev/null
  363. service stunnel4 restart &>/dev/null
  364. }
  365. incertis &>/dev/null && echo -e " \e[1;33mEXTRAYENDO CERTIFICADO " | pv -qL 10
  366. msg -bar
  367. echo -e "${cor[4]} CERTIFICADO INSTALADO \e[0m"
  368. msg -bar
  369. for pid in $(pgrep apache2);do
  370. kill $pid
  371. done
  372. apt install apache2 -y &>/dev/null
  373. echo "Listen 81
  374. <IfModule ssl_module>
  375. Listen 443
  376. </IfModule>
  377. <IfModule mod_gnutls.c>
  378. Listen 443
  379. </IfModule> " > /etc/apache2/ports.conf
  380. service apache2 restart &>/dev/null
  381. service dropbear start &>/dev/null
  382. service dropbear restart &>/dev/null
  383. for port in $(cat /etc/VPS-MX/PortPD.log| grep -v "nobody" |cut -d' ' -f1)
  384. do
  385. PIDVRF3="$(ps aux|grep pydic-"$port" |grep -v grep|awk '{print $2}')"
  386. if [[ -z $PIDVRF3 ]]; then
  387. screen -dmS pydic-"$port" python /etc/VPS-MX/protocolos/python.py "$port"
  388. else
  389. for pid in $(echo $PIDVRF3); do
  390. echo ""
  391. done
  392. fi
  393. done
  394. else
  395. msg -bar
  396. echo -e "${cor[3]} SSL/TLS NO INSTALADO \e[0m"
  397. msg -bar
  398. fi
  399. }
  400. #
  401. clear
  402. if netstat -tnlp |grep 'stunnel4' &>/dev/null || netstat -tnlp |grep 'stunnel' &>/dev/null; then
  403. stunel="\e[32m[ ON ]"
  404. else
  405. stunel="\e[31m[ OFF ]"
  406. fi
  407. msg -bar
  408. msg -bar3
  409. msg -tit
  410. echo -e " \e[91m\e[43mINSTALADOR MULTI SSL\e[0m "
  411. msg -bar
  412. echo -e "$(msg -verd "[1]")$(msg -verm2 "➛ ")$(msg -azu "INICIAR || DETENER SSL") $stunel"
  413. echo -e "$(msg -verd "[2]")$(msg -verm2 "➛ ")$(msg -azu "AGREGAR + PUERTOS SSL")"
  414. msg -bar
  415. echo -e "$(msg -verd "[3]")$(msg -verm2 "➛ ")$(msg -azu "SSL+Python Auto-Config 80➮443 ")"
  416. echo -e "$(msg -verd "[4]")$(msg -verm2 "➛ ")$(msg -azu "\e[1;31mDETENER SERVICIO SSL+Python")"
  417. msg -bar
  418. echo -e "$(msg -verd "[5]")$(msg -verm2 "➛ ")$(msg -azu "CERTIFICADO SSL/TLS")"
  419. msg -bar
  420. echo -ne "\033[1;37mSelecione Una Opcion [0/5]: "
  421. read opcao
  422. case $opcao in
  423. 1)
  424. msg -bar
  425. ssl_stunel
  426. ;;
  427. 2)
  428. msg -bar
  429. ssl_stunel_2
  430. sleep 3
  431. exit
  432. ;;
  433. 3)
  434. sslpython
  435. exit
  436. ;;
  437. 4) unistall ;;
  438. 5)
  439. clear
  440. msg -bar
  441. echo -e " \e[91m\e[43mCERTIFICADO SSL/TLS\e[0m"
  442. msg -bar
  443. echo -e "$(msg -verd "[1]")$(msg -verm2 "➛ ")$(msg -azu "CERTIFICADO ZIP DIRECTO \e[31m(\e[32mEstricto\e[31m)")"
  444. echo -e "$(msg -verd "[2]")$(msg -verm2 "➛ ")$(msg -azu "CERTIFICADO MANUAL ZEROSSL \e[31m(\e[32mAvanzado\e[31m)")"
  445. echo -e "$(msg -verd "[3]")$(msg -verm2 "➛ ")$(msg -azu "CERTIFICADO MANUAL ZEROSSL \e[31m(\e[32mPrincipiantes\e[31m)")"
  446. msg -bar
  447. echo -ne "\033[1;37mSelecione Una Opcion [0/4]: "
  448. read opc
  449. case $opc in
  450. 1)
  451. certif
  452. exit
  453. ;;
  454. 2)
  455. certificadom
  456. exit
  457. ;;
  458. 3)
  459. certifica2
  460. exit
  461. ;;
  462. esac
  463. ;;
  464. esac