Memory Safety¶
Software Security / Memory Safety Lab Report¶
Objective
The objective of this lab was to learn about buffer overflow vulnerabilities and understand how unsafe functions can affect program memory.
Exercise 1: Stack Zero¶
Expected Success Message you have changed the ‘modified’ variable
What happened?¶
In this exercise, I entered more characters than the buffer could store. Since the program uses the unsafe gets() function, it accepted all the input without checking its size. The extra characters overflowed the buffer and changed the nearby variable called modified. As a result, the program displayed the success message.
How can gets(buffer) change the value of modified?¶
The gets() function does not limit the number of characters entered. If the input is longer than the buffer, the extra data is written into nearby memory locations. Because the variable modified is stored next to the buffer, it gets overwritten.
What does “Segmentation Fault” mean?¶
A Segmentation Fault is an error that happens when a program tries to access memory that it is not allowed to use. This usually causes the program to crash.
What I learned¶
Buffers have a fixed size. Writing too much data causes a buffer overflow. Unsafe functions like gets() should not be used.
Exercise 2: Stack One¶
Expected Success Message¶
you have correctly got the variable to the right value
What happened?¶
This exercise required changing the variable modified to a specific value. I learned that computers store numbers in memory in a particular order, so the bytes had to be arranged correctly for the program to recognize the value.
What is Little Endian?¶
Little Endian is the method many computers use to store numbers in memory.
For example, Number: 0x12345678
Stored in memory: 78 56 34 12 The smallest byte is stored first.
Why didn’t you get a Segmentation Fault?
Only the target variable was changed. The program’s important memory, such as its return address, was not overwritten, so the program continued running normally.
What I learned¶
Memory stores numbers in byte order. Little Endian stores the least significant byte first. Not every buffer overflow crashes the program.
Exercise 3: Stack Three¶
Expected Success Message code flow successfully changed How can you input hex values that don’t correspond to keyboard letters?
Hexadecimal values that cannot be typed directly are usually provided using a script (such as Python) or escape sequences, which generate the required bytes.
What happened?¶
In this exercise, the overflow changed a function pointer. Instead of calling the normal function, the program jumped to another function that printed the success message. This demonstrated that a buffer overflow can change the program’s execution path.
What I learned¶
Buffer overflows can affect more than variables. They can change where a program executes. This is called changing the program’s control flow.