Hi,
I want to get shell by exploiting a BOF vulnerability in a simple c code. My problem is that there is a canary guard in the code which does not let to change the memory from buffer -> "ret" address of function just like classic BOF exploits. However, I think there is another mistake in this code. The author has not used the global variable (I mean 'i') therefore, i is copied above the stack like buffer and other arguments. Thus, by changes both the canary and i variable the check should be bypassed!(This is what I think and may be wrong!). I tried to write an exploit for this code but the value of i does not change. If(as I think) the stack is like this:
[ buffer ][canary][sfp][ret][*arg]
then by overwriting a string of 600 or longer the value of i should be changed! but it does not change!! 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/ptrace.h>
int vulnerable(char *arg, unsigned char i)
{
unsigned char canary;
char buffer[512];
canary = i;
strcpy(buffer,arg);
if (canary!=i)
{
printf("Stack protection!\n\n");
exit(200);
}
return 0;
}
int main(int argc, char *argv[])
{
unsigned char i=0;
srand(time(NULL));
i = rand() % 10;
if (argc<2)
{
fprintf(stdout,"Synopsis: vuln <message>\n\n");
exit(1);
}
vulnerable(argv[1],i);
printf("End.\n");
return 0;
}