Jelajahi Sumber

Subir archivos a 'VPS-MX-8.5-Final Oficial/VPS-MX/protocolos'

yosoyhendrix 3 hari lalu
induk
melakukan
5970da9b80

+ 313 - 313
VPS-MX-8.5-Final Oficial/VPS-MX/protocolos/POpen.py

@@ -1,313 +1,313 @@
-#!/usr/bin/env python
-
-import sys
-import httplib
-from SocketServer import ThreadingMixIn
-from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
-from threading import Lock, Timer
-from cStringIO import StringIO
-from urlparse import urlsplit
-import socket
-import select
-import gzip
-import zlib
-import re
-import traceback
-
-
-class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
-
-    address_family = socket.AF_INET
-
-    def handle_error(self, request, client_address):
-        
-        print >>sys.stderr, '-'*40
-        print >>sys.stderr, 'Exception happened during processing of request from', client_address
-        traceback.print_exc()
-        print >>sys.stderr, '-'*40
-        
-     
-class ThreadingHTTPServer6(ThreadingHTTPServer):
-
-    address_family = socket.AF_INET6
-
-
-class SimpleHTTPProxyHandler(BaseHTTPRequestHandler):
-    global_lock = Lock()
-    conn_table = {}
-    timeout = 300               
-    upstream_timeout = 300    
-    proxy_via = None          
-
-    def log_error(self, format, *args):
-        if format == "Request timed out: %r":
-            return
-        self.log_message(format, *args)
-
-    def do_CONNECT(self):
-        
-
-        req = self
-        reqbody = None
-        req.path = "https://%s/" % req.path.replace(':443', '')
-
-        replaced_reqbody = self.request_handler(req, reqbody)
-        if replaced_reqbody is True:
-            return
-
-        u = urlsplit(req.path)
-        address = (u.hostname, u.port or 443)
-        try:
-            conn = socket.create_connection(address)
-        except socket.error:
-            return
-        self.send_response(200, 'SOCKS5')
-        self.send_header('Connection', 'close')
-        self.end_headers()
-
-        conns = [self.connection, conn]
-        keep_connection = True
-        while keep_connection:
-            keep_connection = False
-            rlist, wlist, xlist = select.select(conns, [], conns, self.timeout)
-            if xlist:
-                break
-            for r in rlist:
-                other = conns[1] if r is conns[0] else conns[0]
-                data = r.recv(8192)
-                if data:
-                    other.sendall(data)
-                    keep_connection = True
-        conn.close()
-
-    def do_HEAD(self):
-        self.do_SPAM()
-
-    def do_GET(self):
-        self.do_SPAM()
-
-    def do_POST(self):
-        self.do_SPAM()
-
-    def do_SPAM(self):
-        req = self
-        content_length = int(req.headers.get('Content-Length', 0))
-        if content_length > 0:
-            reqbody = self.rfile.read(content_length)
-        else:
-            reqbody = None
-
-        replaced_reqbody = self.request_handler(req, reqbody)
-        if replaced_reqbody is True:
-            return
-        elif replaced_reqbody is not None:
-            reqbody = replaced_reqbody
-            if 'Content-Length' in req.headers:
-                req.headers['Content-Length'] = str(len(reqbody))
-
-        
-        self.remove_hop_by_hop_headers(req.headers)
-        if self.upstream_timeout:
-            req.headers['Connection'] = 'Keep-Alive'
-        else:
-            req.headers['Connection'] = 'close'
-        if self.proxy_via:
-            self.modify_via_header(req.headers)
-
-        try:
-            res, resdata = self.request_to_upstream_server(req, reqbody)
-        except socket.error:
-            return
-
-        content_encoding = res.headers.get('Content-Encoding', 'identity')
-        resbody = self.decode_content_body(resdata, content_encoding)
-
-        replaced_resbody = self.response_handler(req, reqbody, res, resbody)
-        if replaced_resbody is True:
-            return
-        elif replaced_resbody is not None:
-            resdata = self.encode_content_body(replaced_resbody, content_encoding)
-            if 'Content-Length' in res.headers:
-                res.headers['Content-Length'] = str(len(resdata))
-            resbody = replaced_resbody
-
-        self.remove_hop_by_hop_headers(res.headers)
-        if self.timeout:
-            res.headers['Connection'] = 'Keep-Alive'
-        else:
-            res.headers['Connection'] = 'close'
-        if self.proxy_via:
-            self.modify_via_header(res.headers)
-
-        self.send_response(res.status, res.reason)
-        for k, v in res.headers.items():
-            if k == 'set-cookie':
-                
-                for value in self.split_set_cookie_header(v):
-                    self.send_header(k, value)
-            else:
-                self.send_header(k, v)
-        self.end_headers()
-
-        if self.command != 'HEAD':
-            self.wfile.write(resdata)
-            with self.global_lock:
-                self.save_handler(req, reqbody, res, resbody)
-
-    def request_to_upstream_server(self, req, reqbody):
-        u = urlsplit(req.path)
-        origin = (u.scheme, u.netloc)
-
-        
-        req.headers['Host'] = u.netloc
-        selector = "%s?%s" % (u.path, u.query) if u.query else u.path
-
-        while True:
-            with self.lock_origin(origin):
-                conn = self.open_origin(origin)
-                try:
-                    conn.request(req.command, selector, reqbody, headers=dict(req.headers))
-                except socket.error:
-                    
-                    self.close_origin(origin)
-                    raise
-                try:
-                    res = conn.getresponse(buffering=True)
-                except httplib.BadStatusLine as e:
-                    if e.line == "''":
-                        
-                        self.close_origin(origin)
-                        continue
-                    else:
-                        raise
-                resdata = res.read()
-                res.headers = res.msg    
-                if not self.upstream_timeout or 'close' in res.headers.get('Connection', ''):
-                    self.close_origin(origin)
-                else:
-                    self.reset_timer(origin)
-            return res, resdata
-
-    def lock_origin(self, origin):
-        d = self.conn_table.setdefault(origin, {})
-        if not 'lock' in d:
-            d['lock'] = Lock()
-        return d['lock']
-
-    def open_origin(self, origin):
-        conn = self.conn_table[origin].get('connection')
-        if not conn:
-            scheme, netloc = origin
-            if scheme == 'https':
-                conn = httplib.HTTPSConnection(netloc)
-            else:
-                conn = httplib.HTTPConnection(netloc)
-            self.reset_timer(origin)
-            self.conn_table[origin]['connection'] = conn
-        return conn
-
-    def reset_timer(self, origin):
-        timer = self.conn_table[origin].get('timer')
-        if timer:
-            timer.cancel()
-        if self.upstream_timeout:
-            timer = Timer(self.upstream_timeout, self.close_origin, args=[origin])
-            timer.daemon = True
-            timer.start()
-        else:
-            timer = None
-        self.conn_table[origin]['timer'] = timer
-
-    def close_origin(self, origin):
-        timer = self.conn_table[origin]['timer']
-        if timer:
-            timer.cancel()
-        conn = self.conn_table[origin]['connection']
-        conn.close()
-        del self.conn_table[origin]['connection']
-
-    def remove_hop_by_hop_headers(self, headers):
-        hop_by_hop_headers = ['Connection', 'Keep-Alive', 'Proxy-Authenticate', 'Proxy-Authorization', 'TE', 'Trailers', 'Trailer', 'Transfer-Encoding', 'Upgrade']
-        connection = headers.get('Connection')
-        if connection:
-            keys = re.split(r',\s*', connection)
-            hop_by_hop_headers.extend(keys)
-
-        for k in hop_by_hop_headers:
-            if k in headers:
-                del headers[k]
-
-    def modify_via_header(self, headers):
-        via_string = "%s %s" % (self.protocol_version, self.proxy_via)
-        via_string = re.sub(r'^HTTP/', '', via_string)
-
-        original = headers.get('Via')
-        if original:
-            headers['Via'] = original + ', ' + via_string
-        else:
-            headers['Via'] = via_string
-
-    def decode_content_body(self, data, content_encoding):
-        if content_encoding in ('gzip', 'x-gzip'):
-            io = StringIO(data)
-            with gzip.GzipFile(fileobj=io) as f:
-                body = f.read()
-        elif content_encoding == 'deflate':
-            body = zlib.decompress(data)
-        elif content_encoding == 'identity':
-            body = data
-        else:
-            raise Exception("Unknown Content-Encoding: %s" % content_encoding)
-        return body
-
-    def encode_content_body(self, body, content_encoding):
-        if content_encoding in ('gzip', 'x-gzip'):
-            io = StringIO()
-            with gzip.GzipFile(fileobj=io, mode='wb') as f:
-                f.write(body)
-            data = io.getvalue()
-        elif content_encoding == 'deflate':
-            data = zlib.compress(body)
-        elif content_encoding == 'identity':
-            data = body
-        else:
-            raise Exception("Unknown Content-Encoding: %s" % content_encoding)
-        return data
-
-    def split_set_cookie_header(self, value):
-        re_cookies = r'([^=]+=[^,;]+(?:;\s*Expires=[^,]+,[^,;]+|;[^,;]+)*)(?:,\s*)?'
-        return re.findall(re_cookies, value, flags=re.IGNORECASE)
-
-    def request_handler(self, req, reqbody):
-        
-        pass
-
-    def response_handler(self, req, reqbody, res, resbody):
-     
-        pass
-
-    def save_handler(self, req, reqbody, res, resbody):
-     
-        pass
-
-
-# Port
-
-def test(HandlerClass=SimpleHTTPProxyHandler, ServerClass=ThreadingHTTPServer, protocol="HTTP/1.1"):
-    if sys.argv[1:]:
-        port = int(sys.argv[1])
-    else:
-        port = 80
-    server_address = ('', port)
-
-    HandlerClass.protocol_version = protocol
-    httpd = ServerClass(server_address, HandlerClass)
-
-    sa = httpd.socket.getsockname()
-    print "Serving HTTP on", sa[0], "port", sa[1], "..."
-    httpd.serve_forever()
-
-
-if __name__ == '__main__':
-    test()
-
+#!/usr/bin/env python
+
+import sys
+import httplib
+from SocketServer import ThreadingMixIn
+from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
+from threading import Lock, Timer
+from cStringIO import StringIO
+from urlparse import urlsplit
+import socket
+import select
+import gzip
+import zlib
+import re
+import traceback
+
+
+class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
+
+    address_family = socket.AF_INET
+
+    def handle_error(self, request, client_address):
+        
+        print >>sys.stderr, '-'*40
+        print >>sys.stderr, 'Exception happened during processing of request from', client_address
+        traceback.print_exc()
+        print >>sys.stderr, '-'*40
+        
+     
+class ThreadingHTTPServer6(ThreadingHTTPServer):
+
+    address_family = socket.AF_INET6
+
+
+class SimpleHTTPProxyHandler(BaseHTTPRequestHandler):
+    global_lock = Lock()
+    conn_table = {}
+    timeout = 300               
+    upstream_timeout = 300    
+    proxy_via = None          
+
+    def log_error(self, format, *args):
+        if format == "Request timed out: %r":
+            return
+        self.log_message(format, *args)
+
+    def do_CONNECT(self):
+        
+
+        req = self
+        reqbody = None
+        req.path = "https://%s/" % req.path.replace(':443', '')
+
+        replaced_reqbody = self.request_handler(req, reqbody)
+        if replaced_reqbody is True:
+            return
+
+        u = urlsplit(req.path)
+        address = (u.hostname, u.port or 443)
+        try:
+            conn = socket.create_connection(address)
+        except socket.error:
+            return
+        self.send_response(200, 'SOCKS5')
+        self.send_header('Connection', 'close')
+        self.end_headers()
+
+        conns = [self.connection, conn]
+        keep_connection = True
+        while keep_connection:
+            keep_connection = False
+            rlist, wlist, xlist = select.select(conns, [], conns, self.timeout)
+            if xlist:
+                break
+            for r in rlist:
+                other = conns[1] if r is conns[0] else conns[0]
+                data = r.recv(8192)
+                if data:
+                    other.sendall(data)
+                    keep_connection = True
+        conn.close()
+
+    def do_HEAD(self):
+        self.do_SPAM()
+
+    def do_GET(self):
+        self.do_SPAM()
+
+    def do_POST(self):
+        self.do_SPAM()
+
+    def do_SPAM(self):
+        req = self
+        content_length = int(req.headers.get('Content-Length', 0))
+        if content_length > 0:
+            reqbody = self.rfile.read(content_length)
+        else:
+            reqbody = None
+
+        replaced_reqbody = self.request_handler(req, reqbody)
+        if replaced_reqbody is True:
+            return
+        elif replaced_reqbody is not None:
+            reqbody = replaced_reqbody
+            if 'Content-Length' in req.headers:
+                req.headers['Content-Length'] = str(len(reqbody))
+
+        
+        self.remove_hop_by_hop_headers(req.headers)
+        if self.upstream_timeout:
+            req.headers['Connection'] = 'Keep-Alive'
+        else:
+            req.headers['Connection'] = 'close'
+        if self.proxy_via:
+            self.modify_via_header(req.headers)
+
+        try:
+            res, resdata = self.request_to_upstream_server(req, reqbody)
+        except socket.error:
+            return
+
+        content_encoding = res.headers.get('Content-Encoding', 'identity')
+        resbody = self.decode_content_body(resdata, content_encoding)
+
+        replaced_resbody = self.response_handler(req, reqbody, res, resbody)
+        if replaced_resbody is True:
+            return
+        elif replaced_resbody is not None:
+            resdata = self.encode_content_body(replaced_resbody, content_encoding)
+            if 'Content-Length' in res.headers:
+                res.headers['Content-Length'] = str(len(resdata))
+            resbody = replaced_resbody
+
+        self.remove_hop_by_hop_headers(res.headers)
+        if self.timeout:
+            res.headers['Connection'] = 'Keep-Alive'
+        else:
+            res.headers['Connection'] = 'close'
+        if self.proxy_via:
+            self.modify_via_header(res.headers)
+
+        self.send_response(res.status, res.reason)
+        for k, v in res.headers.items():
+            if k == 'set-cookie':
+                
+                for value in self.split_set_cookie_header(v):
+                    self.send_header(k, value)
+            else:
+                self.send_header(k, v)
+        self.end_headers()
+
+        if self.command != 'HEAD':
+            self.wfile.write(resdata)
+            with self.global_lock:
+                self.save_handler(req, reqbody, res, resbody)
+
+    def request_to_upstream_server(self, req, reqbody):
+        u = urlsplit(req.path)
+        origin = (u.scheme, u.netloc)
+
+        
+        req.headers['Host'] = u.netloc
+        selector = "%s?%s" % (u.path, u.query) if u.query else u.path
+
+        while True:
+            with self.lock_origin(origin):
+                conn = self.open_origin(origin)
+                try:
+                    conn.request(req.command, selector, reqbody, headers=dict(req.headers))
+                except socket.error:
+                    
+                    self.close_origin(origin)
+                    raise
+                try:
+                    res = conn.getresponse(buffering=True)
+                except httplib.BadStatusLine as e:
+                    if e.line == "''":
+                        
+                        self.close_origin(origin)
+                        continue
+                    else:
+                        raise
+                resdata = res.read()
+                res.headers = res.msg    
+                if not self.upstream_timeout or 'close' in res.headers.get('Connection', ''):
+                    self.close_origin(origin)
+                else:
+                    self.reset_timer(origin)
+            return res, resdata
+
+    def lock_origin(self, origin):
+        d = self.conn_table.setdefault(origin, {})
+        if not 'lock' in d:
+            d['lock'] = Lock()
+        return d['lock']
+
+    def open_origin(self, origin):
+        conn = self.conn_table[origin].get('connection')
+        if not conn:
+            scheme, netloc = origin
+            if scheme == 'https':
+                conn = httplib.HTTPSConnection(netloc)
+            else:
+                conn = httplib.HTTPConnection(netloc)
+            self.reset_timer(origin)
+            self.conn_table[origin]['connection'] = conn
+        return conn
+
+    def reset_timer(self, origin):
+        timer = self.conn_table[origin].get('timer')
+        if timer:
+            timer.cancel()
+        if self.upstream_timeout:
+            timer = Timer(self.upstream_timeout, self.close_origin, args=[origin])
+            timer.daemon = True
+            timer.start()
+        else:
+            timer = None
+        self.conn_table[origin]['timer'] = timer
+
+    def close_origin(self, origin):
+        timer = self.conn_table[origin]['timer']
+        if timer:
+            timer.cancel()
+        conn = self.conn_table[origin]['connection']
+        conn.close()
+        del self.conn_table[origin]['connection']
+
+    def remove_hop_by_hop_headers(self, headers):
+        hop_by_hop_headers = ['Connection', 'Keep-Alive', 'Proxy-Authenticate', 'Proxy-Authorization', 'TE', 'Trailers', 'Trailer', 'Transfer-Encoding', 'Upgrade']
+        connection = headers.get('Connection')
+        if connection:
+            keys = re.split(r',\s*', connection)
+            hop_by_hop_headers.extend(keys)
+
+        for k in hop_by_hop_headers:
+            if k in headers:
+                del headers[k]
+
+    def modify_via_header(self, headers):
+        via_string = "%s %s" % (self.protocol_version, self.proxy_via)
+        via_string = re.sub(r'^HTTP/', '', via_string)
+
+        original = headers.get('Via')
+        if original:
+            headers['Via'] = original + ', ' + via_string
+        else:
+            headers['Via'] = via_string
+
+    def decode_content_body(self, data, content_encoding):
+        if content_encoding in ('gzip', 'x-gzip'):
+            io = StringIO(data)
+            with gzip.GzipFile(fileobj=io) as f:
+                body = f.read()
+        elif content_encoding == 'deflate':
+            body = zlib.decompress(data)
+        elif content_encoding == 'identity':
+            body = data
+        else:
+            raise Exception("Unknown Content-Encoding: %s" % content_encoding)
+        return body
+
+    def encode_content_body(self, body, content_encoding):
+        if content_encoding in ('gzip', 'x-gzip'):
+            io = StringIO()
+            with gzip.GzipFile(fileobj=io, mode='wb') as f:
+                f.write(body)
+            data = io.getvalue()
+        elif content_encoding == 'deflate':
+            data = zlib.compress(body)
+        elif content_encoding == 'identity':
+            data = body
+        else:
+            raise Exception("Unknown Content-Encoding: %s" % content_encoding)
+        return data
+
+    def split_set_cookie_header(self, value):
+        re_cookies = r'([^=]+=[^,;]+(?:;\s*Expires=[^,]+,[^,;]+|;[^,;]+)*)(?:,\s*)?'
+        return re.findall(re_cookies, value, flags=re.IGNORECASE)
+
+    def request_handler(self, req, reqbody):
+        
+        pass
+
+    def response_handler(self, req, reqbody, res, resbody):
+     
+        pass
+
+    def save_handler(self, req, reqbody, res, resbody):
+     
+        pass
+
+
+# Port
+
+def test(HandlerClass=SimpleHTTPProxyHandler, ServerClass=ThreadingHTTPServer, protocol="HTTP/1.1"):
+    if sys.argv[1:]:
+        port = int(sys.argv[1])
+    else:
+        port = 80
+    server_address = ('', port)
+
+    HandlerClass.protocol_version = protocol
+    httpd = ServerClass(server_address, HandlerClass)
+
+    sa = httpd.socket.getsockname()
+    print "Serving HTTP on", sa[0], "port", sa[1], "..."
+    httpd.serve_forever()
+
+
+if __name__ == '__main__':
+    test()
+

