clflareIPscan.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import ipcalc
  2. import socket,random,re
  3. import threading,configparser
  4. import requests,sys,time,os
  5. bg=''
  6. G = bg+'\033[32m'
  7. O = bg+'\033[33m'
  8. GR = bg+'\033[37m'
  9. R = bg+'\033[31m'
  10. print(O+'''
  11. \tWEBSOCKET SCANNER
  12. \tBy : mentalista
  13. \t versão Mais rápida (usando rosqueamento, threading)
  14. #'''+GR)
  15. def update():
  16. statement = f"[{R}!{GR}] {O}Observe os intervalos de ip atualizando semanalmente\n {G}Você deseja atualizar os intervalos de ip ?{G} "
  17. for chr in statement:
  18. sys.stdout.write(chr)
  19. sys.stdout.flush()
  20. time.sleep(0.1)
  21. decision = input(f'[y/n]\n< :{GR}')
  22. if decision.upper() == 'Y':
  23. os.system('rm .firstusage.log')
  24. else:return 0
  25. return decision.upper()
  26. ipdict ={}
  27. def createlog():
  28. if os.path.exists('.firstusage.log'):
  29. arg = 'r'
  30. updating = update()
  31. if updating =='Y':
  32. arg = 'a+'
  33. status = '[*] atualizando'
  34. else:
  35. status = 'ola mae !'
  36. arg = 'a+'
  37. with open('.firstusage.log',arg) as f:
  38. if len(f.read()) < 1:
  39. input(f'-{G}{status}{GR}\n{R}[!] mude para wifi ou conexão de dados para atualizar a lista de ipranges e dê Enter {GR}')
  40. url ='https://www.cloudflare.com/ips-v4'
  41. req = requests.get(url).text
  42. ranges = req.split()
  43. input(f'{G}[#]Desligue o wifi ou mude para sem dados \n e então dê Enter para continuar ')
  44. f.write(str(ranges))
  45. else:
  46. with open('.firstusage.log',arg) as f:
  47. ranges = f.read().replace('[','').replace(']','').replace('\'','').split(',')
  48. return ranges
  49. def save(x):
  50. with open('wrCloudflrIp.txt','a') as fl:
  51. fl.write(str(x)+'\n')
  52. fl.close()
  53. def scanner(host):
  54. sock=socket.socket()
  55. sock.settimeout(2)
  56. try:
  57. sock.connect((str(host),80))
  58. payload='GET / HTTP/1.1\r\nHost: {}\r\n\r\n'.format(host)
  59. sock.send(payload.encode())
  60. response=sock.recv(1024).decode('utf-8','ignore')
  61. for data in response.split('\r\n'):
  62. data=data.split(':')
  63. if re.match(r'HTTP/\d(\.\d)?' ,data[0]):
  64. print('response status : {}{}{}'.format(O,data[0],GR))
  65. if data[0]=='Server':
  66. try:
  67. if data[1] ==' cloudflare':
  68. print('{}server : {}\nFound working {}..'.format(G,host,GR))
  69. save(f'{host} === opened')
  70. payloadsnd(host)
  71. except Exception as e:
  72. print(e)
  73. except Exception as e:print(e)
  74. def auto_replace(server,ip):
  75. packet = server.recv(1024).decode('utf-8','ignore')
  76. status = packet.split('\n')[0]
  77. if re.match(r'HTTP/\d(\.\d)? 101',status):
  78. print(f'{O}[TCP] response : {G}{status}{GR}')
  79. save(f'{ip} response ==== {status}')
  80. else:
  81. if re.match(r'HTTP/\d(\.\d)? \d\d\d ',status):
  82. server.send(b'HTTP/1.1 200 Connection established\r\n\r\n')
  83. print(f'{O}[TCP] response : {R}{status}{GR}')
  84. return auto_replace(server,ip)
  85. def payloadsnd(ip):
  86. config = configparser.ConfigParser()
  87. config.read_file(open('configfile.ini'))
  88. domain = config['websocket']['custom_domain']
  89. port =80
  90. sc=socket.socket()
  91. sc.connect((str(ip),port))
  92. payload=f'GET / HTTP/1.0[crlf]Host: {domain}[crlf][crlf]'
  93. payload=payload.replace('[crlf]','\r\n')
  94. sc.send(payload.encode())
  95. auto_replace(sc,ip)
  96. def Main():
  97. ipdict={}
  98. ranges = createlog()
  99. for k,v in enumerate(ranges):
  100. #clr = random.choice([G,GR,O])
  101. ipdict[k]=v
  102. for choose in range(len(ipdict)):
  103. iprange=[]
  104. cidr=ipdict[choose]
  105. print(cidr)
  106. for ip in ipcalc.Network(cidr):
  107. iprange.append(ip)
  108. for index in range(len(iprange)):
  109. try:
  110. print("{}[INFO] Sondagem... ({}/{}) [{}]{}".format(
  111. R,index+1,len(iprange),iprange[index],GR))
  112. sc=threading.Thread(target=scanner,args=(iprange[index],))
  113. sc.start()
  114. except KeyboardInterrupt:
  115. print('{}Verificação abortada pelo Noob!{}'.format(R,GR))
  116. break
  117. if __name__=="__main__":
  118. Main()