I am on Ubuntu Linux 16.04/Intel with ASLR turned off.
The below programme is exploited.
#include <stdio.h>
#include <string.h>
void func(char *name)
{
char buf[100];
strcpy(buf, name);
printf("Welcome %s\n", buf);
}
int main(int argc, char *argv[])
{
func(argv[1]);
return 0;
}
It is built with.
$ gcc buf.c -o buf -fno-stack-protector -mpreferred-stack-boundary=2
I can successfully overflow the buffer and overwrite the return address when using 7-bit characters (?) like below.
gdb-peda$ run $(python3 -c 'print("\x41" * 108)')
However, it doesn't work correctly when I try to insert an 8-bit character (?).
gdb-peda$ run $(python3 -c 'print("\xc0" * 108)')
There seems to be some kind of UTF-8 encoding on the way, so \xc0 becomes \xc3\x80.
I tried running
gdb-peda$ run $(python3 -c 'print(("\xc0".encode("latin1") * 108))')
This does something messed up.. In any case, the return address is not overwritten successfully.
Stuck and any pointers would be much appreciated.


