Kali Linux Basics

Introduction to Kali Linux

Kali Linux is a Debian-based, open-source operating system tailored for penetration testing, digital forensics, and ethical hacking, making it an ideal platform for cybersecurity professionals. It comes pre-installed with hundreds of powerful tools, such as Metasploit, Nmap, Wireshark, and John the Ripper, allowing users to conduct a wide range of security assessments. Kali’s lightweight design and flexibility make it accessible on various platforms, from virtual machines to live USBs. There are many other Linux distributions, or “flavors,” each suited to different purposes. For example, Ubuntu is popular for general-purpose use with a focus on user-friendliness, while CentOS and Red Hat Enterprise Linux are used for enterprise environments due to their stability and long-term support. Arch Linux is favored by users who want a customizable, minimalist system, and Parrot OS is another security-focused distribution, like Kali, but with added privacy tools. This guide will walk you through the basics of using Kali Linux, starting from downloading and installing VirtualBox and Kali, to basic Linux commands that will help you get started.

Downloading VirtualBox

VirtualBox is a free and open-source virtual machine software that allows you to run multiple operating systems on your computer without modifying your primary system. VirtualBox is an essential tool for setting up Kali Linux, especially if you want to run it alongside other operating systems.

Steps to Download VirtualBox:

Downloading Kali Linux

Kali Linux can be downloaded from the official website. The image available for download can be used with VirtualBox to set up a virtual environment for penetration testing.

Steps to Download and Install Kali Linux:

Basic Commands

Video Credit: NetworkChuck - Educational video on Linux Commands.

Updating and Upgrading Packages

After installing Kali Linux, it is essential to update and upgrade the packages to ensure you have the latest features, tools, and security patches.

Update Package Lists: This command will fetch the updated list of packages from all configured sources.

sudo apt update

Upgrade Installed Packages: This command will upgrade all the installed packages to the latest versions available.

sudo apt upgrade

Full Upgrade: Use the following command to perform a full upgrade, which includes removing obsolete dependencies:

sudo apt full-upgrade

Changing Directories

The cd command is used to navigate the Linux file system. Here are different ways you can use the cd command:

Change to a Specific Directory: To navigate to a specific directory, provide the full path.

cd /home/kali/

Move Up One Directory: Use .. to move up one directory level.

cd ..

Return to Home Directory: You can simply use cd to go back to your home directory.

cd

Change to Root Directory: To navigate to the root directory:

cd /

Displaying the Current Directory

The pwd command (print working directory) is used to display the current directory you are in. This is helpful when navigating through the file system and ensuring you are in the correct location.

Display the Current Directory: Simply run the pwd command to see your current directory.

pwd

The output will show the full path of your current directory. For example, if you're in the home directory, it may show:

/home/kali/

Making Directories

The mkdir command is used to create new directories. You can create one or multiple directories at once.

mkdir new_folder

Create Multiple Directories:

mkdir folder1 folder2 folder3

Listing Files and Directories

The ls command lists files and directories within the current directory. Different options allow you to modify the output.

Basic List: Lists all visible files and directories in the current location.

ls

Detailed List: The -l option displays detailed information, including permissions, owner, group, size, and modification date.

ls -l

List All, Including Hidden Files: The -a option displays hidden files (files beginning with a dot).

ls -a

List with Human-Readable File Sizes: The -lh option displays file sizes in a more readable format (KB, MB, etc.).

ls -lh

Managing Users

Managing users is crucial for system administration. Below are commands to add, delete, and modify users.

Adding a User: This command adds a new user and prompts you to create a password.

sudo adduser new_username

Removing a User: This command removes a user account.

sudo deluser username

Changing User Permissions: The chmod command is used to modify permissions, and chown is used to change ownership of a file.

sudo chmod 755 filename
sudo chown username:group filename

Understanding File Permissions and chmod Values

