Files
XSStrike/core/photon.py

83 lines
3.6 KiB
Python
Raw Permalink Normal View History

2019-04-08 13:48:44 +05:30
import re
2018-10-27 18:58:52 +05:30
import concurrent.futures
2018-10-28 00:52:19 +05:30
from urllib.parse import urlparse
2018-10-27 18:58:52 +05:30
2019-04-08 13:48:44 +05:30
from core.dom import dom
from core.log import setup_logger
2018-10-27 18:58:52 +05:30
from core.utils import getUrl, getParams
from core.requester import requester
from core.zetanize import zetanize
2019-04-08 13:48:44 +05:30
from plugins.retireJs import retireJs
logger = setup_logger(__name__)
2018-10-27 18:58:52 +05:30
2018-11-16 21:13:45 +05:30
2019-04-08 13:48:44 +05:30
def photon(seedUrl, headers, level, threadCount, delay, timeout, skipDOM):
2018-11-16 21:13:45 +05:30
forms = [] # web forms
processed = set() # urls that have been crawled
storage = set() # urls that belong to the target i.e. in-scope
schema = urlparse(seedUrl).scheme # extract the scheme e.g. http or https
host = urlparse(seedUrl).netloc # extract the host e.g. example.com
main_url = schema + '://' + host # join scheme and host to make the root url
storage.add(seedUrl) # add the url to storage
2019-04-08 13:48:44 +05:30
checkedDOMs = []
2018-11-16 21:13:45 +05:30
2018-10-27 18:58:52 +05:30
def rec(target):
processed.add(target)
2018-11-22 14:45:34 +05:30
printableTarget = '/'.join(target.split('/')[3:])
if len(printableTarget) > 40:
printableTarget = printableTarget[-40:]
else:
printableTarget = (printableTarget + (' ' * (40 - len(printableTarget))))
logger.run('Parsing %s\r' % printableTarget)
2018-11-13 12:43:47 +05:30
url = getUrl(target, True)
2018-10-27 18:58:52 +05:30
params = getParams(target, '', True)
2018-11-16 21:13:45 +05:30
if '=' in target: # if there's a = in the url, there should be GET parameters
2018-10-27 18:58:52 +05:30
inps = []
for name, value in params.items():
inps.append({'name': name, 'value': value})
forms.append({0: {'action': url, 'method': 'get', 'inputs': inps}})
2018-11-10 17:33:48 +05:30
response = requester(url, params, headers, True, delay, timeout).text
2019-04-06 20:45:10 +05:30
retireJs(url, response)
2019-04-08 13:48:44 +05:30
if not skipDOM:
highlighted = dom(response)
clean_highlighted = ''.join([re.sub(r'^\d+\s+', '', line) for line in highlighted])
if highlighted and clean_highlighted not in checkedDOMs:
checkedDOMs.append(clean_highlighted)
logger.good('Potentially vulnerable objects found at %s' % url)
logger.red_line(level='good')
for line in highlighted:
logger.no_format(line, level='good')
logger.red_line(level='good')
2018-10-27 18:58:52 +05:30
forms.append(zetanize(response))
2019-04-08 13:48:44 +05:30
matches = re.findall(r'<[aA].*href=["\']{0,1}(.*?)["\']', response)
2018-11-16 21:13:45 +05:30
for link in matches: # iterate over the matches
# remove everything after a "#" to deal with in-page anchors
link = link.split('#')[0]
2019-11-01 00:23:25 +05:30
if link.endswith(('.pdf', '.png', '.jpg', '.jpeg', '.xls', '.xml', '.docx', '.doc')):
pass
else:
2019-11-01 00:23:25 +05:30
if link[:4] == 'http':
if link.startswith(main_url):
storage.add(link)
elif link[:2] == '//':
if link.split('/')[2].startswith(host):
storage.add(schema + link)
elif link[:1] == '/':
storage.add(main_url + link)
else:
storage.add(main_url + '/' + link)
try:
for x in range(level):
urls = storage - processed # urls to crawl = all urls - urls that have been crawled
# for url in urls:
# rec(url)
threadpool = concurrent.futures.ThreadPoolExecutor(
max_workers=threadCount)
futures = (threadpool.submit(rec, url) for url in urls)
for i in concurrent.futures.as_completed(futures):
pass
except KeyboardInterrupt:
return [forms, processed]
2018-11-13 12:43:47 +05:30
return [forms, processed]