+ 2 - 2
VPS-MX-8.5-Final Oficial/VPS-MX/protocolos/budp.sh

@@ -1,5 +1,5 @@
 #!/bin/bash
-#25/01/2021
+#17/02/2026
 clear
 clear
 declare -A cor=( [0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m" )
@@ -14,7 +14,7 @@ msg -tit
     msg -ama "            ACTIVADOR DE BADVPN (UDP 7300)"
     msg -bar 
     if [[ ! -e /bin/badvpn-udpgw ]]; then
-    wget -O /bin/badvpn-udpgw https://raw.githubusercontent.com/NetVPS/VPS-MX_Oficial/master/LINKS-LIBRERIAS/badvpn-udpgw &>/dev/null
+    wget -O /bin/badvpn-udpgw https://repo.yosoyhendrix.com/yosoyhendrix/Multi_Script/raw/main/Otros/badvpn-udpgw &>/dev/null
     chmod 777 /bin/badvpn-udpgw
     fi
     screen -dmS badvpn2 /bin/badvpn-udpgw --listen-addr 127.0.0.1:7300 --max-clients 1000 --max-connections-for-client 10 

+ 116 - 113
VPS-MX-8.5-Final Oficial/VPS-MX/protocolos/psiphon.sh

@@ -1,113 +1,116 @@
-
-declare -A cor=( [0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m" )
-SCPdir="/etc/VPS-MX" && [[ ! -d ${SCPdir} ]] && exit 1
-SCPusr="${SCPdir}/controlador" && [[ ! -d ${SCPusr} ]] && mkdir ${SCPusr}
-SCPfrm="${SCPdir}/herramientas" && [[ ! -d ${SCPfrm} ]] && mkdir ${SCPfrm}
-SCPinst="${SCPdir}/protocolos" && [[ ! -d ${SCPfrm} ]] && mkdir ${SCPfrm}
-    if ps aux | grep 'psiphond' | grep -v grep >/dev/null; then
-      echo "El proceso psiphond ya está activo."
-      exit 1
-    fi
-
-    msg -bar
-    msg -tit
-    msg -bar
-    msg -ama "\033[1;32m            INSTALADOR DE SERVR-PSIPHONE"
-    msg -bar
-    echo -e "\033[1;33m Ingrese los puertos segun su necesidad\033[1;97m\n"
-    #echo -e "\033[1;97mDigite los puertos a activar \033[1;97m | \033[1;93mPuerto recomendados \033[1;32m 5300\n"
-    #echo -ne "\033[1;97mDigite los Puertos:\033[1;32m " && read -p " " -e -i "22" portasx
-    #echo "$portasx" >/etc/SCRIPT-LATAM/PortM/UDP-server.log
-
-    #tput cuu1 && tput dl1
-
-    rm -rf /root/psi
-    kill $(ps aux | grep 'psiphond' | awk '{print $2}') 1>/dev/null 2>/dev/null
-    killall psiphond 1>/dev/null 2>/dev/null
-    mkdir -p /root/psi
-    cd /root/psi
-    ship=$(wget -qO- ipinfo.io/ip || wget -qO- ifconfig.me)
-    wget -O /root/psi/psiphond https://repo.yosoyhendrix.com/yosoyhendrix/Multi_Script/raw/main/VPS-MX-8.5-Final%20Oficial/Otros/psiphond &>/dev/null
-    chmod +rwx /root/psi/psiphond
-    echo -ne "\033[1;97m Escribe el puerto para Psiphon SSH:\033[32m " && read -p " " -e -i "3001" sh
-    echo -ne "\033[1;97m Escribe el puerto para Psiphon OSSH:\033[32m " && read -p " " -e -i "3002" osh
-    echo -ne "\033[1;97m Escribe el puerto para Psiphon FRONTED-MEEK:\033[32m " && read -p " " -e -i "443" fm
-    echo -ne "\033[1;97m Escribe el puerto para Psiphon WEB:\033[32m " && read -p " " -e -i "3000" wb
-    #echo -ne "\033[1;97m Escribe el puerto para Psiphon UNFRONTED-MEEK:\033[32m " && read umo
-    #./psiphond --ipaddress $ship --protocol SSH:$sh --protocol OSSH:$osh --protocol FRONTED-MEEK-OSSH:$fm --protocol UNFRONTED-MEEK-OSSH:$umo generate
-    ./psiphond --ipaddress $ship --web $wb --protocol SSH:$sh --protocol OSSH:$osh --protocol FRONTED-MEEK-OSSH:$fm generate
-    
-    chmod 666 psiphond.config
-    chmod 666 psiphond-traffic-rules.config
-    chmod 666 psiphond-osl.config
-    chmod 666 psiphond-tactics.config
-    chmod 666 server-entry.dat
-    cat server-entry.dat >/root/psi.txt
-    screen -dmS psiserver ./psiphond run
-    cd /root
-    psi=$(cat /root/psi.txt)
-    echo -e "\033[1;33m LA CONFIGURACION DE TU SERVIDOR ES:\033[0m"
-    msg -bar
-    echo -e "\033[1;32m $psi \033[0m"
-    msg -bar
-    echo -e "\033[1;33m PROTOCOLOS HABILITADOS:\033[0m"
-    echo -e "\033[1;33m → SSH:\033[1;32m $sh \033[0m"
-    echo -e "\033[1;33m → OSSH:\033[1;32m $osh \033[0m"
-    echo -e "\033[1;33m → FRONTED-MEEK-OSSH:\033[1;32m $fm \033[0m"
-    #echo -e "\033[1;33m → UNFRONTED-MEEK-OSSH:\033[1;32m $umo \033[0m"
-    echo -e "\033[1;33m → WEB:\033[1;32m $wb \033[0m"
-    msg -bar
-    echo -e "\033[1;33m DIRECTORIO DE ARCHIVOS:\033[1;32m /root/psi \033[0m"
-    msg -bar
-    [[ "$(ps x | grep psiserver | grep -v grep | awk '{print $1}')" ]] && msg -verd "    >> SERVIDOR-PSIPHONE INSTALADO CON EXITO <<" || msg -ama "                  ERROR VERIFIQUE"
-    msg -bar
-    read -t 120 -n 1 -rsp $'\033[1;39m       << Presiona enter para Continuar >>\n'
-    menu_inst
-  }
-  desactivar_psiphone() {
-    
-    msg -bar
-    echo -e "\033[1;31m            DESISNTALANDO PUERTOS UDP-SERVER "
-    msg -bar
-    rm -rf /root/psi
-    kill $(ps aux | grep 'psiphond' | awk '{print $2}') 1>/dev/null 2>/dev/null
-    killall psiphond 1>/dev/null 2>/dev/null
-    [[ "$(ps x | grep psiserver | grep -v grep | awk '{print $1}')" ]] && echo -e "\033[1;32m        >> UDP-SERVER DESINSTALADO CON EXICO << "
-    read -t 60 -n 1 -rsp $'\033[1;39m       << Presiona enter para Continuar >>\n'
-    menu_inst
-  }
- 
-  msg -bar
-  msg -tit
-  msg -bar
-  msg -ama "            INSTALADOR DE PSIPHONE-SERVER"
-  msg -bar
-  if [[ ! -e /bin/psiphond ]]; then
-    curl -o /bin/psiphond https://repo.yosoyhendrix.com/yosoyhendrix/Multi_Script/raw/main/VPS-MX-8.5-Final%20Oficial/Otros/psiphond &>/dev/null
-    chmod 777 /bin/psiphond
-  fi
-  echo -ne " \e[1;93m [\e[1;32m1\e[1;93m]\033[1;31m > \e[1;97m INSTALAR SERVER-PSIPHONE  \e[97m \n"
-  echo -ne " \e[1;93m [\e[1;32m2\e[1;93m]\033[1;31m > \033[1;97m DETENER SERVER-PSIPHONE \e[97m \n"
-  msg -bar
-  echo -ne " \e[1;93m [\e[1;32m0\e[1;93m]\033[1;31m > \033[1;97m" && msg -bra "  \e[97m\033[1;41m VOLVER \033[1;37m"
-  msg -bar
-  echo -ne "\033[1;97mDigite solo el numero segun su respuesta:\e[32m "
-  read opcao
-  case $opcao in
-  1)
-    msg -bar
-    install_psiphone
-    ;;
-  2)
-    msg -bar
-    desactivar_psiphone
-    ;;
-  0)
-    menu
-    ;;
-  *)
-    echo -e "$ Porfavor use numeros del [0-2]"
-    msg -bar
-    menu
-    ;;
-  esac
+clear
+clear
+PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
+export PATH
+declare -A cor=( [0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m" )
+SCPdir="/etc/VPS-MX" && [[ ! -d ${SCPdir} ]] && exit 1
+SCPusr="${SCPdir}/controlador" && [[ ! -d ${SCPusr} ]] && mkdir ${SCPusr}
+SCPfrm="${SCPdir}/herramientas" && [[ ! -d ${SCPfrm} ]] && mkdir ${SCPfrm}
+SCPinst="${SCPdir}/protocolos" && [[ ! -d ${SCPfrm} ]] && mkdir ${SCPfrm}
+    if ps aux | grep 'psiphond' | grep -v grep >/dev/null; then
+      echo "El proceso psiphond ya está activo."
+      exit 1
+    fi
+
+    msg -bar
+    msg -tit
+    msg -bar
+    msg -ama "\033[1;32m            INSTALADOR DE SERVR-PSIPHONE"
+    msg -bar
+    echo -e "\033[1;33m Ingrese los puertos segun su necesidad\033[1;97m\n"
+    #echo -e "\033[1;97mDigite los puertos a activar \033[1;97m | \033[1;93mPuerto recomendados \033[1;32m 5300\n"
+    #echo -ne "\033[1;97mDigite los Puertos:\033[1;32m " && read -p " " -e -i "22" portasx
+    #echo "$portasx" >/etc/SCRIPT-LATAM/PortM/UDP-server.log
+
+    #tput cuu1 && tput dl1
+
+    rm -rf /root/psi
+    kill $(ps aux | grep 'psiphond' | awk '{print $2}') 1>/dev/null 2>/dev/null
+    killall psiphond 1>/dev/null 2>/dev/null
+    mkdir -p /root/psi
+    cd /root/psi
+    ship=$(wget -qO- ipinfo.io/ip || wget -qO- ifconfig.me)
+    wget -O /root/psi/psiphond https://repo.yosoyhendrix.com/yosoyhendrix/Multi_Script/raw/main/VPS-MX-8.5-Final%20Oficial/Otros/psiphond &>/dev/null
+    chmod +rwx /root/psi/psiphond
+    echo -ne "\033[1;97m Escribe el puerto para Psiphon SSH:\033[32m " && read -p " " -e -i "3001" sh
+    echo -ne "\033[1;97m Escribe el puerto para Psiphon OSSH:\033[32m " && read -p " " -e -i "3002" osh
+    echo -ne "\033[1;97m Escribe el puerto para Psiphon FRONTED-MEEK:\033[32m " && read -p " " -e -i "443" fm
+    echo -ne "\033[1;97m Escribe el puerto para Psiphon WEB:\033[32m " && read -p " " -e -i "3000" wb
+    #echo -ne "\033[1;97m Escribe el puerto para Psiphon UNFRONTED-MEEK:\033[32m " && read umo
+    #./psiphond --ipaddress $ship --protocol SSH:$sh --protocol OSSH:$osh --protocol FRONTED-MEEK-OSSH:$fm --protocol UNFRONTED-MEEK-OSSH:$umo generate
+    ./psiphond --ipaddress $ship --web $wb --protocol SSH:$sh --protocol OSSH:$osh --protocol FRONTED-MEEK-OSSH:$fm generate
+    
+    chmod 666 psiphond.config
+    chmod 666 psiphond-traffic-rules.config
+    chmod 666 psiphond-osl.config
+    chmod 666 psiphond-tactics.config
+    chmod 666 server-entry.dat
+    cat server-entry.dat >/root/psi.txt
+    screen -dmS psiserver ./psiphond run
+    cd /root
+    psi=$(cat /root/psi.txt)
+    echo -e "\033[1;33m LA CONFIGURACION DE TU SERVIDOR ES:\033[0m"
+    msg -bar
+    echo -e "\033[1;32m $psi \033[0m"
+    msg -bar
+    echo -e "\033[1;33m PROTOCOLOS HABILITADOS:\033[0m"
+    echo -e "\033[1;33m → SSH:\033[1;32m $sh \033[0m"
+    echo -e "\033[1;33m → OSSH:\033[1;32m $osh \033[0m"
+    echo -e "\033[1;33m → FRONTED-MEEK-OSSH:\033[1;32m $fm \033[0m"
+    #echo -e "\033[1;33m → UNFRONTED-MEEK-OSSH:\033[1;32m $umo \033[0m"
+    echo -e "\033[1;33m → WEB:\033[1;32m $wb \033[0m"
+    msg -bar
+    echo -e "\033[1;33m DIRECTORIO DE ARCHIVOS:\033[1;32m /root/psi \033[0m"
+    msg -bar
+    [[ "$(ps x | grep psiserver | grep -v grep | awk '{print $1}')" ]] && msg -verd "    >> SERVIDOR-PSIPHONE INSTALADO CON EXITO <<" || msg -ama "                  ERROR VERIFIQUE"
+    msg -bar
+    read -t 120 -n 1 -rsp $'\033[1;39m       << Presiona enter para Continuar >>\n'
+    menu_inst
+  }
+  desactivar_psiphone() {
+    clear && clear
+    msg -bar
+    echo -e "\033[1;31m            DESISNTALANDO PUERTOS UDP-SERVER "
+    msg -bar
+    rm -rf /root/psi
+    kill $(ps aux | grep 'psiphond' | awk '{print $2}') 1>/dev/null 2>/dev/null
+    killall psiphond 1>/dev/null 2>/dev/null
+    [[ "$(ps x | grep psiserver | grep -v grep | awk '{print $1}')" ]] && echo -e "\033[1;32m        >> UDP-SERVER DESINSTALADO CON EXICO << "
+    read -t 60 -n 1 -rsp $'\033[1;39m       << Presiona enter para Continuar >>\n'
+    menu_inst
+  }
+  clear && clear
+  msg -bar
+  msg -tit
+  msg -bar
+  msg -ama "            INSTALADOR DE PSIPHONE-SERVER"
+  msg -bar
+  if [[ ! -e /bin/psiphond ]]; then
+    curl -o /bin/psiphond https://repo.yosoyhendrix.com/yosoyhendrix/Multi_Script/raw/main/VPS-MX-8.5-Final%20Oficial/Otros/psiphond &>/dev/null
+    chmod 777 /bin/psiphond
+  fi
+  echo -ne " \e[1;93m [\e[1;32m1\e[1;93m]\033[1;31m > \e[1;97m INSTALAR SERVER-PSIPHONE  \e[97m \n"
+  echo -ne " \e[1;93m [\e[1;32m2\e[1;93m]\033[1;31m > \033[1;97m DETENER SERVER-PSIPHONE \e[97m \n"
+  msg -bar
+  echo -ne " \e[1;93m [\e[1;32m0\e[1;93m]\033[1;31m > \033[1;97m" && msg -bra "  \e[97m\033[1;41m VOLVER \033[1;37m"
+  msg -bar
+  echo -ne "\033[1;97mDigite solo el numero segun su respuesta:\e[32m "
+  read opcao
+  case $opcao in
+  1)
+    msg -bar
+    install_psiphone
+    ;;
+  2)
+    msg -bar
+    desactivar_psiphone
+    ;;
+  0)
+    menu
+    ;;
+  *)
+    echo -e "$ Porfavor use numeros del [0-2]"
+    msg -bar
+    menu
+    ;;
+  esac

