You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sqlmap/src/sqlmap-master/tamper/xforwardedfor.py

55 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env python
"""
Copyright (c) 2006-2024 sqlmap developers (https://sqlmap.org/)
See the file 'LICENSE' for copying permission
"""
import random
from lib.core.compat import xrange
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.NORMAL
def dependencies():
pass
def randomIP():
"""
生成一个随机的IP地址
"""
octets = []
# 生成一个随机的IP地址排除10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16这三个私有IP地址段
while not octets or octets[0] in (10, 172, 192):
octets = random.sample(xrange(1, 255), 4)
# 将生成的IP地址段连接成一个字符串
return '.'.join(str(_) for _ in octets)
def tamper(payload, **kwargs):
"""
Append a fake HTTP header 'X-Forwarded-For' (and alike)
"""
# 获取传入的headers参数如果没有则创建一个空字典
headers = kwargs.get("headers", {})
# 生成一个随机的IP地址并将其添加到headers中
headers["X-Forwarded-For"] = randomIP()
headers["X-Client-Ip"] = randomIP()
headers["X-Real-Ip"] = randomIP()
headers["CF-Connecting-IP"] = randomIP()
headers["True-Client-IP"] = randomIP()
# Reference: https://developer.chrome.com/multidevice/data-compression-for-isps#proxy-connection
# 添加一个Via头表示通过Chrome Compression Proxy代理
headers["Via"] = "1.1 Chrome-Compression-Proxy"
# Reference: https://wordpress.org/support/topic/blocked-country-gaining-access-via-cloudflare/#post-9812007
# 添加一个CF-IPCountry头表示通过Cloudflare代理并随机选择一个国家
headers["CF-IPCountry"] = random.sample(('GB', 'US', 'FR', 'AU', 'CA', 'NZ', 'BE', 'DK', 'FI', 'IE', 'AT', 'IT', 'LU', 'NL', 'NO', 'PT', 'SE', 'ES', 'CH'), 1)[0]
# 返回添加了headers的payload
return payload