text stringlengths 1 93.6k |
|---|
except BrokenSocketException as e:
|
raise SystemExit(e)
|
except KeyboardInterrupt:
|
print("User interrupt")
|
raise SystemExit
|
resp_headers, resp_body, cookies = split_headers(initial_response)
|
if args.force_cookie is not None:
|
log.debug("Forcing cookie: {}".format(args.force_cookie))
|
cookies += [get_bytes(args.force_cookie)]
|
print("[*] Connection with web server established")
|
# start HB thread after the connection has been established
|
thread_hb = HeartBeat(websock)
|
thread_hb.daemon = True
|
if not is_async:
|
# note: even if the server is slow in responding because it's trying to
|
# connect to a host (for the 'L' mode), we should assume it's alive so
|
# let's keep poking it anyway. Worst case scenario we're sending
|
# heartbeats to /dev/null
|
thread_hb.start()
|
# this will be started later, at the first client message
|
# in an async scenario
|
counter_thread = CountdownTimer()
|
try:
|
# this 'chunks' is a generator; when polled with
|
# .next() it will read and return data from the
|
# server-side component
|
inbound_data = read_chunks(websock, is_async, resp_body)
|
# tell the web page to get their stuff in order (connect where needed,
|
# etc.)
|
consock = setup(
|
websock,
|
consock,
|
inbound_data,
|
SOCKET_MODE,
|
CONNECT_IP,
|
CONNECT_PORT)
|
# rock and roll. This will keep running until a socket is broken
|
dispatch(
|
websock,
|
consock,
|
inbound_data,
|
thread_hb,
|
counter_thread,
|
post_factory,
|
socket_factory,
|
cookies,
|
is_async,
|
mode)
|
except StopIteration:
|
raise SystemExit("Remote closed connection")
|
except socket.error as e:
|
# error when sending data to the client
|
# (using sendall() on the sockets)
|
raise SystemExit("Socket error: {}".format(e))
|
except BrokenSocketException as e:
|
raise SystemExit(e)
|
except TransmissionError as e:
|
raise SystemExit(e)
|
except KeyboardInterrupt:
|
raise SystemExit("User interrupt")
|
finally:
|
log.debug("Stopping heartbeat...")
|
thread_hb.stop()
|
if thread_hb.is_alive():
|
log.debug("Waiting for heartbeat to stop...")
|
thread_hb.join()
|
if counter_thread.is_alive():
|
# stop timer thread
|
counter_thread.quit = True
|
if consock is not None:
|
# because if there's a failure during setup()
|
# the consock might not even be initialised
|
log.debug("Closing connection to server side...")
|
try:
|
consock.shutdown(socket.SHUT_RDWR)
|
consock.close()
|
except socket.error:
|
print("[!] Local console already closed")
|
pass
|
print("[*] All done.")
|
if __name__ == '__main__':
|
main()
|
# <FILESEP>
|
# Copyright (c) 2011-2015 Rusty Wagner
|
#
|
# This program is free software: you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation, either version 2 of the License, or
|
# (at your option) any later version.
|
#
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.