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

Skip to content

Commit 11124b2

Browse files
committed
implemented --mobile switch
1 parent b299912 commit 11124b2

5 files changed

Lines changed: 55 additions & 18 deletions

File tree

lib/core/enums.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ class HASH:
6969
SHA1_GENERIC = r'(?i)\A[0-9a-f]{40}\Z'
7070
CRYPT_GENERIC = r'(?i)\A[./0-9A-Za-z]{13}\Z'
7171

72+
class MOBILES:
73+
IPHONE = "Apple iPhone 4;Apple-iPhone3C1/801.306"
74+
BLACKBERRY = "Blackberry 9800;Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-US) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.246 Mobile Safari/534.1+"
75+
NEXUS = "Google Nexus One;Mozilla/5.0 (Linux; U; Android 2.2; en-US; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
76+
KINDLE = "Amazon Kindle 3;Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600X800; rotate)"
77+
GALAXY = "Samsung Galaxy S;Mozilla/5.0 (Linux; U; Android 2.2; en-US; SGH-T959D Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
78+
NOKIA = "Nokia N97;Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaN79-1/32.001; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/413 (KHTML, like Gecko) Safari/413"
79+
HP = "HP iPAQ 6365;Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320; HP iPAQ h6300)"
80+
7281
class HTTPHEADER:
7382
ACCEPT_ENCODING = "Accept-Encoding"
7483
AUTHORIZATION = "Authorization"

lib/core/option.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from lib.core.enums import DBMS
5858
from lib.core.enums import HTTPHEADER
5959
from lib.core.enums import HTTPMETHOD
60+
from lib.core.enums import MOBILES
6061
from lib.core.enums import PAYLOAD
6162
from lib.core.enums import PRIORITY
6263
from lib.core.exception import sqlmapFilePathException
@@ -1051,14 +1052,31 @@ def __setHTTPUserAgent():
10511052
file choosed as user option
10521053
"""
10531054

1054-
if conf.agent:
1055+
if conf.mobile:
1056+
message = "which smartphone do you want sqlmap to imitate through HTTP User-Agent header?\n"
1057+
items = sorted(getPublicTypeMembers(MOBILES, True))
1058+
1059+
for count in xrange(len(items)):
1060+
item = items[count]
1061+
message += "[%d] %s%s\n" % (count + 1, item[:item.find(';')], " (default)" if item==MOBILES.IPHONE else "")
1062+
1063+
test = readInput(message.rstrip('\n'), default=items.index(MOBILES.IPHONE) + 1)
1064+
try:
1065+
item = items[int(test) - 1]
1066+
except:
1067+
item = MOBILES.IPHONE
1068+
1069+
item = item[item.find(';') + 1:]
1070+
1071+
conf.httpHeaders.append(("User-Agent", item))
1072+
1073+
elif conf.agent:
10551074
debugMsg = "setting the HTTP User-Agent header"
10561075
logger.debug(debugMsg)
10571076

10581077
conf.httpHeaders.append(("User-Agent", conf.agent))
1059-
return
10601078

1061-
if not conf.randomAgent:
1079+
elif not conf.randomAgent:
10621080
addDefaultUserAgent = True
10631081

10641082
for header, _ in conf.httpHeaders:
@@ -1069,9 +1087,7 @@ def __setHTTPUserAgent():
10691087
if addDefaultUserAgent:
10701088
conf.httpHeaders.append(("User-Agent", __defaultHTTPUserAgent()))
10711089

1072-
return
1073-
1074-
if not kb.userAgents:
1090+
elif not kb.userAgents:
10751091
debugMsg = "loading random HTTP User-Agent header(s) from "
10761092
debugMsg += "file '%s'" % paths.USER_AGENTS
10771093
logger.debug(debugMsg)
@@ -1085,21 +1101,20 @@ def __setHTTPUserAgent():
10851101

10861102
conf.httpHeaders.append((HTTPHEADER.USER_AGENT, __defaultHTTPUserAgent()))
10871103

1088-
return
1089-
1090-
count = len(kb.userAgents)
1091-
1092-
if count == 1:
1093-
userAgent = kb.userAgents[0]
10941104
else:
1095-
userAgent = kb.userAgents[randomRange(stop=count-1)]
1105+
count = len(kb.userAgents)
10961106

1097-
userAgent = sanitizeStr(userAgent)
1098-
conf.httpHeaders.append((HTTPHEADER.USER_AGENT, userAgent))
1107+
if count == 1:
1108+
userAgent = kb.userAgents[0]
1109+
else:
1110+
userAgent = kb.userAgents[randomRange(stop=count-1)]
10991111

1100-
logMsg = "fetched random HTTP User-Agent header from "
1101-
logMsg += "file '%s': %s" % (paths.USER_AGENTS, userAgent)
1102-
logger.info(logMsg)
1112+
userAgent = sanitizeStr(userAgent)
1113+
conf.httpHeaders.append((HTTPHEADER.USER_AGENT, userAgent))
1114+
1115+
logMsg = "fetched random HTTP User-Agent header from "
1116+
logMsg += "file '%s': %s" % (paths.USER_AGENTS, userAgent)
1117+
logger.info(logMsg)
11031118

11041119
def __setHTTPReferer():
11051120
"""
@@ -1566,6 +1581,10 @@ def __basicOptionValidation():
15661581
errMsg = "switch --tor is incompatible with switch --ignore-proxy"
15671582
raise sqlmapSyntaxException, errMsg
15681583

1584+
if conf.mobile and conf.agent:
1585+
errMsg = "switch --mobile is incompatible with switch --user-agent"
1586+
raise sqlmapSyntaxException, errMsg
1587+
15691588
if conf.proxy and conf.ignoreProxy:
15701589
errMsg = "switch --proxy is incompatible with switch --ignore-proxy"
15711590
raise sqlmapSyntaxException, errMsg

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"checkPayload": "boolean",
164164
"cleanup": "boolean",
165165
"googlePage": "integer",
166+
"mobile": "boolean",
166167
"pageRank": "boolean",
167168
"parseErrors": "boolean",
168169
"replicate": "boolean",

lib/parse/cmdline.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ def cmdLineParser():
497497
miscellaneous.add_option("--gpage", dest="googlePage", type="int",
498498
help="Use Google dork results from specified page number")
499499

500+
miscellaneous.add_option("--mobile", dest="mobile",
501+
action="store_true", default=False,
502+
help="Imitate smartphone through HTTP User-Agent header")
503+
500504
miscellaneous.add_option("--page-rank", dest="pageRank",
501505
action="store_true", default=False,
502506
help="Display page rank (PR) for Google dork results")

sqlmap.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ forms = False
538538
# Default: 1
539539
googlePage = 1
540540

541+
# Imitate smartphone through HTTP User-Agent header.
542+
# Valid: True or False
543+
mobile = False
544+
541545
# Display page rank (PR) for Google dork results.
542546
# Valid: True or False
543547
pageRank = False

0 commit comments

Comments
 (0)