This method performs the effective search on Google providing the google dork and the Google session cookie
(dork)
| 38 | from thirdparty.socks import socks |
| 39 | |
| 40 | def _search(dork): |
| 41 | """ |
| 42 | This method performs the effective search on Google providing |
| 43 | the google dork and the Google session cookie |
| 44 | """ |
| 45 | |
| 46 | if not dork: |
| 47 | return None |
| 48 | |
| 49 | page = None |
| 50 | data = None |
| 51 | requestHeaders = {} |
| 52 | responseHeaders = {} |
| 53 | |
| 54 | requestHeaders[HTTP_HEADER.USER_AGENT] = dict(conf.httpHeaders).get(HTTP_HEADER.USER_AGENT, DUMMY_SEARCH_USER_AGENT) |
| 55 | requestHeaders[HTTP_HEADER.ACCEPT_ENCODING] = HTTP_ACCEPT_ENCODING_HEADER_VALUE |
| 56 | requestHeaders[HTTP_HEADER.COOKIE] = GOOGLE_CONSENT_COOKIE |
| 57 | |
| 58 | try: |
| 59 | req = _urllib.request.Request("https://www.google.com/ncr", headers=requestHeaders) |
| 60 | conn = _urllib.request.urlopen(req) |
| 61 | except Exception as ex: |
| 62 | errMsg = "unable to connect to Google ('%s')" % getSafeExString(ex) |
| 63 | raise SqlmapConnectionException(errMsg) |
| 64 | |
| 65 | gpage = conf.googlePage if conf.googlePage > 1 else 1 |
| 66 | logger.info("using search result page #%d" % gpage) |
| 67 | |
| 68 | url = "https://www.google.com/search?" # NOTE: if consent fails, try to use the "http://" |
| 69 | url += "q=%s&" % urlencode(dork, convall=True) |
| 70 | url += "num=100&hl=en&complete=0&safe=off&filter=0&btnG=Search" |
| 71 | url += "&start=%d" % ((gpage - 1) * 100) |
| 72 | |
| 73 | try: |
| 74 | req = _urllib.request.Request(url, headers=requestHeaders) |
| 75 | conn = _urllib.request.urlopen(req) |
| 76 | |
| 77 | requestMsg = "HTTP request:\nGET %s" % url |
| 78 | requestMsg += " %s" % _http_client.HTTPConnection._http_vsn_str |
| 79 | logger.log(CUSTOM_LOGGING.TRAFFIC_OUT, requestMsg) |
| 80 | |
| 81 | page = conn.read() |
| 82 | code = conn.code |
| 83 | status = conn.msg |
| 84 | responseHeaders = conn.info() |
| 85 | |
| 86 | responseMsg = "HTTP response (%s - %d):\n" % (status, code) |
| 87 | |
| 88 | if conf.verbose <= 4: |
| 89 | responseMsg += getUnicode(responseHeaders, UNICODE_ENCODING) |
| 90 | elif conf.verbose > 4: |
| 91 | responseMsg += "%s\n%s\n" % (responseHeaders, page) |
| 92 | |
| 93 | logger.log(CUSTOM_LOGGING.TRAFFIC_IN, responseMsg) |
| 94 | except _urllib.error.HTTPError as ex: |
| 95 | try: |
| 96 | page = ex.read() |
| 97 | responseHeaders = ex.info() |
no test coverage detected
searching dependent graphs…