mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-06-29 17:33:11 +03:00
More elegant implementation for --random-agent
This commit is contained in:
parent
9456dc68e7
commit
e931344617
|
@ -10,6 +10,7 @@ import glob
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import string
|
import string
|
||||||
|
@ -45,7 +46,6 @@ from lib.core.common import openFile
|
||||||
from lib.core.common import parseTargetDirect
|
from lib.core.common import parseTargetDirect
|
||||||
from lib.core.common import parseTargetUrl
|
from lib.core.common import parseTargetUrl
|
||||||
from lib.core.common import paths
|
from lib.core.common import paths
|
||||||
from lib.core.common import randomRange
|
|
||||||
from lib.core.common import randomStr
|
from lib.core.common import randomStr
|
||||||
from lib.core.common import readCachedFileContent
|
from lib.core.common import readCachedFileContent
|
||||||
from lib.core.common import readInput
|
from lib.core.common import readInput
|
||||||
|
@ -1331,15 +1331,7 @@ def _setHTTPUserAgent():
|
||||||
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, _defaultHTTPUserAgent()))
|
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, _defaultHTTPUserAgent()))
|
||||||
return
|
return
|
||||||
|
|
||||||
count = len(kb.userAgents)
|
userAgent = random.sample(kb.userAgents or [_defaultHTTPUserAgent()], 1)[0]
|
||||||
|
|
||||||
if count == 1:
|
|
||||||
userAgent = kb.userAgents[0]
|
|
||||||
else:
|
|
||||||
userAgent = kb.userAgents[randomRange(stop=count - 1)]
|
|
||||||
|
|
||||||
userAgent = sanitizeStr(userAgent)
|
|
||||||
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, userAgent))
|
|
||||||
|
|
||||||
infoMsg = "fetched random HTTP User-Agent header from "
|
infoMsg = "fetched random HTTP User-Agent header from "
|
||||||
infoMsg += "file '%s': %s" % (paths.USER_AGENTS, userAgent)
|
infoMsg += "file '%s': %s" % (paths.USER_AGENTS, userAgent)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user