Consider the following C code: 1 void greet{char *arg) { 2 char buffer (16): 3 p
ID: 3885058 • Letter: C
Question
Consider the following C code: 1 void greet{char *arg) { 2 char buffer (16): 3 printf("I am the Senate. What is your name? *): 4 scanf("%s", buffer): 5 printf("It's treason then, %s " buffer): 6 } 7 8 int main(int argc char *argv[]) { 9 char beg [6] = 'Kenobi': 10 char end [9] = 'maybe not?': 11 strncat(beg, end, 5): 12 greet(argv[1]): 13 return 0: 14 } What is the line number that has a memory vulnerability and what is this vulnerability called? Just before the program executes line 4, the registers are: %esp: 0xBFFFFB20 %ebp: 0xBFFFFB48 Given this information, describe in detail how an attacker would take advantage of the vulnerability. Also make sure to include the address that the attacker needs to over-write. (Maximum 5 sentences) What would you change to fix the problem in part 1? Given the code as is, would stack canaries prevent exploitation of this vulnerability? Why or why not?Explanation / Answer
1. Line number 4,11 has a memory vunerability. Line 11 has vulnerability called buffer overflow. Line number 4 has vulnerability called Stack Smashing.
Explanation: the statement strncat(beg,end,5) tries to concat first 5 charcters of end string to beg which doesn't have enough space since its 6 characters are filled with 'hello' so, in this case it is trying to writes more data to a buffer located on the stack than what is actually allocated for that buffer.
buffer array in function greed has size 16 but if you try to give strings more than 16 it causes stack smashing.
2. The attacker needs to overrite 0xBFFFFFB48 since it will be the return address of the function. he should overwrite the address such a way that from that address he can call a executable code.
3.Modified code
void greet(char *arg)
{
char buffer[16],ch;
int i=0;
printf("I am the senate What is your name? ");
while(i<15 && ch!=' ')
{
scanf("%c",&ch);
buffer[i]=ch;
i=i+1;
}
printf("It's treason then, %s ",buffer);
}
4. Stack Canaries will prevent stack smasing vulnerability because of the following reasons.
Insert a value right in a stack frame right before the stored base pointer/return address – Verify on return from a function that this value was not modified • The inserted value is called a canary, so, in this case our stack smashing will be prevented.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.