sockspy.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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" )
  9. [[ $(dpkg --get-selections|grep -w "python"|head -1) ]] || apt-get install python -y &>/dev/null
  10. mportas () {
  11. unset portas
  12. portas_var=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
  13. while read port; do
  14. var1=$(echo $port | awk '{print $1}') && var2=$(echo $port | awk '{print $9}' | awk -F ":" '{print $2}')
  15. [[ "$(echo -e $portas|grep "$var1 $var2")" ]] || portas+="$var1 $var2\n"
  16. done <<< "$portas_var"
  17. i=1
  18. echo -e "$portas"
  19. }
  20. meu_ip () {
  21. MEU_IP=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
  22. MEU_IP2=$(wget -qO- ipv4.icanhazip.com)
  23. [[ "$MEU_IP" != "$MEU_IP2" ]] && echo "$MEU_IP2" || echo "$MEU_IP"
  24. }
  25. tcpbypass_fun () {
  26. [[ -e $HOME/socks ]] && rm -rf $HOME/socks > /dev/null 2>&1
  27. [[ -d $HOME/socks ]] && rm -rf $HOME/socks > /dev/null 2>&1
  28. cd $HOME && mkdir socks > /dev/null 2>&1
  29. cd socks
  30. patch="https://raw.githubusercontent.com/NetVPS/VPS-MX_Oficial/master/LINKS-LIBRERIAS/backsocz.zip"
  31. arq="backsocz.zip"
  32. wget $patch > /dev/null 2>&1
  33. unzip $arq > /dev/null 2>&1
  34. mv -f /root/socks/backsocz/./ssh /etc/ssh/sshd_config && service ssh restart 1> /dev/null 2>/dev/null
  35. mv -f /root/socks/backsocz/sckt$(python3 --version|awk '{print $2}'|cut -d'.' -f1,2) /usr/sbin/sckt
  36. mv -f /root/socks/backsocz/scktcheck /bin/scktcheck
  37. chmod +x /bin/scktcheck
  38. chmod +x /usr/sbin/sckt
  39. rm -rf $HOME/root/socks
  40. cd $HOME
  41. msg="$2"
  42. [[ $msg = "" ]] && msg="@Kalix1"
  43. portxz="$1"
  44. [[ $portxz = "" ]] && portxz="8080"
  45. screen -dmS sokz scktcheck "$portxz" "$msg" > /dev/null 2>&1
  46. }
  47. gettunel_fun () {
  48. echo "master=NetVPS" > ${SCPinst}/pwd.pwd
  49. while read service; do
  50. [[ -z $service ]] && break
  51. echo "127.0.0.1:$(echo $service|cut -d' ' -f2)=$(echo $service|cut -d' ' -f1)" >> ${SCPinst}/pwd.pwd
  52. done <<< "$(mportas)"
  53. screen -dmS getpy python ${SCPinst}/PGet.py -b "0.0.0.0:$1" -p "${SCPinst}/pwd.pwd"
  54. [[ "$(ps x | grep "PGet.py" | grep -v "grep" | awk -F "pts" '{print $1}')" ]] && {
  55. echo -e "$(fun_trans "Gettunel Iniciado com Sucesso")"
  56. msg -bar
  57. echo -ne "$(fun_trans "Sua Senha Gettunel e"):"
  58. echo -e "\033[1;32m NetVPS"
  59. msg -bar
  60. } || echo -e "$(fun_trans "Gettunel nao foi iniciado")"
  61. msg -bar
  62. }
  63. PythonDic_fun () {
  64. echo -e "\033[1;33m Selecciona Puerto Local y Encabezado\033[1;37m"
  65. msg -bar
  66. echo -ne "\033[1;97mDigite Un Puerto SSH/DROPBEAR activo: \033[1;92m" && read puetoantla
  67. msg -bar
  68. echo -ne "\033[1;97mRespuesta de encabezado (200,101,404,500,etc): \033[1;92m" && read rescabeza
  69. msg -bar
  70. (
  71. less << PYTHON > /etc/VPS-MX/protocolos/PDirect.py
  72. import socket, threading, thread, select, signal, sys, time, getopt
  73. # Listen
  74. LISTENING_ADDR = '0.0.0.0'
  75. if sys.argv[1:]:
  76. LISTENING_PORT = sys.argv[1]
  77. else:
  78. LISTENING_PORT = 80
  79. #Pass
  80. PASS = ''
  81. # CONST
  82. BUFLEN = 4096 * 4
  83. TIMEOUT = 60
  84. DEFAULT_HOST = '127.0.0.1:$puetoantla'
  85. RESPONSE = 'HTTP/1.1 $rescabeza <strong>$texto_soket</strong>\r\nContent-length: 0\r\n\r\nHTTP/1.1 $rescabeza Connection established\r\n\r\n'
  86. #RESPONSE = 'HTTP/1.1 200 Hello_World!\r\nContent-length: 0\r\n\r\nHTTP/1.1 200 Connection established\r\n\r\n' # lint:ok
  87. class Server(threading.Thread):
  88. def __init__(self, host, port):
  89. threading.Thread.__init__(self)
  90. self.running = False
  91. self.host = host
  92. self.port = port
  93. self.threads = []
  94. self.threadsLock = threading.Lock()
  95. self.logLock = threading.Lock()
  96. def run(self):
  97. self.soc = socket.socket(socket.AF_INET)
  98. self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  99. self.soc.settimeout(2)
  100. intport = int(self.port)
  101. self.soc.bind((self.host, intport))
  102. self.soc.listen(0)
  103. self.running = True
  104. try:
  105. while self.running:
  106. try:
  107. c, addr = self.soc.accept()
  108. c.setblocking(1)
  109. except socket.timeout:
  110. continue
  111. conn = ConnectionHandler(c, self, addr)
  112. conn.start()
  113. self.addConn(conn)
  114. finally:
  115. self.running = False
  116. self.soc.close()
  117. def printLog(self, log):
  118. self.logLock.acquire()
  119. print log
  120. self.logLock.release()
  121. def addConn(self, conn):
  122. try:
  123. self.threadsLock.acquire()
  124. if self.running:
  125. self.threads.append(conn)
  126. finally:
  127. self.threadsLock.release()
  128. def removeConn(self, conn):
  129. try:
  130. self.threadsLock.acquire()
  131. self.threads.remove(conn)
  132. finally:
  133. self.threadsLock.release()
  134. def close(self):
  135. try:
  136. self.running = False
  137. self.threadsLock.acquire()
  138. threads = list(self.threads)
  139. for c in threads:
  140. c.close()
  141. finally:
  142. self.threadsLock.release()
  143. class ConnectionHandler(threading.Thread):
  144. def __init__(self, socClient, server, addr):
  145. threading.Thread.__init__(self)
  146. self.clientClosed = False
  147. self.targetClosed = True
  148. self.client = socClient
  149. self.client_buffer = ''
  150. self.server = server
  151. self.log = 'Connection: ' + str(addr)
  152. def close(self):
  153. try:
  154. if not self.clientClosed:
  155. self.client.shutdown(socket.SHUT_RDWR)
  156. self.client.close()
  157. except:
  158. pass
  159. finally:
  160. self.clientClosed = True
  161. try:
  162. if not self.targetClosed:
  163. self.target.shutdown(socket.SHUT_RDWR)
  164. self.target.close()
  165. except:
  166. pass
  167. finally:
  168. self.targetClosed = True
  169. def run(self):
  170. try:
  171. self.client_buffer = self.client.recv(BUFLEN)
  172. hostPort = self.findHeader(self.client_buffer, 'X-Real-Host')
  173. if hostPort == '':
  174. hostPort = DEFAULT_HOST
  175. split = self.findHeader(self.client_buffer, 'X-Split')
  176. if split != '':
  177. self.client.recv(BUFLEN)
  178. if hostPort != '':
  179. passwd = self.findHeader(self.client_buffer, 'X-Pass')
  180. if len(PASS) != 0 and passwd == PASS:
  181. self.method_CONNECT(hostPort)
  182. elif len(PASS) != 0 and passwd != PASS:
  183. self.client.send('HTTP/1.1 400 WrongPass!\r\n\r\n')
  184. elif hostPort.startswith('127.0.0.1') or hostPort.startswith('localhost'):
  185. self.method_CONNECT(hostPort)
  186. else:
  187. self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
  188. else:
  189. print '- No X-Real-Host!'
  190. self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
  191. except Exception as e:
  192. self.log += ' - error: ' + e.strerror
  193. self.server.printLog(self.log)
  194. pass
  195. finally:
  196. self.close()
  197. self.server.removeConn(self)
  198. def findHeader(self, head, header):
  199. aux = head.find(header + ': ')
  200. if aux == -1:
  201. return ''
  202. aux = head.find(':', aux)
  203. head = head[aux+2:]
  204. aux = head.find('\r\n')
  205. if aux == -1:
  206. return ''
  207. return head[:aux];
  208. def connect_target(self, host):
  209. i = host.find(':')
  210. if i != -1:
  211. port = int(host[i+1:])
  212. host = host[:i]
  213. else:
  214. if self.method=='CONNECT':
  215. port = $puetoantla
  216. else:
  217. port = sys.argv[1]
  218. (soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]
  219. self.target = socket.socket(soc_family, soc_type, proto)
  220. self.targetClosed = False
  221. self.target.connect(address)
  222. def method_CONNECT(self, path):
  223. self.log += ' - CONNECT ' + path
  224. self.connect_target(path)
  225. self.client.sendall(RESPONSE)
  226. self.client_buffer = ''
  227. self.server.printLog(self.log)
  228. self.doCONNECT()
  229. def doCONNECT(self):
  230. socs = [self.client, self.target]
  231. count = 0
  232. error = False
  233. while True:
  234. count += 1
  235. (recv, _, err) = select.select(socs, [], socs, 3)
  236. if err:
  237. error = True
  238. if recv:
  239. for in_ in recv:
  240. try:
  241. data = in_.recv(BUFLEN)
  242. if data:
  243. if in_ is self.target:
  244. self.client.send(data)
  245. else:
  246. while data:
  247. byte = self.target.send(data)
  248. data = data[byte:]
  249. count = 0
  250. else:
  251. break
  252. except:
  253. error = True
  254. break
  255. if count == TIMEOUT:
  256. error = True
  257. if error:
  258. break
  259. def print_usage():
  260. print 'Usage: proxy.py -p <port>'
  261. print ' proxy.py -b <bindAddr> -p <port>'
  262. print ' proxy.py -b 0.0.0.0 -p 80'
  263. def parse_args(argv):
  264. global LISTENING_ADDR
  265. global LISTENING_PORT
  266. try:
  267. opts, args = getopt.getopt(argv,"hb:p:",["bind=","port="])
  268. except getopt.GetoptError:
  269. print_usage()
  270. sys.exit(2)
  271. for opt, arg in opts:
  272. if opt == '-h':
  273. print_usage()
  274. sys.exit()
  275. elif opt in ("-b", "--bind"):
  276. LISTENING_ADDR = arg
  277. elif opt in ("-p", "--port"):
  278. LISTENING_PORT = int(arg)
  279. def main(host=LISTENING_ADDR, port=LISTENING_PORT):
  280. print "\n:-------PythonProxy-------:\n"
  281. print "Listening addr: " + LISTENING_ADDR
  282. print "Listening port: " + str(LISTENING_PORT) + "\n"
  283. print ":-------------------------:\n"
  284. server = Server(LISTENING_ADDR, LISTENING_PORT)
  285. server.start()
  286. while True:
  287. try:
  288. time.sleep(2)
  289. except KeyboardInterrupt:
  290. print 'Stopping...'
  291. server.close()
  292. break
  293. ####### parse_args(sys.argv[1:])
  294. if __name__ == '__main__':
  295. main()
  296. PYTHON
  297. ) > $HOME/proxy.log
  298. chmod +x /etc/VPS-MX/protocolos/PDirect.py
  299. screen -dmS pydic-"$porta_socket" python ${SCPinst}/PDirect.py "$porta_socket" "$texto_soket" && echo ""$porta_socket" "$texto_soket"" >> /etc/VPS-MX/PortPD.log
  300. }
  301. pid_kill () {
  302. [[ -z $1 ]] && refurn 1
  303. pids="$@"
  304. for pid in $(echo $pids); do
  305. kill -9 $pid &>/dev/null
  306. done
  307. }
  308. remove_fun () {
  309. echo -e "$(fun_trans "Parando Socks Python")"
  310. msg -bar
  311. pidproxy=$(ps x | grep "PPub.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy ]] && pid_kill $pidproxy
  312. pidproxy2=$(ps x | grep "PPriv.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy2 ]] && pid_kill $pidproxy2
  313. pidproxy3=$(ps x | grep "PDirect.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy3 ]] && pid_kill $pidproxy3
  314. pidproxy4=$(ps x | grep "POpen.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy4 ]] && pid_kill $pidproxy4
  315. pidproxy5=$(ps x | grep "PGet.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy5 ]] && pid_kill $pidproxy5
  316. pidproxy6=$(ps x | grep "scktcheck" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy6 ]] && pid_kill $pidproxy6
  317. pidproxy7=$(ps x | grep "python.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy7 ]] && pid_kill $pidproxy7
  318. echo -e "\033[1;91m $(fun_trans "Socks DETENIDOS")"
  319. msg -bar
  320. rm -rf /etc/VPS-MX/PortPD.log
  321. echo "" > /etc/VPS-MX/PortPD.log
  322. exit 0
  323. }
  324. iniciarsocks () {
  325. pidproxy=$(ps x | grep -w "PPub.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy ]] && P1="\033[1;32m[ON]" || P1="\033[1;31m[OFF]"
  326. pidproxy2=$(ps x | grep -w "PPriv.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy2 ]] && P2="\033[1;32m[ON]" || P2="\033[1;31m[OFF]"
  327. pidproxy3=$(ps x | grep -w "PDirect.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy3 ]] && P3="\033[1;32m[ON]" || P3="\033[1;31m[OFF]"
  328. pidproxy4=$(ps x | grep -w "POpen.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy4 ]] && P4="\033[1;32m[ON]" || P4="\033[1;31m[OFF]"
  329. pidproxy5=$(ps x | grep "PGet.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy5 ]] && P5="\033[1;32m[ON]" || P5="\033[1;31m[OFF]"
  330. pidproxy6=$(ps x | grep "scktcheck" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy6 ]] && P6="\033[1;32m[ON]" || P6="\033[1;31m[OFF]"
  331. msg -bar
  332. msg -tit
  333. msg -ama " INSTALADOR DE PROXY'S VPS-MX By MOD @Kalix1"
  334. msg -bar
  335. echo -e "${cor[4]} [1] $(msg -verm2 "==>>") \033[1;97m$(fun_trans "Proxy Python SIMPLE")\033[1;97m ------------- $P1"
  336. echo -e "${cor[4]} [2] $(msg -verm2 "==>>") \033[1;97m$(fun_trans "Proxy Python SEGURO")\033[1;97m ------------- $P2"
  337. echo -e "${cor[4]} [3] $(msg -verm2 "==>>") \033[1;97m$(fun_trans "Proxy Python DIRETO")\033[1;97m ------------- $P3"
  338. echo -e "${cor[4]} [4] $(msg -verm2 "==>>") \033[1;97m$(fun_trans "Proxy Python OPENVPN")\033[1;97m ------------ $P4"
  339. echo -e "${cor[4]} [5] $(msg -verm2 "==>>") \033[1;97m$(fun_trans "Proxy Python GETTUNEL")\033[1;97m ----------- $P5"
  340. echo -e "${cor[4]} [6] $(msg -verm2 "==>>") \033[1;97m$(fun_trans "Proxy Python TCP BYPASS")\033[1;97m --------- $P6"
  341. echo -e "${cor[4]} [7] $(msg -verm2 "==>>") \033[1;97m$(fun_trans " ¡¡ PARAR TODOS LOS PROXY'S !!")"
  342. echo -e "$(msg -bar)\n${cor[4]} [0] $(msg -verm2 "==>>") \e[97m\033[1;41m VOLVER \033[1;37m"
  343. msg -bar
  344. IP=(meu_ip)
  345. while [[ -z $portproxy || $portproxy != @(0|[1-7]) ]]; do
  346. echo -ne "$(fun_trans "Digite Una Opcion"): \033[1;37m" && read portproxy
  347. tput cuu1 && tput dl1
  348. done
  349. case $portproxy in
  350. 7)remove_fun;;
  351. 0)return;;
  352. esac
  353. echo -e "\033[1;33m Selecciona Puerto Principal del Proxy"
  354. msg -bar
  355. porta_socket=
  356. while [[ -z $porta_socket || ! -z $(mportas|grep -w $porta_socket) ]]; do
  357. echo -ne "Digite el Puerto: \033[1;92m" && read porta_socket
  358. tput cuu1 && tput dl1
  359. done
  360. echo -e "$(fun_trans "Introdusca su Mini-Banner")"
  361. msg -bar
  362. echo -ne "Introduzca el texto de estado plano o en HTML:\n \033[1;37m" && read texto_soket
  363. msg -bar
  364. case $portproxy in
  365. 1)screen -dmS screen python ${SCPinst}/PPub.py "$porta_socket" "$texto_soket";;
  366. 2)screen -dmS screen python3 ${SCPinst}/PPriv.py "$porta_socket" "$texto_soket" "$IP";;
  367. 3)PythonDic_fun;;
  368. 4)screen -dmS screen python ${SCPinst}/POpen.py "$porta_socket" "$texto_soket";;
  369. 5)gettunel_fun "$porta_socket";;
  370. 6)tcpbypass_fun "$porta_socket" "$texto_soket";;
  371. esac
  372. echo -e "\033[1;92m$(fun_trans "Procedimiento COMPLETO")"
  373. msg -bar
  374. }
  375. iniciarsocks