Tools of The Trade - Linux, SQL
Tools of The Trade - Linux, SQL
The BIOS or UEFI microchips contain a variety of loading instructions for the computer to
follow. For example, one of the loading instructions is to verify the health of the computer’s
hardware.
The last instruction from the BIOS or UEFI activates the bootloader. The bootloader is a
software program that boots the operating system. Once the operating system has finished
booting, your computer is ready for use.
Efficiency
Using virtual machines can also be an efficient and convenient way to perform security tasks.
One hypervisor that is useful for you to be familiar with is the Kernel-based Virtual Machine (KVM).
KVM is an open-source hypervisor that is supported by most major Linux distributions. It is built
into the Linux kernel, which means it can be used to create virtual machines on any machine
running a Linux operating system without the need for additional software.
GUI versus CLI
A user interface is a program that allows
a user to control the functions of the operating system.
Two user interfaces that we'll discuss are
the graphical user interface, or
GUI, and the command-line interface, or CLI.
In comparison,
using a GUI is more like ordering food from a restaurant.
You can only order what's on the menu.
If you want both a noodle dish and pizza,
but the first restaurant you go to only has pizza,
you'll have to go to another restaurant
to order the noodles.
With a graphical user interface,
you must do one task at a time.
But the command-line interface allows for customization,
which lets you complete multiple tasks simultaneously.
For example, imagine you
have a folder with hundreds of files of
different file types, and you need to
move only the JPEG files to a new folder
MODULE 2
Linux architecture
The components of Linux include
user,
applications,
shell,
Filesystem Hierarchy Standard,
kernel
hardware.
First, you are the user. The user is the person interacting with the computer.
Linux distributions
Linux is a very customizable operating system.
Unlike other operating systems, there are different versions available for
you to use.
These different versions of Linux are called distributions.
You might also hear them called distros or flavors of Linux.
KALI LINUX ™
KALI LINUX™ is a trademark of Offensive Security and is Debian derived. It's important to note that
KALI LINUX™ should be used on a virtual machine.
This prevents damage to your system in the event its tools are used improperly.
An additional benefit is that using a virtual machine gives you the ability to
revert to a previous state.
To begin, Metasploit can be used to look for and exploit vulnerabilities on machines.
Burp Suite is another tool that helps to test for weaknesses in web applications.
And finally, John the Ripper is a tool used to guess passwords
Ubuntu
Ubuntu is an open-source, user-friendly distribution that is widely used in security and other
industries. It has both a command-line interface (CLI) and a graphical user interface (GUI).
Ubuntu is also Debian-derived and includes common applications by default.
Ubuntu is also widely used for cloud computing. As organizations migrate to cloud servers,
cybersecurity work may more regularly involve Ubuntu derivatives.
Parrot
Parrot is an open-source distribution that is commonly used for security. Similar to KALI
LINUX ™, Parrot comes with pre-installed tools related to penetration testing and digital
forensics. Like both KALI LINUX ™ and Ubuntu, it is based on Debian.
Parrot is also considered to be a user-friendly Linux distribution. This is because it has a GUI
that many find easy to navigate. This is in addition to Parrot’s CLI.
Red Hat® Enterprise Linux®
Red Hat Enterprise Linux is a subscription-based distribution of Linux built for enterprise
use. Red Hat is not free, which is a major difference from the previously mentioned
distributions. Because it’s built and supported for enterprise use, Red Hat also offers a
dedicated support team for customers to call about issue
CentOS
CentOS is an open-source distribution that is closely related to Red Hat. It uses source code
published by Red Hat to provide a similar platform. However, CentOS does not offer the
same enterprise support that Red Hat provides and is supported through the community.
the Red Hat Package Manager (RPM) can be used for Linux distributions derived from Red Hat, and
package managers such as dpkg can be used for Linux distributions derived from Debian.
Echo hello
Module 3
With that background, we're now ready to learn the commands commonly used for navigating the
file system.
First,
pwd prints the working directory onto the screen. When you use this command, the output
tells you which directory you're currently in.
Next,
ls displays the names of files and directories in the current working directory.
Note: If you want to return the contents of a directory that’s not your current working directory,
you can add an argument after ls with the absolute or relative file path to the desired directory. For
example, if you’re in the /home/analyst directory but want to list the contents of its projects
subdirectory, you can enter ls /home/analyst/projects or just ls projects.
And finally,
cd navigates between directories. This is the command you'll use when you want to change
directories.
Pro Tip: You can use the relative file path and enter cd .. to go up one level in the file structure. For
example, if the current directory is /home/analyst/projects, entering cd .. would change your
working directory to /home/analyst.
As a security analyst, you'll also need to know how to read file content in Linux.
When reading file content, there are some commands that will help you.
First,
cat displays the content of a file. This is useful, but sometimes you won't want the full contents
of a large file.
In these cases, you can use the head command. It displays just the beginning of a file, by
default ten lines.
Pro Tip: If you want to change the number of lines returned by head, you can specify the number of
lines by including -n. For example, if you only want to display the first five lines of the updates.txt
file, enter head -n 5 updates.txt
tail
The tail command does the opposite of head. This command can be used to display just the
end of a file, by default 10 lines. Entering tail updates.txt returns only the last 10 lines of the
updates.txt file.
Pro Tip: You can use tail to read the most recent information in a log file.
less
The less command returns the content of a file one page at a time. For example, entering less
updates.txt changes the terminal window to display the contents of updates.txt one page at a
time. This allows you to easily move forward and backward through the content.
Once you’ve accessed your content with the less command, you can use several keyboard
controls to move through the file:
/home: Each user in the system gets their own home directory.
/bin: This directory stands for “binary” and contains binary files and other
executables. Executables are files that contain a series of commands a computer needs
to follow to run programs and perform other functions.
/tmp: This directory stores many temporary files. The /tmp directory is commonly
used by attackers because anyone in the system can modify data in these files.
/mnt: This directory stands for “mount” and stores media, such as USB drives and
hard drives.
Pro Tip: You can use the man hier command to learn more about the FHS and its standard
directories.
When the path leads to a subdirectory below the user’s home directory, the user’s home
directory can be represented as the tilde (~). For example, /home/analyst/logs can also be
represented as ~/logs.
You can navigate to specific subdirectories using their absolute or relative file paths. The
absolute file path is the full file path, which starts from the root. For example,
/home/analyst/projects is an absolute file path. The relative file path is the file path that
starts from a user's current directory.
Note: Relative file paths can use a dot (.) to represent the current directory, or two dots (..)
to represent the parent of the current directory. An example of a relative file path could be
../projects.
Pro Tip: To learn what your username is, use the whoami command. The whoami command returns
the username of the current user. For example, if your username is analyst, entering whoami returns
analyst.
Piping
The pipe command is accessed using the pipe character (|).Piping sends the standard output
of one command as standard input to another command for further processing.
find
The find command searches for directories and files that meet specified criteria. There’s a
wide range of criteria that can be specified with find. For example, you can search for files
and directories that
When using find, the first argument after find indicates where to start searching. For example,
entering find /home/analyst/projects searches for everything starting at the projects directory.
After this first argument, you need to indicate your criteria for the search. If you don’t include
a specific search criteria with your second argument, your search will likely return a lot of
directories and files.
Specifying criteria involves options. Options modify the behavior of a command and
commonly begin with a hyphen (-).
The difference between these two options is that -name is case-sensitive, and -iname is not.
For example, you might want to find all files in the projects directory that contain the word
“log” in the file name. To do this, you’d enter find /home/analyst/projects -name "*log*". You
could also enter find /home/analyst/projects -iname "*log*".
Note: An asterisk (*) is used as a wildcard to represent zero or more unknown characters.
-mtime
Security analysts might also use find to find files or directories last modified within a certain
time frame. The -mtime option can be used for this search. For example, entering find
/home/analyst/projects -mtime -3 returns all files and directories in the projects directory that
have been modified within the past three days.
The -mtime option search is based on days, so entering -mtime +1 indicates all files or
directories last modified more than one day ago, and entering -mtime -1 indicates all files or
directories last modified less than one day ago.
Note: The option -mmin can be used instead of -mtime if you want to base the search on
minutes rather than days.
For example, if you want to create a new directory called network in your /home/analyst/logs
directory, you can enter mkdir /home/analyst/logs/network to create this new directory. If you’re
already in the /home/analyst/logs directory, you can also create this new directory by entering mkdir
network.
rmdir
The rmdir command removes, or deletes, a directory. For example, entering rmdir
/home/analyst/logs/network would remove this empty directory from the file system.
touch and rm
The touch command creates a new file. This file won’t have any content inside. If your
current directory is /home/analyst/reports, entering touch permissions.txt creates a new file
in the reports subdirectory called permissions.txt.
To open an existing file in nano from the directory that contains it, enter nano followed by
the file name. For example, entering nano permissions.txt from the /home/analyst/reports
directory opens a new nano editing window with the permissions.txt file open for editing.
You can also provide the absolute file path to the file if you’re not in the directory that
contains it.
You can also create a new file in nano by entering nano followed by a new file name. For
example, entering nano authorized_users.txt from the /home/analyst/reports directory
creates the authorized_users.txt file within that directory and opens it in a new nano editing
window.
Since there isn't an auto-saving feature in nano, it’s important to save your work before
exiting. To save a file in nano, use the keyboard shortcut Ctrl + O. You’ll be prompted to
confirm the file name before saving. To exit out of nano, use the keyboard shortcut Ctrl + X.
In addition to the pipe (|), you can also use the right angle bracket (>) and double right angle
bracket (>>) operators to redirect standard output.
When used with echo, the > and >> operators can be used to send the output of echo to a
specified file rather than the screen. The difference between the two is that > overwrites
your existing file, and >> adds your content to the end of the existing file instead of
overwriting it. The > operator should be used carefully, because it’s not easy to recover
overwritten files.
When you’re inside the directory containing the permissions.txt file, entering echo "last
updated date" >> permissions.txt adds the string “last updated date” to the file contents.
Entering echo "time" > permissions.txt after this command overwrites the entire file contents
of permissions.txt with the string “time”.
Note: Both the > and >> operators will create a new file if one doesn’t already exist with
your specified name.
drwxrwxrwx
Change permissions
chmod changes permissions on files and directories.
The command chmod stands for change mode.
Another way to assign these permissions is to use the equals sign (=) in this first argument.
Using = with chmod sets, or assigns, the permissions exactly as specified. For example, the
following command would set read permissions for login_sessions.txt for user, group, and
other:
This command overwrites existing permissions. For instance, if the user previously had write
permissions, these write permissions are removed after you specify only read permissions
with =.
Note: When there are permission changes to more than one owner type, commas are
needed to separate changes for each owner type. You should not add spaces after those
commas.
The sudo command temporarily grants elevated permissions to specific users. The name
of this command comes from “super user do.” Users must be given access in a
configuration file to use sudo. This file is called the “sudoers file.” Although using sudo is
preferable to logging in as the root user, it's important to be aware that users with the
elevated permissions to use sudo might be more at risk in the event of an attack.
useradd
The useradd command adds a user to the system. To add a user with the username of fgarcia
with sudo, enter sudo useradd fgarcia. There are additional options you can use with
useradd:
-g: Sets the user’s default group, also called their primary group
-G: Adds the user to additional groups, also called supplemental or secondary groups
To use the -g option, the primary group must be specified after -g. For example, entering sudo
useradd -g security fgarcia adds fgarcia as a new user and assigns their primary group to be
security
To use the -G option, the supplemental group must be passed into the command after -G.
You can add more than one supplemental group at a time with the -G option. Entering
sudo useradd -G finance,admin fgarcia adds fgarcia as a new user and adds them to the
existing finance and admin groups.
usermod
The usermod command modifies existing user accounts. The same -g and -G options from
the useradd command can be used with usermod if a user already exists.
To change the primary group of an existing user, you need the -g option. For example,
entering sudo usermod -g executive fgarcia would change fgarcia’s primary group to the
executive group.
To add a supplemental group for an existing user, you need the -G option. You also need a -a
option, which appends the user to an existing group and is only used with the -G option. For
example, entering sudo usermod -a -G marketing fgarcia would add the existing fgarcia user
to the supplemental marketing group.
When changing the supplemental group of an existing user, if you don't include the -a option,
-G will replace any existing supplemental groups with the groups specified after usermod.
Using -a with -G ensures that the new groups are added but existing groups are not replaced.
There are other options you can use with usermod to specify how you want to modify the
user, including:
The option always goes after the usermod command. For example, to change fgarcia’s
home directory to /home/garcia_f, enter sudo usermod -d /home/garcia_f fgarcia. The
option -d directly follows the command usermod before the other two needed arguments.
userdel
The userdel command deletes a user from the system. For example, entering sudo userdel
fgarcia deletes fgarcia as a user. Be careful before you delete a user using this command. The
userdel command doesn’t delete the files in the user’s home directory unless you use the -r
option. Entering sudo userdel -r fgarcia would delete fgarcia as a user and delete all files in
their home directory. Before deleting any user files, you should ensure you have backups in
case you need them later.
Note: Instead of deleting the user, you could consider deactivating their account with
usermod -L. This prevents the user from logging in while still giving you access to their
account and associated permissions. For example, if a user left an organization, this option
would allow you to identify which files they have ownership over, so you could move this
ownership to other users.
chown
The chown command changes ownership of a file or directory. You can use chown to change
user or group ownership. To change the user owner of the access.txt file to fgarcia, enter
sudo chown fgarcia access.txt. To change the group owner of access.txt to security, enter
sudo chown :security access.txt. You must enter a colon (:) before security to designate it as
a group name.
Similar to useradd, usermod, and userdel, there are additional options that can be used with
chown
Module 4
Wildcards
A wildcard is a special character that can be substituted with any other character. Two of the
most useful wildcards are the percentage sign (%) and the underscore (_):
The BETWEEN operator is inclusive. This means records with a hiredate of January 1,
2002 or January 1, 2003 are included in the results of the previous query.
Inner joins
The first type of join that you might perform is an inner join. INNER JOIN returns rows
matching on a specified column that exists in more than one table.
It only returns the rows where there is a match, but like other types of joins, it returns all
specified columns from all joined tables. For example, if the query joins two tables with
SELECT *, all columns in both of the tables are returned.
Note: If a column exists in both of the tables, it is returned twice when SELECT * is used.
SELECT *
FROM employees
You must specify the two tables to join by including the first or left table after FROM and the
second or right table after INNER JOIN.