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

Skip to content

Commit 8d93bdf

Browse files
committed
minor update (optimization) regarding -a switch
1 parent 857a2a4 commit 8d93bdf

2 files changed

Lines changed: 20 additions & 27 deletions

File tree

lib/core/option.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from lib.core.common import parseTargetUrl
3232
from lib.core.common import paths
3333
from lib.core.common import randomRange
34+
from lib.core.common import readCachedFileContent
3435
from lib.core.common import readInput
3536
from lib.core.common import runningAsAdmin
3637
from lib.core.common import sanitizeStr
@@ -835,7 +836,6 @@ def __setHTTPUserAgent():
835836
* A random value read from a list of User-Agent headers from a
836837
file choosed as user option
837838
"""
838-
839839
if conf.agent:
840840
debugMsg = "setting the HTTP User-Agent header"
841841
logger.debug(debugMsg)
@@ -856,39 +856,28 @@ def __setHTTPUserAgent():
856856

857857
return
858858

859-
debugMsg = "fetching random HTTP User-Agent header from "
860-
debugMsg += "file '%s'" % conf.userAgentsFile
861-
logger.debug(debugMsg)
862-
863-
try:
864-
fd = codecs.open(conf.userAgentsFile, "r", conf.dataEncoding)
865-
except IOError:
866-
warnMsg = "unable to read HTTP User-Agent header "
867-
warnMsg += "file '%s'" % conf.userAgentsFile
868-
logger.warn(warnMsg)
869-
870-
conf.httpHeaders.append(("User-Agent", __defaultHTTPUserAgent()))
871-
872-
return
873-
874-
__count = 0
875-
__userAgents = []
859+
if not kb.userAgents:
860+
debugMsg = "loading random HTTP User-Agent header(s) from "
861+
debugMsg += "file '%s'" % conf.userAgentsFile
862+
logger.debug(debugMsg)
876863

877-
while True:
878-
line = fd.readline()
864+
try:
865+
kb.userAgents = getFileItems(conf.userAgentsFile)
866+
except IOError:
867+
warnMsg = "unable to read HTTP User-Agent header "
868+
warnMsg += "file '%s'" % conf.userAgentsFile
869+
logger.warn(warnMsg)
879870

880-
if not line:
881-
break
871+
conf.httpHeaders.append(("User-Agent", __defaultHTTPUserAgent()))
882872

883-
__userAgents.append(line)
884-
__count += 1
873+
return
885874

886-
fd.close()
875+
__count = len(kb.userAgents)
887876

888877
if __count == 1:
889-
__userAgent = __userAgents[0]
878+
__userAgent = kb.userAgents[0]
890879
else:
891-
__userAgent = __userAgents[randomRange(stop=__count)]
880+
__userAgent = kb.userAgents[randomRange(stop=__count)]
892881

893882
__userAgent = sanitizeStr(__userAgent)
894883
conf.httpHeaders.append(("User-Agent", __userAgent))
@@ -1114,6 +1103,7 @@ def __setKnowledgeBaseAttributes():
11141103
kb.unionPosition = None
11151104
kb.unionNegative = False
11161105
kb.unionFalseCond = False
1106+
kb.userAgents = None
11171107
kb.valueStack = []
11181108

11191109
def __saveCmdline():

txt/user-agents.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/)
2+
# See the file 'doc/COPYING' for copying permission
3+
14
Accoona-AI-Agent/1.1.2 (aicrawler at accoonabot dot com)
25
Baiduspider ( http://www.baidu.com/search/spider.htm)
36
curl/7.13.1 (powerpc-apple-darwin8.0) libcurl/7.13.1 OpenSSL/0.9.7b zlib/1.2.2

0 commit comments

Comments
 (0)