Banner grabbing with Python sockets
The socket
module in Python can be used to connect to network services running on remote ports. This recipe will demonstrate how to use Python sockets to acquire service banners in order to identify the services associated with open ports on a target system.
Getting ready
To use Python to gather service banners, you will need to have a remote system running network services that discloses information when a client device connects to them. In the examples provided, an instance of Metasploitable2 is used to perform this task. For more information on setting up Metasploitable2, refer to the Installing Metasploitable2 recipe in Chapter 1, Getting Started. Additionally, this recipe will require a script to be written to the filesystem using a text editor such as Vim or GNU nano. For more information on writing scripts, refer to the Using text editors (Vim and GNU nano) recipe in Chapter 1, Getting Started.
How to do it….
Let's use Python the collect banner information...