Demonstrate a simple buffer overflow

Assignment Help Computer Engineering
Reference no: EM133678499 , Length: word count:2400

Task 1

Overview

Buffer overflow is a notorious vulnerability which was first reported in 1988 involving the Morris worm. One of the causes of buffer overflow is the lack of input bound check. A recent buffer overflow vulnerability was recorded for the Linux Kernel Ceph file system driver (Torvalds, 2023). See the following link for details.

A clear understanding of how buffer overflows happen can be demonstrated using a simple program that accepts input from the user. Examine the provided C file, below, and practice using it. Compile* it and run it to test its operation. The program is a game to be run from the command line. It takes your name which you can enter when prompted.

Task
(a) Examine the operation of this file.
• Through simple static analysis, show the addresses that are important for understanding the operation of this program.
• Run the program in GDB. Set breakpoint(s) at the most appropriate place. Display information about the stack before and after the buffer overflow with corresponding addresses. From the raw data, identify and annotate which parts of the stack correspond to what. Identify all elements that make up the stack, covering at least one whole stack frame in size. Identify which other elements are a potential target for exploitation.

(b) Demonstrate a simple buffer overflow so that you always win the game, but you do not cause the program to crash. Show the input byte stream and the method used to achieve this exploit. Annotate and explain this input byte stream.

* Assume any ASLR is disabled, the stack is executable, and there are no stack canaries or other optimisations to the code on compilation.
C code: co7605_portfo_ex1.c - This is the source code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#define MAX_NAME_SIZE 256
void prepare_random_num_generator(void);
void game(void)
{ int number; // to hold the random number
char buffer[24]; // to hold the player's name
// Get a random number (from 0 to RAND_MAX)
number = rand();
printf("Please enter your name: ");
fgets(buffer, MAX_NAME_SIZE, stdin); // input from 'Standard In'
printf("Welcome "); //
printf(buffer); //
if (number < (int)(RAND_MAX/20)) // Only win one time in 20
{
printf("YOU WIN!");
}
else
{
printf("YOU LOSE... too bad.");
}
printf("\n"); // 'End of line' / 'Newline' character
return;
}
int main(void)
{
// Program starts here.
// Prepare the random number generator
prepare_random_num_generator();
game();
return 0;
}
// ------------------------------------------------------------------------
void prepare_random_num_generator(void)
{
struct timeval tv; gettimeofday(&tv,
NULL);
srand(tv.tv_usec);
return;
}
// ------------------------------------------------------------------------

Task 2

Overview
Demonstrate stack overflow and direct code execution using a C source code. The program is a server which listens on a chosen port number and waits for an incoming TCP connection from a client. The server prompts and then takes an input from the client and returns a welcome message with the inputted string. The C source code is provided below and on Moodle.

Task
(a) Compile the provided C code co7605_portfo_ex2.c into executable* in the following versions:
• Compile the C code so that the stack is executable and there are no stack canaries or other optimisations to the code.
• Compile the C code so that the stack is not executable, includes stack canaries, and full optimisation to the code.
* Take note that the C code has a header file co7605_portfo_ex2.h
(b) Run** both executables normally to test their operation.
(c) Demonstrate stack overflow with machine code injection delivered via a client for the two binaries.
In doing this you should:
• Do simple static analysis on each of the server binaries to identify critical information for this exercise.
• Use a debugger on the server binaries to identify and detail the call stack locations of importance in achieving this task, and the placement of the injected code. Annotate the call stack etc.
• Construct some code to write a message to screen on each target server using either a call to a library that is already loaded, for example the printf family of functions in libc, or, by doing a write system call. After leaving the message, demonstrate the return of control flow back to the server code, or exit the program safely. Do either of these without crashing the servers.
• Elaborate on and detail the constructed code used in the stack overflow; show how it was constructed and the byte stream equivalent.
(d) Give a brief description of the difference in the outcome of code injection for the two binaries. Include screenshots of your attempts to exploit the two executables.
(e) Specific to the binary with executable stack, no canaries and no optimisations, describe briefly whether it is easier to construct a library call to the loaded dynamic libraries, or to make a system call to the same effect, and why.
(f) Deliverables: In addition to the written work for this exercise, you are required to submit the two executable binaries. The binaries should be uploaded to Executable-files-submission-link in Turnitin.

