5757from lib .core .enums import DBMS
5858from lib .core .enums import HTTPHEADER
5959from lib .core .enums import HTTPMETHOD
60+ from lib .core .enums import MOBILES
6061from lib .core .enums import PAYLOAD
6162from lib .core .enums import PRIORITY
6263from 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
11041119def __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
0 commit comments