+ 312 - 213
VPS-MX-8.5-Final Oficial/VPS-MX/protocolos/python.py

@@ -1,309 +1,408 @@
-#!/usr/bin/env python2.7
 # -*- coding: utf-8 -*-
-import socket, threading, thread, select, signal, sys, time, getopt
 
 # ==============================================================================
-# SCRIPT DE PROXY MULTIFILAMENTADO CON SOPORTE PARA IPV4 E IPV6
-# - Solucionado el error "Address already in use" con la opción IPV6_V6ONLY.
-# - Modificado por Gemini.
+# SCRIPT DE PROXY MULTIFILAMENTADO CON LÍMITE DE CONEXIONES Y RATE-LIMITING
+#
+# - Este script añade un límite al número máximo de conexiones activas que
+#   el servidor puede manejar en un momento dado.
+# - Es la solución más efectiva para prevenir la saturación de la CPU en
+#   entornos donde la arquitectura asíncrona no es viable.
+# - La limitación de velocidad se mantiene para proteger contra ataques de
+#   denegación de servicio.
+#
+# Creado por Gemini
 # ==============================================================================
 
-# Listen
-# Se usan direcciones específicas para evitar errores de getaddrinfo.
+import socket
+import threading
+import select
+import sys
+import time
+import os
+import logging
+import logging.handlers
+
+# ==============================================================================
+# CONFIGURACIÓN GLOBAL Y SETUP DE LOGGING
+# ==============================================================================
+# Direcciones de escucha para ambos protocolos.
 IPV4_ADDR = '0.0.0.0'
 IPV6_ADDR = '::'
 
