I am new to buffer overflow attacks and I am trying to do the same on a sample c code which I have.
- I have three variables a, b and buffer.
- a and b have values assigned to them in the code itself. buffer interactively takes user input. The value of 'buffer' is not taken from the argument.
- My intention is to overflow buffer such that it will overwrite b with a desired value. Overwriting EIP or ESP is not the intention here.
- With gdb I was able to figure out that if I pass on a certain number of values it would overwrite the value of variable b.
- However I am stuck here as gdb doesn't allow me to type or paste the ASCII characters which corresponds to the desired value of b. For example consider 1356 is the desired value. The hex for the same is 0x0000054C. So to overwrite b, I should give in the ASCII of 4C, 05, 00 and 00 in gdb as the last four bytes of the input respectively. Unfortunately this is not possible.
- Another way which I found on web is to pass the hex values using perl. However this method pipes the perl output to the code argument. The variable which I am overflowing here takes it's value from user input while executing the program interactively and not the from the program argument.
Is there a way to pass hex values to non-argument parameters to perform stack based buffer overflow?