Virtualization
September 9 2020 Meeting
- Virtualization and Bash lead by Patrick McCabe
- Docker Containerization lead by Matt Walter
Introduction to Virtualization
What is required?
- A computer
- Internet connection
- Patience (Depending on the OS, current packages will be downloaded during the install)
What is Virtualization?
Virtualization is a way to run other Operating Systems (OS) on top of your host’s (computer’s) operating system. The way we virtualize an OS is through the use of a hypervisor. There are two types of hypervisors. They are the following:
| Type | Description |
|---|---|
| 1 | “Bare Metal” would be set up on a server (ex: home penetration testing lab) |
| 2 | Requires an OS (Windows, MacOS, Linux, etc.), this is the type that we will be setting up in today’s meeting |
How do we set up the Virtualization?
We will cover this in the meeting but the slide deck for today which can be located here. Please also take a look at the Resources tab under the Linux Distros for other OS’s that we recommend for Cyber Security! (There are also pre-built virtual machines for other purposes)
What is Bash?
Bash is shorthand for Bourne Again Shell and is one of many command line interfaces (CLI) that exist in the Linux environment. Bash is one of the more common CLIs across Linux, so we will Some other common CLIs are:
- Friendly Interactive Shell (fish)
- Shell (sh)
- Z Shell (zsh)
- TMux (multi-shell interface)
- Screen (multi-shell interface)
- Powershell? (Yes! There is a Powershell interface on Linux)
How do we use Bash?
We use Bash through a terminal emulator (For Parrot, it will be the Mate Terminal with a >_ as inside a circle for the icon and for Kali it will be Terminal Emulator with a $_ in a rectangle for the icon). Once we have that opened, we can begin to learn Bash!
Some common (and useful) commands are:
pwdwhich will print the current working directory (think of a directory as a folder) as the file pathmkdir [directory]creates a directory (folder) for the current directorylswhich lists the files and directories (All that are unhidden) Some common options (denoted by -) are
- -a: all files (including hidden)
- -l: long form with permissions, links, owner, group, size (in bytes), date modified, time modified, and name of the file or directory
- -t: sort by modification time
- -h: human readable format for the file size
touch [file.extension]creates a file with the specified extension. Some extensions are:
- .txt: for a plaintext file
- .doc or .docx: document
- .log: for a log file
- .conf: for configuration files
nano [file name]this will open the text editor nano Side Note: you can create the file without using touch firstecho "some text"prints out some text to the terminal
echo "some text" > test.txt: this will redirect some text into test.txt and overwrites it to test.txtecho "some text" >> test.txt: this will redirect some text into test.txt and appends it to test.txt
cat test.txtthis will concatenate the file and print it to the terminalless test.txtthis is another way to view a file and will allow scrolling up and down with the arrow keys Side note: the previous version oflesswasmoreand the Linux people decided to have fun with the name of the new versiongrep "some text" test.txtgrep will be used to pattern match (or search for the specified term) in test.txt Side note: grep is a very powerful tool that will be useful for log analysis for computer forensics and data analytics with data sets Some common options for grep are:
- -c: returns the count of “some text” in test.txt
- -E: for regular expressions (REGEX) (info on them can be found here)
- -h: for no file name
- -i: for ignore case
- -l: for files matching the pattern
- -n: for line number where the search matches
- Piping: take the output of one command and sending it to another command (denoted by |)
- Why is this useful? We’ll use cat, sort, and uniq as examples:
cat test.txt | sort | uniqthis will concatenate test.txt, send the output to sort (which sorts alphabetically), and then pipes the output to uniq which returns the uniq strings in the file
wc test.txtprints the word count of test.txt Some helpful options are:
- -c: prints the number of characters
- -l: prints the number of lines
- -w number of words
cp test.txt ~/Desktop/copies test.txt to the Desktop directory and will leave a copy in the current directory. A helpful option for copying files withcpis the -r option for recursive copy, which is used for directories Side note:~is short hand for /home/$USER, with $USER being the signed in usermv test.txt ~/Desktop/this will move test.txt to ~/Desktop/ and will not leave a copy behindrm test.txtthis will delete test.txt. To delete directories, you may need to use the followingrm -r [directory](to recursively delete) orrm -rf [directory]to forcefully delete the directorysudo useradd [username]this command will create a new user Side note: sudo invokes root privileges to run a command that a normal user cannot run Some common options are:
- -m: for a home directory
- -c “some text”: for comments
- -s [shell name]: determines what the login shell is for the new user
sudo passwd [user]this will add a password for any usersu [user]this will switch the current user in the terminal (can be left by typingexitinto the terminal)sudo usermod -aG [group] [user]this will assign the user specified to the group that is specifiedchmodis a crucial command that can be used to change file permissions
Example: -rwxr–r– (the first - is whether or not the file is a directory or an individual file)
| Group | Abbreviation | Placement | Meaning |
|---|---|---|---|
| User | u | first three slots after the first - | this is the group for the file’s owner and the permissions will be described below |
| Group | g | the next three slots after the user | this will set the permissions for the group that the user is a part of |
| Other | o | last three slots after the group | This will be the permissions for all the other users on the system |
Side note: there is a special character for all and it is denoted by a
| Option | Numerical Equivalent | Meaning |
|---|---|---|
| +r | 4 | the file can be read through the specified group |
| +w | 2 | the file can be written to by the specified group |
| +x | 1 | the file can be executed (run) by the specified group |
Side note: these permission numbers can be added up to add multiple permissions at once
To change the permissions, we can do this two different ways:
- We can use
chmod [group]+[permission(s)]or in other words, to add executable status to both the group and other by usingchmog go+x test.txt - The other way to accomplis this is
chmod [number][number][number] test.txtand we will use the following:chmod 755 test.txt. The way that we determined the permission numbers is the following: 4 (read) + 2 (write) + 1 (execute) = 7 (for the user) and 4 (for read) + 1 (execute) = 5 for both the group and other user permissions
ip athis will list out the current network interfaces and IP address for the machine (on Eth0 for Ethernet). Here is a little shortcut to get your IP and subnet (we will go over what a subnet is on Sept. 30)
ip addr show | grep eth0 | grep inet | awk '{print $2}'
man [command]man is short for manual and will be your best friend for learning the options for specific commands and unlocking their full potentialaptis the packacge (software) manager for Debian based systems (Ubuntu, Kali, Parrot, etc.) Side note: most apt commands need root privilege to run so make sure to run the commands. Some common commands are:
sudo apt update: update the packacge repositories for the systemsudo apt full-upgrade: upgrade all the packages on your systemsudo apt autoremove: cleans up unecessary packagessudo apt update && sudo apt full-upgrade: the && will run the first command and then the second command once it has finished
Docker and Containerization
Howdy, welcome to the docker/containerization portion of this meeting.
what exactly is Containerization?
1 | Containerization involves bundling an application together with all of its related configuration files, libraries and dependencies required for it to run in an efficient and bug-free way across different computing environments. |
Well, then what is Docker?
1 | Docker is an open-source project that automates the deployment of software applications inside containers by providing an additional layer of abstraction and automation of OS-level virtualization on Linux. |
GETTING STARTED
Installing docker:
https://docs.docker.com/get-docker/
Debian based Linux (Kali):
First, as always, update APT:
sudo apt update
Then we need to add the official Docker PGP key like so:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
Next, we configure APT so we will be able to download, install and update Docker.
echo 'deb [arch=amd64] https://download.docker.com/linux/debian buster stable' | sudo tee /etc/apt/sources.list.d/docker.list
After adding Docker to APT, we need to update apt once more so we will be able to install Docker on Kali Linux:
sudo apt update
In case you have any old and/or outdated versions of Docker installed on your system, we make sure to get rid of them first:
sudo apt remove docker docker-engine docker.io
Once this is done, we are ready to install Docker on Kali Linux:
sudo apt install docker-ce -y
Finally, starting Docker:
sudo systemctl start docker
Optional – Starting Docker automatically after a reboot. Do this at your own risk. I do not recommend doing this if you don’t know what you’re doing. I usually only start Docker when I actually need to use it.
sudo systemctl enable docker
MacOS:
1 | sidebar: I am a mac person and when it comes to using docker in any form of professional setting I use docker desktop with the VScode docker plugin to manage all of my containers and images. |
That being said,
Windows:
1 | sidebar: Almost the opposite of MacOS, I never use docker on a Windows machine (although you for sure can). Is it worse than a UNIX based machine? yeah, probably, but don't let that stop you, learn the way you can. |
That being said, I assume people use Docker Desktop on Windows, but idk,
Activity:
1. Run,
docker run hello-world
The expected output is very insightful for how the docker work flow functions:
1 | Hello from Docker! |
2. Next, try running an Ubuntu container
docker run -it ubuntu bash
breaking down that command:
- docker –> the CLI command
- run -it ubuntu —> run container “ubuntu” with -it to use interactive mode
- bash —> the program that gets run
3. If you want more practice follow this guide.
https://docker-curriculum.com/
Docker CLI
docker ps–> The docker ps command shows you all containers that are currently running.docker images–> To see the list of images that are available locallydocker run–> To run a Docker container based on this image.docker rm+ (container ID, found in docker ps) –> removes the container
Useful options:
docker ps -a–> will list the status of recent containersdocker run -it–> runs the container in interactive mode, so you can input more than one command.- etc… read the man pages
Docker Terminology
- Image
- Container
- Dockerhub