2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2014-07-03 02:29:20 +04:00
|
|
|
|
|
|
|
"""
|
2022-01-03 13:30:34 +03:00
|
|
|
Copyright (c) 2006-2022 sqlmap developers (https://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2014-07-03 02:29:20 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from lib.core.common import readInput
|
|
|
|
from lib.core.data import kb
|
|
|
|
from lib.core.data import logger
|
2019-03-27 17:48:51 +03:00
|
|
|
from lib.core.datatype import OrderedSet
|
2014-11-01 19:13:33 +03:00
|
|
|
from lib.core.exception import SqlmapSyntaxException
|
2014-07-03 02:29:20 +04:00
|
|
|
from lib.request.connect import Connect as Request
|
2019-03-27 15:33:46 +03:00
|
|
|
from thirdparty.six.moves import http_client as _http_client
|
2014-07-03 02:29:20 +04:00
|
|
|
|
|
|
|
abortedFlag = None
|
|
|
|
|
|
|
|
def parseSitemap(url, retVal=None):
|
|
|
|
global abortedFlag
|
|
|
|
|
|
|
|
if retVal is not None:
|
|
|
|
logger.debug("parsing sitemap '%s'" % url)
|
|
|
|
|
|
|
|
try:
|
|
|
|
if retVal is None:
|
|
|
|
abortedFlag = False
|
2019-03-27 17:48:51 +03:00
|
|
|
retVal = OrderedSet()
|
2014-07-03 02:29:20 +04:00
|
|
|
|
2014-11-01 19:13:33 +03:00
|
|
|
try:
|
|
|
|
content = Request.getPage(url=url, raise404=True)[0] if not abortedFlag else ""
|
2019-03-27 15:33:46 +03:00
|
|
|
except _http_client.InvalidURL:
|
2014-11-01 19:13:33 +03:00
|
|
|
errMsg = "invalid URL given for sitemap ('%s')" % url
|
2018-03-13 13:13:38 +03:00
|
|
|
raise SqlmapSyntaxException(errMsg)
|
2014-11-01 19:13:33 +03:00
|
|
|
|
|
|
|
for match in re.finditer(r"<loc>\s*([^<]+)", content or ""):
|
2014-07-03 02:29:20 +04:00
|
|
|
if abortedFlag:
|
|
|
|
break
|
|
|
|
url = match.group(1).strip()
|
|
|
|
if url.endswith(".xml") and "sitemap" in url.lower():
|
|
|
|
if kb.followSitemapRecursion is None:
|
|
|
|
message = "sitemap recursion detected. Do you want to follow? [y/N] "
|
2017-04-18 16:48:05 +03:00
|
|
|
kb.followSitemapRecursion = readInput(message, default='N', boolean=True)
|
2014-07-03 02:29:20 +04:00
|
|
|
if kb.followSitemapRecursion:
|
|
|
|
parseSitemap(url, retVal)
|
|
|
|
else:
|
|
|
|
retVal.add(url)
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
abortedFlag = True
|
|
|
|
warnMsg = "user aborted during sitemap parsing. sqlmap "
|
|
|
|
warnMsg += "will use partial list"
|
2022-06-22 13:04:34 +03:00
|
|
|
logger.warning(warnMsg)
|
2014-07-03 02:29:20 +04:00
|
|
|
|
|
|
|
return retVal
|