Task 3
Overview
A non-executable (NX) stack will render a code injection attack inert but this countermeasure (the nonexec stack) can itself be countered using ROP (Return Oriented Program). In ROP, attacker is able to
bypass the protections by using existing code to achieve an exploit. Show how the equivalent of
arguments passed to functions and local variables can be used within ROP code.
Task
(a) Compile the provided C code co7605_portfo_ex2.c into executable* in the following version:
• Compile the C code so that the stack is not executable, includes stack canaries, no optimisations to the code. You should use the static flag to ensure that libraries are within the binary.
* Take note that the C code has a header file co7605_portfo_ex2.h
(b) Do static analysis on the executable identify at least three gadgets in the loaded target program's memory address space**, i.e., including the loaded program and libraries at the time of exploitability, giving the location in memory, the machine instructions, and what the gadget corresponds to.
(c) Do dynamic analysis on the executable binary to identify critical information for this exercise.
(d) Use your selected gadgets to demonstrate a ROP attack on the target.
(e) Give a brief discussion on the impact of the ROP input on the target and suggest possible mitigations for the attack.
** Make sure ASLR is disabled on your system.
C code: co7605_portfo_ex2.c - This is the source code.
#include "co7605_portfo_ex1.h"
#define MAX_DATA_SIZE 256
void serve_welcome_response(int the_connection)
{
char buffer[32]; // buffer to hold the client's name
memset(buffer, 0, 32); // Clear the buffer for receiving
// Send the query to the client...
write(the_connection, "Please enter your name: ", 24);
// Get the client's name...
read(the_connection, buffer, MAX_DATA_SIZE);
// Print the received message locally...
printf("Message received: ");
printf(buffer);
printf("\n");
// Send the message back to the client to welcome them...
write(the_connection, "Welcome ", 8); // Send 8 characters
write(the_connection, buffer, strlen(buffer));
return;
}
int server_loop(int port_number)
{
int sockfd, newsockfd;
// Establish a socket for this server to listen on...
sockfd = create_socket(port_number);
for (;;) { // Loop forever
// Accept a new connection - get a 'new socket fd' to handle it...
newsockfd = accept_connection(sockfd);
// serve the client...
serve_welcome_response(newsockfd);
// We've now finished with this 'new socket file descriptor'
close(newsockfd);
}
}
int main(int argc, char *argv[])
{
char some_space[92];
int port_number;
if (argc< 2) {
printf("ERROR: no port provided\n");
exit(-1);
}
else
{
// Get the port number as provided on the command line...
port_number = atoi(argv[1]);
server_loop(port_number);
}
}

Reference no: EM133678499

Questions Cloud

Did they use their power for the common good : Analyze: Did they use their Power for the "Common Good"? Why or why not?
Critically analyse the assigned case study research : Critically analyse the assigned case study research and apply tools, technologies, and models related to the BI systems and technologies to offer recommendation
How is american gi forum of 1948 historically significant : How is the American GI Forum of 1948 historically significant?
Describe the positive and negative aspects of methodologies : Describe the positive and negative aspects of the methodologies for the specific phases of the project with specific ideas on what could be enhanced
Demonstrate a simple buffer overflow : Demonstrate a simple buffer overflow so that you always win the game, but you do not cause the program to crash. Show the input byte stream and the method used
Define the characteristics of an empire : The United States began to look outward and move away from isolationism. Using 3 - 5 key terms, define the characteristics of an empire,.
How radio-isotopes are used for diagnosis or therapy : Describe how radio-isotopes are used for diagnosis or therapy. Pick any organelle and research on disorders/diseases that occur when that organelle malfunctions
Did politics-religion have a stronger influence on history : Did politics or religion have a stronger influence on history in the content since the start of this course? Provide three supporting examples.
How did de facto segregation differ from de jure segregation : How did de facto segregation differ from de jure segregation? Were the differences cosmetic or substantial? Explain.

Reviews

len3678499

4/18/2024 3:15:41 AM

I have an IT assignment relating to software exploitation of a C code and stack overflow analysis All 3 tasks will be done ? Okay I’m actually expecting a distinction 1 task - 600 words 2 task - 1200 words 3 task - 600 words Total 2400 words . For every place a name should come , it should be replaced by J112501 should come in its place. The task is attempted in fedora with user cyberbox Screenshots should be properly annotated and captioned. Apa 7 referencing should be there

Write a Review

Computer Engineering Questions & Answers

  Provide an fidm authentication system that you have used

Provide an FIdM authentication system that you have used (being subjet to).

  What is the total capacity of a disk pack

examine a disk with the following characteristics (these are not parameters of any particular disk unit): block size B=1024 bytes, number of blocks per track=10, number of tracks per surface=400. A disk pack consists of 15 double-sided disks.

  Define all types of travel related cybersecurity issues

What types of travel related cybersecurity issues and concerns did the managers discuss? (write about these in your blog entry)

  Write matlab code that will start with a positive integer

Write MATLAB code that will start with a positive integer and run through this process until a 1 is reached.

  Identify and discuss technologies-software in the movie

Write a program in Pascal, that takes a document and outputs the number of lines, words and characters there are in the document.

  Create two linux lite instances communicating

Explore how to use VirtualBox on a USB stick to save and exchange files and Create two Linux Lite instances communicating on the same host machine

  Discuss the advantages and disadvantages of sso architecture

Discuss the advantages and disadvantages of SSO architecture. Recommend whether SSO or another form of sign on architecture would be best for a company.

  How would you go about making the decision if you were ben

How would you go about making the decision if you were Ben? Include a recommendation if you have one. Explain your reasoning.

  Calculate the result of the first number to the power

Write an assembly language program in ARCTools that Calculates the result of the first number to the power of the second value.

  Develop a web page that lists at least five useful resources

Develop a Web page that lists at least five useful resources along with a brief description of each. Organize your Web page with a table.

  Describe the difference between inheritance and polymorphism

Describe the difference between inheritance and polymorphism. Provide a real-world example of when each could be applied.

  Develop a copy constructor and assignment operator

Develop a copy constructor and assignment operator (and understand why!), work with C-Style strings and pointers.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd