123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- """
- This file is part of the XSSer project, https://xsser.03c8.net
- Copyright (c) 2010/2019 | psy <epsylon@riseup.net>
- xsser is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation version 3 of the License.
- xsser is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- details.
- You should have received a copy of the GNU General Public License along
- with xsser; if not, write to the Free Software Foundation, Inc., 51
- Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- ........
- List of search engines: https://en.wikipedia.org/wiki/List_of_search_engines
- Currently supported: duck(default), startpage, yahoo, bing
- """
- import urllib.request, urllib.error, urllib.parse, traceback, re, random
- urllib.request.socket.setdefaulttimeout(5.0)
- DEBUG = 0
- class Dorker(object):
- def __init__(self, engine='duck'):
- self._engine = engine
- self.search_engines = []
- self.search_engines.append('duck')
- self.search_engines.append('startpage')
- self.search_engines.append('yahoo')
- self.search_engines.append('bing')
- self.agents = []
- try:
- f = open("core/fuzzing/user-agents.txt").readlines()
- except:
- f = open("fuzzing/user-agents.txt").readlines()
- for line in f:
- self.agents.append(line)
- def dork(self, search):
- """
- Perform a search and return links.
- """
- if self._engine == 'bing':
- search_url = 'https://www.bing.com/search?q="' + str(search) + '"'
- print("\nSearching query:", urllib.parse.unquote(search_url))
- elif self._engine == 'yahoo':
- search_url = 'https://search.yahoo.com/search?q="' + str(search) + '"'
- print("\nSearching query:", urllib.parse.unquote(search_url))
- elif self._engine == 'duck':
- search_url = 'https://duckduckgo.com/html/'
- q = 'instreamset:(url):"' + str(search) + '"'
- query_string = { 'q':q }
- print("\nSearching query:", urllib.parse.unquote(search_url) + " [POST: (" + q + ")]")
- elif self._engine == 'startpage':
- search_url = 'https://www.startpage.com/do/asearch'
- q = 'url:"' + str(search) + '"'
- query_string = { 'cmd':'process_search', 'query':q }
- print("\nSearching query:", urllib.parse.unquote(search_url) + " [POST: (" + q + ")]")
- else:
- print("\n[Error] This search engine is not being supported!\n")
- print('-'*25)
- print("\n[Info] Use one from this list:\n")
- for e in self.search_engines:
- print("+ "+e)
- print("\n ex: xsser -d 'profile.asp?num=' --De 'duck'")
- print(" ex: xsser -l --De 'startpage'")
- print("\n[Info] Or try them all:\n\n ex: xsser -d 'news.php?id=' --Da\n")
- try:
- self.search_url = search_url
- user_agent = random.choice(self.agents).strip()
- referer = '127.0.0.1'
- headers = {'User-Agent' : user_agent, 'Referer' : referer}
- if self._engine == 'bing' or self._engine == 'yahoo':
- req = urllib.request.Request(search_url, None, headers)
- elif self._engine == 'duck' or self._engine == 'startpage':
- data = urllib.parse.urlencode(query_string)
- req = urllib.request.Request(search_url, data, headers)
- html_data = urllib.request.urlopen(req).read().decode('utf8')
- print("\n[Info] Retrieving requested info...\n")
- except urllib.error.URLError as e:
- if DEBUG:
- traceback.print_exc()
- print("\n[Error] Cannot connect!")
- print("\n" + "-"*50)
- return
- if self._engine == 'bing':
- regex = '<h2><a href="(.+?)" h='
- if self._engine == 'yahoo':
- regex = 'RU=(.+?)/RK='
- if self._engine == 'duck':
- regex = '<a class="result__url" href="(.+?)">'
- if self._engine == 'startpage':
- regex = 'target="_blank">(.+?)</a>'
- pattern = re.compile(regex)
- links = re.findall(pattern, html_data, flags=0)
- found_links = []
- if links:
- for link in links:
- link = urllib.parse.unquote(link)
- if self._engine == "yahoo":
- if "RU=https://www.yahoo.com/" in link:
- link = ""
- if search.upper() in link.upper():
- sep = search
- link2 = link.split(sep,1)[0]
- if link2 not in found_links:
- found_links.append(link)
- else:
- print("\n[Error] Not any link found for that query!")
- return found_links
- if __name__ == '__main__':
- for a in ['bing', 'yahoo', 'duck', 'startpage']:
- dork = Dorker(a)
- res = dork.dork("news.php?id=")
- if res:
- print("\n[+] Search Engine:", a, "| Found: ", len(res), "\n")
- for b in res:
- print(" *", b)
|