text stringlengths 1 93.6k |
|---|
cookies.append(cookie)
|
return resp_headers, resp_body, cookies
|
def bake_cookies(cookies):
|
# return b''.join([b'Cookie: %s\r\n' % c for c in cookies])
|
return b'Cookie: %s\r\n' % b'; '.join(cookies)
|
def send_standalone_post(
|
socket_factory,
|
post_factory,
|
cookies,
|
data,
|
counter_thread,
|
mode
|
):
|
my_headers = b''.join((
|
b"User-Agent: curl/7.58.0\r\n",
|
# probably not necessary
|
b"Accept: */*\r\n",
|
bake_cookies(cookies),
|
b"X-ClientSide: 1\r\n",
|
header_mode(mode),
|
# close connection; send data in a new TCP stream
|
b"Connection: close\r\n",
|
# keep the connection alive. saves on latency
|
# "Connection: keep-alive\r\n",
|
))
|
# send data as a brand new POST request
|
req = post_factory.build_request(
|
# set a continuation header
|
my_headers=my_headers,
|
# no need for a body: we're initialising the
|
# server-side listener
|
req_body=to_chunk(data),
|
# this terminates the POST with a 0 chunk, so
|
# that the aspx page can read it and send it
|
# over to the server-side socket
|
is_last=True)
|
log.debug("Sending stand-alone POST\n---\n%s\n---", req)
|
# see above
|
# try:
|
# log.debug("Sending stand-alone POST\n---\n{}\n---".format(
|
# req.decode()))
|
# except UnicodeDecodeError:
|
# # ssh will make things iffy here. it's binary data, skip anyway...
|
# pass
|
# # for keep-alive:
|
# with websock_mutex:
|
# # _chunked_data = to_chunk(data)
|
# # websock.sendall(_chunked_data)
|
# websock.sendall(req)
|
# # not needed actually
|
# # split_headers(websock.recv(BUFFER_SIZE))
|
# for new TCP streams:
|
websock2 = socket_factory.build_socket()
|
websock2.sendall(req)
|
# IMPORTANT
|
# We *need* to remove the HTTP headers
|
# from the response from this first, delayed message
|
# otherwise it's going to interfere with things like ssh
|
if counter_thread.first_message:
|
# the message will be delayed by 120s
|
# IIS bug probably.
|
# TODO print only if talking to an ASPX endpoint
|
print("[!] The first message will be delayed "
|
"by 120s. ")
|
print("[!] Why? Who knows. Things will work fine "
|
"afterwards. Please wait...")
|
counter_thread.first_message = False
|
counter_thread.start()
|
# used only to check what's going on; no need to
|
# check the return values. Will raise an exception
|
# it's non-200 or not a HTTP response
|
resp_headers, resp_body, _cookie = split_headers(
|
websock2.recv(BUFFER_SIZE))
|
# removed when adding support for multiple cookies
|
# if _cookie != b"" and _cookie != cookie:
|
# log.warn(
|
# "Cookie value has changed. Something "
|
# "wrong with the remote session storage?.")
|
# cookie = _cookie
|
# TODO catch and finally close?
|
websock2.shutdown(socket.SHUT_RDWR)
|
websock2.close()
|
log.debug("Closed socket")
|
if counter_thread.is_alive():
|
# stop timer thread
|
counter_thread.quit = True
|
return resp_headers, resp_body, cookies
|
def to_chunk(what):
|
# return format(len(what), 'X') + "\r\n" + what + "\r\n"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.