python3-nmap: Python3-nmap converts Nmap commands into python3 methods making it very easy to use nmap in any of your python pentesting projects · Pythie
A python 3 library which helps in using nmap port scanner. The way this tools works is by defining each nmap command into a python function making it very easy to use sophisticated nmap commands in other python scripts. Nmap is a complicated piece of software used for reconnaissance on target networks, over the years new features have been added making it more sophisticated.
With this python3-nmap we make using nmap in python very easy and painless
For example in nmap if you want to scan for common ports you would to something like this
$ nmap your-host.com --top-ports 10
But in this python3-nmap script you would do something like this
import nmap3
nmap = nmap3.Nmap()
results = nmap.scan_top_ports("your-host.com")
# And you would get your results in json
You will notice each nmap command is defined as a python function/method. this make it easy to remember this in python and easily use them.
Again in nmap if you want to use the famous dns-brute script you would do something like this
$ nmap your-host.com --script dns-brute.nse
But in this python3 script again it's very easy you just do something like this
import nmap3
nmap = nmap3.Nmap()
results = nmap.nmap_dns_brute_script("your-host.com")
# And you would get your results in json
[
{
"address": "mail.your-host.com",
"hostname": "68.65.122.10"
},
{
"address": "www.your-host.com",
"hostname": "5.189.129.43"
}
]
How to use python3-nmap
Using this scripts is very easy, though it assumes you have nmap already installed, as it is the primary dependence required. Also this tools supports both windows and linux, it's cross platform so to say.
Installation
$ git clone https://github.com/wangoloj/python3-nmap.git
$ pip3 install -r requirements.txt
# Install nmap online
$ apt-get install nmap
# That's all is needed to get started
In nmap some commands require root privileges for example the command to identify OS requires root privileges;
$ nmap -O your-host.com
TCP/IP fingerprinting (for OS scan) requires root privileges.
QUITTING!
# Until you sudo
$ sudo nmap -O your-host.com
The same applies to the script to be able to run the os identifier you have to be a super user.
How to use the script to identify OS
import nmap3
nmap = nmap3.Nmap()
os_results = nmap.nmap_os_detection("192.168.178.2") # MOST BE ROOT
Nmap is a large tool, as you can see python3-nmap provides only things what you could say commonly used nmap features.
Using custom nmap command line arguments.
As we said, the script defines each set of nmap command as python function/methods. You can also pass arguments to those methods/function thus extending your capabilities for example.
Let's say we want to scan top ports but also perform version detection .
Using the nmap vulners script to identify vulnerabilities (CVE's)
You scan the the target IP using version detection ('-sV') to get the service and, the script performs a lookup in the CVE database. The nmap vulners script is part of the default Nmap installation, so you shouldn't need to install any other packages.