-
Notifications
You must be signed in to change notification settings - Fork 2
Merge IPC into one function #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,40 +56,36 @@ | |
else: # Parent process | ||
logger.debug("Started background process, PID: %d", pid) | ||
|
||
def send_data_to_bg_process(self, action, obj): | ||
def send_data_to_bg_process(self, action, obj, receive=False): | ||
""" | ||
This creates a new client for comms to the background process | ||
""" | ||
|
||
# We want to make sure that sending out this data affects the process as little as possible | ||
# So we run it inside a seperate thread with a timeout of 3 seconds | ||
def target(address, key, data_array): | ||
try: | ||
conn = con.Client(address, authkey=key) | ||
logger.debug("Created connection %s", conn) | ||
for data in data_array: | ||
conn.send(data) | ||
conn.send(("CLOSE", {})) | ||
conn.close() | ||
logger.debug("Connection closed") | ||
except Exception as e: | ||
logger.info("Failed to send data to bg process : %s", e) | ||
# If something goes wrong, it will also be encapsulated in the thread i.e. no crashes | ||
def target(address, key, receive, data, result_obj): | ||
# Create a connection, this can get stuck : | ||
conn = con.Client(address, authkey=key) | ||
|
||
# Send/Receive data : | ||
conn.send(data) | ||
if receive: | ||
result_obj = conn.recv() | ||
|
||
# Close the connection : | ||
conn.send(("CLOSE", {})) | ||
conn.close() | ||
|
||
# Create a shared result object between the thread and this process : | ||
result_obj = None | ||
t = Thread( | ||
target=target, args=(self.address, self.key, [(action, obj)]), daemon=True | ||
target=target, | ||
args=(self.address, self.key, receive, (action, obj), result_obj), | ||
daemon=True, | ||
) | ||
|
||
# Start and join the thread for 3 seconds, afterwards the thread is forced to close (daemon=True) | ||
t.start() | ||
# This joins the thread for 3 seconds, afterwards the thread is forced to close (daemon=True) | ||
t.join(timeout=3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 100 ms ? |
||
|
||
def poll_config(self, prop): | ||
""" | ||
This will poll the config from the Background Process | ||
""" | ||
conn = con.Client(self.address, authkey=self.key) | ||
conn.send(("READ_PROPERTY", prop)) | ||
prop_value = conn.recv() | ||
conn.send(("CLOSE", {})) | ||
conn.close() | ||
logger.debug("Received property %s as %s", prop, prop_value) | ||
return prop_value | ||
return result_obj |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,9 @@ | |
logger.debug("sql_injection results : %s", json.dumps(contains_injection)) | ||
if contains_injection: | ||
get_comms().send_data_to_bg_process("ATTACK", (contains_injection, context)) | ||
should_block = get_comms().poll_config("block") | ||
should_block = get_comms().send_data_to_bg_process( | ||
"READ_PROPERTY", "block", True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. named ? |
||
) | ||
if should_block: | ||
raise AikidoSQLInjection("SQL Injection [aikido_firewall]") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,9 @@ | |
logger.info("sql_injection results : %s", json.dumps(contains_injection)) | ||
if contains_injection: | ||
get_comms().send_data_to_bg_process("ATTACK", (contains_injection, context)) | ||
should_block = get_comms().poll_config("block") | ||
should_block = get_comms().send_data_to_bg_process( | ||
"READ_PROPERTY", "block", True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. named param? |
||
) | ||
if should_block: | ||
raise AikidoSQLInjection("SQL Injection [aikido_firewall]") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment for why daemon