cybersecurity · intermediate · ~15 min · safe pentest lab
Recognize an injection attempt for logging / alerting purposes.
Flag input that carries shell metacharacters — an indicator you can log or alert on when watching for command-injection attempts.
Implement int contains_shell_special(const char *s) that returns 1 if s contains any of these shell metacharacters, else 0:
; & | ` $ ( ) < > \n
s: a NUL-terminated string the grader passes (a candidate command or argument).Returns int: 1 if any listed metacharacter is present, 0 otherwise.
contains_shell_special("hello") -> 0
contains_shell_special("ls; rm -rf /") -> 1
contains_shell_special("echo `whoami`") -> 1
contains_shell_special("echo $HOME") -> 1
execvp with an explicit argv array — never escape-and-allow.A NUL-terminated string s (a candidate command/argument).
An int: 1 if s contains any shell metacharacter, else 0.
Detection only — do not attempt to sanitise the input.
int contains_shell_special(const char *s) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.