-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbanner_scan.py
executable file
·70 lines (53 loc) · 2.28 KB
/
banner_scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket # external package
import select
import pprint # external package
from common_utils import menu_utils
import config_params
""" This module establishes socket connections to grab banners """
def _banner_scan(ip, port):
""" Method to obtain the banner corresponding to the port of the IP """
category = ""
banner = ""
try:
menu_utils.mixed_info("\nBanner grab: Analysing port: ", str(port))
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect((ip, port))
connection.setblocking(False)
ready = select.select([connection], [], [], config_params.BANNER_TIMEOUT)
if ready[0]:
banner = connection.recv(4096)
print("Banner: " + str(banner))
f = open(config_params.VULNERABLE_BANNERS, 'r')
category = "NON-VULNERABLE"
for banner_vulnerable in f:
if str(banner_vulnerable).strip() in str(banner).strip():
category = "VULNERABLE"
break
if category == "VULNERABLE":
menu_utils.super_highlighted_info('[+] The banner is vulnerable')
else:
menu_utils.highlighted_info('[?] The banner seems NOT vulnerable')
else:
menu_utils.warning('[-] The banner is not available')
category = "UNAVAILABLE"
except (ConnectionRefusedError, FileNotFoundError, TimeoutError) as e:
menu_utils.error(e)
category = "UNAVAILABLE"
return category, banner
def scan(ip, ports):
""" This method performs banner grabbing from the different ports of the given IP """
menu_utils.header('BANNER GRABBING, IP: %s ' % ip)
dict_vulnerable_banners = {}
dict_non_vulnerable_banners = {}
for port in ports:
category, banner = _banner_scan(ip, port)
if category == "VULNERABLE":
dict_vulnerable_banners[port] = banner
elif category == "NON-VULNERABLE":
dict_non_vulnerable_banners[port] = banner
menu_utils.header("Vulnerable banners")
pprint.pprint(dict_vulnerable_banners)
menu_utils.header("Other banners")
pprint.pprint(dict_non_vulnerable_banners)