SWS Experiment no 3 (*UPDATED)

AIM - To Simulate the Buffer overflow attack.

#pragma check_stack(off)
#include <string.h>
#include <stdio.h>
void foo(const char* input)
{
   char buf[10];
 printf("My stack looks like:\n%p\n%p\n%p\n%p\n%p\n% p\n\n");
 strcpy(buf, input);
 printf("%s\n", buf);
printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
}
void bar(void)
{
   printf("Augh! I've been hacked!\n");
}
int main(int argc, char* argv[])
{
   printf("Address of foo = %p\n", foo);
   printf("Address of bar = %p\n", bar);
   if (argc != 2)
{
       printf("Please supply a string as an argument!\n");
       return -1;
}
foo(argv[1]);
   return 0;
}



Output:


SWS Experiment no 3 (*UPDATED) SWS Experiment no 3 (*UPDATED) Reviewed by akshay salve on 12:33 PM Rating: 5

No comments:

Powered by Blogger.