+# Puerto de escucha. Se puede pasar como argumento.
 if sys.argv[1:]:
-  LISTENING_PORT = sys.argv[1]
+    LISTENING_PORT = int(sys.argv[1])
 else:
-  LISTENING_PORT = 80
-#Pass
+    LISTENING_PORT = 80
+
+# Contraseña opcional para el proxy.
 PASS = ''
 
-# CONST
+# Controla la prioridad de conexión
+PRIORITIZE_IPV4 = True
+
+# 💡 CONFIGURACIÓN DE SEGURIDAD
+# Tiempo mínimo de espera (en segundos) entre dos conexiones de la misma IP.
+CONNECTION_COOLDOWN_TIME = 100
+
+# 💡 NUEVA CONFIGURACIÓN: Límite de conexiones activas
+MAX_CONNECTIONS = 200  # Máximo de conexiones simultáneas
+
+# Constantes
 BUFLEN = 4096 * 4
 TIMEOUT = 60
 DEFAULT_HOST = '127.0.0.1:22'
-RESPONSE = 'HTTP/1.1 101 Switching Protocols <strong>By: VPS-MX</strong>\r\n\r\n'
+RESPONSE = b'HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nUpgrade: websocket\r\n\r\n'
+
+# Configuración del log
+LOG_FILE = '/root/proxy.log'
+MAX_LOG_SIZE = 5 * 1024 * 1024  # 5 MB
+BACKUP_COUNT = 5 # Cantidad de archivos de log a rotar
+
+def setup_logging():
+    """Configura el logger profesional con rotación de archivos."""
+    log_format = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
+    
+    file_handler = logging.handlers.RotatingFileHandler(
+        LOG_FILE,
+        maxBytes=MAX_LOG_SIZE,
+        backupCount=BACKUP_COUNT
+    )
+    file_handler.setFormatter(log_format)
+    
+    console_handler = logging.StreamHandler()
+    console_handler.setFormatter(log_format)
+    
+    logger = logging.getLogger()
+    logger.setLevel(logging.INFO)
+    logger.addHandler(file_handler)
+    logger.addHandler(console_handler)
+    
+    return logger
+
+# Inicializar el logger
+logger = setup_logging()
+
+# 💡 Variables compartidas para la limitación de velocidad y el semáforo
+last_connection_times = {}
+last_connection_lock = threading.Lock()
+connection_limit_semaphore = threading.Semaphore(MAX_CONNECTIONS)
 
