同步操作将从 yeqingchen1/sqlmap 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python"""Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)See the file 'LICENSE' for copying permission"""from __future__ import divisionimport osimport reimport tempfileimport timefrom lib.core.common import checkSameHostfrom lib.core.common import clearConsoleLinefrom lib.core.common import dataToStdoutfrom lib.core.common import findPageFormsfrom lib.core.common import getSafeExStringfrom lib.core.common import openFilefrom lib.core.common import readInputfrom lib.core.common import safeCSValuefrom lib.core.common import urldecodefrom lib.core.compat import xrangefrom lib.core.convert import htmlUnescapefrom lib.core.data import conffrom lib.core.data import kbfrom lib.core.data import loggerfrom lib.core.datatype import OrderedSetfrom lib.core.enums import MKSTEMP_PREFIXfrom lib.core.exception import SqlmapConnectionExceptionfrom lib.core.exception import SqlmapSyntaxExceptionfrom lib.core.settings import CRAWL_EXCLUDE_EXTENSIONSfrom lib.core.threads import getCurrentThreadDatafrom lib.core.threads import runThreadsfrom lib.parse.sitemap import parseSitemapfrom lib.request.connect import Connect as Requestfrom thirdparty import sixfrom thirdparty.beautifulsoup.beautifulsoup import BeautifulSoupfrom thirdparty.six.moves import http_client as _http_clientfrom thirdparty.six.moves import urllib as _urllibdef crawl(target):try:visited = set()threadData = getCurrentThreadData()threadData.shared.value = OrderedSet()def crawlThread():threadData = getCurrentThreadData()while kb.threadContinue:with kb.locks.limit:if threadData.shared.unprocessed:current = threadData.shared.unprocessed.pop()if current in visited:continueelif conf.crawlExclude and re.search(conf.crawlExclude, current):dbgMsg = "skipping '%s'" % currentlogger.debug(dbgMsg)continueelse:visited.add(current)else:breakcontent = Nonetry:if current:content = Request.getPage(url=current, crawling=True, raise404=False)[0]except SqlmapConnectionException as ex:errMsg = "connection exception detected ('%s'). skipping " % getSafeExString(ex)errMsg += "URL '%s'" % currentlogger.critical(errMsg)except SqlmapSyntaxException:errMsg = "invalid URL detected. skipping '%s'" % currentlogger.critical(errMsg)except _http_client.InvalidURL as ex:errMsg = "invalid URL detected ('%s'). skipping " % getSafeExString(ex)errMsg += "URL '%s'" % currentlogger.critical(errMsg)if not kb.threadContinue:breakif isinstance(content, six.text_type):try:match = re.search(r"(?si)<html[^>]*>(.+)</html>", content)if match:content = "<html>%s</html>" % match.group(1)soup = BeautifulSoup(content)tags = soup('a')tags += re.finditer(r'(?i)<a[^>]+href=["\'](?P<href>[^>"\']+)', content)for tag in tags:href = tag.get("href") if hasattr(tag, "get") else tag.group("href")if href:if threadData.lastRedirectURL and threadData.lastRedirectURL[0] == threadData.lastRequestUID:current = threadData.lastRedirectURL[1]url = _urllib.parse.urljoin(current, htmlUnescape(href))# flag to know if we are dealing with the same target host_ = checkSameHost(url, target)if conf.scope:if not re.search(conf.scope, url, re.I):continueelif not _:continueif url.split('.')[-1].lower() not in CRAWL_EXCLUDE_EXTENSIONS:with kb.locks.value:threadData.shared.deeper.add(url)if re.search(r"(.*?)\?(.+)", url):threadData.shared.value.add(url)except UnicodeEncodeError: # for non-HTML filespassexcept ValueError: # for non-valid linkspassfinally:if conf.forms:findPageForms(content, current, False, True)if conf.verbose in (1, 2):threadData.shared.count += 1status = '%d/%d links visited (%d%%)' % (threadData.shared.count, threadData.shared.length, round(100.0 * threadData.shared.count / threadData.shared.length))dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%X"), status), True)threadData.shared.deeper = set()threadData.shared.unprocessed = set([target])if not conf.sitemapUrl:message = "do you want to check for the existence of "message += "site's sitemap(.xml) [y/N] "if readInput(message, default='N', boolean=True):found = Trueitems = Noneurl = _urllib.parse.urljoin(target, "/sitemap.xml")try:items = parseSitemap(url)except SqlmapConnectionException as ex:if "page not found" in getSafeExString(ex):found = Falselogger.warn("'sitemap.xml' not found")except:passfinally:if found:if items:for item in items:if re.search(r"(.*?)\?(.+)", item):threadData.shared.value.add(item)if conf.crawlDepth > 1:threadData.shared.unprocessed.update(items)logger.info("%s links found" % ("no" if not items else len(items)))infoMsg = "starting crawler"if conf.bulkFile:infoMsg += " for target URL '%s'" % targetlogger.info(infoMsg)for i in xrange(conf.crawlDepth):threadData.shared.count = 0threadData.shared.length = len(threadData.shared.unprocessed)numThreads = min(conf.threads, len(threadData.shared.unprocessed))if not conf.bulkFile:logger.info("searching for links with depth %d" % (i + 1))runThreads(numThreads, crawlThread, threadChoice=(i > 0))clearConsoleLine(True)if threadData.shared.deeper:threadData.shared.unprocessed = set(threadData.shared.deeper)else:breakexcept KeyboardInterrupt:warnMsg = "user aborted during crawling. sqlmap "warnMsg += "will use partial list"logger.warn(warnMsg)finally:clearConsoleLine(True)if not threadData.shared.value:warnMsg = "no usable links found (with GET parameters)"logger.warn(warnMsg)else:for url in threadData.shared.value:kb.targets.add((urldecode(url, kb.pageEncoding), None, None, None, None))storeResultsToFile(kb.targets)def storeResultsToFile(results):if not results:returnif kb.storeCrawlingChoice is None:message = "do you want to store crawling results to a temporary file "message += "for eventual further processing with other tools [y/N] "kb.storeCrawlingChoice = readInput(message, default='N', boolean=True)if kb.storeCrawlingChoice:handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.CRAWLER, suffix=".csv" if conf.forms else ".txt")os.close(handle)infoMsg = "writing crawling results to a temporary file '%s' " % filenamelogger.info(infoMsg)with openFile(filename, "w+b") as f:if conf.forms:f.write("URL,POST\n")for url, _, data, _, _ in results:if conf.forms:f.write("%s,%s\n" % (safeCSValue(url), safeCSValue(data or "")))else:f.write("%s\n" % url)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。