cybersecurity · intermediate · ~15 min · safe pentest lab

Suspicious request path?

Flag traversal indicators in a path.

Challenge

Flag an HTTP request path that shows path-traversal indicators — useful when reviewing captured (authorised) traffic for probing attempts.

Task

Implement int is_suspicious_path(const char *path) that returns 1 if path contains "../" (traversal) or "etc/passwd", and 0 otherwise.

Input

  • path: a NUL-terminated request path the grader provides.

Output

Returns 1 if either marker is present, 0 otherwise.

Example

is_suspicious_path("/files/../../etc/passwd")   ->   1
is_suspicious_path("/index.html")               ->   0

Edge cases

  • A clean path with neither marker returns 0.

Input format

A NUL-terminated request path.

Output format

1 if path contains "../" or "etc/passwd"; otherwise 0.

Constraints

Substring tests for "../" and "etc/passwd".

Starter code

#include <string.h>

int is_suspicious_path(const char *path) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.