nerdexam
GIAC

GCIH · Question #322

John works as a C programmer. He develops the following C program: #include <stdlib.h> #include <stdio.h> #include <string.h> int buffer(char str) { char buffer1[10]; strcpy(buffer1, str); return 1…

The correct answer is C. Buffer overflow. The program uses strcpy to copy an unbounded user-supplied argument into a fixed 10-byte buffer, which is a classic buffer overflow vulnerability.

Vulnerability Exploitation & Privilege Escalation

Question

John works as a C programmer. He develops the following C program:

#include <stdlib.h> #include <stdio.h> #include <string.h> int buffer(char *str) { char buffer1[10]; strcpy(buffer1, str); return 1; } int main(int argc, char *argv[]) { buffer (argv[1]); printf("Executed\n"); return 1; } His program is vulnerable to a __________ attack.

Options

  • ASQL injection
  • BDenial-of-Service
  • CBuffer overflow
  • DCross site scripting

How the community answered

(35 responses)
  • A
    3% (1)
  • B
    9% (3)
  • C
    86% (30)
  • D
    3% (1)

Why each option

The program uses strcpy to copy an unbounded user-supplied argument into a fixed 10-byte buffer, which is a classic buffer overflow vulnerability.

ASQL injection

SQL injection involves inserting malicious SQL statements into database queries; this program has no database interaction or query construction.

BDenial-of-Service

While a very large input could crash the program, the specific vulnerability here is the ability to overwrite stack memory and hijack execution, which is a buffer overflow - not simply a denial-of-service condition.

CBuffer overflowCorrect

The function uses strcpy(buffer1, str) to copy argv[1] into a stack-allocated array of only 10 bytes without any length validation. If the input string exceeds 9 characters, it overwrites adjacent stack memory including the saved return address, enabling a buffer overflow attack. An attacker can exploit this to redirect execution flow or execute arbitrary code.

DCross site scripting

Cross-site scripting (XSS) is a web application vulnerability involving injection of malicious scripts into web pages viewed by users; this is a standalone C program with no web or HTML context.

Concept tested: Stack buffer overflow via unsafe strcpy usage

Source: https://owasp.org/www-community/vulnerabilities/Buffer_Overflow

Topics

#buffer overflow#strcpy#stack smashing#memory corruption

Community Discussion

No community discussion yet for this question.

Full GCIH Practice