【发布时间】:2019-07-07 00:08:20
【问题描述】:
问题
我正在开发一个带有 Python3 套接字的基本代理服务器。它有效,但不是它应该有效的。响应标题很好,但正文不是。 如下图所示,响应体看起来很奇怪“Just Bytes 'x1f\x8b\x08\x00\x00...etc'”,但是当它重定向到浏览器时,它会正确呈现。
通过套接字接收到的响应
b"HTTP/1.1 200 OK
Vary: Accept-Encoding\r\n
Content-Encoding: gzip\r\n
Content-Length: 156\r\n
Keep-Alive: timeout=5, max=100\r\n
Connection: Keep-Alive\r\n
Content-Type: text/html\r\n\
r\n\
x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03-\x8e\xcb\x0e\x83 \x14D\xf7|\x05\xb2.\xd5e\xa3\xe8\xda?p\x8d@\x81\xf4\xea5p\xfb\xf0\xef\x8b\xc6\xd5$'\x939\x03h4\x04\xcc\xa4\x02-00\x15\x9c\xb6%(\x12\xb8\x81\x8d\x0e\x00o|\xc2\x04\xb6b\xaa\xbe\xb0\xaa\xaf\xda\x8cv\xe7\xb37\x08\x98z1\x836/Q\xb0\x8d\x1f\x9ei\x07\xd7\x8bE'\x1f\xd7V\xbf\t\xbbo\xb4\x14\xdaG\xd3l\xbf\xae\xd4\xc6\xc8T%\xa5\x8a\x8b\xe79\x99^\x84\xe7}[\xbd\x18\xa4<\x14e\xe4\x88Cq\x1a\xcf\x7f\x7f\x10\x07P@\xb0\x00\x00\x00"
响应码是:
def receive(sock):
sock.settimeout(3)
data=b""
try:
while 1:
rcvd=sock.recv(4096)
if not rcvd:
break
data+=rcvd
except:
pass
return data
然后我用Burp Suite得到同样的响应,响应的body是正常的。
与 Burp 相同的响应
HTTP/1.1 200 OK
Vary: Accept-Encoding
Content-Length: 176
Connection: close
Content-Type: text/html
localhost<html>
<head>
<title>
Hello, World!
</title>
</head>
<body bgcolor="black">
<div style="margin:auto;width:800px;">
Hi
</div>
</body>
</html>
如果存在 localhost 站点,但如果请求的站点不存在 404 not found ,则会出现此问题,并且响应是正常的并且具有清晰且正常的正文。
所以,我想弄清楚问题是什么以及如何解决它。
【问题讨论】:
标签: python sockets proxy http-proxy burp