This is a simplified llvm Stackprotector which can only run on the x86_64 machine, if you want to build this project on your own machine, you can follow the following steps:
-
You should make sure that llvm is properly built on your machine. The tuotorial can be found from the link
-
First, clone the git repository into your workspace
git clone https://github.com/bin2415/llvm-stack-guard.git
- Second, mkdir a dirtory named build and cmake in it
mkdir build && cd ./build
cmake ../
make
-
Then, you can find a .so file in /build/SSPPass/
-
In test folder, you can find the test file named stack_example.c
-
Compile it through clang
clang -S -emit-llvm -o stack_example.ll stack_example.c
- Use the pass to protect stack.
opt -load ../build/SSPPass/libSSPass.so -SSPPass stack_example.ll -S -o stack_example_protect.ll
- Use the llc tool to generate .o file
llc -filetype=obj stack_example_protect.ll -o stack_example_protect.o
- Use clang to generate a binary file
clang -o stack_example_llvm stack_example_protect.o
- Run the example file and input 111111111111111111111111 to corrupt the program
./stack_example_llvm
111111111111111111111111111111111
And the result is shown as belows:
- You can disassemble the binary to find code that implement the stack smashing protect
objdump -S stack_example_llvm > stack_example_llvm.s
vi stack_example_llvm.s
Enjoy doing it!