cybersecurity · beginner · ~15 min
Heuristic flag for suspicious fd targets.
Symlinks under /proc/PID/fd/ resolve to strings like:
/usr/bin/cat — a regular file (normal)socket:[12345] — a socketpipe:[12345] — a pipeanon_inode:[eventfd] — eventfd / timerfd / signalfd/dev/null — /dev/null/etc/shadow — a sensitive system file (suspicious!)/proc/PID/mem — the memory of another process (suspicious!)Implement int classify_fd_target(const char *target) returning:
1 for /etc/shadow or anything starting with /proc/ that isn't
/proc/self/ (other-process forensics is suspicious)0 for everything else./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.
Symlink target string.
0/1.
String prefix logic.
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.