312-49V10 practice question 29 of 35

Kyle is performing the final testing of an application he developed for the accounting department. His last round of testing is to ensure that the…

Full set: 699 questions
Kyle is performing the final testing of an application he developed for the accounting department. His last round of testing is to ensure that the program is as secure as possible. Kyle runs the following command. What is he testing at this point? #include #include int main(int argc, char *argv[]) { char buffer[10]; if (argc < 2) { fprintf (stderr, "USAGE: %s string\n", argv[0]); return 1; } strcpy(buffer, argv[1]); return 0; }
Answer options
A: Buffer overflow Correct answer
B: SQL injection
C: Format string bug
D: Kernal injection
Correct Answer:
A. Buffer overflow
Explanation

The provided C code contains a classic stack-based buffer overflow vulnerability. The strcpy function is used to copy the first command-line argument (argv[1]) into a fixed-size character array (buffer) of 10 bytes. The strcpy function does not perform bounds checking and will continue to copy data from the source until a null terminator is found. If an input string longer than 9 characters (plus one for the null terminator) is provided, strcpy will write past the end of the buffer, corrupting adjacent memory on the stack. This can lead to a program crash or be exploited to execute arbitrary code. Kyle is testing for this specific vulnerability.

Why Incorrect

B. SQL injection: This attack targets applications that interact with a database. The provided code does not perform any database operations.
C. Format string bug: This vulnerability arises when user-controlled input is used as the format string in functions like printf(). This code does not do that.
D. Kernel injection: This involves injecting code into the OS kernel. The vulnerability shown is in a user-space application, not the kernel itself.

References

1. CERT C Secure Coding Standard. (2016). Software Engineering Institute, Carnegie Mellon University. Rule STR31-C, "Guarantee that storage for strings has sufficient space for character data and the null terminator," explicitly warns against using unbounded string functions like strcpy(), as they are a common source of buffer overflows.

2. Erickson, J. (2008). Hacking: The Art of Exploitation, 2nd Edition. No Starch Press. Chapter 0x300, "Exploiting Stack-Based Buffer Overflows," (pp. 86-90) uses nearly identical C code examples with strcpy() to demonstrate the fundamental mechanism of a stack buffer overflow. This book is frequently used as a textbook in university-level security courses.

3. Howard, M., & LeBlanc, D. (2003). Writing Secure Code, 2nd Edition. Microsoft Press. Chapter 5, "Public Enemy #1: The Buffer Overrun," (pp. 126-129) identifies strcpy() as a "banned function" precisely because it enables buffer overruns by not checking the size of the destination buffer.

4. MIT OpenCourseWare. (2014). 6.858 Computer Systems Security, Fall 2014. Lecture 2 Notes: "Control-flow hijacking attacks." Section 2, "Stack buffer overflows," describes how functions like gets() and strcpy() can be used to write past the end of a buffer on the stack to overwrite control data, such as the return address.

Scroll to Top