同步操作将从 yeqingchen1/sqlmap 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python"""Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)See the file 'LICENSE' for copying permission"""import codecsimport gzipimport ioimport loggingimport reimport structimport zlibfrom lib.core.common import Backendfrom lib.core.common import extractErrorMessagefrom lib.core.common import extractRegexResultfrom lib.core.common import filterNonefrom lib.core.common import getPublicTypeMembersfrom lib.core.common import getSafeExStringfrom lib.core.common import isListLikefrom lib.core.common import randomStrfrom lib.core.common import readInputfrom lib.core.common import resetCookieJarfrom lib.core.common import singleTimeLogMessagefrom lib.core.common import singleTimeWarnMessagefrom lib.core.common import unArrayizeValuefrom lib.core.convert import decodeHexfrom lib.core.convert import getBytesfrom lib.core.convert import getTextfrom lib.core.convert import getUnicodefrom lib.core.data import conffrom lib.core.data import kbfrom lib.core.data import loggerfrom lib.core.decorators import cachedmethodfrom lib.core.dicts import HTML_ENTITIESfrom lib.core.enums import DBMSfrom lib.core.enums import HTTP_HEADERfrom lib.core.enums import PLACEfrom lib.core.exception import SqlmapCompressionExceptionfrom lib.core.settings import BLOCKED_IP_REGEXfrom lib.core.settings import DEFAULT_COOKIE_DELIMITERfrom lib.core.settings import EVENTVALIDATION_REGEXfrom lib.core.settings import IDENTYWAF_PARSE_LIMITfrom lib.core.settings import MAX_CONNECTION_TOTAL_SIZEfrom lib.core.settings import META_CHARSET_REGEXfrom lib.core.settings import PARSE_HEADERS_LIMITfrom lib.core.settings import SELECT_FROM_TABLE_REGEXfrom lib.core.settings import VIEWSTATE_REGEXfrom lib.parse.headers import headersParserfrom lib.parse.html import htmlParserfrom thirdparty import sixfrom thirdparty.chardet import detectfrom thirdparty.identywaf import identYwaffrom thirdparty.odict import OrderedDictfrom thirdparty.six import unichr as _unichrfrom thirdparty.six.moves import http_client as _http_clientdef forgeHeaders(items=None, base=None):"""Prepare HTTP Cookie, HTTP User-Agent and HTTP Referer headers to use when performingthe HTTP requests"""items = items or {}for _ in list(items.keys()):if items[_] is None:del items[_]headers = OrderedDict(conf.httpHeaders if base is None else base)headers.update(items.items())class _str(str):def capitalize(self):return _str(self)def title(self):return _str(self)_ = headersheaders = OrderedDict()for key, value in _.items():success = Falsefor _ in headers:if _.upper() == key.upper():del headers[_]breakif key.upper() not in (_.upper() for _ in getPublicTypeMembers(HTTP_HEADER, True)):try:headers[_str(key)] = value # dirty hack for http://bugs.python.org/issue12455except UnicodeEncodeError: # don't do the hack on non-ASCII header names (they have to be properly encoded later on)passelse:success = Trueif not success:key = '-'.join(_.capitalize() for _ in key.split('-'))headers[key] = valueif conf.cj:if HTTP_HEADER.COOKIE in headers:for cookie in conf.cj:if cookie.domain_specified and not (conf.hostname or "").endswith(cookie.domain):continueif ("%s=" % getUnicode(cookie.name)) in getUnicode(headers[HTTP_HEADER.COOKIE]):if conf.loadCookies:conf.httpHeaders = filterNone((item if item[0] != HTTP_HEADER.COOKIE else None) for item in conf.httpHeaders)elif kb.mergeCookies is None:message = "you provided a HTTP %s header value. " % HTTP_HEADER.COOKIEmessage += "The target URL provided its own cookies within "message += "the HTTP %s header which intersect with yours. " % HTTP_HEADER.SET_COOKIEmessage += "Do you want to merge them in further requests? [Y/n] "kb.mergeCookies = readInput(message, default='Y', boolean=True)if kb.mergeCookies and kb.injection.place != PLACE.COOKIE:def _(value):return re.sub(r"(?i)\b%s=[^%s]+" % (re.escape(getUnicode(cookie.name)), conf.cookieDel or DEFAULT_COOKIE_DELIMITER), ("%s=%s" % (getUnicode(cookie.name), getUnicode(cookie.value))).replace('\\', r'\\'), value)headers[HTTP_HEADER.COOKIE] = _(headers[HTTP_HEADER.COOKIE])if PLACE.COOKIE in conf.parameters:conf.parameters[PLACE.COOKIE] = _(conf.parameters[PLACE.COOKIE])conf.httpHeaders = [(item[0], item[1] if item[0] != HTTP_HEADER.COOKIE else _(item[1])) for item in conf.httpHeaders]elif not kb.testMode:headers[HTTP_HEADER.COOKIE] += "%s %s=%s" % (conf.cookieDel or DEFAULT_COOKIE_DELIMITER, getUnicode(cookie.name), getUnicode(cookie.value))if kb.testMode and not any((conf.csrfToken, conf.safeUrl)):resetCookieJar(conf.cj)return headersdef parseResponse(page, headers, status=None):"""@param page: the page to parse to feed the knowledge base htmlFp(back-end DBMS fingerprint based upon DBMS error messages returnthrough the web application) list and absFilePaths (absolute filepaths) set."""if headers:headersParser(headers)if page:htmlParser(page if not status else "%s\n\n%s" % (status, page))@cachedmethoddef checkCharEncoding(encoding, warn=True):"""Checks encoding name, repairs common misspellings and adjusts toproper namings used in codecs module>>> checkCharEncoding('iso-8858', False)'iso8859-1'>>> checkCharEncoding('en_us', False)'utf8'"""if isinstance(encoding, six.binary_type):encoding = getUnicode(encoding)if isListLike(encoding):encoding = unArrayizeValue(encoding)if encoding:encoding = encoding.lower()else:return encoding# Reference: http://www.destructor.de/charsets/index.htmtranslate = {"windows-874": "iso-8859-11", "utf-8859-1": "utf8", "en_us": "utf8", "macintosh": "iso-8859-1", "euc_tw": "big5_tw", "th": "tis-620", "unicode": "utf8", "utc8": "utf8", "ebcdic": "ebcdic-cp-be", "iso-8859": "iso8859-1", "iso-8859-0": "iso8859-1", "ansi": "ascii", "gbk2312": "gbk", "windows-31j": "cp932", "en": "us"}for delimiter in (';', ',', '('):if delimiter in encoding:encoding = encoding[:encoding.find(delimiter)].strip()encoding = encoding.replace(""", "")# popular typos/errorsif "8858" in encoding:encoding = encoding.replace("8858", "8859") # iso-8858 -> iso-8859elif "8559" in encoding:encoding = encoding.replace("8559", "8859") # iso-8559 -> iso-8859elif "8895" in encoding:encoding = encoding.replace("8895", "8859") # iso-8895 -> iso-8859elif "5889" in encoding:encoding = encoding.replace("5889", "8859") # iso-5889 -> iso-8859elif "5589" in encoding:encoding = encoding.replace("5589", "8859") # iso-5589 -> iso-8859elif "2313" in encoding:encoding = encoding.replace("2313", "2312") # gb2313 -> gb2312elif encoding.startswith("x-"):encoding = encoding[len("x-"):] # x-euc-kr -> euc-kr / x-mac-turkish -> mac-turkishelif "windows-cp" in encoding:encoding = encoding.replace("windows-cp", "windows") # windows-cp-1254 -> windows-1254# name adjustment for compatibilityif encoding.startswith("8859"):encoding = "iso-%s" % encodingelif encoding.startswith("cp-"):encoding = "cp%s" % encoding[3:]elif encoding.startswith("euc-"):encoding = "euc_%s" % encoding[4:]elif encoding.startswith("windows") and not encoding.startswith("windows-"):encoding = "windows-%s" % encoding[7:]elif encoding.find("iso-88") > 0:encoding = encoding[encoding.find("iso-88"):]elif encoding.startswith("is0-"):encoding = "iso%s" % encoding[4:]elif encoding.find("ascii") > 0:encoding = "ascii"elif encoding.find("utf8") > 0:encoding = "utf8"elif encoding.find("utf-8") > 0:encoding = "utf-8"# Reference: http://philip.html5.org/data/charsets-2.htmlif encoding in translate:encoding = translate[encoding]elif encoding in ("null", "{charset}", "charset", "*") or not re.search(r"\w", encoding):return None# Reference: http://www.iana.org/assignments/character-sets# Reference: http://docs.python.org/library/codecs.htmltry:codecs.lookup(encoding)except:encoding = Noneif encoding:try:six.text_type(getBytes(randomStr()), encoding)except:if warn:warnMsg = "invalid web page charset '%s'" % encodingsingleTimeLogMessage(warnMsg, logging.WARN, encoding)encoding = Nonereturn encodingdef getHeuristicCharEncoding(page):"""Returns page encoding charset detected by usage of heuristicsReference: https://chardet.readthedocs.io/en/latest/usage.html>>> getHeuristicCharEncoding(b"<html></html>")'ascii'"""key = hash(page)retVal = kb.cache.encoding.get(key) or detect(page)["encoding"]kb.cache.encoding[key] = retValif retVal:infoMsg = "heuristics detected web page charset '%s'" % retValsingleTimeLogMessage(infoMsg, logging.INFO, retVal)return retValdef decodePage(page, contentEncoding, contentType):"""Decode compressed/charset HTTP response>>> getText(decodePage(b"<html>foo&bar</html>", None, "text/html; charset=utf-8"))'<html>foo&bar</html>'"""if not page or (conf.nullConnection and len(page) < 2):return getUnicode(page)if hasattr(contentEncoding, "lower"):contentEncoding = contentEncoding.lower()else:contentEncoding = ""if hasattr(contentType, "lower"):contentType = contentType.lower()else:contentType = ""if contentEncoding in ("gzip", "x-gzip", "deflate"):if not kb.pageCompress:return Nonetry:if contentEncoding == "deflate":data = io.BytesIO(zlib.decompress(page, -15)) # Reference: http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementationselse:data = gzip.GzipFile("", "rb", 9, io.BytesIO(page))size = struct.unpack("<l", page[-4:])[0] # Reference: http://pydoc.org/get.cgi/usr/local/lib/python2.5/gzip.pyif size > MAX_CONNECTION_TOTAL_SIZE:raise Exception("size too large")page = data.read()except Exception as ex:if "<html" not in page: # in some cases, invalid "Content-Encoding" appears for plain HTML (should be ignored)errMsg = "detected invalid data for declared content "errMsg += "encoding '%s' ('%s')" % (contentEncoding, getSafeExString(ex))singleTimeLogMessage(errMsg, logging.ERROR)warnMsg = "turning off page compression"singleTimeWarnMessage(warnMsg)kb.pageCompress = Falseraise SqlmapCompressionExceptionif not conf.encoding:httpCharset, metaCharset = None, None# Reference: http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicodeif contentType.find("charset=") != -1:httpCharset = checkCharEncoding(contentType.split("charset=")[-1])metaCharset = checkCharEncoding(extractRegexResult(META_CHARSET_REGEX, page))if (any((httpCharset, metaCharset)) and not all((httpCharset, metaCharset))) or (httpCharset == metaCharset and all((httpCharset, metaCharset))):kb.pageEncoding = httpCharset or metaCharset # Reference: http://bytes.com/topic/html-css/answers/154758-http-equiv-vs-true-header-has-precedencedebugMsg = "declared web page charset '%s'" % kb.pageEncodingsingleTimeLogMessage(debugMsg, logging.DEBUG, debugMsg)else:kb.pageEncoding = Noneelse:kb.pageEncoding = conf.encoding# can't do for all responses because we need to support binary files tooif isinstance(page, six.binary_type) and "text/" in contentType:# e.g. 	Ãëàâàif b"&#" in page:page = re.sub(b"&#x([0-9a-f]{1,2});", lambda _: decodeHex(_.group(1) if len(_.group(1)) == 2 else "0%s" % _.group(1)), page)page = re.sub(b"&#(\\d{1,3});", lambda _: six.int2byte(int(_.group(1))) if int(_.group(1)) < 256 else _.group(0), page)# e.g. %20%28%29if b"%" in page:page = re.sub(b"%([0-9a-fA-F]{2})", lambda _: decodeHex(_.group(1)), page)# e.g. &page = re.sub(b"&([^;]+);", lambda _: six.int2byte(HTML_ENTITIES[getText(_.group(1))]) if HTML_ENTITIES.get(getText(_.group(1)), 256) < 256 else _.group(0), page)kb.pageEncoding = kb.pageEncoding or checkCharEncoding(getHeuristicCharEncoding(page))if (kb.pageEncoding or "").lower() == "utf-8-sig":kb.pageEncoding = "utf-8"if page and page.startswith("\xef\xbb\xbf"): # Reference: https://docs.python.org/2/library/codecs.html (Note: noticed problems when "utf-8-sig" is left to Python for handling)page = page[3:]page = getUnicode(page, kb.pageEncoding)# e.g. ’…™if "&#" in page:def _(match):retVal = match.group(0)try:retVal = _unichr(int(match.group(1)))except (ValueError, OverflowError):passreturn retValpage = re.sub(r"&#(\d+);", _, page)# e.g. ζpage = re.sub(r"&([^;]+);", lambda _: _unichr(HTML_ENTITIES[_.group(1)]) if HTML_ENTITIES.get(_.group(1), 0) > 255 else _.group(0), page)return pagedef processResponse(page, responseHeaders, code=None, status=None):kb.processResponseCounter += 1page = page or ""parseResponse(page, responseHeaders if kb.processResponseCounter < PARSE_HEADERS_LIMIT else None, status)if not kb.tableFrom and Backend.getIdentifiedDbms() in (DBMS.ACCESS,):kb.tableFrom = extractRegexResult(SELECT_FROM_TABLE_REGEX, page)else:kb.tableFrom = Noneif conf.parseErrors:msg = extractErrorMessage(page)if msg:logger.warning("parsed DBMS error message: '%s'" % msg.rstrip('.'))if kb.processResponseCounter < IDENTYWAF_PARSE_LIMIT:rawResponse = "%s %s %s\n%s\n%s" % (_http_client.HTTPConnection._http_vsn_str, code or "", status or "", getUnicode("".join(responseHeaders.headers if responseHeaders else [])), page)identYwaf.non_blind.clear()if identYwaf.non_blind_check(rawResponse, silent=True):for waf in identYwaf.non_blind:if waf not in kb.identifiedWafs:kb.identifiedWafs.add(waf)errMsg = "WAF/IPS identified as '%s'" % identYwaf.format_name(waf)singleTimeLogMessage(errMsg, logging.CRITICAL)if kb.originalPage is None:for regex in (EVENTVALIDATION_REGEX, VIEWSTATE_REGEX):match = re.search(regex, page)if match and PLACE.POST in conf.parameters:name, value = match.groups()if PLACE.POST in conf.paramDict and name in conf.paramDict[PLACE.POST]:if conf.paramDict[PLACE.POST][name] in page:continueelse:msg = "do you want to automatically adjust the value of '%s'? [y/N]" % nameif not readInput(msg, default='N', boolean=True):continueconf.paramDict[PLACE.POST][name] = valueconf.parameters[PLACE.POST] = re.sub(r"(?i)(%s=)[^&]+" % re.escape(name), r"\g<1>%s" % value.replace('\\', r'\\'), conf.parameters[PLACE.POST])if not kb.browserVerification and re.search(r"(?i)browser.?verification", page or ""):kb.browserVerification = TruewarnMsg = "potential browser verification protection mechanism detected"if re.search(r"(?i)CloudFlare", page):warnMsg += " (CloudFlare)"singleTimeWarnMessage(warnMsg)if not kb.captchaDetected and re.search(r"(?i)captcha", page or ""):for match in re.finditer(r"(?si)<form.+?</form>", page):if re.search(r"(?i)captcha", match.group(0)):kb.captchaDetected = TruewarnMsg = "potential CAPTCHA protection mechanism detected"if re.search(r"(?i)<title>[^<]*CloudFlare", page):warnMsg += " (CloudFlare)"singleTimeWarnMessage(warnMsg)breakif re.search(BLOCKED_IP_REGEX, page):warnMsg = "it appears that you have been blocked by the target server"singleTimeWarnMessage(warnMsg)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。