+# ==============================================================================
+# CLASE DEL SERVIDOR
+# Gestiona la creación de sockets y la aceptación de conexiones
+# ==============================================================================
 class Server(threading.Thread):
-    def __init__(self, host, port):
-        threading.Thread.__init__(self)
+    def __init__(self, port):
+        super().__init__()
         self.running = False
-        self.host = host
         self.port = port
         self.threads = []
-        self.threadsLock = threading.Lock()
-        self.logLock = threading.Lock()
-        self.soc = None
-        self.soc_v6 = None
-        
+        self.threads_lock = threading.Lock()
+        self.ipv4_socket = None
+        self.ipv6_socket = None
+
     def run(self):
-        self.printLog("\n:-------PythonProxy-------:\n")
-        self.printLog("Listening addr: " + IPV4_ADDR + " and " + IPV6_ADDR)
-        self.printLog("Listening port: " + str(self.port) + "\n")
-        self.printLog(":-------------------------:\n")
+        logger.info("\n:-------PythonProxy-------:\n")
+        logger.info(f"Listening addr: {IPV4_ADDR} and {IPV6_ADDR}")
+        logger.info(f"Listening port: {self.port}\n")
+        logger.info(f"Límite de conexiones: {MAX_CONNECTIONS}\n")
+        logger.info(":-------------------------:\n")
 
         # Intentar enlazar a IPv4
         try:
