Mastering faked-tcp: Network Daemon Internals in fakeroot

Technical Overview

Operating behind the scenes of the standard fakeroot utility, faked-tcp functions as an essential state-tracking backend daemon. Its core purpose is simulating privileged operations—such as file ownership shifts and mode bit modifications—entirely within unprivileged user space. By interposing on standard library calls, it returns mock metadata without requiring true administrative access. In this comprehensive walk-through, we examine how the daemon handles TCP-based state persistence, inspect its operational flags, and test simulated root environments directly via the command line.

Setting Up fakeroot and Locating the Daemon Binaries

To begin evaluating the fake root toolchain, provision the required binaries from the official Ubuntu repositories using sudo apt-get update -qq && sudo apt-get install -y fakeroot.

Update APT repositories and install fakeroot utility

Discover the exact location of the backend server executable on your file system by issuing which faked-tcp || which faked.

⚙️ Daemon Runtime Parameters

--debug : Emits detailed tracing logs covering inter-process communications and state updates.
--foreground : Forces the daemon process to stay attached to the current terminal instead of detaching as a service.
--cleanup : Purges registered shared memory segments and communication handles during shutdown.
--key <키값> : Assigns a distinct session identifier or security token for routing incoming client library connections.
--unknown-is-real : Instructs the daemon to pass through native OS filesystem metadata whenever querying unmapped objects.
--port <포트번호> : Dictates the listening TCP socket port when operating in networked mode (faked-tcp).

Discover the binary path for faked-tcp or faked

Trace which package delivers the resolved binary by querying the local package database with dpkg -S $(which faked-tcp 2>/dev/null || which faked).

Audit the origin package with dpkg search

To review standard invocation syntax along with supported command-line arguments, invoke faked-tcp --help || faked --help.

Display available flags and help documentation

Spawning the Backend Daemon and Inspecting Active Sockets

To launch the TCP-backed state daemon directly as a background process listening on port 12345 with the session key 987654321, run faked-tcp --port 12345 --key 987654321 &.
This manually initialized server session stands ready to log and maintain simulated inode mappings pushed by hooked client libraries.

Start background faked-tcp listener on a custom port

Allow the daemon process a brief window to complete its initialization and socket binding by running sleep 1.

Pause shell execution to allow socket binding

Verify whether the process is actively serving connections on the designated port by inspecting open network endpoints with ss -tulpn | grep 12345 || netstat -tulpn | grep 12345.

Check active TCP listening sockets on target port

Once verification is complete, terminate the running background server and release network resources with killall faked-tcp || killall faked.

Terminate daemon processes and clear network port

Simulating Privileged File Attributes with fakeroot-tcp

Create an isolated staging directory for experimental file manipulation and enter it with mkdir -p /tmp/faked_demo && cd /tmp/faked_demo.

Create sandbox directory under tmp

Generate an empty target file to test virtual privilege modifications with touch test_file.txt.

Generate sample target file

Inspect the unprivileged starting state of the target file using ls -l test_file.txt.
Capturing these native file permissions establishes a baseline against which we can contrast subsequent virtual metadata overrides.

Inspect baseline file permissions and ownership

Launch an encapsulated shell using fakeroot-tcp bash -c 'chown root:root test_file.txt && chmod 700 test_file.txt && ls -l test_file.txt' to reassign ownership to root:root and restrict permissions to 700 (-rwx------).
Behind the curtain, faked-tcp intercepts standard metadata modification calls, presenting the nested subshell with simulated root credentials while the host OS stays completely untouched.

Execute simulated ownership modifications inside virtual session

Evaluate the true state of the filesystem outside the virtualized scope by running ls -l test_file.txt.
You will observe that standard attributes remain unchanged on disk, proving that the simulated alterations were held entirely in the daemon’s internal state tables.

Examine real filesystem attributes outside the virtual environment

Persisting and Restoring Daemon State Across Sessions

Ensure you remain in the staging workspace before executing persistence workflows via cd /tmp/faked_demo.

Navigate to working demonstration path

Export simulated privilege data across invocations with fakeroot-tcp -s fake_state.dat bash -c 'chown 0:0 test_file.txt && chmod 4755 test_file.txt'.
This adjusts the virtual ownership to UID/GID 0:0 with SetUID permissions (4755), while the -s flag instructs the environment to serialize all tracking structures into fake_state.dat before shutting down.

Serialize virtual permissions to disk file

Inspect the underlying layout of the serialized metadata file by viewing its initial entries with cat fake_state.dat | head -n 5.
The file reveals plain-text records mapping target storage devices (dev) and inode identifiers (ino) directly to simulated octal modes (mode=104755) and user IDs (uid=0,gid=0).

Inspect the raw contents of serialized metadata

Reconstitute the saved permissions in a brand-new subshell using fakeroot-tcp -i fake_state.dat bash -c 'ls -l test_file.txt'.
By loading the serialized map via -i, the new environment instantly reflects root ownership and the SetUID bit (-rwsr-xr-x) without altering the host filesystem at any point.

Reload saved environment state to verify reconstructed attributes

Finally, clean up the testing environment and discard temporary artifacts with rm -rf /tmp/faked_demo.

Remove temporary demo directory and test files

Through this exploration, we have traced how the faked-tcp daemon establishes socket communication, manages translated metadata queries, and serializes state mappings across disconnected runs. Mastering these mechanics offers valuable clarity when troubleshooting Debian packaging pipelines, containerized toolchains, and unprivileged archive generation workflows.