程序代写CS代考 MSc Advanced Cyber Security 7CCSONSE Security Engineering

MSc Advanced Cyber Security 7CCSONSE Security Engineering
Demonstration of the UID program in Week 1, Section 1.5
This document provides the steps to run the program in Week 1, Section 1.5. Follow the steps below, you can edit and run the program in the module VM.
Step1: Log in your VM
this can be done by the following command on a terminal on your operation system.
$ ssh
You may be asked for inputting your password.
Step2: Edit the C program
Edit the program in a C program file and include the following header files at the beginning of the C file. Figure 1 (on next page) shows the screenshot of the program after adding the header files.
#define _GNU_SOURCE
#include
#include
1

Fig.1 UID Program with necessary libraries
Alternatively, you can choose to edit the c file (e.g., VS Code) on your laptop and use the scp command to copy the file to your remote VM.
$ scp path_to_file.c
• The first argument (path_to_file.c) is the path to your edited c file on your laptop.
• The second argument has two parts which connected by a “:”. Before the colon is the
username at IP of your VM and after that is the destination path.
2

Fig.2 Copy the C file to temote VM
Step3: Compile the copied c file in your VM
As shown in the ls command, we can see the copied c file main.c is in the path of the home directory.
We need to use the gcc command to compile the file. This command has already been installed on the VM.
$ gcc -g main.c -o uid-demo
Two flags are used here
• The g flag is for allowing debugging so that we can see how all XXIDs change during
execution.
• The o flag is for defining the output file’s name. We use uid-demo as the output file name in
this demonstration.
Fig.3 Compile the C file
Step.4: Debug the code to check how parameters change after each step $ gdb uid-demo
Here the uid-demo is the executable file that we compiled just now.
3

Fig.4 Use GDB to debug the executable file
Here we can use command b to add a breakpoint in gdb.
The breakpoint position is aligned with the source code. For example, if we want to add a breakpoint at line 8 of the c file, we just use the command
(gdb) b 8
After adding breakpoint, we use the command run to start execution. (gdb) run
4

Fig.5 Adding breakpoint & starting execution in GDB
You can now use the next command to trace how parameters change after each instruction.
(gdb) next
Fig.6 Tracing parameters’ change step by step
5

Step.5: Exit the debugging mode
(gdb) q
Fig.7 Exit debugging in gdb
We can use the q command to exit debugging.
Step 6: We can also execute the program directly in terminal without debugging.
$ ./uid-demo
The result is shown in Fig.8.
6

End of the demonstration
Fig.8 Execution result
7