Banner grabbing
Banner grabbing can be used to gain information about a system, this is easy to do in Nmap. But how does this work?
Introduction
I used Nmaps banner grabbing for a while, but I got curious… How does this actually work?
What is banner grabbing
Banner grabbing is a technique that reveals information about a contained within the ‘banner’ of a target system, which typically includes the system’s name and version. This can be helpful in security assesments, providing useful information (name and version).
Telnet example
The banner here is OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.13 (Ubuntu Linux; protocol 2.0)
Nmap example
The same information is gathered via Nmap by providing the -sV
command (Attempts to determine the version of the service running on port).
The banner here is (same as Telnet) OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.13 (Ubuntu Linux; protocol 2.0)
Making my own banner grabbing script
To understand the banner grabbing better, I will write my own banner grabbing script using Python3. This script will not focus on performance with multithreading etc, since it is about understanding the underlaying concepts.
import socket
def grab_banner(ip, port):
try:
s = socket.socket()
s.settimeout(5) # to avoid blocks (so it doesn't hang)
s.connect((ip, port))
s.send(b'GET HTTP/1.1 \r\n\r\n')
respone = s.recv(1024).decode() # recieve response and decode the bytes to utf-8
print(f'Banner for ip {ip}:{port} - {respone}')
s.close() # close the socket connection
except socket.error as e:
print(f'Error for {ip}:{port} - {e} ')
for port in range (1, 1043): # well known ports - could also be all ports
grab_banner('scanme.nmap.org', port)
Running the script
The script runs exactly how I expected, since it shows the same SSH banner as before on port 22.
Conclusion
Banner grabbing is an important tool to gain information about a service running on a port. This can help in finding vulnerabilties.