Lab 6.1 Linux Buffer Overflow Command Injection
Lab 6.1 Linux Buffer Overflow Command Injection
extra
credit)
What You Need
A 32-bit x86 Kali 2 Linux machine, real or virtual.
Purpose
To develop a very simple buffer overflow exploit in Linux, using injected shell commands.
nano buf.c
#include <string.h>
#include <stdio.h>
main(){
char name[200];
printf("What is your name?\n");
scanf("%s", name);
bo(name, "uname -a");
}
Execute this command to compile the code without modern protections against stack overflows, and with debugging symbols:
That means gcc is not properly installed, which was the case on my Kali 2017.3 machine.
./buf
The program prints out the location of the Name buffer and the command buffer, says "Goodbye", and excutes the command "uname -a", as shown below.
Observing a Crash
Execute this command:
./buf
./buf
Enter:
The program attempts to execute the command EEEEEEEEEE, as shown below. So any text we put in place of EEEEEEEEEE will execute.
Executing the "ls" command
Execute this command:
./buf
Enter ten 'A' characters, then ten 'B' characters, then ten 'C' characters, then ten 'D' characters, then ls
The program executes the "ls" command, showing the files in your working directory, as shown below.
Press the PrintScrn key to copy the whole desktop to the clipboard.
Save the document with the filename "YOUR NAME Proj 1a", replacing "YOUR NAME" with your real name.
Hint
If spaces are annoying you, try using $IFS to replace them.
Press the PrintScrn key to copy the whole desktop to the clipboard.
Save the document with the filename "YOUR NAME Proj 1b", replacing "YOUR NAME" with your real name.
nc attack32direct.samsclass.info 1055
/home/p1x/winners
/home/p1x/updatenow
After one minute, your name will appear on the WINNERS page here:
http://attack32direct.samsclass.info/p1x-winners.html
Hint
The injected commands run in the Bourne shell (sh), not the bash shell. You can test commands on your local Mac or Linux box by using the sh
command to open a Bourne shell.
Troubleshooting
If you have network problems, you can check the local network connections at this page:
http://attack32direct.samsclass.info/netstat.htm
Save the document with the filename "YOUR NAME Proj 1c", replacing "YOUR NAME" with your real name.
Sources
I based this on the "pwn1" and "pwn2" challenges in the 2015 SCTF competition.