Format String Theory Flashcards

1
Q

What are the format strings?

A

They make possible for the programmer to include variables in a string format as he likes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the key elements in a format string?

A

The placeholders which specify how data is formatted into a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are some examples of format print functions?

A

They are:

  • Printf
  • fprintf
  • sprintf
  • snprintf
  • vfprintf
  • vsprintf
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the parameters passed to the format print functions?

A

snprintf(buf, buf_size, “string + placeholders”, placeholder_values)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does a format print function and the placeholders parameters relate

A

When the format string is parsed, the function expects The parameters values to replace the placeholders

According to the convention, these are expected to be pushed on to the stack by the caller

The function, therefore, expects the placeholder values to be on the stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens when we do not place the placeholder values at the end of the format print functions

A

The function reads the values in the stack, even if they were not expected to be used in such way

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

We can also insert in the stack some contents through the format string functions. How can we find out in which position in the stack they were placed?

A

We can scan the stack with the %N$x syntax, which goes to the Nth parameter, along with a simple shell script

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can we use the scan on the stack as an information leakage vulnerability

A

By searching interesting in the memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can we write on the stack?

A

By using the %n placeholder, which writes in the address pointed by the argument, the number of chars printed so far

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can we use the format strings to write on the stack?

A

First, we put the address of the memory cell that we want to modify on the stack, then we use the %x to go find it on the stack (%N$x). Finally, we use the %n to write on the target address placed in the stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can we write a valid address on the stack

A

We use python to emit non-printable chars

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do we write in there arbitrary number that we can control?

A

We use the %c Parameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the detailed steps to write an arbitrary number into a target address?

A

First, you put the target address on the stack as part of the format string, then you find it on the stack using the %N$x along with a shell script and finally you use the %c and %n to write a specific number to the target address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the problem in writing 32 bit addresses?

A

The size of the number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can we write a 32 bit address

A

We split each DWORD (32 bits) into two WORDs (16 bit), and write then two rounds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the steps to write a 32 bit address to the target address

A

First, we put the two target addresses of the memory cells to modify as part of the foreman string, then we use the %N$x to find the position of the placed target address one (the position of the target address two will be the position of target address one+1). Finally we use %c and %n two right the lower and higher portions of the 32 bit address

17
Q

What is the rational behind the size of the numbers to be written as part of the 32 bit address And the format string exploit

A

Since we are using the %c to control the number of chars printed and because of that we cannot reduced the number of chars printed we need to first place portion of the 32 bit address with the lower value then the higher one.

These difference in the order Of inserted values is done, mainly by exchanging addresses order in the stack