#!/bin/bash
clear
echo -e "\033[1;33m ""\033[1;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"
echo -e "\033[1;33m ""\E[41;1;37m << ENCABEZADOS 101 200 300 700 AL GUSTO O EL QUE QUIERAS >> \033[0m"
echo -e "\033[1;33m ""\033[1;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"
echo ""
echo ""
echo -e "\E[0;37;41mPARA HACER ESTE PROCESO DEVES INSTALAR EL PUERTO PYTHON PRIMERO\033[0m"
echo ""
echo ""
echo -e "\E[0;37;41mCONFUGURACION ENCABEZADO INTERNO PROTOTIPO\033[0m"
echo -e "\E[48;1;37m[1] • AGREGAR CABECERAS CON PUERTO SSL 101\033[0m"
echo -e "\E[48;1;37m[2] • AGREGA CABECERA CON PUERTO PYTHON\033[0m"
echo ""
echo ""
echo -e "\E[0;37;41m[15]-AUTO-MENU O menu\033[0m ""\E[0;37;41m[00]-EXIT\033[0m"
echo ""
function ls () {
pkill python
echo -ne "\E[0;37;41mESCRIVE TU CABECERA REQUERIDA 101 200 600 700\033[0m""\033[1;37m>>\033[0m "; read amor
echo -e "\E[0;37;44mAGREGADO SACTIFACTORIA MENTE\033[0m"
sleep 3s
echo -ne "\E[0;37;41mPUERTO DIRECCION INTERNA SOLO PUERTO >SSH LOCAL\033[0m""\033[1;37m>>\033[0m "; read as
echo -e "\E[0;37;44mAGREGADO SACTIFACTORIA MENTE\033[0m"
sleep 3s
echo -e "\E[0;37;44mFINALIZADO\033[0m"
sleep 3s
(
less << g > /root/te.py
# encoding: utf-8
import socket, threading, thread, select, signal, sys, time
from os import system
system("clear")
IP = '0.0.0.0'
try:
PORT = int(sys.argv[1])
except:
PORT = 80
PASS = ''
BUFLEN = 4196
TIMEOUT = 60
MSG = 'FULL'
COR = ''
FTAG = ''
DEFAULT_HOST = '0.0.0.0:$as'
RESPONSE = "HTTP/1.1 $amor " + str(COR) + str(MSG) + str(FTAG) + "\r\n\r\n"
class Server(threading.Thread):
def __init__(self, host, port):
threading.Thread.__init__(self)
self.running = False
self.host = host
self.port = port
self.threads = []
self.threadsLock = threading.Lock()
self.logLock = threading.Lock()
def run(self):
self.soc = socket.socket(socket.AF_INET)
self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.soc.settimeout(2)
self.soc.bind((self.host, self.port))
self.soc.listen(0)
self.running = True
try:
while self.running:
try:
c, addr = self.soc.accept()
c.setblocking(1)
except socket.timeout:
continue
conn = ConnectionHandler(c, self, addr)
conn.start();
self.addConn(conn)
finally:
self.running = False
self.soc.close()
def printLog(self, log):
self.logLock.acquire()
print log
self.logLock.release()
def addConn(self, conn):
try:
self.threadsLock.acquire()
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 close(self):
try:
self.running = False
self.threadsLock.acquire()
threads = list(self.threads)
for c in threads:
c.close()
finally:
self.threadsLock.release()
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 = ''
self.server = server
self.log = 'Conexao: ' + str(addr)
def close(self):
try:
if not self.clientClosed:
self.client.shutdown(socket.SHUT_RDWR)
self.client.close()
except:
pass
finally:
self.clientClosed = True
try:
if not self.targetClosed:
self.target.shutdown(socket.SHUT_RDWR)
self.target.close()
except:
pass
finally:
self.targetClosed = True
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
split = self.findHeader(self.client_buffer, 'X-Split')
if 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')
if hostPort.startswith(IP):
self.method_CONNECT(hostPort)
else:
self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
else:
print '- No X-Real-Host!'
self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
except Exception as e:
self.log += ' - error: ' + e.strerror
self.server.printLog(self.log)
pass
finally:
self.close()
self.server.removeConn(self)
def findHeader(self, head, header):
aux = head.find(header + ': ')
if aux == -1:
return ''
aux = head.find(':', aux)
head = head[aux+2:]
aux = head.find('\r\n')
if aux == -1:
return ''
return head[:aux];
def connect_target(self, host):
i = host.find(':')
if i != -1:
port = int(host[i+1:])
host = host[:i]
else:
if self.method=='CONNECT':
port = 443
else:
port = 22
(soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[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):
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)
if data:
if in_ is self.target:
self.client.send(data)
else:
while data:
byte = self.target.send(data)
data = data[byte:]
count = 0
else:
break
except:
error = True
break
if count == TIMEOUT:
error = True
if error:
break
def main(host=IP, port=PORT):
print "\033[1;31m━"*34,"\033[1;37m PROTOCOLO","\033[1;31m━"*34,"\n"
print "\033[0m ""\033[1;37mIP:\033[1;37m " + IP
print " ""\033[1;37mPORTA:\033[1;37m " + str(PORT) + "\n"
print "\033[1;31m━"*34,"\033[1;37m FULLLL\033[0m","\033[1;31m━\033[1;37m"*37,"\n"
server = Server(IP, PORT)
server.start()
while True:
try:
time.sleep(2)
except KeyboardInterrupt:
print '\nParando...'
server.close()
break
if __name__ == '__main__':
main()
g
)
pkill -f python &&screen python /root/te.py > /dev/null 2>&1
screen -dmS proxy python te.py
/root/jrd.sh
}
function hg () {
pkill python
echo -ne "\E[0;37;41mESCRIVE TU CABECERA REQUERIDA 101 200 600 700\033[0m""\033[1;37m>>\033[0m "; read amor
echo -e "\E[0;37;44mAGREGADO SACTIFACTORIA MENTE\033[0m"
sleep 3s
echo -ne "\E[0;37;41mESCRIVE TU PUERTO PYTHON EL QUE SEVA UTILIZAR\033[0m""\033[1;37m>>\033[0m "; read f
echo -e "\E[0;37;44mESCOGIDO Y AGREGADO CON EXITO\033[0m"
sleep 3s
echo -ne "\E[0;37;41mPUERTO DIRECCION INTERNA SOLO PUERTO >SSH LOCAL\033[0m""\033[1;37m>>\033[0m "; read as
echo -e "\E[0;37;44mAGREGADO SACTIFACTORIA MENTE\033[0m"
sleep 3s
echo -e "\E[0;37;44mFINALIZADO\033[0m"
sleep 3s
(
less << f > /root/ht.py
import socket, threading, thread, select, signal, sys, time, getopt
# CONFIG
LISTENING_ADDR = '0.0.0.0'
LISTENING_PORT = $f
PASS = ''
# CONST
BUFLEN = 4096 * 4
TIMEOUT = 60
DEFAULT_HOST = "127.0.0.1:$as"
RESPONSE = 'HTTP/1.1 $amor OMAR PROTOCOLO \r\n\r\n'
class Server(threading.Thread):
def __init__(self, host, port):
threading.Thread.__init__(self)
self.running = False
self.host = host
self.port = port
self.threads = []
self.threadsLock = threading.Lock()
self.logLock = threading.Lock()
def run(self):
self.soc = socket.socket(socket.AF_INET)
self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.soc.settimeout(2)
self.soc.bind((self.host, self.port))
self.soc.listen(0)
self.running = True
try:
while self.running:
try:
c, addr = self.soc.accept()
c.setblocking(1)
except socket.timeout:
continue
conn = ConnectionHandler(c, self, addr)
conn.start();
self.addConn(conn)
finally:
self.running = False
self.soc.close()
def printLog(self, log):
self.logLock.acquire()
print log
self.logLock.release()
def addConn(self, conn):
try:
self.threadsLock.acquire()
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 close(self):
try:
self.running = False
self.threadsLock.acquire()
threads = list(self.threads)
for c in threads:
c.close()
finally:
self.threadsLock.release()
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 = ''
self.server = server
self.log = 'Connection: ' + str(addr)
def close(self):
try:
if not self.clientClosed:
self.client.shutdown(socket.SHUT_RDWR)
self.client.close()
except:
pass
finally:
self.clientClosed = True
try:
if not self.targetClosed:
self.target.shutdown(socket.SHUT_RDWR)
self.target.close()
except:
pass
finally:
self.targetClosed = True
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
split = self.findHeader(self.client_buffer, 'X-Split')
if 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)
else:
self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
else:
print '- No X-Real-Host!'
self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
except Exception as e:
self.log += ' - error: ' + e.strerror
self.server.printLog(self.log)
pass
finally:
self.close()
self.server.removeConn(self)
def findHeader(self, head, header):
aux = head.find(header + ': ')
if aux == -1:
return ''
aux = head.find(':', aux)
head = head[aux+2:]
aux = head.find('\r\n')
if aux == -1:
return ''
return head[:aux];
def connect_target(self, host):
i = host.find(':')
if i != -1:
port = int(host[i+1:])
host = host[:i]
else:
if self.method=='CONNECT':
port = 443
else:
port = 22
(soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[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):
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)
if data:
if in_ is self.target:
self.client.send(data)
else:
while data:
byte = self.target.send(data)
data = data[byte:]
count = 0
else:
break
except:
error = True
break
if count == TIMEOUT:
error = True
if error:
break
def print_usage():
print 'Usage: proxy.py -p '
print ' proxy.py -b -p '
print ' proxy.py -b 0.0.0.0 -p 1080'
def parse_args(argv):
global LISTENING_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"):
LISTENING_ADDR = arg
elif opt in ("-p", "--port"):
LISTENING_PORT = int(arg)
def main(host=LISTENING_ADDR, port=LISTENING_PORT):
print "\n ==============================\n"
print "\n PYTHON PROXY \n"
print "\n ==============================\n"
print "corriendo ip: " + LISTENING_ADDR
print "corriendo port: " + str(LISTENING_PORT) + "\n"
print "Se ha Iniciado Por Favor Cierre el Terminal\n"
server = Server(LISTENING_ADDR, LISTENING_PORT)
server.start()
while True:
try:
time.sleep(2)
except KeyboardInterrupt:
print 'Stopping...'
server.close()
break
if __name__ == '__main__':
parse_args(sys.argv[1:])
main()
f
)
screen -dmS python python /root/ht.py -p $f > /dev/null 2>&1
screen -dmS python python proxy.py -p 80
/root/jrd.sh
}
lsof -V -i tcp -P -n | grep -v "ESTABLISHED" | grep -v "COMMAND" | grep "LISTEN" > /bin/m
sed -n ""p /bin/m | grep ssh /bin/m > /bin/j
sed -n ""p /bin/j | awk '{print $9}' | awk -F ":" '{print $2}' > /bin/s
t="SSH LOCAL:"
r=$(sed "1d" /bin/s)
echo -e "$t $r"
echo -ne "\E[0;37;41mOPCION:\033[0m""\033[1;37m>>\033[0m "; read tt > /dev/null 2>&1
case $tt in
1)ls
;;
2)hg
;;
15)echo -e "\033[1;34mVOLVIENDO...\033[0m"
sleep 2s
/root/menu
;;
esac
exit