Soru

Zorluk: OrtaApplication and Software Vulnerabilities

During a security audit of a native C application, an analyst evaluates a logging routine designed to capture user-submitted feedback. The code snippet under review is as follows:

c
void log_user_feedback(char *user_input) {
FILE *log_file = fopen("/var/log/app_feedback.log", "a");
if (log_file != NULL) {
fprintf(log_file, user_input);
fclose(log_file);
}
}

The analyst notes that input submitted directly by remote users is passed to `fprintf` as the primary formatting parameter without explicit format specifiers. Which of the following application vulnerabilities is directly present in this code?

  1. Format string vulnerabilityCevap
  2. B
    SQL injection
  3. C
    Heap buffer overflow
  4. D
    Improper authorization

Cevap

Format string vulnerability
The correct answer identifies a format string vulnerability. When C functions such as `printf`, `fprintf`, or `sprintf` receive user-controlled input as their format string parameter without explicit specifiers (e.g., `%s`), conversion specifiers embedded within the user data are interpreted by the formatter. This permits memory disclosure and arbitrary memory writes.

Adım Adım Çözüm

1
Analyze the function parameters and standard library call
The function `log_user_feedback` accepts an unvalidated string pointer `user_input` and passes it directly as the second parameter to `fprintf(log_file, user_input)`.
In C library function syntax, `fprintf(stream, format, ...)` expects the second argument to be a conversion control string containing specifiers such as `%s`, `%d`, or `%x`.
2
Evaluate the risk of using user input as the format string
If `user_input` contains format tokens like `%x` or `%n`, `fprintf` evaluates the stack for arguments that were never supplied, reading or writing memory values.
This allows attackers to read internal stack memory (information disclosure) or write to arbitrary memory locations (`%n`), leading to denial of service or remote code execution.
3
Identify the proper vulnerability classification and remediation
The flaw is classified as a format string vulnerability. The appropriate fix is modifying the call to `fprintf(log_file, "%s", user_input)`.
Specifying `"%s"` forces the print routine to treat `user_input` purely as static string data rather than executable formatting instructions.

Anahtar Kavram

Format String Vulnerabilities
Tahmini Süre:1m 15s
Bu soruyu puanla