Skip to content

Instantly share code, notes, and snippets.

@TheFlash2k
Created December 12, 2021 16:25
Show Gist options
  • Save TheFlash2k/7d70d3d86b3b02a76f43f42ad73d0ed0 to your computer and use it in GitHub Desktop.
Save TheFlash2k/7d70d3d86b3b02a76f43f42ad73d0ed0 to your computer and use it in GitHub Desktop.
A bash script to compile binaries vulnerable to Stack Buffer Overflow
#!/bin/bash
if [[ $# != 1 ]]; then
echo "[!] No arguments provided! Please provide the name of the file that you want to compile!"
echo "Usage: $0 <file_name.c>
exit
fi
out_file=`echo $1 | cut -d '.' -f 1`
echo "[+] Disabling ASLR"
sudo sysctl -w kernel.randomize_va_space=0
echo "[+] Compiling binary for x86 Architecture"
gcc -z execstack -o $out_file $1 -fno-stack-protector -no-pie -m32 2>/dev/null
if [[ $? != 0 ]]; then
echo "[-] Unable to compile the binary. Please install the following libraries:"
echo "sudo apt-get install gcc-multilib"
echo "sudo apt-get install libx11-dev:i386 libx11-dev"
exit
fi
echo "[+] Changing permissions to a SETUID binary"
sudo chown root stack
sudo chgrp root stack
sudo chmod 4755 stack
echo "[*] Successful!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment