-
Notifications
You must be signed in to change notification settings - Fork 11
/
banner-grabber.py
78 lines (68 loc) · 3.05 KB
/
banner-grabber.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
71
72
73
74
75
76
77
78
import socket,sys,time
logo = '''\033[92m
___ ___ _ _
| _ ) __ _ _ _ _ _ ___ _ _ / __|_ _ __ _| |__| |__ ___ _ _
| _ \/ _` | ' \| ' \/ -_) '_| | (_ | '_/ _` | '_ \ '_ \/ -_) '_|
|___/\__,_|_||_|_||_\___|_| \___|_| \__,_|_.__/_.__/\___|_|
coded by Sumalya Chatterjee
'''
print(logo)
try:
def slowprint(s):
for c in s + '\n' :
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(10. / 100)
def ban_grab(host, port, delay) :
'''
This function takes three parameters from main() to process and get the banner of the requested port
It has a specific condition for HTTP port which make this program more flexible than other simple
banner grabbers
:param host: Ask HULK a IP ADDRESS or URL
:param port: HULK REQUESTED PORT
:param delay: TIME DELAY for SEARCH
:return: None
'''
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Making a TCP socket
try :
s.settimeout(delay)
if port == 80 : # If user requested port is 80
s.connect((str(host), port))
GET = 'GET / HTTP/1.1\nHost: '+ str(host) +'\n\n' # Request more than ordinary three way handshake
s.sendall(str.encode(GET))
banner = s.recvfrom(512) # Important part of the banner received
else :
s.connect((str(host), port)) # Trying normal TCP handshake and getting banner
banner = s.recvfrom(512)
banner = banner[0]
banner = banner.splitlines() # Processing received banner
for line in banner:
line = str(line)
line = line.replace('\'','') # Removing unnecessary part of the line
print(line[1::])
except Exception as er :
slowprint('\033[91m Error : ' + str(er)) # Exception handling
finally :
s.close() # Closing socket
def user_input(msg) : # Checking for keyboard interrupt
while True :
try :
return input(msg)
except KeyboardInterrupt :
slowprint('\033[91m [-] HULK does not allowed you to quit right now !')
def main() :
host = user_input('\033[92m [+] Ask HULK a IP or URL : ') # Taking and validating user inputs
port = int(user_input('\033[92m [+] Ask HULK a port : '))
if port < 1 or port > 65535 :
slowprint('\033[91m [+] Invalid input for port\nDefault set 80')
port = 80
delay = int(user_input('\033[92m [+] Enter delay : '))
if delay < 0 or delay > 100 :
slowprint('\033[91m [-] Invalid input for delay\nDefault set 5')
delay = 5
print('='*30 + 'Banner' +'='*30)
ban_grab(host, port, delay) # Calling function ban_grab()
if __name__ == '__main__' :
main()
except KeyboardInterrupt:
slowprint(' [-] Exiting....')