-            self.soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-            self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-            self.soc.settimeout(2)
-            self.soc.bind((IPV4_ADDR, int(self.port)))
-            self.soc.listen(0)
-            self.printLog("Esperando conexiones IPv4 en %s:%s" % (IPV4_ADDR, self.port))
+            self.ipv4_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            self.ipv4_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+            self.ipv4_socket.bind((IPV4_ADDR, self.port))
+            self.ipv4_socket.listen(0)
+            logger.info(f"Esperando conexiones IPv4 en {IPV4_ADDR}:{self.port}")
         except socket.error as e:
-            self.printLog("No se pudo enlazar a IPv4 (%s)" % e)
-            if self.soc:
-                self.soc.close()
-            self.soc = None
+            logger.error(f"No se pudo enlazar a IPv4 ({e})")
+            if self.ipv4_socket:
+                self.ipv4_socket.close()
+            self.ipv4_socket = None
 
         # Intentar enlazar a IPv6
         try:
-            self.soc_v6 = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
-            self.soc_v6.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-            # 💡 SOLUCIÓN: Establecer la opción IPV6_V6ONLY para evitar conflictos con IPv4.
-            # Esto fuerza al socket IPv6 a solo aceptar conexiones IPv6.
-            self.soc_v6.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
-            self.soc_v6.settimeout(2)
-            self.soc_v6.bind((IPV6_ADDR, int(self.port), 0, 0))
-            self.soc_v6.listen(0)
-            self.printLog("Esperando conexiones IPv6 en %s:%s" % (IPV6_ADDR, self.port))
+            self.ipv6_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+            self.ipv6_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+            self.ipv6_socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
+            self.ipv6_socket.bind((IPV6_ADDR, self.port, 0, 0))
+            self.ipv6_socket.listen(0)
+            logger.info(f"Esperando conexiones IPv6 en {IPV6_ADDR}:{self.port}")
         except socket.error as e:
-            self.printLog("No se pudo enlazar a IPv6 (%s)" % e)
-            if self.soc_v6:
-                self.soc_v6.close()
-            self.soc_v6 = None
+            logger.error(f"No se pudo enlazar a IPv6 ({e})")
+            if self.ipv6_socket:
+                self.ipv6_socket.close()
+            self.ipv6_socket = None
 
-        if not self.soc and not self.soc_v6:
-            self.printLog("No se pudo iniciar el servidor. Saliendo.")
+        if not self.ipv4_socket and not self.ipv6_socket:
+            logger.critical("No se pudo iniciar el servidor. Saliendo.")
             return
 
         self.running = True
-        
         active_sockets = []
-        if self.soc:
-            active_sockets.append(self.soc)
-        if self.soc_v6:
-            active_sockets.append(self.soc_v6)
+        if self.ipv4_socket:
+            active_sockets.append(self.ipv4_socket)
+        if self.ipv6_socket:
+            active_sockets.append(self.ipv6_socket)
 
         try:
             while self.running:
