cybersecurity · beginner · ~15 min
Heuristic flag for suspicious fd targets.
Flag a process's open-file descriptor as suspicious based on where its /proc/PID/fd/ symlink points — a basic forensic heuristic.
Those symlinks resolve to strings such as /usr/bin/cat (a regular file), socket:[12345], pipe:[12345], anon_inode:[eventfd], /etc/shadow (a sensitive system file), or /proc/PID/mem (another process's memory).
Implement int classify_fd_target(const char *target) that returns:
1 if target is exactly /etc/shadow, or starts with /proc/ but is not under /proc/self/ (inspecting another process is suspicious);0 for everything else.target: a fixed symlink-target string the grader provides (NUL-terminated; may be empty or NULL).Returns 1 if the target is suspicious, 0 otherwise.
classify_fd_target("/usr/bin/cat") -> 0
classify_fd_target("/etc/shadow") -> 1
classify_fd_target("/proc/1234/mem") -> 1 (another process)
classify_fd_target("/proc/self/status") -> 0 (self-inspection is fine)
classify_fd_target("socket:[12345]") -> 0
classify_fd_target("") -> 0
classify_fd_target(NULL) -> 0
/proc/self/... is normal self-introspection: return 0.NULL: return 0./proc/PID/fd/ symlinks point at whatever the process has open — files, sockets, pipes, eventfds. A defender's tool flags any fd that resolves to a suspicious path.
A fixed symlink-target string (NUL-terminated; may be empty or NULL).
1 if target is /etc/shadow or /proc/ but not /proc/self/; otherwise 0.
String prefix logic; NULL-safe.
int classify_fd_target(const char *target) { /* TODO */ (void)target; return 0; }
Flagging /proc/self/* (that's normal — process inspecting itself).
Empty string; exactly '/proc' (no trailing slash).
O(strlen).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.