Question

In: Computer Science

How format string vulnerabilities can be exploited for buffer overflow attacks?

How format string vulnerabilities can be exploited for buffer overflow attacks?

Solutions

Expert Solution

Answer::

Buffer overflow attacks are considered to be the most insidious attacks in Information Security.Due to buffer flow attack the attacker could execute your code. Buffer overflow attacks are analogous to the problem of water in a bucket. For example, when more water is added than a bucket can hold, water overflows and spills.

Due to this, we can lost our data and it could leads to inefficient user application with so many flaws.

The Format String exploit occurs when the submitted data of an input string is evaluated as a command by the application.In this way the attacker could read ,execute or cause a memory fault in memory while running application.

  • Components of format string
  1. The Format Function is an ANSI C conversion function, like printf, fprintf, which converts a primitive variable of the programming language into a human-readable string representation.
  2. The Format String is the argument of the Format Function and is an ASCII Z string which contains text and format parameters, like: printf (“The magic number is: %d\n”, 2020);
  3. The Format String Parameter, like %x %s,%n defines the type of conversion of the format function.

The attack can be executed if the application doesn't properly validate the input.Suppose you are passing a format parameter %s  to a format function,and the conversion specified in the parameters is executed.But if format function want more arguments and if you not supplied then attacker could able read stack or execute stack.

So stop attacker being execute or read stack you have to pass well-crafted input to the format function in the form of format string.

Attackers will usually look out for functions such as:

  1. strcpy
  2. strncpy
  3. strcat
  4. sprint
  5. scanf
  6. fgets
  7. gets
  8. getws
  9. memcpy
  10. memmove

All these functions are used for moving data between memory locations and are usually mishandled by the developer.

Below are some format parameters which can be used and their consequences:

•”%x” Read data from the stack

•”%s” Read character strings from the process’ memory

•”%n” Write an integer to locations in the process’ memory

Example of vulnerability:

Suppose if you want to print username using printf() function and if you use printf(username) the this kind of statement vulnerable to the attacker and he could execute or read the stack.

Example::

#include  <stdio.h> 
void main(int argc, char **argv)
{
        // This line is safe
        printf("%s\n", argv[1]);

        // This line is vulnerable
        printf(argv[1]);
}

Explaination::

Safe Code

The line printf("%s", argv[1]); in the example is safe, if you compile the program and run it:

"Say hii! %s%s%s%s"

The printf in the first line will not interpret the “%s%s%s%s” in the input string, and the output will be: “Say hii! %s%s%s%s”

Vulnerable Code

The line printf(argv[1]); in the example is vulnerable, if you compile the program and run it:

./example "Hello World %s%s%s%s%s%s"

The printf in the second line will interpret the %s%s%s%s%s%s in the input string as a reference to string pointers, so it will try to interpret every %s as a pointer to a string, starting from the location of the buffer (probably on the Stack). At some point, it will get to an invalid address, and attempting to access it will cause the program to crash.


Related Solutions

How integer overflow can be exploited for buffer overflow attacks?
How integer overflow can be exploited for buffer overflow attacks?
Research on buffer overflow attacks. How do the various types of overflow attacks differ? When did...
Research on buffer overflow attacks. How do the various types of overflow attacks differ? When did they first start to occur? What can they do and not do? What must a programmer do to prevent a buffer overflow? Answer briefly in your own words.
Research buffer overflow attacks and develop a timeline of major attacks. Comment on why the buffer...
Research buffer overflow attacks and develop a timeline of major attacks. Comment on why the buffer overflow vulnerability still exists
Windows vulnerability that has been exploited widely, such as the SQL Injection, Buffer Overflow. a) What...
Windows vulnerability that has been exploited widely, such as the SQL Injection, Buffer Overflow. a) What windows vulnerability in SQL Injection is and explain with references? b) What windows vulnerability in Buffer Overflow is and explain with references? c) What the weakness windows was and how it was exploited? d) What was the impact to society and economy?
How can buffer overflows be avoided and what are the steps involved in a buffer overflow...
How can buffer overflows be avoided and what are the steps involved in a buffer overflow exploit? What are some of the C functions susceptible to buffer overflow?
What is an NX (no-execute) bit, and how can it be used to counter buffer overflow...
What is an NX (no-execute) bit, and how can it be used to counter buffer overflow attacks?
Discuss how a stack buffer overflow attack is implemented.
Discuss how a stack buffer overflow attack is implemented.
Select the item below that best describes a buffer overflow and how is it used against...
Select the item below that best describes a buffer overflow and how is it used against a web server? a. A buffer overflow occurs when more data is sent to an input buffer field than its size. This can be used to overwrite the stack with malicious code and a return pointer to the malicious code. b. A buffer overflow is caused over a network when there is a mismatch in the processing rates between the two entities involved in...
How would you correct this function in C to prevent buffer overflow using the fgets() function...
How would you correct this function in C to prevent buffer overflow using the fgets() function and strncat() function void nameBuilder() {    char fname[10];    char lname[10];    char fullname[20];    printf("Enter your first name: ");    scanf("%s", fname);    printf("Enter your last name: ");    scanf("%s", lname);    strcat(fullname, fname);    strcat(fullname, " ");    strcat(fullname, lname);    printf("Welcome. %s\n", fullname);    return; }
What properties would make a buffer overflow condition in a program exploitable or useful to an...
What properties would make a buffer overflow condition in a program exploitable or useful to an attacker?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT