1
0

jrd.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. #!/bin/bash
  2. clear
  3. echo -e "\033[1;33m ""\033[1;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"
  4. echo -e "\033[1;33m ""\E[41;1;37m << ENCABEZADOS 101 200 300 700 AL GUSTO O EL QUE QUIERAS >> \033[0m"
  5. echo -e "\033[1;33m ""\033[1;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"
  6. echo ""
  7. echo ""
  8. echo -e "\E[0;37;41mPARA HACER ESTE PROCESO DEVES INSTALAR EL PUERTO PYTHON PRIMERO\033[0m"
  9. echo ""
  10. echo ""
  11. echo -e "\E[0;37;41mCONFUGURACION ENCABEZADO INTERNO PROTOTIPO\033[0m"
  12. echo -e "\E[48;1;37m[1] • AGREGAR CABECERAS CON PUERTO SSL 101\033[0m"
  13. echo -e "\E[48;1;37m[2] • AGREGA CABECERA CON PUERTO PYTHON\033[0m"
  14. echo ""
  15. echo ""
  16. echo -e "\E[0;37;41m[15]-AUTO-MENU O menu\033[0m ""\E[0;37;41m[00]-EXIT\033[0m"
  17. echo ""
  18. function ls () {
  19. pkill python
  20. echo -ne "\E[0;37;41mESCRIVE TU CABECERA REQUERIDA 101 200 600 700\033[0m""\033[1;37m>>\033[0m "; read amor
  21. echo -e "\E[0;37;44mAGREGADO SACTIFACTORIA MENTE\033[0m"
  22. sleep 3s
  23. echo -ne "\E[0;37;41mPUERTO DIRECCION INTERNA SOLO PUERTO >SSH LOCAL\033[0m""\033[1;37m>>\033[0m "; read as
  24. echo -e "\E[0;37;44mAGREGADO SACTIFACTORIA MENTE\033[0m"
  25. sleep 3s
  26. echo -e "\E[0;37;44mFINALIZADO\033[0m"
  27. sleep 3s
  28. (
  29. less << g > /root/te.py
  30. # encoding: utf-8
  31. import socket, threading, thread, select, signal, sys, time
  32. from os import system
  33. system("clear")
  34. IP = '0.0.0.0'
  35. try:
  36. PORT = int(sys.argv[1])
  37. except:
  38. PORT = 80
  39. PASS = ''
  40. BUFLEN = 4196
  41. TIMEOUT = 60
  42. MSG = 'FULL'
  43. COR = '<font color="null">'
  44. FTAG = '</font>'
  45. DEFAULT_HOST = '0.0.0.0:$as'
  46. RESPONSE = "HTTP/1.1 $amor " + str(COR) + str(MSG) + str(FTAG) + "\r\n\r\n"
  47. class Server(threading.Thread):
  48. def __init__(self, host, port):
  49. threading.Thread.__init__(self)
  50. self.running = False
  51. self.host = host
  52. self.port = port
  53. self.threads = []
  54. self.threadsLock = threading.Lock()
  55. self.logLock = threading.Lock()
  56. def run(self):
  57. self.soc = socket.socket(socket.AF_INET)
  58. self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  59. self.soc.settimeout(2)
  60. self.soc.bind((self.host, self.port))
  61. self.soc.listen(0)
  62. self.running = True
  63. try:
  64. while self.running:
  65. try:
  66. c, addr = self.soc.accept()
  67. c.setblocking(1)
  68. except socket.timeout:
  69. continue
  70. conn = ConnectionHandler(c, self, addr)
  71. conn.start();
  72. self.addConn(conn)
  73. finally:
  74. self.running = False
  75. self.soc.close()
  76. def printLog(self, log):
  77. self.logLock.acquire()
  78. print log
  79. self.logLock.release()
  80. def addConn(self, conn):
  81. try:
  82. self.threadsLock.acquire()
  83. if self.running:
  84. self.threads.append(conn)
  85. finally:
  86. self.threadsLock.release()
  87. def removeConn(self, conn):
  88. try:
  89. self.threadsLock.acquire()
  90. self.threads.remove(conn)
  91. finally:
  92. self.threadsLock.release()
  93. def close(self):
  94. try:
  95. self.running = False
  96. self.threadsLock.acquire()
  97. threads = list(self.threads)
  98. for c in threads:
  99. c.close()
  100. finally:
  101. self.threadsLock.release()
  102. class ConnectionHandler(threading.Thread):
  103. def __init__(self, socClient, server, addr):
  104. threading.Thread.__init__(self)
  105. self.clientClosed = False
  106. self.targetClosed = True
  107. self.client = socClient
  108. self.client_buffer = ''
  109. self.server = server
  110. self.log = 'Conexao: ' + str(addr)
  111. def close(self):
  112. try:
  113. if not self.clientClosed:
  114. self.client.shutdown(socket.SHUT_RDWR)
  115. self.client.close()
  116. except:
  117. pass
  118. finally:
  119. self.clientClosed = True
  120. try:
  121. if not self.targetClosed:
  122. self.target.shutdown(socket.SHUT_RDWR)
  123. self.target.close()
  124. except:
  125. pass
  126. finally:
  127. self.targetClosed = True
  128. def run(self):
  129. try:
  130. self.client_buffer = self.client.recv(BUFLEN)
  131. hostPort = self.findHeader(self.client_buffer, 'X-Real-Host')
  132. if hostPort == '':
  133. hostPort = DEFAULT_HOST
  134. split = self.findHeader(self.client_buffer, 'X-Split')
  135. if split != '':
  136. self.client.recv(BUFLEN)
  137. if hostPort != '':
  138. passwd = self.findHeader(self.client_buffer, 'X-Pass')
  139. if len(PASS) != 0 and passwd == PASS:
  140. self.method_CONNECT(hostPort)
  141. elif len(PASS) != 0 and passwd != PASS:
  142. self.client.send('HTTP/1.1 400 WrongPass!\r\n\r\n')
  143. if hostPort.startswith(IP):
  144. self.method_CONNECT(hostPort)
  145. else:
  146. self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
  147. else:
  148. print '- No X-Real-Host!'
  149. self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
  150. except Exception as e:
  151. self.log += ' - error: ' + e.strerror
  152. self.server.printLog(self.log)
  153. pass
  154. finally:
  155. self.close()
  156. self.server.removeConn(self)
  157. def findHeader(self, head, header):
  158. aux = head.find(header + ': ')
  159. if aux == -1:
  160. return ''
  161. aux = head.find(':', aux)
  162. head = head[aux+2:]
  163. aux = head.find('\r\n')
  164. if aux == -1:
  165. return ''
  166. return head[:aux];
  167. def connect_target(self, host):
  168. i = host.find(':')
  169. if i != -1:
  170. port = int(host[i+1:])
  171. host = host[:i]
  172. else:
  173. if self.method=='CONNECT':
  174. port = 443
  175. else:
  176. port = 22
  177. (soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]
  178. self.target = socket.socket(soc_family, soc_type, proto)
  179. self.targetClosed = False
  180. self.target.connect(address)
  181. def method_CONNECT(self, path):
  182. self.log += ' - CONNECT ' + path
  183. self.connect_target(path)
  184. self.client.sendall(RESPONSE)
  185. self.client_buffer = ''
  186. self.server.printLog(self.log)
  187. self.doCONNECT()
  188. def doCONNECT(self):
  189. socs = [self.client, self.target]
  190. count = 0
  191. error = False
  192. while True:
  193. count += 1
  194. (recv, _, err) = select.select(socs, [], socs, 3)
  195. if err:
  196. error = True
  197. if recv:
  198. for in_ in recv:
  199. try:
  200. data = in_.recv(BUFLEN)
  201. if data:
  202. if in_ is self.target:
  203. self.client.send(data)
  204. else:
  205. while data:
  206. byte = self.target.send(data)
  207. data = data[byte:]
  208. count = 0
  209. else:
  210. break
  211. except:
  212. error = True
  213. break
  214. if count == TIMEOUT:
  215. error = True
  216. if error:
  217. break
  218. def main(host=IP, port=PORT):
  219. print "\033[1;31m━"*34,"\033[1;37m PROTOCOLO","\033[1;31m━"*34,"\n"
  220. print "\033[0m ""\033[1;37mIP:\033[1;37m " + IP
  221. print " ""\033[1;37mPORTA:\033[1;37m " + str(PORT) + "\n"
  222. print "\033[1;31m━"*34,"\033[1;37m FULLLL\033[0m","\033[1;31m━\033[1;37m"*37,"\n"
  223. server = Server(IP, PORT)
  224. server.start()
  225. while True:
  226. try:
  227. time.sleep(2)
  228. except KeyboardInterrupt:
  229. print '\nParando...'
  230. server.close()
  231. break
  232. if __name__ == '__main__':
  233. main()
  234. g
  235. )
  236. pkill -f python &&screen python /root/te.py > /dev/null 2>&1
  237. screen -dmS proxy python te.py
  238. /root/jrd.sh
  239. }
  240. function hg () {
  241. pkill python
  242. echo -ne "\E[0;37;41mESCRIVE TU CABECERA REQUERIDA 101 200 600 700\033[0m""\033[1;37m>>\033[0m "; read amor
  243. echo -e "\E[0;37;44mAGREGADO SACTIFACTORIA MENTE\033[0m"
  244. sleep 3s
  245. echo -ne "\E[0;37;41mESCRIVE TU PUERTO PYTHON EL QUE SEVA UTILIZAR\033[0m""\033[1;37m>>\033[0m "; read f
  246. echo -e "\E[0;37;44mESCOGIDO Y AGREGADO CON EXITO\033[0m"
  247. sleep 3s
  248. echo -ne "\E[0;37;41mPUERTO DIRECCION INTERNA SOLO PUERTO >SSH LOCAL\033[0m""\033[1;37m>>\033[0m "; read as
  249. echo -e "\E[0;37;44mAGREGADO SACTIFACTORIA MENTE\033[0m"
  250. sleep 3s
  251. echo -e "\E[0;37;44mFINALIZADO\033[0m"
  252. sleep 3s
  253. (
  254. less << f > /root/ht.py
  255. import socket, threading, thread, select, signal, sys, time, getopt
  256. # CONFIG
  257. LISTENING_ADDR = '0.0.0.0'
  258. LISTENING_PORT = $f
  259. PASS = ''
  260. # CONST
  261. BUFLEN = 4096 * 4
  262. TIMEOUT = 60
  263. DEFAULT_HOST = "127.0.0.1:$as"
  264. RESPONSE = 'HTTP/1.1 $amor OMAR PROTOCOLO \r\n\r\n'
  265. class Server(threading.Thread):
  266. def __init__(self, host, port):
  267. threading.Thread.__init__(self)
  268. self.running = False
  269. self.host = host
  270. self.port = port
  271. self.threads = []
  272. self.threadsLock = threading.Lock()
  273. self.logLock = threading.Lock()
  274. def run(self):
  275. self.soc = socket.socket(socket.AF_INET)
  276. self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  277. self.soc.settimeout(2)
  278. self.soc.bind((self.host, self.port))
  279. self.soc.listen(0)
  280. self.running = True
  281. try:
  282. while self.running:
  283. try:
  284. c, addr = self.soc.accept()
  285. c.setblocking(1)
  286. except socket.timeout:
  287. continue
  288. conn = ConnectionHandler(c, self, addr)
  289. conn.start();
  290. self.addConn(conn)
  291. finally:
  292. self.running = False
  293. self.soc.close()
  294. def printLog(self, log):
  295. self.logLock.acquire()
  296. print log
  297. self.logLock.release()
  298. def addConn(self, conn):
  299. try:
  300. self.threadsLock.acquire()
  301. if self.running:
  302. self.threads.append(conn)
  303. finally:
  304. self.threadsLock.release()
  305. def removeConn(self, conn):
  306. try:
  307. self.threadsLock.acquire()
  308. self.threads.remove(conn)
  309. finally:
  310. self.threadsLock.release()
  311. def close(self):
  312. try:
  313. self.running = False
  314. self.threadsLock.acquire()
  315. threads = list(self.threads)
  316. for c in threads:
  317. c.close()
  318. finally:
  319. self.threadsLock.release()
  320. class ConnectionHandler(threading.Thread):
  321. def __init__(self, socClient, server, addr):
  322. threading.Thread.__init__(self)
  323. self.clientClosed = False
  324. self.targetClosed = True
  325. self.client = socClient
  326. self.client_buffer = ''
  327. self.server = server
  328. self.log = 'Connection: ' + str(addr)
  329. def close(self):
  330. try:
  331. if not self.clientClosed:
  332. self.client.shutdown(socket.SHUT_RDWR)
  333. self.client.close()
  334. except:
  335. pass
  336. finally:
  337. self.clientClosed = True
  338. try:
  339. if not self.targetClosed:
  340. self.target.shutdown(socket.SHUT_RDWR)
  341. self.target.close()
  342. except:
  343. pass
  344. finally:
  345. self.targetClosed = True
  346. def run(self):
  347. try:
  348. self.client_buffer = self.client.recv(BUFLEN)
  349. hostPort = self.findHeader(self.client_buffer, 'X-Real-Host')
  350. if hostPort == '':
  351. hostPort = DEFAULT_HOST
  352. split = self.findHeader(self.client_buffer, 'X-Split')
  353. if split != '':
  354. self.client.recv(BUFLEN)
  355. if hostPort != '':
  356. passwd = self.findHeader(self.client_buffer, 'X-Pass')
  357. if len(PASS) != 0 and passwd == PASS:
  358. self.method_CONNECT(hostPort)
  359. elif len(PASS) != 0 and passwd != PASS:
  360. self.client.send('HTTP/1.1 400 WrongPass!\r\n\r\n')
  361. elif hostPort.startswith('127.0.0.1') or hostPort.startswith('localhost'):
  362. self.method_CONNECT(hostPort)
  363. else:
  364. self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
  365. else:
  366. print '- No X-Real-Host!'
  367. self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
  368. except Exception as e:
  369. self.log += ' - error: ' + e.strerror
  370. self.server.printLog(self.log)
  371. pass
  372. finally:
  373. self.close()
  374. self.server.removeConn(self)
  375. def findHeader(self, head, header):
  376. aux = head.find(header + ': ')
  377. if aux == -1:
  378. return ''
  379. aux = head.find(':', aux)
  380. head = head[aux+2:]
  381. aux = head.find('\r\n')
  382. if aux == -1:
  383. return ''
  384. return head[:aux];
  385. def connect_target(self, host):
  386. i = host.find(':')
  387. if i != -1:
  388. port = int(host[i+1:])
  389. host = host[:i]
  390. else:
  391. if self.method=='CONNECT':
  392. port = 443
  393. else:
  394. port = 22
  395. (soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]
  396. self.target = socket.socket(soc_family, soc_type, proto)
  397. self.targetClosed = False
  398. self.target.connect(address)
  399. def method_CONNECT(self, path):
  400. self.log += ' - CONNECT ' + path
  401. self.connect_target(path)
  402. self.client.sendall(RESPONSE)
  403. self.client_buffer = ''
  404. self.server.printLog(self.log)
  405. self.doCONNECT()
  406. def doCONNECT(self):
  407. socs = [self.client, self.target]
  408. count = 0
  409. error = False
  410. while True:
  411. count += 1
  412. (recv, _, err) = select.select(socs, [], socs, 3)
  413. if err:
  414. error = True
  415. if recv:
  416. for in_ in recv:
  417. try:
  418. data = in_.recv(BUFLEN)
  419. if data:
  420. if in_ is self.target:
  421. self.client.send(data)
  422. else:
  423. while data:
  424. byte = self.target.send(data)
  425. data = data[byte:]
  426. count = 0
  427. else:
  428. break
  429. except:
  430. error = True
  431. break
  432. if count == TIMEOUT:
  433. error = True
  434. if error:
  435. break
  436. def print_usage():
  437. print 'Usage: proxy.py -p <port>'
  438. print ' proxy.py -b <bindAddr> -p <port>'
  439. print ' proxy.py -b 0.0.0.0 -p 1080'
  440. def parse_args(argv):
  441. global LISTENING_ADDR
  442. global LISTENING_PORT
  443. try:
  444. opts, args = getopt.getopt(argv,"hb:p:",["bind=","port="])
  445. except getopt.GetoptError:
  446. print_usage()
  447. sys.exit(2)
  448. for opt, arg in opts:
  449. if opt == '-h':
  450. print_usage()
  451. sys.exit()
  452. elif opt in ("-b", "--bind"):
  453. LISTENING_ADDR = arg
  454. elif opt in ("-p", "--port"):
  455. LISTENING_PORT = int(arg)
  456. def main(host=LISTENING_ADDR, port=LISTENING_PORT):
  457. print "\n ==============================\n"
  458. print "\n PYTHON PROXY \n"
  459. print "\n ==============================\n"
  460. print "corriendo ip: " + LISTENING_ADDR
  461. print "corriendo port: " + str(LISTENING_PORT) + "\n"
  462. print "Se ha Iniciado Por Favor Cierre el Terminal\n"
  463. server = Server(LISTENING_ADDR, LISTENING_PORT)
  464. server.start()
  465. while True:
  466. try:
  467. time.sleep(2)
  468. except KeyboardInterrupt:
  469. print 'Stopping...'
  470. server.close()
  471. break
  472. if __name__ == '__main__':
  473. parse_args(sys.argv[1:])
  474. main()
  475. f
  476. )
  477. screen -dmS python python /root/ht.py -p $f > /dev/null 2>&1
  478. screen -dmS python python proxy.py -p 80
  479. /root/jrd.sh
  480. }
  481. lsof -V -i tcp -P -n | grep -v "ESTABLISHED" | grep -v "COMMAND" | grep "LISTEN" > /bin/m
  482. sed -n ""p /bin/m | grep ssh /bin/m > /bin/j
  483. sed -n ""p /bin/j | awk '{print $9}' | awk -F ":" '{print $2}' > /bin/s
  484. t="SSH LOCAL:"
  485. r=$(sed "1d" /bin/s)
  486. echo -e "$t $r"
  487. echo -ne "\E[0;37;41mOPCION:\033[0m""\033[1;37m>>\033[0m "; read tt > /dev/null 2>&1
  488. case $tt in
  489. 1)ls
  490. ;;
  491. 2)hg
  492. ;;
  493. 15)echo -e "\033[1;34mVOLVIENDO...\033[0m"
  494. sleep 2s
  495. /root/menu
  496. ;;
  497. esac
  498. exit