Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdd1e49

Browse files
committed
Dealing with Github issue creation (default UA blacklisted)
1 parent 0c005c4 commit fdd1e49

4 files changed

Lines changed: 32 additions & 52 deletions

File tree

lib/core/common.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,6 +3497,28 @@ def getLatestRevision():
34973497

34983498
return retVal
34993499

3500+
def fetchRandomAgent():
3501+
"""
3502+
Returns random HTTP User-Agent header value
3503+
3504+
>>> '(' in fetchRandomAgent()
3505+
True
3506+
"""
3507+
3508+
if not kb.userAgents:
3509+
debugMsg = "loading random HTTP User-Agent header(s) from "
3510+
debugMsg += "file '%s'" % paths.USER_AGENTS
3511+
logger.debug(debugMsg)
3512+
3513+
try:
3514+
kb.userAgents = getFileItems(paths.USER_AGENTS)
3515+
except IOError:
3516+
errMsg = "unable to read HTTP User-Agent header "
3517+
errMsg += "file '%s'" % paths.USER_AGENTS
3518+
raise SqlmapSystemException(errMsg)
3519+
3520+
return random.sample(kb.userAgents, 1)[0]
3521+
35003522
def createGithubIssue(errMsg, excMsg):
35013523
"""
35023524
Automatically create a Github issue with unhandled exception information
@@ -3550,9 +3572,9 @@ def createGithubIssue(errMsg, excMsg):
35503572
except:
35513573
pass
35523574

3553-
userAgent = "curl/7.{curl_minor}.{curl_revision} (x86_64-pc-linux-gnu) libcurl/7.{curl_minor}.{curl_revision} OpenSSL/0.9.8{openssl_revision} zlib/1.2.{zlib_revision}".format(curl_minor=random.randint(8, 22), curl_revision=random.randint(1, 9), openssl_revision=random.choice(string.ascii_lowercase), zlib_revision=random.randint(2, 6))
3575+
35543576
data = {"title": "Unhandled exception (#%s)" % key, "body": "```%s\n```\n```\n%s```" % (errMsg, excMsg)}
3555-
req = _urllib.request.Request(url="https://api.github.com/repos/sqlmapproject/sqlmap/issues", data=getBytes(json.dumps(data)), headers={HTTP_HEADER.AUTHORIZATION: "token %s" % decodeBase64(GITHUB_REPORT_OAUTH_TOKEN, binary=False), HTTP_HEADER.USER_AGENT: userAgent})
3577+
req = _urllib.request.Request(url="https://api.github.com/repos/sqlmapproject/sqlmap/issues", data=getBytes(json.dumps(data)), headers={HTTP_HEADER.AUTHORIZATION: "token %s" % decodeBase64(GITHUB_REPORT_OAUTH_TOKEN, binary=False), HTTP_HEADER.USER_AGENT: fetchRandomAgent()})
35563578

35573579
try:
35583580
content = _urllib.request.urlopen(req).read()

lib/core/option.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from lib.core.common import decodeStringEscape
2626
from lib.core.common import getPublicTypeMembers
2727
from lib.core.common import getSafeExString
28+
from lib.core.common import fetchRandomAgent
2829
from lib.core.common import filterNone
2930
from lib.core.common import findLocalPort
3031
from lib.core.common import findPageForms
@@ -137,7 +138,6 @@
137138
from lib.request.pkihandler import HTTPSPKIAuthHandler
138139
from lib.request.rangehandler import HTTPRangeHandler
139140
from lib.request.redirecthandler import SmartRedirectHandler
140-
from lib.request.templates import getPageTemplate
141141
from lib.utils.har import HTTPCollectorFactory
142142
from lib.utils.crawler import crawl
143143
from lib.utils.deps import checkDependencies
@@ -1400,22 +1400,7 @@ def _setHTTPUserAgent():
14001400
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, DEFAULT_USER_AGENT))
14011401

14021402
else:
1403-
if not kb.userAgents:
1404-
debugMsg = "loading random HTTP User-Agent header(s) from "
1405-
debugMsg += "file '%s'" % paths.USER_AGENTS
1406-
logger.debug(debugMsg)
1407-
1408-
try:
1409-
kb.userAgents = getFileItems(paths.USER_AGENTS)
1410-
except IOError:
1411-
warnMsg = "unable to read HTTP User-Agent header "
1412-
warnMsg += "file '%s'" % paths.USER_AGENTS
1413-
logger.warn(warnMsg)
1414-
1415-
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, DEFAULT_USER_AGENT))
1416-
return
1417-
1418-
userAgent = random.sample(kb.userAgents or [DEFAULT_USER_AGENT], 1)[0]
1403+
userAgent = fetchRandomAgent()
14191404

14201405
infoMsg = "fetched random HTTP User-Agent header value '%s' from " % userAgent
14211406
infoMsg += "file '%s'" % paths.USER_AGENTS

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty import six
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.3.5.24"
21+
VERSION = "1.3.5.25"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

txt/user-agents.txt

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ Opera/9.20 (X11; Linux i686; U; es-es)
285285
Opera/9.20 (X11; Linux i686; U; pl)
286286
Opera/9.20 (X11; Linux i686; U; ru)
287287
Opera/9.20 (X11; Linux i686; U; tr)
288-
Opera/9.20 (X11; Linux ppc; U; en)
289288
Opera/9.20 (X11; Linux x86_64; U; en)
290289
Opera/9.21 (Macintosh; Intel Mac OS X; U; en)
291290
Opera/9.21 (Macintosh; PPC Mac OS X; U; en)
@@ -364,8 +363,8 @@ Opera/9.27 (Windows NT 5.1; U; ja)
364363
Opera/9.27 (Windows NT 5.2; U; en)
365364
Opera/9.27 (X11; Linux i686; U; en)
366365
Opera/9.27 (X11; Linux i686; U; fr)
367-
Opera 9.4 (Windows NT 5.3; U; en)
368-
Opera 9.4 (Windows NT 6.1; U; en)
366+
Opera/9.4 (Windows NT 5.3; U; en)
367+
Opera/9.4 (Windows NT 6.1; U; en)
369368
Opera/9.50 (Macintosh; Intel Mac OS X; U; de)
370369
Opera/9.50 (Macintosh; Intel Mac OS X; U; en)
371370
Opera/9.50 (Windows NT 5.1; U; es-ES)
@@ -375,7 +374,6 @@ Opera/9.50 (Windows NT 5.1; U; nn)
375374
Opera/9.50 (Windows NT 5.1; U; ru)
376375
Opera/9.50 (Windows NT 5.2; U; it)
377376
Opera/9.50 (X11; Linux i686; U; es-ES)
378-
Opera/9.50 (X11; Linux ppc; U; en)
379377
Opera/9.50 (X11; Linux x86_64; U; nb)
380378
Opera/9.50 (X11; Linux x86_64; U; pl)
381379
Opera/9.51 (Macintosh; Intel Mac OS X; U; en)
@@ -406,7 +404,6 @@ Opera/9.52 (Windows NT 6.0; U; Opera/9.52 (X11; Linux x86_64; U); en)
406404
Opera/9.52 (X11; Linux i686; U; cs)
407405
Opera/9.52 (X11; Linux i686; U; en)
408406
Opera/9.52 (X11; Linux i686; U; fr)
409-
Opera/9.52 (X11; Linux ppc; U; de)
410407
Opera/9.52 (X11; Linux x86_64; U)
411408
Opera/9.52 (X11; Linux x86_64; U; en)
412409
Opera/9.52 (X11; Linux x86_64; U; ru)
@@ -616,7 +613,6 @@ Opera/12.80 (Windows NT 5.1; U; en) Presto/2.10.289 Version/12.02
616613

617614
# Mozilla Firefox
618615

619-
mozilla/3.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/5.0.1
620616
Mozilla/4.0 (compatible; Intel Mac OS X 10.6; rv:2.0b8) Gecko/20100101 Firefox/4.0b8)
621617
Mozilla/4.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.2) Gecko/2010324480 Firefox/3.5.4
622618
Mozilla/4.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.7) Gecko/2008398325 Firefox/3.1.4
@@ -1125,7 +1121,7 @@ Mozilla/5.0 (Windows; U; Windows NT 5.2; nl; rv:1.9b5) Gecko/2008032620 Firefox/
11251121
Mozilla/5.0 (Windows; U; Windows NT 5.2; ru; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11
11261122
Mozilla/5.0 (Windows; U; Windows NT 5.2; rv:1.7.3) Gecko/20041001 Firefox/0.10.1
11271123
Mozilla/5.0 (Windows; U; Windows NT 5.2; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11
1128-
Mozilla/5.0(Windows; U; Windows NT 5.2; rv:1.9.2) Gecko/20100101 Firefox/3.6
1124+
Mozilla/5.0 (Windows; U; Windows NT 5.2; rv:1.9.2) Gecko/20100101 Firefox/3.6
11291125
Mozilla/5.0 (Windows; U; Windows NT 5.2; sk; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15
11301126
Mozilla/5.0 (Windows; U; Windows NT 5.2 x64; en-US; rv:1.9a1) Gecko/20060214 Firefox/1.6a1
11311127
Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-CN; rv:1.9.1.5) Gecko/Firefox/3.5.5
@@ -1355,7 +1351,7 @@ Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.14) Gecko/20110218 Fire
13551351
Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
13561352
Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
13571353
Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-TW; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4 (.NET CLR 3.5.30729)
1358-
Mozilla/5.0(Windows; U; Windows NT 7.0; rv:1.9.2) Gecko/20100101 Firefox/3.6
1354+
Mozilla/5.0 (Windows; U; Windows NT 7.0; rv:1.9.2) Gecko/20100101 Firefox/3.6
13591355
Mozilla/5.0 (Windows; U; WinNT4.0; de-DE; rv:1.7.5) Gecko/20041108 Firefox/1.0
13601356
Mozilla/5.0 (Windows; U; WinNT4.0; de-DE; rv:1.7.6) Gecko/20050226 Firefox/1.0.1
13611357
Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0
@@ -1385,7 +1381,6 @@ Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0
13851381
Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0
13861382
Mozilla/5.0 (X11; Linux i686; U; en; rv:1.8.0) Gecko/20060728 Firefox/1.5.0
13871383
Mozilla/5.0 (X11; Linux i686; U; pl; rv:1.8.1) Gecko/20061208 Firefox/2.0.0
1388-
Mozilla/5.0 (X11; Linux ppc; rv:5.0) Gecko/20100101 Firefox/5.0
13891384
Mozilla/5.0 (X11; Linux x86_64) Gecko Firefox/5.0
13901385
Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110506 Firefox/4.0.1
13911386
Mozilla/5.0 (X11; Linux x86_64; rv:2.0b4) Gecko/20100818 Firefox/4.0b4
@@ -2209,13 +2204,6 @@ Mozilla/5.0 (X11; U; Linux i686; zh-TW; rv:1.9.0.3) Gecko/2008092510 Ubuntu/8.04
22092204
Mozilla/5.0 (X11; U; Linux i686; zh-TW; rv:1.9.0.7) Gecko/2009030422 Ubuntu/8.04 (hardy) Firefox/3.0.7
22102205
Mozilla/5.0 (X11; U; Linux ia64; en-US; rv:1.9.0.3) Gecko/2008092510 Ubuntu/8.04 (hardy) Firefox/3.0.3
22112206
Mozilla/5.0 (X11; U; Linux MIPS32 1074Kf CPS QuadCore; en-US; rv:1.9.2.13) Gecko/20110103 Fedora/3.6.13-1.fc14 Firefox/3.6.13
2212-
Mozilla/5.0 (X11; U; Linux ppc64; en-US; rv:1.8.1.14) Gecko/20080418 Ubuntu/7.10 (gutsy) Firefox/2.0.0.14
2213-
Mozilla/5.0 (X11; U; Linux ppc; da-DK; rv:1.7.12) Gecko/20051010 Firefox/1.0.7 (Ubuntu package 1.0.7)
2214-
Mozilla/5.0 (X11; U; Linux ppc; en-GB; rv:1.9.0.12) Gecko/2009070818 Ubuntu/8.10 (intrepid) Firefox/3.0.12
2215-
Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.7.12) Gecko/20051222 Firefox/1.0.7
2216-
Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.8.1.3) Gecko/20070310 Firefox/2.0.0.3 (Debian-2.0.0.3-1)
2217-
Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.9.0.4) Gecko/2008111317 Ubuntu/8.04 (hardy) Firefox/3.0.4
2218-
Mozilla/5.0 (X11; U; Linux ppc; fr; rv:1.9.2.12) Gecko/20101027 Ubuntu/10.10 (maverick) Firefox/3.6.12
22192207
Mozilla/5.0 (X11; U; Linux sparc64; en-US; rv:1.8.1.17) Gecko/20081108 Firefox/2.0.0.17
22202208
Mozilla/5.0 (X11; U; Linux x64_64; es-AR; rv:1.9.0.3) Gecko/2008092515 Ubuntu/8.10 (intrepid) Firefox/3.0.3
22212209
Mozilla/5.0 (X11; U; Linux x86_64; cs-CZ; rv:1.9.0.4) Gecko/2008111318 Ubuntu/8.04 (hardy) Firefox/3.0.4
@@ -2547,7 +2535,6 @@ Mozilla/5.0 (X11; U; OpenBSD i386; en-US; rv:1.8.1.6) Gecko/20070819 Firefox/2.0
25472535
Mozilla/5.0 (X11; U; OpenBSD i386; en-US; rv:1.8.1.7) Gecko/20070930 Firefox/2.0.0.7
25482536
Mozilla/5.0 (X11; U; OpenBSD i386; en-US; rv:1.9.2.20) Gecko/20110803 Firefox/3.6.20
25492537
Mozilla/5.0 (X11; U; OpenBSD i386; en-US; rv:1.9.2.8) Gecko/20101230 Firefox/3.6.8
2550-
Mozilla/5.0 (X11; U; OpenBSD ppc; en-US; rv:1.8.0.10) Gecko/20070223 Firefox/1.5.0.10
25512538
Mozilla/5.0 (X11; U; OpenBSD sparc64; en-AU; rv:1.8.1.6) Gecko/20071225 Firefox/2.0.0.6
25522539
Mozilla/5.0 (X11; U; OpenBSD sparc64; en-CA; rv:1.8.0.2) Gecko/20060429 Firefox/1.5.0.2
25532540
Mozilla/5.0 (X11; U; OpenBSD sparc64; en-US; rv:1.8.1.6) Gecko/20070816 Firefox/2.0.0.6
@@ -3452,16 +3439,6 @@ Mozilla/4.0 (compatible; MSIE 4.01; Windows 98; DigExt)
34523439
Mozilla/4.0 (compatible; MSIE 4.01; Windows 98; Hotbar 3.0)
34533440
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE)
34543441
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC)
3455-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320; PPC)
3456-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320; Sprint:PPC-6700; PPC; 240x320)
3457-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Smartphone; 176x220)
3458-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Sprint;PPC-i830; PPC; 240x320)
3459-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Sprint:PPC-i830; PPC; 240x320)
3460-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Sprint:SCH-i320; Smartphone; 176x220)
3461-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Sprint; SCH-i830; PPC; 240x320)
3462-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Sprint:SCH-i830; PPC; 240x320)
3463-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Sprint:SPH-ip320; Smartphone; 176x220)
3464-
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Sprint:SPH-ip830w; PPC; 240x320)
34653442
Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)
34663443
Mozilla/4.0 (compatible; MSIE 4.01; Windows NT 5.0)
34673444
Mozilla/4.0 (compatible; MSIE 4.0; Windows 95)
@@ -3597,16 +3574,13 @@ Mozilla/4.0 (Mozilla/4.0; MSIE 7.0; Windows NT 5.1; FDM; SV1)
35973574
Mozilla/4.0 (Mozilla/4.0; MSIE 7.0; Windows NT 5.1; FDM; SV1; .NET CLR 3.0.04506.30)
35983575
Mozilla/4.0 (MSIE 6.0; Windows NT 5.0)
35993576
Mozilla/4.0 (MSIE 6.0; Windows NT 5.1)
3600-
Mozilla/4.0 PPC (compatible; MSIE 4.01; Windows CE; PPC; 240x320; Sprint:PPC-6700; PPC; 240x320)
36013577
Mozilla/4.0 WebTV/2.6 (compatible; MSIE 4.0)
36023578
Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.0)
36033579
Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
36043580
Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.2)
36053581
Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 6.0)
36063582
Mozilla/4.0 (Windows; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
36073583
Mozilla/4.0 (X11; MSIE 6.0; i686; .NET CLR 1.1.4322; .NET CLR 2.0.50727; FDM)
3608-
Mozilla/45.0 (compatible; MSIE 6.0; Windows NT 5.1)
3609-
Mozilla/4.79 [en] (compatible; MSIE 7.0; Windows NT 5.0; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)
36103584
Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)
36113585
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/4.0; InfoPath.2; SV1; .NET CLR 2.0.50727; WOW64)
36123586
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)
@@ -3809,7 +3783,6 @@ Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; sv-se) AppleWebKit/525.18 (KHTM
38093783
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; sv-se) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1
38103784
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; tr) AppleWebKit/528.4+ (KHTML, like Gecko) Version/4.0dp1 Safari/526.11.2
38113785
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_2; en) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18
3812-
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_2; en-gb) AppleWebKit/526+ (KHTML, like Gecko) Version/3.1 iPhone
38133786
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_2; en-gb) AppleWebKit/526+ (KHTML, like Gecko) Version/3.1 Safari/525.9
38143787
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_3; en) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.20
38153788
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_3; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.20
@@ -4209,4 +4182,4 @@ Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN) AppleWebKit/533+ (KHTML, like Ge
42094182
Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-HK) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5
42104183
Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-TW) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10
42114184
Mozilla/5.0 (X11; U; Linux x86_64; en-ca) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+
4212-
Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+
4185+
Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+

0 commit comments

Comments
 (0)