1
0

sockspy.sh 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. #!/bin/bash
  2. ll="/usr/local/include/snaps" && [[ ! -d ${ll} ]] && exit
  3. #
  4. clear
  5. clear
  6. SCPdir="/etc/VPS-MX"
  7. SCPfrm="${SCPdir}/herramientas" && [[ ! -d ${SCPfrm} ]] && exit
  8. SCPinst="${SCPdir}/protocolos" && [[ ! -d ${SCPinst} ]] && exit
  9. declare -A cor=([0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m")
  10. [[ $(dpkg --get-selections | grep -w "python" | head -1) ]] || apt-get install python -y &>/dev/null
  11. [[ $(dpkg --get-selections | grep -w "python-pip" | head -1) ]] || apt-get install python pip -y &>/dev/null
  12. [[ $(dpkg --get-selections | grep -w "net-tools" | head -1) ]] || apt-get install net-tools -y &>/dev/null
  13. mportas() {
  14. unset portas
  15. portas_var=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" | grep -v "COMMAND" | grep "LISTEN")
  16. while read port; do
  17. var1=$(echo $port | awk '{print $1}') && var2=$(echo $port | awk '{print $9}' | awk -F ":" '{print $2}')
  18. [[ "$(echo -e $portas | grep "$var1 $var2")" ]] || portas+="$var1 $var2\n"
  19. done <<<"$portas_var"
  20. i=1
  21. echo -e "$portas"
  22. }
  23. meu_ip() {
  24. 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)
  25. MEU_IP2=$(wget -qO- ipv4.icanhazip.com)
  26. [[ "$MEU_IP" != "$MEU_IP2" ]] && echo "$MEU_IP2" || echo "$MEU_IP"
  27. }
  28. IP=$(wget -qO- ipv4.icanhazip.com)
  29. tcpbypass_fun() {
  30. [[ -e $HOME/socks ]] && rm -rf $HOME/socks >/dev/null 2>&1
  31. [[ -d $HOME/socks ]] && rm -rf $HOME/socks >/dev/null 2>&1
  32. cd $HOME && mkdir socks >/dev/null 2>&1
  33. cd socks
  34. patch="https://www.dropbox.com/s/mn75pqufdc7zn97/backsocz"
  35. arq="backsocz"
  36. wget $patch -o /dev/null
  37. unzip $arq >/dev/null 2>&1
  38. mv -f ./ssh /etc/ssh/sshd_config && service ssh restart 1>/dev/null 2>/dev/null
  39. mv -f sckt$(python3 --version | awk '{print $2}' | cut -d'.' -f1,2) /usr/sbin/sckt
  40. mv -f scktcheck /bin/scktcheck
  41. chmod +x /bin/scktcheck
  42. chmod +x /usr/sbin/sckt
  43. rm -rf $HOME/socks
  44. cd $HOME
  45. msg="$2"
  46. [[ $msg = "" ]] && msg="@vpsmod"
  47. portxz="$1"
  48. [[ $portxz = "" ]] && portxz="8080"
  49. screen -dmS sokz scktcheck "$portxz" "$msg" >/dev/null 2>&1
  50. }
  51. l="/usr/local/lib/sped" && [[ ! -d ${l} ]] && exit
  52. gettunel_fun() {
  53. echo "master=NetVPS" >${SCPinst}/pwd.pwd
  54. while read service; do
  55. [[ -z $service ]] && break
  56. echo "127.0.0.1:$(echo $service | cut -d' ' -f2)=$(echo $service | cut -d' ' -f1)" >>${SCPinst}/pwd.pwd
  57. done <<<"$(mportas)"
  58. screen -dmS getpy python ${SCPinst}/PGet.py -b "0.0.0.0:$1" -p "${SCPinst}/pwd.pwd"
  59. [[ "$(ps x | grep "PGet.py" | grep -v "grep" | awk -F "pts" '{print $1}')" ]] && {
  60. echo -e "Gettunel Iniciado con Sucesso"
  61. msg -bar
  62. echo -ne "Su contraseña Gettunel es:"
  63. echo -e "\033[1;32m NetVPS"
  64. msg -bar
  65. } || echo -e "Gettunel no fue iniciado"
  66. msg -bar
  67. }
  68. sistema20() {
  69. if [[ ! -e /etc/VPS-MX/fix ]]; then
  70. echo ""
  71. ins() {
  72. export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games/
  73. apt-get install python -y
  74. apt-get install python pip -y
  75. }
  76. ins &>/dev/null && echo -e "INSTALANDO FIX" | pv -qL 40
  77. sleep 1.s
  78. [[ ! -e /etc/VPS-MX/fix ]] && touch /etc/VPS-MX/fix
  79. else
  80. echo ""
  81. fi
  82. }
  83. sistema22() {
  84. if [[ ! -e /etc/VPS-MX/fixer ]]; then
  85. echo ""
  86. ins() {
  87. export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games/
  88. apt-get install python2 -y
  89. apt-get install python -y
  90. apt install python pip -y
  91. rm -rf /usr/bin/python
  92. ln -s /usr/bin/python2.7 /usr/bin/python
  93. }
  94. ins &>/dev/null && echo -e "INSTALANDO FIX" | pv -qL 40
  95. sleep 1.s
  96. [[ ! -e /etc/VPS-MX/fixer ]] && touch /etc/VPS-MX/fixer
  97. else
  98. echo ""
  99. fi
  100. }
  101. PythonDic_fun() {
  102. clear
  103. echo ""
  104. echo ""
  105. msg -tit
  106. msg -bar
  107. echo -e "\033[1;31m SOCKS DIRECTO-PY | CUSTOM\033[0m"
  108. while true; do
  109. msg -bar
  110. echo -ne "\033[1;37m"
  111. read -p " ESCRIBE SU PUERTO: " porta_socket
  112. echo -e ""
  113. [[ $(mportas | grep -w "$porta_socket") ]] || break
  114. echo -e " ESTE PUERTO YA ESTÁ EN USO"
  115. unset porta_socket
  116. done
  117. msg -bar
  118. echo -e "\033[1;97m Digite Un Puerto Local 22|443|80\033[1;37m"
  119. msg -bar
  120. while true; do
  121. echo -ne "\033[1;36m"
  122. read -p " Digite Un Puerto SSH/DROPBEAR activo: " PORTLOC
  123. echo -e ""
  124. if [[ ! -z $PORTLOC ]]; then
  125. if [[ $(echo $PORTLOC | grep [0-9]) ]]; then
  126. [[ $(mportas | grep $PORTLOC | head -1) ]] && break || echo -e "ESTE PUERTO NO EXISTE"
  127. fi
  128. fi
  129. done
  130. #
  131. puertoantla="$(mportas | grep $PORTLOC | awk '{print $2}' | head -1)"
  132. msg -bar
  133. echo -ne " Escribe El HTTP Response? 101|200|300: \033[1;37m" && read cabezado
  134. tput cuu1 && tput dl1
  135. if [[ -z $cabezado ]]; then
  136. cabezado="200"
  137. echo -e " \e[31mResponse Default:\033[1;32m ${cabezado}"
  138. else
  139. echo -e " \e[31mResponse Elegido:\033[1;32m ${cabezado}"
  140. fi
  141. msg -bar
  142. echo -e "$(fun_trans "Introdusca su Mini-Banner")"
  143. msg -bar
  144. echo -ne " Introduzca el texto de estado plano o en HTML:\n \033[1;37m" && read texto_soket
  145. tput cuu1 && tput dl1
  146. if [[ -z $texto_soket ]]; then
  147. texto_soket="@lacasitamx"
  148. echo -e " \e[31mMensage Default: \033[1;32m${texto_soket} "
  149. else
  150. echo -e " \e[31mMensage: \033[1;32m ${texto_soket}"
  151. fi
  152. msg -bar
  153. (
  154. less <<CPM >/etc/VPS-MX/protocolos/PDirect.py
  155. import socket, threading, thread, select, signal, sys, time, getopt
  156. # Listen
  157. LISTENING_ADDR = '0.0.0.0'
  158. LISTENING_PORT = int("$porta_socket")
  159. PASS = ''
  160. # CONST
  161. BUFLEN = 4096 * 4
  162. TIMEOUT = 60
  163. DEFAULT_HOST = '127.0.0.1:$puertoantla'
  164. RESPONSE = 'HTTP/1.1 $cabezado <strong>$texto_soket</strong>\r\n\r\nHTTP/1.1 $cabezado Conexion Exitosa\r\n\r\n'
  165. class Server(threading.Thread):
  166. def __init__(self, host, port):
  167. threading.Thread.__init__(self)
  168. self.running = False
  169. self.host = host
  170. self.port = port
  171. self.threads = []
  172. self.threadsLock = threading.Lock()
  173. self.logLock = threading.Lock()
  174. def run(self):
  175. self.soc = socket.socket(socket.AF_INET)
  176. self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  177. self.soc.settimeout(2)
  178. self.soc.bind((self.host, self.port))
  179. self.soc.listen(0)
  180. self.running = True
  181. try:
  182. while self.running:
  183. try:
  184. c, addr = self.soc.accept()
  185. c.setblocking(1)
  186. except socket.timeout:
  187. continue
  188. conn = ConnectionHandler(c, self, addr)
  189. conn.start()
  190. self.addConn(conn)
  191. finally:
  192. self.running = False
  193. self.soc.close()
  194. def printLog(self, log):
  195. self.logLock.acquire()
  196. print log
  197. self.logLock.release()
  198. def addConn(self, conn):
  199. try:
  200. self.threadsLock.acquire()
  201. if self.running:
  202. self.threads.append(conn)
  203. finally:
  204. self.threadsLock.release()
  205. def removeConn(self, conn):
  206. try:
  207. self.threadsLock.acquire()
  208. self.threads.remove(conn)
  209. finally:
  210. self.threadsLock.release()
  211. def close(self):
  212. try:
  213. self.running = False
  214. self.threadsLock.acquire()
  215. threads = list(self.threads)
  216. for c in threads:
  217. c.close()
  218. finally:
  219. self.threadsLock.release()
  220. class ConnectionHandler(threading.Thread):
  221. def __init__(self, socClient, server, addr):
  222. threading.Thread.__init__(self)
  223. self.clientClosed = False
  224. self.targetClosed = True
  225. self.client = socClient
  226. self.client_buffer = ''
  227. self.server = server
  228. self.log = 'Connection: ' + str(addr)
  229. def close(self):
  230. try:
  231. if not self.clientClosed:
  232. self.client.shutdown(socket.SHUT_RDWR)
  233. self.client.close()
  234. except:
  235. pass
  236. finally:
  237. self.clientClosed = True
  238. try:
  239. if not self.targetClosed:
  240. self.target.shutdown(socket.SHUT_RDWR)
  241. self.target.close()
  242. except:
  243. pass
  244. finally:
  245. self.targetClosed = True
  246. def run(self):
  247. try:
  248. self.client_buffer = self.client.recv(BUFLEN)
  249. hostPort = self.findHeader(self.client_buffer, 'X-Real-Host')
  250. if hostPort == '':
  251. hostPort = DEFAULT_HOST
  252. split = self.findHeader(self.client_buffer, 'X-Split')
  253. if split != '':
  254. self.client.recv(BUFLEN)
  255. if hostPort != '':
  256. passwd = self.findHeader(self.client_buffer, 'X-Pass')
  257. if len(PASS) != 0 and passwd == PASS:
  258. self.method_CONNECT(hostPort)
  259. elif len(PASS) != 0 and passwd != PASS:
  260. self.client.send('HTTP/1.1 400 WrongPass!\r\n\r\n')
  261. elif hostPort.startswith('127.0.0.1') or hostPort.startswith('localhost'):
  262. self.method_CONNECT(hostPort)
  263. else:
  264. self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
  265. else:
  266. print '- No X-Real-Host!'
  267. self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
  268. except Exception as e:
  269. self.log += ' - error: ' + e.strerror
  270. self.server.printLog(self.log)
  271. pass
  272. finally:
  273. self.close()
  274. self.server.removeConn(self)
  275. def findHeader(self, head, header):
  276. aux = head.find(header + ': ')
  277. if aux == -1:
  278. return ''
  279. aux = head.find(':', aux)
  280. head = head[aux+2:]
  281. aux = head.find('\r\n')
  282. if aux == -1:
  283. return ''
  284. return head[:aux];
  285. def connect_target(self, host):
  286. i = host.find(':')
  287. if i != -1:
  288. port = int(host[i+1:])
  289. host = host[:i]
  290. else:
  291. if self.method=='CONNECT':
  292. port = 443
  293. else:
  294. port = 80
  295. port = 8080
  296. port = 8799
  297. port = 3128
  298. (soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]
  299. self.target = socket.socket(soc_family, soc_type, proto)
  300. self.targetClosed = False
  301. self.target.connect(address)
  302. def method_CONNECT(self, path):
  303. self.log += ' - CONNECT ' + path
  304. self.connect_target(path)
  305. self.client.sendall(RESPONSE)
  306. self.client_buffer = ''
  307. self.server.printLog(self.log)
  308. self.doCONNECT()
  309. def doCONNECT(self):
  310. socs = [self.client, self.target]
  311. count = 0
  312. error = False
  313. while True:
  314. count += 1
  315. (recv, _, err) = select.select(socs, [], socs, 3)
  316. if err:
  317. error = True
  318. if recv:
  319. for in_ in recv:
  320. try:
  321. data = in_.recv(BUFLEN)
  322. if data:
  323. if in_ is self.target:
  324. self.client.send(data)
  325. else:
  326. while data:
  327. byte = self.target.send(data)
  328. data = data[byte:]
  329. count = 0
  330. else:
  331. break
  332. except:
  333. error = True
  334. break
  335. if count == TIMEOUT:
  336. error = True
  337. if error:
  338. break
  339. def main(host=LISTENING_ADDR, port=LISTENING_PORT):
  340. print "\n:-------PythonProxy-------:\n"
  341. print "Listening addr: " + LISTENING_ADDR
  342. print "Listening port: " + str(LISTENING_PORT) + "\n"
  343. print ":-------------------------:\n"
  344. server = Server(LISTENING_ADDR, LISTENING_PORT)
  345. server.start()
  346. while True:
  347. try:
  348. time.sleep(2)
  349. except KeyboardInterrupt:
  350. print 'Stopping...'
  351. server.close()
  352. break
  353. if __name__ == '__main__':
  354. main()
  355. CPM
  356. ) >$HOME/proxy.log &
  357. chmod +x /etc/VPS-MX/protocolos/PDirect.py
  358. screen -dmS ws$porta_socket python ${SCPinst}/PDirect.py $porta_socket $texto_soket >/root/proxy.log &
  359. #screen -dmS pydic-"$porta_socket" python ${SCPinst}/PDirect.py "$porta_socket" "$texto_soket" && echo ""$porta_socket" "$texto_soket"" >> /etc/VPS-MX/PortPD.log
  360. echo "$porta_socket $texto_soket" >/etc/VPS-MX/PortPD.log
  361. [[ $(grep -wc "PDirect.py" /etc/autostart) = '0' ]] && {
  362. echo -e "netstat -tlpn | grep -w $porta_socket > /dev/null || { screen -r -S 'ws$porta_socket' -X quit; screen -dmS ws$porta_socket python ${SCPinst}/PDirect.py $porta_socket $texto_soket; }" >>/etc/autostart
  363. } || {
  364. sed -i '/PDirect.py/d' /etc/autostart
  365. echo -e "netstat -tlpn | grep -w $porta_socket > /dev/null || { screen -r -S 'ws$porta_socket' -X quit; screen -dmS ws$porta_socket python ${SCPinst}/PDirect.py $porta_socket $texto_soket; }" >>/etc/autostart
  366. }
  367. }
  368. pythontest() {
  369. clear
  370. echo ""
  371. echo ""
  372. msg -tit
  373. msg -bar
  374. echo -e "\033[1;31m SOCKS DIRECTO-PY | CUSTOM\033[0m"
  375. while true; do
  376. msg -bar
  377. echo -ne "\033[1;37m"
  378. read -p " ESCRIBE SU PUERTO: " porta_socket
  379. echo -e ""
  380. [[ $(mportas | grep -w "$porta_socket") ]] || break
  381. echo -e " ESTE PUERTO YA ESTÁ EN USO"
  382. unset porta_socket
  383. done
  384. msg -bar
  385. echo -e "\033[1;97m Digite Un Puerto Local 22|443|80\033[1;37m"
  386. msg -bar
  387. while true; do
  388. echo -ne "\033[1;36m"
  389. read -p " Digite Un Puerto SSH/DROPBEAR activo: " PORTLOC
  390. echo -e ""
  391. if [[ ! -z $PORTLOC ]]; then
  392. if [[ $(echo $PORTLOC | grep [0-9]) ]]; then
  393. [[ $(mportas | grep $PORTLOC | head -1) ]] && break || echo -e "ESTE PUERTO NO EXISTE"
  394. fi
  395. fi
  396. done
  397. #
  398. puertoantla="$(mportas | grep $PORTLOC | awk '{print $2}' | head -1)"
  399. msg -bar
  400. echo -ne " Escribe El HTTP Response? 101|200|300: \033[1;37m" && read cabezado
  401. tput cuu1 && tput dl1
  402. if [[ -z $cabezado ]]; then
  403. cabezado="200"
  404. echo -e " \e[31mResponse Default:\033[1;32m ${cabezado}"
  405. else
  406. echo -e " \e[31mResponse Elegido:\033[1;32m ${cabezado}"
  407. fi
  408. msg -bar
  409. echo -e "$(fun_trans "Introdusca su Mini-Banner")"
  410. msg -bar
  411. echo -ne " Introduzca el texto de estado plano o en HTML:\n \033[1;37m" && read texto_soket
  412. tput cuu1 && tput dl1
  413. if [[ -z $texto_soket ]]; then
  414. texto_soket="@lacasitamx"
  415. echo -e " \e[31mMensage Default: \033[1;32m${texto_soket} "
  416. else
  417. echo -e " \e[31mMensage: \033[1;32m ${texto_soket}"
  418. fi
  419. msg -bar
  420. (
  421. less <<CPM >/etc/VPS-MX/protocolos/python.py
  422. import socket, threading, thread, select, signal, sys, time, getopt
  423. # Listen
  424. LISTENING_ADDR = '0.0.0.0'
  425. LISTENING_PORT = int("$porta_socket")
  426. PASS = ''
  427. # CONST
  428. BUFLEN = 4096 * 4
  429. TIMEOUT = 60
  430. DEFAULT_HOST = '127.0.0.1:$puertoantla'
  431. RESPONSE = 'HTTP/1.1 $cabezado <strong>$texto_soket</strong>\r\n\r\nHTTP/1.1 $cabezado Conexion Exitosa\r\n\r\n'
  432. class Server(threading.Thread):
  433. def __init__(self, host, port):
  434. threading.Thread.__init__(self)
  435. self.running = False
  436. self.host = host
  437. self.port = port
  438. self.threads = []
  439. self.threadsLock = threading.Lock()
  440. self.logLock = threading.Lock()
  441. def run(self):
  442. self.soc = socket.socket(socket.AF_INET)
  443. self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  444. self.soc.settimeout(2)
  445. self.soc.bind((self.host, self.port))
  446. self.soc.listen(0)
  447. self.running = True
  448. try:
  449. while self.running:
  450. try:
  451. c, addr = self.soc.accept()
  452. c.setblocking(1)
  453. except socket.timeout:
  454. continue
  455. conn = ConnectionHandler(c, self, addr)
  456. conn.start()
  457. self.addConn(conn)
  458. finally:
  459. self.running = False
  460. self.soc.close()
  461. def printLog(self, log):
  462. self.logLock.acquire()
  463. print log
  464. self.logLock.release()
  465. def addConn(self, conn):
  466. try:
  467. self.threadsLock.acquire()
  468. if self.running:
  469. self.threads.append(conn)
  470. finally:
  471. self.threadsLock.release()
  472. def removeConn(self, conn):
  473. try:
  474. self.threadsLock.acquire()
  475. self.threads.remove(conn)
  476. finally:
  477. self.threadsLock.release()
  478. def close(self):
  479. try:
  480. self.running = False
  481. self.threadsLock.acquire()
  482. threads = list(self.threads)
  483. for c in threads:
  484. c.close()
  485. finally:
  486. self.threadsLock.release()
  487. class ConnectionHandler(threading.Thread):
  488. def __init__(self, socClient, server, addr):
  489. threading.Thread.__init__(self)
  490. self.clientClosed = False
  491. self.targetClosed = True
  492. self.client = socClient
  493. self.client_buffer = ''
  494. self.server = server
  495. self.log = 'Connection: ' + str(addr)
  496. def close(self):
  497. try:
  498. if not self.clientClosed:
  499. self.client.shutdown(socket.SHUT_RDWR)
  500. self.client.close()
  501. except:
  502. pass
  503. finally:
  504. self.clientClosed = True
  505. try:
  506. if not self.targetClosed:
  507. self.target.shutdown(socket.SHUT_RDWR)
  508. self.target.close()
  509. except:
  510. pass
  511. finally:
  512. self.targetClosed = True
  513. def run(self):
  514. try:
  515. self.client_buffer = self.client.recv(BUFLEN)
  516. hostPort = self.findHeader(self.client_buffer, 'X-Real-Host')
  517. if hostPort == '':
  518. hostPort = DEFAULT_HOST
  519. split = self.findHeader(self.client_buffer, 'X-Split')
  520. if split != '':
  521. self.client.recv(BUFLEN)
  522. if hostPort != '':
  523. passwd = self.findHeader(self.client_buffer, 'X-Pass')
  524. if len(PASS) != 0 and passwd == PASS:
  525. self.method_CONNECT(hostPort)
  526. elif len(PASS) != 0 and passwd != PASS:
  527. self.client.send('HTTP/1.1 400 WrongPass!\r\n\r\n')
  528. elif hostPort.startswith('127.0.0.1') or hostPort.startswith('localhost'):
  529. self.method_CONNECT(hostPort)
  530. else:
  531. self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
  532. else:
  533. print '- No X-Real-Host!'
  534. self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
  535. except Exception as e:
  536. self.log += ' - error: ' + e.strerror
  537. self.server.printLog(self.log)
  538. pass
  539. finally:
  540. self.close()
  541. self.server.removeConn(self)
  542. def findHeader(self, head, header):
  543. aux = head.find(header + ': ')
  544. if aux == -1:
  545. return ''
  546. aux = head.find(':', aux)
  547. head = head[aux+2:]
  548. aux = head.find('\r\n')
  549. if aux == -1:
  550. return ''
  551. return head[:aux];
  552. def connect_target(self, host):
  553. i = host.find(':')
  554. if i != -1:
  555. port = int(host[i+1:])
  556. host = host[:i]
  557. else:
  558. if self.method=='CONNECT':
  559. port = 443
  560. else:
  561. port = 80
  562. port = 8080
  563. port = 8799
  564. port = 3128
  565. (soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]
  566. self.target = socket.socket(soc_family, soc_type, proto)
  567. self.targetClosed = False
  568. self.target.connect(address)
  569. def method_CONNECT(self, path):
  570. self.log += ' - CONNECT ' + path
  571. self.connect_target(path)
  572. self.client.sendall(RESPONSE)
  573. self.client_buffer = ''
  574. self.server.printLog(self.log)
  575. self.doCONNECT()
  576. def doCONNECT(self):
  577. socs = [self.client, self.target]
  578. count = 0
  579. error = False
  580. while True:
  581. count += 1
  582. (recv, _, err) = select.select(socs, [], socs, 3)
  583. if err:
  584. error = True
  585. if recv:
  586. for in_ in recv:
  587. try:
  588. data = in_.recv(BUFLEN)
  589. if data:
  590. if in_ is self.target:
  591. self.client.send(data)
  592. else:
  593. while data:
  594. byte = self.target.send(data)
  595. data = data[byte:]
  596. count = 0
  597. else:
  598. break
  599. except:
  600. error = True
  601. break
  602. if count == TIMEOUT:
  603. error = True
  604. if error:
  605. break
  606. def main(host=LISTENING_ADDR, port=LISTENING_PORT):
  607. print "\n:-------PythonProxy-------:\n"
  608. print "Listening addr: " + LISTENING_ADDR
  609. print "Listening port: " + str(LISTENING_PORT) + "\n"
  610. print ":-------------------------:\n"
  611. server = Server(LISTENING_ADDR, LISTENING_PORT)
  612. server.start()
  613. while True:
  614. try:
  615. time.sleep(2)
  616. except KeyboardInterrupt:
  617. print 'Stopping...'
  618. server.close()
  619. break
  620. if __name__ == '__main__':
  621. main()
  622. CPM
  623. ) >$HOME/proxy.log &
  624. chmod +x /etc/VPS-MX/protocolos/python.py
  625. echo -e "[Unit]\nDescription=python.py Service by @lacasitamx\nAfter=network.target\nStartLimitIntervalSec=0\n\n[Service]\nType=simple\nUser=root\nWorkingDirectory=/root\nExecStart=/usr/bin/python ${SCPinst}/python.py $porta_socket $texto_soket\nRestart=always\nRestartSec=3s\n[Install]\nWantedBy=multi-user.target" >/etc/systemd/system/python.PD.service
  626. echo "$porta_socket $texto_soket" >/etc/VPS-MX/PortPD.log
  627. systemctl enable python.PD &>/dev/null
  628. systemctl start python.PD &>/dev/null
  629. }
  630. pid_kill() {
  631. [[ -z $1 ]] && refurn 1
  632. pids="$@"
  633. for pid in $(echo $pids); do
  634. kill -9 $pid &>/dev/null
  635. done
  636. }
  637. selecionador() {
  638. clear
  639. echo ""
  640. echo ""
  641. echo ""
  642. while true; do
  643. msg -bar
  644. echo -ne "\033[1;37m"
  645. read -p " ESCRIBE SU PUERTO: " porta_socket
  646. echo -e ""
  647. [[ $(mportas | grep -w "$porta_socket") ]] || break
  648. echo -e " ESTE PUERTO YA ESTÁ EN USO"
  649. unset porta_socket
  650. done
  651. echo -e "Introdusca su Mini-Banner"
  652. msg -bar
  653. echo -ne "Introduzca el texto de estado plano o en HTML:\n \033[1;37m" && read texto_soket
  654. msg -bar
  655. }
  656. remove_fun() {
  657. echo -e "Parando Socks Python"
  658. msg -bar
  659. pidproxy=$(ps x | grep "PPub.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy ]] && pid_kill $pidproxy
  660. pidproxy2=$(ps x | grep "PPriv.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy2 ]] && pid_kill $pidproxy2
  661. pidproxy3=$(ps x | grep "PDirect.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy3 ]] && pid_kill $pidproxy3
  662. pidproxy4=$(ps x | grep "POpen.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy4 ]] && pid_kill $pidproxy4
  663. pidproxy5=$(ps x | grep "PGet.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy5 ]] && pid_kill $pidproxy5
  664. pidproxy6=$(ps x | grep "scktcheck" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy6 ]] && pid_kill $pidproxy6
  665. pidproxy7=$(ps x | grep "python.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy7 ]] && pid_kill $pidproxy7
  666. pidproxy8=$(ps x | grep "lacasitamx.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy8 ]] && pid_kill $pidproxy8
  667. echo -e "\033[1;91mSocks DETENIDOS"
  668. msg -bar
  669. rm /etc/VPS-MX/PortPD.log &>/dev/null
  670. echo "" >/etc/VPS-MX/PortPD.log
  671. for pidproxy in $(screen -ls | grep ".ws" | awk {'print $1'}); do
  672. screen -r -S "$pidproxy" -X quit
  673. done
  674. [[ $(grep -wc "PDirect.py" /etc/autostart) != '0' ]] && {
  675. sed -i '/PDirect.py/d' /etc/autostart
  676. }
  677. sleep 1
  678. screen -wipe >/dev/null
  679. systemctl stop python.PD &>/dev/null
  680. systemctl disable python.PD &>/dev/null
  681. rm /etc/systemd/system/python.PD.service &>/dev/null
  682. exit 0
  683. }
  684. iniciarsocks() {
  685. pidproxy=$(ps x | grep -w "PPub.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy ]] && P1="\033[1;32m[ON]" || P1="\e[37m[\033[1;31mOFF\e[37m]"
  686. pidproxy2=$(ps x | grep -w "PPriv.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy2 ]] && P2="\033[1;32m[ON]" || P2="\e[37m[\033[1;31mOFF\e[37m]"
  687. pidproxy3=$(ps x | grep -w "PDirect.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy3 ]] && P3="\033[1;32m[ON]" || P3="\e[37m[\033[1;31mOFF\e[37m]"
  688. pidproxy4=$(ps x | grep -w "POpen.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy4 ]] && P4="\033[1;32m[ON]" || P4="\e[37m[\033[1;31mOFF\e[37m]"
  689. pidproxy5=$(ps x | grep "PGet.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy5 ]] && P5="\033[1;32m[ON]" || P5="\e[37m[\033[1;31mOFF\e[37m]"
  690. pidproxy6=$(ps x | grep "scktcheck" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy6 ]] && P6="\033[1;32m[ON]" || P6="\e[37m[\033[1;31mOFF\e[37m]"
  691. pidproxy7=$(ps x | grep "python.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy7 ]] && P7="\033[1;32m[ON]" || P7="\e[37m[\033[1;31mOFF\e[37m]"
  692. pidproxy8=$(ps x | grep "python.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy8 ]] && P8="\033[1;32m[ON]" || P8="\e[37m[\033[1;31mOFF\e[37m]"
  693. #msg -bar
  694. msg -tit
  695. msg -bar
  696. echo -e " \e[91m\e[43mINSTALADOR DE PROXY'S\e[0m "
  697. msg -bar
  698. echo -e " \e[1;93m[\e[92m1\e[93m] \e[97m$(msg -verm2 "➛ ")\033[1;97mProxy Python SIMPLE $P1"
  699. echo -e " \e[1;93m[\e[92m2\e[93m] \e[97m$(msg -verm2 "➛ ")\033[1;97mProxy Python SEGURO $P2"
  700. echo -e " \e[1;93m[\e[92m3\e[93m] \e[97m$(msg -verm2 "➛ ")\033[1;97mProxy WEBSOCKET Custom $P3 \e[1;32m(Screen TEST)"
  701. echo -e " \e[1;93m[\e[92m4\e[93m] \e[97m$(msg -verm2 "➛ ")\033[1;97mProxy WEBSOCKET Custom $P7 \e[1;32m(Socks HTTP)"
  702. echo -e " \e[1;93m[\e[92m5\e[93m] \e[97m$(msg -verm2 "➛ ")\033[1;97mProxy Python OPENVPN $P4"
  703. echo -e " \e[1;93m[\e[92m6\e[93m] \e[97m$(msg -verm2 "➛ ")\033[1;97mProxy Python GETTUNEL $P5"
  704. echo -e " \e[1;93m[\e[92m7\e[93m] \e[97m$(msg -verm2 "➛ ")\033[1;97mProxy Python TCP BYPASS $P6"
  705. echo -e " \e[1;93m[\e[92m8\e[93m] \e[97m$(msg -verm2 "➛ ")\033[1;97mAplicar Fix en \e[1;32m(Ubu22 o Debian11 )"
  706. echo -e " \e[1;93m[\e[92m9\e[93m] \e[97m$(msg -verm2 "➛ ")\033[1;97mDETENER SERVICIO PYTHON"
  707. msg -bar
  708. echo -e " \e[1;93m[\e[92m0\e[93m] \e[97m$(msg -verm2 "➛ ") \e[97m\033[1;41m VOLVER \033[1;37m"
  709. msg -bar
  710. IP=(meu_ip)
  711. while [[ -z $portproxy || $portproxy != @(0|[1-9]) ]]; do
  712. echo -ne " Digite Una Opcion: \033[1;37m" && read portproxy
  713. tput cuu1 && tput dl1
  714. done
  715. case $portproxy in
  716. 1)
  717. selecionador
  718. screen -dmS screen python ${SCPinst}/PPub.py "$porta_socket" "$texto_soket"
  719. ;;
  720. 2)
  721. selecionador
  722. screen -dmS screen python3 ${SCPinst}/PPriv.py "$porta_socket" "$texto_soket" "$IP"
  723. ;;
  724. 3)
  725. PIDI="$(ps aux | grep -v grep | grep "ws")"
  726. if [[ -z $PIDI ]]; then
  727. sistema20
  728. PythonDic_fun
  729. else
  730. for pidproxy in $(screen -ls | grep ".ws" | awk {'print $1'}); do
  731. screen -r -S "$pidproxy" -X quit
  732. done
  733. [[ $(grep -wc "PDirect.py" /etc/autostart) != '0' ]] && {
  734. sed -i '/PDirect.py/d' /etc/autostart
  735. }
  736. sleep 1
  737. screen -wipe >/dev/null
  738. msg -bar
  739. echo -e "\033[1;91mSocks Directo DETENIDO"
  740. msg -bar
  741. exit 0
  742. fi
  743. ;;
  744. 4)
  745. if [[ ! -e /etc/systemd/system/python.PD.service ]]; then
  746. sistema20
  747. pythontest
  748. else
  749. systemctl stop python.PD &>/dev/null
  750. systemctl disable python.PD &>/dev/null
  751. rm /etc/systemd/system/python.PD.service &>/dev/null
  752. msg -bar
  753. echo -e "\033[1;91mSocks Directo DETENIDO"
  754. msg -bar
  755. exit 0
  756. fi
  757. ;;
  758. 5)
  759. selecionador
  760. screen -dmS screen python ${SCPinst}/POpen.py "$porta_socket" "$texto_soket"
  761. ;;
  762. 6)
  763. selecionador
  764. gettunel_fun "$porta_socket"
  765. ;;
  766. 7)
  767. selecionador
  768. tcpbypass_fun "$porta_socket" "$texto_soket"
  769. ;;
  770. 8)
  771. sistema22
  772. msg -bar
  773. msg -ama " AHORA REGRESA EN LA OPCION 3 DE SOCKS HTTP"
  774. msg -bar
  775. ;;
  776. 9) remove_fun ;;
  777. 0) return ;;
  778. esac
  779. echo -e "\033[1;92mProcedimiento COMPLETO"
  780. msg -bar
  781. }
  782. iniciarsocks