In Linux, file permissions are critical for security and system integrity. Permissions determine who can read, write, or execute a file. The chmod command is used to change these permissions, and they can be set using either symbolic or numeric values.

Using chmod with Symbolic Permissions

Symbolic permissions are represented by characters like r (read), w (write), and x (execute). You can add or remove permissions using symbols like + and -:

To add execute permissions to a file, use the following command:

chmod +x filename

To remove write permissions for the group, use the following command:

chmod g-w filename

In this example, the +x flag adds execute permissions, and the g-w removes write permissions for the group.

Using chmod with Numeric Permissions

Permissions in Linux can also be represented by a three-digit number, where each digit corresponds to the permissions for the user (owner), group, and others. The digits are calculated by adding the following values:

To set specific permissions, you add the values for read, write, and execute.

Set read, write, and execute for the owner, and read and execute for group and others:

chmod 755 filename

In this example, 755 sets full permissions for the owner (7 = 4 + 2 + 1), and read and execute permissions for the group and others (5 = 4 + 1). The second example, 640, sets read and write permissions for the owner (6 = 4 + 2), read-only for the group (4), and no permissions for others (0).

Understanding chmod Examples

Here is a breakdown of common permission values:

Changing Passwords

The passwd command is used to change the password for the current user or another user.

passwd

Change Another User's Password:

sudo passwd username

Creating and Managing Files

Create a New File: Use the touch command to create a new, empty file.

touch newfile.txt

Editing Files with Nano

Open a File with Nano: Nano is a straightforward text editor that is used for editing configuration files and scripts.

nano filename.txt

Basic Commands in Nano:

Searching with Grep

The grep command is used to search for specific patterns within files or output. It is an invaluable tool for quickly locating information.

grep 'pattern' filename.txt

Search Recursively in All Files:

grep -r 'pattern' /path/to/directory

Using the Pipe Operator (|)

The pipe operator | allows you to use the output of one command as input to another command. This is useful for chaining commands together to accomplish more complex tasks.

ls -l | grep 'filename'

In this example, ls -l lists all files in long format, and grep 'filename' filters the output to show only lines containing 'filename'.

Unzipping Files

Linux provides several tools to extract compressed files.

Unzip a ZIP File: Use the unzip command:

unzip file.zip

Unzip a GZ File: Use the gunzip command:

gunzip file.gz

Extract a TAR File: Use the tar command:

tar -xvf file.tar

Extract a TAR.GZ File:

tar -zxvf file.tar.gz

Cloning Repositories with Git

Clone a GitHub Repository: Use git clone to download a repository from GitHub to your local machine. This is commonly used to obtain scripts and tools for cybersecurity tasks.

git clone https://github.com/user/repository.git

Using Man to Read Manuals

The man command displays the manual pages for other commands. It is an excellent resource for understanding how commands work and what options are available.

man nmap

Press q to quit the manual page once you are done reading.

Copying and Moving Files

Copy a File: The cp command is used to copy files or directories from one location to another.

cp source_file destination_directory/

Move a File: The mv command is used to move files or directories. It can also be used to rename them.

mv filename.txt /path/to/destination/

Rename a File

mv old_name.txt new_name.txt

Removing Files and Directories

The rm command is used to remove files and directories in Linux. Be cautious when using this command, as deleted files and directories are not easily recoverable.

Remove a Specific File: To remove a file, use the rm command followed by the file name.

rm filename.txt

Remove an Empty Directory: To remove an empty directory, you can use the rmdir command followed by the directory name.

rmdir directory_name

Remove a Directory and Its Contents: To remove a directory along with all of its contents, including subdirectories and files, use the rm command with the -r (recursive) option.

rm -r directory_name

Force Remove a File or Directory: You can use the -f (force) option to remove files or directories without any prompts.

rm -rf directory_name

Remove Multiple Files: To remove multiple files, list them with a space between each file name.

rm file1.txt file2.txt file3.txt