Question
Having the program below called exploit.c : #include #include #include #include #include /* * a toy program for learning stack buffer * overflow exploiting *
Having the program below called exploit.c:
#include
#include
#include
#include
#include
/*
* a toy program for learning stack buffer
* overflow exploiting
* It reads a list of hex data from the
* specified file, and performs bubble sorting
*/
uint32_t n = 0, c = 0, d = 0, v = 0, swap = 0;
FILE *fp = NULL;
void Sort()
{
uint32_t array[5];
printf(".txt file contains: ");
char line[sizeof(uint32_t) * 2 + 1] = {0};
while(fgets(line, sizeof(line), fp))
{
if (strlen((char *)line) > 1)
{
sscanf(line, "%x", &(array[n]));
printf("%x ", array[n]);
++n;
}
}
fclose(fp);
#if 1 //Change this 1 to a 0 and recompile if you do not want the function to sort your values.
for (c = 0; c < (n - 1); c++)
{
v = c;
for (d = ( c + 1 ); d < n; d++)
{
if (array[d] < array[v])
{
// Swap the found minimum element with the first element
swap = array[d];
array[d] = array[v];
array[v] = swap;
}
}
}
#endif
// output sorting result
printf(" Sorted list in ascending order: ");
for ( c = 0 ; c < n ; c++ )
printf("%x ", array[c]);
}
int main(int argc, char **argv)
{
if(argc!=2)
{
printf("Usage: ./exploit file_name ");
return -1;
}
fp = fopen(argv[1], "rb");
Sort();
return 0;
}
I need to figure out the required amount of padding to construct an attack to exploit the program above. But I'm not sure how to find the padding and what it is. Could you please give some help?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started