Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Practical Web Penetration Testing

You're reading from  Practical Web Penetration Testing

Product type Book
Published in Jun 2018
Publisher Packt
ISBN-13 9781788624039
Pages 294 pages
Edition 1st Edition
Languages
Author (1):
Gus Khawaja Gus Khawaja
Profile icon Gus Khawaja

Table of Contents (18) Chapters

Preface 1. Building a Vulnerable Web Application Lab 2. Kali Linux Installation 3. Delving Deep into the Usage of Kali Linux 4. All About Using Burp Suite 5. Understanding Web Application Vulnerabilities 6. Application Security Pre-Engagement 7. Application Threat Modeling 8. Source Code Review 9. Network Penetration Testing 10. Web Intrusion Tests 11. Pentest Automation Using Python 12. Nmap Cheat Sheet 13. Metasploit Cheat Sheet 14. Netcat Cheat Sheet 15. Networking Reference Section 16. Python Quick Reference 17. Other Books You May Enjoy

Delving Deep into the Usage of Kali Linux

I have been so excited to write this chapter and share all of the information that you will need to master the usage of Kali Linux. A lot of the content in this chapter will be common among Debian Linux distributions, and by the end of the chapter, you will be able to handle Kali Linux with ease, like a real hacker. Speaking of hackers, it's good to know that Kali Linux is used by both black hat hackers and professional penetration testers. I've always used it during my engagements, and I occasionally (but rarely) use Microsoft Windows OS.

Kali Linux contains tons of tools dedicated to penetration testing, and it would be a big challenge to get used to all of them at once. In this chapter, I will show you my most often used commands. I keep them with me when I'm on an engagement, in order to manipulate the operating system...

The Kali filesystem structure

The first thing that you need to start to understand is the Kali Linux filesystem structure, which is based on the Debian distribution filesystem. If you have used Microsoft Windows OS before, then the Linux structure will be a bit similar to it. For example, Windows starts with the C:\ directory, while the Linux OS starts with /, which is called the root directory.

The root directory (/) and the root home directory (/root) that you use in Kali are not the same. The latter is used as a home directory for the root user.

In Kali, we always use the root user to log in to our machine, and that means that you have no limits to what you can do in the OS. Every single piece in the Linux system is based on files; it's okay to look around, but be careful if you decide to change any of the configuration files.

The directory structure in Kali is based on...

Handling applications and packages

Kali Linux packages are stored in repositories and downloaded to the system to ensure the integrity of the package. Make sure to always update the system, as mentioned in the previous chapter. The repository configuration file is located at /etc/apt/sources.list. Make sure that this file is not empty (it will be if you didn't choose the network mirror option during the installation process); if it is, your Kali will not update.

The Advanced Packaging Tool

The Advanced Packaging Tool (APT) is used for installing or upgrading packages, along with all of the required dependencies. The APT can also be used to upgrade a complete distribution of Kali:

  • apt-get update or apt update: This command...

Handling the filesystem in Kali

I could write a whole book for this section, but I will do my best to show you the commands that you're going to need in your arsenal as a penetration tester.

Before I start listing all of the commands, I would like to share a unique command-line utility that you'll need to master before starting with any of the utilities in this chapter. You can probably guess it; it's called the Help switch! This option will give you a handful of information regarding the command that you are going to execute.

For example, if you want to list the contents of a directory and you're not sure of the options for the command, all you need to do is append the --help switch, and you can visualize all of the possible functionalities of the command:

Are you ready? This is going to be a long list (a sort of cheat sheet). Let's start:

  • To list the...

Security management

Managing users in Kali is not an everyday task, but you will probably use it occasionally. Personally, I rarely use the following commands, but sometimes, you might need to handle user management:

  • To add a user with sudo capabilities in Kali, use the following command:
useradd -m [username] -G sudo -s /bin/bash
  • If you're logged in and you want to elevate your privilege to a root user, try this command:
su - [desired root user name]
  • If you're logged in and you want to execute a root command, use the following:
sudo [application name]
  • To change the root (or any user's) password, use the following:
passwd [user name]
  • The shadow file is important in Kali, because it stores the hashed passwords and some useful information about users. For example, I created a user called gus on Kali, so, to get his information, I should execute the following...

Secure shell protocol

Secure shell (SSH) protocol is a network protocol that is used to establish an encrypted communication between a server and a client, using the TCP protocol. The SSH service is TCP-based, and listens, by default, on port 22. In general, a public-private key pair allows users to log in to a system without requiring a password. The public key is present on all systems that require a secure connection, while the user keeps the private key in a secure place. On the target systems, the public key is verified against a list of authorized keys that are allowed to remotely access the server. SSH can be compromised when the public key is not cryptographically strong enough, and can be guessed.

  • To start the ssh service, use the following:
service ssh start
  • To check whether the service is running properly, use the following:
netstat -antp|grep sshd
# or
service ssh...

Configuring network services in Kali

I'm doing my best to show you the necessary commands in each section. You don't need to know all of the commands for managing network services in Kali, but you are surely going to use some of them. In this section, I will show you my favorite commands related to the network services in Kali Linux.

To operate Kali properly, you need to ensure that it has connectivity to either a wired or a wireless network. You may need to obtain an IP address through Dynamic Host Configuration Protocol (DHCP), or assign one statically.

The first important command is ifconfig, which you will use to check the IP address on your Kali machine:

You can see my Kali IP address, 10.0.0.197, after executing this command (in the preceding screenshot). Also, you need to pay attention to the network interface names—eth0 represents the Ethernet cable,...

Process management commands

In general, Kali Linux is a stable system. However, things may occasionally go wrong, and sometimes, we will wish to tweak the system to better suit our needs. In this section, we will take a brief look at how we can manage processes on a Kali Linux system.

Htop utility

Before I start listing all of the built-in commands for managing the processes in Kali, there is a handy tool that I always use. Unfortunately, it's not preinstalled on Kali. It's called htop. This command-line tool lists all of the running processes in the Terminal window, in a nice, user-friendly layout:

#To install it
apt-get install htop
# To execute it
htop
Through using htop, I can see that I have a memory issue which...

System info commands

This section will be very useful in the post-exploitation phase.

Suppose that you just escalated your privileges on a Linux box; how can you know if you're really an admin? Just execute the id command, and you'll get the results. Don't underestimate this section! Review it carefully, and see the commands that you can take advantage of during the post-exploitation phase on a Linux machine:

  • To show the current host uptime, use the following:
uptime
  • To show who's logged in, use the following:
w
whoami
  • To show who you are (as a user), use the following:
id
  • To display information about a user, use the following:
finger [user name]
  • To show kernel information, use the following:
uname -a
  • To show CPU information, use the following:
cat /proc/cpuinfo
  • To show memory information, use the following:
cat /proc/meminfo
  • To show disk usage...

Summary

Another chapter has been completed. You are now smarter than you were yesterday. So many commands, right? Don't worry; you don't need to memorize all of these commands. You can always come back to this chapter and use it as a reference for your Terminal window ninja skills.

As you may have realized, I get straight to the point, without wasting your time on useless information and nitty-gritty details that you will never use in your career. I hope that you enjoyed this chapter, and that you learned something new, so that you can start using your Kali Linux baby machine.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Practical Web Penetration Testing
Published in: Jun 2018 Publisher: Packt ISBN-13: 9781788624039
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}