I am completely lost with this. I know I have to use a buffer overflow in order to get char 'c' to be the pointer address of ptr, but I have no idea how.
/*
* Task: Print out "Wecome to overflow!"
* Setup: You need to first run the command below (Note, system will ask your sudo password after running it)
* echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
* Hint:
* You can compile this code on ubuntu using the following command "gcc -fno-stack-protector -m32 -o hw hw.c"; note that you will need to run command "sudo apt-get install gcc-multilib" and then enter 'Y' before compiling your code using the aforementioned command
* Submission: a screenshot with commands like echo -e -n 'abcddd\x11\x1A' > tmp
*/
#include <stdio.h>
int main(){
int a = 10;
char *ptr;
char c = 'X';
char array[4];
char array2[] = {'X', 'Y', 'Z'};
ptr = &c;
printf("please enter: \n");
scanf("%s", array);
/* The following is just for the purpose of debugging */
printf("ptr is 0x%x \n", (unsigned int)ptr);
printf("addr of array2[1] is %p \n", &array2[1]);
*ptr = '5';
if (array2[1] == '5') {
printf("Welcome to overflow!\n");
} else {
printf("This is normal output!\n");
}
}