Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python在使用BurpSuite时请求https:code 403,但不请求code 200_Python_Ssl_Python Requests_Certificate_Burp - Fatal编程技术网

Python在使用BurpSuite时请求https:code 403,但不请求code 200

Python在使用BurpSuite时请求https:code 403,但不请求code 200,python,ssl,python-requests,certificate,burp,Python,Ssl,Python Requests,Certificate,Burp,我目前正试图从retailmenot.com上搜刮我的代码: import requests from collections import OrderedDict s = requests.session() s.headers = OrderedDict() s.headers["Connection"] = "close" s.headers["Upgrade-Insecure-Requests"] = "1&quo

我目前正试图从retailmenot.com上搜刮我的代码:

import requests
from collections import OrderedDict

s = requests.session()

s.headers = OrderedDict()
s.headers["Connection"] = "close"
s.headers["Upgrade-Insecure-Requests"] = "1"
s.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
s.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
s.headers["Sec-Fetch-Site"] = "none"
s.headers["Sec-Fetch-Mode"] = "navigate"
s.headers["Sec-Fetch-Dest"] = "document"
s.headers["Accept-Encoding"] = "gzip, deflate"
s.headers["Accept-Language"] = "en-GB,en-US;q=0.9,en;q=0.8"

s.get("https://www.retailmenot.com/sitemap/A")
当我使用这段代码时,我立即被重定向到CloudFlare页面。也就是说,每当我通过Burpusuite传递流量时,用下面这行代码替换我的最后一行代码:

s.get("https://www.retailmenot.com/sitemap/A", proxies = {"https":"https://127.0.0.1:8080"}, verify ="/Users/Downloads/cacert (1).pem")

我直接进入网站。我觉得这有点奇怪,想知道是否有人可以向我解释为什么会发生这种情况,以及是否有一种方法可以通过使用不同的证书获得类似的结果(为了使用BurpSuite证书,我需要保持应用程序打开)。非常感谢

看来问题在于底层客户端TLS行为

我有一个使用OpenSSL 1.1.1b的较旧版本的Python,还有一个使用OpenSSL 1.1.1f的较新版本。它在第一个版本中失败,但在第二个版本中有效。这也解释了为什么它与打嗝一起工作:它使用了稍微不同的TLS行为

我试图找出问题所在:让非工作版本使用工作版本的密码不会有帮助。另一个主要区别是受支持的签名算法。事实上,使用上述openssl 1.1.1b(但也使用Anaconda Python附带的较新版本),差异可以减少到sigalgs:

 $ openssl s_client -connect www.retailmenot.com:443 -crlf
 ...[various output]...
 <paste the expected HTTP request>
 ...
 HTTP/1.1 403 Forbidden

 $ openssl s_client -connect www.retailmenot.com:443 -crlf -sigalgs 'ECDSA+SHA256'
 ...[various output]...
 <paste the expected HTTP request>
 ...
 HTTP/1.1 200 OK

这与特定的头设置一起,导致我在
中进行测试,而对于相同的Python版本,在没有更改安全级别的情况下,它导致

很可能是Burp更改了头的顺序,添加了一些头或类似的头,从而绕过了bot保护。更好地比较传入和传出请求。这可能与证书无关。@SteffenUllrich感谢您的回复。我知道Burpuite发送的头的顺序,这就是我使用
OrderedDict()
的原因。疯狂的是,我尝试了很多方法,似乎唯一有效的方法就是使用Burpusuite证书。你知道发生了什么事吗?很难说。也许是TLS指纹。通过使用BurpSuite,TLS连接在BurpSuite和服务器之间,因此如果TLS配置在那里,它将使用属性。@SteffenUllrich非常感谢您的回复。我想可能是因为TLS指纹?你知道我还可以使用其他证书吗?TLS指纹与使用的证书完全无关。嘿,Steffe。非常感谢您的回答!有没有一种方法可以在python请求中使用某种其他CA使其工作?如果不是的话,是不是有一些演练,或者是python请求无法完成的事情?@NazimKerimbekov:这与使用的CA完全无关。CA仅由客户端在本地用于验证服务器证书。它不会影响TLS握手的外观,也不会影响服务器的应答。再一次,它在Python的一个版本(Ubuntu20.04)中工作,因此可以使用Python,这取决于Python中使用的OpenSSL是如何构建的。非常感谢您的回复Steffen。我正在iMac上运行Python 3.9。我应该更新我的python版本吗?更换电脑?@NazimKerimbekov:这与Python的版本无关。由于Python不提供设置签名算法的API,因此它完全取决于OpenSSL(Python使用的)的编译方式。因此,仅仅更新Python是没有帮助的。同样,它与Ubuntu 20.04上的Python配合使用,因此将计算机更改为该版本(或在Mac上安装为VM)会有所帮助。@SteffenUllrich“非对称密钥算法(RSA和ECDSA)”中描述的解决方案是否可行?
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.ssl_ import create_urllib3_context

CIPHERS = ('DEFAULT:@SECLEVEL=2')
class CipherAdapter(HTTPAdapter):
    def init_poolmanager(self, *args, **kwargs):
        context = create_urllib3_context(ciphers=CIPHERS)
        kwargs['ssl_context'] = context
        return super(CipherAdapter, self).init_poolmanager(*args, **kwargs)

    def proxy_manager_for(self, *args, **kwargs):
        context = create_urllib3_context(ciphers=CIPHERS)
        kwargs['ssl_context'] = context
        return super(CipherAdapter, self).proxy_manager_for(*args, **kwargs)

s = requests.session()
s.mount('https://www.retailmenot.com/', CipherAdapter())
...
print(s.get("https://www.retailmenot.com/sitemap/A"))