Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Python Ethical Hacking from Scratch

You're reading from  Python Ethical Hacking from Scratch

Product type Book
Published in Jun 2021
Publisher Packt
ISBN-13 9781838829506
Pages 214 pages
Edition 1st Edition
Languages
Author (1):
Fahad Ali Sarwar Fahad Ali Sarwar
Profile icon Fahad Ali Sarwar

Table of Contents (14) Chapters

Preface 1. Section 1: The Nuts and Bolts of Ethical Hacking – The Basics
2. Chapter 1: Introduction to Hacking 3. Chapter 2: Getting Started – Setting Up a Lab Environment 4. Section 2: Thinking Like a Hacker – Network Information Gathering and Attacks
5. Chapter 3: Reconnaissance and Information Gathering 6. Chapter 4: Network Scanning 7. Chapter 5: Man in the Middle Attacks 8. Section 3: Malware Development
9. Chapter 6: Malware Development 10. Chapter 7: Advanced Malware 11. Chapter 8: Post Exploitation 12. Chapter 9: System Protection and Perseverance 13. Other Books You May Enjoy

Chapter 3: Reconnaissance and Information Gathering

In this chapter, we will learn about the basics of networking. Without having a solid understanding of computer networks, you will not be able to go very far in the field of penetration testing and ethical hacking. We will cover some basic details about how networking works. We will also take a look at the different abstraction layers in networking and the role of each layer.

Every ethical hacking process starts with gathering relevant information about the target, and this chapter is dedicated to what type of information we can obtain and how this information can be useful to us. We will discuss the standard OSI model that's used to describe the network layers and how this model can be helpful for us. In this chapter, we will cover the following topics:

  • What is a computer network?
  • Classifying networks
  • Network stack
  • Network entities
  • Protection
  • Changing MAC

What is a computer network?

In the Information Technology (IT) domain, networking means the ability of two or more devices to be able to communicate and exchange data with each other. In the early days of computing, computers were unable to talk to each other and were standalone systems. Their functionalities were very limited. As the technology advanced, the need for communication between devices grew. In its simplest form, two computers that connect with each over a medium form a network. This medium is the link through which these devices talk with each other. As we proceed, you will see that things become very complicated very quickly in computer networks:

Figure 3.1 – The simplest form of a network – two interconnected computers

As you will see in the following chapters, most modern-day computer networks are not built like this. For your computer to talk to other computers, it will need as many links as it has computers, and this can quickly...

Components of a basic computer network

In this section, we will learn about the different components of a computer network. In computer network literature, you will often see the term node being used to represent a computer in a network. In networking domains, a specific nomenclature is used to identify particular devices in a network. We will look at these terms next.

Node

A node is usually a device that is connected to the central device. In a sense, it is a computer that takes part in a communication network. This works for simple and small networks, but as more and more devices get added to a network, different devices start taking up different roles, so we can only simplify a device's role in a network as a node up to a certain point. In qualifying scenarios, nodes can be your laptop, desktop PC, printer, tablet, phone, or any other network connected device.

Server

Servers are computers that hold some information that can be shared over the network to devices...

Classifying network

As more and more computers start connecting, it becomes essential to classify them into different classes so that we can use them. There are various methods we can use for classification; however, the most common one is network classification based on geography. We will discuss this next.

Local area network

When you connect your laptop or phone to a Wi-Fi router located in your home, you are essentially participating in a local area network (LAN). There are multiple types of connections you can make to a LAN, such as by using Wi-Fi, which is a wireless connection, or by using a wired connection such as an ethernet cable. There is no hard definition of what constitutes a LAN. However, a LAN is usually composed of devices that are in the same proximity in a building. LAN can be as simple as two devices connecting to a router or as complicated as LANs in universities and offices.

Ethernet

Ethernet is one of the most used technologies in LAN. Modern ethernet...

Network stack

The previous section gave us a high-level introduction to networking. Now, we will learn about how the actual bits and pieces are transferred over a network.

Introduction to OSI model

From the time you type a message on an application to the time that it gets delivered to its intended recipient, your message passes though different layers in a communication system. To help us understand all the communication processes and mediums your data passes though before it reaches its destination, a framework was conceptualized to describe the functionality of a networking system. This model is called the Open Systems Interconnected (OSI) model. This model is not necessarily applied to the internet alone and can be applied to any modern communication system:

Figure 3.6 – 7-layer OSI stack

The OSI model contains 7 layers that conceptualize how data is transferred over any electronic communication medium. Let's look at these layers in more...

Network entities

Before proceeding, we will introduce a few network-related concepts that will be used throughout this book. Having prior knowledge of them is essential so that you have a complete understanding of this book.

Private IP address

An internet protocol (IP) address is a unique identifier that identifies a device in a network. An IP address is a 32-bit number. Whenever you connect to a new network, you are either assigned a new IP address by a Dynamic Host Control Protocol (DHCP) server or you get an IP address stored in your system configuration if it is available. This is usually called a local/private IP address. More often than not, you will see this address in the form 192.168.1.x.

Important Note about IP Addresses

IP addresses are 32-bit, which means that there are only 2^32 = 4,294,967,295 internet addresses available. The IP address is an old protocol and when it was developed, there were not many internet-connected devices. At the time, 4 billion devices...

Protection

So far in this chapter, we have learned about the basics of computer networking, which are essential to understanding the rest of this book. Now, we will start looking at what parameters can be used to track us and how we can protect ourselves. In the previous chapter, we learned that the first step in ethical hacking is information gathering. But before we start gathering information, we must make sure that our identity is protected. Otherwise, we can be easily tracked. Your identity can be tracked back to you with a number of parameters. The most common is your IP address and your MAC address.

To mask your public IP address, you can use Virtual Private Networks (VPNs). We will not be discussing VPNs as they are not in the scope of this book. One important thing to note here is that you should not put complete trust in your VPN provider. From a security point of view, using a VPN simply means that you are handing over your trust from your internet service provider ...

Changing our MAC address

In this section, we will try to change our MAC address on the Kali machine. Let's start our Kali machine and open up a Terminal. To change the MAC address, you will need to install the net-tools package. In most Linux distributions, this tool is already available. However, if it is not installed, you can install it using the following commands:

 sudo apt-get update -y
sudo apt-get install -y net-tools

It will prompt you for a password, which is kali. Once the tools have been installed, you can view the MAC address with the following command:

sudo ifconfig

If everything goes well, you will see an output similar to the following:

Figure 3.12 – ifconfig command output

There is a lot to unpack here, so let's break it down. There are two values here called eth0 and lo. eth0 is the name of the NIC, whereas lo is the loopback adapter. For now, we can ignore the loopback adapter. The inet field represents the private...

Summary

In this chapter, we learned about the basics of networking and how we can protect ourselves on a local network by spoofing our MAC address for scanning purposes. This chapter helped us get a deeper insight into the networking aspects of the computer system, as well as how we can use Python to protect and mask our identity in a local network. In the next chapter, we will learn about scanning local networks.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Python Ethical Hacking from Scratch
Published in: Jun 2021 Publisher: Packt ISBN-13: 9781838829506
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}