cybersecurity · beginner · ~15 min · safe pentest lab

Is the scan target allowed?

Restrict a scanner to loopback.

Challenge

Restrict a scanner to loopback so it can never accidentally touch someone else's host.

Task

Implement int scan_allowed(const char *host) that returns 1 only for the three loopback spellings, else 0.

Allowed hosts: "127.0.0.1", "localhost", "::1".

Input

  • host: a NUL-terminated host string the grader passes.

Output

Returns int: 1 if host is exactly one of the loopback spellings, else 0.

Example

scan_allowed("127.0.0.1")       ->   1
scan_allowed("localhost")       ->   1
scan_allowed("::1")             ->   1
scan_allowed("scanme.example")  ->   0

Edge cases

  • Any non-loopback host returns 0.

Rules

  • Exact string comparison against the three allowed spellings.

Input format

A NUL-terminated host string host.

Output format

An int: 1 for a loopback host, else 0.

Constraints

Allow only 127.0.0.1, localhost, ::1 (exact match).

Starter code

#include <string.h>

int scan_allowed(const char *host) {
    /* TODO */
    return 0;
}

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