COMP6236 2023-无代写
时间:2023-04-27
COMP6236 2023
Laboratory 0: Using Vagrant, C and Linux
Welcome to Laboratory 0, in this lab you will be introduced to the first set of tools that we
will be using in this module. First, we will explain how to install the experimental setup
for you to do your assignments. Thereafter, we set a couple of exercises to prepare you for
the next lab.
Submission Instructions
There are no marks for this Lab.
1 Experimental Setup
For this lab we are using Vagrant. It works by reading configuration files in your current directory and
using them to create VMs. The instructions in subsection 1.1 are for using the experimental setup in an
ECS lab while subsection 1.2 provides instructions should you wish to use this at home or on your own
laptop/PC. If you are using your own equipment and you are not on campus then you will also have to
use the university VPN.
Vagrant is a tool which allows virtual machines with specific configurations to be spun up from config-
uration files. In order to use it, you will need to download some software. This tool will ensure that you
have a clean experimental setup every time. Also, to help you get up and ready for the lab in no time,
all the tools and data will be inside the vagrant script.
VirtualBox is a tool that allows you to run virtual machines on your computer and its a pre-requisite
for Vagrant.
Git is a tool that implements source control. You will be using this to download the new lab every week.
1.1 ECS lab setup
Log into any Windows PC in an ECS Lab, open “File Explorer” and navigate to the C drive, then the
Apps folder and from there the COMP Files folder and finally the COMP6236 folder. In there you will
see a number of Lab folders. Please right click on the correct folder for this lab and then from the
context menu navigate to ”DOS Shells” and choose Vagrant. See the image below that demonstrates
this process. Then proceed in the newly opened terminal by running “vagrant up”.
#!/bin/bash
vagrant up
If you have the VirtualBox window open, you will notice that a new VM appears, and Vagrant begins
to build it. It should take a couple of minutes. When the build process is complete, you can connect to
a shell on your newly created VM using the following command:
#!/bin/bash
vagrant ssh
You can now proceed to Section 2.
1
1.2 Personal computers
Only follow these instructions if you are using your own machines at home!
Note: We can not provide troubleshooting for non-university systems but there are extensive online
resources you can consult should you have installation issues.
Please download and install them in this order:
1. Download Virtualbox from https://www.virtualbox.org/wiki/downloads.
2. Download Vagrant from https://www.vagrantup.com/downloads.
3. Download git (Windows) from https://git-scm.com/downloads. If you’re running mac or Linux,
you should already have this installed.
4. When installing git, make sure you tick the option to “Add to path”, which will allow you to run
git from the terminal.
2
Once both of these packages have been installed, you should be able to open up a terminal on your
computer (cmd on Windows, Terminal on Mac/Linux) and type vagrant to check it is installed and
working.
In order to spin up the VM, you may need to use the cd command in your terminal to change-directory
into the correct folder. Change directory into a working folder from which you wish to complete the labs.
You will need to make it if it doesn’t exist, and then cd into it for example:
#!/bin/bash
cd Documents/comp6236-labs
Download the lab0 VM image from the UoS Git server by typing the following:
#!/bin/bash
git clone https://git.soton.ac.uk/comp6236/lab0
Change into the lab0 folder so we can use vagrant:
#!/bin/bash
cd lab0
You should now be able to run the following command to
#!/bin/bash
vagrant up
If you have the virtualbox window open, you will notice that a new VM appears, and vagrant begins to
build it. It should take a couple of minutes. When the build process is complete, you can connect to a
shell on your newly created VM using the following command:
#!/bin/bash
vagrant ssh
You can now proceed to Section 2.
3
2 Challenges
Before we introduce any assignment, we will present you with several challenges, that escalate in difficulty
to help you off your feet, and break up what you need to learn into smaller chunks.
2.1 Challenge 1 - Compile a C Program
Inside your VM, you can use a number of commands to make, move, and modify files. If this is your first
time using a command line, check out some online tutorials about how to interface with the command
line, for example, https://ubuntu.com/tutorials/command-line-for-beginners.
Inside lab0/task1, there is a file called helloworld.c.
Using online resources, find out how to compile the program using gcc and run it. What does the program
output when it is run?
Hint: What can you learn from running the following command “man gcc”?
Hint: to run a newly compiled C program you need to prefix “./”” to the program name.
2.2 Challenge 2 - Extracting Strings from a Program
Inside lab0/task2 is another identical C program, but it has been compiled with a secret string which is
never output. The source code is available in task2-redacted.c
#!/bin/bash
$ ./task2
Exiting...
Can you find a tool available in Linux for extracting strings from files?
What is the secret string that would be printed if the program was compiled to output it?
2.3 Challenge 3 - Decompiling a C Program
Inside lab0/task3, you will find a number-guessing C program. As the user, you have to guess a number,
and if it’s correct, you get to see a secret string.
The source code is available in task3-redacted.c.
#!/bin/bash
$ ./task3
Usage: task3
guess: what number Im thinking of
$ ./task3 10
Thats not the number I was thinking.
Using online resources, explore how to use objdump to decompile the binary.
What number do you need to input to make the program output the secret string?
You may find this short guide useful for understanding x86 assembly pneumonics.
What is the output of the program when you get the number correct?
2.4 Golden Challenge - Advance Decompiling in C Program
Inside lab0/task4 is another C program which is very similar to task 3. The source code is available in
task4-redacted.c. The only difference is that this program doesn’t use a direct comparison to check the
number, and instead uses a series of mathematical functions in a certain order.
Can you reverse engineer the check function using Objdump to determine what number to input for it
to output the secret string?
What string is output when you get the number correct?