-                try:
-                    readable, _, _ = select.select(active_sockets, [], [], 2)
-                    for sock in readable:
-                        c, addr = sock.accept()
-                        c.setblocking(1)
-                        conn = ConnectionHandler(c, self, addr)
-                        conn.start()
-                        self.addConn(conn)
-                except socket.timeout:
-                    continue
-                except socket.error as e:
-                    if self.running:
-                        self.printLog("Error al aceptar conexión: %s" % e)
-                    continue
-
+                readable, _, _ = select.select(active_sockets, [], [], 2)
+                for sock in readable:
+                    c, addr = sock.accept()
+                    client_ip = addr[0]
+                    current_time = time.time()
+
+                    # 💡 Lógica del cooldown (rate-limiting)
+                    with last_connection_lock:
+                        last_time = last_connection_times.get(client_ip, 0)
+                        if current_time - last_time < CONNECTION_COOLDOWN_TIME:
+                            logger.warning(f"[{client_ip}] Conexión rechazada por rate-limiting.")
+                            c.close()
+                            continue
+                        last_connection_times[client_ip] = current_time
+
+                    # 💡 Intenta adquirir un "slot" del semáforo
+                    if not connection_limit_semaphore.acquire(timeout=0):
+                        logger.warning(f"[{client_ip}] Conexión rechazada. Límite de conexiones alcanzado.")
+                        c.close()
+                        continue
+
+                    c.setblocking(1)
+                    conn = ConnectionHandler(c, self, addr)
+                    conn.start()
+                    self.add_conn(conn)
+        except Exception as e:
+            logger.error(f"Error en el bucle principal del servidor: {e}")
         finally:
             self.running = False
-            if self.soc:
-                self.soc.close()
-            if self.soc_v6:
-                self.soc_v6.close()
-
-    def printLog(self, log):
-        self.logLock.acquire()
-        print log
-        self.logLock.release()
-
-    def addConn(self, conn):
-        try:
-            self.threadsLock.acquire()
+            if self.ipv4_socket:
+                self.ipv4_socket.close()
+            if self.ipv6_socket:
+                self.ipv6_socket.close()
+
+    def add_conn(self, conn):
+        """Añade un hilo de conexión a la lista de hilos activos de forma segura."""
+        with self.threads_lock:
             if self.running:
                 self.threads.append(conn)
-        finally:
-            self.threadsLock.release()
 
-    def removeConn(self, conn):
-        try:
-            self.threadsLock.acquire()
-            self.threads.remove(conn)
-        finally:
-            self.threadsLock.release()
+    def remove_conn(self, conn):
+        """Remueve un hilo de conexión de la lista de hilos activos de forma segura."""
+        with self.threads_lock:
+            if conn in self.threads:
+                self.threads.remove(conn)
 
     def close(self):
-        try:
-            self.running = False
-            self.threadsLock.acquire()
+        """Cierra el servidor y todos los hilos de conexión."""
+        self.running = False
+        with self.threads_lock:
             threads = list(self.threads)
             for c in threads:
                 c.close()
-        finally:
-            self.threadsLock.release()
 
+# ==============================================================================
+# CLASE MANEJADORA DE CONEXIONES
+# Gestiona la lógica de cada conexión de cliente en un hilo separado
+# ==============================================================================
 class ConnectionHandler(threading.Thread):
-    def __init__(self, socClient, server, addr):
-        threading.Thread.__init__(self)
-        self.clientClosed = False
-        self.targetClosed = True
-        self.client = socClient
-        self.client_buffer = ''
+    def __init__(self, client_socket, server, addr):
+        super().__init__()
+        self.client_closed = False
+        self.target_closed = True
+        self.client = client_socket
+        self.client_buffer = b''
         self.server = server
-        self.log = 'Connection: ' + str(addr)
+        self.addr = addr
+        self.log_prefix = f"{addr[0]}:{addr[1]}"
+        logger.info(f"Nueva conexión de {self.log_prefix}")
+        self.target = None
 
     def close(self):
+        """Cierra los sockets del cliente y el destino."""
+        logger.info(f"Cerrando conexión {self.log_prefix}")
+        
         try:
-            if not self.clientClosed:
+            if not self.client_closed:
                 self.client.shutdown(socket.SHUT_RDWR)
                 self.client.close()
-        except:
+        except Exception:
             pass
         finally:
-            self.clientClosed = True
+            self.client_closed = True
 
         try:
-            if not self.targetClosed:
+            if not self.target_closed:
                 self.target.shutdown(socket.SHUT_RDWR)
                 self.target.close()
-        except:
+        except Exception:
             pass
         finally:
-            self.targetClosed = True
+            self.target_closed = True
+        
+        # 💡 Libera el semáforo al cerrar la conexión
+        connection_limit_semaphore.release()
 
     def run(self):
         try:
             self.client_buffer = self.client.recv(BUFLEN)
-            hostPort = self.findHeader(self.client_buffer, 'X-Real-Host')
-            if hostPort == '':
-                hostPort = DEFAULT_HOST
+            if not self.client_buffer:
+                return
+
+            headers = self.client_buffer.decode('latin-1')
+            logger.debug(f"Headers received from {self.log_prefix}:\n{headers.strip()}")
 
-            split = self.findHeader(self.client_buffer, 'X-Split')
-            if split != '':
+            host_port = self.find_header(headers, 'X-Real-Host')
+            if not host_port:
+                host_port = DEFAULT_HOST
+
+            if self.find_header(headers, 'X-Split'):
                 self.client.recv(BUFLEN)
 
-            if hostPort != '':
-                passwd = self.findHeader(self.client_buffer, 'X-Pass')
-                if len(PASS) != 0 and passwd == PASS:
-                    self.method_CONNECT(hostPort)
-                elif len(PASS) != 0 and passwd != PASS:
-                    self.client.send('HTTP/1.1 400 WrongPass!\r\n\r\n')
-                elif hostPort.startswith('127.0.0.1') or hostPort.startswith('localhost'):
-                    self.method_CONNECT(hostPort)
+            if host_port:
+                passwd = self.find_header(headers, 'X-Pass')
+                if PASS and passwd == PASS:
+                    logger.info(f"Autenticación exitosa para {self.log_prefix} -> {host_port}")
+                    self.method_connect(host_port)
+                elif PASS and passwd != PASS:
+                    logger.warning(f"Fallo de autenticación para {self.log_prefix} -> {host_port}")
+                    self.client.send(b'HTTP/1.1 400 WrongPass!\r\n\r\n')
+                elif host_port.startswith('127.0.0.1') or host_port.startswith('localhost'):
+                    logger.info(f"Conexión local permitida para {self.log_prefix} -> {host_port}")
+                    self.method_connect(host_port)
                 else:
-                    self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
+                    logger.warning(f"Acceso denegado (sin contraseña) para {self.log_prefix} -> {host_port}")
+                    self.client.send(b'HTTP/1.1 403 Forbidden!\r\n\r\n')
             else:
-                self.server.printLog('- No X-Real-Host!')
-                self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
+                logger.error(f"Encabezado 'X-Real-Host' no encontrado en la conexión de {self.log_prefix}")
+                self.client.send(b'HTTP/1.1 400 NoXRealHost!\r\n\r\n')
 
         except Exception as e:
-            self.log += ' - error: ' + str(e)
-            self.server.printLog(self.log)
-            pass
+            logger.error(f"Error inesperado en el hilo de conexión {self.log_prefix}: {e}")
         finally:
             self.close()
-            self.server.removeConn(self)
+            self.server.remove_conn(self)
 
-    def findHeader(self, head, header):
-        aux = head.find(header + ': ')
-        if aux == -1:
+    def find_header(self, head, header):
+        """Busca un encabezado en la solicitud HTTP."""
+        try:
+            aux = head.find(header + ': ')
+            if aux == -1: return ''
+            head = head[aux + len(header) + 2:]
+            aux = head.find('\r\n')
+            if aux == -1: return ''
+            return head[:aux]
+        except Exception as e:
+            logger.error(f"Error al analizar el encabezado '{header}': {e}")
             return ''
 
