Skip to content

Commit da21091

Browse files
committed
Update regarding the search engines naggings
1 parent 5e2a6ae commit da21091

3 files changed

Lines changed: 78 additions & 2 deletions

File tree

‎lib/core/settings.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty import six
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.10.10.15"
23+
VERSION = "1.10.10.16"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -216,6 +216,9 @@
216216
# Regular expression used for extracting results from Bing search
217217
BING_REGEX = r'<h2[^>]*><a [^>]*href="(?:https?://www\.bing\.com/ck/a\?[^"]*?[?;]u=a1([^&"]+)[^"]*|([^"]+))"'
218218

219+
# Markers of search engine abuse/captcha pages (i.e. used IP address got blocked)
220+
SEARCH_ABUSE_MARKERS = ("detected unusual traffic", "issue with the Tor Exit Node you are currently using", "anomaly.js", "Verifying your browser", "automated queries")
221+
219222
# Dummy user agent for search (if default one returns different results)
220223
DUMMY_SEARCH_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0"
221224

‎lib/utils/search.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from lib.core.settings import GOOGLE_CONSENT_COOKIE
3030
from lib.core.settings import GOOGLE_REGEX
3131
from lib.core.settings import HTTP_ACCEPT_ENCODING_HEADER_VALUE
32+
from lib.core.settings import SEARCH_ABUSE_MARKERS
3233
from lib.core.settings import UNICODE_ENCODING
3334
from lib.request.basic import decodePage
3435
from thirdparty.six.moves import http_client as _http_client
@@ -124,7 +125,7 @@ def _search(dork):
124125
break # Note: stop at the first engine that actually returns results (others are only fallbacks)
125126

126127
# Note: switch proxy (if available) when an abuse/captcha page was served (instead of pointlessly falling through to the next engine from the same blocked IP)
127-
if conf.proxyList and (("detected unusual traffic" in page) or ("issue with the Tor Exit Node you are currently using" in page)):
128+
if conf.proxyList and any(marker in page for marker in SEARCH_ABUSE_MARKERS):
128129
warnMsg = "%s has detected 'unusual' traffic from the used IP address" % name
129130
raise SqlmapBaseException(warnMsg)
130131

‎tests/test_dork_search.py‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
5+
See the file 'LICENSE' for copying permission
6+
7+
Unit tests for lib/utils/search.py (dork search), exercising the engine loop by
8+
MOCKING the network layer (_fetch).
9+
10+
No network is involved: _fetch is patched to return canned search engine result
11+
pages, so we can assert both on the links extracted per engine and on the
12+
abuse/captcha detection that triggers proxy rotation (SEARCH_ABUSE_MARKERS).
13+
"""
14+
15+
import os
16+
import sys
17+
import unittest
18+
19+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
20+
from _testutils import bootstrap
21+
22+
bootstrap()
23+
24+
from lib.core.data import conf
25+
from lib.core.exception import SqlmapBaseException
26+
from lib.core.settings import SEARCH_ABUSE_MARKERS
27+
import lib.utils.search as smod
28+
29+
BING_PAGE = '<h2><a target="_blank" href="https://www.bing.com/ck/a?!&amp;&amp;p=1&amp;u=a1aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vYS5waHA_aWQ9MQ&amp;ntb=1">a</a></h2>'
30+
DUCKDUCKGO_PAGE = '<a class="result__url" href="https://www.example.com/b.php?id=2">b</a>'
31+
32+
class TestDorkSearch(unittest.TestCase):
33+
def setUp(self):
34+
conf.googlePage = 1
35+
conf.proxyList = None
36+
self._fetch = smod._fetch
37+
38+
def tearDown(self):
39+
smod._fetch = self._fetch
40+
41+
def _pages(self, *pages):
42+
"""Patches _fetch to serve `pages` in engine order (None meaning no reply)"""
43+
44+
served = list(pages)
45+
smod._fetch = lambda *args, **kwargs: served.pop(0) if served else None
46+
47+
def test_duckduckgo_results(self):
48+
self._pages(DUCKDUCKGO_PAGE)
49+
self.assertEqual(smod._search("dork"), ["https://www.example.com/b.php?id=2"])
50+
51+
def test_bing_fallback_decodes_redirect(self):
52+
self._pages(None, BING_PAGE)
53+
self.assertEqual(smod._search("dork"), ["https://www.example.com/a.php?id=1"])
54+
55+
def test_abuse_page_switches_proxy(self):
56+
# Note: without '--proxy-list' there is nothing to switch to, hence no exception
57+
for marker in SEARCH_ABUSE_MARKERS:
58+
self._pages("<html>%s</html>" % marker)
59+
conf.proxyList = None
60+
self.assertEqual(smod._search("dork"), [])
61+
62+
self._pages("<html>%s</html>" % marker)
63+
conf.proxyList = ["http://127.0.0.1:8080"]
64+
self.assertRaises(SqlmapBaseException, smod._search, "dork")
65+
66+
def test_results_page_is_not_mistaken_for_abuse(self):
67+
self._pages(DUCKDUCKGO_PAGE)
68+
conf.proxyList = ["http://127.0.0.1:8080"]
69+
self.assertEqual(smod._search("dork"), ["https://www.example.com/b.php?id=2"])
70+
71+
if __name__ == "__main__":
72+
unittest.main()

0 commit comments

Comments
 (0)