forked from p15670423/monkey
Agent: Add comment to _get_new_http_handler_class()
This commit is contained in:
parent
3698a28e26
commit
c4f971ff33
|
@ -1,6 +1,7 @@
|
||||||
import http.server
|
import http.server
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
from typing import Type
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -26,7 +27,18 @@ def do_GET(self):
|
||||||
self.wfile.write(self.java_class)
|
self.wfile.write(self.java_class)
|
||||||
|
|
||||||
|
|
||||||
def get_new_http_handler_class(java_class: bytes, class_downloaded: threading.Event):
|
def _get_new_http_handler_class(
|
||||||
|
java_class: bytes, class_downloaded: threading.Event
|
||||||
|
) -> Type[http.server.BaseHTTPRequestHandler]:
|
||||||
|
"""
|
||||||
|
Dynamically create a new subclass of http.server.BaseHTTPRequestHandler and return it to the
|
||||||
|
caller.
|
||||||
|
|
||||||
|
Because Python's http.server.HTTPServer accepts a class and creates a new object to
|
||||||
|
handle each request it receives, any state that needs to be shared between requests must be
|
||||||
|
stored as class variables. Creating the request handler classes dynamically at runtime allows
|
||||||
|
multiple ExploitClassHTTPServers, each with it's own unique state, to run concurrently.
|
||||||
|
"""
|
||||||
return type(
|
return type(
|
||||||
"HTTPHandler",
|
"HTTPHandler",
|
||||||
(http.server.BaseHTTPRequestHandler,),
|
(http.server.BaseHTTPRequestHandler,),
|
||||||
|
@ -60,7 +72,7 @@ class ExploitClassHTTPServer:
|
||||||
self._class_downloaded = threading.Event()
|
self._class_downloaded = threading.Event()
|
||||||
self._poll_interval = poll_interval
|
self._poll_interval = poll_interval
|
||||||
|
|
||||||
HTTPHandler = get_new_http_handler_class(java_class, self._class_downloaded)
|
HTTPHandler = _get_new_http_handler_class(java_class, self._class_downloaded)
|
||||||
|
|
||||||
self._server = http.server.HTTPServer((ip, port), HTTPHandler)
|
self._server = http.server.HTTPServer((ip, port), HTTPHandler)
|
||||||
# Setting `daemon=True` to save ourselves some trouble when this is merged to the
|
# Setting `daemon=True` to save ourselves some trouble when this is merged to the
|
||||||
|
|
Loading…
Reference in New Issue