-        aux = head.find(':', aux)
-        head = head[aux+2:]
-        aux = head.find('\r\n')
+    def connect_target(self, host_port):
+        """Intenta conectarse al host de destino con una lógica de reconexión."""
+        i = host_port.find(':')
+        if i != -1:
+            try:
+                port = int(host_port[i+1:])
+                host = host_port[:i]
+            except ValueError:
+                raise RuntimeError(f"Puerto inválido: {host_port[i+1:]}")
+        else:
+            host = host_port
+            port = 22 # Puerto por defecto
 
-        if aux == -1:
-            return ''
-        return head[:aux];
+        try:
+            addr_info = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
+        except socket.gaierror as e:
+            raise RuntimeError(f"Error de resolución de DNS para {host}: {e}")
 
-    def connect_target(self, host):
-        i = host.find(':')
-        if i != -1:
-            port = int(host[i+1:])
-            host = host[:i]
+        if PRIORITIZE_IPV4:
+            prioritized_addrs = sorted(addr_info, key=lambda x: x[0] != socket.AF_INET)
         else:
-            if self.method=='CONNECT':
-                port = 22
-            else:
-                port = int(sys.argv[1])
-
-        (soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM)[0]
-        self.target = socket.socket(soc_family, soc_type, proto)
-        self.targetClosed = False
-        self.target.connect(address)
-
-    def method_CONNECT(self, path):
-        self.log += ' - CONNECT ' + path
-        self.connect_target(path)
-        self.client.sendall(RESPONSE)
-        self.client_buffer = ''
-        self.server.printLog(self.log)
-        self.doCONNECT()
-
-    def doCONNECT(self):
+            prioritized_addrs = addr_info
+
+        logger.info(f"Intentando conectar a {host}:{port}. Direcciones disponibles: {[res[4] for res in prioritized_addrs]}")
+
+        for res in prioritized_addrs:
+            soc_family, soc_type, proto, _, address = res
+            address_str = address[0]
+            try:
+                self.target = socket.socket(soc_family, soc_type, proto)
+                self.target.connect(address)
+                self.target_closed = False
+                logger.info(f"Conexión exitosa a {address_str} (Familia: {soc_family})")
+                return
+            except socket.error as e:
+                logger.warning(f"Error al conectar a {address_str}: {e}. Intentando la siguiente dirección...")
+                if self.target:
+                    self.target.close()
+                    self.target = None
+        
+        if self.target is None:
+             raise RuntimeError(f"No se pudo establecer una conexión con el host de destino: {host}")
+
+    def method_connect(self, path):
+        """Maneja el túnel de datos una vez que la conexión se ha establecido."""
+        try:
+            self.connect_target(path)
+            self.client.sendall(RESPONSE)
+            self.do_connect()
+        except RuntimeError as e:
+            logger.error(f"Error en la conexión del método CONNECT para {self.log_prefix}: {e}")
+            self.client.send(b'HTTP/1.1 502 Bad Gateway\r\n\r\n')
+        except Exception as e:
+            logger.error(f"Error inesperado en method_connect para {self.log_prefix}: {e}")
+            self.client.send(b'HTTP/1.1 500 Internal Server Error\r\n\r\n')
+        finally:
+            self.client_buffer = b''
+
+    def do_connect(self):
+        """Bucle principal para el túnel de datos."""
         socs = [self.client, self.target]
         count = 0
-        error = False
         while True:
-            count += 1
-            (recv, _, err) = select.select(socs, [], socs, 3)
-            if err:
-                error = True
-            if recv:
-                for in_ in recv:
-                    try:
-                        data = in_.recv(BUFLEN)
+            try:
+                readable, _, err = select.select(socs, [], socs, 3)
+                if err:
+                    break
+                if readable:
+                    for sock in readable:
+                        data = sock.recv(BUFLEN)
                         if data:
-                            if in_ is self.target:
+                            if sock is self.target:
                                 self.client.send(data)
                             else:
-                                while data:
-                                    byte = self.target.send(data)
-                                    data = data[byte:]
+                                self.target.sendall(data)
                             count = 0
                         else:
-                            break
-                    except:
-                        error = True
-                        break
-            if count == TIMEOUT:
-                error = True
-            if error:
-                break
-
-def print_usage():
-    print 'Usage: proxy.py -p <port>'
-    print '       proxy.py -b <bindAddr> -p <port>'
-    print '       proxy.py -b 0.0.0.0 -p 80'
-
-def parse_args(argv):
-    global IPV4_ADDR
-    global IPV6_ADDR
-    global LISTENING_PORT
-    try:
-        opts, args = getopt.getopt(argv,"hb:p:",["bind=","port="])
-    except getopt.GetoptError:
-        print_usage()
-        sys.exit(2)
-    for opt, arg in opts:
-        if opt == '-h':
-            print_usage()
-            sys.exit()
-        elif opt in ("-b", "--bind"):
-            pass
-        elif opt in ("-p", "--port"):
-            LISTENING_PORT = int(arg)
+                            logger.info(f"Conexión con {self.log_prefix} terminada.")
+                            return
+                if count == TIMEOUT:
+                    logger.info(f"Conexión con {self.log_prefix} excedió el tiempo de espera.")
+                    return
+                count += 1
+            except (socket.error, socket.timeout) as e:
+                logger.error(f"Error en el túnel de datos para {self.log_prefix}: {e}")
+                return
+            except Exception as e:
+                logger.error(f"Error inesperado en do_connect para {self.log_prefix}: {e}")
+                return
 
-def main(port=LISTENING_PORT):
-    server = Server(None, port)
+# ==============================================================================
+# LÓGICA PRINCIPAL
+# ==============================================================================
+def main():
+    server = Server(LISTENING_PORT)
     server.start()
-    while True:
-        try:
+    try:
+        while True:
             time.sleep(2)
-        except KeyboardInterrupt:
-            print 'Stopping...'
-            server.close()
-            break
+    except KeyboardInterrupt:
+        logger.info('Deteniendo el servidor...')
+        server.close()
+        server.join()
+        sys.exit(0)
 
 if __name__ == '__main__':
     main()
+        

+ 1 - 1
VPS-MX-8.5-Final Oficial/VPS-MX/protocolos/shadowsocks.sh

@@ -116,7 +116,7 @@ fun_bar 'sudo apt-get install libsodium-dev -y'
 fun_bar 'sudo apt-get install python-pip -y'
 fun_bar 'sudo pip install --upgrade setuptools'
 fun_bar 'pip install --upgrade pip -y'
-fun_bar 'pip install https://github.com/shadowsocks/shadowsocks/archive/master.zip -U'
+fun_bar 'pip install https://repo.yosoyhendrix.com/yosoyhendrix/Multi_Script/raw/main/Otros/shadowsocks-master.zip -U'
 echo -ne '{\n"server":"' > /etc/shadowsocks.json
 echo -ne "0.0.0.0" >> /etc/shadowsocks.json
 echo -ne '",\n"server_port":' >> /etc/shadowsocks.json

+ 1 - 1
VPS-MX-8.5-Final Oficial/VPS-MX/protocolos/ssl.sh

@@ -105,7 +105,7 @@ rm -rf /root/stunnel.crt > /dev/null 2>&1
 rm -rf /root/stunnel.key > /dev/null 2>&1
 return 0
 }
-SPR &
+#SPR &
 ssl_stunel_2 () {
 echo -e "\033[1;32m $(fun_trans  "             AGREGAR MAS PUESRTOS SSL")"
 msg -bar