This project was created to demonstrate how to automate network mapping by integrating the python-nmap library, which is a Python wrapper for the popular Nmap tool commonly found in network engineering and cybersecurity environments. We will create the script in a Kali Linux virtual machine and scan the vulnerable Metasploitable2 machine which will be in our network.
Oracle VM Virtual Box
Kali Linux
Metasploitable2
python-namp
Visual Studio Code
Even though this is out of the scope of the project and not our main focus point. I will provide links for installing and configuring the Oracle Vm Virtual Box, Kali Linux machine, Visual Studio Code(on Kali Linux machine) and Metasploitable2 machine below:
https://www.youtube.com/watch?v=nvdnQX9UkMY&t=256s
https://www.youtube.com/watch?v=sAMnXte56yY
https://www.youtube.com/watch?v=1rIvnMenA2g&t=172s
https://www.youtube.com/watch?v=I9rGQFq6x_4
We want to ensure that both our Kali Linux machine and our Metasploitable2 machine are on the same network. We after following the videos to set up the machines, go into the "Setting" of each individual virtual machine. Then you will need to navigate to the "Network" tab and change "Attached to" to a "NAT Network" and assign each machine to the same NAT network for connection purposes.
Using the default credentials (msfadmin:msfadmin) to log into the Metasploitable2 machine and use the command ip a to find the IP address for the vulnerable machine.
We will now go into the Kali machine to check if the Metasploitable2 machine is on our same network by using the command sudo netdiscover -r 10.0.2.0/24
Go into Visual Studio Code, here you will need create a folder and file to the python script where the code will run. We will write our code here. Example path to code, /testcode/src/scanner.py
This section of the code imports the Nmap module and creates an instance of the PortScanner class
This section of the code prints to the console about our script. The scanner ask for an IP address as user input. The scanner will return responses based on the user input.
This section of the code returns to the console responses based on the users input between 1-3.
We will now change to root privilege using the sudo su command. We will then navigate to the directory that our scanner.py code is in. In this "src" directory we will then use the command to run scanner using the python3 scanner.py command.
You will then need to follow the prompt from the script and then select through the 3 options to see the output and test them with the existing Nmap tool on the Kali linux machine.
***Note: UDP will not scan UDP ports for the Metasploitable2 machine. However, it is working***