|
13 | 13 | import urllib2 |
14 | 14 |
|
15 | 15 | from lib.core.common import getUnicode |
| 16 | +from lib.core.common import readInput |
16 | 17 | from lib.core.common import urlencode |
17 | 18 | from lib.core.data import conf |
18 | 19 | from lib.core.data import logger |
19 | 20 | from lib.core.enums import CUSTOM_LOGGING |
| 21 | +from lib.core.enums import HTTP_HEADER |
20 | 22 | from lib.core.exception import SqlmapConnectionException |
21 | 23 | from lib.core.exception import SqlmapGenericException |
22 | 24 | from lib.core.settings import GOOGLE_REGEX |
| 25 | +from lib.core.settings import DUCKDUCKGO_REGEX |
23 | 26 | from lib.core.settings import UNICODE_ENCODING |
24 | 27 | from lib.request.basic import decodePage |
25 | 28 |
|
@@ -103,4 +106,52 @@ def search(self, dork): |
103 | 106 | warnMsg += "used IP address disabling further searches" |
104 | 107 | raise SqlmapGenericException(warnMsg) |
105 | 108 |
|
| 109 | + if not retVal: |
| 110 | + message = "no usable links found. " |
| 111 | + message += "do you want to (re)try with DuckDuckGo? [Y/n] " |
| 112 | + output = readInput(message, default="Y") |
| 113 | + |
| 114 | + if output.strip().lower() != 'n': |
| 115 | + url = "https://duckduckgo.com/d.js?" |
| 116 | + url += "q=%s&p=%d&s=100" % (urlencode(dork, convall=True), gpage) |
| 117 | + |
| 118 | + if not conf.randomAgent: |
| 119 | + conf.opener.addheaders = [_ for _ in conf.opener.addheaders if _[0].lower() != HTTP_HEADER.USER_AGENT.lower()] |
| 120 | + conf.opener.addheaders.append((HTTP_HEADER.USER_AGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0")) |
| 121 | + |
| 122 | + try: |
| 123 | + conn = self.opener.open(url) |
| 124 | + |
| 125 | + requestMsg = "HTTP request:\nGET %s" % url |
| 126 | + requestMsg += " %s" % httplib.HTTPConnection._http_vsn_str |
| 127 | + logger.log(CUSTOM_LOGGING.TRAFFIC_OUT, requestMsg) |
| 128 | + |
| 129 | + page = conn.read() |
| 130 | + code = conn.code |
| 131 | + status = conn.msg |
| 132 | + responseHeaders = conn.info() |
| 133 | + page = decodePage(page, responseHeaders.get("Content-Encoding"), responseHeaders.get("Content-Type")) |
| 134 | + |
| 135 | + responseMsg = "HTTP response (%s - %d):\n" % (status, code) |
| 136 | + |
| 137 | + if conf.verbose <= 4: |
| 138 | + responseMsg += getUnicode(responseHeaders, UNICODE_ENCODING) |
| 139 | + elif conf.verbose > 4: |
| 140 | + responseMsg += "%s\n%s\n" % (responseHeaders, page) |
| 141 | + |
| 142 | + logger.log(CUSTOM_LOGGING.TRAFFIC_IN, responseMsg) |
| 143 | + except urllib2.HTTPError, e: |
| 144 | + try: |
| 145 | + page = e.read() |
| 146 | + except socket.timeout: |
| 147 | + warnMsg = "connection timed out while trying " |
| 148 | + warnMsg += "to get error page information (%d)" % e.code |
| 149 | + logger.critical(warnMsg) |
| 150 | + return None |
| 151 | + except (urllib2.URLError, socket.error, socket.timeout): |
| 152 | + errMsg = "unable to connect to DuckDuckGo" |
| 153 | + raise SqlmapConnectionException(errMsg) |
| 154 | + |
| 155 | + retVal = [urllib.unquote(match.group(1)) for match in re.finditer(DUCKDUCKGO_REGEX, page, re.I | re.S)] |
| 156 | + |
106 | 157 | return retVal |
0 commit comments