One of the most fundamental tasks in Linux—or any operating system—is adding and removing software. You’ll often need to install software that didn’t come with your distribution or remove unwanted software so it doesn’t take up hard drive space.
Some software requires other software to run, and you’ll sometimes find that you can download everything you need at once in a software package, which is a group of files—typically libraries and other dependencies—that you need for a piece of software to run successfully. When you install a package, all the files within it are installed together, along with a script to make loading the software simpler.
In this chapter, we examine three key methods for adding new software: apt package manager, GUI-based installation managers, and git.
In Debian-based Linux distributions, which include Kali and Ubuntu, the default software manager is the Advanced Packaging Tool, or apt, whose primary command is apt-get. In its simplest and most common form, you can use apt-get to download and install new software packages, but you can also update and upgrade software with it.
Before downloading a software package, you can check whether the package you need is available from your repository, which is a place where your operating system stores information. The apt tool has a search function that can check whether the package is available. The syntax is straightforward:
apt-cache search keyword
Note that we use the apt-cache command to search the apt cache, or the place it stores the package names. So if you were searching for the intrusion detection system Snort, for example, you would enter the command shown in Listing 4-1.
kali >apt-cache search snort
fwsnort - Snort-to-iptables rule translator
ippl - IP protocols logger
--snip--
snort - flexible Network Intrusion Detection System
snort-common - flexible Network Intrusion Detection System - common files
--snip--
Listing 4-1: Searching the system with apt-cache for Snort
As you can see, numerous files have the keyword snort in them, but near the middle of the output we see snort – flexible Network Intrusion Detection System. That’s what we are looking for!
Now that you know the snort package exists in your repository, you can use apt-get to download the software.
To install a piece of software from your operating system’s default repository in the terminal, use the apt-get command, followed by the keyword install and then the name of the package you want to install. The syntax looks like this:
apt-get install packagename
Let’s try this out by installing Snort on your system. Enter apt-get install snort as a command statement, as shown in Listing 4-2.
kali >apt-get install snort
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
snort-doc
The following NEW packages will be installed:
snort
--snip--
Install these packages without verification [Y/n]?
Listing 4-2: Installing Snort with apt-get install
The output you see tells you what is being installed. If everything looks correct, go ahead and enter y when prompted, and your software installation will proceed.
When removing software, use apt-get with the remove option, followed by the name of the software to remove (see Listing 4-3).
kali >apt-get remove snort
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer
required:
libdaq0 libprelude2 oinkmaster snort-common-libraries snort-rules-default
--snip--
Do you want to continue [Y/n]?
Listing 4-3: Removing Snort with apt-get remove
Again, you’ll see the tasks being done in real time and you will be asked whether you want to continue. You can enter y to uninstall, but you might want to keep Snort since we’ll be using it again. The remove command doesn’t remove the configuration files, which means you can reinstall the same package in the future without reconfiguring.
If you do want to remove the configuration files at the same time as the package, you can use the purge option, as shown in Listing 4-4.
kali >apt-get purge snort
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libdaq0 libprelude2 oinkmaster snort-common-libraries snort-rules-default
--snip--
Do you want to continue [Y/n]?
Listing 4-4: Removing Snort and the accompanying configuration files with apt-get purge
Simply enter Y at the prompt to continue the purge of the software package and the configuration files.
You may have noticed the line The following packages were automatically installed and are no longer required in the output. To keep things small and modular, many Linux packages are broken into software units that many different programs might use. When you installed Snort, you installed several dependencies or libraries with it that Snort requires in order to run. Now that you’re removing Snort, those other libraries or dependencies are no longer required, so they are removed, too.
Software repositories will be periodically updated with new software or new versions of existing software. These updates don’t reach you automatically, so you have to request them in order to apply these updates to your own system. Updating isn’t the same as upgrading: updating simply updates the list of packages available for download from the repository, whereas upgrading will upgrade the package to the latest version in the repository.
You can update your individual system by entering the apt-get command followed by the keyword update. This will search through all the packages on your system and check whether updates are available. If so, the updates are downloaded (see Listing 4-5).
kali >apt-get update
Get:1 http://mirrors.ocf.berkeley.edu/kali kali-rolling InRelease [30.5kb]
Get:2 http://mirrors.ocf.berkeley.edu/kali kali-rolling/main amd64 Packages [14.9MB]
Get:3 http://mirrors.ocf.berkeley.edu/kali kali-rolling non-free amd64 Packages [163kb]
Get:4 http://mirrors.ocf.berkeley.edu/kali kali-rolling/contrib amd64 Packages [107 kB]
Fetched 15.2 MB in 1min 4s (236 kB/s)
Reading package lists... Done
Listing 4-5: Updating all out-of-date packages with apt-get update
The list of available software in the repository on your system will be updated. If the update is successful, your terminal will state Reading package lists... Done, as you can see in Listing 4-5. Note that the name of the repository and the values—time, size, and so on—might be different on your system.
To upgrade the existing packages on your system, use apt-get upgrade. Because upgrading your packages may make changes to your software, you must be logged in as root or use the sudo command before entering apt-get upgrade. This command will upgrade every package on your system that apt knows about, meaning only those stored in the repository (see Listing 4-6). Upgrading can be time-consuming, so you might not be able to use your system for a while.
kali >apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Calculating upgrade... Done
The following packages were automatically installed and no longer required:
--snip--
The following packages will be upgraded:
--snip--
1101 upgraded, 0 newly installed, 0 to remove and 318 not upgraded.
Need to get 827 MB of archives.
After this operation, 408 MB disk space will be freed.
Do you want to continue? [Y/n]
Listing 4-6: Upgrading all out-of-date packages with apt-get upgrade
You should see in the output that your system estimates the amount of hard drive space necessary for the software package. Go ahead and enter Y if you want to continue and have enough hard drive space for the upgrade.
The servers that hold the software for particular distributions of Linux are known as repositories. Nearly every distribution has its own repositories of software—developed and configured for that distribution—that might not work well, or at all, with other distributions. Although these repositories often contain the same or similar software, they aren’t identical, and they sometimes have different versions of the same software or entirely different software.
You will, of course, be using the Kali repository, which has a large amount of security and hacking software. But because Kali specializes in security and hacking, it doesn’t include some specialty software and tools and even some run-of-the-mill software. It’s worth adding a backup repository or two that your system can search through in case it doesn’t find it a specific software in the Kali repository.
The repositories your system will search for software are stored in the sources.list file, and you can alter this file to define from which repositories you want to download software. I often add the Ubuntu repositories after the Kali repositories in my sources.list file; that way, when I request to download a new software package, my system will first look in the Kali repository, and if the software package isn’t there, it will look in the Ubuntu repository.
You can find the sources.list file at /etc/apt/sources.list and open it with any text editor. I’ll again be using Leafpad. To open the sources.list file, enter the following into your terminal, replacing leafpad with the name of your editor:
kali >leafpad /etc/apt/sources.list
After entering this command, you should see a window like the one in Figure 4-1, with a list of Kali’s default repositories.
Figure 4-1: Kali’s default repositories in sources.list
Many Linux distributions divide repositories into separate categories. For instance, Ubuntu breaks out its repository categories as follows:
main Contains supported open source software
universe Contains community-maintained open source software
multiverse Contains software restricted by copyright or other legal issues
restricted Contains proprietary device drivers
backports Contains packages from later releases
I don’t recommend using testing, experimental, or unstable repositories in your sources.list because they can download problematic software to your system. Software that isn’t fully tested might break your system.
When you ask to download a new software package, the system looks sequentially through your repositories listed in sources.list and stops when it finds the desired package. Check first that the repository is compatible for your system. Kali, like Ubuntu, is built on Debian, so these repositories work pretty well with each of these systems.
To add a repository, just edit the sources.list file by adding the name of the repository to the list and then save the file. Say, for example, you want to install Oracle Java 8 on Kali. No apt package for Oracle Java 8 is available as part of the default Kali sources, but a quick search online shows that the fine folk at WebUpd8 have created one. If you add their repository to the sources, you can then install Oracle Java 8 with the apt-get install oracle-java8-installer command. At the time of writing, you would need to add the following repository locations to sources.list in order to add the necessary repositories:
deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main
Newer versions of Kali no longer include a GUI-based software installation tool, but you can always install one with the apt-get command. The two most common GUI-based installation tools are Synaptic and Gdebi. Let’s install Synaptic and use it to install our Snort package:
kali >apt-get install synaptic
Reading package lists... Done
Building dependency tree
Reading state information... Done
--snip--
Processing triggers for menu (2.1.47)...
kali >
Once you have Synaptic installed, you can start it from Settings ▸ Synaptic Package Manager, which should open a window like the one in Figure 4-2.
Figure 4-2: The Synaptic Package Manager interface
Now you can search for the package you’re looking for. Simply click the Search tab to open a search window. Because you are looking for Snort again, enter snort into the search window and click Search. Scroll down the search results to find the package you’re looking for. Check the box next to snort and then click the Apply tab, as shown in Figure 4-3. Synaptic will now download and install Snort from the repository along with any necessary dependencies.
Figure 4-3: Downloading Snort from the Synaptic Package Manager
Sometimes the software you want isn’t available in any of the repositories—especially if it’s brand new—but it may be available on github (https://www.github.com/), a site that allows developers to share their software with others to download, use, and provide feedback. For instance, if you want bluediving, a Bluetooth hacking and pentesting suite, and can’t find it in the Kali repository, you can search github for the software by entering bluediving into the search bar. If it exists on github, you should see the repository for it in the search results.
Once you’ve found the software on github, you can install it from the terminal by entering the git clone command followed by its github URL. For instance, bluediving is located at https://www.github.com/balle/bluediving.git. To clone it into your system, enter the command shown in Listing 4-7.
kali >git clone https://www.github.com/balle/bluediving.git
Cloning into 'bluediving'...
remote: Counting objects: 131, Done.
remote: Total 131 (delta 0), reused 0 (delta 0), pack-reused 131
Receiving objects: 100% (131/131), 900.81 KiB | 646.00 KiB/s, Done.
Resolving deltas: 100% (9/9), Done.
Checking connectivity... Done.
Listing 4-7: Cloning bluediving with git clone
The git clone command copies all the data and files from that location onto your system. You can check to see that they’ve been successfully downloaded by using the long listing command ls –l on the target directory, like so:
kali >ls -l
If you’ve successfully cloned bluediving to your system, you should see the following output:
total 80
drwxr-xr-x 7 root root 4096 Jan 10 22:19 bluediving
drwxr-xr-x 2 root root 4096 Dec 5 11:17 Desktop
drwxr-xr-x 2 root root 4096 Dec 5 11:17 Documents
drwxr-xr-x 2 root root 4096 Dec 5 11:17 Downloads
drwxr-xr-x 2 root root 4096 Dec 5 11:17 Music
--snip--
As you can see, bluediving has been successfully cloned to the system, and a new directory named bluediving has been created for its files.
In this chapter, you learned a few of the many ways to download and install new software on your Linux system. Software package managers (like apt), GUI-based installers, and git clones are the most common and crucial methods for an aspiring hacker to know. You’ll soon find yourself becoming familiar with each of them.