Skip to content

Commit

Permalink
splitted channals for warning and config update to allow better manag…
Browse files Browse the repository at this point in the history
…ment on xfarm client and group manager worker on config changes
  • Loading branch information
domysh committed Dec 14, 2024
1 parent 7e8df89 commit 48a41b6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
23 changes: 12 additions & 11 deletions backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ class redis_channels:
stats = "stats"
config = "config"
password_change = "password_change"
error_warning = "error_warning"

REDIS_CHANNEL_PUBLISH_LIST = [
"client",
"attack_group",
"exploit",
"service",
"team",
"attack_execution",
"exploit_source",
"submitter",
"stats",
"config"
redis_channels.client,
redis_channels.attack_group,
redis_channels.exploit,
redis_channels.service,
redis_channels.team,
redis_channels.attack_execution,
redis_channels.exploit_source,
redis_channels.submitter,
redis_channels.stats,
redis_channels.config,
redis_channels.error_warning
]


class redis_keys:
stats = "stats"
Expand Down
2 changes: 1 addition & 1 deletion backend/workers/submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def err_warn_event_update():
if g.error_was_generated or g.first_time_config_triggered or (not g.error_was_generated and g.last_time_error_was_generated):
g.error_was_generated = False
g.first_time_config_triggered = True
await redis_conn.publish(redis_channels.config, "update")
await redis_conn.publish(redis_channels.error_warning, "update")
g.last_time_error_was_generated = g.error_was_generated

def raw_submit_task_execution(submitter:Submitter, flags: List[str], return_dict: dict):
Expand Down
25 changes: 9 additions & 16 deletions client/exploitfarm/xploit.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,6 @@ def repush_flags():
if os.path.exists(".flag_queue.json"):
os.remove(".flag_queue.json")

def config_comp_and_update():
new_conf = deepcopy(g.exec.config.status)
old_conf = g.old_config
for ignore_key in ["server_time", "start_time", "end_time", "submitter", "services", "messages"]:
if new_conf.get(ignore_key, None):
del new_conf[ignore_key]
if old_conf.get(ignore_key, None):
del old_conf[ignore_key]
if new_conf != old_conf:
qprint('--- Config updated! ---')
g.old_config = new_conf
return True
return False

def attack_group_updater(event):
try:
groups = g.exec.config.reqs.groups()
Expand All @@ -281,7 +267,7 @@ def attack_group_updater(event):
qprint(f"Can't get group info from the server: {repr(e)}")
qprint(traceback.format_exc())

def update_server_config(event):
def refetch_config(send_update_config: bool):
try:
g.exec.config.fetch_status()
if g.exec.config.status:
Expand All @@ -302,13 +288,19 @@ def update_server_config(event):
qprint('Server ID changed, restart the exploit')
shutdown(restart=True)
return
if config_comp_and_update():
if send_update_config:
g.exec.config_update_queue.put("update")
except Exception as e:
qprint(f"Can't get config from the server: {repr(e)}")
qprint(traceback.format_exc())
g.exec.info.config_update = False

def update_warnings(event):
refetch_config(send_update_config=False)

def update_server_config(event):
refetch_config(send_update_config=True)

def post_attacks(attacks):
try:
g.exec.config.reqs.submit_flags(attacks, exploit=g.exploit_config.uuid)
Expand Down Expand Up @@ -844,6 +836,7 @@ def start_xploit(

#socket io update stream connection
g.exec.config.skio.on("config", update_server_config)
g.exec.config.skio.on("error_warning", update_warnings)
g.exec.config.skio.on("disconnect", disconnected_from_server)
g.exec.config.skio.on("connect", connected_to_server)
g.exec.config.skio.on("message", skio_message_handler)
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/utils/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const SOCKET_IO_CHANNELS = [
"exploit_source",
"submitter",
"stats",
"config"
"config",
"error_warning"
]

export const DEBOUNCED_SOCKET_IO_CHANNELS = [
Expand All @@ -43,6 +44,10 @@ export const sockIoChannelToQueryKeys = (channel:string):string[][] => {
return [
["clients"]
]
case "error_warning":
return [
["status"]
]
case "attack_group":
return [
["attacks"]
Expand Down
2 changes: 1 addition & 1 deletion tests/xploit_test/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name = "xploit_test"
interpreter = "python3"
run = "main.py"
language = "python"
service = "d6cb61ec-e5e9-4239-be81-e3697eef6b4c"
service = "c8d38285-b20e-410d-becf-b5250cfb12fa"

0 comments on commit 48a41b6

Please sign in to comment.