Advertisement
SAINTSATRIA

leaked-search.py

May 16th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1.  
  2. # -*- encoding: utf8 -*-
  3. # Multi searcher by Nas @proclnas <proclnas@gmail.com>
  4. #
  5. # Current engines:
  6. # [ask, bing, rambler.ru]
  7. #
  8. # Made to be simple and fast. Edit if you want. (:
  9. #
  10. # Verificar propriedades para menos código.
  11.  
  12. import requests
  13. import re
  14. import os
  15. import argparse
  16. from sys import exit
  17. from threading import Thread, Event
  18. from Queue import Queue
  19. from bs4 import BeautifulSoup
  20.  
  21.  
  22. class MultiSearcher:
  23. def __init__(self, dork_file, output, threads):
  24. self.dork_file = dork_file
  25. self.output = output
  26. self.links = []
  27. self.ptr_limits = {
  28. 'bing': 611,
  29. 'ask': 20,
  30. 'rambler': 20
  31. }
  32. self.exclude_itens = 'msn|microsoft|php-brasil|facebook|4shared|bing|imasters|phpbrasil|php.net|yahoo| \
  33. scrwordtbrasil|under-linux|google|msdn|ask|bing|rambler|youtube'
  34.  
  35. self.engines = {
  36. 'bing': {
  37. 'progress_string': '[Bing] Quering page {}/{} with dork {}\n',
  38. 'search_string': 'http://www.bing.com/search?q={}&count=50&first={}',
  39. 'page_range': xrange(1, self.ptr_limits['bing'], 10)
  40. },
  41. 'ask': {
  42. 'progress_string': '[Ask] Quering page {}/{} with dork {}\n',
  43. 'search_string': 'http://www.ask.com/web?q={}&page={}',
  44. 'page_range': xrange(1, self.ptr_limits['ask'])
  45. },
  46. 'rambler': {
  47. 'progress_string': '[Rambler.ru] Quering page {}/{} with dork {}\n',
  48. 'search_string': 'http://nova.rambler.ru/search?query={}&page={}',
  49. 'page_range': xrange(1, self.ptr_limits['rambler'])
  50. }
  51. }
  52.  
  53. self.threads = threads
  54. self.q = Queue()
  55. self.t_stop = Event()
  56. self.counter = 0
  57. self.list_size = len(open(self.dork_file).readlines())
  58.  
  59. def get_links(self, word, engine):
  60. self.links = []
  61. current_engine = self.engines[engine]
  62.  
  63. for ptr in current_engine['page_range']:
  64. print current_engine['progress_string'].format(ptr, self.ptr_limits[engine], word)
  65.  
  66. content = requests.get(current_engine['search_string'].format(word, str(ptr)))
  67.  
  68. if content.ok:
  69. try:
  70. soup = BeautifulSoup(content.text)
  71.  
  72. for link in soup.find_all('a'):
  73. link = link.get('href')
  74.  
  75. if 'http' in link and not re.search(self.exclude_itens, link):
  76.  
  77. if link not in self.links:
  78. self.links.append(link)
  79. with open(self.output, 'a+') as fd:
  80. fd.write(link + '\n')
  81. except Exception:
  82. pass
  83.  
  84. def search(self, q):
  85. while not self.t_stop.is_set():
  86. self.t_stop.wait(1)
  87.  
  88. try:
  89. word = q.get()
  90. self.get_links(word, 'bing') # Bing
  91. self.get_links(word, 'ask') # Ask
  92. self.get_links(word, 'rambler') # Rambler
  93.  
  94. except Exception:
  95. pass
  96. finally:
  97. self.counter += 1
  98. q.task_done()
  99.  
  100. def main(self):
  101. for _ in xrange(self.threads):
  102. t = Thread(target=self.search, args=(self.q,))
  103. t.setDaemon(True)
  104. t.start()
  105.  
  106. for word in open(self.dork_file):
  107. self.q.put(word.strip())
  108.  
  109. try:
  110. while not self.t_stop.is_set():
  111. self.t_stop.wait(1)
  112. if self.counter == self.list_size:
  113. self.t_stop.set()
  114.  
  115. except KeyboardInterrupt:
  116. print '~ Sending signal to kill threads...'
  117. self.t_stop.set()
  118. exit(0)
  119.  
  120. self.q.join()
  121. print 'Finished!'
  122.  
  123. if __name__ == "__main__":
  124. banner = '''
  125. __ __ _ _ _ _____ _
  126. | \/ | | | | (_)/ ____| | |
  127. | \ / |_ _| | |_ _| (___ ___ __ _ _ __ ___| |__ ___ _ __
  128. | |\/| | | | | | __| |\___ \ / _ \/ _` | '__/ __| '_ \ / _ \ '__|
  129. | | | | |_| | | |_| |____) | __/ (_| | | | (__| | | | __/ |
  130. |_| |_|\__,_|_|\__|_|_____/ \___|\__,_|_| \___|_| |_|\___|_|
  131. By @proclnas
  132. '''
  133.  
  134. parser = argparse.ArgumentParser(description='Procz Multi Searcher')
  135.  
  136. parser.add_argument(
  137. '-f', '--file',
  138. action='store',
  139. dest='dork_file',
  140. help='List with dorks to scan (One per line)',
  141. required=True
  142. )
  143. parser.add_argument(
  144. '-o', '--output',
  145. action='store',
  146. dest='output',
  147. help='Output to save valid results',
  148. default='output.txt'
  149. )
  150. parser.add_argument(
  151. '-t', '--threads',
  152. action='store',
  153. default=1,
  154. dest='threads',
  155. help='Concurrent workers (By word)',
  156. type=int
  157. )
  158. parser.add_argument('--version', action='version', version='%(prog)s 1.0')
  159. args = parser.parse_args()
  160.  
  161. if args.dork_file:
  162. if not os.path.isfile(args.dork_file):
  163. exit('File {} not found'.format(args.dork_file))
  164.  
  165. print banner
  166. multi_searcher = MultiSearcher(args.dork_file, args.output, args.threads)
  167. multi_searcher.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement