MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / _setHTTPUserAgent

Function _setHTTPUserAgent

lib/core/option.py:1443–1500  ·  view source on GitHub ↗

Set the HTTP User-Agent header. Depending on the user options it can be: * The default sqlmap string * A default value read as user option * A random value read from a list of User-Agent headers from a file choosed as user option

()

Source from the content-addressed store, hash-verified

1441 conf.httpHeaders.append((HTTP_HEADER.CACHE_CONTROL, "no-cache"))
1442
1443def _setHTTPUserAgent():
1444 """
1445 Set the HTTP User-Agent header.
1446 Depending on the user options it can be:
1447
1448 * The default sqlmap string
1449 * A default value read as user option
1450 * A random value read from a list of User-Agent headers from a
1451 file choosed as user option
1452 """
1453
1454 debugMsg = "setting the HTTP User-Agent header"
1455 logger.debug(debugMsg)
1456
1457 if conf.mobile:
1458 if conf.randomAgent:
1459 _ = random.sample([_[1] for _ in getPublicTypeMembers(MOBILES, True)], 1)[0]
1460 conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, _))
1461 else:
1462 message = "which smartphone do you want sqlmap to imitate "
1463 message += "through HTTP User-Agent header?\n"
1464 items = sorted(getPublicTypeMembers(MOBILES, True))
1465
1466 for count in xrange(len(items)):
1467 item = items[count]
1468 message += "[%d] %s%s\n" % (count + 1, item[0], " (default)" if item == MOBILES.IPHONE else "")
1469
1470 test = readInput(message.rstrip('\n'), default=items.index(MOBILES.IPHONE) + 1)
1471
1472 try:
1473 item = items[int(test) - 1]
1474 except:
1475 item = MOBILES.IPHONE
1476
1477 conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, item[1]))
1478
1479 elif conf.agent:
1480 conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, conf.agent))
1481
1482 elif not conf.randomAgent:
1483 _ = True
1484
1485 for header, _ in conf.httpHeaders:
1486 if header.upper() == HTTP_HEADER.USER_AGENT.upper():
1487 _ = False
1488 break
1489
1490 if _:
1491 conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, DEFAULT_USER_AGENT))
1492
1493 else:
1494 userAgent = fetchRandomAgent()
1495
1496 infoMsg = "fetched random HTTP User-Agent header value '%s' from " % userAgent
1497 infoMsg += "file '%s'" % paths.USER_AGENTS
1498 logger.info(infoMsg)
1499
1500 conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, userAgent))

Callers 1

initFunction · 0.85

Calls 8

getPublicTypeMembersFunction · 0.90
readInputFunction · 0.90
fetchRandomAgentFunction · 0.90
xrangeClass · 0.85
debugMethod · 0.80
infoMethod · 0.80
appendMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…