[Software and System Security] Integer overflow, format string, and array out-of-bounds access vulnerabilities

1. Integer overflow

Integer representation

Insert image description here
Original code, inverse code and complement code represent:
Insert image description here
For positive numbers, the original code, inverse code and complement code are themselves. The original code of a negative number is itself, the complement code is the inversion of all bits of the original code except the sign bit, and the complement code is the complement code plus 1.
Insert image description here
CF is the unsigned overflow flag, and OF is the signed overflow flag. Even if the addition/subtraction of signed numbers results in CF=1, it is meaningless and cannot indicate whether the result is correct or not. At this time, OF=1 means the result overflows and an error occurs; OF=0 means the result is correct. This process has nothing to do with CF at all. CF=1/0 will not affect it.

This shows that different pointer types have different "interpretations" of a number.

Example

Type conversion leads to overflow.
Insert image description here
Failure to pay attention to upper bound
Insert image description here
overflow leads to infinite loop
Insert image description here
complement range problem
Insert image description here
. Return to itself. . . .
May cause buffer overflow
Insert image description here

protection

  1. IntScope
    Insert image description here
  2. IntPatch detects and fixes subsequent buffer overflows

2. Format string vulnerability

Insert image description here
When the stack grows from high to low, the order of pushing onto the stack is input actual parameters (from right to left), return address RA EBP, and local variables (in order). When pushing onto the stack, the
address of the formatted string is first placed (regarded as arg1 in the figure). Then put the actual parameter address
printf() to sequentially display the contents of the address behind the format parameter in the stack based on the number of format print format%, moving one word (4 bytes) each time.
Insert image description here
The input is "hello world" and printing is normal; if the string you want to print happens to have formatting characters such as "%d" and "%x", then the parameter value of a variable will be taken from the stack.
There is no parameter after it, but printf thinks there is a parameter after it, so it will print the 4 bytes corresponding to the current stack (should be the high address) as %x. With specific designs, memory information at specific locations can be printed.
Insert image description here

Insert image description here
If it is %s, you can read any memory length (from low byte to high byte)

Insert image description here
What if it is %n
Insert image description here

3. Array out-of-bounds access vulnerability

Overflow and out-of-bounds are not exactly equal. Array out-of-bounds is divided into two situations: read/write, while overflow vulnerabilities belong to out-of-bounds writing.
The essence of some overflow vulnerabilities is array out-of-bounds.

produce

Insert image description here

Example

**CVE-2014-0160 "OpenSSL Array Out-of-Bounds Access Vulnerability" (Heartbleed) **
Insert image description here

Guess you like

Origin blog.csdn.net/qq_39679772/article/details/124890705