8 Using Kali Linux Command Line , Free Hacking Complete Course Step By Step

Free Hacking Complete Course Step By Step

Using Kali Linux Command Line

You will use Kali Linux as the attack platform throughout this blog. Kali, the successor to the popular BackTrack Linux, is a Debian-based distribution that comes with a plethora of penetration testing tools preinstalled and preconfigured. Anyone who’s ever tried to set up a pentesting box from scratch the day before a big engagement knows that getting everything working correctly can be a real pain. Having everything preconfigured in Kali can save a lot of time and headaches. Kali Linux works just like the standard Debian GNU/Linux distribution, with a lot of extra tools. Rather than point and click your way through Kali, you’ll use the Linux command line because that’s where the real power lies. In this blog we’ll look at how to perform some common Linux tasks from the command line. If you’re already a Linux expert, you can skip this day blog and move on to next blog; if not, take some time and dive in.

Linux Command Line

The Linux command line looks like this:

root@kali:~#

Like a DOS prompt or the Mac OS terminal, the Linux command line gives you access to a command processor called Bash that allows you to control the system by entering text-based instructions. When you open the command line you’ll see the prompt root@kali#. Root is the superuser on Linux systems, and it has complete control of Kali. To perform operations in Linux, you enter commands along with any relevant options. For example, to view the contents of root’s home directory, enter the command ls as shown here.

root@kali:~# ls
Desktop

As you can see, there’s not much in the root directory, only a folder
called Desktop.

The Linux Filesystem

In the Linux world, everything is a file: keyboards, printers, network devices—everything. All files can be viewed, edited, deleted, created, and moved. The Linux filesystem is made up of a series of directories that branch off from the root of the filesystem (/).
To see your current directory, enter pwd at the terminal: 
 
            root@kali:~# pwd
             /root

Changing Directories

To move to another directory, enter cd directory using either the absolute or relative path to the new directory, based your current location. The absolute path is the path to a file in relation to the root directory (/). For example, to change to your desktop from anywhere, you could enter the absolute path to the desktop with cd /root/Desktop to reach the root user’s desktop. If you were in the directory /root (the root user’s home directory), you could use the relative path to the desktop (that is, relative to your current location) by entering cd Desktop, which would also take you to the desktop.
            The command cd .. takes you back one level in the filesystem, as shown here.

root@kali:~/Desktop# cd..
root@kali:~/# cd../etc
root@kali:/etc#

          Entering cd.. from root’s Desktop directory takes us back to root’s home directory. Entering cd../etc from there moves us back up to the root of the filesystem and then to the /etc directory. 

Learning About Commands: The Man Pages

To learn more about a command and its options and arguments, you can view its documentation (called its manual page, or man page) by entering man command. For example, to learn more about the ls command enter man ls as shown in Listing.

root@kali:~# man ls

LS(1)                                                     User Commands                                             LS (1) 

NAME                   

ls - list directory contents

SYNOPSIS

ls [OPTION]... [FILE]... (1)

DESCRIPTION (2)

List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. Mandatory arguments to long options are mandatory for short options too.

-a, --all (3)

do not ignore entries starting with .

-A, --almost-all

do not list implied . and ..

--snip--

-l use a long listing format

--snip--

The man page gives useful (if a bit unfriendly looking) information about the ls command including its usage (1), description (2), and available options (3).

As you can see in the description section at (2), the ls command lists all files in the current working directory by default, but you can also use ls to get information about a particular file. For example, according to the man page you can use the -a option with ls to show all files, including hidden directories—directories not shown in the default ls listing—as shown in Listing.

root@kali:~# ls -a 

.                                  .mozilla
..                                 .msf4
.android                      .mysql_history
.bash_history              .nano_history 

--snip--

As you can see, there are several hidden directories in the root directory, all of which are preceded by a period (.) character. You can also see the entries . and .., which denote the current directory and the parent directory, respectively. 

User Privileges 

Linux user accounts offer resources to a particular individual or service. A user may log in with a password and be offered certain resources on the Linux system, such as the ability to write files and browse the Internet. That user may not be able to see files that belong to other users and can have reasonable assurance that other users can’t see his or her files either. In addition to traditional user accounts used by a person who logs in with a password and accesses the system, Linux systems can allow software to have a user account. The software can have the ability to use system resources to do its job, but it cannot read other users’ private files. The accepted best practice on Linux systems is to run day-to-day commands as an unprivileged user account instead of running everything as the privileged root user to avoid inadvertently harming your system or granting excessive privilege to the commands and applications you run.

Adding a User

By default, Kali offers only the privileged root account. Though many security tools require root privileges to run, you may want to add another unprivileged account for everyday use to reduce the potential for damage to your system. Remember, the root account can do anything on Linux, including corrupting all of your files.

To add a new user for ex. Accused to your Kali system use the adduser command, as shown in Listing

root@kali:~# adduser Accused
Adding user `Accused' ...
Adding new group `Accused' (1000) ...
Adding new user `Accused' (1000) with group `Accused' ... (1)
Creating home directory `/home/Accused' ... (2)
Copying files from `/etc/skel' ...
Enter new UNIX password: (3)
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for Accused
Enter the new value, or press ENTER for the default
Full Name []: Accused Hacking (4)
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y 

As you can see, in addition to adding a user to the system, a group Accused is created, a new user is added to this group (1), a home directory is created for the user (2), and the system prompts for information about the user, such as a password (3) and the user’s full name (4).  

Adding a User to the sudoers File

When you need to do something that requires root privileges as a regular user, use the sudo command along with the command that you want to run as root, and then enter your password. For the newly created user Accused to be able to run privileged commands you need to add her to the sudoers file, which specifies which users can use the sudo command. To do so, enter adduser username sudo as shown here.

root@kali:~# adduser Accused sudo
Adding user 'Accused' to group `sudo' ...
Adding user Accused to group sudo
Done.

Switching Users and Using sudo 

To switch users in your terminal session, say from the root user to Accused, use the su command as shown in Listing

root@kali:~# su Accused
Accused@kali:/root$ adduser john
bash: adduser: command not found (1)
Accused@kali:/root$ sudo adduser john
[sudo] password for Accused:
Adding user `john' ... (2)
Adding new group `john' (1002) ...
Adding new user `john' (1002) with group `john' ...
--snip--
Accused@kali:/root$ su
Password:
root@kali:~#

You switch users with the su command. If you try to run commands (such as the adduser command) that require more privileges than the current user (Accused), the command is unsuccessful (command not found) (1) because you can run the adduser command only as root.

Luckily, as discussed previously, you can use the sudo command to run a command as root. Because the Accused user is a member of the sudo group, you can run privileged commands, and you can see user john is added (2) to the system. 

To change back to the root user, enter the su command with no username. You will be prompted for the root’s password (toor). 


In our last blog we had installed all the Installing Vulnerable Software For Target Machine, our next tops will be Creating Files Using Kali Linux Command Line. If you have not followed us yet, then do so so that you do not miss the upcoming topics. Click Here To Read Our Blogs From Getting Started.


Comments

Popular posts from this blog

5 Setting Up Android Emulators, Free Hacking Course Complete Step By Step

3 Configuring the Network for Virtual Machine, Hacking Complete Free Course Step By Step

14 Creating Standalone Payloads with Msfvenom, Free Hacking Complete Course Step By Step