diff --git a/sondib/compose.yml b/sondib/compose.yml index 6ba270b..af12796 100755 --- a/sondib/compose.yml +++ b/sondib/compose.yml @@ -27,7 +27,7 @@ services: mem_limit: 2g pids_limit: 64 healthcheck: - test: ["CMD", "/app/bin/sdb", "list", "127.0.0.1"] + test: ["CMD", "/app/bin/sdb", "search", "127.0.0.1", "__healthcheck_nonexistent__"] interval: 10s timeout: 5s retries: 5 diff --git a/sondib/patch_sondibd.py b/sondib/patch_sondibd.py index 1076759..fe79050 100644 --- a/sondib/patch_sondibd.py +++ b/sondib/patch_sondibd.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 """Apply security guards to the bundled sondibd binary. -The repository ships the service as a release binary. The patch fixes -session resume ownership, skips deleted records during SID lookup, and -filters private/deleted records from unauthenticated search responses. +The repository ships the service as a release binary. The patch removes +implicit admin access from fresh connections, fixes session resume ownership, +skips deleted records, and filters private/deleted search results. """ from __future__ import annotations @@ -19,6 +19,8 @@ MATCH_VA = 0x404154 SEARCH_HELPER_VA = 0x40410C SEARCH_CALL_VA = 0x402ACA RESUME_VA = 0x403467 +CONN_INIT_VA = 0x402045 +UNAUTH_CAVE_VA = 0x40412D GUARD_SIZE = 0x20 OLD_GUARD = bytes.fromhex( @@ -46,6 +48,14 @@ FIXED_RESUME = bytes.fromhex( "74 0c 48 89 e9 48 89 c5 3b 10 74 0c " "eb eb e9 1e 02 00 00 90 90 90 90 90" ) +OLD_CONN_INIT = bytes.fromhex("89 57 04 89 57 20") +FIXED_CONN_INIT = bytes.fromhex("e8 e3 20 00 00 90") +OLD_UNAUTH_CAVE = b"\x90" * 15 +FIXED_UNAUTH_CAVE = bytes.fromhex( + "c7 47 04 ff ff ff ff " # conn.user = -1 + "c7 47 20 00 00 00 00 " # conn parser state = 0 + "c3" +) def file_offset(virtual_address: int) -> int: @@ -60,12 +70,16 @@ def patch(path: Path) -> None: search_helper_offset = file_offset(SEARCH_HELPER_VA) search_call_offset = file_offset(SEARCH_CALL_VA) resume_offset = file_offset(RESUME_VA) + conn_init_offset = file_offset(CONN_INIT_VA) + unauth_cave_offset = file_offset(UNAUTH_CAVE_VA) guard = bytes(data[guard_offset:guard_offset + GUARD_SIZE]) branch = bytes(data[match_offset:match_offset + len(OLD_BRANCH)]) entry = bytes(data[entry_offset:entry_offset + len(ENTRY_JUMP)]) search_helper = bytes(data[search_helper_offset:search_helper_offset + len(SEARCH_HELPER)]) search_call = bytes(data[search_call_offset:search_call_offset + len(OLD_SEARCH_CALL)]) resume = bytes(data[resume_offset:resume_offset + len(OLD_RESUME)]) + conn_init = bytes(data[conn_init_offset:conn_init_offset + len(OLD_CONN_INIT)]) + unauth_cave = bytes(data[unauth_cave_offset:unauth_cave_offset + len(OLD_UNAUTH_CAVE)]) if branch == bytes.fromhex("74 ca"): changed = False @@ -90,6 +104,12 @@ def patch(path: Path) -> None: changed = True elif resume != FIXED_RESUME: raise SystemExit(f"unexpected sondibd resume bytes in {path}") + if conn_init == OLD_CONN_INIT and unauth_cave == OLD_UNAUTH_CAVE: + data[conn_init_offset:conn_init_offset + len(FIXED_CONN_INIT)] = FIXED_CONN_INIT + data[unauth_cave_offset:unauth_cave_offset + len(FIXED_UNAUTH_CAVE)] = FIXED_UNAUTH_CAVE + changed = True + elif conn_init != FIXED_CONN_INIT or unauth_cave != FIXED_UNAUTH_CAVE: + raise SystemExit(f"unexpected sondibd connection-init bytes in {path}") if changed: path.write_bytes(data) return @@ -99,6 +119,8 @@ def patch(path: Path) -> None: raise SystemExit(f"unexpected sondibd search-filter bytes in {path}") if resume != OLD_RESUME: raise SystemExit(f"unexpected sondibd resume bytes in {path}") + if conn_init != OLD_CONN_INIT or unauth_cave != OLD_UNAUTH_CAVE: + raise SystemExit(f"unexpected sondibd connection-init bytes in {path}") # je 0x404120; then skip track+0x21d when it is non-zero. guard_code = bytes.fromhex( @@ -112,6 +134,8 @@ def patch(path: Path) -> None: data[search_helper_offset:search_helper_offset + len(SEARCH_HELPER)] = SEARCH_HELPER data[search_call_offset:search_call_offset + len(FILTERED_SEARCH_CALL)] = FILTERED_SEARCH_CALL data[resume_offset:resume_offset + len(FIXED_RESUME)] = FIXED_RESUME + data[conn_init_offset:conn_init_offset + len(FIXED_CONN_INIT)] = FIXED_CONN_INIT + data[unauth_cave_offset:unauth_cave_offset + len(FIXED_UNAUTH_CAVE)] = FIXED_UNAUTH_CAVE path.write_bytes(data)